diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 32e06eb3b5fc39556863c05f718bb653217ba8f8..92668a5b6c2389a2e9ff28a4aa0508317f905af2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -240,7 +240,7 @@ stages: ### run pytest - exit_code=0 - - python3 -m pytest --tb=no $TEST_SUITE -v --create_cut --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld --ssnr --dut_encoder_path $DUT_ENCODER_PATH --dut_decoder_path $DUT_DECODER_PATH -n auto --testcase_timeout $testcase_timeout || exit_code=$? + - python3 -m pytest --tb=no $TEST_SUITE -v --create_cut --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld --ssnr --odg --dut_encoder_path $DUT_ENCODER_PATH --dut_decoder_path $DUT_DECODER_PATH -n auto --testcase_timeout $testcase_timeout || exit_code=$? - zero_errors=$(cat report-junit.xml | grep -c 'errors="0"') || true - python3 scripts/parse_xml_report.py report-junit.xml $MLD_ARTIFACT_NAME diff --git a/Makefile b/Makefile index 52622713d4f63e280c65046e6d2a5da2ac2b3d4d..4e92bc951388c8564bc2f2319e1a646aef1e01b1 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,8 @@ CFLAGS += -std=c99 -pedantic -Wcast-qual -Wall -W -Wextra -Wno-long-long \ -Wno-implicit-fallthrough -ffp-contract=off # to be uncommented in CI # CFLAGS += -Werror +CFLAGS += -Winit-self +CFLAGS += -Wunused-but-set-variable # libs to link LDLIBS += -lm diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index f55a30abbd690261a49233e1d5cadbbb59ef1c9a..9119a2c38c6d94ad4c32158b3b97aaa32b9348f1 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -388,8 +388,10 @@ + + @@ -399,8 +401,7 @@ - - + diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index d46cc4712a40bc6363cc3460921e6dc9d1cac854..c8ed6bc107148cc9fdc3c6c50e73f1ebce697ff7 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -593,11 +593,16 @@ common_h - - common_h + + + common_h + + + common_h + diff --git a/Workspace_msvc/renderer.vcxproj b/Workspace_msvc/renderer.vcxproj index c62874ec0afbfb789e4d8814ab3938b3e33f3410..1f95040e1f2189e4fed248f58eddd0e27e8da7a0 100644 --- a/Workspace_msvc/renderer.vcxproj +++ b/Workspace_msvc/renderer.vcxproj @@ -65,7 +65,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_util;..\lib_rend;.%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_util;..\lib_rend;..\lib_dec;..\lib_enc;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) EnableFastChecks diff --git a/apps/decoder.c b/apps/decoder.c index dc1cc25b35998a1f38f62f7481e0d28083441758..54a4c1dfe970f29f9dc79f83cd87a2993e56b7fa 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -45,6 +45,7 @@ #include "rotation_file_reader.h" #include "vector3_pair_file_reader.h" #include "wmc_auto.h" +#include "options.h" #include "stl.h" @@ -54,7 +55,7 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#if !defined( DEBUGGING ) && !defined( WMOPS_FLT ) +#if !defined( DEBUGGING ) && !defined( WMOPS ) static #endif int32_t frame = 0; /* Counter of frames */ @@ -161,15 +162,11 @@ int main( IVAS_RENDER_FRAMESIZE asked_frame_size; int16_t run_unit_tests = 0; -#ifdef WMOPS_FLT +#ifdef WMOPS reset_wmops(); reset_mem( USE_BYTES ); #endif -#if ( WMOPS ) -#ifndef DONT_COUNT - BASOP_init -#endif -#endif + /*------------------------------------------------------------------------------------------* * Parse command-line arguments *------------------------------------------------------------------------------------------*/ @@ -611,12 +608,8 @@ int main( mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ cleanup: -#ifndef DONT_COUNT - /* end of WMOPS counting */ - BASOP_end - BASOP_end_noprint -#endif - free( pcmBuf ); + + free( pcmBuf ); if ( arg.hrtfReaderEnabled ) { @@ -642,10 +635,11 @@ cleanup: fprintf( stderr, "\nError while closing file: %s\nContinuing...\n\n", arg.inputBitstreamFilename ); } -#ifdef WMOPS_FLT +#ifdef WMOPS print_wmops(); print_mem( NULL ); #endif + if ( !arg.quietModeEnabled ) { printf( "\n" ); @@ -1550,7 +1544,7 @@ static ivas_error decodeG192( delayNumSamples_orig[0] = -1; -#ifdef WMOPS_FLT +#ifdef WMOPS reset_stack(); reset_wmops(); #endif @@ -1806,28 +1800,18 @@ static ivas_error decodeG192( } } } + vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; -#ifdef WMOPS_FLT + +#ifdef WMOPS if ( vec_pos_update == 0 ) { update_wmops(); update_mem(); -#ifdef MEM_COUNT_DETAILS - export_mem( "mem_analysis.csv" ); -#endif } -#endif -#ifdef WMOPS -#ifndef DONT_COUNT - if ( vec_pos_update == 0 ) - { - /* update WMPOS counting (end of frame) */ - BASOP_frame_update(); - } - -#endif #endif } + /*------------------------------------------------------------------------------------------* * Flush what is still left in the VoIP Buffers.... *------------------------------------------------------------------------------------------*/ @@ -1948,12 +1932,15 @@ static ivas_error decodeG192( } } } + #ifdef WMOPS -#ifndef DONT_COUNT - /* update WMPOS counting (end of frame) */ - BASOP_frame_update(); + update_wmops(); + update_mem(); +#ifdef MEM_COUNT_DETAILS + export_mem( "mem_analysis.csv" ); #endif #endif + frame++; if ( !arg.quietModeEnabled ) { @@ -2211,7 +2198,7 @@ static ivas_error decodeVoIP( fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" ); } -#ifdef WMOPS_FLT +#ifdef WMOPS reset_stack(); reset_wmops(); #endif @@ -2493,13 +2480,8 @@ static ivas_error decodeVoIP( vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; frame++; systemTime_ms += systemTimeInc_ms; + #ifdef WMOPS -#ifndef DONT_COUNT - /* update WMPOS counting (end of frame) */ - BASOP_frame_update(); -#endif -#endif -#ifdef WMOPS_FLT update_mem(); update_wmops(); #endif diff --git a/apps/encoder.c b/apps/encoder.c index 283f1626a57fbfd0f2c159cf7fb73616e39eddbf..e7c5a20b7be9e3a6525e1c9041b3ef8a45cc28ce 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -39,6 +39,7 @@ #include "jbm_file_reader.h" #include "masa_file_reader.h" #include "wmc_auto.h" +#include "options.h" #include "stl.h" diff --git a/apps/renderer.c b/apps/renderer.c index 1cc4c1a321cc59149a23d78cdd4a426f84826df9..fcc1a04b785a036a6582e84b14a4a3fa845c30db 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -49,7 +49,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" +#include "prot_fx.h" #endif #define WMC_TOOL_SKIP diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c index 07637ff320105e2b3401795614086daec85f97ce..54f5e18feee3490e5829aaee85b9d1dc82b0d809 100644 --- a/lib_com/ACcontextMapping.c +++ b/lib_com/ACcontextMapping.c @@ -47,6 +47,7 @@ *-------------------------------------------------------------------*/ /*! r: index of next coefficient */ +#ifndef IVAS_FLOAT_FIXED int16_t get_next_coeff_mapped_ivas( int16_t ii[2], /* i/o: coefficient indexes */ int32_t *pp, /* o : peak(1)/hole(0) indicator */ @@ -64,6 +65,28 @@ int16_t get_next_coeff_mapped_ivas( return hm_cfg->indexBuffer[*idx]; } +#else +Word16 get_next_coeff_mapped_ivas( + Word16 ii[2], /* i/o: coefficient indexes */ + Word32 *pp, /* o : peak(1)/hole(0) indicator */ + Word16 *idx, /* o : index in unmapped domain */ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ +) +{ + UWord32 p; + + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); + p >>= sub( sizeof( p ) * 8, 1 ); + *pp = p; + move32(); + *idx = ii[p]; + move16(); + ii[p] = add( ii[p], 1 ); + move16(); + + return hm_cfg->indexBuffer[*idx]; +} +#endif /*-------------------------------------------------------------------* diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index 6cf368a46d5f166a2866d9e0a71f23651d65edec..ef550869294a871eac2f8084330357af76a39452 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -6,8 +6,7 @@ #include "options.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /* Returns: index of next coefficient */ diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index a16885a62a723d1abd6e6afa9ee585eb146f8366..3b36d10b320b4ca5ef082d785740f10754e03ba1 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -5,8 +5,7 @@ #include #include "assert.h" #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" /** diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 425823d27380ff43359f741bd16c784fd9f20dcb..767aea860a1f2591044ee1b3ee9de2c0ce1c380a 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -9,8 +9,7 @@ #include "cnst.h" #include "basop_util.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) void UnmapIndex( diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index 08c972ea919c48a45851cbf6b83c1d9868359ef7..bba7ab973482d64139bab72adab396014fe674af 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -223,7 +223,7 @@ void powfp_odd2_evs( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ -void tcx_arith_scale_envelope_flt( +void tcx_arith_scale_envelope_ivas( const Word16 L_spec_core, /* i : number of lines to scale Q0 */ Word16 L_frame, /* i : number of lines Q0 */ const Word32 env[], /* i : unscaled envelope Q16 */ @@ -518,7 +518,7 @@ void tcx_arith_scale_envelope_flt( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ -void tcx_arith_render_envelope_flt( +void tcx_arith_render_envelope_ivas( const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ const Word16 L_frame, /* i : number of spectral lines */ const Word16 L_spec, /* i : length of the coded spectrum */ diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 54533aacab113bf313d1edfcc4ae63f94a2bb69d..64cc81d04c07e795318487e3314dd0242216b140 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 3c45383b7e63e6080275ae67d6795ec214c4e8cc..2a813e15c27a7a0b7ce0b6a337d1320615e1693b 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -170,7 +170,7 @@ HISTORY: #pragma warning( disable : 4310 ) #endif -#if ( WMOPS ) +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif @@ -896,11 +896,10 @@ Word16 shl_sat( Word16 var1, Word16 var2 ) */ #ifdef BASOP_NOGLOB Word16 shr_o( Word16 var1, Word16 var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word16 shr( Word16 var1, Word16 var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word16 var_out; if ( var2 < 0 ) @@ -914,7 +913,7 @@ Word16 shr( Word16 var1, Word16 var2 ) var_out = shl( var1, var2 ); #endif /* BASOP_NOGLOB */ -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].shl--; #endif } @@ -995,11 +994,10 @@ Word16 shr_sat( Word16 var1, Word16 var2 ) */ #ifdef BASOP_NOGLOB Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word16 mult( Word16 var1, Word16 var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word16 var_out; Word32 L_product; @@ -1589,11 +1587,10 @@ Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ) #endif #ifdef BASOP_NOGLOB Word32 L_macNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word32 L_var_out; #ifdef BASOP_NOGLOB diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 4044484d32909f3def868e69585b42ac7f8d7883..ce32ca59c023b82176d608b85e270c57043229b7 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -936,13 +936,14 @@ Word32 div_w( Word32 L_num, Word32 L_den ) Word16 iteration; - if ( L_den == (Word32) 0 ) + IF( L_den == 0 ) { /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */ return ( 0 ); } - if ( ( L_num < (Word32) 0 ) || ( L_den < (Word32) 0 ) ) + test(); + IF( ( L_num < 0 ) || ( L_den < 0 ) ) { /* printf("Division Error in div_l, Fatal error in "); printStack(); */ return ( 0 ); @@ -951,24 +952,24 @@ Word32 div_w( Word32 L_num, Word32 L_den ) W_num = W_deposit32_h( L_num ); W_den = W_deposit32_h( L_den ); - if ( W_num >= W_den ) + IF( W_sub( W_num, W_den ) >= 0 ) { return MAX_32; } - else + ELSE { - W_num = W_shr( W_num, (Word16) 1 ); - W_den = W_shr( W_den, (Word16) 1 ); + W_num = W_shr( W_num, 1 ); + W_den = W_shr( W_den, 1 ); - for ( iteration = (Word16) 0; iteration < (Word16) 31; iteration++ ) + FOR( iteration = 0; iteration < 31; iteration++ ) { - L_var_out = L_shl( L_var_out, (Word16) 1 ); - W_num = W_shl( W_num, (Word16) 1 ); + L_var_out = L_shl( L_var_out, 1 ); + W_num = W_shl( W_num, 1 ); - if ( W_num >= W_den ) + IF( W_sub( W_num, W_den ) >= 0 ) { W_num = W_sub( W_num, W_den ); - L_var_out = L_add( L_var_out, (Word32) 1 ); + L_var_out = L_add( L_var_out, 1 ); } } @@ -1583,6 +1584,22 @@ Word16 idiv1616( Word16 x, Word16 y ) return y; } +Word16 idiv1616_1( Word16 x, Word16 y ) +{ + IF( L_mult0( x, y ) < 0 ) + { + return negate( idiv1616( abs_s( x ), abs_s( y ) ) ); + } + ELSE IF( L_mult0( x, y ) > 0 ) + { + return idiv1616( x, y ); + } + ELSE + { + return 0; + } +} + Word32 norm_llQ31( /* o : normalized result Q31 */ Word32 L_c, /* i : upper bits of accu Q-1 */ Word32 L_sum, /* i : lower bits of accu, unsigned Q31 */ @@ -2596,7 +2613,7 @@ cmplx CL_scale_t( cmplx x, Word16 y ) cmplx result; result.re = Mpy_32_16_1( x.re, y ); result.im = Mpy_32_16_1( x.im, y ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].CL_scale++; @@ -2609,11 +2626,11 @@ cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ) cmplx result; result.re = Mpy_32_16_1( x.re, y1 ); result.im = Mpy_32_16_1( x.im, y2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].CL_dscale++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -2622,7 +2639,7 @@ cmplx CL_mult_32x16( cmplx input, cmplx_s coeff ) cmplx result; result.re = L_sub( Mpy_32_16_1( input.re, coeff.re ), Mpy_32_16_1( input.im, coeff.im ) ); result.im = L_add( Mpy_32_16_1( input.re, coeff.im ), Mpy_32_16_1( input.im, coeff.re ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_multr_32x16++; multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].Mpy_32_16_1--; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 380c8316bfa3e1c8707e03cc256176b3b20f51a1..d633a33f918410a7b5ee32b6aceb7a1a279af15c 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -582,6 +582,8 @@ Word16 idiv1616U( Word16 x, Word16 y ); Word16 idiv1616( Word16 x, Word16 y ); +Word16 idiv1616_1( Word16 x, Word16 y ); + /*------------------------------------------------------------------* * Dot_product16HQ: * diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index 78f6ac2764e31bd1e2f9410f7d7015408777ee8b..c20235e391d15ae9f3e1a8b1ebf2efe1e7a0e561 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ void bitalloc_fx( Word16 *y, /* i : reordered norm of sub-vectors Q0 */ diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index fd34a0c1d225791932e1b1e38c6a7e607fb58f8e..c8ad205e1e3ae5fa02fd6ac91575d713fe475df2 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------------- * bitallocsum_fx() @@ -36,6 +35,7 @@ void bitallocsum_fx( total = add( total, tmp ); } *sum = total; + move16(); IF( LE_16( length, L_FRAME32k ) ) { @@ -50,6 +50,7 @@ void bitallocsum_fx( move16(); diff = sub( diff, 1 ); *sum = add( *sum, 1 ); + move16(); } i = add( i, 1 ); if ( GE_16( i, nb_sfm ) ) diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 0638b903c828699c91c578f07603db8418a6ace2..1e1fd7552deb65ca4b71bce3410fc67112b9e6b2 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_com.h" @@ -67,7 +66,7 @@ void BITS_ALLOC_init_config_acelp( /*ACELP ICB config*/ test(); - IF( EQ_16( rate_mode_index, 0 ) || NE_16( narrowBand, 0 ) ) + IF( ( rate_mode_index == 0 ) || ( narrowBand != 0 ) ) { move16(); move16(); @@ -149,16 +148,16 @@ Word16 BITS_ALLOC_config_acelp( { move16(); pConfigAcelp->formant_enh = 1; - if ( EQ_16( coder_type, INACTIVE ) ) + if ( coder_type == INACTIVE ) { move16(); pConfigAcelp->formant_enh = 0; } } - IF( s_and( (Word16) EQ_16( band_index, 1 ), (Word16) EQ_16( nb_subfr, 4 ) ) ) + IF( L_and( EQ_16( band_index, 1 ), EQ_16( nb_subfr, 4 ) ) ) { - IF( EQ_16( coder_type, INACTIVE ) ) + IF( coder_type == INACTIVE ) { pConfigAcelp->pre_emphasis = 0; move16(); @@ -213,7 +212,9 @@ Word16 BITS_ALLOC_config_acelp( IF( GT_16( coder_type, ACELP_MODE_MAX ) ) /* keep pitch sharpening for RF_ALLPRED mode */ { pConfigAcelp->pitch_sharpening = 0; + move16(); pConfigAcelp->phase_scrambling = 0; + move16(); } /*Allocate bits and different modes*/ @@ -238,9 +239,10 @@ Word16 BITS_ALLOC_config_acelp( move16(); pConfigAcelp->ltf_bits = ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; - if ( s_and( (Word16) EQ_16( nb_subfr, 5 ), (Word16) EQ_16( pConfigAcelp->ltf_bits, 4 ) ) ) + IF( L_and( EQ_16( nb_subfr, 5 ), EQ_16( pConfigAcelp->ltf_bits, 4 ) ) ) { pConfigAcelp->ltf_bits = add( pConfigAcelp->ltf_bits, 1 ); + move16(); } bits = add( bits, pConfigAcelp->ltf_bits ); @@ -253,9 +255,10 @@ Word16 BITS_ALLOC_config_acelp( /* skip subframe 1, 3 gain encoding, and use from subframe 0, and 3, respectively */ test(); test(); - IF( GE_16( coder_type, ACELP_MODE_MAX ) && ( EQ_16( i, 1 ) || EQ_16( i, 3 ) ) ) + if ( GE_16( coder_type, ACELP_MODE_MAX ) && ( EQ_16( i, 1 ) || EQ_16( i, 3 ) ) ) { pConfigAcelp->gains_mode[i] = 0; + move16(); } bits = add( bits, ACELP_GAINS_BITS[pConfigAcelp->gains_mode[i]] ); @@ -267,7 +270,7 @@ Word16 BITS_ALLOC_config_acelp( /*Innovation*/ - if ( LT_16( bits_frame, bits ) ) + IF( LT_16( bits_frame, bits ) ) { printf( "Warning: bits per frame too low\n" ); return -1; @@ -280,10 +283,15 @@ Word16 BITS_ALLOC_config_acelp( ELSE IF( EQ_16( coder_type, RF_GENPRED ) ) { pConfigAcelp->fixed_cdk_index[0] = 0; /* 7 bits */ + move16(); pConfigAcelp->fixed_cdk_index[1] = -1; + move16(); pConfigAcelp->fixed_cdk_index[2] = 0; /* 7 bits */ + move16(); pConfigAcelp->fixed_cdk_index[3] = -1; + move16(); pConfigAcelp->fixed_cdk_index[4] = -1; + move16(); bits = add( bits, 14 ); } ELSE IF( EQ_16( coder_type, RF_NOPRED ) ) @@ -339,14 +347,14 @@ static Word16 BITS_ALLOC_adjust_generic( FOR( k = 0; k < pulseconfig_size - 1; k++ ) { - IF( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_subframe2 ) + IF( GT_16( i_mult2( pulseconfigbits[k], nb_subfr ), bits_subframe2 ) ) { k = sub( k, 1 ); /* previous mode did not exceed bit-budget */ BREAK; } } - if ( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_subframe2 ) + if ( GT_16( i_mult2( pulseconfigbits[k], nb_subfr ), bits_subframe2 ) ) { k = sub( k, 1 ); /* previous mode did not exceed bit-budget */ } @@ -361,14 +369,14 @@ static Word16 BITS_ALLOC_adjust_generic( bits_currsubframe = sub( add( i_mult2( sfr, bits_subframe2 ), bits_subframe2 ), bitsused ); /* try increasing mode while below threshold */ - WHILE( ( LT_16( k, pulseconfig_size - 1 ) ) && ( LE_16( i_mult2( pulseconfigbits[add( k, 1 )], nb_subfr ), bits_currsubframe ) ) ) + WHILE( ( LT_16( k, sub( pulseconfig_size, 1 ) ) ) && ( LE_16( i_mult2( pulseconfigbits[k + 1], nb_subfr ), bits_currsubframe ) ) ) { test(); k = add( k, 1 ); } /* try decreasing mode until below threshold */ - WHILE( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_currsubframe ) + WHILE( GT_16( i_mult2( pulseconfigbits[k], nb_subfr ), bits_currsubframe ) ) { k = sub( k, 1 ); @@ -416,9 +424,11 @@ static Word16 fcb_table( // PMT("Not floating point computation, but fixed point operator are still missing ") out = PulseConfTable[n].bits; - if ( L_subfr > L_SUBFR ) + move16(); + if ( GT_16( L_subfr, L_SUBFR ) ) { out = fast_FCB_bits_2sfr[n]; + move16(); } return ( out ); @@ -448,50 +458,61 @@ static ivas_error acelp_FCB_allocator( // PMT("Not floating point computation, but fixed point operator are still missing ") error = IVAS_ERR_OK; + move32(); cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ + move16(); p_fixed_cdk_index = fixed_cdk_index; + move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ - if ( tc_subfr >= L_SUBFR && fix_first ) + test(); + IF( GE_16( tc_subfr, L_SUBFR ) && fix_first ) { Word16 i; - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { - *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ); + *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) ); + move16(); } return error; } /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ sfr = 0; - if ( fix_first ) + move16(); + IF( fix_first ) { - *nBits -= ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ); + *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) ); + move16(); sfr = 1; + move16(); p_fixed_cdk_index++; nb_subfr = 3; + move16(); } /* distribute the bit-budget equally between subframes */ - if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ + IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */ { max_n = 6; + move16(); } - else + ELSE { max_n = ACELP_FIXED_CDK_NB; + move16(); } - for ( cdbk = 0; cdbk < max_n; cdbk++ ) + FOR( cdbk = 0; cdbk < max_n; cdbk++ ) { - if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits ) + IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) ) { - break; + BREAK; } } - cdbk--; + cdbk = sub( cdbk, 1 ); #if defined DEBUGGING if ( cdbk < 0 && coder_type != TRANSITION ) @@ -506,64 +527,74 @@ static ivas_error acelp_FCB_allocator( set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); nBits_tmp = 0; - if ( cdbk >= 0 ) + move16(); + IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); + move16(); } - else + ELSE { nBits_tmp = 0; + move16(); } - *nBits -= nBits_tmp * nb_subfr; + *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) ); + move16(); /* try to increase the FCB bit-budget of the first subframe(s) */ - if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) + IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { - step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; - while ( *nBits >= step ) + step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); + WHILE( GE_16( *nBits, step ) ) { ( *p_fixed_cdk_index )++; - *nBits -= step; + *nBits = sub( *nBits, step ); + move16(); p_fixed_cdk_index++; } /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); - if ( *nBits >= step && cdbk >= 0 ) + step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) ); + test(); + IF( GE_16( *nBits, step ) && cdbk >= 0 ) { fixed_cdk_index[sfr]++; - *nBits -= step; - - if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) + *nBits = sub( *nBits, step ); + move16(); + test(); + IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { sfr++; fixed_cdk_index[sfr]++; - *nBits -= step; + *nBits = sub( *nBits, step ); + move16(); } } } /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ - if ( tc_subfr >= L_SUBFR ) + IF( GE_16( tc_subfr, L_SUBFR ) ) { Word16 tempr; SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ - if ( tc_subfr / L_SUBFR < nb_subfr - 1 ) + IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) { - SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); + SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } } /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ - if ( L_subfr > L_SUBFR ) + IF( GT_16( L_subfr, L_SUBFR ) ) { Word16 i, j; - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { j = fixed_cdk_index[i]; + move16(); fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; + move16(); } } @@ -621,17 +652,25 @@ ivas_error config_acelp1( ivas_error error; error = IVAS_ERR_OK; + move32(); // PMT("Not floating point computation, but fixed point operator are still missing ") /*-----------------------------------------------------------------* * Set the flag indicating two-stage Unvoiced (UC) frame *-----------------------------------------------------------------*/ *uc_two_stage_flag = 0; - if ( coder_type == UNVOICED ) + move16(); + IF( EQ_16( coder_type, UNVOICED ) ) { - if ( total_brate >= MIN_UNVOICED_TWO_STAGE_BRATE && element_mode > EVS_MONO && ( idchan == 0 || ( ( total_brate >= 8500 || extl_brate == 0 ) && tdm_LRTD_flag == 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + if ( GE_32( total_brate, MIN_UNVOICED_TWO_STAGE_BRATE ) && element_mode > EVS_MONO && ( idchan == 0 || ( ( GE_32( total_brate, 8500 ) || extl_brate == 0 ) && EQ_16( tdm_LRTD_flag, 1 ) ) ) ) { *uc_two_stage_flag = 1; + move16(); } } @@ -639,9 +678,10 @@ ivas_error config_acelp1( * Set the number of subframes *-----------------------------------------------------------------*/ - if ( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { nb_subfr = NB_SUBFR; + move16(); #if defined DEBUGGING if ( ( ( core_brate_inp < 5900 && coder_type > UNVOICED ) && !( core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION ) ) && !( idchan > 0 && element_mode == IVAS_CPE_TD ) && !( element_mode == IVAS_SCE && tdm_low_rate_mode ) ) @@ -655,9 +695,10 @@ ivas_error config_acelp1( } #endif } - else /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { nb_subfr = NB_SUBFR16k; + move16(); #if defined DEBUGGING if ( core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE ) @@ -668,13 +709,16 @@ ivas_error config_acelp1( } coder_type_sw = coder_type; - if ( core != ACELP_CORE ) + move16(); + IF( core != ACELP_CORE ) { /* used in acelp_core_switch_enc() */ nb_subfr = 1; - if ( L_frame == L_FRAME ) + move16(); + if ( EQ_16( L_frame, L_FRAME ) ) { coder_type_sw = TRANSITION; + move16(); } } @@ -683,171 +727,230 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ flag_hardcoded = 0; + move16(); i = 0; + move16(); - while ( i < SIZE_BRATE_INTERMED_TBL ) + WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) { - if ( core_brate_inp == brate_intermed_tbl[i] ) + IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 1; - break; + move16(); + BREAK; } - if ( core_brate_inp < brate_intermed_tbl[i] ) + IF( LT_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 0; - break; + move16(); + BREAK; } i++; } - if ( element_mode == IVAS_CPE_TD && coder_type == AUDIO && - core_brate_inp <= STEREO_GSC_BIT_RATE_ALLOC && brate_intermed_tbl[i] == ACELP_9k60 ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + test(); + test(); + test(); + if ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate_inp, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i--; + i = sub( i, 1 ); } core_brate = brate_intermed_tbl[i]; + move32(); if ( element_mode > EVS_MONO ) { flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ + move16(); } + test(); if ( core != ACELP_CORE && element_mode == EVS_MONO ) /* needed for mode1 core switching in EVS mono */ { flag_hardcoded = 1; + move16(); } /*-----------------------------------------------------------------* * ACELP bit allocation *-----------------------------------------------------------------*/ - - if ( !( coder_type == TRANSITION && tc_subfr != -1 ) || enc_dec == DEC ) + test(); + test(); + IF( !( EQ_16( coder_type, TRANSITION ) && NE_16( tc_subfr, -1 ) ) || EQ_16( enc_dec, DEC ) ) { /* Set the bit-budget */ - bits = (Word16) ( core_brate_inp / FRAMES_PER_SEC ); + bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - if ( coder_type == TRANSITION && enc_dec == DEC && tc_call == 1 ) + test(); + test(); + if ( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) { - bits += *nBits_es_Pred; /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ + bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } /* Subtract signalling bits */ - if ( enc_dec == DEC && idchan == 1 && element_mode > EVS_MONO ) + test(); + test(); + IF( EQ_16( enc_dec, DEC ) && EQ_16( idchan, 1 ) && element_mode > EVS_MONO ) { - bits -= TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS; + bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - if ( tdm_LRTD_flag == 1 ) + if ( EQ_16( tdm_LRTD_flag, 1 ) ) { - bits += STEREO_BITS_TCA; + bits = add( bits, STEREO_BITS_TCA ); } /* subtract TBE/BWE flag */ - if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { - bits--; + bits = sub( bits, 1 ); } } - else + ELSE { /* Subtract signalling bits */ - bits -= signalling_bits; + bits = sub( bits, signalling_bits ); } - if ( extl_brate > 0 && ( extl == WB_TBE || extl == SWB_TBE || extl == FB_TBE || extl == WB_BWE || extl == SWB_BWE || extl == FB_BWE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { /* extension layer signalling bit is counted in the extension layer bitbudget */ - bits++; + bits = add( bits, 1 ); } /*-----------------------------------------------------------------* * LSF Q bit-budget *-----------------------------------------------------------------*/ - - if ( !tdm_lp_reuse_flag || idchan == 0 ) + test(); + test(); + test(); + IF( !tdm_lp_reuse_flag || idchan == 0 ) { /* LSF Q bit-budget */ acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; + move16(); - if ( !flag_hardcoded ) + IF( !flag_hardcoded ) { - if ( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { - if ( element_mode == IVAS_SCE && tdm_low_rate_mode ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) { acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; + move16(); } - else if ( ( total_brate < 7200 || coder_type == INACTIVE || coder_type == AUDIO ) && idchan == 1 ) + ELSE IF( ( LT_32( total_brate, 7200 ) || coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( idchan, 1 ) ) { /* TD stereo, secondary channel: do nothing */ acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; + move16(); } - else if ( element_mode > EVS_MONO && coder_type == AUDIO && brate_intermed_tbl[i] < ACELP_9k60 ) + ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LT_32( brate_intermed_tbl[i], ACELP_9k60 ) ) { /* primary channel: do nothing */ } - else if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ ) + ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ ) { acelp_cfg->lsf_bits = 42; + move16(); } - else if ( total_brate <= 9600 || coder_type == UNVOICED ) + ELSE IF( LE_32( total_brate, 9600 ) || EQ_16( coder_type, UNVOICED ) ) { acelp_cfg->lsf_bits = 31; + move16(); } - else if ( total_brate <= 20000 ) + ELSE IF( LE_32( total_brate, 20000 ) ) { acelp_cfg->lsf_bits = 36; + move16(); } - else + ELSE { acelp_cfg->lsf_bits = 41; + move16(); } } - else /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { acelp_cfg->lsf_bits = 41; + move16(); } } - bits -= acelp_cfg->lsf_bits; + bits = sub( bits, acelp_cfg->lsf_bits ); /* mid-LSF Q bit-budget */ acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; + move16(); - if ( element_mode > EVS_MONO && coder_type == AUDIO /*&& brate_intermed_tbl[i] < ACELP_9k60*/ ) + test(); + if ( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] < ACELP_9k60*/ ) { acelp_cfg->mid_lsf_bits = 5; + move16(); /* primary channel: do nothing */ } - bits -= acelp_cfg->mid_lsf_bits; + bits = sub( bits, acelp_cfg->mid_lsf_bits ); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE - else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) + ELSE IF( EQ_16( tdm_lp_reuse_flag, 1 ) && EQ_16( idchan, 1 ) && NE_16( active_cnt, 1 ) ) { - bits -= TDM_IC_LSF_PRED_BITS; + bits = sub( bits, TDM_IC_LSF_PRED_BITS ); } #endif /* gain Q bit-budget - part 1 */ - if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) || ( coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && coder_type != INACTIVE && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) || ( coder_type == INACTIVE && GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, -1 )]; - bits -= *nBits_es_Pred; + move16(); + bits = sub( bits, *nBits_es_Pred ); } - else if ( *uc_two_stage_flag ) + ELSE IF( *uc_two_stage_flag ) { *nBits_es_Pred = 4; - bits -= *nBits_es_Pred; + move16(); + bits = sub( bits, *nBits_es_Pred ); } } - else + ELSE { bits = *unbits; + move16(); } - if ( coder_type == TRANSITION && tc_call == 0 ) + test(); + IF( EQ_16( coder_type, TRANSITION ) && tc_call == 0 ) { *unbits = bits; return error; @@ -856,14 +959,19 @@ ivas_error config_acelp1( /*-----------------------------------------------------------------* * Low-rate mode - bits are allocated in tdm_low_rate_enc() *-----------------------------------------------------------------*/ - - if ( element_mode == IVAS_SCE && tdm_low_rate_mode ) + test(); + IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) { acelp_cfg->FEC_mode = 0; acelp_cfg->ltf_mode = FULL_BAND; *nBits_es_Pred = 0; *unbits = 0; acelp_cfg->ubits = 0; + move16(); + move16(); + move16(); + move16(); + move16(); return error; } @@ -873,34 +981,43 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ acelp_cfg->FEC_mode = 0; - if ( core_brate >= ACELP_11k60 && ( idchan == 0 || element_mode == EVS_MONO ) ) + move16(); + test(); + test(); + IF( GE_32( core_brate, ACELP_11k60 ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { acelp_cfg->FEC_mode = 1; + move16(); - if ( coder_type > UNVOICED && coder_type < AUDIO && coder_type != VOICED ) + test(); + test(); + if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) { - bits -= FEC_BITS_CLS; + bits = sub( bits, FEC_BITS_CLS ); } - if ( coder_type != TRANSITION ) + IF( NE_16( coder_type, TRANSITION ) ) { - if ( total_brate >= ACELP_16k40 ) + IF( GE_32( total_brate, ACELP_16k40 ) ) { acelp_cfg->FEC_mode = 2; - - if ( coder_type > UNVOICED && coder_type < AUDIO ) + move16(); + test(); + if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { - bits -= FEC_BITS_ENR; + bits = sub( bits, FEC_BITS_ENR ); } } - if ( total_brate >= ACELP_32k ) + IF( GE_32( total_brate, ACELP_32k ) ) { acelp_cfg->FEC_mode = 3; + move16(); - if ( coder_type > UNVOICED && coder_type < AUDIO ) + test(); + if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { - bits -= FEC_BITS_POS; + bits = sub( bits, FEC_BITS_POS ); } } } @@ -909,50 +1026,68 @@ ivas_error config_acelp1( /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation *-----------------------------------------------------------------*/ - - if ( idchan > 0 && element_mode > EVS_MONO ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( idchan > 0 && element_mode > EVS_MONO ) { acelp_cfg->ltf_mode = FULL_BAND; + move16(); } - else if ( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { acelp_cfg->ltf_mode = FULL_BAND; + move16(); } - else if ( ( coder_type == GENERIC || coder_type == TRANSITION ) && core_brate < ACELP_11k60 ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && core_brate < ACELP_11k60 ) { acelp_cfg->ltf_mode = LOW_PASS; + move16(); } - else if ( core_brate >= ACELP_11k60 && ( coder_type != AUDIO && !( coder_type == INACTIVE && L_frame == L_FRAME ) ) ) + ELSE IF( GE_32( core_brate, ACELP_11k60 ) && ( NE_16( coder_type, AUDIO ) && !( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME ) ) ) ) { - if ( coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE ) /* GSC Inactive @16kHz */ + test(); + test(); + IF( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) /* GSC Inactive @16kHz */ { acelp_cfg->ltf_mode = FULL_BAND; + move16(); } - else + ELSE { acelp_cfg->ltf_mode = NORMAL_OPERATION; + move16(); if ( coder_type != TRANSITION ) { - bits -= nb_subfr; + bits = sub( bits, nb_subfr ); } } } - else + ELSE { acelp_cfg->ltf_mode = FULL_BAND; + move16(); } /*-----------------------------------------------------------------* * UC bit-budget *-----------------------------------------------------------------*/ - - if ( ( ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && core_brate <= ACELP_9k60 ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) + test(); + test(); + test(); + test(); + test(); + test(); + if ( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { - bits -= NBITS_NOISENESS; /* noiseness */ + bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ } - if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) + if ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { - bits -= ( 3 * NB_SUBFR ); /* tilt factor */ + bits = sub( bits, 3 * NB_SUBFR ); /* tilt factor */ } /*-----------------------------------------------------------------* @@ -960,100 +1095,102 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ fix_first = 0; - if ( coder_type == TRANSITION ) + move16(); + IF( EQ_16( coder_type, TRANSITION ) ) { - if ( tc_call == 2 ) + if ( EQ_16( tc_call, 2 ) ) { fix_first = 1; + move16(); } /* TC signalling */ - if ( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { - if ( tc_subfr == TC_0_0 ) + IF( EQ_16( tc_subfr, TC_0_0 ) ) { if ( enc_dec == ENC ) { - bits -= 1; /* TC signalling */ + bits = sub( bits, 1 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= 3; /* LP filtering flag */ + bits = sub( bits, 3 ); /* LP filtering flag */ } } - else if ( tc_subfr == TC_0_64 ) + ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { if ( enc_dec == ENC ) { - bits -= 4; /* TC signalling */ + bits = sub( bits, 4 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= 3; /* LP filtering flag */ + bits = sub( bits, 3 ); /* LP filtering flag */ } } - else if ( tc_subfr == TC_0_128 ) + ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { if ( enc_dec == ENC ) { - bits -= 4; /* TC signalling */ + bits = sub( bits, 4 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= 2; /* LP filtering flag */ + bits = sub( bits, 2 ); /* LP filtering flag */ } } - else if ( tc_subfr == TC_0_192 ) + ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { if ( enc_dec == ENC ) { - bits -= 3; /* TC signalling */ + bits = sub( bits, 3 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= 1; /* LP filtering flag */ + bits = sub( bits, 1 ); /* LP filtering flag */ } } - else if ( tc_subfr == L_SUBFR ) + ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { if ( enc_dec == ENC ) { - bits -= 3; /* TC signalling */ + bits = sub( bits, 3 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ + bits = sub( bits, idiv1616( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ } } - else + ELSE { if ( enc_dec == ENC ) { - bits -= 4; /* TC signalling */ + bits = sub( bits, 4 ); /* TC signalling */ } - if ( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - bits -= ( L_FRAME - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ + bits = sub( bits, idiv1616_1( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ } } } - else /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { - if ( tc_subfr <= 2 * L_SUBFR ) + IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) { - bits -= 2; /* TC signalling */ + bits = sub( bits, 2 ); /* TC signalling */ } - else + ELSE { - bits -= 3; /* TC signalling */ + bits = sub( bits, 3 ); /* TC signalling */ } } @@ -1061,7 +1198,7 @@ ivas_error config_acelp1( } /* glottal-shape codebook bits */ - bits -= ( 3 + 6 + 1 + 3 ); + bits = sub( bits, 3 + 6 + 1 + 3 ); } /*-----------------------------------------------------------------* @@ -1069,24 +1206,43 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ acelp_cfg->fcb_mode = 0; - - if ( element_mode == IVAS_CPE_TD && tdm_low_rate_mode == 1 && coder_type != INACTIVE && coder_type != UNVOICED ) /* GENERIC low rate mode for secondary channel */ + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ { set16_fx( acelp_cfg->pitch_bits, 0, NB_SUBFR16k ); set16_fx( acelp_cfg->gains_mode, 0, NB_SUBFR16k ); - for ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { acelp_cfg->pitch_bits[i] = 0; - if ( tdm_Pitch_reuse_flag == 0 ) + move16(); + IF( tdm_Pitch_reuse_flag == 0 ) { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, 2 * i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; - bits -= acelp_cfg->pitch_bits[i]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( 2 * L_SUBFR, i ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); + bits = sub( bits, acelp_cfg->pitch_bits[i] ); } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; - bits -= acelp_cfg->gains_mode[i]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + bits = sub( bits, acelp_cfg->gains_mode[i] ); } acelp_cfg->fcb_mode = 1; + move16(); #ifdef DEBUGGING if ( bits >= 55 ) @@ -1096,89 +1252,111 @@ ivas_error config_acelp1( } else #endif - if ( bits >= 16 ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - } - else + IF( GE_16( bits, 16 ) ) + { + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + } + ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_cfg->fixed_cdk_index[1] = -1; + move16(); } acelp_cfg->fixed_cdk_index[2] = -1; + move16(); acelp_cfg->fixed_cdk_index[3] = -1; + move16(); } - else if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || ( nb_subfr == NB_SUBFR16k && ( total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE ) ) || core == HQ_CORE ) + ELSE IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && ( GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) || coder_type != INACTIVE ) ) || EQ_16( core, HQ_CORE ) ) { /* pitch Q & gain Q bit-budget - part 2*/ - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { - if ( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { - if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 ) + IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) { acelp_cfg->pitch_bits[i] = 0; + move16(); } - else + ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); } - else /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - if ( tdm_Pitch_reuse_flag == 1 && idchan == 1 ) + test(); + IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) { acelp_cfg->pitch_bits[i] = 0; + move16(); } - else + ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + move16(); } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + move16(); } - bits -= acelp_cfg->pitch_bits[i]; + bits = sub( bits, acelp_cfg->pitch_bits[i] ); - if ( coder_type == INACTIVE && acelp_cfg->gains_mode[i] == 6 /* VQ vs. SQ threshold @32 kbps */ ) + test(); + IF( coder_type == INACTIVE && EQ_16( acelp_cfg->gains_mode[i], 6 ) /* VQ vs. SQ threshold @32 kbps */ ) { - bits -= 5; + bits = sub( bits, 5 ); } - else + ELSE { - if ( *uc_two_stage_flag == 1 ) + if ( EQ_16( *uc_two_stage_flag, 1 ) ) { acelp_cfg->gains_mode[i] = 7; + move16(); } - bits -= acelp_cfg->gains_mode[i]; + bits = sub( bits, acelp_cfg->gains_mode[i] ); } } /* algebraic codebook bit-budget */ - if ( flag_hardcoded || ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( flag_hardcoded || ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) || ( GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) && coder_type == INACTIVE ) ) { - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { - if ( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_fx( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); } - else /* L_frame == L_FRAME16k */ + ELSE /* L_frame == L_FRAME16k */ { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + move16(); } - bits -= acelp_cfg->fixed_cdk_index[i]; + bits = sub( bits, acelp_cfg->fixed_cdk_index[i] ); } } - else if ( !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) + ELSE IF( !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) { - if ( coder_type == UNVOICED && !( *uc_two_stage_flag ) ) + test(); + IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { - i = bits / NB_SUBFR; + i = idiv1616( bits, NB_SUBFR ); + move16(); if ( i % 2 == 0 ) { - i--; /* must be odd */ + i = sub( i, 1 ); /* must be odd */ } i = s_min( i, 13 ); #ifdef DEBUG_MODE_TD @@ -1187,55 +1365,71 @@ ivas_error config_acelp1( #endif i = s_max( i, 0 ); /* If i == 0-> random noise generator will be used as FCB */ set16_fx( acelp_cfg->fixed_cdk_index, i, NB_SUBFR ); - bits -= ( i * NB_SUBFR ); + bits = sub( bits, i_mult( i, NB_SUBFR ) ); } - else + ELSE { acelp_cfg->fcb_mode = 1; - if ( element_mode == IVAS_CPE_TD ) + move16(); + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr ) ) /* enough bits for all fcb */ + IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), ( nb_subfr ) ) ) ) /* enough bits for all fcb */ { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } - else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 1 ) ) + ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; + move16(); } - else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) * ( nb_subfr - 2 ) ) + ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 2, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; + move16(); acelp_cfg->fixed_cdk_index[1] = -1; + move16(); acelp_cfg->fixed_cdk_index[3] = -1; + move16(); } - else if ( bits >= ACELP_FIXED_CDK_BITS( 0 ) ) + ELSE IF( GE_16( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; + move16(); acelp_cfg->fixed_cdk_index[0] = -1; + move16(); acelp_cfg->fixed_cdk_index[2] = -1; + move16(); acelp_cfg->fixed_cdk_index[3] = -1; + move16(); } - else /* No FCB */ + ELSE /* No FCB */ { #if defined DEBUGGING IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n" ); #endif acelp_cfg->fixed_cdk_index[0] = -1; + move16(); acelp_cfg->fixed_cdk_index[1] = -1; + move16(); acelp_cfg->fixed_cdk_index[2] = -1; + move16(); acelp_cfg->fixed_cdk_index[3] = -1; + move16(); } } - else if ( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) + ELSE IF( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) { bits = 100; /* 9 kbps for fcb */ + move16(); acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } - else + ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } @@ -1243,102 +1437,136 @@ ivas_error config_acelp1( } /* AVQ codebook */ - if ( ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) + test(); + test(); + test(); + IF( ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) || ( GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) && coder_type == INACTIVE ) ) { - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { - if ( flag_hardcoded ) + IF( flag_hardcoded ) { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; + move16(); { - bits -= acelp_cfg->AVQ_cdk_bits[i]; + bits = sub( bits, acelp_cfg->AVQ_cdk_bits[i] ); } } - bits -= G_AVQ_BITS; + bits = sub( bits, G_AVQ_BITS ); } - if ( core_brate_inp >= MIN_BRATE_AVQ_EXC && core_brate_inp <= MAX_BRATE_AVQ_EXC_TD && coder_type == GENERIC ) + test(); + test(); + if ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) { /* harm. flag ACELP AVQ */ - bits--; + bits = sub( bits, 1 ); } - if ( !flag_hardcoded ) + IF( !flag_hardcoded ) { Word16 bit_tmp; - bit_tmp = bits / nb_subfr; + bit_tmp = idiv1616( bits, nb_subfr ); set16_fx( acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr ); - bits -= bit_tmp * nb_subfr; + bits = sub( bits, i_mult( bit_tmp, nb_subfr ) ); bit_tmp = bits % nb_subfr; - acelp_cfg->AVQ_cdk_bits[0] += bit_tmp; - bits -= bit_tmp; + move16(); + acelp_cfg->AVQ_cdk_bits[0] = add( acelp_cfg->AVQ_cdk_bits[0], bit_tmp ); + move16(); + bits = sub( bits, bit_tmp ); } } } - else if ( ( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) || ( ( coder_type == INACTIVE || coder_type == AUDIO ) && nb_subfr == NB_SUBFR ) || ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) ) + ELSE IF( ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) || ( ( coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( nb_subfr, NB_SUBFR ) ) || ( coder_type == INACTIVE && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { Word32 Local_BR, Pitch_BR; Word16 Pitch_CT; /* as defined at the beginning of [enc,dec]_pit_exc() */ - if ( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || core_brate > GSC_H_RATE_STG ) ) + test(); + test(); + IF( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || GT_32( core_brate, GSC_H_RATE_STG ) ) ) { Local_BR = ACELP_8k00; + move32(); Pitch_CT = GENERIC; + move16(); Pitch_BR = ACELP_8k00; - if ( L_frame == L_FRAME16k ) + move32(); + IF( EQ_16( L_frame, L_FRAME16k ) ) { Local_BR = ACELP_14k80; - if ( GSC_IVAS_mode > 0 && core_brate < IVAS_24k4 ) + move32(); + test(); + if ( GSC_IVAS_mode > 0 && LT_32( core_brate, IVAS_24k4 ) ) { Local_BR = ACELP_9k60; + move32(); } Pitch_BR = core_brate; + move32(); } } - else if ( GSC_noisy_speech ) + ELSE IF( GSC_noisy_speech ) { Local_BR = ACELP_7k20; + move32(); Pitch_CT = GENERIC; + move16(); Pitch_BR = ACELP_7k20; - if ( L_frame == L_FRAME16k ) + move32(); + if ( EQ_16( L_frame, L_FRAME16k ) ) { Pitch_BR = core_brate; + move32(); } } - else + ELSE { Local_BR = ACELP_7k20; + move32(); Pitch_CT = AUDIO; + move16(); Pitch_BR = core_brate; + move32(); - if ( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { Local_BR = ACELP_13k20; + move32(); Pitch_CT = GENERIC; + move16(); } } - for ( i = 0; i < nb_subfr; i++ ) + FOR( i = 0; i < nb_subfr; i++ ) { - if ( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; + move16(); + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; + move16(); } - else + ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; + move16(); + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; + move16(); + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; + move16(); } } } - if ( coder_type == TRANSITION && ( tc_call == 1 && tc_subfr == 0 && L_frame == L_FRAME ) ) + test(); + test(); + test(); + IF( EQ_16( coder_type, TRANSITION ) && ( EQ_16( tc_call, 1 ) && tc_subfr == 0 && EQ_16( L_frame, L_FRAME ) ) ) { return error; } @@ -1348,70 +1576,101 @@ ivas_error config_acelp1( *-----------------------------------------------------------------*/ acelp_cfg->ubits = 0; /* these bits could be reused for something else */ + move16(); - if ( flag_hardcoded && core_brate != PPP_NELP_2k80 ) + test(); + IF( flag_hardcoded && NE_32( core_brate, PPP_NELP_2k80 ) ) { /* unused bits */ - if ( coder_type == AUDIO || ( coder_type == INACTIVE && core_brate <= ACELP_24k40 ) ) + IF( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_24k40 ) ) ) { acelp_cfg->ubits = 0; + move16(); } - else if ( L_frame == L_FRAME ) + ELSE IF( EQ_16( L_frame, L_FRAME ) ) { acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); } - else + ELSE { acelp_cfg->ubits = 0; + move16(); } - bits -= acelp_cfg->ubits; + bits = sub( bits, acelp_cfg->ubits ); } /* sanity check */ - if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || nb_subfr == NB_SUBFR16k ) + test(); + test(); + test(); + IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || EQ_16( nb_subfr, NB_SUBFR16k ) ) { - if ( ( L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) || ( GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) ) /* GSC Inactive @16kHz */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( L_frame, L_FRAME16k ) && coder_type == INACTIVE && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) || ( GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) ) /* GSC Inactive @16kHz */ { acelp_cfg->ubits = 0; + move16(); } - else if ( flag_hardcoded && core == ACELP_CORE && bits != 0 ) + ELSE IF( flag_hardcoded && core == ACELP_CORE && bits != 0 ) { #if defined DEBUGGING IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); #endif } - else if ( bits > 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) + ELSE IF( bits > 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) { - if ( idchan > 0 && element_mode == IVAS_CPE_TD ) + test(); + test(); + test(); + test(); + IF( idchan > 0 && EQ_16( element_mode, IVAS_CPE_TD ) ) { #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE - if ( !tdm_lp_reuse_flag ) + IF( !tdm_lp_reuse_flag ) { - acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ + acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ + move16(); bits = 0; + move16(); } - else + ELSE { Word16 nb_prm = 4; - if ( tdm_low_rate_mode == 1 ) + move16(); + if ( EQ_16( tdm_low_rate_mode, 1 ) ) { nb_prm = 2; + move16(); } /* First add remaining bits on gains */ - bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ); + bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ) ); /* Then, Increase pitch bit budget */ - if ( tdm_Pitch_reuse_flag == 0 && bits > 0 ) + test(); + IF( tdm_Pitch_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ); + bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ) ); } /* Increase mid-lsf bit budget */ - if ( tdm_lp_reuse_flag == 0 && bits > 0 ) + test(); + IF( tdm_lp_reuse_flag == 0 && bits > 0 ) { - bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ); - bits -= allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ); + bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ) ); + bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ) ); } } #else @@ -1449,27 +1708,34 @@ ivas_error config_acelp1( #endif } - else if ( core == ACELP_CORE && coder_type >= UNVOICED && coder_type <= GENERIC && L_frame == L_FRAME ) + ELSE IF( core == ACELP_CORE && GE_16( coder_type, UNVOICED ) && LE_16( coder_type, GENERIC ) && EQ_16( L_frame, L_FRAME ) ) { - acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ + acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ + move16(); - if ( acelp_cfg->lsf_bits > 46 ) + test(); + IF( GT_16( acelp_cfg->lsf_bits, 46 ) ) { - acelp_cfg->ubits = acelp_cfg->lsf_bits - 46; + acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 46 ); + move16(); acelp_cfg->lsf_bits = 46; + move16(); } - else if ( acelp_cfg->lsf_bits > 42 && L_frame == L_FRAME ) + ELSE IF( GT_16( acelp_cfg->lsf_bits, 42 ) && EQ_16( L_frame, L_FRAME ) ) { - acelp_cfg->ubits = acelp_cfg->lsf_bits - 42; + acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 42 ); + move16(); acelp_cfg->lsf_bits = 42; + move16(); } } - else + ELSE { acelp_cfg->ubits = bits; + move16(); } } - else if ( bits < 0 && !( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) ) + ELSE IF( bits < 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) { #if defined DEBUGGING IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); @@ -1496,75 +1762,92 @@ static Word16 allocate_unused( Word16 *prm_bit_mode ) { Word16 max_bit_per_pos = 0, bit_added = 0; + move16(); + move16(); // PMT("Not floating point computation, but fixed point operator are still missing ") - if ( prm_type == GAINSPRM ) + IF( prm_type == GAINSPRM ) { max_bit_per_pos = 6; - if ( core_brate > ACELP_8k00 ) + move16(); + IF( GT_32( core_brate, ACELP_8k00 ) ) { max_bit_per_pos = 7; + move16(); } - else if ( coder_type != UNVOICED ) + ELSE IF( NE_16( coder_type, UNVOICED ) ) { - if ( subfr >= 1 ) + IF( GE_16( subfr, 1 ) ) { max_bit_per_pos = 7; + move16(); } - else if ( subfr == 0 ) + ELSE IF( subfr == 0 ) { max_bit_per_pos = 8; + move16(); } } - else if ( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { max_bit_per_pos = 9; /* No real limit on UC gain bit budget of the secondary channel */ + move16(); } } - else if ( prm_type == PITCHPRM ) + ELSE IF( EQ_16( prm_type, PITCHPRM ) ) { max_bit_per_pos = 6; - if ( subfr == 0 || subfr == 2 || nb_prm == 2 ) + move16(); + test(); + test(); + if ( subfr == 0 || EQ_16( subfr, 2 ) || EQ_16( nb_prm, 2 ) ) { max_bit_per_pos = 10; + move16(); } - if ( coder_type == UNVOICED ) + if ( EQ_16( coder_type, UNVOICED ) ) { max_bit_per_pos = 0; /* Should not allocate bits in case of unvoiced coder type */ + move16(); } } - else if ( prm_type == MID_LSFSPRM ) + ELSE IF( EQ_16( prm_type, MID_LSFSPRM ) ) { max_bit_per_pos = 5; + move16(); } - else if ( prm_type == LSFPRM ) + ELSE IF( EQ_16( prm_type, LSFPRM ) ) { max_bit_per_pos = 42; + move16(); } - else + ELSE { #ifdef DEBUG_MODE_TD IVAS_ERROR( IVAS_ERR_WRONG_MODE, "unknown mode in bit_alloc.c" ); #endif } - max_bit_per_pos = s_min( unused_bits, max_bit_per_pos - prm_bit_mode[subfr] ); - if ( max_bit_per_pos < 0 ) + max_bit_per_pos = s_min( unused_bits, sub( max_bit_per_pos, prm_bit_mode[subfr] ) ); + test(); + IF( max_bit_per_pos < 0 ) { return 0; } - else if ( max_bit_per_pos >= 0 && subfr == ( nb_prm - 1 ) ) + ELSE IF( max_bit_per_pos >= 0 && EQ_16( subfr, sub( nb_prm, 1 ) ) ) { - prm_bit_mode[subfr] += max_bit_per_pos; + prm_bit_mode[subfr] = add( prm_bit_mode[subfr], max_bit_per_pos ); + move16(); } - else + ELSE { - prm_bit_mode[subfr] += max_bit_per_pos; - bit_added += allocate_unused( core_brate, coder_type, unused_bits - max_bit_per_pos, nb_prm, subfr + 1, prm_type, &prm_bit_mode[0] ); + prm_bit_mode[subfr] = add( prm_bit_mode[subfr], max_bit_per_pos ); + move16(); + bit_added = add( bit_added, allocate_unused( core_brate, coder_type, sub( unused_bits, max_bit_per_pos ), nb_prm, add( subfr, 1 ), prm_type, &prm_bit_mode[0] ) ); } - return bit_added + max_bit_per_pos; + return add( bit_added, max_bit_per_pos ); } @@ -1591,7 +1874,7 @@ Word16 set_ACELP_flag( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) { return 1; } @@ -1600,7 +1883,7 @@ Word16 set_ACELP_flag( test(); test(); test(); - IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) + IF( GE_32( element_brate, IVAS_24k4 ) && ( idchan == 0 ) && ( ( tdm_LRTD_flag == 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) { return 1; } @@ -1723,7 +2006,7 @@ Word16 set_ACELP_flag_IVAS( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) { return 1; } @@ -1732,7 +2015,7 @@ Word16 set_ACELP_flag_IVAS( test(); test(); test(); - IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) + IF( GE_32( element_brate, IVAS_24k4 ) && ( idchan == 0 ) && ( ( tdm_LRTD_flag == 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) { return 1; } diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 47c30f497f880bc601564fef35972664bfc5b90b..975dd32938cccef10c5145d6dad51c4c97eab6f6 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -159,6 +159,138 @@ Word16 rate2EVSmode_float( * Re-allocate the list of indices *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ind_list_realloc( + INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ + const Word16 max_num_indices, /* i : new maximum number of allowed indices in the list */ + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +) +{ + Word16 i, n, ch, n_channels, ind_list_pos, is_metadata, ivas_max_num_indices; + INDICE_HANDLE new_ind_list; + BSTR_ENC_HANDLE hBstr; + + IF( st_ivas == NULL ) + { + return IVAS_ERR_OK; + } + + /* get the pointer to the beginning of the old buffer of indices (either metadata or core coders) */ + IF( old_ind_list == st_ivas->ind_list_metadata ) + { + is_metadata = 1; + ivas_max_num_indices = st_ivas->ivas_max_num_indices_metadata; + } + ELSE + { + is_metadata = 0; + ivas_max_num_indices = st_ivas->ivas_max_num_indices; + } + move16(); + move16(); + + /* allocate new buffer of indices */ + IF( ( new_ind_list = (INDICE_HANDLE) malloc( max_num_indices * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); + } + + /* move indices from the old list to the new list */ + FOR( i = 0; i < s_min( max_num_indices, ivas_max_num_indices ); i++ ) + { + IF( GT_16( old_ind_list[i].nb_bits, -1 ) ) + { + new_ind_list[i].id = old_ind_list[i].id; + new_ind_list[i].value = old_ind_list[i].value; + move16(); + move16(); + } + new_ind_list[i].nb_bits = old_ind_list[i].nb_bits; + move16(); + } + + /* reset nb_bits of all other indices to -1 */ + FOR( ; i < max_num_indices; i++ ) + { + new_ind_list[i].nb_bits = -1; + move16(); + } + + /* update parameters in all SCE elements */ + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + /* get the pointer to hBstr */ + IF( is_metadata ) + { + hBstr = st_ivas->hSCE[n]->hMetaData; + } + ELSE + { + hBstr = st_ivas->hSCE[n]->hCoreCoder[0]->hBstr; + } + + IF( hBstr != NULL ) + { + /* get the current position inside the old list */ + ind_list_pos = (Word16) ( hBstr->ind_list - old_ind_list ); + + /* set pointers in the new list */ + *( hBstr->ivas_ind_list_zero ) = new_ind_list; + hBstr->ind_list = &new_ind_list[ind_list_pos]; + + /* set the new maximum number of indices */ + *( hBstr->ivas_max_num_indices ) = max_num_indices; + move16(); + } + } + + /* update parameters in all CPE elements */ + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + /* get the pointer to hBstr */ + IF( is_metadata ) + { + n_channels = 1; + } + ELSE + { + n_channels = CPE_CHANNELS; + } + move16(); + + FOR( ch = 0; ch < n_channels; ch++ ) + { + IF( is_metadata ) + { + hBstr = st_ivas->hCPE[n]->hMetaData; + } + ELSE + { + hBstr = st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr; + } + + IF( hBstr != NULL ) + { + /* get the current position inside the old list */ + ind_list_pos = (Word16) ( hBstr->ind_list - old_ind_list ); + + /* set pointers in the new list */ + *( hBstr->ivas_ind_list_zero ) = new_ind_list; + hBstr->ind_list = &new_ind_list[ind_list_pos]; + + /* set the new maximum number of indices */ + *( hBstr->ivas_max_num_indices ) = max_num_indices; + move16(); + } + } + } + + /* free the old list */ + free( old_ind_list ); + + return IVAS_ERR_OK; +} +#else ivas_error ind_list_realloc( INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */ @@ -280,6 +412,7 @@ ivas_error ind_list_realloc( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* @@ -1267,6 +1400,61 @@ void move_indices( * Check, if we will not overwrite an existing indice -> adjust the location *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error check_ind_list_limits( + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +) +{ + Indice *ivas_ind_list_zero, *ivas_ind_list_last; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + ivas_ind_list_zero = *( hBstr->ivas_ind_list_zero ); + + /* check, if the maximum number of indices has been reached and re-allocate the buffer */ + /* the re-allocation can be avoided by increasing the limits in get_ivas_max_num_indices() or get_ivas_max_num_indices_metadata() */ + IF( GE_16( (Word16) ( &hBstr->ind_list[hBstr->nb_ind_tot] - ivas_ind_list_zero ), *( hBstr->ivas_max_num_indices ) ) ) + { + + /* reallocate the buffer of indices with increased limit */ + IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* check, if we will not overwrite an existing indice */ + IF( hBstr->ind_list[hBstr->nb_ind_tot].nb_bits > 0 ) + { + IF( hBstr->nb_ind_tot == 0 ) + { + /* move the pointer to the next available empty slot */ + ivas_ind_list_last = &ivas_ind_list_zero[*( hBstr->ivas_max_num_indices )]; + WHILE( hBstr->ind_list[0].nb_bits > 0 && hBstr->ind_list < ivas_ind_list_last ) + { + hBstr->ind_list++; + } + + IF( hBstr->ind_list >= ivas_ind_list_last ) + { + + /* no available empty slot -> need to re-allocate the buffer */ + IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Buffer of indices corrupted in frame %d! Attempt to overwrite indice ID = %d (value: %d, bits: %d)!\n", hBstr->ind_list[hBstr->nb_ind_tot].id, hBstr->ind_list[hBstr->nb_ind_tot].value, hBstr->ind_list[hBstr->nb_ind_tot].nb_bits ); + } + } + + return error; +} +#else ivas_error check_ind_list_limits( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) @@ -1319,6 +1507,7 @@ ivas_error check_ind_list_limits( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1327,6 +1516,67 @@ ivas_error check_ind_list_limits( * Push a new indice into the buffer *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error push_indice( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ +) +{ + Word16 i; + Word16 j; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + /* check the limits of the list of indices */ + IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n" ); + } + + /* find the location in the list of indices based on ID */ + i = hBstr->nb_ind_tot; + move16(); + WHILE( i > 0 && LT_16( id, hBstr->ind_list[i - 1].id ) ) + { + i = sub( i, 1 ); + } + + /* shift indices, if the new ID is to be written somewhere inside the list */ + IF( i < hBstr->nb_ind_tot ) + { + FOR( j = hBstr->nb_ind_tot; j > i; j-- ) + { + hBstr->ind_list[j].id = hBstr->ind_list[j - 1].id; + hBstr->ind_list[j].nb_bits = hBstr->ind_list[j - 1].nb_bits; + hBstr->ind_list[j].value = hBstr->ind_list[j - 1].value; + move16(); + move16(); + move16(); + } + } + + + /* store the new indice in the list */ + hBstr->ind_list[i].id = id; + hBstr->ind_list[i].value = value; + hBstr->ind_list[i].nb_bits = nb_bits; + move16(); + move16(); + move16(); + + /* updates */ + hBstr->nb_ind_tot = add( hBstr->nb_ind_tot, 1 ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + move16(); + move16(); + + return error; +} +#else ivas_error push_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t id, /* i : ID of the indice */ @@ -1377,13 +1627,61 @@ ivas_error push_indice( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * push_next_indice() * * Push a new indice into the buffer at the next position *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error push_next_indice( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ +) +{ + Word16 prev_id; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + + /* check the limits of the list of indices */ + IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* get the id of the previous indice -> it will be re-used */ + IF( hBstr->nb_ind_tot > 0 ) + { + prev_id = hBstr->ind_list[hBstr->nb_ind_tot - 1].id; + } + ELSE + { + prev_id = 0; + } + move16(); + + /* store the values in the list */ + hBstr->ind_list[hBstr->nb_ind_tot].id = prev_id; + hBstr->ind_list[hBstr->nb_ind_tot].value = value; + hBstr->ind_list[hBstr->nb_ind_tot].nb_bits = nb_bits; + move16(); + move16(); + move16(); + + /* updates */ + hBstr->nb_ind_tot = add( hBstr->nb_ind_tot, 1 ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + move16(); + move16(); + return error; +} +#else ivas_error push_next_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ uint16_t value, /* i : value of the quantized indice */ @@ -1423,7 +1721,7 @@ ivas_error push_next_indice( return error; } - +#endif /*-------------------------------------------------------------------* * push_next_bits() @@ -1698,6 +1996,38 @@ uint16_t get_indice( *-------------------------------------------------------------------*/ /*! r: value of the indice */ +#ifdef IVAS_FLOAT_FIXED +UWord16 get_indice_st( + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 pos, /* i : absolute position in the bitstream */ + const Word16 nb_bits /* i : number of bits to quantize the indice */ +) +{ + UWord16 value; + Word16 i; + + assert( nb_bits <= 16 ); + + /* detect corrupted bitstream */ + IF( GT_32( L_deposit_l( add( pos, nb_bits ) ), Mpy_32_32( element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ) + { + st->BER_detect = 1; + move16(); + return ( 0 ); + } + + value = 0; + move16(); + FOR( i = 0; i < nb_bits; i++ ) + { + value = shl( value, 1 ); + value = add( value, st->bit_stream[add( pos, i )] ); + } + + return value; +} +#else uint16_t get_indice_st( Decoder_State *st, /* i/o: decoder state structure */ const int32_t element_brate, /* i : element bitrate */ @@ -1726,7 +2056,8 @@ uint16_t get_indice_st( return value; } - +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * get_indice_1() * @@ -1750,7 +2081,7 @@ uint16_t get_indice_1( return st->bit_stream[pos]; } - +#endif #define WMC_TOOL_SKIP /*-------------------------------------------------------------------* @@ -1782,15 +2113,24 @@ void reset_indices_enc( * * Reset the buffer of decoder indices *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void reset_indices_dec( Decoder_State *st ) { st->next_bit_pos = 0; + move16(); return; } +#else +void reset_indices_dec( + Decoder_State *st ) +{ + st->next_bit_pos = 0; + return; +} +#endif /*-------------------------------------------------------------------* * write_indices_to_stream() * @@ -2020,7 +2360,7 @@ ivas_error write_indices_ivas( return error; } - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * convertSerialToBytestream( ) * @@ -2069,7 +2409,7 @@ void convertBytestreamToSerial( serial[i] = ( bytestream[( i >> 3 )] >> ( 7 - ( i & 7 ) ) ) & 0x1; } } - +#endif /*-------------------------------------------------------------------* * decoder_selectCodec() * @@ -2804,7 +3144,7 @@ ivas_error read_indices( return error; } - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * get_rfFrameType() * @@ -3222,5 +3562,5 @@ void dtx_read_padding_bits( return; } - +#endif #undef WMC_TOOL_SKIP diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 2fca67ff96e8903562e2577c44308c18fe7eeabd..67f959a1de658954a0f3c4088ab3dfc2d58d0496 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -39,7 +39,7 @@ #include #include "options.h" #include "ivas_cnst.h" /* Common constants */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_com.h" @@ -121,18 +121,22 @@ static void pack_bit( UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ ) { - if ( *omask == 0x80 ) + if ( EQ_16( *omask, 0x80 ) ) { **pt = 0; + move16(); } - if ( bit != 0 ) + IF( bit != 0 ) { - **pt = **pt | *omask; + **pt = (UWord8) s_or( **pt, *omask ); + move16(); } - *omask >>= 1; - if ( *omask == 0 ) + *omask = (UWord8) shr( *omask, 1 ); + move16(); + IF( *omask == 0 ) { *omask = 0x80; + move16(); ( *pt )++; } @@ -151,11 +155,13 @@ static Word16 unpack_bit( { Word16 bit; - bit = ( **pt & *mask ) != 0; - *mask >>= 1; - if ( *mask == 0 ) + bit = s_and( **pt, *mask ) != 0; + *mask = (UWord8) shr( *mask, 1 ); + move16(); + IF( *mask == 0 ) { *mask = 0x80; + move16(); ( *pt )++; } return bit; @@ -212,6 +218,7 @@ Word16 rate2EVSmode( if ( is_amr_wb != NULL ) { *is_amr_wb = 0; + move16(); } switch ( brate ) { @@ -250,6 +257,7 @@ Word16 rate2EVSmode( if ( is_amr_wb != NULL ) { *is_amr_wb = 1; + move16(); } return rate2AMRWB_IOmode( brate ); } @@ -274,29 +282,32 @@ void push_indice_fx( { /* indice with the same name as the previous one */ i = hBstr->next_ind_fx; + move16(); } ELSE { /* new indice - find an empty slot in the list */ i = id; move16(); - WHILE( NE_16( hBstr->ind_list_fx[i].nb_bits, -1 ) ) + WHILE( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { i = add( i, 1 ); } } /* store the values in the list */ - hBstr->ind_list_fx[i].value = value; + hBstr->ind_list[i].value = value; move16(); - hBstr->ind_list_fx[i].nb_bits = nb_bits; + hBstr->ind_list[i].nb_bits = nb_bits; move16(); /* updates */ hBstr->next_ind_fx = add( i, 1 ); + move16(); hBstr->last_ind_fx = id; move16(); - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + move16(); return; } @@ -314,15 +325,16 @@ void push_next_indice_fx( { /* store the values in the list */ - hBstr->ind_list_fx[hBstr->next_ind_fx].value = value; + hBstr->ind_list[hBstr->next_ind_fx].value = value; move16(); - hBstr->ind_list_fx[hBstr->next_ind_fx].nb_bits = nb_bits; + hBstr->ind_list[hBstr->next_ind_fx].nb_bits = nb_bits; move16(); hBstr->next_ind_fx = add( hBstr->next_ind_fx, 1 ); - + move16(); /* update the total number of bits already written */ - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + move16(); return; } @@ -343,7 +355,7 @@ void push_next_bits_fx( Word16 i, nb_bits_m15; Indice *ptr; - ptr = &hBstr->ind_list_fx[hBstr->next_ind_fx]; + ptr = &hBstr->ind_list[hBstr->next_ind_fx]; nb_bits_m15 = sub( nb_bits, 15 ); i = 0; move16(); @@ -374,8 +386,10 @@ void push_next_bits_fx( ++ptr; } } - hBstr->next_ind_fx = (Word16) ( ptr - hBstr->ind_list_fx ); - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->next_ind_fx = (Word16) ( ptr - hBstr->ind_list ); + move16(); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + move16(); } /*-------------------------------------------------------------------* @@ -397,7 +411,7 @@ UWord16 get_next_indice_fx( /* o : value of the indice */ value = 0; move16(); - nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* detect corrupted bitstream */ IF( GT_16( add( st_fx->next_bit_pos, nb_bits ), nbits_total ) ) { @@ -409,11 +423,12 @@ UWord16 get_next_indice_fx( /* o : value of the indice */ FOR( i = 0; i < nb_bits; i++ ) { value = lshl( value, 1 ); - value = add( value, st_fx->bit_stream[st_fx->next_bit_pos + i] ); + value = add( value, st_fx->bit_stream[add( st_fx->next_bit_pos, i )] ); } /* update the position in the bitstream */ st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); + move16(); return value; } @@ -428,7 +443,7 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice * ) { Word16 nbits_total; - nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* detect corrupted bitstream */ test(); test(); @@ -458,6 +473,7 @@ void get_next_indice_tmp_fx( { /* update the position in the bitstream */ st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); + move16(); } /*-------------------------------------------------------------------* @@ -490,7 +506,7 @@ UWord16 get_indice_fx( /* o : value of the indice */ FOR( i = 0; i < nb_bits; i++ ) { value = lshl( value, 1 ); - value = add( value, st_fx->bit_stream[pos + i] ); + value = add( value, st_fx->bit_stream[add( pos, i )] ); } return value; @@ -508,7 +524,7 @@ UWord16 get_indice_1_fx( /* o : value of the indice */ ) { Word16 nbits_total; - nbits_total = (Word16) ( st_fx->total_brate / FRAMES_PER_SEC ); + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* detect corrupted bitstream */ IF( GT_16( add( pos, 1 ), nbits_total ) ) { @@ -532,7 +548,7 @@ void reset_indices_enc_fx( { Word16 i; - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; move16(); hBstr->next_ind_fx = 0; move16(); @@ -541,7 +557,7 @@ void reset_indices_enc_fx( FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -584,80 +600,89 @@ void write_indices_fx( Word32 mask; UWord8 header; Word16 isAmrWb = 0; + move16(); - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /*-----------------------------------------------------------------* * Encode Sync Header and Frame Length *-----------------------------------------------------------------*/ pt_stream = stream; - for ( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) + FOR( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) { stream[i] = 0; + move16(); } - *pt_stream++ = (Word16) SYNC_GOOD_FRAME; - *pt_stream++ = hBstr->nb_bits_tot_fx; + *pt_stream++ = SYNC_GOOD_FRAME; + move16(); + *pt_stream++ = hBstr->nb_bits_tot; + move16(); /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) * Writing the serial stream into file *----------------------------------------------------------------*/ - for ( i = 0; i < MAX_NUM_INDICES; i++ ) + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = L_shl( 1, sub( hBstr->ind_list[i].nb_bits, 1 ) ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list_fx[i].value & mask ) + IF( L_and( hBstr->ind_list[i].value, mask ) ) { *pt_stream++ = G192_BIN1; + move16(); } - else + ELSE { *pt_stream++ = G192_BIN0; + move16(); } - mask >>= 1; + mask = L_shr( mask, 1 ); } } } } - else + ELSE { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ) ); + header = (UWord8) ( s_or( s_or( shl( st_fx->Opt_AMR_WB, 5 ), shl( st_fx->Opt_AMR_WB, 4 ) ), rate2EVSmode( L_mult0( hBstr->nb_bits_tot, 50 ), &isAmrWb ) ) ); + move16(); fwrite( &header, sizeof( UWord8 ), 1, file ); /* Write speech bits */ - fwrite( pFrame, sizeof( UWord8 ), ( pFrame_size + 7 ) >> 3, file ); + fwrite( pFrame, sizeof( UWord8 ), shr( add( pFrame_size, 7 ), 3 ), file ); } /* Clearing of indices */ FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /* write the serial stream into file */ fwrite( stream, sizeof( unsigned short ), 2 + stream[1], file ); } /* reset index pointers */ - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; + move16(); hBstr->next_ind_fx = 0; + move16(); hBstr->last_ind_fx = -1; + move16(); return; } - /*-------------------------------------------------------------------* * write_indices_buf_fx() * @@ -689,8 +714,8 @@ void write_indices_buf_fx( stream[i] = 0; } //*pt_stream++ = (Word16) SYNC_GOOD_FRAME; - //*pt_stream++ = hBstr->nb_bits_tot_fx; - *num_bits = hBstr->nb_bits_tot_fx; + //*pt_stream++ = hBstr->nb_bits_tot; + *num_bits = hBstr->nb_bits_tot; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -698,15 +723,15 @@ void write_indices_buf_fx( *----------------------------------------------------------------*/ for ( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + if ( hBstr->ind_list[i].nb_bits != -1 ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list_fx[i].value & mask ) + if ( hBstr->ind_list[i].value & mask ) { //*pt_stream++ = G192_BIN1; *pt_stream++ = 1; @@ -726,7 +751,7 @@ void write_indices_buf_fx( { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ) ); + header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot * 50, &isAmrWb ) ); // fwrite(&header, sizeof(UWord8), 1, file); memcpy( out_buf, &header, sizeof( UWord8 ) ); *num_bits += sizeof( UWord8 ); @@ -739,7 +764,7 @@ void write_indices_buf_fx( /* Clearing of indices */ FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -755,13 +780,12 @@ void write_indices_buf_fx( //*num_bits += sizeof( unsigned short ) * ( 2 + stream[1] ); } /* reset index pointers */ - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; hBstr->next_ind_fx = 0; hBstr->last_ind_fx = -1; return; } - /*-------------------------------------------------------------------* * indices_to_serial() * @@ -782,65 +806,74 @@ void indices_to_serial( UWord8 omask = 0x80; UWord8 *pt_pFrame = pFrame; Word16 isAmrWb = 0; + move16(); + move16(); + move16(); + move16(); - if ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { cmi = rate2EVSmode( st_fx->total_brate, &isAmrWb ); - core_mode = rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ); + core_mode = rate2EVSmode( L_mult0( hBstr->nb_bits_tot, 50 ), &isAmrWb ); j = 0; - for ( i = 0; i < MAX_NUM_INDICES; i++ ) + move16(); + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = L_shl( 1, sub( hBstr->ind_list[i].nb_bits, 1 ) ); /* temporarily save bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - amrwb_bits[j++] = ( hBstr->ind_list_fx[i].value & mask ) > 0; - mask >>= 1; + amrwb_bits[j++] = L_and( hBstr->ind_list[i].value, mask ) > 0; + move16(); + mask = L_shr( mask, 1 ); } } } } - *pFrame_size = hBstr->nb_bits_tot_fx; + *pFrame_size = hBstr->nb_bits_tot; + move16(); /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) *----------------------------------------------------------------*/ j = 0; - for ( i = 0; i < MAX_NUM_INDICES; i++ ) + move16(); + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = L_shl( 1, sub( hBstr->ind_list[i].nb_bits, 1 ) ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( st_fx->Opt_AMR_WB ) + IF( st_fx->Opt_AMR_WB ) { pack_bit( amrwb_bits[sort_ptr[core_mode][j++]], &pt_pFrame, &omask ); } - else + ELSE { - pack_bit( hBstr->ind_list_fx[i].value & mask, &pt_pFrame, &omask ); - j++; + pack_bit( hBstr->ind_list[i].value & mask, &pt_pFrame, &omask ); + j = add( j, 1 ); } - mask >>= 1; + mask = L_shr( mask, 1 ); } } } - if ( st_fx->Opt_AMR_WB && core_mode == AMRWB_IO_SID ) /* SID UPD frame always written now .... */ + test(); + IF( st_fx->Opt_AMR_WB && EQ_16( core_mode, AMRWB_IO_SID ) ) /* SID UPD frame always written now .... */ { /* insert STI bit and CMI */ pack_bit( 1, &pt_pFrame, &omask ); - for ( mask = 0x08; mask > 0; mask >>= 1 ) + FOR( mask = 0x08; mask > 0; mask >>= 1 ) { pack_bit( cmi & mask, &pt_pFrame, &omask ); } @@ -869,7 +902,8 @@ void indices_to_serial_generic( nb_bits_tot = 0; move16(); - omask = ( 0x80 >> ( *pFrame_size & 0x7 ) ); + omask = (UWord8) shr( 0x80, s_and( *pFrame_size, 0x7 ) ); + move16(); pt_pFrame += shr( *pFrame_size, 3 ); /*----------------------------------------------------------------* @@ -877,27 +911,26 @@ void indices_to_serial_generic( *----------------------------------------------------------------*/ j = 0; move16(); - for ( i = 0; i < num_indices; i++ ) - { - if ( ind_list[i].nb_bits != -1 ) - { + FOR( i = 0; i < num_indices; i++ ){ + IF( NE_16( ind_list[i].nb_bits, -1 ) ){ /* mask from MSB to LSB */ - mask = 1 << ( ind_list[i].nb_bits - 1 ); + mask = L_shl( 1, sub( ind_list[i].nb_bits, 1 ) ); - /* write bit by bit */ - for ( k = 0; k < ind_list[i].nb_bits; k++ ) - { - pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask ); - j++; - mask >>= 1; - } - nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits ); - } + /* write bit by bit */ + FOR( k = 0; k < ind_list[i].nb_bits; k++ ) + { + pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask ); + j++; + mask = L_shr( mask, 1 ); } + nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits ); +} +} - *pFrame_size = add( *pFrame_size, nb_bits_tot ); +*pFrame_size = add( *pFrame_size, nb_bits_tot ); +move16(); - return; +return; } @@ -924,7 +957,7 @@ static void decoder_selectCodec( st->Opt_AMR_WB = 1; move16(); } - ELSE IF( NE_32( total_brate, FRAME_NO_DATA ) ) + ELSE IF( total_brate != FRAME_NO_DATA ) { st->Opt_AMR_WB = 0; move16(); @@ -1008,7 +1041,7 @@ static void decoder_selectCodec( IF( st->ini_frame == 0 ) { - IF( EQ_16( st->codec_mode, -1 ) ) + if ( EQ_16( st->codec_mode, -1 ) ) { st->codec_mode = MODE1; move16(); @@ -1020,7 +1053,7 @@ static void decoder_selectCodec( /* set SID/CNG type */ IF( EQ_32( total_brate, SID_2k40 ) ) { - IF( bit0 == G192_BIN0 ) + IF( EQ_16( bit0, G192_BIN0 ) ) { st->cng_type = LP_CNG; move16(); @@ -1032,6 +1065,7 @@ static void decoder_selectCodec( ELSE { st->cng_type = FD_CNG; + move16(); test(); if ( EQ_16( st->last_codec_mode, MODE2 ) && EQ_32( st->last_total_brate, 13200 ) ) { @@ -1040,6 +1074,7 @@ static void decoder_selectCodec( } } st->hTdCngDec->last_cng_type_fx = st->cng_type; /* CNG type switching at the first correctly received SID frame */ + move16(); } @@ -1058,7 +1093,7 @@ void dec_prm_core( Decoder_State *st ) st->core = -1; move16(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) + IF( st->total_brate == FRAME_NO_DATA ) { st->m_frame_type = ZERO_FRAME; move16(); @@ -1086,11 +1121,13 @@ void dec_prm_core( Decoder_State *st ) } /* Get bandwidth mode */ - st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + st->bwidth = get_next_indice_fx( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + move16(); st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); - if ( GT_16( st->bwidth, FB ) ) + IF( GT_16( st->bwidth, FB ) ) { st->bwidth = FB; move16(); @@ -1098,7 +1135,8 @@ void dec_prm_core( Decoder_State *st ) move16(); } - if ( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) + test(); + IF( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) { st->bwidth = SWB; move16(); @@ -1109,11 +1147,11 @@ void dec_prm_core( Decoder_State *st ) /* Skip reserved bit */ get_next_indice_tmp_fx( st, FrameSizeConfig[frame_size_index].reserved_bits ); - IF( get_next_indice_1( st ) != 0 ) /* TCX */ + IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ { st->core = TCX_20_CORE; move16(); - if ( get_next_indice_1( st ) != 0 ) + if ( get_next_indice_1_fx( st ) != 0 ) { st->core = HQ_CORE; move16(); @@ -1150,7 +1188,7 @@ void decision_matrix_core_dec( move16(); test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) { st->core = ACELP_CORE; move16(); @@ -1176,7 +1214,8 @@ void decision_matrix_core_dec( ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) { /* read the ACELP/HQ core selection bit */ - st->core = imult1616( get_next_indice( st, 1 ), HQ_CORE ); + st->core = imult1616( get_next_indice_fx( st, 1 ), HQ_CORE ); + move16(); } ELSE { @@ -1188,7 +1227,7 @@ void decision_matrix_core_dec( * Read ACELP signalling bits from the bitstream *-----------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; @@ -1206,8 +1245,9 @@ void decision_matrix_core_dec( start_idx = add( start_idx, 1 ); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add( start_idx, get_next_indice( st, nBits ) )]; + ind = acelp_sig_tbl[add( start_idx, get_next_indice_fx( st, nBits ) )]; st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); + move16(); /* convert signalling indice into signalling information */ if ( EQ_32( L_and( ind, 0x7 ), LR_MDCT ) ) @@ -1225,7 +1265,7 @@ void decision_matrix_core_dec( IF( EQ_16( st->core, HQ_CORE ) ) { /* read the HQ/TCX core switching flag */ - if ( get_next_indice( st, 1 ) != 0 ) + if ( get_next_indice_fx( st, 1 ) != 0 ) { st->core = TCX_20_CORE; move16(); @@ -1235,7 +1275,7 @@ void decision_matrix_core_dec( test(); IF( EQ_16( st->core, TCX_20_CORE ) && GT_32( st->total_brate, ACELP_16k40 ) ) { - ind = get_next_indice( st, 2 ); + ind = get_next_indice_fx( st, 2 ); IF( ind == 0 ) { @@ -1360,7 +1400,7 @@ static void mdct_switching_dec( /* Rewind bitstream */ st->next_bit_pos = next_bit_pos_save; move16(); - IF( st->bfi != 0 ) + if ( st->bfi != 0 ) { st->core = core_save; move16(); @@ -1418,6 +1458,7 @@ Word16 BRATE2IDX16k_fx( Word32 brate ) if ( EQ_32( brate, ACELP_16k40 ) ) { brate = ACELP_14k80; + move16(); } /* This is a Fast Bit Rate Value to Index Value Binary Search */ @@ -1449,8 +1490,8 @@ Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ) temp = BRATE2IDX_fx( brate ); L_temp = L_mac0( L_temp, 4 * 256, temp ); - if ( tc >= 0 ) - L_temp = L_mac0( L_temp, ( 10 - 4 ) * 256, temp ); + IF( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 10 - 4 ) * 256, temp ); /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ L_temp = L_mac0( L_temp, 1 * 256, s_max( 0, tc ) ); @@ -1480,8 +1521,8 @@ Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 t temp = BRATE2IDX16k_fx( brate ); L_temp = L_mac0( L_temp, 3, temp ); - if ( tc >= 0 ) - L_temp = L_mac0( L_temp, ( 7 - 3 ), temp ); + IF( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 7 - 3 ), temp ); /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ L_temp = L_mac0( L_temp, 1, s_max( 0, tc ) ); @@ -1521,25 +1562,29 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem Word16 num_bits_read; st->bfi = 0; + move16(); st->BER_detect = 0; + move16(); st->mdct_sw_enable = 0; + move16(); st->mdct_sw = 0; + move16(); reset_indices_dec_fx( st ); /* read the Sync Header field from the bitstream */ /* in case rew_flag is set, read until first good frame is encountered */ - do + DO { /* read the Sync header */ - if ( fread( &utmp, sizeof( unsigned short ), 1, file ) != 1 ) + IF( NE_32( fread( &utmp, sizeof( unsigned short ), 1, file ), 1 ) ) { - if ( ferror( file ) ) + IF( ferror( file ) ) { /* error during reading */ fprintf( stderr, "\nError reading the bitstream !" ); exit( -1 ); } - else + ELSE { /* end of file reached */ return 0; @@ -1547,39 +1592,39 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem } /* set the BFI indicator according the value of Sync Header */ - if ( EQ_16( utmp, SYNC_BAD_FRAME ) ) + IF( EQ_16( utmp, SYNC_BAD_FRAME ) ) { st->bfi = 1; + move16(); } - - - else + ELSE { st->bfi = 0; + move16(); } /* read the Frame Length field from the bitstream */ - if ( fread( &num_bits, sizeof( unsigned short ), 1, file ) != 1 ) + IF( NE_32( fread( &num_bits, sizeof( unsigned short ), 1, file ), 1 ) ) { - if ( ferror( file ) ) + IF( ferror( file ) ) { /* error during reading */ fprintf( stderr, "\nError reading the bitstream !" ); exit( -1 ); } - else + ELSE { /* end of file reached */ return 0; } } /* convert the frame length to total bitrate */ - total_brate = (long) ( num_bits * 50 ); + total_brate = L_mult0( num_bits, 50 ); /* read ITU-T G.192 serial stream of indices from file to the local buffer */ /* Validate that the G.192 length is within the defined bit rate range to not allow writing past the end of the "stream" buffer */ - if ( num_bits > MAX_BITS_PER_FRAME ) + IF( GT_16( num_bits, MAX_BITS_PER_FRAME ) ) { fprintf( stderr, "\nError, too large G.192 frame (size(%d))! Exiting ! \n", num_bits ); exit( -1 ); @@ -1587,7 +1632,7 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem /* verify that a valid num bits value is present in the G.192 file */ /* only AMRWB or EVS bit rates or 0(NO DATA) are allowed in G.192 file frame reading */ - if ( rate2EVSmode( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */ + IF( rate2EVSmode( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */ { fprintf( stderr, "\nError, illegal bit rate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); exit( -1 ); @@ -1595,63 +1640,77 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem pt_stream = stream; num_bits_read = (Word16) fread( pt_stream, sizeof( unsigned short ), num_bits, file ); + move16(); - if ( num_bits_read != num_bits ) + IF( NE_16( num_bits_read, num_bits ) ) { fprintf( stderr, "\nError, invalid number of bits read ! Exiting ! \n" ); exit( -1 ); } - - } while ( rew_flag && ( st->bfi || LT_32( total_brate, 2800 ) ) ); + test(); + } + WHILE( rew_flag && ( st->bfi || LT_32( total_brate, 2800 ) ) ); /* G.192 RX DTX handler*/ - if ( !rew_flag ) + IF( !rew_flag ) { /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */ /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */ curr_ft_good_sp = 0; + move16(); curr_ft_bad_sp = 0; + move16(); - if ( total_brate > SID_2k40 ) + IF( GT_32( total_brate, SID_2k40 ) ) { - if ( st->bfi == 0 ) + IF( st->bfi == 0 ) { curr_ft_good_sp = 1; + move16(); } - else + ELSE { curr_ft_bad_sp = 1; + move16(); } } sid_update = 0; + move16(); sid_upd_bad = 0; + move16(); - if ( total_brate == SID_1k75 || total_brate == SID_2k40 ) + test(); + IF( total_brate == SID_1k75 || total_brate == SID_2k40 ) { - if ( st->bfi == 0 ) + IF( st->bfi == 0 ) { sid_update = 1; + move16(); } - else + ELSE { sid_upd_bad = 1; /* may happen in CS , corrupt but detected sid frame */ + move16(); } } /* all zero indeces/bits iSP AMRWB SID_update results in a valid LP filter with extremely high LP-filter-gain */ /* all zero indeces/bits may be a result of CS bit errors and/or erroneously injected by gateways or by a bad dejitter handlers */ - if ( total_brate == SID_1k75 && sid_update == 1 ) + test(); + IF( EQ_32( total_brate, SID_1k75 ) && EQ_16( sid_update, 1 ) ) { /* valid sid_update received, check for very risky but formally valid content */ Word16 sum = 0; - for ( k = 0; k < num_bits; ++k ) + move16(); + FOR( k = 0; k < num_bits; ++k ) { - sum += ( pt_stream[k] == G192_BIN1 ); /* check of 35 zeroes, 35 ones */ + sum = add( sum, extract_l( EQ_16( pt_stream[k], G192_BIN1 ) ) ); /* check of 35 zeroes, 35 ones */ } if ( sum == 0 ) { /* all zeros */ sid_upd_bad = 1; /* initial signal as corrupt (BER likley) */ + move16(); } } @@ -1662,14 +1721,21 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . */ - if ( sid_upd_bad ) + IF( sid_upd_bad ) { sid_upd_bad = 0; + move16(); total_brate = FRAME_NO_DATA; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */ + move32(); } g192_sid_first = 0; - if ( st->core == AMR_WB_CORE && st->prev_ft_speech_fx && total_brate == FRAME_NO_DATA && st->bfi == 0 ) + move16(); + + test(); + test(); + test(); + if ( EQ_16( st->core, AMR_WB_CORE ) && st->prev_ft_speech_fx && total_brate == FRAME_NO_DATA && st->bfi == 0 ) { g192_sid_first = 1; /* SID_FIRST detected for previous AMRWB/AMRWBIO active frames only */ /* @@ -1678,43 +1744,58 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem and a good length 0 "SID_FIRST"(NO_DATA) frame is sent in AMRWBIO, , due to the one frame state memory in the AMRWB legacy G.192 SID_FIRST encoding */ + move16(); } speech_bad = 0; - if ( total_brate > SID_2k40 && st->bfi != 0 ) /* CS-type of CRC failure frame */ + move16(); + + test(); + if ( GT_32( total_brate, SID_2k40 ) && st->bfi != 0 ) /* CS-type of CRC failure frame */ { speech_bad = 1; /* initial assumption, CNG_state decides what to do */ + move16(); } speech_lost = 0; + move16(); + + test(); if ( total_brate == 0 && st->bfi != 0 ) /* unsent NO_DATA or stolen NO_DATA/signaling frame */ { speech_lost = 1; /* initial assumption, CNG_state decides what to do */ + move16(); } /* Do not allow decoder to enter CNG-synthesis for any instantly received GOOD+LENGTH==0 frame as this frame was never transmitted, one can not know it is good and has a a length of zero ) */ - if ( st->CNG_fx != 0 ) + IF( st->CNG_fx != 0 ) { /* We were in CNG synthesis */ if ( curr_ft_good_sp != 0 ) { /* only a good speech frame makes you leave CNG synthesis */ st->CNG_fx = 0; + move16(); } } - else + ELSE { /* We were in SPEECH synthesis */ /* only a received SID frame can make the decoder enter into CNG synthsis */ + test(); + test(); if ( g192_sid_first || sid_update || sid_upd_bad ) { st->CNG_fx = 1; + move16(); } } /* handle the g.192 _simulated_ untransmitted frame, setting for decoder SPEECH synthesis */ + test(); + test(); if ( ( st->CNG_fx == 0 ) && ( total_brate == 0 && st->bfi == 0 ) ) { st->bfi = 1; @@ -1723,14 +1804,21 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem } /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ + test(); + test(); + test(); if ( ( ( st->CNG_fx != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ ( sid_upd_bad != 0 ) ) /* SID_UPD_BAD --> start CNG */ { st->bfi = 0; + move16(); total_brate = 0; + move32(); } /* update for next frame's G.192 file format's SID_FIRST detection (primarily for AMRWBIO) */ + test(); st->prev_ft_speech_fx = ( ( curr_ft_good_sp != 0 ) || ( curr_ft_bad_sp != 0 ) ); + move16(); /* st->total brate= total_brate ; updated in a good frame below */ } /* rew_flag */ @@ -1739,7 +1827,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem #ifdef DEBUGGING st->bfi |= file_read_FECpattern(); #endif - if ( st->bfi == 0 && !rew_flag ) + test(); + IF( st->bfi == 0 && !rew_flag ) { /* select MODE1 or MODE2 */ decoder_selectCodec( st, total_brate, *pt_stream ); @@ -1747,10 +1836,11 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem Mpy_32_16_ss( total_brate, 5243, &L_tmp, &utmp ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->total_num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + move16(); /* in case rew_flag is set, rewind the file and return */ /* (used in io_enc() to print out info about technologies and to initialize the codec) */ - if ( rew_flag ) + IF( rew_flag ) { rewind( file ); st->total_brate = total_brate; @@ -1759,24 +1849,27 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem } /* GOOD frame */ - if ( st->bfi == 0 ) + IF( st->bfi == 0 ) { /* GOOD frame - convert ITU-T G.192 words to short values */ bit_stream_ptr = st->bit_stream; - for ( k = 0; k < num_bits; ++k ) + FOR( k = 0; k < num_bits; ++k ) { - *bit_stream_ptr++ = ( *pt_stream++ == G192_BIN1 ); + *bit_stream_ptr++ = (UWord16) EQ_32( *pt_stream++, G192_BIN1 ); + move16(); } /*add two zero bytes for arithmetic coder flush*/ - for ( k = 0; k < 2 * 8; ++k ) + FOR( k = 0; k < 2 * 8; ++k ) { *bit_stream_ptr++ = 0; + move16(); } /*a change of the total bitrate should not be known to the decoder, if the received frame was lost*/ st->total_brate = total_brate; + move32(); mdct_switching_dec( st ); } @@ -1815,87 +1908,115 @@ static Word32 read_indices_mime_handle_dtx( Word16 speech_bad = 0; Word16 sid_upd_bad = 0, sid_update = 0; Word16 amrwb_sid_first = 0; /* derived from sti SID_FIRST indicator in AMRWB payload */ + move16(); + move16(); + move16(); + move16(); + move16(); /* keep st->CNG , st_bfi and total_brate updated for proper synthesis in DTX and FER */ - if ( GT_32( total_brate, SID_2k40 ) ) + IF( GT_32( total_brate, SID_2k40 ) ) { - if ( st->bfi != 1 ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ + if ( NE_16( st->bfi, 1 ) ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ { curr_ft_good_sp = 1; + move16(); } } /* handle q_bit and lost_sp clash , assume worst case */ - if ( speech_lost != 0 ) /* overrides a good q_bit */ + IF( speech_lost != 0 ) /* overrides a good q_bit */ { curr_ft_good_sp = 0; + move16(); st->bfi = 1; /* override qbit */ + move16(); } /* now_bfi_fx has been set based on q_bit and ToC fields */ /* SID_UPDATE check */ - if ( total_brate == SID_1k75 || total_brate == SID_2k40 ) + test(); + IF( total_brate == SID_1k75 || total_brate == SID_2k40 ) { - if ( st->bfi == 0 ) + IF( st->bfi == 0 ) { /* typically from q bit */ sid_update = 1; + move16(); } - else + ELSE { sid_upd_bad = 1; /* may happen in saving from e.g. a CS-connection */ + move16(); } } - if ( isAMRWB_IOmode && total_brate == 0 && sti == 0 ) + test(); + test(); + IF( isAMRWB_IOmode && total_brate == 0 && sti == 0 ) { - if ( st->bfi ) + IF( st->bfi ) { sid_upd_bad = 1; /* corrupt sid_first, signaled as bad sid */ + move16(); } - else + ELSE { amrwb_sid_first = 1; /* 1-sti */ + move16(); } } - if ( sid_upd_bad != 0 && ( ( isAMRWB_IOmode != 0 && st->Opt_AMR_WB == 0 ) || /* switch to AMRWBIO */ - ( isAMRWB_IOmode != 1 && st->Opt_AMR_WB == 1 ) /* switch from AMRWBIO */ - ) ) + test(); + test(); + test(); + test(); + IF( sid_upd_bad != 0 && ( ( isAMRWB_IOmode != 0 && st->Opt_AMR_WB == 0 ) || /* switch to AMRWBIO */ + ( NE_16( isAMRWB_IOmode, 1 ) && EQ_16( st->Opt_AMR_WB, 1 ) ) /* switch from AMRWBIO */ + ) ) { /* do not allow a normal start of CNG synthesis if this SID(with BER or FER) is a switch to/from AMRWBIO */ sid_upd_bad = 0; /* revert this detection due to AMRWBIO/EVS mode switch */ + move16(); total_brate = 0; + move32(); no_data = 1; + move16(); assert( st->bfi == 1 ); /* bfi stays 1 */ } - if ( GT_32( total_brate, SID_2k40 ) && st->bfi == 1 ) /* typically from q bit */ + test(); + if ( GT_32( total_brate, SID_2k40 ) && EQ_16( st->bfi, 1 ) ) /* typically from q bit */ { speech_bad = 1; /* initial assumption, CNG synt state decides what to actually do */ + move16(); } /* all frame types decoded */ /* update CNG synthesis state */ /* Decoder can only enter CNG-synthesis for CNG frame types (sid_upd, sid_bad, sid_first) */ - if ( st->CNG_fx != 0 ) + IF( st->CNG_fx != 0 ) { /* We were in CNG synthesis */ if ( curr_ft_good_sp != 0 ) { /* only a good speech frame makes decoder leave CNG synthesis */ st->CNG_fx = 0; + move16(); } } - else + ELSE { /* We were in SPEECH synthesis */ /* only a received SID frame can make the decoder enter into CNG synthesis */ + test(); + test(); if ( amrwb_sid_first || sid_update || sid_upd_bad ) { st->CNG_fx = 1; + move16(); } } @@ -1903,20 +2024,28 @@ static Word32 read_indices_mime_handle_dtx( /* in SPEECH synthesis, make sure to activate speech plc for a received no_data frame, no_data frames may be injected by the network or by the dejitter buffer */ /* modify bfi_flag to stay/move into the correct decoder PLC section */ + test(); if ( ( st->CNG_fx == 0 ) && ( no_data != 0 ) ) { /* treat no_data received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ st->bfi = 1; + move16(); /* total_brate= 0; always zero for no_data */ } /* in CNG */ /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - if ( ( st->CNG_fx != 0 && ( speech_bad || speech_lost || no_data ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ + test(); + test(); + test(); + test(); + IF( ( st->CNG_fx != 0 && ( speech_bad || speech_lost || no_data ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ { - st->bfi = 0; /* mark as good to not start speech PLC */ + st->bfi = 0; /* mark as good to not start speech PLC */ + move16(); total_brate = 0; /* this zeroing needed for speech_bad, sid_bad frames */ + move32(); } @@ -1929,22 +2058,33 @@ static Word32 read_indices_mime_handle_dtx( /* handle available AMRWB/AMRWBIO MIME header ToC rate-info at startup */ - if ( ( st->bfi == 1 && st->ini_frame == 0 ) && - ( ( st->amrwb_rfc4867_flag != 0 ) || ( st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0 ) ) ) /*AMRWB ToC */ + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->bfi, 1 ) && st->ini_frame == 0 ) && + ( ( st->amrwb_rfc4867_flag != 0 ) || ( st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0 ) ) ) /*AMRWB ToC */ { Word32 init_rate; init_rate = total_brate; /* default , may have been modified from original ToC value */ - if ( speech_lost != 0 || no_data != 0 ) + move32(); + + test(); + IF( speech_lost != 0 || no_data != 0 ) { init_rate = ACELP_12k65; /* make sure the decoder starts up in a selected AMRWB mode */ + move32(); } - else if ( speech_bad != 0 ) + ELSE IF( speech_bad != 0 ) { init_rate = AMRWB_IOmode2rate[core_mode]; /* read from from ToC */ + move32(); } st->total_brate = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ + move32(); st->core_brate = init_rate; + move32(); } return total_brate; @@ -1964,27 +2104,31 @@ static void read_indices_mime_handle_sti_and_all_zero_bits( { Word16 k; - if ( sti == 0 ) + IF( sti == 0 ) { *total_brate = 0; /* signal received SID_FIRST as a good frame with no bits */ - for ( k = 0; k < 35; k++ ) + move32(); + FOR( k = 0; k < 35; k++ ) { - st->bfi |= st->bit_stream[k]; /* partity check of 35 zeroes, any single 1 gives BFI */ + st->bfi = s_or( st->bfi, st->bit_stream[k] ); /* partity check of 35 zeroes, any single 1 gives BFI */ + move16(); } } /* all zero bit SID_update results in a valid LP filter with extremely high LP-filter-gain */ /* all zero bits signal may be a result of CS bit errors or erronesouly injected by gateways or bad dejitter handlers */ - if ( sti == 1 ) + IF( EQ_16( sti, 1 ) ) { /*sid_update received */ Word16 sum = 0; - for ( k = 0; k < 35; k++ ) + move16(); + FOR( k = 0; k < 35; k++ ) { - sum += st->bit_stream[k]; /* check of 35 zeroes */ + sum = add( sum, st->bit_stream[k] ); /* check of 35 zeroes */ } if ( sum == 0 ) { st->bfi = 1; /* eventually becomes SID_UPD_BAD */ + move16(); } } } @@ -2015,22 +2159,31 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem Word16 speech_lost = 0, no_data = 0; Word16 num_bytes_read; + move16(); + move16(); + move16(); + move16(); + st->BER_detect = 0; + move16(); st->bfi = 0; + move16(); st->mdct_sw_enable = 0; + move16(); st->mdct_sw = 0; + move16(); reset_indices_dec_fx( st ); /* read the FT Header field from the bitstream */ - if ( fread( &header, sizeof( UWord8 ), 1, file ) != 1 ) + IF( NE_32( fread( &header, sizeof( UWord8 ), 1, file ), 1 ) ) { - if ( ferror( file ) ) + IF( ferror( file ) ) { /* error during reading */ fprintf( stderr, "\nError reading the bitstream !" ); exit( -1 ); } - else + ELSE { /* end of file reached */ return 0; @@ -2039,8 +2192,9 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem /* init local RXDTX flags */ sti = -1; + move16(); - if ( st->amrwb_rfc4867_flag != 0 ) + IF( st->amrwb_rfc4867_flag != 0 ) { /* RFC 4867 5.3 .... @@ -2054,12 +2208,16 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem Section 4.3.2. The P bits are padding and MUST be set to 0, and MUST be ignored. */ isAMRWB_IOmode = 1; - qbit = ( header >> 2 ) & 0x01; /* b2 bit (b7 is the F bit ) */ + move16(); + qbit = s_and( shr( header, 2 ), 0x01 ); /* b2 bit (b7 is the F bit ) */ + move16(); st->bfi = !qbit; - core_mode = ( ( header >> 3 ) & 0x0F ); /* b6..b3 */ - total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ + move16(); + core_mode = s_and( shr( header, 3 ), 0x0F ); /* b6..b3 */ + total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ + move32(); } - else + ELSE { /*0 1 2 3 4 5 6 7 MS-bit ---> LS-bit +-+-+-+-+-+-+-+-+ @@ -2071,40 +2229,47 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem x is the q-bit if E=1, q==1(good), Q==0(bad, maybe bit errors in payload ) H,F always 0 in RTP format. */ - isAMRWB_IOmode = ( header & 0x20 ) > 0; /* get EVS mode-from header */ /* b2 */ - core_mode = ( header & 0x0F ); /* b4,b5,b6,b7 */ + isAMRWB_IOmode = extract_l( GT_16( s_and( header, 0x20 ), 0 ) ); /* get EVS mode-from header */ /* b2 */ + core_mode = s_and( header, 0x0F ); /* b4,b5,b6,b7 */ - if ( isAMRWB_IOmode ) + IF( isAMRWB_IOmode ) { - qbit = ( header & 0x10 ) > 0; /* get Q bit, valid for IO rates */ /* b3 */ + qbit = extract_l( GT_16( s_and( header, 0x10 ), 0 ) ); /* get Q bit, valid for IO rates */ /* b3 */ total_brate = AMRWB_IOmode2rate[core_mode]; + move32(); } - else + ELSE { qbit = 1; /* assume good q_bit for the unused EVS-mode bit, complete ToC validity checked later */ + move16(); total_brate = PRIMARYmode2rate[core_mode]; + move32(); } st->bfi = !qbit; + move16(); } /* set up RX-DTX-handler input */ - if ( core_mode == 14 ) + if ( EQ_16( core_mode, 14 ) ) { /* SP_LOST */ speech_lost = 1; + move16(); } - if ( core_mode == 15 ) + if ( EQ_16( core_mode, 15 ) ) { /* NO_DATA unsent CNG frame OR any frame marked or injected as no_data by e.g a signaling layer or dejitter buffer */ no_data = 1; + move16(); } Mpy_32_16_ss( total_brate, 5243, &L_tmp, &utmp ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ st->total_num_bits = num_bits; + move16(); - if ( total_brate < 0 ) + IF( total_brate < 0 ) { /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ fprintf( stderr, "\n Error. Illegal total bit rate (= %d) in MIME ToC header \n", total_brate ); @@ -2112,26 +2277,33 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem } /* Check correctness of ToC headers */ - if ( st->amrwb_rfc4867_flag == 0 ) + IF( st->amrwb_rfc4867_flag == 0 ) { /* EVS ToC header (FT field(b2-b7), H bit (b0), F bit (b1) , (EVS-modebit(b2)=0 unused(Qbit)(b3)==0) */ - if ( ( isAMRWB_IOmode == 0 ) && ( ( num_bits < 0 ) || ( ( header & 0x80 ) > 0 ) || ( ( header & 0x40 ) > 0 ) || ( header & 0x30 ) != 0x00 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( isAMRWB_IOmode == 0 ) && ( ( num_bits < 0 ) || ( s_and( header, 0x80 ) > 0 ) || ( s_and( header, 0x40 ) > 0 ) || s_and( header, 0x30 ) != 0x00 ) ) { /* incorrect FT header */ fprintf( stderr, "\nError in EVS FT ToC header(%02x) ! ", header ); exit( -1 ); } - else if ( ( isAMRWB_IOmode != 0 ) && ( ( num_bits < 0 ) || ( ( header & 0x80 ) > 0 ) || ( ( header & 0x40 ) > 0 ) ) ) /* AMRWBIO */ + ELSE IF( ( isAMRWB_IOmode != 0 ) && ( ( num_bits < 0 ) || ( s_and( header, 0x80 ) > 0 ) || ( s_and( header, 0x40 ) > 0 ) ) ) /* AMRWBIO */ { /* incorrect IO FT header */ fprintf( stderr, "\nError in EVS(AMRWBIO) FT ToC header(%02x) ! ", header ); exit( -1 ); } } - else + ELSE { /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ - if ( num_bits < 0 ) + IF( num_bits < 0 ) { /* incorrect FT header */ fprintf( stderr, "\nError in AMRWB RFC4867 Toc(FT) header(%02x) !", header ); @@ -2140,8 +2312,8 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem } /* read serial stream of indices from file to the local buffer */ - num_bytes_read = (Word16) fread( pFrame, sizeof( UWord8 ), ( num_bits + 7 ) >> 3, file ); - if ( num_bytes_read != ( num_bits + 7 ) >> 3 ) + num_bytes_read = extract_l( fread( pFrame, sizeof( UWord8 ), shr( add( num_bits, 7 ), 3 ), file ) ); + IF( NE_16( num_bytes_read, shr( add( num_bits, 7 ), 3 ) ) ) { fprintf( stderr, "\nError, invalid number of bytes read ! Exiting ! \n" ); exit( -1 ); @@ -2149,10 +2321,13 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem /* in case rew_flag is set, rewind the file and return */ /* (used in io_dec() to attempt print out info about technologies and to initialize the codec ) */ - if ( rew_flag ) + IF( rew_flag ) { st->total_brate = total_brate; /* used for the codec banner output */ - if ( st->bfi == 0 && speech_lost == 0 && no_data == 0 ) + move32(); + test(); + test(); + IF( st->bfi == 0 && speech_lost == 0 && no_data == 0 ) { decoder_selectCodec( st, total_brate, unpack_bit( &pt_pFrame, &mask ) ? G192_BIN1 : G192_BIN0 ); } @@ -2162,51 +2337,56 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem /* unpack speech data */ bit_stream_ptr = st->bit_stream; - for ( k = 0; k < num_bits; k++ ) + FOR( k = 0; k < num_bits; k++ ) { - if ( isAMRWB_IOmode ) + IF( isAMRWB_IOmode ) { st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_pFrame, &mask ); + move16(); bit_stream_ptr++; } - else + ELSE { *bit_stream_ptr++ = unpack_bit( &pt_pFrame, &mask ); + move16(); } } /* unpack auxiliary bits */ /* Note: the cmi bits are unpacked for demo purposes; */ - if ( isAMRWB_IOmode && total_brate == SID_1k75 ) + test(); + IF( isAMRWB_IOmode && EQ_32( total_brate, SID_1k75 ) ) { sti = unpack_bit( &pt_pFrame, &mask ); - cmi = unpack_bit( &pt_pFrame, &mask ) << 3; - cmi |= unpack_bit( &pt_pFrame, &mask ) << 2; - cmi |= unpack_bit( &pt_pFrame, &mask ) << 1; - cmi |= unpack_bit( &pt_pFrame, &mask ); + cmi = shl( unpack_bit( &pt_pFrame, &mask ), 3 ); + cmi = s_or( cmi, shl( unpack_bit( &pt_pFrame, &mask ), 2 ) ); + cmi = s_or( cmi, shl( unpack_bit( &pt_pFrame, &mask ), 1 ) ); + cmi = s_or( cmi, unpack_bit( &pt_pFrame, &mask ) ); read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); } /*add two zero bytes for arithmetic coder flush*/ - for ( k = 0; k < 2 * 8; ++k ) + FOR( k = 0; k < 2 * 8; ++k ) { *bit_stream_ptr++ = 0; + move16(); } /* MIME RX_DTX handler */ - if ( !rew_flag ) + IF( !rew_flag ) { total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); } - if ( st->bfi == 0 ) + IF( st->bfi == 0 ) { /* select MODE1 or MODE2 in MIME */ decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ st->total_brate = total_brate; + move32(); mdct_switching_dec( st ); } /* else{ bfi stay in past synthesis mode(SP,CNG) } */ @@ -2226,7 +2406,9 @@ static void berCheck( ) { /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ - if ( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) + test(); + test(); + IF( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) { if ( EQ_16( st->use_partial_copy, 1 ) ) { @@ -2271,13 +2453,17 @@ void getPartialCopyInfo( /* reset number of target bits in case of rate switching */ st->rf_target_bits = 0; + move16(); /* Get the number of bits used for RF*/ IF( EQ_16( st->rf_flag, 1 ) ) { *coder_type = s_and( ind, 0x7 ); + move16(); st->bwidth = s_and( shr( ind, 3 ), 0x7 ); + move16(); *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); + move16(); st->codec_mode = MODE2; move16(); get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); @@ -2285,17 +2471,22 @@ void getPartialCopyInfo( IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) { st->use_partial_copy = 1; + move16(); /* now set the frame mode to normal mode */ test(); IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) { st->bfi = 1; + move16(); st->core = 1; + move16(); } ELSE { st->bfi = FRAMEMODE_NORMAL; + move16(); st->core = 0; + move16(); } } /* check for bit errors */ @@ -2322,14 +2513,16 @@ void get_rfFlag( /* Init */ *rf_flag = 0; + move16(); /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ test(); test(); - IF( EQ_32( st->total_brate, ACELP_13k20 ) && ( EQ_16( st->bfi, FRAMEMODE_NORMAL ) || EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) ) + IF( EQ_32( st->total_brate, ACELP_13k20 ) && ( ( st->bfi == FRAMEMODE_NORMAL ) || EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; + move16(); WHILE( NE_32( acelp_sig_tbl[start_idx], st->total_brate ) ) { start_idx++; @@ -2341,21 +2534,26 @@ void get_rfFlag( /* retrieve the number of bits */ nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + move16(); /* retrieve the signalling indice */ - ind_tmp = (Word16) acelp_sig_tbl[start_idx + get_indice( st, 0, nBits_tmp )]; + ind_tmp = (Word16) acelp_sig_tbl[add( start_idx, get_indice( st, 0, nBits_tmp ) )]; + move16(); /* convert signalling indice into RF flag. */ *rf_flag = s_and( shr( ind_tmp, 7 ), 0x1 ); + move16(); if ( ind ) { *ind = ind_tmp; + move16(); } if ( nBits ) { *nBits = nBits_tmp; + move16(); } } } @@ -2372,16 +2570,17 @@ void get_rfFrameType( ) { Word16 num_bits = 0; + move16(); IF( EQ_16( st->rf_flag, 1 ) ) { /*num_bits = st->total_brate/50;*/ - if ( EQ_32( st->total_brate, ACELP_13k20 ) ) + IF( EQ_32( st->total_brate, ACELP_13k20 ) ) { num_bits = 264; move16(); /* @13.2kbps */ } - else + ELSE { UWord16 lsb; Word32 L_tmp; @@ -2390,11 +2589,13 @@ void get_rfFrameType( } /* the last three bits in a packet is the RF frame type */ - *rf_frame_type = get_indice( st, num_bits - 3, 3 ); + *rf_frame_type = get_indice( st, sub( num_bits, 3 ), 3 ); + move16(); } ELSE { *rf_frame_type = 0; + move16(); } } @@ -2414,12 +2615,12 @@ void get_rf_fec_offset( IF( EQ_16( st->rf_flag, 1 ) ) { /*num_bits = st->total_brate/50;*/ - if ( EQ_32( st->total_brate, ACELP_13k20 ) ) + IF( EQ_32( st->total_brate, ACELP_13k20 ) ) { num_bits = 264; move16(); /* @13.2kbps */ } - else + ELSE { UWord16 lsb; Word32 L_tmp; @@ -2428,16 +2629,17 @@ void get_rf_fec_offset( } /* the two bits before the rf frame type contain the fec offset */ - tmp = get_indice( st, num_bits - 5, 2 ); + tmp = get_indice( st, sub( num_bits, 5 ), 2 ); - if ( tmp == 0 ) + IF( tmp == 0 ) { *rf_fec_offset = 2; move16(); } - else + ELSE { *rf_fec_offset = add( shl( tmp, 1 ), 1 ); + move16(); } } ELSE @@ -2465,31 +2667,39 @@ void get_rfTargetBits( { case RF_NO_DATA: *rf_target_bits = 5; + move16(); BREAK; case RF_TCXFD: *rf_target_bits = 27; + move16(); BREAK; case RF_TCXTD1: *rf_target_bits = 16; + move16(); BREAK; case RF_TCXTD2: *rf_target_bits = 16; + move16(); BREAK; case RF_ALLPRED: /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ *rf_target_bits = 63; + move16(); BREAK; case RF_NOPRED: /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ *rf_target_bits = 66; + move16(); BREAK; case RF_GENPRED: /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ *rf_target_bits = 70; + move16(); BREAK; case RF_NELP: /* gain: 19, Diff GFr: 5 */ *rf_target_bits = 45; + move16(); BREAK; } } @@ -2515,9 +2725,11 @@ void get_NextCoderType_fx( FOR( k = 0; k < ACELP_13k20 / 50; k++ ) { - bit_stream[k] = ( bitsteam[k / 8] >> ( 7 - ( k % 8 ) ) ) & 0x1; + bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, ( k % 8 ) ) ), 0x1 ); + move16(); } start_idx = 0; + move16(); WHILE( NE_32( acelp_sig_tbl[start_idx], ACELP_13k20 ) ) { start_idx = add( start_idx, 1 ); @@ -2530,13 +2742,15 @@ void get_NextCoderType_fx( tmp = 0; move16(); nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + move16(); FOR( k = 0; k < nBits_tmp; k++ ) { tmp = lshl( tmp, 1 ); tmp = add( tmp, bit_stream[k] ); } /* retrieve the signalling indice */ - *next_coder_type = s_and( (Word16) acelp_sig_tbl[start_idx + tmp], 0x7 ); + *next_coder_type = s_and( (Word16) acelp_sig_tbl[add( start_idx, tmp )], 0x7 ); + move16(); } /*-------------------------------------------------------------------* @@ -2564,84 +2778,110 @@ void read_indices_from_djb_fx( Word32 total_brate; Word16 speech_lost = 0; + move16(); + move16(); + move16(); + move16(); + st->bfi = 0; + move16(); st->BER_detect = 0; + move16(); st->mdct_sw_enable = 0; + move16(); st->mdct_sw = 0; + move16(); reset_indices_dec_fx( st ); st->bfi = !qbit; - total_brate = (Word32) (num_bits) *50; + move16(); + total_brate = L_mult0( num_bits, 50 ); st->total_num_bits = num_bits; + move16(); - if ( num_bits == 0 ) /* guess type of missing frame for SP_LOST and NO_DATA */ + IF( num_bits == 0 ) /* guess type of missing frame for SP_LOST and NO_DATA */ { speech_lost = st->CNG_fx == 0; + move16(); + move16(); no_data = st->CNG_fx != 0; + move16(); + move16(); } - if ( partialframe || st->prev_use_partial_copy ) + test(); + IF( partialframe || st->prev_use_partial_copy ) { st->next_coder_type = next_coder_type; + move16(); } - else + ELSE { st->next_coder_type = INACTIVE; + move16(); } - if ( partialframe == 1 ) + if ( EQ_16( partialframe, 1 ) ) { st->bfi = 2; + move16(); } /* unpack speech data */ bit_stream_ptr = st->bit_stream; /* convert bitstream from compact bytes to short values and store it in decoder state */ - for ( k = 0; k < num_bits; k++ ) + FOR( k = 0; k < num_bits; k++ ) { - if ( st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode ) + test(); + IF( st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode ) { st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_stream, &mask ); + move16(); bit_stream_ptr++; } - else + ELSE { *bit_stream_ptr++ = unpack_bit( &pt_stream, &mask ); + move16(); } } /* unpack auxiliary bits */ - if ( isAMRWB_IOmode && total_brate == SID_1k75 ) + test(); + IF( isAMRWB_IOmode && EQ_32( total_brate, SID_1k75 ) ) { - if ( st->bitstreamformat == VOIP_RTPDUMP ) + IF( EQ_16( st->bitstreamformat, VOIP_RTPDUMP ) ) { /* A.2.2.1.3: AMR-WB SID_1k75 frame is followed by STI bit and CMI bits */ sti = unpack_bit( &pt_stream, &mask ); } - else + ELSE { /* VOIP_G192_RTP does not contain STI and CMI */ sti = 1; + move16(); } read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); } /* add two zero bytes for arithmetic coder flush */ - for ( k = 0; k < 8 * 2; ++k ) + FOR( k = 0; k < 8 * 2; ++k ) { *bit_stream_ptr++ = 0; + move16(); } total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); /* st->CNG_fx set inside */ - if ( st->bfi != 1 ) + IF( NE_16( st->bfi, 1 ) ) { /* select Mode 1 or Mode 2 */ decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ st->total_brate = total_brate; + move32(); mdct_switching_dec( st ); } @@ -2668,15 +2908,17 @@ static UWord16 get_indice_preview( bitstreamShortPtr = bitstreamShort; FOR( i = 0; i < bitstreamSize; i++ ) { - *bitstreamShortPtr++ = ( bitstream[i / 8] >> ( 7 - ( i % 8 ) ) ) & 0x1; + *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( i % 8 ) ) ), 0x1 ); + move16(); } assert( nb_bits <= 16 ); value = 0; + move16(); FOR( i = 0; i < nb_bits; i++ ) { value = shl( value, 1 ); - value = add( value, bitstreamShort[pos + i] ); + value = add( value, bitstreamShort[add( pos, i )] ); } return value; } @@ -2698,14 +2940,18 @@ void evs_dec_previewFrame( Word16 rf_flag; rf_flag = 0; + move16(); *partialCopyFrameType = 0; + move16(); *partialCopyOffset = 0; - total_brate = bitstreamSize * 50; + move16(); + total_brate = L_mult0( bitstreamSize, 50 ); IF( EQ_32( total_brate, ACELP_13k20 ) ) { /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; + move16(); WHILE( NE_32( acelp_sig_tbl[start_idx], total_brate ) ) { start_idx = add( start_idx, 1 ); @@ -2716,9 +2962,11 @@ void evs_dec_previewFrame( start_idx = add( start_idx, 1 ); /* retrieve the number of bits */ nBits = (Word16) acelp_sig_tbl[start_idx++]; + move16(); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits )]; + ind = acelp_sig_tbl[add( start_idx, get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; + move32(); /* convert signalling indice into RF flag. */ rf_flag = s_and( extract_l( L_shr( ind, 7 ) ), 0x1 ); @@ -2726,14 +2974,15 @@ void evs_dec_previewFrame( IF( rf_flag != 0 ) { /* read the fec offset at which the partial copy is received */ - ind = get_indice_preview( bitstream, bitstreamSize, ( bitstreamSize - 5 ), 2 ); + ind = get_indice_preview( bitstream, bitstreamSize, sub( bitstreamSize, 5 ), 2 ); IF( ind == 0 ) *partialCopyOffset = 2; ELSE IF( EQ_32( ind, 1 ) ) *partialCopyOffset = 3; ELSE IF( EQ_32( ind, 2 ) ) *partialCopyOffset = 5; ELSE IF( EQ_32( ind, 3 ) ) *partialCopyOffset = 7; - + move16(); /* the last three bits in a packet is the RF frame type */ *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); + move16(); } } } @@ -2748,6 +2997,7 @@ void dtx_read_padding_bits_fx( tmp = st->total_brate; move32(); st->total_brate = L_add( st->total_brate, L_mult0( num_bits, FRAMES_PER_SEC ) ); + move32(); get_next_indice_fx( st, num_bits ); st->total_brate = tmp; move32(); diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index d8dec57d6e2b008080f310d4a5ca32814ed7af75..fcd9e06e4a237f67e8560474738803ff8d44b8b1 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* */ /* * E_GAIN_f_pitch_sharpening @@ -29,7 +28,7 @@ static void E_GAIN_f_pitch_sharpening( Word16 *x, Word16 pit_lag, Word16 L_subfr FOR( i = pit_lag; i < L_subfr; i++ ) { /*x[i] += x[i - pit_lag] * F_PIT_SHARP;*/ - tmp = mult_r( x[i - pit_lag], 27853 /*F_PIT_SHARP Q15*/ ); + tmp = mult_r( x[sub( i, pit_lag )], 27853 /*F_PIT_SHARP Q15*/ ); x[i] = add( x[i], tmp ); move16(); } @@ -101,7 +100,7 @@ void cb_shape_fx( { weight_a_fx( p_Aq, A_num, g1, M ); weight_a_fx( p_Aq, A_den, g2, M ); - set16_fx( buff, 0, M + L_subfr ); + set16_fx( buff, 0, add( M, L_subfr ) ); IF( formantTiltFlag ) { Copy( A_num, buff + M, M + 1 ); @@ -109,7 +108,7 @@ void cb_shape_fx( E_UTIL_synthesis( 1, A_den, buff + M, buff + M, L_subfr, buff, 0, M ); /*Compute tilt of formant enhancement*/ - tilt = extract_l( L_shr( get_gain( buff + M + 1, buff + M, L_subfr - 1 ), 1 ) ); + tilt = extract_l( L_shr( get_gain( buff + M + 1, buff + M, sub( L_subfr, 1 ) ), 1 ) ); /*Combine tilt of code and fe*/ tmp = 0; diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index b2022f7252d456ba6c4668c0138bdf8cf9744419..e81ab78ec78cfad53252bc9594f31ddfb953b0b5 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -40,11 +40,10 @@ #include #include "stat_dec.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "rom_com_fx.h" #include "wmc_auto.h" -#include "prot_fx2.h" #if __STDC_VERSION__ >= 199901L #if defined __ICL #define restrict __restrict @@ -60,6 +59,8 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs ); + static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc ); /*-------------------------------------------------------------------* @@ -270,6 +271,7 @@ void cldfbAnalysis_ivas_fx( Word16 i, k; Word16 L2, M1, M2, M4; Word16 no_col = h_cldfb->no_col; + move16(); Word32 r1_fx, r2_fx, rr12_fx, ir12_fx; Word32 i1_fx, i2_fx, ri12_fx, ii12_fx; @@ -293,7 +295,7 @@ void cldfbAnalysis_ivas_fx( IF( GT_16( samplesToProcess, -1 ) ) { Copy32( timeIn_fx, timeBuffer_fx + offset, samplesToProcess ); - set32_fx( timeBuffer_fx + offset + samplesToProcess, 0, sub( frameSize, samplesToProcess ) ); + set32_fx( timeBuffer_fx + add( offset, samplesToProcess ), 0, sub( frameSize, samplesToProcess ) ); } ELSE { @@ -307,11 +309,12 @@ void cldfbAnalysis_ivas_fx( } M1 = h_cldfb->no_channels; + move16(); M2 = shr( M1, 1 ); M4 = shr( M1, 2 ); L2 = shl( M1, 1 ); - IF( M2 & 1 ) + if ( s_and( M2, 1 ) ) { M4 = add( M4, 1 ); } @@ -328,29 +331,29 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // Qx - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ) ); // Qx - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // Qx - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -361,47 +364,47 @@ void cldfbAnalysis_ivas_fx( rr12_fx = L_sub( r1_fx, r2_fx ); // Qx - 1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // Qx - 1 // cplxMult( &rBuffer_fx[2 * k], &rBuffer_fx[2 * k + 1], rr12_fx, ri12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // Qx - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // Qx - 3 + rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ ir12_fx = L_add( r1_fx, r2_fx ); // Qx - 1 ii12_fx = L_sub( i1_fx, i2_fx ); // Qx - 1 // cplxMult( &iBuffer_fx[2 * k], &iBuffer_fx[2 * k + 1], ir12_fx, ii12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // Qx - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // Qx - 3 + iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // Qx - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // Qx - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // Qx - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // Qx - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // Qx - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // Qx - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // Qx - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -412,18 +415,18 @@ void cldfbAnalysis_ivas_fx( rr12_fx = L_add( r1_fx, r2_fx ); // Qx - 1 ri12_fx = L_sub( i1_fx, i2_fx ); // Qx - 1 // cplxMult( &rBuffer_fx[2 * k], &rBuffer[2 * k + 1], rr12, ri12, rot_vctr_re[k], rot_vctr_im[k] ); - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // Qx - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // Qx - 3 + rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ ir12_fx = L_sub( r1_fx, r2_fx ); // Qx - 1 ii12_fx = L_add( i1_fx, i2_fx ); // Qx - 1 // cplxMult( &iBuffer[2 * k], &iBuffer[2 * k + 1], ir12, ii12, rot_vctr_re[k], rot_vctr_im[k] ); - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // Qx - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // Qx - 3 + iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } @@ -435,9 +438,9 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M2; k++ ) { // cplxMult( &realBuffer[i][M1 - 1 - ( 2 * k )], &realBuffer[i][2 * k], rBuffer[2 * k], rBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - realBuffer_fx[i][M1 - 1 - ( 2 * k )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // Qx - 5 + realBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // Qx - 5 move32(); - realBuffer_fx[i][2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // Qx - 5 + realBuffer_fx[i][2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } @@ -450,14 +453,14 @@ void cldfbAnalysis_ivas_fx( { /* do it inplace */ // cplxMult( &imagBuffer[i][2 * k], &imagBuffer[i][M1 - 1 - ( 2 * k )], iBuffer[2 * k], iBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - imagBuffer_fx[i][2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // QX - 5 + imagBuffer_fx[i][2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // QX - 5 move32(); - imagBuffer_fx[i][M1 - 1 - ( 2 * k )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // Qx - 5 + imagBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } - timeBuffer_fx += L2 * 5; - timeBuffer_fx += h_cldfb->no_channels - h_cldfb->p_filter_length; + timeBuffer_fx += i_mult( L2, 5 ); + timeBuffer_fx += sub( h_cldfb->no_channels, h_cldfb->p_filter_length ); } /* update memory */ @@ -702,6 +705,7 @@ void cldfbAnalysis_ts_fx( Word16 i, k; Word16 L2, M1, M2, M4; Word16 no_col = h_cldfb->no_col; + move16(); Word32 r1_fx, r2_fx, rr12_fx, ir12_fx; Word32 i1_fx, i2_fx, ri12_fx, ii12_fx; @@ -716,40 +720,45 @@ void cldfbAnalysis_ts_fx( Word32 *timeBuffer_fx, buffer_fx[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )]; Word16 offset, frameSize; - offset = h_cldfb->p_filter_length - h_cldfb->no_channels; - frameSize = h_cldfb->no_channels * h_cldfb->no_col; + offset = sub( h_cldfb->p_filter_length, h_cldfb->no_channels ); + frameSize = i_mult( h_cldfb->no_channels, h_cldfb->no_col ); /* prepare input buffer */ timeBuffer_fx = buffer_fx; Copy32( h_cldfb->cldfb_state_fx, timeBuffer_fx, offset ); - if ( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { Copy32( timeIn_fx, timeBuffer_fx + offset, samplesToProcess ); - set32_fx( timeBuffer_fx + offset + samplesToProcess, 0, ( frameSize - samplesToProcess ) ); + set32_fx( timeBuffer_fx + add( offset, samplesToProcess ), 0, sub( frameSize, samplesToProcess ) ); } - else + ELSE { Copy32( timeIn_fx, timeBuffer_fx + offset, frameSize ); } h_cldfb->Q_cldfb_state = *q_cldfb; + move16(); /* only process needed cols */ - if ( samplesToProcess > -1 ) + IF( samplesToProcess > -1 ) { - no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels ); + no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } M1 = h_cldfb->no_channels; - M2 = M1 >> 1; - M4 = M1 >> 2; - L2 = M1 << 1; + move16(); + M2 = shr( M1, 1 ); + move16(); + M4 = shr( M1, 2 ); + move16(); + L2 = shl( M1, 1 ); + move16(); - if ( M2 & 1 ) + if ( s_and( M2, 1 ) ) { - M4 += 1; + M4 = add( M4, 1 ); } rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 @@ -759,35 +768,36 @@ void cldfbAnalysis_ts_fx( ptr_pf_fx = h_cldfb->p_filter; ptr_pf_sf = h_cldfb->p_filter_sf; + move16(); - for ( i = 0; i < no_col; i++ ) + FOR( i = 0; i < no_col; i++ ) { - for ( k = 0; k < M4; k++ ) + FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -798,43 +808,47 @@ void cldfbAnalysis_ts_fx( rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + move32(); + move32(); ///* folding + pre modulation of DCT IV */ ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + move32(); + move32(); } - for ( k = M4; k < M2; k++ ) + FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -845,72 +859,88 @@ void cldfbAnalysis_ts_fx( rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + rBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + move32(); + move32(); /* folding + pre modulation of DCT IV */ ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 + iBuffer_fx[add( 2 * k, 1 )] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + move32(); + move32(); } *q_cldfb = sub( *q_cldfb, 3 ); + move16(); /* FFT of DST IV */ Word16 q_shift; - q_shift = sub( s_min( getScaleFactor32( rBuffer_fx, 2 * M2 ), getScaleFactor32( iBuffer_fx, 2 * M2 ) ), find_guarded_bits_fx( M2 ) ); + q_shift = sub( s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ), find_guarded_bits_fx( M2 ) ); *q_cldfb = add( *q_cldfb, q_shift ); - for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + move16(); + FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); + move32(); } - for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); + move32(); } fft_cldfb_fx( rBuffer_fx, M2 ); /* post modulation of DST IV */ - for ( k = 0; k < M2; k++ ) + FOR( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 - realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 + realBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ) ); // q - 5 + realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ) ); // q - 5 + move32(); + move32(); } *q_cldfb = sub( *q_cldfb, 2 ); + move16(); /* FFT of DCT IV */ fft_cldfb_fx( iBuffer_fx, M2 ); - q_shift = s_min( getScaleFactor32( rBuffer_fx, 2 * M2 ), getScaleFactor32( iBuffer_fx, 2 * M2 ) ); + q_shift = s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ); *q_cldfb = add( *q_cldfb, q_shift ); - for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + move16(); + FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); + move32(); } - for ( Word16 ind = 0; ind < 2 * M2; ind++ ) + FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); + move32(); } /* post modulation of DCT IV */ - for ( k = 0; k < M2; k++ ) + FOR( k = 0; k < M2; k++ ) { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 - imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 + imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ) ); // q - 5 + imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ) ); // q - 5 + move32(); + move32(); } - if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) + IF( EQ_32( h_cldfb->prototype, CLDFB_PROTOTYPE_5_00MS ) ) { /* rotation due to delay*/ /*if(h_cldfb->da != M1)*/ - if ( rot_vctr_delay_re_fx != NULL ) + IF( rot_vctr_delay_re_fx != NULL ) { - for ( k = 0; k < M1; k++ ) + FOR( k = 0; k < M1; k++ ) { Word32 cplx_aux_fx; /* delay */ @@ -923,20 +953,22 @@ void cldfbAnalysis_ts_fx( cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 realBuffer_fx[k] = cplx_aux_fx; + move32(); + move32(); } } } - timeBuffer_fx += L2 * 5; - timeBuffer_fx += h_cldfb->no_channels - h_cldfb->p_filter_length; + timeBuffer_fx += i_mult( L2, 5 ); + timeBuffer_fx += sub( h_cldfb->no_channels, h_cldfb->p_filter_length ); } /* update memory */ - if ( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { Copy32( buffer_fx + samplesToProcess, h_cldfb->cldfb_state_fx, offset ); } - else + ELSE { Copy32( buffer_fx + frameSize, h_cldfb->cldfb_state_fx, offset ); } @@ -958,7 +990,7 @@ void cldfbAnalysis_ts_fx_fixed_q( Word16 i, k; Word16 L2, M1, M2, M4; Word16 no_col = h_cldfb->no_col; - + move16(); Word32 r1_fx, r2_fx, rr12_fx, ir12_fx; Word32 i1_fx, i2_fx, ri12_fx, ii12_fx; Word32 rBuffer_fx[2 * CLDFB_NO_CHANNELS_MAX]; @@ -972,39 +1004,44 @@ void cldfbAnalysis_ts_fx_fixed_q( Word32 *timeBuffer_fx, buffer_fx[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )]; Word16 offset, frameSize; - offset = h_cldfb->p_filter_length - h_cldfb->no_channels; - frameSize = h_cldfb->no_channels * h_cldfb->no_col; + offset = sub( h_cldfb->p_filter_length, h_cldfb->no_channels ); + frameSize = i_mult( h_cldfb->no_channels, h_cldfb->no_col ); /* prepare input buffer */ timeBuffer_fx = buffer_fx; Copy32( h_cldfb->cldfb_state_fx, timeBuffer_fx, offset ); h_cldfb->Q_cldfb_state = *q_cldfb; + move16(); - if ( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { Copy32( timeIn_fx, timeBuffer_fx + offset, samplesToProcess ); - set32_fx( timeBuffer_fx + offset + samplesToProcess, 0, ( frameSize - samplesToProcess ) ); + set32_fx( timeBuffer_fx + add( offset, samplesToProcess ), 0, sub( frameSize, samplesToProcess ) ); } - else + ELSE { Copy32( timeIn_fx, timeBuffer_fx + offset, frameSize ); } /* only process needed cols */ - if ( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels ); + no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } M1 = h_cldfb->no_channels; - M2 = M1 >> 1; - M4 = M1 >> 2; - L2 = M1 << 1; + M2 = shr( M1, 1 ); + M4 = shr( M1, 2 ); + L2 = shl( M1, 1 ); + move16(); + move16(); + move16(); + move16(); - if ( M2 & 1 ) + if ( s_and( M2, 1 ) ) { - M4 += 1; + M4 = add( M4, 1 ); } rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 @@ -1014,35 +1051,36 @@ void cldfbAnalysis_ts_fx_fixed_q( ptr_pf_fx = h_cldfb->p_filter; ptr_pf_sf = h_cldfb->p_filter_sf; + move16(); - for ( i = 0; i < no_col; i++ ) + FOR( i = 0; i < no_col; i++ ) { - for ( k = 0; k < M4; k++ ) + FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -1053,43 +1091,47 @@ void cldfbAnalysis_ts_fx_fixed_q( rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); ///* folding + pre modulation of DCT IV */ ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); } - for ( k = M4; k < M2; k++ ) + FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - r1_fx = L_sub( r1_fx, Mpy_32_16_1( timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - r2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - r2_fx = L_sub( r2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q - - i1_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ) ); // q - i1_fx = L_sub( i1_fx, Mpy_32_16_1( timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ) ); // q - - i2_fx = L_sub( 0, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ) ); // q - i2_fx = L_sub( i2_fx, Mpy_32_16_1( timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ) ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -1100,50 +1142,60 @@ void cldfbAnalysis_ts_fx_fixed_q( rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - rBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ri12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); /* folding + pre modulation of DCT IV */ ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_im_fx[k] ) ); // q - 3 - iBuffer_fx[2 * k + 1] = L_add( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), Mpy_32_32( ii12_fx, rot_vctr_re_fx[k] ) ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); } *q_cldfb = sub( *q_cldfb, 3 ); + move16(); /* FFT of DST IV */ fft_cldfb_fx( rBuffer_fx, M2 ); /* post modulation of DST IV */ - for ( k = 0; k < M2; k++ ) + FOR( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 - realBuffer_fx[2 * k] = L_add( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 + realBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 + realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + move32(); + move32(); } *q_cldfb = sub( *q_cldfb, 2 ); + move16(); /* FFT of DCT IV */ fft_cldfb_fx( iBuffer_fx, M2 ); /* post modulation of DCT IV */ - for ( k = 0; k < M2; k++ ) + FOR( k = 0; k < M2; k++ ) { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ) ); // q - 5 - imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ) ); // q - 5 + imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 + imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + move32(); + move32(); } - if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) + IF( EQ_32( h_cldfb->prototype, CLDFB_PROTOTYPE_5_00MS ) ) { /* rotation due to delay*/ /*if(h_cldfb->da != M1)*/ - if ( rot_vctr_delay_re_fx != NULL ) + IF( rot_vctr_delay_re_fx != NULL ) { - for ( k = 0; k < M1; k++ ) + FOR( k = 0; k < M1; k++ ) { Word32 cplx_aux_fx; /* delay */ @@ -1153,23 +1205,25 @@ void cldfbAnalysis_ts_fx_fixed_q( /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ /*realBuffer[k] = rBuffer[k]; imagBuffer[k] = iBuffer[k];*/ - cplx_aux_fx = L_sub( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ) ); // q - 5 - imagBuffer_fx[k] = L_add( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), Mpy_32_32( imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ) ); // q - 5 + cplx_aux_fx = Msub_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ); // q - 5 + imagBuffer_fx[k] = Madd_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ); // q - 5 realBuffer_fx[k] = cplx_aux_fx; + move32(); + move32(); } } } - timeBuffer_fx += L2 * 5; - timeBuffer_fx += h_cldfb->no_channels - h_cldfb->p_filter_length; + timeBuffer_fx += i_mult( L2, 5 ); + timeBuffer_fx += sub( h_cldfb->no_channels, h_cldfb->p_filter_length ); } /* update memory */ - if ( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { Copy32( buffer_fx + samplesToProcess, h_cldfb->cldfb_state_fx, offset ); } - else + ELSE { Copy32( buffer_fx + frameSize, h_cldfb->cldfb_state_fx, offset ); } @@ -1411,7 +1465,7 @@ void cldfbSynthesis_ivas_fx( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels ); + no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); move16(); } @@ -1422,7 +1476,7 @@ void cldfbSynthesis_ivas_fx( rot_vctr_delay_im_fx = h_cldfb->rot_vec_syn_delay_im_fx; synthesisBuffer_fx = buffer_fx; - Copy32( h_cldfb->cldfb_state_fx, synthesisBuffer_fx + ( M1 * no_col ), h_cldfb->p_filter_length ); + Copy32( h_cldfb->cldfb_state_fx, synthesisBuffer_fx + i_mult( M1, no_col ), h_cldfb->p_filter_length ); p_filter = h_cldfb->p_filter; p_filter_sf = h_cldfb->p_filter_sf; @@ -1430,7 +1484,7 @@ void cldfbSynthesis_ivas_fx( ptr_time_out_fx = timeOut_fx; /*synthesisBuffer += M1 * h_cldfb->no_col;*/ - synthesisBuffer_fx += M1 * no_col; + synthesisBuffer_fx += i_mult( M1, no_col ); FOR( k = 0; k < no_col; k++ ) { @@ -1448,8 +1502,8 @@ void cldfbSynthesis_ivas_fx( sin((EVS_PI/M1)*(i+0.5)*(-(h_cldfb->ds-M1)*0.5)));*/ /*cplxMult(&rBuffer[i], &iBuffer[i], realBuffer[k][i], imagBuffer[k][i], rot_vctr_delay_re[i], rot_vctr_delay_im[i]);*/ /*cplxMult(&realBuffer[k][i], &imagBuffer[k][i], realBuffer[k][i], imagBuffer[k][i], rot_vctr_delay_re[i], rot_vctr_delay_im[i]);*/ - cplx_aux = L_sub( Mpy_32_32( realBuffer_fx[k][i], rot_vctr_delay_re_fx[i] ), Mpy_32_32( imagBuffer_fx[k][i], rot_vctr_delay_im_fx[i] ) ); // Qx - imagBuffer_fx[k][i] = L_add( Mpy_32_32( realBuffer_fx[k][i], rot_vctr_delay_im_fx[i] ), Mpy_32_32( imagBuffer_fx[k][i], rot_vctr_delay_re_fx[i] ) ); + cplx_aux = Msub_32_32( Mpy_32_32( realBuffer_fx[k][i], rot_vctr_delay_re_fx[i] ), imagBuffer_fx[k][i], rot_vctr_delay_im_fx[i] ); // Qx + imagBuffer_fx[k][i] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][i], rot_vctr_delay_im_fx[i] ), imagBuffer_fx[k][i], rot_vctr_delay_re_fx[i] ); move32(); realBuffer_fx[k][i] = cplx_aux; move32(); @@ -1460,9 +1514,9 @@ void cldfbSynthesis_ivas_fx( } FOR( i = Mz; i < M1; i++ ) { - realBuffer_fx[k][i] = L_deposit_l( 0 ); + realBuffer_fx[k][i] = 0; move32(); - imagBuffer_fx[k][i] = L_deposit_l( 0 ); + imagBuffer_fx[k][i] = 0; move32(); } @@ -1470,16 +1524,16 @@ void cldfbSynthesis_ivas_fx( { /* pre modulation of DST IV */ /*cplxMult(&rBuffer[2*i], &rBuffer[2*i+1], realBuffer[k][2*i], realBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - rBuffer_fx[2 * i] = L_sub( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), Mpy_32_32( realBuffer_fx[k][M1 - 1 - 2 * i], rot_vctr_im_fx[i] ) ); // Qx + rBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx move32(); - rBuffer_fx[2 * i + 1] = L_add( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), Mpy_32_32( realBuffer_fx[k][M1 - 1 - 2 * i], rot_vctr_re_fx[i] ) ); // Qx + rBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx move32(); /* pre modulation of DCT IV */ /*cplxMult(&iBuffer[2*i], &iBuffer[2*i+1],-imagBuffer[k][2*i], imagBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - iBuffer_fx[2 * i] = L_sub( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), Mpy_32_32( imagBuffer_fx[k][M1 - 1 - 2 * i], rot_vctr_im_fx[i] ) ); // Qx + iBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx move32(); - iBuffer_fx[2 * i + 1] = L_add( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), Mpy_32_32( imagBuffer_fx[k][M1 - 1 - 2 * i], rot_vctr_re_fx[i] ) ); // Qx + iBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx move32(); } @@ -1493,69 +1547,69 @@ void cldfbSynthesis_ivas_fx( FOR( i = 0; i < M41; i++ ) { /* post modulation of DST IV */ - rr12_fx = L_sub( Mpy_32_32( rBuffer_fx[M1 - 2 - 2 * i], rot_vctr_re_fx[M2 - 1 - i] ), Mpy_32_32( rBuffer_fx[M1 - 1 - 2 * i], rot_vctr_im_fx[M2 - 1 - i] ) ); // Qx - ri12_fx = L_add( Mpy_32_32( rBuffer_fx[M1 - 2 - 2 * i], rot_vctr_im_fx[M2 - 1 - i] ), Mpy_32_32( rBuffer_fx[M1 - 1 - 2 * i], rot_vctr_re_fx[M2 - 1 - i] ) ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx /* post modulation of DCT IV */ - ir12_fx = L_sub( Mpy_32_32( iBuffer_fx[M1 - 2 - 2 * i], rot_vctr_re_fx[M2 - 1 - i] ), Mpy_32_32( iBuffer_fx[M1 - 1 - 2 * i], rot_vctr_im_fx[M2 - 1 - i] ) ); // Qx - ii12_fx = L_add( Mpy_32_32( iBuffer_fx[M1 - 2 - 2 * i], rot_vctr_im_fx[M2 - 1 - i] ), Mpy_32_32( iBuffer_fx[M1 - 1 - 2 * i], rot_vctr_re_fx[M2 - 1 - i] ) ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx - new_samples_fx[M1 + M2 + 1 + 2 * i] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx + new_samples_fx[add( add( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx move32(); - new_samples_fx[M2 - 2 - 2 * i] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx + new_samples_fx[sub( sub( M2, 2 ), shl( i, 1 ) )] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx move32(); - new_samples_fx[M1 + M2 - 2 - 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[sub( sub( add( M1, M2 ), 2 ), shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[M2 + 1 + 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[add( add( M2, 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); } FOR( i = 0; i < M42; i++ ) { /* post modulation of DST IV */ - rr12_fx = L_sub( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), Mpy_32_32( rBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ) ); // Qx - ri12_fx = L_add( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), Mpy_32_32( rBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ) ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx /* post modulation of DCT IV */ - ir12_fx = L_sub( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), Mpy_32_32( iBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ) ); // Qx - ii12_fx = L_add( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), Mpy_32_32( iBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ) ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx - new_samples_fx[M1 + M2 + 2 * i] = L_add( ri12_fx, ir12_fx ); // Qx + new_samples_fx[add( add( M1, M2 ), shl( i, 1 ) )] = L_add( ri12_fx, ir12_fx ); // Qx move32(); - new_samples_fx[M2 - 1 - 2 * i] = L_add( rr12_fx, ii12_fx ); // Qx + new_samples_fx[sub( sub( M2, 1 ), shl( i, 1 ) )] = L_add( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[M1 + M2 - 1 - 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[sub( sub( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); - new_samples_fx[M2 + 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[add( M2, shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); } /* synthesis prototype filter */ FOR( i = 0; i < L2; i++ ) { - accu0 = L_add( synthesisBuffer_fx[0 * L2 + i], Mpy_32_16_1( Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 0 * L2 + i )] ), p_filter_sf ) ); // Qx - 1 - accu1 = L_add( synthesisBuffer_fx[1 * L2 + i], Mpy_32_16_1( Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 1 * L2 + i )] ), p_filter_sf ) ); // Qx - 1 - accu2 = L_add( synthesisBuffer_fx[2 * L2 + i], Mpy_32_16_1( Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 2 * L2 + i )] ), p_filter_sf ) ); // Qx - 1 - accu3 = L_add( synthesisBuffer_fx[3 * L2 + i], Mpy_32_16_1( Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 3 * L2 + i )] ), p_filter_sf ) ); // Qx - 1 - accu4 = L_add( synthesisBuffer_fx[4 * L2 + i], Mpy_32_16_1( Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 4 * L2 + i )] ), p_filter_sf ) ); // Qx - 1 + accu0 = Madd_32_16( synthesisBuffer_fx[i], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[i] ), p_filter_sf ); // Qx - 1 + accu1 = Madd_32_16( synthesisBuffer_fx[add( L2, i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( L2, i )] ), p_filter_sf ); // Qx - 1 + accu2 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 2, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 2, L2 ), i )] ), p_filter_sf ); // Qx - 1 + accu3 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 3, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 3, L2 ), i )] ), p_filter_sf ); // Qx - 1 + accu4 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 4, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 4, L2 ), i )] ), p_filter_sf ); // Qx - 1 - synthesisBuffer_fx[0 * L2 + i] = accu0; + synthesisBuffer_fx[i] = accu0; move32(); - synthesisBuffer_fx[1 * L2 + i] = accu1; + synthesisBuffer_fx[add( L2, i )] = accu1; move32(); - synthesisBuffer_fx[2 * L2 + i] = accu2; + synthesisBuffer_fx[add( i_mult( 2, L2 ), i )] = accu2; move32(); - synthesisBuffer_fx[3 * L2 + i] = accu3; + synthesisBuffer_fx[add( i_mult( 3, L2 ), i )] = accu3; move32(); - synthesisBuffer_fx[4 * L2 + i] = accu4; + synthesisBuffer_fx[add( i_mult( 4, L2 ), i )] = accu4; move32(); } FOR( i = 0; i < M1; i++ ) { - ptr_time_out_fx[M1 - 1 - i] = synthesisBuffer_fx[4 * L2 + M1 + i]; + ptr_time_out_fx[sub( sub( M1, 1 ), i )] = synthesisBuffer_fx[add( i_mult( 4, L2 ), add( M1, i ) )]; move32(); } @@ -1596,6 +1650,28 @@ void configureCldfb_ivas( return; } +void configureCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const int32_t sampling_rate /* i : sampling rate */ +) +{ + + h_cldfb->no_col = CLDFB_NO_COL_MAX; + h_cldfb->bandsToZero = 0; + h_cldfb->nab = 0; + + h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); + h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; +#ifdef IVAS_FLOAT_FIXED + h_cldfb->zeros = 0; + h_cldfb->anaScalefactor = 0; + h_cldfb->synScalefactor = 0; + h_cldfb->filterScale = 1; +#endif + cldfb_init_proto_and_twiddles_enc( h_cldfb ); + + return; +} #ifdef IVAS_FLOAT_FIXED void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ @@ -1604,16 +1680,23 @@ void configureCldfb_ivas_fx( { h_cldfb->no_col = CLDFB_NO_COL_MAX; + move16(); h_cldfb->bandsToZero = 0; + move16(); h_cldfb->nab = 0; + move16(); // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); - Word32 n_sampling_rate = sampling_rate * 2; - Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */ ), 1 ); - val = L_shr( val, 1 ); - h_cldfb->no_channels = extract_l( val ); - - h_cldfb->p_filter_length = 10 * h_cldfb->no_channels; + h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); + move16(); + h_cldfb->zeros = 0; + move16(); + h_cldfb->anaScalefactor = 0; + move16(); + h_cldfb->synScalefactor = 0; + move16(); + h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); + move16(); cldfb_init_proto_and_twiddles( h_cldfb ); @@ -1626,6 +1709,67 @@ void configureCldfb_ivas_fx( * open and configures a CLDFB handle *--------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +ivas_error openCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const Word32 sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +) +{ + HANDLE_CLDFB_FILTER_BANK hs; + Word16 buf_len; + + IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + + hs->type = type; + move16(); + hs->prototype = prototype; + move16(); + + // configureCldfb_ivas( hs, sampling_rate ); + configureCldfb_ivas_fx( hs, sampling_rate ); + hs->memory_flt = NULL; + hs->FilterStates = NULL; + hs->memory_length = 0; + move16(); + + IF( EQ_32( type, CLDFB_ANALYSIS ) ) + { + buf_len = sub( hs->p_filter_length, hs->no_channels ); + } + ELSE + { + buf_len = hs->p_filter_length; + move16(); + } + + IF( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); + hs->Q_cldfb_state = Q11; + /* TODO: remove the floating point dependency */ + + /*IF( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + }*/ + + // set_f( hs->cldfb_state, 0.0f, buf_len ); + + *h_cldfb = hs; + move16(); + + return IVAS_ERR_OK; +} + ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -1645,6 +1789,7 @@ ivas_error openCldfb_ivas( hs->prototype = prototype; configureCldfb_ivas( hs, sampling_rate ); + hs->memory_flt = NULL; hs->memory_length = 0; @@ -1668,9 +1813,12 @@ ivas_error openCldfb_ivas( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + move16(); + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + move16(); set32_fx( hs->cldfb_state_fx, 0, buf_len ); hs->Q_cldfb_state = Q11; + move16(); #endif // IVAS_FLOAT_FIXED @@ -1722,74 +1870,76 @@ ivas_error openCldfb_ivas( return IVAS_ERR_OK; } #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error openCldfb_ivas_fx( +ivas_error openCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const Word32 sampling_rate, /* i : sampling rate */ + const int32_t sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ) { HANDLE_CLDFB_FILTER_BANK hs; - Word16 buf_len; + int16_t buf_len; - IF( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) + if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } hs->type = type; - move16(); hs->prototype = prototype; - move16(); - // configureCldfb_ivas( hs, sampling_rate ); - configureCldfb_ivas_fx( hs, sampling_rate ); + configureCldfb_ivas_enc( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; - move16(); - IF( EQ_32( type, CLDFB_ANALYSIS ) ) + if ( type == CLDFB_ANALYSIS ) { - buf_len = sub( hs->p_filter_length, hs->no_channels ); + buf_len = hs->p_filter_length - hs->no_channels; +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } - ELSE + else { buf_len = hs->p_filter_length; - move16(); +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } - IF( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - - hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ - set32_fx( hs->cldfb_state_fx, 0, buf_len ); - hs->Q_cldfb_state = Q11; - /* TODO: remove the floating point dependency */ - - IF( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) + set_f( hs->cldfb_state, 0.0f, buf_len ); +#ifdef IVAS_FLOAT_FIXED + if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + move16(); + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + move16(); + set32_fx( hs->cldfb_state_fx, 0, buf_len ); + set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); + set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); +#endif // IVAS_FLOAT_FIXED - set_f( hs->cldfb_state, 0.0f, buf_len ); *h_cldfb = hs; - move16(); return IVAS_ERR_OK; } -#endif /*-------------------------------------------------------------------* * resampleCldfb_ivas() * * Change sample rate of filter bank *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void resampleCldfb_ivas( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const int32_t newSamplerate ) @@ -1809,7 +1959,7 @@ void resampleCldfb_ivas( return; } -#ifdef IVAS_FLOAT_FIXED +#else void resampleCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const Word32 newSamplerate ) @@ -1862,6 +2012,44 @@ void analysisCldfbEncoder_ivas( return; } +void analysisCldfbEncoder_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *timeIn, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 *ppBuf_Ener, + Word16 *enerBuffSum_exp, + CLDFB_SCALE_FACTOR *scale ) +{ + Word16 i; + CLDFB_SCALE_FACTOR enerScale; + Word32 *ppBuf_Real[CLDFB_NO_COL_MAX]; + Word32 *ppBuf_Imag[CLDFB_NO_COL_MAX]; + Word16 *ppBuf_Real16[CLDFB_NO_COL_MAX]; + Word16 *ppBuf_Imag16[CLDFB_NO_COL_MAX]; + Word32 workBuffer[256]; + + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + ppBuf_Real[i] = &realBuffer[i][0]; + ppBuf_Imag[i] = &imagBuffer[i][0]; + ppBuf_Real16[i] = &realBuffer16[i][0]; + ppBuf_Imag16[i] = &imagBuffer16[i][0]; + } + + cldfbAnalysisFiltering( st->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, scale, timeIn, 0, CLDFB_NO_COL_MAX, workBuffer ); + + enerScale.lb_scale = negate( scale->lb_scale ); + enerScale.lb_scale16 = negate( scale->lb_scale ); + + AnalysisPostSpectrumScaling_Fx( st->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, ppBuf_Real16, ppBuf_Imag16, &enerScale.lb_scale16 ); + + GetEnergyCldfb( &st->energyCoreLookahead_Fx, &st->sf_energyCoreLookahead_Fx, 1, ppBuf_Real16, ppBuf_Imag16, enerScale.lb_scale16, st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, &st->currEnergyHF_fx, &st->currEnergyHF_e_fx, ppBuf_Ener, enerBuffSum_exp, st->hTECEnc ); + + return; +} /*-------------------------------------------------------------------* * GetEnergyCldfb_ivas() * @@ -1949,6 +2137,7 @@ void deleteCldfb_ivas( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; + test(); IF( h_cldfb == NULL || *h_cldfb == NULL ) { return; @@ -1959,10 +2148,15 @@ void deleteCldfb_ivas( free( hs->cldfb_state ); } #ifdef IVAS_FLOAT_FIXED - if ( hs->cldfb_state_fx ) + IF( hs->cldfb_state_fx ) { free( hs->cldfb_state_fx ); } + + IF( hs->FilterStates ) + { + free( hs->FilterStates ); + } #endif free( hs ); @@ -1988,10 +2182,10 @@ void deleteCldfb_ivas_fx( free( hs->cldfb_state_fx ); } #ifdef IVAS_FLOAT_FIXED // TODO : Will be removed later - IF( hs->cldfb_state ) - { - free( hs->cldfb_state ); - } + // IF( hs->cldfb_state ) + //{ + // free( hs->cldfb_state ); + // } #endif free( hs ); @@ -2390,7 +2584,416 @@ static void cldfb_init_proto_and_twiddles( return; } +static void cldfb_init_proto_and_twiddles_enc( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +) +{ + /*find appropriate set of rotVecs*/ + switch ( hs->no_channels ) + { + case 10: + hs->rot_vec_ana_re = rot_vec_ana_re_L10; + hs->rot_vec_ana_im = rot_vec_ana_im_L10; + hs->rot_vec_syn_re = rot_vec_syn_re_L10; + hs->rot_vec_syn_im = rot_vec_syn_im_L10; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L10_fx; + hs->rRotVctr = rRotVectr_10; + hs->iRotVctr = iRotVectr_10; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_10_flt; + hs->scale_flt = CLDFB80_10_SCALE; + hs->ds = 10; + hs->da = 10; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17036; + hs->scale = cldfb_scale_2_5ms[0]; + hs->p_filter = cldfb_protoFilter_2_5ms[0]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_10; + hs->scale_flt = LDQMF_10_SCALE; + hs->ds = 40; + hs->da = -20; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->p_filter = cldfb_protoFilter_5_0ms[0]; + hs->scale = cldfb_scale_5_0ms[0]; +#endif + } + break; + + case 16: + hs->rot_vec_ana_re = rot_vec_ana_re_L16; + hs->rot_vec_ana_im = rot_vec_ana_im_L16; + hs->rot_vec_syn_re = rot_vec_syn_re_L16; + hs->rot_vec_syn_im = rot_vec_syn_im_L16; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L16_fx; + hs->rRotVctr = rRotVectr_16; + hs->iRotVctr = iRotVectr_16; + { + hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_16_flt; + hs->scale_flt = CLDFB80_16_SCALE; + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->p_filter = cldfb_protoFilter_2_5ms[1]; + hs->scale = cldfb_scale_2_5ms[1]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_16; + hs->scale_flt = LDQMF_16_SCALE; + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->p_filter = cldfb_protoFilter_5_0ms[1]; + hs->scale = cldfb_scale_5_0ms[1]; +#endif + } + break; + + case 20: + hs->rot_vec_ana_re = rot_vec_ana_re_L20; + hs->rot_vec_ana_im = rot_vec_ana_im_L20; + hs->rot_vec_syn_re = rot_vec_syn_re_L20; + hs->rot_vec_syn_im = rot_vec_syn_im_L20; +#ifdef IVAS_FLOAT_FIXED + hs->rRotVctr = rRotVectr_20; + hs->iRotVctr = iRotVectr_20; + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L20_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L20_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L20_fx; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_20_flt; + hs->scale_flt = CLDFB80_20_SCALE; + hs->ds = 20; + hs->da = 20; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17050; + hs->p_filter = cldfb_protoFilter_2_5ms[2]; + hs->scale = cldfb_scale_2_5ms[2]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_20; + hs->scale_flt = LDQMF_20_SCALE; + hs->ds = 80; + hs->da = -40; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15390; + hs->p_filter = cldfb_protoFilter_5_0ms[2]; + hs->scale = cldfb_scale_5_0ms[2]; +#endif + } + break; + case 30: + hs->rot_vec_ana_re = rot_vec_ana_re_L30; + hs->rot_vec_ana_im = rot_vec_ana_im_L30; + hs->rot_vec_syn_re = rot_vec_syn_re_L30; + hs->rot_vec_syn_im = rot_vec_syn_im_L30; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L30_fx; + hs->rRotVctr = rRotVectr_30; + hs->iRotVctr = iRotVectr_30; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_30_flt; + hs->scale_flt = CLDFB80_30_SCALE; + hs->ds = 30; + hs->da = 30; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->scale = cldfb_scale_2_5ms[6]; + hs->p_filter = cldfb_protoFilter_2_5ms[6]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_30; + hs->scale_flt = LDQMF_30_SCALE; + hs->ds = 120; + hs->da = -60; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15388; + hs->scale = cldfb_scale_5_0ms[6]; + hs->p_filter = cldfb_protoFilter_5_0ms[6]; +#endif + } + break; + + case 32: + hs->rot_vec_ana_re = rot_vec_ana_re_L32; + hs->rot_vec_ana_im = rot_vec_ana_im_L32; + hs->rot_vec_syn_re = rot_vec_syn_re_L32; + hs->rot_vec_syn_im = rot_vec_syn_im_L32; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L32_fx; + hs->rRotVctr = rRotVectr_32; + hs->iRotVctr = iRotVectr_32; + { + hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_32_flt; + hs->scale_flt = CLDFB80_32_SCALE; + hs->ds = 32; + hs->da = 32; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17050; + hs->p_filter = cldfb_protoFilter_2_5ms[3]; + hs->scale = cldfb_scale_2_5ms[3]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_32; + hs->scale_flt = LDQMF_32_SCALE; + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 15392; + hs->scale = cldfb_scale_5_0ms[3]; + hs->p_filter = cldfb_protoFilter_5_0ms[3]; +#endif + } + break; + + case 40: + hs->rot_vec_ana_re = rot_vec_ana_re_L40; + hs->rot_vec_ana_im = rot_vec_ana_im_L40; + hs->rot_vec_syn_re = rot_vec_syn_re_L40; + hs->rot_vec_syn_im = rot_vec_syn_im_L40; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L40_fx; + hs->rRotVctr = rRotVectr_40; + hs->iRotVctr = iRotVectr_40; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_40_flt; + hs->scale_flt = CLDFB80_40_SCALE; + hs->ds = 40; + hs->da = 40; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->p_filter_sf = (Word16) 17051; + hs->q_scale = norm_s( (Word16) CLDFB80_40_SCALE ); + hs->scale = cldfb_scale_2_5ms[4]; + hs->p_filter = cldfb_protoFilter_2_5ms[4]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_40; + hs->scale_flt = LDQMF_40_SCALE; + hs->ds = 160; + hs->da = -80; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; + hs->p_filter = cldfb_protoFilter_5_0ms[4]; + hs->scale = cldfb_scale_5_0ms[4]; +#endif + } + break; + + case 60: + hs->rot_vec_ana_re = rot_vec_ana_re_L60; + hs->rot_vec_ana_im = rot_vec_ana_im_L60; + hs->rot_vec_syn_re = rot_vec_syn_re_L60; + hs->rot_vec_syn_im = rot_vec_syn_im_L60; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; + hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; + hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; + hs->rot_vec_syn_im_fx = rot_vec_syn_im_L60_fx; + hs->rRotVctr = rRotVectr_60; + hs->iRotVctr = iRotVectr_60; + IF( hs->type == CLDFB_SYNTHESIS ) + { + hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); + move16(); + } + ELSE + { + hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); + move16(); + } +#endif + if ( hs->prototype == CLDFB_PROTOTYPE_1_25MS ) + { + hs->p_filter_flt = CLDFB80_60_flt; + hs->scale_flt = CLDFB80_60_SCALE; + hs->ds = 60; + hs->da = 60; + hs->rot_vec_ana_delay_re = NULL; + hs->rot_vec_ana_delay_im = NULL; + hs->rot_vec_syn_delay_re = NULL; + hs->rot_vec_syn_delay_im = NULL; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = NULL; + hs->rot_vec_ana_delay_im_fx = NULL; + hs->rot_vec_syn_delay_re_fx = NULL; + hs->rot_vec_syn_delay_im_fx = NULL; + hs->p_filter_sf = (Word16) 17051; + hs->p_filter = cldfb_protoFilter_2_5ms[5]; + hs->scale = cldfb_scale_2_5ms[5]; +#endif + } + else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + hs->p_filter_flt = LDQMF_60; + hs->scale_flt = LDQMF_60_SCALE; + hs->ds = 240; + hs->da = -120; + hs->rot_vec_ana_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_ana_delay_im = rot_vec_delay_im_LDQMF; + hs->rot_vec_syn_delay_re = rot_vec_delay_re_LDQMF; + hs->rot_vec_syn_delay_im = rot_vec_delay_im_LDQMF; +#ifdef IVAS_FLOAT_FIXED + hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; + hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; + hs->p_filter_sf = (Word16) 15391; + hs->p_filter = cldfb_protoFilter_5_0ms[5]; + hs->scale = cldfb_scale_5_0ms[5]; +#endif + } + break; + } + + return; +} /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * @@ -2403,7 +3006,7 @@ ivas_error cldfb_save_memory_ivas_fx( { UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); - IF( hs->memory_flt != NULL || NE_16( hs->memory_length, 0 ) ) + IF( hs->memory_flt != NULL || ( hs->memory_length != 0 ) ) { /* memory already stored; Free memory first */ return IVAS_ERR_OK; @@ -2434,8 +3037,7 @@ ivas_error cldfb_save_memory_ivas_fx( return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED - +#else ivas_error cldfb_save_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -2467,7 +3069,7 @@ ivas_error cldfb_save_memory_ivas( return IVAS_ERR_OK; } - +#endif /*-------------------------------------------------------------------* * cldfb_restore_memory_ivas() @@ -2481,13 +3083,14 @@ void cldfb_restore_memory_ivas_fx( { UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); UWord16 size; + test(); IF( hs->memory_flt == NULL || EQ_16( hs->memory_length, 0 ) ) { /* memory not allocated */ return; } - IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) + IF( hs->type == CLDFB_ANALYSIS ) { size = offset; move16(); @@ -2507,7 +3110,9 @@ void cldfb_restore_memory_ivas_fx( L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, size, hs->memory_length ); } hs->cldfb_state_length = size; + move16(); hs->memory_length = 0; + move16(); #if 1 // Remove later free( hs->memory_flt ); hs->memory_flt = NULL; @@ -2517,8 +3122,7 @@ void cldfb_restore_memory_ivas_fx( return; } -#endif // IVAS_FLOAT_FIXED - +#else void cldfb_restore_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -2556,7 +3160,7 @@ void cldfb_restore_memory_ivas( return; } - +#endif /*-------------------------------------------------------------------* * cldfb_reset_memory_ivas() @@ -2596,16 +3200,20 @@ void cldfb_reset_memory_fx( IF( hs->type == CLDFB_ANALYSIS ) { memory_length = offset; + move16(); } ELSE { memory_length = hs->p_filter_length; + move16(); } hs->cldfb_state_length = memory_length; + move16(); /* save the memory */ set32_fx( hs->cldfb_state_fx, 0, memory_length ); hs->Q_cldfb_state = Q11; + move16(); return; } diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 59c8df22186294ae1abb94a73f6e441505023d76..1186c82fae9369424ac970c12f58424e70536ae4 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -20,8 +20,7 @@ #include "stat_com.h" #include "rom_com.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include #define STATE_BUFFER_SIZE ( 9 + 16 ) @@ -230,19 +229,21 @@ static void calcModulation( Word32 *rYR, { cmplx CL_x, CL_z; cmplx_s C_c; - int i; - int lc = m >> 1; + Word32 i; + Word32 lc = L_shr( m, 1 ); const Word16 *cr = rRotVctr; const Word16 *ci = iRotVctr; - for ( i = 0; i < lc; i++ ) + FOR( i = 0; i < lc; i++ ) { CL_x = CL_form( *rXR, *rXI ); C_c = C_form( *cr, *ci ); CL_z = CL_mult_32x16( CL_x, C_c ); *rYR = CL_Extract_real( CL_z ); + move64(); *rYI = CL_Extract_imag( CL_z ); + move64(); rYR += srYR; rYI += srYI; rXR += srXR; @@ -251,7 +252,9 @@ static void calcModulation( Word32 *rYR, CL_x = CL_form( *iXR, *iXI ); CL_z = CL_mult_32x16( CL_x, C_c ); *iYR = CL_Extract_real( CL_z ); + move64(); *iYI = CL_Extract_imag( CL_z ); + move64(); iYR += siYR; iYI += siYI; iXR += siXR; @@ -298,14 +301,14 @@ static void calcModulationAndFolding( Word16 *rY, const Word16 *r11, *r12, *r21, *r22; - y11 = &rY[m + m2 + 1]; - y12 = &rY[m2 - 2]; - y13 = &rY[m + m2 - 2]; + y11 = &rY[add( add( m, m2 ), 1 )]; + y12 = &rY[sub( m2, 2 )]; + y13 = &rY[sub( add( m, m2 ), 2 )]; y14 = &rY[m2 + 1]; - y21 = &rY[m + m2]; + y21 = &rY[add( m, m2 )]; y22 = &rY[m2 - 1]; - y23 = &rY[m + m2 - 1]; + y23 = &rY[sub( add( m, m2 ), 1 )]; y24 = &rY[m2]; x11 = &rX[m - 2]; @@ -416,6 +419,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, stride = 1; /* constant */ + move16(); m = cldfbBank->no_channels; move16(); L2 = shl( m, 1 ); @@ -447,12 +451,12 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, p_stride = CLDFB_NO_POLY; pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; - pFilter1 = &pFilter[p_stride * L3M1]; - pFilter2 = &pFilter[p_stride * L3]; - pFilter3 = &pFilter[p_stride * m2]; - pFilter4 = &pFilter[p_stride * M2M1]; - pFilter5 = &pFilter[p_stride * L4M1]; - pFilter6 = &pFilter[p_stride * M0M2]; + pFilter1 = &pFilter[i_mult( p_stride, L3M1 )]; + pFilter2 = &pFilter[i_mult( p_stride, L3 )]; + pFilter3 = &pFilter[i_mult( p_stride, m2 )]; + pFilter4 = &pFilter[i_mult( p_stride, M2M1 )]; + pFilter5 = &pFilter[i_mult( p_stride, L4M1 )]; + pFilter6 = &pFilter[i_mult( p_stride, M0M2 )]; nSamples = i_mult( nTimeSlots, cldfbBank->no_channels ); nSamplesUpd = i_mult( cldfbBank->no_col, cldfbBank->no_channels ); @@ -465,7 +469,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, move16(); FOR( i = 0; i < offset; i += cldfbBank->no_channels ) { - cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[k + cldfbBank->no_col]; + cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[add( k, cldfbBank->no_col )]; move16(); assert( (size_t) k < sizeof( cldfbBank->FilterStates_e ) / sizeof( cldfbBank->FilterStates_e[0] ) ); scale = s_max( scale, cldfbBank->FilterStates_e[k] ); @@ -517,80 +521,80 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < M4; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i] ); - - r2 = L_msu0( 0, pFilter2[0 + p_stride * 2 * i], pStates2[0 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter2[1 + p_stride * 2 * i], pStates2[1 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter2[2 + p_stride * 2 * i], pStates2[2 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter2[3 + p_stride * 2 * i], pStates2[3 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter2[4 + p_stride * 2 * i], pStates2[4 * L2 + 2 * i] ); - - i1 = L_msu0( 0, pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i] ); - i1 = L_msu0( i1, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i] ); - i1 = L_msu0( i1, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i] ); - i1 = L_msu0( i1, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i] ); - i1 = L_msu0( i1, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i] ); - - i2 = L_msu0( 0, pFilter4[0 - p_stride * 2 * i], pStates4[0 * L2 - 2 * i] ); - i2 = L_msu0( i2, pFilter4[1 - p_stride * 2 * i], pStates4[1 * L2 - 2 * i] ); - i2 = L_msu0( i2, pFilter4[2 - p_stride * 2 * i], pStates4[2 * L2 - 2 * i] ); - i2 = L_msu0( i2, pFilter4[3 - p_stride * 2 * i], pStates4[3 * L2 - 2 * i] ); - i2 = L_msu0( i2, pFilter4[4 - p_stride * 2 * i], pStates4[4 * L2 - 2 * i] ); + r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + r2 = L_msu0( 0, pFilter2[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter2[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter2[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter2[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter2[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + i1 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + i2 = L_msu0( 0, pFilter4[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter4[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter4[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter4[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter4[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); /* folding */ rBuffer[2 * i] = L_sub( r1, r2 ); move32(); - rBuffer[2 * i + 1] = L_negate( L_add( i1, i2 ) ); + rBuffer[add( shl( i, 1 ), 1 )] = L_negate( L_add( i1, i2 ) ); move32(); /* folding */ iBuffer[2 * i] = L_add( r1, r2 ); move32(); - iBuffer[2 * i + 1] = L_sub( i1, i2 ); + iBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); move32(); } FOR( i = M4; i < m2; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i] ); - r1 = L_msu0( r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i] ); - - r2 = L_msu0( 0, pFilter6[0 + p_stride * 2 * i], pStates6[0 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter6[1 + p_stride * 2 * i], pStates6[1 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter6[2 + p_stride * 2 * i], pStates6[2 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter6[3 + p_stride * 2 * i], pStates6[3 * L2 + 2 * i] ); - r2 = L_msu0( r2, pFilter6[4 + p_stride * 2 * i], pStates6[4 * L2 + 2 * i] ); - - i1 = L_msu0( 0, pFilter5[0 - p_stride * 2 * i], pStates5[0 * L2 - 2 * i] ); - i1 = L_msu0( i1, pFilter5[1 - p_stride * 2 * i], pStates5[1 * L2 - 2 * i] ); - i1 = L_msu0( i1, pFilter5[2 - p_stride * 2 * i], pStates5[2 * L2 - 2 * i] ); - i1 = L_msu0( i1, pFilter5[3 - p_stride * 2 * i], pStates5[3 * L2 - 2 * i] ); - i1 = L_msu0( i1, pFilter5[4 - p_stride * 2 * i], pStates5[4 * L2 - 2 * i] ); - - i2 = L_msu0( 0, pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i] ); - i2 = L_msu0( i2, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i] ); - i2 = L_msu0( i2, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i] ); - i2 = L_msu0( i2, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i] ); - i2 = L_msu0( i2, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i] ); + r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + r2 = L_msu0( 0, pFilter6[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter6[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter6[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter6[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); + r2 = L_msu0( r2, pFilter6[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + i1 = L_msu0( 0, pFilter5[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter5[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter5[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter5[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); + i1 = L_msu0( i1, pFilter5[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); + + i2 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); + i2 = L_msu0( i2, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); /* folding */ rBuffer[2 * i] = L_add( r1, r2 ); move32(); - rBuffer[2 * i + 1] = L_sub( i1, i2 ); + rBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); move32(); /* folding */ iBuffer[2 * i] = L_sub( r1, r2 ); move32(); - iBuffer[2 * i + 1] = L_add( i1, i2 ); + iBuffer[add( shl( i, 1 ), 1 )] = L_add( i1, i2 ); move32(); } @@ -722,7 +726,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, iBuffer = &pWorkBuffer[m]; nBuffer = (Word16 *) ( &pWorkBuffer[L2] ); - rAnalysisS = &pWorkBuffer[3 * m]; + rAnalysisS = &pWorkBuffer[i_mult( 3, m )]; iAnalysisS = &pWorkBuffer[4 * m]; rRotVctr = cldfbBank->rRotVctr; @@ -784,7 +788,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( ; i < m; i += 2 ) { rAnalysisS[i] = L_deposit_l( 0 ); + move32(); iAnalysisS[i] = L_deposit_l( 0 ); + move32(); } } @@ -812,7 +818,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( ; i < m; i += 2 ) { rAnalysisS[i] = L_deposit_l( 0 ); + move32(); iAnalysisS[i] = L_deposit_l( 0 ); + move32(); } } } @@ -837,14 +845,14 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, calcModulationAndFolding( nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2 ); /* prototype filter */ - pStates = &cldfbBank->FilterStates[k * L2]; + pStates = &cldfbBank->FilterStates[i_mult( k, L2 )]; pFilterS = &cldfbBank->p_filter[0]; pFilterM = &cldfbBank->p_filter[shr( cldfbBank->p_filter_length, 1 )]; FOR( i = 0; i < channels0; i++ ) { pStatesI = &pStates[i]; - pStatesR = &pStates[i + channels3]; + pStatesR = &pStates[add( i, channels3 )]; acc = L_mult( *pStatesI, *pFilterS++ ); acc = L_mac( acc, *pStatesR, *pFilterM++ ); @@ -866,21 +874,22 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, pStatesI += channels4; acc = L_mac( acc, *pStatesI, *pFilterS++ ); - acc = L_mac( acc, nBuffer[channels1 - i], *pFilterM++ ); + acc = L_mac( acc, nBuffer[sub( channels1, i )], *pFilterM++ ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[( offset1 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); + timeOut[i_mult( sub( offset1, i ), stride )] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else timeOut[( offset1 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif BASOP_SATURATE_WARNING_ON_EVS + move16(); } FOR( ; i < cldfbBank->no_channels; i++ ) { - pStatesI = &pStates[i + channels2]; - pStatesR = &pStates[i + channels2 + channels3]; + pStatesI = &pStates[add( i, channels2 )]; + pStatesR = &pStates[add( add( i, channels2 ), channels3 )]; acc = L_mult( *pStatesI, *pFilterS++ ); acc = L_mac( acc, *pStatesR, *pFilterM++ ); @@ -905,22 +914,23 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[( offset2 - i ) * stride] = round_fx_sat( L_shl_sat( acc, outScale ) ); + timeOut[i_mult( sub( offset2, i ), stride )] = round_fx_sat( L_shl_sat( acc, outScale ) ); #else timeOut[( offset2 - i ) * stride] = round_fx( L_shl( acc, outScale ) ); #endif BASOP_SATURATE_WARNING_ON_EVS + move16(); } FOR( i = 0; i < cldfbBank->no_channels; i++ ) { - pStates[statesSizeM1 + i] = nBuffer[channels1 - i]; + pStates[add( statesSizeM1, i )] = nBuffer[sub( channels1, i )]; move16(); - pStates[statesSizeM2 + i] = nBuffer[channels1 + m - i]; + pStates[add( statesSizeM2, i )] = nBuffer[sub( add( channels1, m ), i )]; move16(); } - timeOut = &timeOut[m * stride]; + timeOut = &timeOut[i_mult( m, stride )]; } /* move filter states */ @@ -945,6 +955,7 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ move16(); assert( h_cldfb->no_channels >= 10 ); h_cldfb->no_col = div_l( frameSize, shr( h_cldfb->no_channels, 1 ) ); + move16(); /* was cldfbInitFilterBank()*/ h_cldfb->anaScalefactor = 0; @@ -964,6 +975,7 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ move16(); h_cldfb->flags = s_or( h_cldfb->flags, CLDFB_FLAG_2_5MS_SETUP ); + move16(); h_cldfb->filterScale = CLDFB_CLDFB80_PFT_SCALE; move16(); @@ -1004,8 +1016,8 @@ ivas_error openCldfb( { HANDLE_CLDFB_FILTER_BANK hs; - hs = (HANDLE_CLDFB_FILTER_BANK) count_malloc( sizeof( CLDFB_FILTER_BANK ) ); - if ( hs == NULL ) + hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ); + IF( hs == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -1018,11 +1030,11 @@ ivas_error openCldfb( IF( type == CLDFB_ANALYSIS ) { - hs->FilterStates = (Word16 *) count_malloc( STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + hs->FilterStates = (Word16 *) malloc( STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); } ELSE { - hs->FilterStates = (Word16 *) count_malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + hs->FilterStates = (Word16 *) malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); } if ( hs->FilterStates == NULL ) { @@ -1048,7 +1060,7 @@ ivas_error openCldfb( move16(); } } - ELSE IF( hs->type == CLDFB_SYNTHESIS ) + ELSE IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) { IF( hs->FilterStates != 0 ) { @@ -1102,8 +1114,8 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, IF( firstFrame == 0 ) { /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ - lerp( hs->FilterStates + ( noChannelsOld * hs->no_col ), hs->FilterStates + ( noChannelsOld * hs->no_col ), timeOffset, timeOffsetOld ); - Copy( hs->FilterStates + ( noChannelsOld * hs->no_col ), hs->FilterStates + frameSize, timeOffset ); + lerp( hs->FilterStates + i_mult( noChannelsOld, hs->no_col ), hs->FilterStates + i_mult( noChannelsOld, hs->no_col ), timeOffset, timeOffsetOld ); + Copy( hs->FilterStates + i_mult( noChannelsOld, hs->no_col ), hs->FilterStates + frameSize, timeOffset ); } return; @@ -1159,6 +1171,8 @@ AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); iSubband16[i][j] = round_fx( L_shl( iSubband32[i][j], headRoom ) ); #endif + move32(); + move32(); } } @@ -1195,6 +1209,7 @@ void analysisCldfbEncoder_fx( Word16 *ppBuf_Imag16[CLDFB_NO_COL_MAX]; Word32 workBuffer[256]; Word16 num_slots = 1; + move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { @@ -1272,6 +1287,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) // Word16 freqTable[2] = {20, 40}; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( k = 0; k < numberCols; k++ ) @@ -1286,7 +1302,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } } - IF( GE_16( numberBands, freqTable[1] ) ) + IF( GE_16( numberBands, freqTable[1] ) && hTecEnc != NULL ) { Word32 *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; Word16 ScaleX2; @@ -1310,12 +1326,13 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) FOR( j = 0; j < numberBands; j++ ) { energyValuesSum[j] = L_deposit_l( 0 ); + move32(); energyValuesSumE[j] = 31; move16(); FOR( k = 0; k < CLDFB_NO_COL_MAX; k++ ) { nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); - IF( L_sub( maxWord32, nrg ) < energyValuesSum[j] ) + IF( LT_32( L_sub( maxWord32, nrg ), energyValuesSum[j] ) ) { energyValuesSumE[j] = add( energyValuesSumE[j], 1 ); move16(); @@ -1327,9 +1344,10 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) move32(); } test(); - IF( j == 0 || GT_16( energyValuesSumE[j], *energyValuesSum_Exp ) ) + if ( j == 0 || GT_16( energyValuesSumE[j], *energyValuesSum_Exp ) ) { *energyValuesSum_Exp = energyValuesSumE[j]; + move16(); } } FOR( j = 0; j < numberBands; j++ ) @@ -1419,6 +1437,7 @@ CLDFB_getNumChannels( Word32 sampleRate ) { Word16 nChannels = 0; + move16(); SWITCH( sampleRate ) @@ -1481,9 +1500,9 @@ void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ) /* i: cldfb handle */ { IF( ( *h_cldfb )->FilterStates != NULL ) { - count_free( ( *h_cldfb )->FilterStates ); + free( ( *h_cldfb )->FilterStates ); } - count_free( *h_cldfb ); + free( *h_cldfb ); } *h_cldfb = NULL; } @@ -1510,7 +1529,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->p_filter = cldfb_protoFilter_2_5ms[0]; hs->scale = cldfb_scale_2_5ms[0]; move16(); - IF( hs->type == CLDFB_SYNTHESIS ) + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) { hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); move16(); @@ -1520,7 +1539,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); move16(); } - break; + BREAK; case 16: hs->rRotVctr = rRotVectr_16; @@ -1534,7 +1553,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); move16(); } - break; + BREAK; case 20: hs->rRotVctr = rRotVectr_20; @@ -1544,7 +1563,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->p_filter = cldfb_protoFilter_2_5ms[2]; hs->scale = cldfb_scale_2_5ms[2]; move16(); - IF( hs->type == CLDFB_SYNTHESIS ) + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) { hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); move16(); @@ -1554,7 +1573,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); move16(); } - break; + BREAK; case 32: hs->rRotVctr = rRotVectr_32; @@ -1568,7 +1587,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); move16(); } - break; + BREAK; case 40: hs->rRotVctr = rRotVectr_40; @@ -1578,7 +1597,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->p_filter = cldfb_protoFilter_2_5ms[4]; hs->scale = cldfb_scale_2_5ms[4]; move16(); - IF( hs->type == CLDFB_SYNTHESIS ) + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) { hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); move16(); @@ -1588,7 +1607,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); move16(); } - break; + BREAK; case 60: hs->rRotVctr = rRotVectr_60; @@ -1598,7 +1617,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->p_filter = cldfb_protoFilter_2_5ms[5]; hs->scale = cldfb_scale_2_5ms[5]; move16(); - IF( hs->type == CLDFB_SYNTHESIS ) + IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) { hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); move16(); @@ -1608,7 +1627,7 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); move16(); } - break; + BREAK; } } @@ -1624,7 +1643,7 @@ ivas_error cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { - if ( hs->memory != NULL || hs->memory_length != 0 ) + IF( hs->memory != NULL || hs->memory_length != 0 ) { /* memory already stored; Free memory first */ return IVAS_ERR_OK; @@ -1637,7 +1656,7 @@ cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ Copy( hs->FilterStates_e, hs->memory + hs->memory_length, CLDFB_MEM_EXPONENTS ); hs->memory[hs->memory_length + CLDFB_MEM_EXPONENTS] = hs->FilterStates_eg; move16(); - if ( hs->memory == NULL ) + IF( hs->memory == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } @@ -1672,7 +1691,7 @@ void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ } hs->memory_length = 0; - count_free( hs->memory ); + free( hs->memory ); hs->memory = NULL; return; diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index e8e69432f12cbb9a97064f19907f2a4045fbeee6..b43b174484afef7a20210a21898cd13171605194 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" #include "ivas_rom_com_fx.h" @@ -86,7 +85,7 @@ void CNG_exc_fx( IF( *first_CNG == 0 ) { - IF( EQ_32( core_brate, FRAME_NO_DATA ) ) + IF( core_brate == FRAME_NO_DATA ) { /* needed only in decoder when the very first SID frame was erased and this frame is FRAME_NO_DATA frame */ /*fenew = dotp( fexc, fexc, pit_max )/pit_max;*/ @@ -102,7 +101,7 @@ void CNG_exc_fx( move32(); } - if ( EQ_16( element_mode, EVS_MONO ) ) + if ( element_mode == EVS_MONO ) { *lp_ener = *Enew; move32(); @@ -114,7 +113,7 @@ void CNG_exc_fx( *---------------------------------------------------------------------*/ test(); test(); - IF( NE_32( last_core_brate, SID_1k75 ) && NE_32( last_core_brate, FRAME_NO_DATA ) && NE_32( last_core_brate, SID_2k40 ) ) + IF( NE_32( last_core_brate, SID_1k75 ) && ( last_core_brate != FRAME_NO_DATA ) && NE_32( last_core_brate, SID_2k40 ) ) { /* Partially reset CNG energy after active speech period */ test(); @@ -171,7 +170,7 @@ if ( EQ_16( allow_cn_step, 1 ) ) move16(); } /* If not mono, skip CNG here */ -if ( GT_16( element_mode, IVAS_SCE ) ) +IF( GT_16( element_mode, IVAS_SCE ) ) { return; } @@ -234,9 +233,9 @@ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) FOR( i = 0; i < L_SUBFR; i++ ) { /* exc2[i] *= enr */ - L_tmp = L_mult( exc2[i_subfr + i], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ + L_tmp = L_mult( exc2[add( i_subfr, i )], tmp ); /* Q-4 * Q_exc+19 -> Q_exc +16 */ #ifdef BASOP_NOGLOB - exc2[i_subfr + i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); + exc2[add( i_subfr, i )] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); #else exc2[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); #endif @@ -307,15 +306,16 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) /* calculate the spectrum of random excitation signal */ Copy( exc2, fft_io, L_frame ); + Word16 Q_new_inp, mem_decim_size; // TO be removed IF( EQ_16( L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0 ); + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem1, 0, &Q_new_inp, &mem_decim_size ); } /* fft_rel(fft_io, L_FFT, LOG2_L_FFT); */ fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); /* ??????? */ ptR = &fft_io[1]; - ptI = &fft_io[sub( L_FFT, 1 )]; + ptI = &fft_io[L_FFT - 1]; FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ @@ -351,20 +351,23 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) if ( denv[i] < 0 ) { - denv[i] = L_deposit_l( 0 ); + denv[i] = 0; + move32(); } } set32_fx( itmp, 0, NUM_ENV_CNG ); set16_fx( fft_io, 0, L_FFT ); ptR = &fft_io[1]; - ptI = &fft_io[sub( L_FFT, 1 )]; + ptI = &fft_io[L_FFT - 1]; FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* *ptR = own_random( cng_ener_seed1 ); */ /* *ptI = own_random( cng_ener_seed1 ); */ *ptR = Random( cng_ener_seed1 ); + move16(); *ptI = Random( cng_ener_seed1 ); + move16(); /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ L_tmp = L_mult0( *ptR, *ptR ); /* Q0 */ @@ -395,7 +398,7 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) } } ptR = &fft_io[1]; - ptI = &fft_io[sub( L_FFT, 1 )]; + ptI = &fft_io[L_FFT - 1]; FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* *ptR *= sqrt(itmp[i]/env[i]); */ @@ -428,13 +431,14 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) #else *ptR = extract_h( L_shl( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ #endif + move16(); L_tmp2 = Mult_32_16( L_tmp, *ptI ); /*Q(16-exp)*/ #ifdef BASOP_NOGLOB *ptI = extract_h( L_shl_sat( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ #else *ptI = extract_h( L_shl( L_tmp2, add( exp, Q_exc ) ) ); /*Q_exc*/ #endif - + move16(); ptR++; ptI--; } @@ -443,7 +447,7 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) IF( EQ_16( L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0 ); + modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0, &Q_new_inp, &mem_decim_size ); } /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ @@ -509,7 +513,7 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) test(); test(); test(); - IF( NE_32( last_core_brate, SID_2k40 ) && NE_32( last_core_brate, SID_1k75 ) && NE_32( last_core_brate, FRAME_NO_DATA ) && EQ_32( core_brate, SID_2k40 ) ) + IF( NE_32( last_core_brate, SID_2k40 ) && NE_32( last_core_brate, SID_1k75 ) && ( last_core_brate != FRAME_NO_DATA ) && EQ_32( core_brate, SID_2k40 ) ) { #ifdef BASOP_NOGLOB IF( GT_32( L_tmp, L_shl_sat( 1, sub( 31, exp ) ) ) ) @@ -525,8 +529,9 @@ IF( NE_16( Opt_AMR_WB, 1 ) ) FOR( i = 0; i < L_SUBFR; i++ ) { /* fft_io[i] *= enr */ - L_tmp = L_mult( fft_io[i_subfr + i], tmp ); /* Q_exc + 16 - exp */ - fft_io[i_subfr + i] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc*/ + L_tmp = L_mult( fft_io[add( i_subfr, i )], tmp ); /* Q_exc + 16 - exp */ + fft_io[add( i_subfr, i )] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc*/ + move16(); } } @@ -674,6 +679,7 @@ void cng_params_postupd_fx( Word32 last_active_brate; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif ptr = add( sub( ho_circ_ptr, *cng_buf_cnt ), 1 ); @@ -686,7 +692,9 @@ void cng_params_postupd_fx( { exc2 = &cng_exc2_buf[ptr * L_FFT]; Q_exc = cng_Qexc_buf[ptr]; + move16(); last_active_brate = cng_brate_buf[ptr]; + move32(); /* calculate the spectrum of residual signal */ Copy( exc2, fft_io, L_FFT ); @@ -758,10 +766,12 @@ void cng_params_postupd_fx( if ( EQ_16( ptr, HO_HIST_SIZE ) ) { ptr = 0; + move16(); } } *cng_buf_cnt = 0; + move16(); return; } @@ -810,11 +820,13 @@ void cng_params_upd_fx( Word16 exp_pow; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* update the pointer to circular buffer of old LSP vectors */ *ho_circ_ptr = add( *ho_circ_ptr, 1 ); + move16(); if ( EQ_16( *ho_circ_ptr, HO_HIST_SIZE ) ) { @@ -837,7 +849,6 @@ void cng_params_upd_fx( scale = norm_s( maxv ); pt_exc2 = exc2; - move16(); L_ener = L_deposit_l( 0 ); IF( EQ_16( L_frame, L_FRAME ) ) { @@ -891,10 +902,11 @@ void cng_params_upd_fx( ho_ener_circ[*ho_circ_ptr] = L_ener; move32(); - IF( EQ_16( enc_dec_flag, ENC ) ) + IF( enc_dec_flag == ENC ) { /* Store residual signal for postponed FFT-processing*/ *cng_buf_cnt = add( *cng_buf_cnt, 1 ); + move16(); if ( GT_16( *cng_buf_cnt, HO_HIST_SIZE ) ) { *cng_buf_cnt = HO_HIST_SIZE; @@ -974,6 +986,7 @@ void cng_params_upd_fx( Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); } *ho_circ_size = add( *ho_circ_size, 1 ); + move16(); if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) { *ho_circ_size = HO_HIST_SIZE; @@ -1016,15 +1029,17 @@ void cng_params_upd_ivas_fx( Word16 exp1; Word16 CNG_mode; Word16 tmp = 0; + move16(); Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - /* update the pointer to circular buffer of old LSP vectors */ *ho_circ_ptr = add( *ho_circ_ptr, 1 ); + move16(); if ( EQ_16( *ho_circ_ptr, HO_HIST_SIZE ) ) { @@ -1047,7 +1062,6 @@ void cng_params_upd_ivas_fx( scale = norm_s( maxv ); pt_exc2 = exc2; - move16(); L_ener = L_deposit_l( 0 ); IF( EQ_16( L_frame, L_FRAME ) ) { @@ -1101,10 +1115,11 @@ void cng_params_upd_ivas_fx( ho_ener_circ[*ho_circ_ptr] = L_ener; move32(); - IF( EQ_16( enc_dec_flag, ENC ) ) + IF( enc_dec_flag == ENC ) { /* Store residual signal for postponed FFT-processing*/ *cng_buf_cnt = add( *cng_buf_cnt, 1 ); + move16(); if ( GT_16( *cng_buf_cnt, HO_HIST_SIZE ) ) { *cng_buf_cnt = HO_HIST_SIZE; @@ -1148,16 +1163,23 @@ void cng_params_upd_ivas_fx( Copy32( sp, env, NUM_ENV_CNG ); Word16 shift = 0; - if ( element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT ) + move16(); + test(); + IF( EQ_16( element_mode, IVAS_SCE ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) { Word32 att_fx = 0; Word16 index = 0; + move32(); + move16(); apply_scale_ivas_fx( &att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index ); att_fx = pow_10_q23[index]; // Q23 - tmp = extract_h( att_fx ); // Q7 + move32(); + tmp = extract_h( att_fx ); // Q7 + move16(); shift = 8; + move16(); } - else + ELSE { CNG_mode = get_cng_mode( last_active_brate ); /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ @@ -1187,6 +1209,7 @@ void cng_params_upd_ivas_fx( scale_sig32( &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG, shift ); } *ho_circ_size = add( *ho_circ_size, 1 ); + move16(); if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) { *ho_circ_size = HO_HIST_SIZE; @@ -1212,22 +1235,27 @@ Word16 get_cng_mode( IF( GT_32( last_active_brate, ACELP_13k20 ) ) { CNG_mode = 4; + move16(); } ELSE IF( GT_32( last_active_brate, ACELP_9k60 ) ) { CNG_mode = 3; + move16(); } ELSE IF( GT_32( last_active_brate, ACELP_8k00 ) ) { CNG_mode = 2; + move16(); } ELSE IF( GT_32( last_active_brate, ACELP_7k20 ) ) { CNG_mode = 1; + move16(); } ELSE { CNG_mode = 0; + move16(); } return ( CNG_mode ); diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 55eafef53d7c092eacc411237d4d6cfb4ce4b1e3..c5562860337081413241365f1f56cd73668cd5be 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -156,6 +156,8 @@ #define RANDOM_INITSEED 21845 /* Seed for random generators */ #ifndef FLT_MIN #define FLT_MIN ( 1.175494351e-38F ) +#define FLT_MIN_10_EXP (-37) // min decimal exponent +#define FLT_MIN_EXP (-125) // min binary exponent #endif #ifndef FLT_MAX #define FLT_MAX ( 3.402823466e+38F ) @@ -573,11 +575,9 @@ enum *----------------------------------------------------------------------------------*/ #define FRAMES_PER_SEC 50 -#ifdef IVAS_FLOAT_FIXED #define MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC 200 //(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) #define ONE_BY_FRAMES_PER_SEC_Q31 ( 42949673 ) #define FRAMES_PER_SEC_BY_2 (FRAMES_PER_SEC >> 1) -#endif #define INV_FRAME_PER_SEC_Q15 656 #define INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 164 #define FRAME_SIZE_NS 20000000L @@ -1919,6 +1919,7 @@ typedef enum _DCTTYPE #define N_SMC_MIXTURES 6 /* number of mixtures */ #define N_PCA_COEF 12 /* number of PCA components */ #define SMC_ST_MEAN_FACT 0.5 /* forgetting factor of short-term IIR mean filter */ +#define SMC_ST_MEAN_RSHIFT_FACT_FX 1 /* SMC_ST_MEAN_FACT equivalent right shift factor */ #define M_LSP_SPMUS 6 /* number of LSPs used in speech/music classifier */ #define NB_BANDS_SPMUS 15 @@ -2881,6 +2882,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_GAIN_ANA_16 ( 3 ) #define SCALE_GAIN_ANA_20 ( 3 ) #define SCALE_GAIN_ANA_32 ( 2 ) +#define SCALE_GAIN_ANA_30 ( 2 ) #define SCALE_GAIN_ANA_40 ( 2 ) #define SCALE_GAIN_ANA_60 ( 1 ) @@ -2892,6 +2894,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_CLDFB_ANA_32 ( SCALE_MODULATION + SCALE_GAIN_ANA_32 ) #define SCALE_CLDFB_ANA_40 ( SCALE_MODULATION + SCALE_GAIN_ANA_40 ) #define SCALE_CLDFB_ANA_60 ( SCALE_MODULATION + SCALE_GAIN_ANA_60 ) +#define SCALE_CLDFB_ANA_30 ( SCALE_MODULATION + SCALE_GAIN_ANA_30 ) #define SCALE_CLDFB_SYN_10 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_16 ( SCALE_MODULATION + SCALE_GAIN_SYN ) @@ -2899,6 +2902,7 @@ typedef enum SIGNAL_CLASSIFER_MODE #define SCALE_CLDFB_SYN_32 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_40 ( SCALE_MODULATION + SCALE_GAIN_SYN ) #define SCALE_CLDFB_SYN_60 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_30 ( SCALE_MODULATION + SCALE_GAIN_SYN ) /************************************************************************/ /* FFT */ @@ -3036,7 +3040,7 @@ extern const Word16 Idx2Freq_Tbl[]; /* 'x' is converted to Q6, 'Freq_Tbl'/1000 in Q9 */ /* only works for 'fs' = [8000,12800,16000,25600,32000,48000] (unpredictable otherwise) */ /* 15625 is 1000000.0f/Q6 but we use the calculated value to avoid float point code */ -#define NS2SA_fx2(fs,x) (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625))) +#define NS2SA_FX2(fs,x) (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625))) #define L_FRAME_12k8 256 /* Frame size at 12k8Hz: 20ms = 256 samples */ #define L_FRAME_16k 320 /* Frame size at 16kHz: 20ms = 320 samples */ diff --git a/lib_com/codec_tcx_common.c b/lib_com/codec_tcx_common.c index 79f0fa4c57e355992586f670fc57ab7884244699..e2fbbb9f31e2c7550d61c7c46468ea3be5b1259a 100644 --- a/lib_com/codec_tcx_common.c +++ b/lib_com/codec_tcx_common.c @@ -7,8 +7,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" #include "rom_com.h" @@ -37,7 +36,7 @@ Word16 tcxGetNoiseFillingTilt( { firstLine = shr( L_frame, 3 ); - Copy_Scale_sig( A, As, lpcorder + 1, sub( norm_s( A[0] ), 2 ) ); + Copy_Scale_sig( A, As, add( lpcorder, 1 ), sub( norm_s( A[0] ), 2 ) ); tmp = get_gain( As + 1, As, lpcorder ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB @@ -68,6 +67,7 @@ void tcxFormantEnhancement( Word16 xn_buf_e, xn_one, m, e; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */ @@ -144,7 +144,7 @@ void tcxFormantEnhancement( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); + xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -193,7 +193,7 @@ void tcxFormantEnhancement( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); + xn_buf[add( l, j )] = s_min( xn_one, shl_sat( mult( xn_buf[add( l, j )], fac ), fac_e ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -241,6 +241,7 @@ void tcxFormantEnhancement_with_shift( Word16 xn_buf_e, xn_one, m, e; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */ @@ -295,16 +296,16 @@ void tcxFormantEnhancement_with_shift( move16(); tmp = sub( e, fac_e ); - IF( GT_16( tmp, 0 ) ) + IF( tmp > 0 ) { fac0 = shr( fac0, tmp ); } - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { fac1 = shl( fac1, tmp ); } - IF( GT_16( tmp, 0 ) ) + IF( tmp > 0 ) { fac_e = e; move16(); @@ -321,7 +322,7 @@ void tcxFormantEnhancement_with_shift( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); + xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -370,7 +371,7 @@ void tcxFormantEnhancement_with_shift( fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); + xn_buf[add( l, j )] = s_min( xn_one, shl_o( mult( xn_buf[add( l, j )], fac ), fac_e, &Overflow ) ); #else xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) ); #endif @@ -427,7 +428,7 @@ void tcxInvertWindowGrouping( test(); test(); - if ( ( frame_cnt != 0 ) && ( bfi == 0 ) && NE_16( last_core, ACELP_CORE ) ) /* fix sub-window overlap */ + if ( ( frame_cnt != 0 ) && ( bfi == 0 ) && ( last_core != ACELP_CORE ) ) /* fix sub-window overlap */ { hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); @@ -459,7 +460,7 @@ void tcxInvertWindowGrouping( move32(); } - p = spectrum + L_frame - 1; + p = spectrum + sub( L_frame, 1 ); FOR( i = sub( L_frame, 1 ); i > L_win; i -= 2 ) { *p-- = spectrum[i]; @@ -475,8 +476,8 @@ void tcxInvertWindowGrouping( IF( LT_16( L_spec, L_frame ) ) { Copy32( spectrum + 8, spectrum + 16, sub( shr( L_spec, 1 ), 8 ) ); - Copy32( spectrum + L_frame / 2, spectrum + 8, 8 ); - Copy32( spectrum + L_frame / 2 + 8, spectrum + L_spec / 2 + 8, sub( shr( L_spec, 1 ), 8 ) ); + Copy32( spectrum + shr( L_frame, 1 ), spectrum + 8, 8 ); + Copy32( spectrum + add( shr( L_frame, 1 ), 8 ), spectrum + add( shr( L_spec, 1 ), 8 ), sub( shr( L_spec, 1 ), 8 ) ); } ELSE { @@ -642,7 +643,7 @@ void tcx5SpectrumInterleaving_fx( FOR( i = 0; i < tcx5Size; i++ ) { interleaveBuf[2 * i] = spectrum[i]; - interleaveBuf[2 * i + 1] = spectrum[tcx5Size + i]; + interleaveBuf[add( 2 * i, 1 )] = spectrum[add( tcx5Size, i )]; } Copy32( interleaveBuf, spectrum, shl( tcx5Size, 1 ) ); @@ -669,7 +670,7 @@ void tcx5SpectrumDeinterleaving_fx( FOR( i = 0; i < tcx5Size; i++ ) { interleaveBuf[i] = spectrum[2 * i]; - interleaveBuf[tcx5Size + i] = spectrum[2 * i + 1]; + interleaveBuf[add( tcx5Size, i )] = spectrum[add( 2 * i, 1 )]; } Copy32( interleaveBuf, spectrum, shl( tcx5Size, 1 ) ); @@ -693,7 +694,7 @@ void tcx5TnsGrouping_fx( { Copy32( spectrum + 8, spectrum + 16, sub( L_spec, 8 ) ); Copy32( spectrum + L_frame, spectrum + 8, 8 ); - Copy32( spectrum + L_frame + 8, spectrum + L_spec + 8, sub( L_spec, 8 ) ); + Copy32( spectrum + add( L_frame, 8 ), spectrum + add( L_spec, 8 ), sub( L_spec, 8 ) ); } ELSE { @@ -722,11 +723,11 @@ void tcx5TnsUngrouping_fx( /* undo rearrangement of LF sub-window lines prior to TNS analysis */ IF( LT_16( L_spec, L_frame ) ) { - Copy32( spectrum + L_spec + 8, spectrum + L_frame + 8, sub( L_spec, 8 ) ); + Copy32( spectrum + L_spec + 8, spectrum + add( L_frame, 8 ), sub( L_spec, 8 ) ); Copy32( spectrum + 8, spectrum + L_frame, 8 ); Copy32( spectrum + 16, spectrum + 8, sub( L_spec, 8 ) ); set32_fx( spectrum + L_spec, 0, sub( L_frame, L_spec ) ); - set32_fx( spectrum + L_frame + L_spec, 0, sub( L_frame, L_spec ) ); + set32_fx( spectrum + add( L_frame, L_spec ), 0, sub( L_frame, L_spec ) ); } ELSE { diff --git a/lib_com/codec_tcx_common_flt.c b/lib_com/codec_tcx_common_flt.c index 12e7d80994eb62b11ddb7a7294a38143c5898dcc..a9314e871522aa830b23aa958b94faa95c78bab9 100644 --- a/lib_com/codec_tcx_common_flt.c +++ b/lib_com/codec_tcx_common_flt.c @@ -145,7 +145,7 @@ void tcxInvertWindowGrouping_flt( float xn_buf[], float spectrum[], const int16_t L_frame, - const int16_t fUseTns, + const int8_t fUseTns, const int16_t last_core, const int16_t index, const int16_t frame_cnt, diff --git a/lib_com/complex_basop.c b/lib_com/complex_basop.c index b9a20ddaf0816bbdd3bb941400a1f3f07847db83..ffe56d47545610529d208ab39b4d0f9c5b2c4757 100644 --- a/lib_com/complex_basop.c +++ b/lib_com/complex_basop.c @@ -17,7 +17,7 @@ #include "stl.h" -#if ( WMOPS ) +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; @@ -35,7 +35,7 @@ cmplx CL_shr( cmplx inp, Word16 shift_val ) cmplx out; out.re = L_shr( inp.re, shift_val ); out.im = L_shr( inp.im, shift_val ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_shr++; multiCounter[currCounter].L_shr--; multiCounter[currCounter].L_shr--; @@ -48,7 +48,7 @@ cmplx CL_shl( cmplx inp, Word16 shift_val ) cmplx out; out.re = L_shl( inp.re, shift_val ); out.im = L_shl( inp.im, shift_val ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_shl++; multiCounter[currCounter].L_shl--; multiCounter[currCounter].L_shl--; @@ -61,7 +61,7 @@ cmplx CL_add( cmplx inp1, cmplx inp2 ) cmplx out; out.re = L_add( inp1.re, inp2.re ); out.im = L_add( inp1.im, inp2.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_add++; multiCounter[currCounter].L_add--; multiCounter[currCounter].L_add--; @@ -74,7 +74,7 @@ cmplx CL_sub( cmplx inp1, cmplx inp2 ) cmplx out; out.re = L_sub( inp1.re, inp2.re ); out.im = L_sub( inp1.im, inp2.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_sub++; multiCounter[currCounter].L_sub--; multiCounter[currCounter].L_sub--; @@ -87,11 +87,11 @@ cmplx CL_scale( cmplx x, Word16 y ) cmplx result; result.re = Mpy_32_16_r( x.re, y ); result.im = Mpy_32_16_r( x.im, y ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].CL_scale++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -100,11 +100,11 @@ cmplx CL_dscale( cmplx x, Word16 y1, Word16 y2 ) cmplx result; result.re = Mpy_32_16_r( x.re, y1 ); result.im = Mpy_32_16_r( x.im, y2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].CL_dscale++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -113,7 +113,7 @@ cmplx CL_msu_j( cmplx x, cmplx y ) cmplx result; result.re = L_add( x.re, y.im ); result.im = L_sub( x.im, y.re ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_msu_j++; multiCounter[currCounter].L_add--; multiCounter[currCounter].L_sub--; @@ -126,7 +126,7 @@ cmplx CL_mac_j( cmplx x, cmplx y ) cmplx result; result.re = L_sub( x.re, y.im ); result.im = L_add( x.im, y.re ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_mac_j++; multiCounter[currCounter].L_add--; multiCounter[currCounter].L_sub--; @@ -136,7 +136,7 @@ cmplx CL_mac_j( cmplx x, cmplx y ) cmplx CL_move( cmplx x ) { -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move++; #endif return x; @@ -144,7 +144,7 @@ cmplx CL_move( cmplx x ) Word32 CL_Extract_real( cmplx x ) { -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_Extract_real++; #endif return x.re; @@ -152,7 +152,7 @@ Word32 CL_Extract_real( cmplx x ) Word32 CL_Extract_imag( cmplx x ) { -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_Extract_imag++; #endif return x.im; @@ -163,7 +163,7 @@ cmplx CL_form( Word32 re, Word32 im ) cmplx result; result.re = re; result.im = im; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_form++; #endif return result; @@ -174,7 +174,7 @@ cmplx CL_multr_32x16( cmplx input, cmplx_s coeff ) cmplx result; result.re = W_round48_L( W_sub_nosat( W_mult_32_16( input.re, coeff.re ), W_mult_32_16( input.im, coeff.im ) ) ); result.im = W_round48_L( W_add_nosat( W_mult_32_16( input.re, coeff.im ), W_mult_32_16( input.im, coeff.re ) ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_multr_32x16++; multiCounter[currCounter].W_mult_32_16--; multiCounter[currCounter].W_mult_32_16--; @@ -193,7 +193,7 @@ cmplx CL_negate( cmplx x ) cmplx result; result.re = L_negate( x.re ); result.im = L_negate( x.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_negate++; multiCounter[currCounter].L_negate--; multiCounter[currCounter].L_negate--; @@ -206,7 +206,7 @@ cmplx CL_conjugate( cmplx x ) cmplx result; result.re = x.re; result.im = L_negate( x.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_conjugate++; multiCounter[currCounter].L_negate--; #endif @@ -220,7 +220,7 @@ cmplx CL_mul_j( cmplx input ) temp = CL_negate( input ); result.re = temp.im; result.im = input.re; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_mul_j++; multiCounter[currCounter].CL_negate--; #endif @@ -232,7 +232,7 @@ cmplx CL_swap_real_imag( cmplx input ) cmplx result; result.re = input.im; result.im = input.re; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_swap_real_imag++; #endif return result; @@ -244,7 +244,7 @@ cmplx_s C_add( cmplx_s inp1, cmplx_s inp2 ) out.re = add( inp1.re, inp2.re ); out.im = add( inp1.im, inp2.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_add++; multiCounter[currCounter].add--; multiCounter[currCounter].add--; @@ -258,7 +258,7 @@ cmplx_s C_sub( cmplx_s inp1, cmplx_s inp2 ) out.re = sub( inp1.re, inp2.re ); out.im = sub( inp1.im, inp2.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_sub++; multiCounter[currCounter].sub--; multiCounter[currCounter].sub--; @@ -274,7 +274,7 @@ cmplx_s C_mul_j( cmplx_s input ) result.re = temp; result.im = input.re; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_mul_j++; multiCounter[currCounter].negate--; #endif @@ -287,7 +287,7 @@ cmplx_s C_multr( cmplx_s x, cmplx_s c ) result.re = round_fx( W_sat_l( W_sub_nosat( W_mult_16_16( x.re, c.re ), W_mult_16_16( x.im, c.im ) ) ) ); result.im = round_fx( W_sat_l( W_add_nosat( W_mult_16_16( x.im, c.re ), W_mult_16_16( x.re, c.im ) ) ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_multr++; multiCounter[currCounter].W_mult_16_16--; multiCounter[currCounter].W_mult_16_16--; @@ -308,7 +308,7 @@ cmplx_s C_form( Word16 re, Word16 im ) cmplx_s result; result.re = re; result.im = im; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_form++; #endif return result; @@ -319,11 +319,11 @@ cmplx C_scale( cmplx_s x, Word16 y ) cmplx result; result.re = L_mult( x.re, y ); result.im = L_mult( x.im, y ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_mult--; multiCounter[currCounter].L_mult--; multiCounter[currCounter].C_scale++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -333,7 +333,7 @@ cmplx_s CL_round32_16( cmplx x ) result.re = round_fx( x.re ); result.im = round_fx( x.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_round32_16++; multiCounter[currCounter].round--; multiCounter[currCounter].round--; @@ -346,11 +346,11 @@ cmplx CL_scale_32( cmplx x, Word32 y ) cmplx result; result.re = Mpy_32_32_r( x.re, y ); result.im = Mpy_32_32_r( x.im, y ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].CL_scale_32++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -359,11 +359,11 @@ cmplx CL_dscale_32( cmplx x, Word32 y1, Word32 y2 ) cmplx result; result.re = Mpy_32_32_r( x.re, y1 ); result.im = Mpy_32_32_r( x.im, y2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].CL_dscale_32++; -#endif /* #if (WMOPS) */ +#endif /* #ifdef WMOPS */ return ( result ); } @@ -373,7 +373,7 @@ cmplx CL_multr_32x32( cmplx x, cmplx y ) result.re = W_round64_L( W_sub( W_mult_32_32( x.re, y.re ), W_mult_32_32( x.im, y.im ) ) ); result.im = W_round64_L( W_add( W_mult_32_32( x.im, y.re ), W_mult_32_32( x.re, y.im ) ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_multr_32x32++; multiCounter[currCounter].W_mult_32_32--; multiCounter[currCounter].W_mult_32_32--; @@ -393,7 +393,7 @@ cmplx_s C_mac_r( cmplx x, cmplx_s y, Word16 c ) cmplx temp = CL_add( x, C_scale( y, c ) ); result = CL_round32_16( temp ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_mac_r++; multiCounter[currCounter].CL_add--; multiCounter[currCounter].C_scale--; @@ -408,7 +408,7 @@ cmplx_s C_msu_r( cmplx x, cmplx_s y, Word16 c ) cmplx temp = CL_sub( x, C_scale( y, c ) ); result = CL_round32_16( temp ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_msu_r++; multiCounter[currCounter].CL_sub--; multiCounter[currCounter].C_scale--; @@ -419,7 +419,7 @@ cmplx_s C_msu_r( cmplx x, cmplx_s y, Word16 c ) Word16 C_Extract_real( cmplx_s x ) { -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_Extract_real++; #endif return x.re; @@ -427,7 +427,7 @@ Word16 C_Extract_real( cmplx_s x ) Word16 C_Extract_imag( cmplx_s x ) { -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_Extract_imag++; #endif return x.im; @@ -438,7 +438,7 @@ cmplx_s C_negate( cmplx_s x ) cmplx_s result; result.re = negate( x.re ); result.im = negate( x.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_negate++; multiCounter[currCounter].negate--; multiCounter[currCounter].negate--; @@ -451,7 +451,7 @@ cmplx_s C_conjugate( cmplx_s x ) cmplx_s result; result.re = x.re; result.im = negate( x.im ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_conjugate++; multiCounter[currCounter].negate--; #endif @@ -463,7 +463,7 @@ cmplx_s C_shr( cmplx_s inp, Word16 shift_val ) cmplx_s out; out.re = shr( inp.re, shift_val ); out.im = shr( inp.im, shift_val ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_shr++; multiCounter[currCounter].shr--; multiCounter[currCounter].shr--; @@ -476,7 +476,7 @@ cmplx_s C_shl( cmplx_s inp, Word16 shift_val ) cmplx_s out; out.re = shl( inp.re, shift_val ); out.im = shl( inp.im, shift_val ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].C_shl++; multiCounter[currCounter].shl--; multiCounter[currCounter].shl--; diff --git a/lib_com/control.c b/lib_com/control.c index 94f3d5aeb9d7781811c93d5359a8c232b133dd8e..20865de23788f218d0022257b64fe0a2d8c35ad6 100644 --- a/lib_com/control.c +++ b/lib_com/control.c @@ -36,7 +36,7 @@ Flag LT_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LT_16++; #endif return F_ret; @@ -50,7 +50,7 @@ Flag GT_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GT_16++; #endif return F_ret; @@ -64,7 +64,7 @@ Flag LE_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LE_16++; #endif return F_ret; @@ -78,7 +78,7 @@ Flag GE_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GE_16++; #endif return F_ret; @@ -92,7 +92,7 @@ Flag EQ_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].EQ_16++; #endif return F_ret; @@ -106,7 +106,7 @@ Flag NE_16( Word16 var1, Word16 var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].NE_16++; #endif return F_ret; @@ -120,7 +120,7 @@ Flag LT_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LT_32++; #endif return F_ret; @@ -134,7 +134,7 @@ Flag GT_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GT_32++; #endif return F_ret; @@ -148,7 +148,7 @@ Flag LE_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LE_32++; #endif return F_ret; @@ -162,7 +162,7 @@ Flag GE_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GE_32++; #endif return F_ret; @@ -176,7 +176,7 @@ Flag EQ_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].EQ_32++; #endif return F_ret; @@ -190,7 +190,7 @@ Flag NE_32( Word32 L_var1, Word32 L_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].NE_32++; #endif return F_ret; @@ -204,7 +204,7 @@ Flag LT_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LT_64++; #endif return F_ret; @@ -218,7 +218,7 @@ Flag GT_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GT_64++; #endif return F_ret; @@ -232,7 +232,7 @@ Flag LE_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].LE_64++; #endif return F_ret; @@ -245,7 +245,7 @@ Flag GE_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].GE_64++; #endif return F_ret; @@ -259,7 +259,7 @@ Flag EQ_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].EQ_64++; #endif return F_ret; @@ -272,7 +272,7 @@ Flag NE_64( Word64 L64_var1, Word64 L64_var2 ) { F_ret = 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].NE_64++; #endif return F_ret; diff --git a/lib_com/control.h b/lib_com/control.h index d6a9610ac2185bbbdcfc8b7f920e4657c09f2ab2..ad1e5ae6929c43918f6b9438232418ee31e1082b 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -41,7 +41,7 @@ * Constants and Globals * *****************************************************************************/ -#if ( WMOPS ) +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index c91e6f78262f5422a0e7b1239950cf05f23e038b..4b16b0b53cb5a4a3a143a69e4b755399cd9c1993 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -41,8 +41,9 @@ #include "prot.h" #include "wmc_auto.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" +#define FSCALE_DENOM_BY_12800_Q15 1311 /*-------------------------------------------------------------------* * is_EVS_bitrate() * @@ -58,9 +59,11 @@ Word16 is_EVS_bitrate( Word16 j; j = 0; + move16(); WHILE( LT_16( j, SIZE_BRATE_TBL ) && NE_32( ivas_total_brate, brate_tbl[j] ) ) { - j++; + test(); + j = add( j, 1 ); } /* AMR-WB IO mode/EVS primary mode determination */ @@ -82,14 +85,15 @@ Word16 is_EVS_bitrate( { return 0; } - BREAK; } *Opt_AMR_WB = 1; + move16(); } ELSE { *Opt_AMR_WB = 0; + move16(); } return 1; @@ -107,45 +111,59 @@ Word16 get_codec_mode( const Word32 total_brate /* i : total bitrate */ ) { - Word16 codec_mode = -1; + Word16 codec_mode; + codec_mode = -1; + move16(); SWITCH( total_brate ) { case 5900: codec_mode = MODE1; + move16(); BREAK; case 7200: codec_mode = MODE1; + move16(); BREAK; case 8000: codec_mode = MODE1; + move16(); BREAK; case 9600: codec_mode = MODE2; + move16(); BREAK; case 13200: codec_mode = MODE1; + move16(); BREAK; case 16400: codec_mode = MODE2; + move16(); BREAK; case 24400: codec_mode = MODE2; + move16(); BREAK; case 32000: codec_mode = MODE1; + move16(); BREAK; case 48000: codec_mode = MODE2; + move16(); BREAK; case 64000: codec_mode = MODE1; + move16(); BREAK; case 96000: codec_mode = MODE2; + move16(); BREAK; case 128000: codec_mode = MODE2; + move16(); BREAK; } @@ -270,207 +288,241 @@ Word16 getTcxonly( } break; #endif - return tcxonly; +#ifdef IVAS_CODE_SWITCHING } +#endif + return tcxonly; +} - Word16 getTcxonly_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const Word16 is_ism_format /* i : flag indicating ISM format */ - ) - { - Word16 tcxonly = 0; +Word16 getTcxonly_fx( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 is_ism_format /* i : flag indicating ISM format */ +) +{ + Word16 tcxonly; + tcxonly = 0; + move16(); - SWITCH( element_mode ) - { - case EVS_MONO: - IF( GT_32( total_brate, ACELP_32k ) ) + SWITCH( element_mode ) + { + case EVS_MONO: + if ( GT_32( total_brate, ACELP_32k ) ) + { + tcxonly = 1; + move16(); + } + BREAK; + case IVAS_SCE: + IF( is_ism_format ) + { + if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) ) { tcxonly = 1; + move16(); } - BREAK; - case IVAS_SCE: - IF( is_ism_format ) - { - IF( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) ) - { - tcxonly = 1; - } - } - ELSE + } + ELSE + { + if ( GT_32( total_brate, MAX_ACELP_BRATE ) ) { - IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) - { - tcxonly = 1; - } + tcxonly = 1; + move16(); } - BREAK; + } + BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - IF( GT_32( total_brate, MAX_ACELP_BRATE ) ) + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( GT_32( total_brate, MAX_ACELP_BRATE ) ) + { + tcxonly = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + IF( MCT_flag ) + { + + if ( GE_32( total_brate, IVAS_32k ) ) { tcxonly = 1; + move16(); } - BREAK; - case IVAS_CPE_MDCT: - IF( GE_32( total_brate, ( MCT_flag ? IVAS_32k : IVAS_48k ) ) ) + } + ELSE + { + if ( GE_32( total_brate, IVAS_48k ) ) { tcxonly = 1; + move16(); } - BREAK; - } - - return tcxonly; + } + BREAK; } - /*-------------------------------------------------------------------* - * getCtxHm() - * - * - *-------------------------------------------------------------------*/ + return tcxonly; +} - Word16 getCtxHm( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_flag /* i : flag to signal the RF mode */ - ) - { - Word16 ctx_hm; +/*-------------------------------------------------------------------* + * getCtxHm() + * + * + *-------------------------------------------------------------------*/ - ctx_hm = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( ( ( LE_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) && !rf_flag && ( ( LE_32( total_brate, IVAS_64k ) && NE_16( element_mode, IVAS_CPE_DFT ) ) || ( LT_32( total_brate, 24400 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) - { - ctx_hm = 1; - move16(); - } +Word16 getCtxHm( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_flag /* i : flag to signal the RF mode */ +) +{ + Word16 ctx_hm; - return ctx_hm; + ctx_hm = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( ( ( LE_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) && !rf_flag && ( ( LE_32( total_brate, IVAS_64k ) && NE_16( element_mode, IVAS_CPE_DFT ) ) || ( LT_32( total_brate, 24400 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + ctx_hm = 1; + move16(); } - /*-------------------------------------------------------------------* - * getResq() - * - * - *-------------------------------------------------------------------*/ + return ctx_hm; +} - Word16 getResq( - const Word32 total_brate /* i : total bitrate */ - ) - { - Word16 resq; +/*-------------------------------------------------------------------* + * getResq() + * + * + *-------------------------------------------------------------------*/ - resq = 0; - move16(); - IF( LE_32( total_brate, IVAS_64k ) ) - { - resq = 1; - move16(); - } +Word16 getResq( + const Word32 total_brate /* i : total bitrate */ +) +{ + Word16 resq; - return resq; + resq = 0; + move16(); + if ( LE_32( total_brate, IVAS_64k ) ) + { + resq = 1; + move16(); } - /*-------------------------------------------------------------------* - * getTnsAllowed() - * - * - *-------------------------------------------------------------------*/ + return resq; +} - Word16 getTnsAllowed( - const Word32 total_brate, /* i : total bitrate */ - const Word16 igf, /* i : flag indicating IGF activity*/ - const Word16 element_mode /* i : IVAS element mode */ - ) - { - Word16 tnsAllowed = 0; +/*-------------------------------------------------------------------* + * getTnsAllowed() + * + * + *-------------------------------------------------------------------*/ - tnsAllowed = 0; - move16(); - IF( NE_16( igf, 0 ) ) +Word16 getTnsAllowed( + const Word32 total_brate, /* i : total bitrate */ + const Word16 igf, /* i : flag indicating IGF activity*/ + const Word16 element_mode /* i : IVAS element mode */ +) +{ + Word16 tnsAllowed; + + tnsAllowed = 0; + move16(); + IF( igf != 0 ) + { + test(); + test(); + if ( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) { - IF( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) - { - tnsAllowed = 1; - move16(); - } + tnsAllowed = 1; + move16(); } - ELSE + } + ELSE + { + if ( GT_32( total_brate, HQ_32k ) ) { - IF( GT_32( total_brate, HQ_32k ) ) - { - tnsAllowed = 1; - move16(); - } + tnsAllowed = 1; + move16(); } - - return tnsAllowed; } - /*-------------------------------------------------------------------* - * getRestrictedMode() - * - * - *-------------------------------------------------------------------*/ + return tnsAllowed; +} - Word16 getRestrictedMode( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ - ) - { - Word16 restrictedMode = 3; +/*-------------------------------------------------------------------* + * getRestrictedMode() + * + * + *-------------------------------------------------------------------*/ - IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_32k ) && NE_16( element_mode, IVAS_SCE ) ) ) - { - restrictedMode = 6; - } - ELSE IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_48k ) && EQ_16( element_mode, IVAS_SCE ) ) ) - { - restrictedMode = 6; - } - ELSE IF( Opt_AMR_WB ) - { - restrictedMode = 1; - } +Word16 getRestrictedMode( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) +{ + Word16 restrictedMode; + restrictedMode = 3; + move16(); - return restrictedMode; + test(); + test(); + test(); + test(); + IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_32k ) && NE_16( element_mode, IVAS_SCE ) ) ) + { + restrictedMode = 6; + move16(); + } + ELSE IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_48k ) && EQ_16( element_mode, IVAS_SCE ) ) ) + { + restrictedMode = 6; + move16(); + } + ELSE IF( Opt_AMR_WB ) + { + restrictedMode = 1; + move16(); } - /*-------------------------------------------------------------------* - * getMdctWindowLength() - * - * - *-------------------------------------------------------------------*/ + return restrictedMode; +} - int16_t getMdctWindowLength( - const int16_t fscale ) - { - int16_t mdctWindowLength; +/*-------------------------------------------------------------------* + * getMdctWindowLength() + * + * + *-------------------------------------------------------------------*/ + +int16_t getMdctWindowLength( + const int16_t fscale ) +{ + int16_t mdctWindowLength; - mdctWindowLength = ( L_LOOK_12k8 * fscale ) / FSCALE_DENOM; + mdctWindowLength = ( L_LOOK_12k8 * fscale ) / FSCALE_DENOM; - return mdctWindowLength; - } + return mdctWindowLength; +} #ifdef IVAS_FLOAT_FIXED - Word16 getMdctWindowLength_fx( - const Word16 fscale ) - { - Word16 mdctWindowLength; - mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); +Word16 getMdctWindowLength_fx( + const Word16 fscale ) +{ + Word16 mdctWindowLength; + mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); - return mdctWindowLength; - } + return mdctWindowLength; +} #endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -479,1094 +531,1140 @@ Word16 getTcxonly( * *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - Word16 sr2fscale_fx( - const Word32 sr_core /* i : internal sampling rate */ - ) - { - return (Word16) ( ( FSCALE_DENOM * sr_core ) / 12800 ); - } +Word16 sr2fscale_fx( + const Word32 sr_core /* i : internal sampling rate */ +) +{ + return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); +} #endif - int16_t sr2fscale( - const int32_t sr_core /* i : internal sampling rate */ - ) - { - - return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 ); - } +int16_t sr2fscale( + const int32_t sr_core /* i : internal sampling rate */ +) +{ - /*-------------------------------------------------------------------* - * getCoreSamplerateMode2_flt() - * - * - *-------------------------------------------------------------------*/ + return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 ); +} - int32_t getCoreSamplerateMode2_flt( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ - const int16_t rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ - ) - { - int32_t sr_core = 0; +/*-------------------------------------------------------------------* + * getCoreSamplerateMode2_flt() + * + * + *-------------------------------------------------------------------*/ - if ( bwidth == NB ) - { - sr_core = INT_FS_12k8; - } - else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) ) - { - sr_core = INT_FS_12k8; - } - else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 ) - { - sr_core = INT_FS_12k8; - } - else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format ) - { - sr_core = INT_FS_16k; - } - else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format ) - { - sr_core = 25600; - } - else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) ) - { - sr_core = 25600; - } - else if ( bwidth == SWB || bwidth == FB ) - { - sr_core = 32000; - } +int32_t getCoreSamplerateMode2_flt( + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ + const int16_t rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ +) +{ + int32_t sr_core = 0; - return sr_core; + if ( bwidth == NB ) + { + sr_core = INT_FS_12k8; } - - Word32 getCoreSamplerateMode2( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ - ) + else if ( element_mode == EVS_MONO && ( ( bwidth == WB && total_brate < ACELP_13k20 ) || ( bwidth == SWB && total_brate <= ACELP_13k20 ) || ( rf_mode == 1 ) ) ) + { + sr_core = INT_FS_12k8; + } + else if ( element_mode > EVS_MONO && flag_ACELP16k == 0 ) + { + sr_core = INT_FS_12k8; + } + else if ( bwidth == WB || ( bwidth == SWB && total_brate <= ACELP_32k ) || ( bwidth == FB && total_brate <= ACELP_32k ) ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && !is_ism_format ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE_ISM && element_mode == IVAS_SCE && is_ism_format ) + { + sr_core = INT_FS_16k; + } + else if ( ( bwidth == SWB || bwidth == FB ) && total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && is_ism_format ) + { + sr_core = 25600; + } + else if ( ( ( bwidth == SWB || bwidth == FB ) && element_mode == EVS_MONO && total_brate <= HQ_64k ) || ( element_mode > IVAS_SCE && ( ( bwidth == SWB && total_brate <= IVAS_96k ) || ( bwidth == FB && total_brate <= IVAS_96k ) ) ) ) + { + sr_core = 25600; + } + else if ( bwidth == SWB || bwidth == FB ) { + sr_core = 32000; + } - Word32 sr_core; - Word16 bwd_swb_or_fb_flag; - sr_core = -1; /* to suppress MSVC warning */ - move32(); + return sr_core; +} - bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) ); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_32( bwidth, NB ) ) - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF( EQ_16( element_mode, EVS_MONO ) && ( L_and( EQ_32( bwidth, WB ), LT_32( total_brate, ACELP_13k20 ) ) || - L_and( EQ_32( bwidth, SWB ), LE_32( total_brate, ACELP_13k20 ) ) || EQ_16( rf_mode, 1 ) ) ) +Word32 getCoreSamplerateMode2( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format */ +) +{ - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF( GT_16( element_mode, EVS_MONO ) && flag_ACELP16k == 0 ) - { - sr_core = INT_FS_12k8; - move32(); - } - ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) ) - { - sr_core = INT_FS_16k; - move32(); - } - ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && !is_ism_format ) - { - sr_core = INT_FS_16k; - move32(); - } - ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE_ISM ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) - { - sr_core = INT_FS_16k; - } - ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) - { - sr_core = 25600; - } - ELSE IF( ( EQ_16( element_mode, EVS_MONO ) && ( bwd_swb_or_fb_flag && LE_32( total_brate, HQ_64k ) ) ) || ( GT_16( element_mode, IVAS_SCE ) && ( ( EQ_16( bwidth, SWB ) && LE_32( total_brate, IVAS_96k ) ) || ( EQ_16( bwidth, FB ) && LE_32( total_brate, IVAS_96k ) ) ) ) ) - { - sr_core = 25600; - move32(); - } - ELSE IF( bwd_swb_or_fb_flag ) - { - sr_core = 32000; - move32(); - } - ELSE - { - assert( 0 ); - } - - return sr_core; + Word32 sr_core; + Word16 bwd_swb_or_fb_flag; + sr_core = -1; /* to suppress MSVC warning */ + move32(); + + bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( bwidth == NB ) + { + sr_core = INT_FS_12k8; + move32(); } - - Word16 getTcxBandwidth( - const Word16 bwidth /* i : audio bandwidth */ - ) + ELSE IF( element_mode == EVS_MONO && ( L_and( EQ_32( bwidth, WB ), LT_32( total_brate, ACELP_13k20 ) ) || + L_and( EQ_32( bwidth, SWB ), LE_32( total_brate, ACELP_13k20 ) ) || EQ_16( rf_mode, 1 ) ) ) + { + sr_core = INT_FS_12k8; + move32(); + } + ELSE IF( element_mode > EVS_MONO && flag_ACELP16k == 0 ) + { + sr_core = INT_FS_12k8; + move32(); + } + ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) ) + { + sr_core = INT_FS_16k; + move32(); + } + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && !is_ism_format ) + { + sr_core = INT_FS_16k; + move32(); + } + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE_ISM ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) + { + sr_core = INT_FS_16k; + move32(); + } + ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format ) + { + sr_core = 25600; + move32(); + } + ELSE IF( ( element_mode == EVS_MONO && ( bwd_swb_or_fb_flag && LE_32( total_brate, HQ_64k ) ) ) || ( GT_16( element_mode, IVAS_SCE ) && ( ( EQ_16( bwidth, SWB ) && LE_32( total_brate, IVAS_96k ) ) || ( EQ_16( bwidth, FB ) && LE_32( total_brate, IVAS_96k ) ) ) ) ) + { + sr_core = 25600; + move32(); + } + ELSE IF( bwd_swb_or_fb_flag ) { + sr_core = 32000; + move32(); + } + ELSE + { + assert( 0 ); + } - Word16 tcxBandwidth; + return sr_core; +} - tcxBandwidth = 16384 /*0.5f Q15*/; - move16(); - if ( EQ_16( bwidth, NB ) ) - { - tcxBandwidth = 10240 /*0.3125f Q15*/; - move16(); - } +Word16 getTcxBandwidth( + const Word16 bwidth /* i : audio bandwidth */ +) +{ + + Word16 tcxBandwidth; - return tcxBandwidth; + tcxBandwidth = 16384 /*0.5f Q15*/; + move16(); + if ( bwidth == NB ) + { + tcxBandwidth = 10240 /*0.3125f Q15*/; + move16(); } - /*-------------------------------------------------------------------* - * getTcxBandwidth_flt() - * - * - *-------------------------------------------------------------------*/ + return tcxBandwidth; +} - float getTcxBandwidth_flt( - const int16_t bwidth /* i : audio bandwidth */ - ) - { - float tcxBandwidth = 0.5f; +/*-------------------------------------------------------------------* + * getTcxBandwidth_flt() + * + * + *-------------------------------------------------------------------*/ - if ( bwidth == NB ) - { - tcxBandwidth = 0.3125f; - } +float getTcxBandwidth_flt( + const int16_t bwidth /* i : audio bandwidth */ +) +{ + float tcxBandwidth = 0.5f; - return tcxBandwidth; + if ( bwidth == NB ) + { + tcxBandwidth = 0.3125f; } - /*-------------------------------------------------------------------* - * getIgfPresent() - * - * - *-------------------------------------------------------------------*/ + return tcxBandwidth; +} - int16_t getIgfPresent( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t rf_mode /* i : flag to signal the RF mode */ - ) - { - int16_t igfPresent = 0; +/*-------------------------------------------------------------------* + * getIgfPresent() + * + * + *-------------------------------------------------------------------*/ +int16_t getIgfPresent( + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t rf_mode /* i : flag to signal the RF mode */ +) +{ + int16_t igfPresent = 0; - if ( bwidth == SWB ) - { - switch ( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= HQ_64k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - if ( total_brate <= HQ_48k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_MDCT: - if ( total_brate <= IVAS_96k ) - { - igfPresent = 1; - } - break; - } - } - else if ( bwidth == FB ) + + if ( bwidth == SWB ) + { + switch ( element_mode ) { - switch ( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= IVAS_128k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - if ( total_brate <= IVAS_48k ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_MDCT: - if ( total_brate <= IVAS_128k ) - { - igfPresent = 1; - } - break; - } + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= HQ_64k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( total_brate <= HQ_48k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_MDCT: + if ( total_brate <= IVAS_96k ) + { + igfPresent = 1; + } + break; } - else if ( bwidth == WB ) + } + else if ( bwidth == FB ) + { + switch ( element_mode ) { - switch ( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - if ( total_brate <= ACELP_9k60 ) - { - igfPresent = 1; - } - break; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - case IVAS_CPE_MDCT: - if ( total_brate <= ACELP_13k20 ) - { - igfPresent = 1; - } - break; - } + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= IVAS_128k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( total_brate <= IVAS_48k ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_MDCT: + if ( total_brate <= IVAS_128k ) + { + igfPresent = 1; + } + break; } - - if ( ( ( bwidth == WB ) || ( bwidth == SWB ) ) && ( rf_mode == 1 ) && ( total_brate == ACELP_13k20 ) ) + } + else if ( bwidth == WB ) + { + switch ( element_mode ) { - igfPresent = 1; + case EVS_MONO: + case IVAS_SCE: + if ( total_brate <= ACELP_9k60 ) + { + igfPresent = 1; + } + break; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + case IVAS_CPE_MDCT: + if ( total_brate <= ACELP_13k20 ) + { + igfPresent = 1; + } + break; } - - return igfPresent; } - Word16 getIgfPresent_fx( - const Word16 element_mode, /* i : IVAS element mode */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 rf_mode /* i : flag to signal the RF mode */ - ) + if ( ( ( bwidth == WB ) || ( bwidth == SWB ) ) && ( rf_mode == 1 ) && ( total_brate == ACELP_13k20 ) ) { - Word16 igfPresent = 0; - move16(); + igfPresent = 1; + } - IF( EQ_16( bwidth, SWB ) ) - { - SWITCH( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, HQ_64k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - IF( LE_32( total_brate, HQ_48k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_MDCT: - IF( LE_32( total_brate, IVAS_96k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - } - } - ELSE IF( EQ_16( bwidth, FB ) ) - { - SWITCH( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, IVAS_128k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - IF( LE_32( total_brate, IVAS_48k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_MDCT: - IF( LE_32( total_brate, IVAS_128k ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - } - } - ELSE IF( bwidth == WB ) + return igfPresent; +} + +Word16 getIgfPresent_fx( + const Word16 element_mode, /* i : IVAS element mode */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +) +{ + Word16 igfPresent; + igfPresent = 0; + move16(); + + IF( EQ_16( bwidth, SWB ) ) + { + SWITCH( element_mode ) { - SWITCH( element_mode ) - { - case EVS_MONO: - case IVAS_SCE: - IF( LE_32( total_brate, ACELP_9k60 ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - case IVAS_CPE_DFT: - case IVAS_CPE_TD: - case IVAS_CPE_MDCT: - IF( LE_32( total_brate, ACELP_13k20 ) ) - { - igfPresent = 1; - move16(); - } - BREAK; - } + case EVS_MONO: + case IVAS_SCE: + if ( LE_32( total_brate, HQ_64k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( LE_32( total_brate, HQ_48k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + if ( LE_32( total_brate, IVAS_96k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; } - test(); - test(); - test(); - IF( ( ( EQ_16( bwidth, WB ) ) || ( EQ_16( bwidth, SWB ) ) ) && ( EQ_16( rf_mode, 1 ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) + } + ELSE IF( EQ_16( bwidth, FB ) ) + { + SWITCH( element_mode ) { - igfPresent = 1; - move16(); + case EVS_MONO: + case IVAS_SCE: + if ( LE_32( total_brate, IVAS_128k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + if ( LE_32( total_brate, IVAS_48k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_MDCT: + if ( LE_32( total_brate, IVAS_128k ) ) + { + igfPresent = 1; + move16(); + } + BREAK; } - - return igfPresent; } - /*-------------------------------------------------------------------* - * getCnaPresent() - * - * - *-------------------------------------------------------------------*/ - - int16_t getCnaPresent( - const int16_t element_mode, /* i : element mode */ - const int32_t element_brate, /* i : element bitrate */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bwidth /* i : audio bandwidth */ - ) + ELSE IF( EQ_16( bwidth, WB ) ) { - int16_t flag_cna = 0; - - if ( element_mode == IVAS_CPE_DFT && element_brate <= CNA_MAX_BRATE_DFT_STEREO ) + SWITCH( element_mode ) { - flag_cna = 1; + case EVS_MONO: + case IVAS_SCE: + if ( LE_32( total_brate, ACELP_9k60 ) ) + { + igfPresent = 1; + move16(); + } + BREAK; + case IVAS_CPE_DFT: + case IVAS_CPE_TD: + case IVAS_CPE_MDCT: + if ( LE_32( total_brate, ACELP_13k20 ) ) + { + igfPresent = 1; + move16(); + } + BREAK; } - else - { - if ( bwidth == NB && total_brate <= ACELP_13k20 ) - { - flag_cna = 1; - } + } + test(); + test(); + test(); + if ( ( ( EQ_16( bwidth, WB ) ) || ( EQ_16( bwidth, SWB ) ) ) && ( EQ_16( rf_mode, 1 ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) ) + { + igfPresent = 1; + move16(); + } - if ( bwidth == WB && total_brate <= ACELP_13k20 ) - { - flag_cna = 1; - } + return igfPresent; +} +/*-------------------------------------------------------------------* + * getCnaPresent() + * + * + *-------------------------------------------------------------------*/ - if ( bwidth == SWB && total_brate <= ACELP_13k20 ) - { - flag_cna = 1; - } - } +int16_t getCnaPresent( + const int16_t element_mode, /* i : element mode */ + const int32_t element_brate, /* i : element bitrate */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t bwidth /* i : audio bandwidth */ +) +{ + int16_t flag_cna = 0; - return flag_cna; + if ( element_mode == IVAS_CPE_DFT && element_brate <= CNA_MAX_BRATE_DFT_STEREO ) + { + flag_cna = 1; } - - Word16 getCnaPresent_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bwidth /* i : audio bandwidth */ - ) + else { - Word16 flag_cna = 0; - - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) + if ( bwidth == NB && total_brate <= ACELP_13k20 ) { flag_cna = 1; } - ELSE + + if ( bwidth == WB && total_brate <= ACELP_13k20 ) { - move16(); - test(); - IF( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) ) - { - flag_cna = 1; - move16(); - } + flag_cna = 1; } - return flag_cna; + if ( bwidth == SWB && total_brate <= ACELP_13k20 ) + { + flag_cna = 1; + } } - /*-------------------------------------------------------------------* - * getTcxLtp() - * - * - *-------------------------------------------------------------------*/ - Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ - ) - { - Word16 tcxltp = 0; + return flag_cna; +} + +Word16 getCnaPresent_fx( + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bwidth /* i : audio bandwidth */ +) +{ + Word16 flag_cna; + flag_cna = 0; + move16(); - tcxltp = 0; + test(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) + { + flag_cna = 1; move16(); + } + ELSE + { test(); - IF( ( LE_32( sr_core, 25600 ) ) ) + if ( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) ) { - tcxltp = 1; + flag_cna = 1; move16(); } + } - return tcxltp; + return flag_cna; +} +/*-------------------------------------------------------------------* + * getTcxLtp() + * + * + *-------------------------------------------------------------------*/ + +Word16 getTcxLtp( + const Word32 sr_core /* i : internal sampling rate */ +) +{ + Word16 tcxltp; + + tcxltp = 0; + move16(); + + if ( ( LE_32( sr_core, 25600 ) ) ) + { + tcxltp = 1; + move16(); } - /*-------------------------------------------------------------------* - * initPitchLagParameters() - * - * - *-------------------------------------------------------------------*/ + return tcxltp; +} + +/*-------------------------------------------------------------------* + * initPitchLagParameters() + * + * + *-------------------------------------------------------------------*/ + +Word16 initPitchLagParameters( + const Word32 sr_core, + Word16 *pit_min, + Word16 *pit_fr1, + Word16 *pit_fr1b, + Word16 *pit_fr2, + Word16 *pit_max ) +{ + Word16 pit_res_max; - Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max ) + IF( EQ_32( sr_core, INT_FS_12k8 ) ) + { + *pit_min = PIT_MIN_12k8; + move16(); + *pit_max = PIT_MAX_12k8; + move16(); + *pit_fr2 = PIT_FR2_12k8; + move16(); + *pit_fr1 = PIT_FR1_12k8; + move16(); + *pit_fr1b = PIT_FR1_8b_12k8; + move16(); + pit_res_max = 4; + move16(); + } + ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) + { + *pit_min = PIT_MIN_16k; + move16(); + *pit_max = PIT16k_MAX; + move16(); + *pit_fr2 = PIT_FR2_16k; + move16(); + *pit_fr1 = PIT_FR1_16k; + move16(); + *pit_fr1b = PIT_FR1_8b_16k; + move16(); + pit_res_max = 6; + move16(); + } + ELSE IF( EQ_32( sr_core, 25600 ) ) { - Word16 pit_res_max; + *pit_min = PIT_MIN_25k6; + move16(); + *pit_max = PIT_MAX_25k6; + move16(); + *pit_fr2 = PIT_FR2_25k6; + move16(); + *pit_fr1 = PIT_FR1_25k6; + move16(); + *pit_fr1b = PIT_FR1_8b_25k6; + move16(); + pit_res_max = 4; + move16(); + } + ELSE /* sr_core==32000 */ + { + *pit_min = PIT_MIN_32k; + move16(); + *pit_max = PIT_MAX_32k; + move16(); + *pit_fr2 = PIT_FR2_32k; + move16(); + *pit_fr1 = PIT_FR1_32k; + move16(); + *pit_fr1b = PIT_FR1_8b_32k; + move16(); + pit_res_max = 6; + move16(); + } - IF( EQ_32( sr_core, INT_FS_12k8 ) ) - { - *pit_min = PIT_MIN_12k8; - move16(); - *pit_max = PIT_MAX_12k8; - move16(); - *pit_fr2 = PIT_FR2_12k8; - move16(); - *pit_fr1 = PIT_FR1_12k8; - move16(); - *pit_fr1b = PIT_FR1_8b_12k8; - move16(); - pit_res_max = 4; - move16(); - } - ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) - { - *pit_min = PIT_MIN_16k; - move16(); - *pit_max = PIT16k_MAX; - move16(); - *pit_fr2 = PIT_FR2_16k; - move16(); - *pit_fr1 = PIT_FR1_16k; - move16(); - *pit_fr1b = PIT_FR1_8b_16k; - move16(); - pit_res_max = 6; - move16(); - } - ELSE IF( EQ_32( sr_core, 25600 ) ) - { - *pit_min = PIT_MIN_25k6; - move16(); - *pit_max = PIT_MAX_25k6; - move16(); - *pit_fr2 = PIT_FR2_25k6; - move16(); - *pit_fr1 = PIT_FR1_25k6; - move16(); - *pit_fr1b = PIT_FR1_8b_25k6; - move16(); - pit_res_max = 4; - move16(); - } - ELSE /* sr_core==32000 */ - { - *pit_min = PIT_MIN_32k; - move16(); - *pit_max = PIT_MAX_32k; + return pit_res_max; +} + +/*-------------------------------------------------------------------* + * getNumTcxCodedLines() + * + * + *-------------------------------------------------------------------*/ + +Word16 getNumTcxCodedLines( + const Word16 bwidth /* i : audio bandwidth */ +) +{ + Word16 tcx_coded_lines; + + tcx_coded_lines = 0; + move16(); + + SWITCH( bwidth ) + { + case NB: + tcx_coded_lines = 160; move16(); - *pit_fr2 = PIT_FR2_32k; + BREAK; + case WB: + tcx_coded_lines = 320; move16(); - *pit_fr1 = PIT_FR1_32k; + BREAK; + case SWB: + tcx_coded_lines = 640; move16(); - *pit_fr1b = PIT_FR1_8b_32k; + BREAK; + case FB: + tcx_coded_lines = 960; move16(); - pit_res_max = 6; + BREAK; + default: + tcx_coded_lines = 0; move16(); - } + BREAK; + } + + return tcx_coded_lines; +} - return pit_res_max; +/*-------------------------------------------------------------------* + * getTcxLpcShapedAri() + * + * + *-------------------------------------------------------------------*/ + +Word16 getTcxLpcShapedAri( + const Word32 total_brate, /* i : total bitrate */ + const Word16 rf_mode, /* i : flag to signal the RF mode */ + const Word16 element_mode /* i : IVAS element mode */ +) +{ + Word16 tcx_lpc_shaped_ari; + tcx_lpc_shaped_ari = 0; + move16(); + + test(); + test(); + test(); + test(); + if ( ( ( LE_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) || rf_mode ) + { + tcx_lpc_shaped_ari = 1; + move16(); } - /*-------------------------------------------------------------------* - * getNumTcxCodedLines() - * - * - *-------------------------------------------------------------------*/ + return tcx_lpc_shaped_ari; +} + - Word16 getNumTcxCodedLines( - const Word16 bwidth /* i : audio bandwidth */ - ) +/*-----------------------------------------------------------------------* + * init_tcx_window_cfg() + * + * Initialization of TCX windows + *-----------------------------------------------------------------------*/ + +void init_tcx_window_cfg( + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ + const int32_t sr_core, /* i : SR core */ + const int32_t input_Fs, /* i : input/output SR */ + const int16_t L_frame, /* i : L_frame at sr_core */ + const int16_t L_frameTCX, /* i : L_frame at i/o SR */ + const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */ + const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */ + const int16_t mdctWindowLength, /* i : window length at sr_core */ + const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */ + const int16_t element_mode /* i : mode of CPE/SCE */ +) +{ + /* Symmetric window = sine LD window*/ + hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; + hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; + hTcxCfg->tcx_mdct_window_length = mdctWindowLength; + hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; + + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_flt, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); + if ( hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB ) { - Word16 tcx_coded_lines; + mvr2r( hTcxCfg->tcx_mdct_window_flt, hTcxCfg->tcx_mdct_windowFB_flt, hTcxCfg->tcx_mdct_window_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_windowFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); + } - tcx_coded_lines = 0; - move16(); + /*ALDO windows for MODE2*/ + mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_flt, hTcxCfg->tcx_aldo_window_2_flt, L_frame ); + mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_FB_flt, hTcxCfg->tcx_aldo_window_2_FB_flt, NS2SA( input_Fs, FRAME_SIZE_NS ) ); + hTcxCfg->tcx_aldo_window_1_trunc_flt = hTcxCfg->tcx_aldo_window_1_flt + NS2SA( sr_core, N_ZERO_MDCT_NS ); + hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( input_Fs, N_ZERO_MDCT_NS ); + + /*1.25ms transition window for ACELP->TCX*/ + hTcxCfg->tcx_mdct_window_trans_length = NS2SA( sr_core, ACELP_TCX_TRANS_NS ); + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_trans_flt, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA( input_Fs, ACELP_TCX_TRANS_NS ); + if ( hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_trans_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_transFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); + } - SWITCH( bwidth ) - { - case NB: - tcx_coded_lines = 160; - BREAK; - case WB: - tcx_coded_lines = 320; - BREAK; - case SWB: - tcx_coded_lines = 640; - BREAK; - case FB: - tcx_coded_lines = 960; - BREAK; - default: - tcx_coded_lines = 0; - BREAK; - } + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + hTcxCfg->tcx_mdct_window_half_length = 2 * ( ( encoderLookahead_enc - (int16_t) ( 0.005f * sr_core + 0.5f ) ) >> 1 ); + hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ( ( encoderLookahead_FB - (int16_t) ( 0.005f * input_Fs + 0.5f ) ) >> 1 ); + assert( ( hTcxCfg->tcx_mdct_window_half_length > 16 ) && "Half window can not be large enough!" ); - return tcx_coded_lines; + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_half_flt, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); + if ( hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_half_flt, hTcxCfg->tcx_mdct_window_halfFB_flt, hTcxCfg->tcx_mdct_window_half_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_halfFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); } - /*-------------------------------------------------------------------* - * getTcxLpcShapedAri() - * - * - *-------------------------------------------------------------------*/ + /* minimum overlap 1.25 ms */ + hTcxCfg->tcx_mdct_window_min_length = (int16_t) ( sr_core * INV_CLDFB_BANDWIDTH ); + hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH ); + /* save complexity by copying the small windows if they have the same length */ + if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length ) + { + mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_min_length ); + } + else + { + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimum_flt, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); + } - Word16 getTcxLpcShapedAri( - const Word32 total_brate, /* i : total bitrate */ - const Word16 rf_mode, /* i : flag to signal the RF mode */ - const Word16 element_mode /* i : IVAS element mode */ - ) + if ( hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); + } + else if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB ) + { + mvr2r( hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); + } + else { - Word16 tcx_lpc_shaped_ari = 0; + mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimumFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); + } - move16(); - test(); - test(); - test(); - IF( ( ( LE_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) || rf_mode ) - { - tcx_lpc_shaped_ari = 1; - move16(); - } + /* TCX Offset */ + hTcxCfg->tcx_offset = ( hTcxCfg->tcx_mdct_window_delay >> 1 ); + hTcxCfg->tcx_offsetFB = ( hTcxCfg->tcx_mdct_window_delayFB >> 1 ); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4; + hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4; - return tcx_lpc_shaped_ari; - } - - - /*-----------------------------------------------------------------------* - * init_tcx_window_cfg() - * - * Initialization of TCX windows - *-----------------------------------------------------------------------*/ - - void init_tcx_window_cfg( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const int32_t sr_core, /* i : SR core */ - const int32_t input_Fs, /* i : input/output SR */ - const int16_t L_frame, /* i : L_frame at sr_core */ - const int16_t L_frameTCX, /* i : L_frame at i/o SR */ - const int16_t encoderLookahead_enc, /* i : encoder LA at sr_core */ - const int16_t encoderLookahead_FB, /* i : encoder LA at i/o SR */ - const int16_t mdctWindowLength, /* i : window length at sr_core */ - const int16_t mdctWindowLengthFB, /* i : window length at i/o SR */ - const int16_t element_mode /* i : mode of CPE/SCE */ - ) - { - /* Symmetric window = sine LD window*/ - hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; - hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; - hTcxCfg->tcx_mdct_window_length = mdctWindowLength; - hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; - - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_flt, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); - if ( hTcxCfg->tcx_mdct_window_length == hTcxCfg->tcx_mdct_window_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_flt, hTcxCfg->tcx_mdct_windowFB_flt, hTcxCfg->tcx_mdct_window_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_windowFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); - } + return; +} - /*ALDO windows for MODE2*/ - mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_flt, hTcxCfg->tcx_aldo_window_2_flt, L_frame ); - mdct_window_aldo_flt( hTcxCfg->tcx_aldo_window_1_FB_flt, hTcxCfg->tcx_aldo_window_2_FB_flt, NS2SA( input_Fs, FRAME_SIZE_NS ) ); - hTcxCfg->tcx_aldo_window_1_trunc_flt = hTcxCfg->tcx_aldo_window_1_flt + NS2SA( sr_core, N_ZERO_MDCT_NS ); - hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( input_Fs, N_ZERO_MDCT_NS ); - - /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA( sr_core, ACELP_TCX_TRANS_NS ); - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_trans_flt, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA( input_Fs, ACELP_TCX_TRANS_NS ); - if ( hTcxCfg->tcx_mdct_window_trans_length == hTcxCfg->tcx_mdct_window_trans_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_trans_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_transFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); - } +/*-----------------------------------------------------------------------* + * init_tcx() + * + * Initialization of TCX + *-----------------------------------------------------------------------*/ + +void init_tcx_cfg( + TCX_CONFIG_HANDLE hTcxCfg, + const int32_t total_brate, + const int32_t sr_core, + const int32_t input_Fs, + const int16_t L_frame, + const int16_t bwidth, + const int16_t L_frameTCX, + const int16_t fscale, + const int16_t encoderLookahead_enc, + const int16_t encoderLookahead_FB, + const float preemph_fac, + const int16_t tcxonly, + const int16_t rf_mode, + const int16_t igf, + const int16_t infoIGFStopFreq, + const int16_t element_mode, + const int16_t ini_frame, + const int16_t MCT_flag ) +{ + int16_t i; + int16_t mdctWindowLength; + int16_t mdctWindowLengthFB; + int16_t na_scale_bwidth; - /*Mid-OLA*/ - /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = 2 * ( ( encoderLookahead_enc - (int16_t) ( 0.005f * sr_core + 0.5f ) ) >> 1 ); - hTcxCfg->tcx_mdct_window_half_lengthFB = 2 * ( ( encoderLookahead_FB - (int16_t) ( 0.005f * input_Fs + 0.5f ) ) >> 1 ); - assert( ( hTcxCfg->tcx_mdct_window_half_length > 16 ) && "Half window can not be large enough!" ); + hTcxCfg->preemph_fac_flt = preemph_fac; + hTcxCfg->tcx5Size = NS2SA( sr_core, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ + hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_half_flt, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); - if ( hTcxCfg->tcx_mdct_window_half_length == hTcxCfg->tcx_mdct_window_half_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_half_flt, hTcxCfg->tcx_mdct_window_halfFB_flt, hTcxCfg->tcx_mdct_window_half_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_halfFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); - } + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + mdctWindowLength = getMdctWindowLength( fscale ); + mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); - /* minimum overlap 1.25 ms */ - hTcxCfg->tcx_mdct_window_min_length = (int16_t) ( sr_core * INV_CLDFB_BANDWIDTH ); - hTcxCfg->tcx_mdct_window_min_lengthFB = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH ); - /* save complexity by copying the small windows if they have the same length */ - if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_trans_length ) - { - mvr2r( hTcxCfg->tcx_mdct_window_trans_flt, hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_min_length ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimum_flt, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); - } + init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); - if ( hTcxCfg->tcx_mdct_window_min_lengthFB == hTcxCfg->tcx_mdct_window_trans_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_transFB_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); - } - else if ( hTcxCfg->tcx_mdct_window_min_length == hTcxCfg->tcx_mdct_window_min_lengthFB ) - { - mvr2r( hTcxCfg->tcx_mdct_window_minimum_flt, hTcxCfg->tcx_mdct_window_minimumFB_flt, hTcxCfg->tcx_mdct_window_min_lengthFB ); - } - else - { - mdct_window_sine_flt( hTcxCfg->tcx_mdct_window_minimumFB_flt, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); - } + /* SQ deadzone & memory quantization*/ + hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - /* TCX Offset */ - hTcxCfg->tcx_offset = ( hTcxCfg->tcx_mdct_window_delay >> 1 ); - hTcxCfg->tcx_offsetFB = ( hTcxCfg->tcx_mdct_window_delayFB >> 1 ); - /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - hTcxCfg->lfacNext = hTcxCfg->tcx_offset - L_frame / 4; - hTcxCfg->lfacNextFB = hTcxCfg->tcx_offsetFB - L_frameTCX / 4; - - return; - } - - /*-----------------------------------------------------------------------* - * init_tcx() - * - * Initialization of TCX - *-----------------------------------------------------------------------*/ - - void init_tcx_cfg( - TCX_CONFIG_HANDLE hTcxCfg, - const int32_t total_brate, - const int32_t sr_core, - const int32_t input_Fs, - const int16_t L_frame, - const int16_t bwidth, - const int16_t L_frameTCX, - const int16_t fscale, - const int16_t encoderLookahead_enc, - const int16_t encoderLookahead_FB, - const float preemph_fac, - const int16_t tcxonly, - const int16_t rf_mode, - const int16_t igf, - const int16_t infoIGFStopFreq, - const int16_t element_mode, - const int16_t ini_frame, - const int16_t MCT_flag ) - { - int16_t i; - int16_t mdctWindowLength; - int16_t mdctWindowLengthFB; - int16_t na_scale_bwidth; - - hTcxCfg->preemph_fac_flt = preemph_fac; - hTcxCfg->tcx5Size = NS2SA( sr_core, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = NS2SA( input_Fs, FRAME_SIZE_NS / 4 ); /* Always 5 ms */ - - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - mdctWindowLength = getMdctWindowLength( fscale ); - mdctWindowLengthFB = (int16_t) ( mdctWindowLength * input_Fs / sr_core ); - - init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode ); - - /* SQ deadzone & memory quantization*/ - hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - - /* TCX rate loop */ - hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; - hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; - - /* TCX bandwidth */ - hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); - - /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); - - /* TNS in TCX */ - hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); - - if ( hTcxCfg->fIsTNSAllowed ) - { - InitTnsConfigs_flt( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); + /* TCX rate loop */ + hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0; + hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; - SetAllowTnsOnWhite_flt( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); - } + /* TCX bandwidth */ + hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); - if ( ini_frame == 0 ) - { - hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - hTcxCfg->last_aldo = 1; - } + /* set number of coded lines */ + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); - /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + /* TNS in TCX */ + hTcxCfg->pCurrentTnsConfig = NULL; + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); - /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); - hTcxCfg->tcxRateLoopOpt = ( hTcxCfg->resq && !tcxonly ) ? 1 : hTcxCfg->tcxRateLoopOpt; + if ( hTcxCfg->fIsTNSAllowed ) + { + InitTnsConfigs_flt( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - /*Set bandwidth scale*/ - if ( bwidth == NB ) - { - na_scale_bwidth = NB; - } - else if ( sr_core <= INT_FS_16k ) - { - na_scale_bwidth = WB; - } - else - { - na_scale_bwidth = SWB; - } + SetAllowTnsOnWhite_flt( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); + } + + if ( ini_frame == 0 ) + { + hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + hTcxCfg->last_aldo = 1; + } + + /* Context HM*/ + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + + /* Residual Coding*/ + hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->tcxRateLoopOpt = ( hTcxCfg->resq && !tcxonly ) ? 1 : hTcxCfg->tcxRateLoopOpt; + + /*Set bandwidth scale*/ + if ( bwidth == NB ) + { + na_scale_bwidth = NB; + } + else if ( sr_core <= INT_FS_16k ) + { + na_scale_bwidth = WB; + } + else + { + na_scale_bwidth = SWB; + } - /* Scale TCX for non-active frames to adjust loudness with ACELP*/ - hTcxCfg->na_scale_flt = 1.f; + /* Scale TCX for non-active frames to adjust loudness with ACELP*/ + hTcxCfg->na_scale_flt = 1.f; - if ( na_scale_bwidth < SWB && !tcxonly ) + if ( na_scale_bwidth < SWB && !tcxonly ) + { + for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) { - for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) + if ( ( na_scale_bwidth == scaleTcxTable[i].bwmode ) && + ( total_brate >= scaleTcxTable[i].bitrateFrom ) && + ( total_brate < scaleTcxTable[i].bitrateTo ) ) { - if ( ( na_scale_bwidth == scaleTcxTable[i].bwmode ) && - ( total_brate >= scaleTcxTable[i].bitrateFrom ) && - ( total_brate < scaleTcxTable[i].bitrateTo ) ) + if ( rf_mode ) { - if ( rf_mode ) - { - i--; - } - hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; - break; + i--; } + hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt; + break; } } + } - if ( tcxonly ) - { - InitPsychLPC( sr_core, L_frame, hTcxCfg ); - } - else - { - hTcxCfg->psychParamsCurrent = NULL; - } - - return; + if ( tcxonly ) + { + InitPsychLPC( sr_core, L_frame, hTcxCfg ); } + else + { + hTcxCfg->psychParamsCurrent = NULL; + } + + return; +} #ifdef IVAS_FLOAT_FIXED - void init_tcx_window_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ - const Word32 sr_core, /* i : SR core */ - const Word32 input_Fs, /* i : input/output SR */ - const Word16 L_frame, /* i : L_frame at sr_core */ - const Word16 L_frameTCX, /* i : L_frame at i/o SR */ - const Word16 mdctWindowLength, /* i : window length at sr_core */ - const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ - const Word16 element_mode /* i : mode of CPE/SCE */ - ) - { - /* Symmetric window = sine LD window*/ - hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; - hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; - hTcxCfg->tcx_mdct_window_length = mdctWindowLength; - hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); - - IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, hTcxCfg->tcx_mdct_window_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); - } +void init_tcx_window_cfg_fx( + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle */ + const Word32 sr_core, /* i : SR core */ + const Word32 input_Fs, /* i : input/output SR */ + const Word16 L_frame, /* i : L_frame at sr_core */ + const Word16 L_frameTCX, /* i : L_frame at i/o SR */ + const Word16 mdctWindowLength, /* i : window length at sr_core */ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR */ + const Word16 element_mode /* i : mode of CPE/SCE */ +) +{ + /* Symmetric window = sine LD window*/ + hTcxCfg->tcx_mdct_window_delay = mdctWindowLength; + hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB; + hTcxCfg->tcx_mdct_window_length = mdctWindowLength; + hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB; + move16(); + move16(); + move16(); + move16(); + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode ); - /*ALDO windows for MODE2*/ - mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame ); - mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_fx2( input_Fs, FRAME_SIZE_NS ) ); + IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode ); + } - /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA_fx2( sr_core, ACELP_TCX_TRANS_NS ); - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); - hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_fx2( input_Fs, ACELP_TCX_TRANS_NS ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_trans_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); - } - /*Mid-OLA*/ - /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ - hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); - hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_fx2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); - assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); - - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_half_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); - } + /*ALDO windows for MODE2*/ + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame ); + mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_FX2( input_Fs, FRAME_SIZE_NS ) ); - /* minimum overlap 1.25 ms */ - hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ - hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ - /* save complexity by copying the small windows if they have the same length */ - IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); - } + /*1.25ms transition window for ACELP->TCX*/ + hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); + move16(); + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); + move16(); + IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode ); + } + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); + hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA_FX2( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); + move16(); + move16(); + assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); - IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); - } - ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) - { - Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_min_lengthFB / 2 ); - } - ELSE - { - mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); - } - /* TCX Offset */ - hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); - hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); - /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); - hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); - - return; - } - - void init_tcx_cfg_fx( - TCX_CONFIG_HANDLE hTcxCfg, - const Word32 total_brate, - const Word32 sr_core, - const Word32 input_Fs, - const Word16 L_frame, - const Word16 bwidth, - const Word16 L_frameTCX, - const Word16 fscale, - const Word16 preemph_fac, - const Word16 tcxonly, - const Word16 rf_mode, - const Word16 igf, - const Word16 infoIGFStopFreq, - const Word16 element_mode, - const Word16 ini_frame, - const Word16 MCT_flag, - const Word16 fscaleFB ) - { - Word16 i; - Word16 mdctWindowLength; - Word16 mdctWindowLengthFB; - Word16 na_scale_bwidth; - - hTcxCfg->preemph_fac = preemph_fac; - move16(); + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode ); + IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode ); + } - hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ - hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + /* minimum overlap 1.25 ms */ + hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + move16(); + move16(); + /* save complexity by copying the small windows if they have the same length */ + IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode ); + } - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; - move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); - mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); - init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); - /* SQ deadzone & memory quantization*/ - hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - move16(); + IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + } + ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) ) + { + Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + } + ELSE + { + mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode ); + } + /* TCX Offset */ + hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); + hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) ); + hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) ); + move16(); + move16(); + move16(); + move16(); - /* TCX rate loop */ - hTcxCfg->tcxRateLoopOpt = 0; - move16(); + return; +} - IF( tcxonly != 0 ) - { - hTcxCfg->tcxRateLoopOpt = 2; - move16(); - } - IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) +void init_tcx_cfg_fx( + TCX_CONFIG_HANDLE hTcxCfg, + const Word32 total_brate, + const Word32 sr_core, + const Word32 input_Fs, + const Word16 L_frame, + const Word16 bwidth, + const Word16 L_frameTCX, + const Word16 fscale, + const Word16 preemph_fac, + const Word16 tcxonly, + const Word16 rf_mode, + const Word16 igf, + const Word16 infoIGFStopFreq, + const Word16 element_mode, + const Word16 ini_frame, + const Word16 MCT_flag, + const Word16 fscaleFB ) +{ + Word16 i; + Word16 mdctWindowLength; + Word16 mdctWindowLengthFB; + Word16 na_scale_bwidth; + + hTcxCfg->preemph_fac = preemph_fac; + move16(); + + hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms */ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */ + move16(); + move16(); + + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + move16(); + mdctWindowLength = getMdctWindowLength_fx( fscale ); + mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); + init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); + /* SQ deadzone & memory quantization*/ + hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + move16(); + + /* TCX rate loop */ + hTcxCfg->tcxRateLoopOpt = 0; + move16(); + + if ( tcxonly != 0 ) + { + hTcxCfg->tcxRateLoopOpt = 2; + move16(); + } + if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { hTcxCfg->tcxRateLoopOpt = 3; - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); move16(); + } + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + move16(); - /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + /* set number of coded lines */ + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + move16(); - /* TNS in TCX */ - hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + /* TNS in TCX */ + hTcxCfg->pCurrentTnsConfig = NULL; + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + move16(); - IF( hTcxCfg->fIsTNSAllowed ) - { - InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); + IF( hTcxCfg->fIsTNSAllowed ) + { + InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - SetAllowTnsOnWhite( hTcxCfg->tnsConfig, element_mode == IVAS_CPE_MDCT ); - } + SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); + } - IF( ini_frame == 0 ) - { - hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - hTcxCfg->last_aldo = 1; - } + IF( ini_frame == 0 ) + { + hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + hTcxCfg->last_aldo = 1; + move16(); + move16(); + move16(); + } - /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + /* Context HM*/ + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + move16(); - /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); - IF( hTcxCfg->resq && !tcxonly ) - { - hTcxCfg->tcxRateLoopOpt = 1; - move16(); - } + /* Residual Coding*/ + hTcxCfg->resq = getResq( total_brate ); + move16(); + test(); + if ( hTcxCfg->resq && !tcxonly ) + { + hTcxCfg->tcxRateLoopOpt = 1; + move16(); + } - /*Set bandwidth scale*/ - IF( EQ_16( bwidth, NB ) ) - { - na_scale_bwidth = NB; - } - ELSE IF( LE_32( sr_core, INT_FS_16k ) ) - { - na_scale_bwidth = WB; - } - ELSE - { - na_scale_bwidth = SWB; - } - hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + /*Set bandwidth scale*/ + IF( bwidth == NB ) + { + na_scale_bwidth = NB; + } + ELSE IF( LE_32( sr_core, INT_FS_16k ) ) + { + na_scale_bwidth = WB; + } + ELSE + { + na_scale_bwidth = SWB; + } + move16(); + hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); - IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly ) + test(); + IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly ) + { + FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) { - FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) + test(); + test(); + IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) && + ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && + ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) && - ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && - ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) + if ( rf_mode ) { - IF( rf_mode ) - { - i--; - } - hTcxCfg->na_scale = scaleTcxTable[i].scale; - BREAK; + i = sub( i, 1 ); } + hTcxCfg->na_scale = scaleTcxTable[i].scale; + move16(); + BREAK; } } + } - IF( tcxonly ) - { - InitPsychLPC( sr_core, L_frame, hTcxCfg ); - } - ELSE - { - hTcxCfg->psychParamsCurrent = NULL; - } - - return; + IF( tcxonly ) + { + InitPsychLPC( sr_core, L_frame, hTcxCfg ); + } + ELSE + { + hTcxCfg->psychParamsCurrent = NULL; } + + return; +} #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/count.c b/lib_com/count.c index 999229e3d8194d95b5250985f874c142a87da56b..e2c2ba8ee804e58da86326a02f84b3e2fc96a349 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -46,23 +46,51 @@ #include #include #include -#include "stl.h" #include +#include "stl.h" +#include "options.h" +#include "wmc_auto.h" + +#define WMC_TOOL_SKIP #ifdef WMOPS static double frameRate = FRAME_RATE; /* default value : 10 ms */ -#endif /* ifdef WMOPS */ -#ifdef WMOPS +#define MAX_RECORDS 1024 +#define MAX_STACK 64 +#define MAX_CHAR 64 + +// struct wmops_record +//{ +// char label[MAX_CHAR]; +// long call_number; +// long update_cnt; +// int call_tree[MAX_RECORDS]; +// double start_selfcnt; +// double current_selfcnt; +// double max_selfcnt; +// double min_selfcnt; +// double tot_selfcnt; +// double start_cnt; /* The following take into account the decendants */ +// double current_cnt; +// double max_cnt; +// double min_cnt; +// double tot_cnt; +// }; +// +// static struct wmops_record wmops[MAX_RECORDS]; + +static int stack[MAX_STACK]; +static int sptr; +static int sum_stack[MAX_STACK]; + /* Global counter variable for calculation of complexity weight */ /* Some enhancement written by Vail., GJR and M.Mul. during EVS time */ BASIC_OP multiCounter[MAXCOUNTERS]; BASIC_OP glob_multiCounter; int currCounter = 0; /* Zero equals global counter */ -#endif /* ifdef WMOPS */ -#ifdef WMOPS void setFrameRate( int samplingFreq, int frameLength ) { if ( frameLength > 0 ) @@ -72,9 +100,7 @@ void setFrameRate( int samplingFreq, int frameLength ) return; } -#endif /* ifdef WMOPS */ -#ifdef WMOPS /* * Below list is used for displaying the code profiling information in * the file which name is defined by CODE_PROFILE_FILENAME. @@ -142,10 +168,8 @@ char *BasicOperationList[] = { #endif /* #ifdef CONTROL_CODE_OPS */ }; -#endif /* ifdef WMOPS */ -#ifdef WMOPS const BASIC_OP op_weight = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -297,9 +321,9 @@ static char *my_strdup( const char *s ) #endif /* ifdef WMOPS */ -int getCounterId( char *objectNameArg ) +int getCounterId( const char *objectNameArg ) { -#if WMOPS +#ifdef WMOPS if ( maxCounter >= MAXCOUNTERS - 1 ) return 0; objectName[++maxCounter] = my_strdup( objectNameArg ); @@ -313,7 +337,7 @@ int getCounterId( char *objectNameArg ) } -#if WMOPS +#ifdef WMOPS int readCounterId() { return currCounter; @@ -330,7 +354,7 @@ char *readCounterIdName() void setCounter( int counterId ) { -#if WMOPS +#ifdef WMOPS if ( ( counterId > maxCounter ) || ( counterId < 0 ) ) { currCounter = 0; @@ -346,7 +370,7 @@ void setCounter( int counterId ) void incrementNbTimeObjectIsCalled( int counterId ) { -#if WMOPS +#ifdef WMOPS if ( ( counterId > maxCounter ) || ( counterId < 0 ) ) { nbTimeObjectIsCalled[0]++; @@ -359,7 +383,7 @@ void incrementNbTimeObjectIsCalled( int counterId ) } -#if WMOPS +#ifdef WMOPS static Word32 WMOPS_frameStat( void ) { /* calculate the WMOPS seen so far and update the global @@ -411,7 +435,7 @@ static void WMOPS_clearMultiCounter( void ) void ClearNbTimeObjectsAreCalled() { -#if WMOPS +#ifdef WMOPS Word16 i; for ( i = 0; i < (Word16) ( sizeof( multiCounter[currCounter] ) / sizeof( Word32 ) ); i++ ) @@ -423,13 +447,14 @@ void ClearNbTimeObjectsAreCalled() Word32 TotalWeightedOperation() { -#if WMOPS +#ifdef WMOPS Word16 i; - Word32 tot, *ptr, *ptr2; + Word32 tot, *ptr; + const Word32 *ptr2; tot = 0; ptr = (Word32 *) &multiCounter[currCounter]; - ptr2 = (Word32 *) &op_weight; + ptr2 = (const Word32 *) &op_weight; for ( i = 0; i < (Word16) ( sizeof( multiCounter[currCounter] ) / sizeof( Word32 ) ); i++ ) { tot += ( ( *ptr++ ) * ( *ptr2++ ) ); @@ -445,7 +470,7 @@ Word32 TotalWeightedOperation() Word32 DeltaWeightedOperation() { -#if WMOPS +#ifdef WMOPS Word32 NewWOper, delta; NewWOper = TotalWeightedOperation(); @@ -462,7 +487,7 @@ Word32 DeltaWeightedOperation() void Init_WMOPS_counter( void ) { -#if WMOPS +#ifdef WMOPS Word16 i; /* reset function weight operation counter variable */ @@ -507,7 +532,7 @@ void Init_WMOPS_counter( void ) Word32 Reset_WMOPS_counter( void ) { -#if WMOPS +#ifdef WMOPS Word32 tot = WMOPS_frameStat(); /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ @@ -535,7 +560,7 @@ Word32 Reset_WMOPS_counter( void ) Word32 fwc( void ) { /* function worst case */ -#if WMOPS +#ifdef WMOPS Word32 tot; tot = DeltaWeightedOperation(); @@ -561,7 +586,7 @@ Word32 fwc( void ) void WMOPS_output( Word16 dtx_mode ) { -#if WMOPS +#ifdef WMOPS Word16 i; Word32 tot, tot_wm, tot_wc; @@ -596,7 +621,7 @@ void WMOPS_output( Word16 dtx_mode ) void WMOPS_output_avg( Word16 dtx_mode, Word32 *tot_wm, Word32 *num_frames ) { -#if WMOPS +#ifdef WMOPS Word16 i; Word32 tot, tot_wc; @@ -632,10 +657,11 @@ void WMOPS_output_avg( Word16 dtx_mode, Word32 *tot_wm, Word32 *num_frames ) void generic_WMOPS_output( Word16 dtx_mode, char *test_file_name ) { -#if WMOPS +#ifdef WMOPS int saved_value; Word16 i; - Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; + Word32 tot, tot_wm, tot_wc, *ptr; + const Word32 *ptr2; Word40 grand_total; FILE *WMOPS_file; @@ -744,7 +770,7 @@ void generic_WMOPS_output( Word16 dtx_mode, char *test_file_name ) tot = 0; ptr = (Word32 *) &multiCounter[0] + i; - ptr2 = (Word32 *) &op_weight + i; + ptr2 = (const Word32 *) &op_weight + i; for ( currCounter = 0; currCounter <= maxCounter; currCounter++ ) { tot += ( ( *ptr ) * ( *ptr2 ) ); @@ -777,17 +803,11 @@ void generic_WMOPS_output( Word16 dtx_mode, char *test_file_name ) } /* FROM_EVS_DEV */ -#define MAX_STACK 64 -#if WMOPS -static int stack[MAX_STACK]; -static int sptr; -static int sum_stack[MAX_STACK]; -#endif /* jdr 20120117: add FLC similar functions */ void BASOP_frame_update( void ) { -#if WMOPS +#ifdef WMOPS int i, current; #if MAX_CALLERS_SAVED_FRAMES int k; @@ -907,7 +927,7 @@ void BASOP_frame_update( void ) void printStack( char *text, char *Id ) { -#if WMOPS +#ifdef WMOPS int i; if ( !Id ) return; @@ -927,7 +947,7 @@ void printStack( char *text, char *Id ) void BASOP_push_wmops( const char *label ) { -#if WMOPS +#ifdef WMOPS int new_flag, prev_counter; int i, j; @@ -1004,7 +1024,7 @@ void BASOP_push_wmops( const char *label ) Word32 BASOP_pop_wmops( void ) { -#if WMOPS +#ifdef WMOPS Word32 ops_cnt; #ifdef DEBUG_COUNTER @@ -1050,17 +1070,10 @@ Word32 BASOP_get_wops( void ) return BASOP_pop_wmops(); } -#define FRAMES_PER_SECOND 50.0 -#define MILLION_CYCLES 1e6 -#define FAC ( FRAMES_PER_SECOND / MILLION_CYCLES ) - -#if WMOPS -static Word32 prom_cnt = 0; -#endif void WMOPS_destroy( void ) { -#if WMOPS +#ifdef WMOPS int i; /* release the memory allocated for the objectName array */ @@ -1068,7 +1081,7 @@ void WMOPS_destroy( void ) { if ( NULL != objectName[i] ) { - free( objectName[i] ); + free_( objectName[i] ); objectName[i] = NULL; } } @@ -1082,7 +1095,7 @@ void WMOPS_destroy( void ) void WMOPS_output_all( Word16 dtx_mode ) { -#if WMOPS +#ifdef WMOPS float ops_cnt = 0.0f; int i; @@ -1091,7 +1104,6 @@ void WMOPS_output_all( Word16 dtx_mode ) char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - fprintf( stderr, "\nProgram Memory Analysis: %12.0f words\n", (float) prom_cnt ); /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ fprintf( stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int) nbframe[0] ); /* added -- JPA */ for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) @@ -1236,7 +1248,7 @@ void WMOPS_output_all( Word16 dtx_mode ) } void WMOPS_output_all_std( Word16 dtx_mode ) { -#if WMOPS +#ifdef WMOPS float ops_cnt = 0.0f; int i; @@ -1245,7 +1257,6 @@ void WMOPS_output_all_std( Word16 dtx_mode ) char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - fprintf( stdout, "\nProgram Memory Analysis: %12.0f words\n", (float) prom_cnt ); /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ fprintf( stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int) nbframe[0] ); /* added -- JPA */ if ( nbframe[0] > 0 ) @@ -1338,7 +1349,7 @@ void WMOPS_output_all_std( Word16 dtx_mode ) void Reset_all_WMOPS_counter( void ) { -#if WMOPS +#ifdef WMOPS int i; int currCounterSave; @@ -1359,7 +1370,7 @@ void Reset_all_WMOPS_counter( void ) /* Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ void BASOP_get_total_wmops( double *min, double *max, double *avg ) { -#if WMOPS +#ifdef WMOPS if ( min != NULL ) *min = frameRate * glob_bc[0]; if ( max != NULL ) @@ -1378,3 +1389,4 @@ void BASOP_get_total_wmops( double *min, double *max, double *avg ) UNUSED_PARAM( avg ); } /* end of file */ +#undef WMC_TOOL_SKIP diff --git a/lib_com/count.h b/lib_com/count.h index 1e5cd840840d2524c2c5db2d0798430044d2db73..10e96e44fad77b519fa544389b64623cad14b4be 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -60,12 +60,13 @@ #ifndef _COUNT_H #define _COUNT_H "$Id$" -/*#define WMOPS 1*/ /* <<<- enable or disable WMOPS profiling features here */ +#include + #define MAXCOUNTERS ( 512 ) #define MAX_CALLERS_SAVED_FRAMES 5 /* # of Frame for which WMOPS Complexity Details will be saved, 0 = Disabled */ -int getCounterId( char *objectName ); +int getCounterId( const char *objectName ); /* * Create a counter group, the "objectname" will be used when printing * statistics for this counter group. @@ -586,30 +587,6 @@ void BASOP_get_total_wmops( double *min, double *max, double *avg ); #define END_SUB_WMOPS BASOP_sub_end() -#if !defined WMOPS_FL //&& defined WMOPS -#include -#define reset_wmops() BASOP_init -// extern int cntr_push_pop; -#define push_wmops( x ) \ - { \ - BASOP_push_wmops( x ); \ - } -#define pop_wmops() \ - { \ - BASOP_pop_wmops(); \ - } -#define update_wmops() \ - { \ - BASOP_frame_update(); \ - } -#define print_wmops() \ - { \ - WMOPS_output_all_std( 0 ); \ - } -#define update_mem() ; -#endif - - #endif /* _COUNT_H */ diff --git a/lib_com/deemph.c b/lib_com/deemph.c index a746d326ea57e84ee76d6f36ad703270b7a8ac49..9583a79d4c21627746d37604084611bbbccc0dc1 100644 --- a/lib_com/deemph.c +++ b/lib_com/deemph.c @@ -38,8 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * deemph() * @@ -79,13 +78,16 @@ void deemph_fx_32( Word32 *mem /* i/o: memory (y[-1]) Qx*/ ) { - int16_t i; + Word16 i; signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); + move32(); FOR( i = 1; i < L; i++ ) { signal[i] = L_add( signal[i], Mpy_32_16_1( signal[i - 1], mu ) ); signal[i] = L_shl( signal[i], shift ); + move32(); + move32(); } *mem = signal[L - 1]; @@ -125,7 +127,9 @@ void deemph_fx( Word16 i; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow; + Overflow = 0; + move32(); #endif L_tmp = L_deposit_h( signal[0] ); @@ -136,6 +140,7 @@ void deemph_fx( L_tmp = L_mac( L_tmp, *mem, mu ); signal[0] = round_fx( L_tmp ); #endif + move16(); FOR( i = 1; i < L; i++ ) { @@ -147,6 +152,7 @@ void deemph_fx( L_tmp = L_mac( L_tmp, signal[i - 1], mu ); signal[i] = round_fx( L_tmp ); #endif /* BASOP_NOGLOB */ + move16(); } *mem = signal[L - 1]; @@ -169,7 +175,9 @@ void Deemph2( Word16 i; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow; + Overflow = 0; + move32(); #endif /* saturation can occur in L_mac() */ @@ -215,7 +223,9 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W Word16 i; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow; + Overflow = 0; + move32(); #endif /* signal[0] = signal[0] + mu * (*mem); */ @@ -232,6 +242,7 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); x[i] = round_fx( L_tmp ); #endif + move16(); } } ELSE @@ -245,6 +256,7 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), shr( x[i], shift ), -32768 ); x[i] = round_fx( L_tmp ); #endif + move16(); } } diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 0c0beef9ec54164b276fef2e0b9fa77a2ac94c0f..c1e1e869ccf7edaffd278c77435f785e950ce39c 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -39,8 +39,7 @@ #include "prot.h" #include "ivas_cnst.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------------- * get_delay() @@ -124,10 +123,11 @@ Word32 get_delay_fx( /* o : delay value in ms #endif ) { - Word32 delay = 0; + Word32 delay; + delay = 0; move32(); - IF( EQ_16( what_delay, ENC ) ) + IF( what_delay == ENC ) { IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ { @@ -139,14 +139,14 @@ Word32 get_delay_fx( /* o : delay value in ms delay = IVAS_ENC_DELAY_NS; move32(); test(); - IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { delay = 0; /* All delay is compensated in the decoder with MASA */ move32(); } } test(); - IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + if ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { /* compensate for DirAC/SPAR filterbank delay */ delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); @@ -177,7 +177,7 @@ Word32 get_delay_fx( /* o : delay value in ms IF( NE_16( output_config, AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) { #endif - IF( hCldfb != NULL ) + if ( hCldfb != NULL ) { /* compensate for filterbank delay */ delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); @@ -186,7 +186,7 @@ Word32 get_delay_fx( /* o : delay value in ms } #endif test(); - IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ } diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index 63391f6d004b2c2dba98a219b0566d6135659515..be4b2769671f470b500ca229cf0c41b6120c384d 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -6,8 +6,7 @@ /* Header files */ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" void dlpc_bfi( const Word16 L_frame, @@ -35,7 +34,7 @@ void dlpc_bfi( { /* Decode the second LPC */ lsf_dec_bfi( MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt + 1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0 ); + 0, L_frame, last_good, add( nbLostCmpt, 1 ), plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly, 0 ); } /**/ /*No local variabvles defined*/ } diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index 0bc9234c2f540408d5631075d6eace42b46ceedc..bd27d2137a5234757c747e4b90270f0c69c67bbf 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -4,11 +4,10 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" @@ -18,140 +17,146 @@ static Word16 get_edxt_factor( Word16 length ) /* Returns value of sqrtf(2.f/length) in Q15 */ { - Word16 factor = 0; /*Q15*/ + Word16 factor; /*Q15*/ + factor = 0; + move16(); IF( EQ_16( length, 512 ) ) { factor = 2048; + move16(); } ELSE IF( EQ_16( length, 256 ) ) { factor = 2896; + move16(); } ELSE IF( EQ_16( length, 128 ) ) { factor = 4096; + move16(); } ELSE IF( EQ_16( length, 640 ) ) { factor = 1832; + move16(); } ELSE IF( EQ_16( length, 320 ) ) { factor = 2590; + move16(); } ELSE IF( EQ_16( length, 160 ) ) { factor = 3663; + move16(); } ELSE IF( EQ_16( length, 80 ) ) { factor = 5181; + move16(); } ELSE IF( EQ_16( length, 40 ) ) { factor = 7327; + move16(); } ELSE IF( EQ_16( length, 960 ) ) { factor = 1496; + move16(); } ELSE IF( EQ_16( length, 480 ) ) { factor = 2115; + move16(); } ELSE IF( EQ_16( length, 240 ) ) { factor = 2991; + move16(); } ELSE IF( EQ_16( length, 120 ) ) { factor = 4230; + move16(); } ELSE IF( EQ_16( length, 1200 ) ) { factor = 1338; + move16(); } ELSE IF( EQ_16( length, 800 ) ) { factor = 1638; + move16(); } ELSE IF( EQ_16( length, 400 ) ) { factor = 2317; + move16(); } ELSE IF( EQ_16( length, 200 ) ) { factor = 3277; + move16(); } return factor; } static Word16 const *get_edct_table( Word16 length, Word16 *q ) { - Word16 const *edct_table = NULL; + Word16 const *edct_table; + edct_table = NULL; SWITCH( length ) { case 1200: edct_table = edct_table_600_fx; - move16(); *q = add( *q, 2 ); + move16(); BREAK; case 960: edct_table = edct_table_480_fx; - move16(); BREAK; case 640: edct_table = edct_table_320_fx; - move16(); BREAK; case 320: edct_table = edct_table_160_fx; - move16(); BREAK; case 256: edct_table = edct_table_128_fx; - move16(); BREAK; case 240: edct_table = edct_table_120_fx; - move16(); BREAK; case 200: edct_table = edct_table_100_fx; - move16(); BREAK; case 160: edct_table = edct_table_80_fx; - move16(); BREAK; case 40: edct_table = edct_table_20_fx; - move16(); BREAK; case 800: edct_table = edct_table_400_fx; - move16(); *q = add( *q, 2 ); + move16(); BREAK; case 512: edct_table = edct_table_256_fx; - move16(); BREAK; case 480: edct_table = edct_table_240_fx; - move16(); BREAK; case 400: edct_table = edct_table_200_fx; - move16(); BREAK; case 128: edct_table = edct_table_64_fx; - move16(); BREAK; case 80: edct_table = edct_table_40_fx; - move16(); BREAK; default: BREAK; @@ -182,7 +187,7 @@ void edct_fx( Word16 i; Word32 re; Word32 im; - const Word16 *edct_table = 0; /*Q16 */ + const Word16 *edct_table; /*Q16 */ Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )]; Word32 L_tmp; Word16 tmp; @@ -193,32 +198,34 @@ void edct_fx( /* Twiddling and Pre-rotate */ FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ - complex_buf[2 * i] = Madd_32_16( L_tmp, x[length - 1 - 2 * i], edct_table[len1 - 1 - i] ); /*Q(q+1) */ + L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */ + complex_buf[2 * i] = Madd_32_16( L_tmp, x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[sub( len1, add( 1, i ) )] ); /*Q(q+1) */ move32(); - L_tmp = Mult_32_16( x[length - 1 - 2 * i], edct_table[i] ); /*Q(q+1) */ + L_tmp = Mult_32_16( x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[i] ); /*Q(q+1) */ - complex_buf[2 * i + 1] = Msub_32_16( L_tmp, x[2 * i], edct_table[len1 - 1 - i] ); /*Q(q+1) */ + complex_buf[add( shl( i, 1 ), 1 )] = Msub_32_16( L_tmp, x[shl( i, 1 )], edct_table[sub( len1, add( 1, i ) )] ); /*Q(q+1) */ move32(); } *q = sub( 15, *q ); + move16(); BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); tmp = div_s( 1, length ); /*Q15 */ tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16( complex_buf[2 * i], complex_buf[2 * i + 1], tmp ); - im = Madd_32_16( complex_buf[2 * i + 1], complex_buf[2 * i], tmp ); - y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[len1 - 1 - i] ) ); + re = Msub_32_16( complex_buf[2 * i], complex_buf[add( shl( i, 1 ), 1 )], tmp ); + im = Madd_32_16( complex_buf[add( shl( i, 1 ), 1 )], complex_buf[2 * i], tmp ); + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[sub( len1, add( 1, i ) )] ) ); move32(); - y[length - 1 - 2 * i] = L_sub( Mult_32_16( re, edct_table[len1 - 1 - i] ), Mult_32_16( im, edct_table[i] ) ); + y[sub( length, add( 1, shl( i, 1 ) ) )] = L_sub( Mult_32_16( re, edct_table[sub( len1, add( 1, i ) )] ), Mult_32_16( im, edct_table[i] ) ); move32(); } /*Q(q-2) */ *q = sub( 15 + 2, *q ); + move16(); return; } @@ -245,7 +252,7 @@ void edst_fx( Word16 i; Word32 re; Word32 im; - const Word16 *edct_table = 0; /*Q16 */ + const Word16 *edct_table; /*Q16 */ Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )]; Word32 L_tmp; Word16 tmp; @@ -256,31 +263,33 @@ void edst_fx( /* Twiddling and Pre-rotate */ FOR( i = 0; i < len1; i++ ) { - L_tmp = Mult_32_16( x[length - 1 - 2 * i], edct_table[i] ); - complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[len1 - 1 - i] ); + L_tmp = Mult_32_16( x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[i] ); + complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[sub( len1, add( 1, i ) )] ); move32(); L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); - complex_buf[2 * i + 1] = Msub_32_16( L_tmp, x[length - 1 - 2 * i], edct_table[len1 - 1 - i] ); + complex_buf[add( shl( i, 1 ), 1 )] = Msub_32_16( L_tmp, x[sub( length, add( 1, shl( i, 1 ) ) )], edct_table[sub( len1, add( 1, i ) )] ); move32(); } *q = sub( 15, *q ); + move16(); BASOP_cfft( (cmplx *) complex_buf, len1, q, y ); tmp = div_s( 1, length ); /*Q15 */ tmp = round_fx( L_shl( L_mult( tmp, 19302 ), 2 ) ); /*Q15 */ FOR( i = 0; i < len1; i++ ) { - re = Msub_32_16( complex_buf[2 * i], complex_buf[2 * i + 1], tmp ); - im = Madd_32_16( complex_buf[2 * i + 1], complex_buf[2 * i], tmp ); - y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[len1 - 1 - i] ) ); + re = Msub_32_16( complex_buf[2 * i], complex_buf[add( shl( i, 1 ), 1 )], tmp ); + im = Madd_32_16( complex_buf[add( shl( i, 1 ), 1 )], complex_buf[2 * i], tmp ); + y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[sub( len1, add( 1, i ) )] ) ); move32(); - y[length - 1 - 2 * i] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[len1 - 1 - i] ) ); + y[sub( length, add( 1, shl( i, 1 ) ) )] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[sub( len1, add( 1, i ) )] ) ); move32(); } /*Q(q) */ *q = sub( 15 + 2, *q ); + move16(); return; } @@ -316,7 +325,7 @@ void edct_16fx( Word16 i; Word16 re[L_FRAME48k / 2]; Word16 im[L_FRAME48k / 2]; - const Word16 *edct_table = 0; + const Word16 *edct_table = NULL; Word16 re2[L_FRAME48k / 2]; Word16 im2[L_FRAME48k / 2]; @@ -330,24 +339,23 @@ void edct_16fx( (void) element_mode; #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow; + Overflow = 0; + move32(); #endif /*COMPLETE: some eDCT sub function are missing */ IF( EQ_16( length, L_FRAME32k ) ) { edct_table = &edct_table_320_16fx[0]; - move16(); } ELSE IF( EQ_16( length, L_FRAME ) ) { edct_table = &edct_table_128_16fx[0]; - move16(); } ELSE IF( EQ_16( length, L_FRAME16k ) ) { edct_table = &edct_table_160_16fx[0]; - move16(); } ELSE { @@ -356,8 +364,8 @@ void edct_16fx( /* Twiddling and Pre-rotate */ Lmax = L_deposit_l( 0 ); Len2 = shr( length, 1 ); - px = x + length - 1; - pt = edct_table + Len2 - 1; + px = x + sub( length, 1 ); + pt = edct_table + sub( Len2, 1 ); FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -376,14 +384,15 @@ void edct_16fx( } tmp = 31; + move16(); if ( Lmax != 0 ) { tmp = norm_l( Lmax ); } Q_edct = sub( tmp, bh ); /*creating a bit-headroom */ - px = x + length - 1; - pt = edct_table + Len2 - 1; + px = x + sub( length, 1 ); + pt = edct_table + sub( Len2, 1 ); FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -396,7 +405,7 @@ void edct_16fx( Lacc = L_mac( L_tmp, *px, *pt ); /*Q(Qx+16) */ re2[i] = round_fx( L_shl( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ #endif - + move16(); L_tmp = L_mult( *px, edct_table[i] ); /*Q(Qx+16) */ #ifdef BASOP_NOGLOB Lacc = L_msu_o( L_tmp, x[i2], *pt, &Overflow ); /*Q(Qx+16) */ @@ -405,6 +414,7 @@ void edct_16fx( Lacc = L_msu( L_tmp, x[i2], *pt ); /*Q(Qx+16) */ im2[i] = round_fx( L_shl( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ #endif + move16(); px -= 2; pt--; } @@ -426,7 +436,7 @@ void edct_16fx( tmp = div_s( 1, length ); /*Q15 */ L_tmp = L_mult( tmp, 19302 ); /*Q29, (3*PI/4) in Q13 */ fact = round_fx( L_shl( L_tmp, 2 ) ); /*Q15 */ - FOR( i = 0; i < length / 2; i++ ) + FOR( i = 0; i < shr( length, 1 ); i++ ) { tmp = mult_r( im2[i], fact ); /*Q(Qx+Q_edct) */ #ifdef BASOP_NOGLOB @@ -448,8 +458,8 @@ void edct_16fx( } /* Post-rotate and obtain the output data */ - py = y + length - 1; - pt = edct_table + Len2 - 1; + py = y + sub( length, 1 ); + pt = edct_table + sub( Len2, 1 ); FOR( i = 0; i < Len2; i++ ) { i2 = shl( i, 1 ); @@ -462,14 +472,16 @@ void edct_16fx( Lacc = L_mac( L_tmp, im[i], *pt ); /*Q(Qx+Q_edct+16) */ y[i2] = round_fx( L_shr( Lacc, Q_edct ) ); /* Q(Qx) */ #endif /* BASOP_NOGLOB */ + move16(); - L_tmp = L_mult( re[i], edct_table[length / 2 - 1 - i] ); /*Q(Qx+Q_edct+16) */ - Lacc = L_msu( L_tmp, im[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ + L_tmp = L_mult( re[i], edct_table[sub( shr( length, 1 ), add( 1, i ) )] ); /*Q(Qx+Q_edct+16) */ + Lacc = L_msu( L_tmp, im[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ #ifdef BASOP_NOGLOB *py = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ #else /* BASOP_NOGLOB */ *py = round_fx( L_shr( Lacc, Q_edct ) ); /* Q(Qx) */ #endif + move16(); py -= 2; pt--; @@ -521,13 +533,13 @@ void iedct_short_fx( } FOR( i = 0; i < seg_len_div4; i++ ) { - out[i] = alias[seg_len_div4 + i]; + out[i] = alias[add( seg_len_div4, i )]; move32(); - out[seg_len_div4 + i] = L_negate( alias[seg_len_div2 - 1 - i] ); + out[add( seg_len_div4, i )] = L_negate( alias[sub( sub( seg_len_div2, 1 ), i )] ); move32(); - out[seg_len_div2 + i] = L_negate( alias[seg_len_div4 - 1 - i] ); + out[add( seg_len_div2, i )] = L_negate( alias[sub( sub( seg_len_div4, 1 ), i )] ); move32(); - out[seg_len_3mul_div4 + i] = L_negate( alias[i] ); + out[add( seg_len_3mul_div4, i )] = L_negate( alias[i] ); move32(); } @@ -549,112 +561,132 @@ void edxt_fx( const UWord16 synthesis /* i : nonzero for inverse */ ) { - Word16 k, m, fac = 0; - const Word16 *cosPtr = NULL, *sinPtr = NULL; - Word16 n = 0; - + Word16 k, m, fac; + const Word16 *cosPtr, *sinPtr; + Word16 n; + n = 0; + move16(); + cosPtr = NULL; + sinPtr = NULL; IF( EQ_16( length, 512 ) ) { cosPtr = cos_scale_tbl_512; sinPtr = sin_scale_tbl_512; n = 1; + move16(); } ELSE IF( EQ_16( length, 256 ) ) { cosPtr = cos_scale_tbl_512; sinPtr = sin_scale_tbl_512; n = 2; + move16(); } ELSE IF( EQ_16( length, 128 ) ) { cosPtr = cos_scale_tbl_512; sinPtr = sin_scale_tbl_512; n = 4; + move16(); } ELSE IF( EQ_16( length, 640 ) ) { cosPtr = cos_scale_tbl_640; sinPtr = sin_scale_tbl_640; n = 1; + move16(); } ELSE IF( EQ_16( length, 320 ) ) { cosPtr = cos_scale_tbl_640; sinPtr = sin_scale_tbl_640; n = 2; + move16(); } ELSE IF( EQ_16( length, 160 ) ) { cosPtr = cos_scale_tbl_640; sinPtr = sin_scale_tbl_640; n = 4; + move16(); } ELSE IF( EQ_16( length, 80 ) ) { cosPtr = cos_scale_tbl_640; sinPtr = sin_scale_tbl_640; n = 8; + move16(); } ELSE IF( EQ_16( length, 40 ) ) { cosPtr = cos_scale_tbl_640; sinPtr = sin_scale_tbl_640; n = 16; + move16(); } ELSE IF( EQ_16( length, 960 ) ) { cosPtr = cos_scale_tbl_960; sinPtr = sin_scale_tbl_960; n = 1; + move16(); } ELSE IF( EQ_16( length, 480 ) ) { cosPtr = cos_scale_tbl_960; sinPtr = sin_scale_tbl_960; n = 2; + move16(); } ELSE IF( EQ_16( length, 240 ) ) { cosPtr = cos_scale_tbl_960; sinPtr = sin_scale_tbl_960; n = 4; + move16(); } ELSE IF( EQ_16( length, 120 ) ) { cosPtr = cos_scale_tbl_960; sinPtr = sin_scale_tbl_960; n = 8; + move16(); } ELSE IF( EQ_16( length, 1200 ) ) { cosPtr = cos_scale_tbl_1200; sinPtr = sin_scale_tbl_1200; n = 1; + move16(); } ELSE IF( EQ_16( length, 800 ) ) { cosPtr = cos_scale_tbl_800; sinPtr = sin_scale_tbl_800; n = 1; + move16(); } ELSE IF( EQ_16( length, 400 ) ) { cosPtr = cos_scale_tbl_800; sinPtr = sin_scale_tbl_800; n = 2; + move16(); } ELSE IF( EQ_16( length, 200 ) ) { cosPtr = cos_scale_tbl_800; sinPtr = sin_scale_tbl_800; n = 4; + move16(); } #ifdef FAST_EDXT + test(); IF( EQ_16( kernelType, MDST_II ) || EQ_16( kernelType, MDCT_II ) ) { const Word16 Nm1 = sub( length, 1 ); - const Word16 xSign = 2 * ( kernelType >> 1 ) - 1; + const Word16 xSign = sub( imult1616( 2, shr( kernelType, 1 ) ), 1 ); Word32 re[L_FRAME_PLUS]; Word32 im[L_FRAME_PLUS]; @@ -663,8 +695,11 @@ void edxt_fx( FOR( k = shr( Nm1, 1 ); k >= 0; k-- ) /* pre-modulation of audio input */ { re[k] = x[2 * k]; - re[Nm1 - k] = Mpy_32_16_1( x[2 * k + 1], shl_sat( xSign, 15 ) ); - im[k] = im[Nm1 - k] = 0; + re[sub( Nm1, k )] = Mpy_32_16_1( x[add( shl( k, 1 ), 1 )], shl_sat( xSign, 15 ) ); + im[k] = im[sub( Nm1, k )] = 0; + move32(); + move32(); + move32(); } IF( EQ_16( length, 512 ) ) @@ -682,13 +717,16 @@ void edxt_fx( { // const float wRe = cosf( scale * k ); // const float wIm = sinf( scale * k ); - const Word16 wRe = cosPtr[k * n]; - const Word16 wIm = sinPtr[k * n]; + const Word16 wRe = cosPtr[imult1616( k, n )]; + const Word16 wIm = sinPtr[imult1616( k, n )]; y[k] /*pt 1*/ = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); - y[length - k] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); + y[sub( length, k )] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); + move32(); + move32(); } y[shr( length, 1 )] = Mpy_32_16_1( re[shr( length, 1 )], INV_SQRT_2_Q15 ); + move32(); } ELSE /* forw. DST-II */ { @@ -696,16 +734,20 @@ void edxt_fx( { // const float wRe = cosf( scale * k ); // const float wIm = sinf( scale * k ); - const Word16 wRe = cosPtr[k * n]; - const Word16 wIm = sinPtr[k * n]; + const Word16 wRe = cosPtr[imult1616( k, n )]; + const Word16 wIm = sinPtr[imult1616( k, n )]; - y[Nm1 - k] = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); + y[sub( Nm1, k )] = L_add( Mpy_32_16_1( re[k], wRe ), Mpy_32_16_1( im[k], wIm ) ); y[k - 1] = L_sub( Mpy_32_16_1( re[k], wIm ), Mpy_32_16_1( im[k], wRe ) ); + move32(); + move32(); } y[shr( Nm1, 1 )] = Mpy_32_16_1( re[shr( length, 1 )], INV_SQRT_2_Q15 ); + move32(); } - y[Nm1 - Nm1 * ( kernelType >> 1 )] = L_shr( re[0], 1 ); + y[sub( Nm1, imult1616( Nm1, shl( kernelType, 1 ) ) )] = L_shr( re[0], 1 ); + move32(); } ELSE /* inverse II = III */ { @@ -715,13 +757,16 @@ void edxt_fx( { // const float wRe = cosf( scale * k ) * 0.5f; // const float wIm = sinf( scale * k ) * 0.5f; - const Word16 wRe = shr( cosPtr[k * n], 1 ); - const Word16 wIm = shr( sinPtr[k * n], 1 ); + const Word16 wRe = shr( cosPtr[imult1616( k, n )], 1 ); + const Word16 wIm = shr( sinPtr[imult1616( k, n )], 1 ); - re[k] = L_add( Mpy_32_16_1( x[k], wRe ), Mpy_32_16_1( x[length - k], wIm ) ); - im[k] = L_sub( Mpy_32_16_1( x[length - k], wRe ), Mpy_32_16_1( x[k], wIm ) ); + re[k] = L_add( Mpy_32_16_1( x[k], wRe ), Mpy_32_16_1( x[sub( length, k )], wIm ) ); + im[k] = L_sub( Mpy_32_16_1( x[sub( length, k )], wRe ), Mpy_32_16_1( x[k], wIm ) ); + move32(); + move32(); } re[shr( length, 1 )] = Mpy_32_16_1( x[shr( length, 1 )], INV_SQRT_2_Q15 ); + move32(); } ELSE /* DST type III */ { @@ -729,21 +774,28 @@ void edxt_fx( { // const float wRe = cosf( scale * k ) * 0.5f; // const float wIm = sinf( scale * k ) * 0.5f; - const Word16 wRe = shr( cosPtr[k * n], 1 ); - const Word16 wIm = shr( sinPtr[k * n], 1 ); + const Word16 wRe = shr( cosPtr[imult1616( k, n )], 1 ); + const Word16 wIm = shr( sinPtr[imult1616( k, n )], 1 ); - re[k] = L_add( Mpy_32_16_1( x[Nm1 - k], wRe ), Mpy_32_16_1( x[k - 1], wIm ) ); - im[k] = L_sub( Mpy_32_16_1( x[k - 1], wRe ), Mpy_32_16_1( x[Nm1 - k], wIm ) ); + re[k] = L_add( Mpy_32_16_1( x[sub( Nm1, k )], wRe ), Mpy_32_16_1( x[sub( k, 1 )], wIm ) ); + im[k] = L_sub( Mpy_32_16_1( x[sub( k, 1 )], wRe ), Mpy_32_16_1( x[sub( Nm1, k )], wIm ) ); + move32(); + move32(); } re[shr( length, 1 )] = Mpy_32_16_1( x[shr( Nm1, 1 )], INV_SQRT_2_Q15 ); + move32(); } - re[0] = x[Nm1 - Nm1 * shr( kernelType, 1 )]; + re[0] = x[sub( Nm1, imult1616( Nm1, shr( kernelType, 1 ) ) )]; im[0] = im[shr( length, 1 )] = 0; + move32(); + move32(); FOR( k = shr( Nm1, 1 ); k > 0; k-- ) { - re[length - k] = re[k]; - im[length - k] = L_negate( im[k] ); + re[sub( length, k )] = re[k]; + im[sub( length, k )] = L_negate( im[k] ); + move32(); + move32(); } IF( EQ_16( length, 512 ) ) @@ -758,14 +810,16 @@ void edxt_fx( FOR( k = shr( Nm1, 1 ); k >= 0; k-- ) /* post-modulation of FFT output */ { y[2 * k] = re[k]; - IF( NE_16( xSign, 0 ) ) + move32(); + IF( xSign != 0 ) { - y[2 * k + 1] = Mpy_32_16_1( re[sub( Nm1, k )], shl_sat( xSign, 15 ) ); + y[add( shl( k, 1 ), 1 )] = Mpy_32_16_1( re[sub( Nm1, k )], shl_sat( xSign, 15 ) ); } ELSE { - y[2 * k + 1] = 0; + y[add( shl( k, 1 ), 1 )] = 0; } + move32(); } } } @@ -812,7 +866,7 @@ void edxt_fx( #endif // IVAS_FLOAT_FIXED_TO_BE_DONE /*v_multc(y, (kernelType == MDCT_II ? -1.f : 1.f) * sqrtf(2.f / length), y, length);*/ fac = get_edxt_factor( length ); /* Q15 */ - IF( EQ_16( kernelType, MDCT_II ) ) + if ( EQ_16( kernelType, MDCT_II ) ) { fac = negate( fac ); } @@ -820,6 +874,7 @@ void edxt_fx( FOR( m = 0; m < length; m++ ) { y[m] = Mpy_32_16_1( y[m], fac ); + move32(); } return; } diff --git a/lib_com/enh1632.c b/lib_com/enh1632.c index 3704c2bd39f729cb73b8e456bc9cca713647682b..1e6c41a0ef9ccb5b558dbb021ee700875ad16f2c 100644 --- a/lib_com/enh1632.c +++ b/lib_com/enh1632.c @@ -56,7 +56,9 @@ #include #include "stl.h" -#if ( WMOPS ) +#define WMC_TOOL_SKIP + +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* ifdef WMOPS */ @@ -117,7 +119,7 @@ Word16 lshl( Word16 var1, Word16 var2 ) var2 = -var2; var_out = lshr( var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].lshr--; #endif /* ifdef WMOPS */ } @@ -136,7 +138,7 @@ Word16 lshl( Word16 var1, Word16 var2 ) var_out = var1 << var2; } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].lshl++; #endif /* ifdef WMOPS */ @@ -184,7 +186,7 @@ Word16 lshr( Word16 var1, Word16 var2 ) var2 = -var2; var_out = lshl( var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].lshl--; #endif /* ifdef WMOPS */ } @@ -205,7 +207,7 @@ Word16 lshr( Word16 var1, Word16 var2 ) var_out = var_out >> ( var2 - 1 ); } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].lshr++; #endif /* ifdef WMOPS */ @@ -254,7 +256,7 @@ Word32 L_lshl( Word32 L_var1, Word16 var2 ) var2 = -var2; L_var_out = L_lshr( L_var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_lshr--; #endif /* ifdef WMOPS */ } @@ -273,7 +275,7 @@ Word32 L_lshl( Word32 L_var1, Word16 var2 ) L_var_out = L_var1 << var2; } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_lshl++; #endif /* ifdef WMOPS */ @@ -322,7 +324,7 @@ Word32 L_lshr( Word32 L_var1, Word16 var2 ) var2 = -var2; L_var_out = L_lshl( L_var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_lshl--; #endif /* ifdef WMOPS */ } @@ -343,7 +345,7 @@ Word32 L_lshr( Word32 L_var1, Word16 var2 ) L_var_out = L_var_out >> ( var2 - 1 ); } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_lshr++; #endif /* ifdef WMOPS */ @@ -382,11 +384,10 @@ Word32 L_lshr( Word32 L_var1, Word16 var2 ) *****************************************************************************/ #ifdef BASOP_NOGLOB Word16 shl_ro( Word16 var1, Word16 var2, Flag *Overflow ) -{ #else Word16 shl_r( Word16 var1, Word16 var2 ) -{ #endif +{ Word16 var_out; if ( var2 >= 0 ) @@ -396,7 +397,7 @@ Word16 shl_r( Word16 var1, Word16 var2 ) #else var_out = shl( var1, var2 ); #endif -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].shl--; #endif /* ifdef WMOPS */ } @@ -408,12 +409,12 @@ Word16 shl_r( Word16 var1, Word16 var2 ) #else var_out = shr_r( var1, var2 ); #endif -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].shr_r--; #endif /* ifdef WMOPS */ } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].shl_r++; #endif /* ifdef WMOPS */ @@ -462,7 +463,7 @@ Word32 L_shl_r( Word32 L_var1, Word16 var2 ) { var_out = L_shl( L_var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_shl--; #endif /* ifdef WMOPS */ } @@ -471,12 +472,12 @@ Word32 L_shl_r( Word32 L_var1, Word16 var2 ) var2 = -var2; var_out = L_shr_r( L_var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_shr_r--; #endif /* ifdef WMOPS */ } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_shl_r++; #endif /* ifdef WMOPS */ @@ -521,7 +522,7 @@ Word16 rotr( Word16 var1, Word16 var2, Word16 *var3 ) *var3 = s_and( var1, 0x1 ); var_out = s_or( lshr( var1, 1 ), lshl( var2, 15 ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_and--; multiCounter[currCounter].lshl--; multiCounter[currCounter].lshr--; @@ -571,7 +572,7 @@ Word16 rotl( Word16 var1, Word16 var2, Word16 *var3 ) var_out = s_or( lshl( var1, 1 ), s_and( var2, 0x1 ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].lshr--; multiCounter[currCounter].s_and--; multiCounter[currCounter].lshl--; @@ -621,7 +622,7 @@ Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3 ) L_var_out = L_or( L_lshr( L_var1, 1 ), L_lshl( L_deposit_l( var2 ), 31 ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].extract_l--; multiCounter[currCounter].s_and--; multiCounter[currCounter].L_deposit_l--; @@ -673,7 +674,7 @@ Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3 ) L_var_out = L_or( L_lshl( L_var1, 1 ), L_deposit_l( s_and( var2, 0x1 ) ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_lshr--; multiCounter[currCounter].extract_l--; multiCounter[currCounter].s_and--; @@ -686,5 +687,6 @@ Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3 ) return ( L_var_out ); } +#undef WMC_TOOL_SKIP /* end of file */ diff --git a/lib_com/enh1632.h b/lib_com/enh1632.h index 2ef87cd64a2bf56d25b2bbf230a8874b1a46dbb5..1477c6c8093b3048dcf64e3fbc2b874d49dc9945 100644 --- a/lib_com/enh1632.h +++ b/lib_com/enh1632.h @@ -36,7 +36,7 @@ #include "stl.h" -#if ( WMOPS ) +#ifdef WMOPS #include "count.h" extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; @@ -109,7 +109,7 @@ static __inline Word16 s_max( Word16 var1, Word16 var2 ) else var_out = var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_max++; #endif /* ifdef WMOPS */ @@ -154,7 +154,7 @@ static __inline Word16 s_min( Word16 var1, Word16 var2 ) else var_out = var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_min++; #endif /* ifdef WMOPS */ @@ -199,7 +199,7 @@ static __inline Word32 L_max( Word32 L_var1, Word32 L_var2 ) else L_var_out = L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_max++; #endif /* ifdef WMOPS */ @@ -244,7 +244,7 @@ static __inline Word32 L_min( Word32 L_var1, Word32 L_var2 ) else L_var_out = L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_min++; #endif /* ifdef WMOPS */ @@ -287,7 +287,7 @@ static __inline Word16 s_and( Word16 var1, Word16 var2 ) var_out = var1 & var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_and++; #endif /* ifdef WMOPS */ @@ -330,7 +330,7 @@ static __inline Word32 L_and( Word32 L_var1, Word32 L_var2 ) L_var_out = L_var1 & L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_and++; #endif /* ifdef WMOPS */ @@ -373,7 +373,7 @@ static __inline Word16 s_or( Word16 var1, Word16 var2 ) var_out = var1 | var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_or++; #endif /* ifdef WMOPS */ @@ -417,7 +417,7 @@ static __inline Word32 L_or( Word32 L_var1, Word32 L_var2 ) L_var_out = L_var1 | L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_or++; #endif /* ifdef WMOPS */ @@ -460,7 +460,7 @@ static __inline Word16 s_xor( Word16 var1, Word16 var2 ) var_out = var1 ^ var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].s_xor++; #endif /* ifdef WMOPS */ @@ -503,7 +503,7 @@ static __inline Word32 L_xor( Word32 L_var1, Word32 L_var2 ) L_var_out = L_var1 ^ L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].L_xor++; #endif /* ifdef WMOPS */ diff --git a/lib_com/enh32.c b/lib_com/enh32.c index 3fb1148fcda0cd6eac261c5cb089b47112ebae6b..d2466ce6423561dc4139627fcb0c8e1ac3bb7493 100644 --- a/lib_com/enh32.c +++ b/lib_com/enh32.c @@ -23,7 +23,9 @@ #include #include "enh32.h" -#if ( WMOPS ) +#define WMC_TOOL_SKIP + +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ @@ -51,7 +53,7 @@ extern int currCounter; Word32 Mpy_32_16_1( Word32 L_var1, Word16 var2 ) { Word32 L_var_out = W_sat_m( W_mult_32_16( L_var1, var2 ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_1++; multiCounter[currCounter].W_mult_32_16--; multiCounter[currCounter].W_sat_m--; @@ -62,7 +64,7 @@ Word32 Mpy_32_16_1( Word32 L_var1, Word16 var2 ) Word32 Mpy_32_16_r( Word32 L_var1, Word16 var2 ) { Word32 L_var_out = W_round48_L( W_mult_32_16( L_var1, var2 ) ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_r++; multiCounter[currCounter].W_mult_32_16--; multiCounter[currCounter].W_round48_L--; @@ -85,7 +87,7 @@ Word32 Mpy_32_32( Word32 L_var1, Word32 L_var2 ) L64_var1 = W_shl( L64_var1, 1 ); #endif /* BASOP_NOGLOB */ L_var_out = W_extract_h( L64_var1 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32++; multiCounter[currCounter].W_shl--; multiCounter[currCounter].W_extract_h--; @@ -101,7 +103,7 @@ Word32 Mpy_32_32_r( Word32 L_var1, Word32 L_var2 ) L64_var1 = ( (Word64) L_var1 * L_var2 ); L64_var1 = W_shr( L64_var1, 15 ); L_var_out = W_round48_L( L64_var1 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_r++; multiCounter[currCounter].W_shr--; multiCounter[currCounter].W_round48_L--; @@ -123,7 +125,7 @@ Word32 Madd_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) L_var_out = L_add( L_var3, L_var_out ); #endif /* BASOP_NOGLOB */ -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].L_add--; multiCounter[currCounter].Madd_32_16++; @@ -138,7 +140,7 @@ Word32 Madd_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ) L_var_out = Mpy_32_16_r( L_var1, var2 ); L_var_out = L_add( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].L_add--; multiCounter[currCounter].Madd_32_16_r++; @@ -160,7 +162,7 @@ Word32 Msub_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) L_var_out = L_sub( L_var3, L_var_out ); #endif -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_1--; multiCounter[currCounter].L_sub--; multiCounter[currCounter].Msub_32_16++; @@ -175,7 +177,7 @@ Word32 Msub_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ) L_var_out = Mpy_32_16_r( L_var1, var2 ); L_var_out = L_sub( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_r--; multiCounter[currCounter].L_sub--; multiCounter[currCounter].Msub_32_16_r++; @@ -190,7 +192,7 @@ Word32 Madd_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) L_var_out = Mpy_32_32( L_var1, L_var2 ); L_var_out = L_add( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32--; multiCounter[currCounter].L_add--; multiCounter[currCounter].Madd_32_32++; @@ -205,7 +207,7 @@ Word32 Madd_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) L_var_out = Mpy_32_32_r( L_var1, L_var2 ); L_var_out = L_add( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].L_add--; multiCounter[currCounter].Madd_32_32_r++; @@ -220,7 +222,7 @@ Word32 Msub_32_32( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) L_var_out = Mpy_32_32( L_var1, L_var2 ); L_var_out = L_sub( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32--; multiCounter[currCounter].L_sub--; multiCounter[currCounter].Msub_32_32++; @@ -235,7 +237,7 @@ Word32 Msub_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) L_var_out = Mpy_32_32_r( L_var1, L_var2 ); L_var_out = L_sub( L_var3, L_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_r--; multiCounter[currCounter].L_sub--; multiCounter[currCounter].Msub_32_32_r++; @@ -244,5 +246,6 @@ Word32 Msub_32_32_r( Word32 L_var3, Word32 L_var1, Word32 L_var2 ) } #endif /* #ifdef ENH_32_BIT_OPERATOR */ +#undef WMC_TOOL_SKIP /* end of file */ diff --git a/lib_com/enh64.c b/lib_com/enh64.c index f0b80407634c3a6e6b1f2cfe423d3c6072917828..0571277fe1afd638a168a5b25ecf47155be300c3 100644 --- a/lib_com/enh64.c +++ b/lib_com/enh64.c @@ -18,7 +18,9 @@ #include #include "enh64.h" -#if ( WMOPS ) +#define WMC_TOOL_SKIP + +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ @@ -81,7 +83,7 @@ Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ) L64_var_out = L64_var1 + L64_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_add_nosat++; #endif @@ -124,7 +126,7 @@ Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) L64_var_out = L64_var1 - L64_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_sub_nosat++; #endif @@ -167,11 +169,10 @@ Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) */ #ifdef BASOP_NOGLOB Word64 W_shl_o( Word64 L64_var1, Word16 var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_shl( Word64 L64_var1, Word16 var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out = 0LL; @@ -213,7 +214,7 @@ Word64 W_shl( Word64 L64_var1, Word16 var2 ) L64_var_out = L64_var1; } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shl++; #endif @@ -272,7 +273,7 @@ Word64 W_shr( Word64 L64_var1, Word16 var2 ) var2 = -var2; L64_var_out = W_shl( L64_var1, var2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shl--; #endif /* if WMOPS */ } @@ -281,7 +282,7 @@ Word64 W_shr( Word64 L64_var1, Word16 var2 ) L64_var_out = L64_var1 >> var2; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shr++; #endif /* if WMOPS */ @@ -337,7 +338,7 @@ Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ) { L64_var_out = L64_var1 << var2; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shl_nosat++; #endif @@ -395,7 +396,7 @@ Word64 W_shr_nosat( Word64 L64_var1, Word16 var2 ) L64_var_out = L64_var1 >> var2; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shr_nosat++; #endif /* if WMOPS */ @@ -443,7 +444,7 @@ Word64 W_mac_32_16( Word64 L64_var1, Word32 L_var2, Word16 var3 ) { Word64 L64_var_out = ( (Word64) L_var2 * var3 ) << 1; L64_var_out += L64_var1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mac_32_16++; #endif /* if WMOPS */ return L64_var_out; @@ -490,7 +491,7 @@ Word64 W_msu_32_16( Word64 L64_var1, Word32 L_var2, Word16 var3 ) { Word64 L64_var_out = ( (Word64) L_var2 * var3 ) << 1; L64_var_out = L64_var1 - L64_var_out; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_msu_32_16++; #endif /* if WMOPS */ return L64_var_out; @@ -531,7 +532,7 @@ Word64 W_msu_32_16( Word64 L64_var1, Word32 L_var2, Word16 var3 ) Word64 W_mult_32_16( Word32 L_var1, Word16 var2 ) { Word64 L64_var_out = ( (Word64) L_var1 * var2 ) << 1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mult_32_16++; #endif /* if WMOPS */ return L64_var_out; @@ -571,7 +572,7 @@ Word64 W_mult_32_16( Word32 L_var1, Word16 var2 ) Word64 W_mult0_16_16( Word16 var1, Word16 var2 ) { Word64 L64_var_out = (Word64) var1 * var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mult0_16_16++; #endif /* if WMOPS */ return L64_var_out; @@ -616,7 +617,7 @@ Word64 W_mac0_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) { Word64 L64_var_out = (Word64) var2 * var3; L64_var_out += L64_var1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mac0_16_16++; #endif /* if WMOPS */ return L64_var_out; @@ -662,7 +663,7 @@ Word64 W_msu0_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) { Word64 L64_var_out = (Word64) var2 * var3; L64_var_out = L64_var1 - L64_var_out; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_msu0_16_16++; #endif /* if WMOPS */ return L64_var_out; @@ -713,7 +714,7 @@ Word32 W_sat_l( Word64 L64_var ) L_var_out = (Word32) L64_var; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_sat_l++; #endif /* if WMOPS */ @@ -756,7 +757,7 @@ Word32 W_sat_m( Word64 L64_var ) L64_var = L64_var >> 16; L_var_out = W_sat_l( L64_var ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_sat_l--; multiCounter[currCounter].W_sat_m++; #endif /* if WMOPS */ @@ -798,7 +799,7 @@ Word64 W_deposit32_l( Word32 L_var1 ) L64_var_out = (Word64) L_var1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_deposit32_l++; #endif @@ -839,7 +840,7 @@ Word64 W_deposit32_h( Word32 L_var1 ) L64_var_out = (Word64) L_var1 << 32; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_deposit32_h++; #endif @@ -880,7 +881,7 @@ Word32 W_extract_l( Word64 L64_var1 ) L_var_out = (Word32) L64_var1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_extract_l++; #endif /* if WMOPS */ @@ -921,7 +922,7 @@ Word32 W_extract_h( Word64 L64_var1 ) L_var_out = (Word32) ( L64_var1 >> 32 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_extract_h++; #endif /* if WMOPS */ @@ -963,7 +964,7 @@ Word32 W_extract_h( Word64 L64_var1 ) Word64 W_mult_16_16( Word16 var1, Word16 var2 ) { Word64 L64_var_out = ( (Word64) var1 * var2 ) << 1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mult_16_16++; #endif /* if WMOPS */ return L64_var_out; @@ -1009,7 +1010,7 @@ Word64 W_mac_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ) Word64 L64_var_out = ( (Word64) var1 * var2 ) << 1; L64_acc = L64_acc + L64_var_out; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mac_16_16++; #endif /* if WMOPS */ return L64_acc; @@ -1056,12 +1057,62 @@ Word64 W_msu_16_16( Word64 L64_var1, Word16 var2, Word16 var3 ) { Word64 L64_var_out = ( (Word64) var2 * var3 ) << 1; L64_var_out = L64_var1 - L64_var_out; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_msu_16_16++; #endif /* if WMOPS */ return L64_var_out; } +/* Below BASOP is not part of STL 2023 library, might be proposed in next update */ +/*________________________________________________________________________________________________ +| | +| Function Name : W_mac_32_32 | +| | +| Purpose : | +| | +| Multiply var1 by var2 and shift the result left by 1 and add the 64 bit result to L64_acc, | +| return a 64 bit result. | +| | +| Complexity weight : 1 | +| | +| Inputs : | +| | +| L64_acc | +| 64 bit long long signed integer (Word64) whose value falls in the | +| range : 0x80000000 00000000LL <= L64_acc <= 0x7fffffff ffffffffLL. | +| | +| var1 | +| 32 bit signed integer (Word32) whose value falls in the | +| range : 0x8000 0000 <= var1 <= 0x7fff 0000. | +| | +| var2 | +| 32 bit signed integer (Word32) whose value falls in the | +| range : 0x8000 0000 <= var2 <= 0x7fff 0000. | +| | +| Outputs : | +| | +| none | +| | +| Return Value : | +| | +| L64_var_out | +| 64 bit long long signed integer (Word64) whose value falls in the | +| range : 0x80000000 00000000LL <= L64_var_out <= 0x7fffffff ffffffffLL. | +|_________________________________________________________________________________________________| +*/ +Word64 W_mac_32_32( Word64 L64_var1, Word32 L_var2, Word32 L_var3 ) +{ + Word64 L64_var_out = W_mult_32_32( L_var2, L_var3 ); + L64_var_out = W_add( L64_var1, L64_var_out ); + +#ifdef WMOPS + multiCounter[currCounter].W_mult_32_32--; + /* multiCounter[currCounter].W_add--; */ +#endif + + return L64_var_out; +} + /*___________________________________________________________________________ | | @@ -1103,7 +1154,7 @@ Word32 W_shl_sat_l( Word64 L64_var, Word16 n ) d_var_64 = W_shl( L64_var, n ); L_result = W_sat_l( d_var_64 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_shl_sat_l++; multiCounter[currCounter].W_shl--; multiCounter[currCounter].W_sat_l--; @@ -1142,11 +1193,10 @@ Word32 W_shl_sat_l( Word64 L64_var, Word16 n ) */ #ifdef BASOP_NOGLOB Word32 W_round48_L_o( Word64 L64_var1, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word32 W_round48_L( Word64 L64_var1 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; Word32 L_result; @@ -1171,7 +1221,7 @@ Word32 W_round48_L( Word64 L64_var1 ) } } L_result = W_extract_h( L64_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_round48_L++; multiCounter[currCounter].W_extract_h--; multiCounter[currCounter].W_shl--; @@ -1216,11 +1266,10 @@ Word32 W_round48_L( Word64 L64_var1 ) */ #ifdef BASOP_NOGLOB Word16 W_round32_s_o( Word64 L64_var1, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word16 W_round32_s( Word64 L64_var1 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; Word32 L_var; Word16 var_out; @@ -1247,7 +1296,7 @@ Word16 W_round32_s( Word64 L64_var1 ) } L_var = W_extract_h( L64_var_out ); var_out = extract_h( L_var ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_round32_s++; multiCounter[currCounter].W_extract_h--; multiCounter[currCounter].extract_h--; @@ -1317,7 +1366,7 @@ Word16 W_norm( Word64 L64_var1 ) } } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_norm++; #endif /* if WMOPS */ return ( var_out ); @@ -1357,11 +1406,10 @@ Word16 W_norm( Word64 L64_var1 ) */ #ifdef BASOP_NOGLOB Word64 W_add_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_add( Word64 L64_var1, Word64 L64_var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; L64_var_out = L64_var1 + L64_var2; @@ -1379,7 +1427,7 @@ Word64 W_add( Word64 L64_var1, Word64 L64_var2 ) } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_add++; #endif return L64_var_out; @@ -1425,11 +1473,10 @@ Word64 W_add( Word64 L64_var1, Word64 L64_var2 ) */ #ifdef BASOP_NOGLOB Word64 W_sub_o( Word64 L64_var1, Word64 L64_var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; L64_var_out = L64_var1 - L64_var2; @@ -1447,7 +1494,7 @@ Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ) } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_add++; #endif return L64_var_out; @@ -1490,11 +1537,10 @@ Word64 W_sub( Word64 L64_var1, Word64 L64_var2 ) */ #ifdef BASOP_NOGLOB Word64 W_neg_o( Word64 L64_var1, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_neg( Word64 L64_var1 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; if ( L64_var1 == MIN_64 ) @@ -1511,7 +1557,7 @@ Word64 W_neg( Word64 L64_var1 ) L64_var_out = -L64_var1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_neg++; #endif @@ -1555,11 +1601,10 @@ Word64 W_neg( Word64 L64_var1 ) */ #ifdef BASOP_NOGLOB Word64 W_abs_o( Word64 L64_var1, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_abs( Word64 L64_var1 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; if ( L64_var1 == MIN_64 ) @@ -1583,7 +1628,7 @@ Word64 W_abs( Word64 L64_var1 ) } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_abs++; #endif @@ -1631,11 +1676,10 @@ Word64 W_abs( Word64 L64_var1 ) */ #ifdef BASOP_NOGLOB Word64 W_mult_32_32_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ) -{ #else /* BASOP_NOGLOB */ Word64 W_mult_32_32( Word32 L_var1, Word32 L_var2 ) -{ #endif /* BASOP_NOGLOB */ +{ Word64 L64_var_out; if ( ( L_var1 == MIN_32 ) && ( L_var2 == MIN_32 ) ) @@ -1652,7 +1696,7 @@ Word64 W_mult_32_32( Word32 L_var1, Word32 L_var2 ) L64_var_out = ( (Word64) L_var1 * L_var2 ) << 1; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mult_32_32++; #endif /* if WMOPS */ return L64_var_out; @@ -1703,7 +1747,7 @@ Word64 W_mult0_32_32( Word32 L_var1, Word32 L_var2 ) L64_var_out = (Word64) L_var1 * L_var2; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_mult0_32_32++; #endif /* if WMOPS */ return L64_var_out; @@ -1755,7 +1799,7 @@ UWord64 W_lshl( UWord64 L64_var1, Word16 var2 ) { L64_var_out = L64_var1 << var2; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_lshl++; #endif @@ -1807,7 +1851,7 @@ UWord64 W_lshr( UWord64 L64_var1, Word16 var2 ) { L64_var_out = L64_var1 >> var2; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_lshr++; #endif @@ -1852,7 +1896,7 @@ Word32 W_round64_L( Word64 L64_var1 ) L64_var_out = W_add( L64_var1, L64_tmp ); L_result = W_extract_h( L64_var_out ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].W_round64_L++; multiCounter[currCounter].W_extract_h--; multiCounter[currCounter].W_add--; @@ -1862,5 +1906,6 @@ Word32 W_round64_L( Word64 L64_var1 ) } #endif /* #ifdef ENH_64_BIT_OPERATOR */ +#undef WMC_TOOL_SKIP /* end of file */ diff --git a/lib_com/enh64.h b/lib_com/enh64.h index 9016a27aef7990c5e5038fe54400d01a622be81d..8aed870a67e0688ab7e3398caa7f7aa040f186b0 100644 --- a/lib_com/enh64.h +++ b/lib_com/enh64.h @@ -36,6 +36,8 @@ Word64 W_msu0_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); Word64 W_mult_16_16( Word16 var1, Word16 var2 ); Word64 W_mac_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); Word64 W_msu_16_16( Word64 L64_acc, Word16 var1, Word16 var2 ); +/* BASOP W_mac_32_32 is not part of STL 2023 library, might be proposed in next update */ +Word64 W_mac_32_32( Word64 L64_acc, Word32 var1, Word32 var2 ); Word64 W_deposit32_l( Word32 L_var1 ); Word64 W_deposit32_h( Word32 L_var1 ); diff --git a/lib_com/enhUL32.c b/lib_com/enhUL32.c index 0aa21b4fcf3789ed72a7c8c6bac0b3d0c1b7e8e4..ff1c684250c24dece2d10241aab626895ae16818 100644 --- a/lib_com/enhUL32.c +++ b/lib_com/enhUL32.c @@ -27,7 +27,9 @@ #include "stl.h" #include "enhUL32.h" -#if ( WMOPS ) +#define WMC_TOOL_SKIP + +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* if WMOPS */ @@ -62,7 +64,7 @@ UWord32 UL_deposit_l( UWord16 uvar ) { UWord32 UL_result; UL_result = (UWord32) uvar; /* no sign extension*/ -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].UL_deposit_l++; #endif return ( UL_result ); @@ -113,7 +115,7 @@ Word16 norm_ul_float (UWord32 UL_var1) { } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].norm_ul_float++; #endif @@ -155,7 +157,7 @@ UWord32 UL_addNs( UWord32 UL_var1, UWord32 UL_var2, UWord16 *wrap ) *wrap = 0; } -#if WMOPS +#ifdef WMOPS multiCounter[currCounter].UL_addNs++; #endif @@ -195,7 +197,7 @@ UWord32 UL_subNs( UWord32 UL_var1, UWord32 UL_var2, UWord16 *sgn ) *sgn = 1; /* "negative", wrapped output */ } -#if WMOPS +#ifdef WMOPS multiCounter[currCounter].UL_subNs++; #endif return UL_var3; @@ -247,7 +249,7 @@ void Mpy_32_16_uu( UWord32 UL_var1, UWord16 uvar2, UWord32 *UL_varout_h, UWord16 *varout_l = (UWord16) UL64_var1; *UL_varout_h = (UWord32) ( UL64_var1 >> 16 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_16_uu++; #endif /* if WMOPS */ @@ -297,7 +299,7 @@ void Mpy_32_32_uu( UWord32 UL_var1, UWord32 UL_var2, UWord32 *UL_varout_h, UWord *UL_varout_h = (UWord32) ( UL64_var1 >> 32 ); *UL_varout_l = (UWord32) ( UL64_var1 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].Mpy_32_32_uu++; #endif /* if WMOPS */ @@ -350,7 +352,7 @@ UWord32 UL_Mpy_32_32( UWord32 UL_var1, UWord32 UL_var2 ) UL_varout_l = UL_varout_l & MASK32; #undef MASK32 -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].UL_Mpy_32_32++; #endif /* if WMOPS */ @@ -417,5 +419,6 @@ UWord32 UL_addNsD( UWord32 UL_var1, UWord32 UL_var2 ) #endif #endif /* ENH_U_32_BIT_OPERATOR */ +#undef WMC_TOOL_SKIP /* end of file */ diff --git a/lib_com/enhUL32.h b/lib_com/enhUL32.h index 240dead793f3cc8177be74a7b0f71cb038f5d6b9..39a79d700d330a41545a87b301b5ae1745581495 100644 --- a/lib_com/enhUL32.h +++ b/lib_com/enhUL32.h @@ -24,7 +24,7 @@ #define UWord64 unsigned long long /* for local use inside UL_Mpy_32_* */ #endif -#if ( WMOPS ) +#ifdef WMOPS #include "count.h" extern BASIC_OP multiCounter[MAXCOUNTERS]; /* existing signed counters are reused for unsigedn operators */ extern int currCounter; diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 6336dd685b19ffd2a84bd3a515fe94eec665c84c..7f529ec125be9e019273fec1354b8abc302108b8 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "basop_util.h" /*---------------------------------------------------------------------* @@ -25,38 +24,38 @@ static void phase_dispersion_fx( Word32 gain_code, Word16 gain_pit, Word16 code[ static void agc2_fx( const Word16 *sig_in, Word16 *sig_out, const Word16 l_trm ); /*======================================================================================*/ -/* FUNCTION : enhancer_fx() */ +/* FUNCTION : enhancer_fx() */ /*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Enhancement of the excitation signal before synthesis */ +/* PURPOSE : Enhancement of the excitation signal before synthesis */ /*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : decoder bitrate */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ -/* _ (Word16) coder_type : coder type */ -/* _ (Word16) i_subfr : subframe number */ -/* _ (Word16) voice_fac : subframe voicing estimation (Q15) */ -/* _ (Word16) stab_fac : LP filter stablility measure (Q15) */ -/* _ (Word32) norm_gain_code : normalised innovative cb. gain (Q16) */ -/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) */ -/* _ (Word16) gain_pit_fx : Pitch gain (Q14) */ -/* _ (Word16) Q_exc : Q of the excitation */ -/* _ (Word16) Enc : Encoder = 1; decoder = 0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) core_brate : decoder bitrate */ +/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ +/* _ (Word16) coder_type : coder type */ +/* _ (Word16) i_subfr : subframe number */ +/* _ (Word16) voice_fac : subframe voicing estimation (Q15) */ +/* _ (Word16) stab_fac : LP filter stablility measure (Q15) */ +/* _ (Word32) norm_gain_code : normalised innovative cb. gain (Q16) */ +/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) */ +/* _ (Word16) gain_pit_fx : Pitch gain (Q14) */ +/* _ (Word16) Q_exc : Q of the excitation */ +/* _ (Word16) Enc : Encoder = 1; decoder = 0 */ /*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15) */ /*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word32*) gc_threshold : gain code threshold (Q16) */ -/* _ (Word16*[]) code : innovation (Q12) */ -/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0) */ -/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory */ -/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word32*) gc_threshold : gain code threshold (Q16) */ +/* _ (Word16*[]) code : innovation (Q12) */ +/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0) */ +/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory */ +/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ /*--------------------------------------------------------------------------------------*/ -/* _ None */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================================*/ void enhancer_fx( const Word32 core_brate, /* i : decoder bitrate */ @@ -87,7 +86,6 @@ void enhancer_fx( pit_sharp = gain_pit; move16(); /* to remove gcc warning */ pt_exc2 = exc2 + i_subfr; - move16(); /*------------------------------------------------------------* * Phase dispersion to enhance noise at low bit rate @@ -120,7 +118,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -186,6 +184,7 @@ void enhancer_fx( FOR( i = 0; i < L_SUBFR; i++ ) { pt_exc2[i] = round_fx( L_shl( L_mult( gain_code_hi, code[i] ), sc ) ); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + move16(); } } ELSE @@ -236,9 +235,11 @@ void enhancer_fx( #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); pt_exc2[0] = msu_r_sat( L_tmp, -32768, pt_exc2[0] ); + move16(); #else L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); + move16(); #endif move16(); /* in Q_exc */ @@ -251,6 +252,7 @@ void enhancer_fx( tmp16 = msu_r_sat( L_tmp, code[i - 1], tmp ); L_tmp = L_shl_sat( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r_sat( L_tmp, -32768, pt_exc2[i] ); + move16(); #else tmp16 = msu_r( L_tmp, code[i - 1], tmp ); L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); @@ -265,8 +267,10 @@ void enhancer_fx( L_tmp = L_shl( L_mult( gain_code_hi, extract_h( L_tmp ) ), sc ); #ifdef BASOP_NOGLOB pt_exc2[L_SUBFR - 1] = msu_r_sat( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); + move16(); #else pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); + move16(); #endif move16(); /* in Q_exc */ test(); @@ -294,38 +298,38 @@ void enhancer_fx( /*======================================================================================*/ -/* FUNCTION : enhancer_fx() */ +/* FUNCTION : enhancer_fx() */ /*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Enhancement of the excitation signal before synthesis */ +/* PURPOSE : Enhancement of the excitation signal before synthesis */ /*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : decoder bitrate */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ -/* _ (Word16) coder_type : coder type */ -/* _ (Word16) i_subfr : subframe number */ -/* _ (Word16) voice_fac : subframe voicing estimation (Q15) */ -/* _ (Word16) stab_fac : LP filter stablility measure (Q15) */ -/* _ (Word32) norm_gain_code : normalised innovative cb. gain (Q16) */ -/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) */ -/* _ (Word16) gain_pit_fx : Pitch gain (Q14) */ -/* _ (Word16) Q_exc : Q of the excitation */ -/* _ (Word16) Enc : Encoder = 1; decoder = 0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) core_brate : decoder bitrate */ +/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ +/* _ (Word16) coder_type : coder type */ +/* _ (Word16) i_subfr : subframe number */ +/* _ (Word16) voice_fac : subframe voicing estimation (Q15) */ +/* _ (Word16) stab_fac : LP filter stablility measure (Q15) */ +/* _ (Word32) norm_gain_code : normalised innovative cb. gain (Q16) */ +/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) */ +/* _ (Word16) gain_pit_fx : Pitch gain (Q14) */ +/* _ (Word16) Q_exc : Q of the excitation */ +/* _ (Word16) Enc : Encoder = 1; decoder = 0 */ /*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15) */ /*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word32*) gc_threshold : gain code threshold (Q16) */ -/* _ (Word16*[]) code : innovation (Q12) */ -/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0) */ -/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory */ -/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word32*) gc_threshold : gain code threshold (Q16) */ +/* _ (Word16*[]) code : innovation (Q12) */ +/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0) */ +/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory */ +/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ /*--------------------------------------------------------------------------------------*/ -/* _ None */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================================*/ void enhancer_ivas_fx( const Word16 codec_mode, /* i : flag indicating Codec Mode */ @@ -358,7 +362,6 @@ void enhancer_ivas_fx( pit_sharp = gain_pit; move16(); /* to remove gcc warning */ pt_exc2 = exc2 + i_subfr; - move16(); /*------------------------------------------------------------* * Phase dispersion to enhance noise at low bit rate @@ -366,6 +369,9 @@ void enhancer_ivas_fx( i = 2; move16(); /* no dispersion */ + test(); + test(); + test(); IF( Opt_AMR_WB ) { IF( LE_32( core_brate, ACELP_6k60 ) ) @@ -391,7 +397,7 @@ void enhancer_ivas_fx( i = 0; move16(); /* high dispersion */ } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && LE_32( core_brate, ACELP_9k60 ) ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -399,18 +405,29 @@ void enhancer_ivas_fx( } ELSE IF( EQ_16( codec_mode, MODE2 ) ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 2 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME ) && LE_16( cbk_index, 10 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME16k ) && LE_16( cbk_index, 14 ) ) ) { i = 0; /* high dispersion */ + move16(); } ELSE IF( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 7 ) ) { i = 1; /* low dispersion */ + move16(); } } ELSE IF( EQ_16( codec_mode, MODE1 ) && EQ_16( coder_type, UNVOICED ) && cbk_index /*uc_two_stage_flag*/ ) { i = 0; /* high dispersion */ + move16(); } phase_dispersion_fx( norm_gain_code, gain_pit, code, i, dm_fx ); @@ -472,6 +489,7 @@ void enhancer_ivas_fx( FOR( i = 0; i < L_SUBFR; i++ ) { pt_exc2[i] = round_fx( L_shl( L_mult( gain_code_hi, code[i] ), sc ) ); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + move16(); } } ELSE @@ -593,7 +611,7 @@ Word16 E_UTIL_enhancer( move16(); code_exp = 15 - 9; - exc2_exp = 15 - Q_new; + exc2_exp = sub( 15, Q_new ); gain_inov = shr( gain_inov, 1 ); /*-----------------------------------------------------------------* * Phase dispersion to enhance noise at low bit rates @@ -659,8 +677,9 @@ Word16 E_UTIL_enhancer( L_tmp = Mpy_32_32( L_tmp, 1804608000l /*1.0f/1.19f Q31*/ ); L_tmp = L_max( L_tmp, *gc_threshold ); } - move32(); + *gc_threshold = L_tmp; /* in 15Q16 */ + move32(); /* gain = ( (fac * L_tmp) + (gain_code - fac*gain_code) ) * gain_inov */ /* exponent of L_tmp: 31-16 + 15-11 */ @@ -670,7 +689,6 @@ Word16 E_UTIL_enhancer( tmp = norm_l( L_tmp ); /* exponent of code: 31-16 + 15-11 - tmp + code_exp */ - move16(); code_exp = sub( add( 31 - 16 + 15 - 11, code_exp ), tmp ); #ifdef BASOP_NOGLOB @@ -699,7 +717,7 @@ Word16 E_UTIL_enhancer( gain = add( sub( code_exp, exc2_exp ), 1 ); tmp = mac_r( 268435456l /*0.125f Q31*/, 4096 /*0.125f Q15*/, voice_fac ); /* 0.25=voiced, 0=unvoiced */ - if ( EQ_16( L_frame, L_FRAME16k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { tmp = mac_r( 322122560l /*0.150f Q31*/, 4915 /*0.150f Q15*/, voice_fac ); /* 0.30=voiced, 0=unvoiced */ } @@ -707,7 +725,7 @@ Word16 E_UTIL_enhancer( /* exc2[0] = exc2[0] + code[0] - tmp*code[1]; */ L_tmp = L_mult( code[0], 16384 ); L_tmp = L_msu0( L_tmp, tmp, code[1] ); - if ( gain ) + IF( gain ) { #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_tmp, gain ); @@ -722,14 +740,14 @@ Word16 E_UTIL_enhancer( #endif move16(); - FOR( i = 1; i < L_subfr - 1; i++ ) + FOR( i = 1; i < sub( L_subfr, 1 ); i++ ) { /* exc2[i] = exc2[i] + code[i] - tmp*(code[i+1]+code[i-1]); */ L_tmp = L_mult( code[i], 16384 ); #ifdef BASOP_NOGLOB L_tmp = L_msu0_sat( L_tmp, tmp, code[i - 1] ); L_tmp = L_msu0_sat( L_tmp, tmp, code[i + 1] ); - if ( gain ) + IF( gain ) { L_tmp = L_shl_sat( L_tmp, gain ); } @@ -749,7 +767,7 @@ Word16 E_UTIL_enhancer( L_tmp = L_mult( code[i], 16384 ); #ifdef BASOP_NOGLOB L_tmp = L_msu0_sat( L_tmp, tmp, code[i - 1] ); - if ( gain ) + IF( gain ) { L_tmp = L_shl_sat( L_tmp, gain ); } @@ -774,28 +792,28 @@ Word16 E_UTIL_enhancer( * post-processing to enhance noise in low bit rate. *-----------------------------------------------------------------------*/ /*======================================================================================*/ -/* FUNCTION : phase_dispersion_fx() */ +/* FUNCTION : phase_dispersion_fx() */ /*--------------------------------------------------------------------------------------*/ -/* PURPOSE : post-processing to enhance noise in low bit rate. */ +/* PURPOSE : post-processing to enhance noise in low bit rate. */ /*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) gain_code : gain of code Q16 */ -/* _ (Word16) gain_pit : gain of pitch Q14 */ -/* _ (Word16) mode : level, 0=hi, 1=lo, 2=off */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) gain_code : gain of code Q16 */ +/* _ (Word16) gain_pit : gain of pitch Q14 */ +/* _ (Word16) mode : level, 0=hi, 1=lo, 2=off */ /*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ +/* OUTPUT ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) code : code vector (Q12) */ -/* _ (struct dispMem_fx*) dm_fx : static memory (size = 8) */ -/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) code : code vector (Q12) */ +/* _ (struct dispMem_fx*) dm_fx : static memory (size = 8) */ +/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */ /*--------------------------------------------------------------------------------------*/ -/* _ None */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================================*/ static void phase_dispersion_fx( Word32 gain_code, /* i : gain of code Q16 */ @@ -886,26 +904,19 @@ static void phase_dispersion_fx( r_fft_fx_lc( phs_tbl_dec, SIZE, SIZE2, NUM_STAGES, code, code2, 1 ); h_real = Mid_H_phasedisp; - move16(); if ( state == 0 ) { h_real = Low_H_phasedisp; - move16(); } /* FFT Coefs are in code2 */ code2_real = code2; - move16(); code2_imag = code2 + L_SUBFR - 1; - move16(); code_real = code; - move16(); code_imag = code + L_SUBFR - 1; - move16(); h_imag = h_real + L_SUBFR - 1; - move16(); *code_real++ = mult( *code2_real++, *h_real++ ); move16(); /* DC */ @@ -937,25 +948,25 @@ static void phase_dispersion_fx( } /*======================================================================================*/ -/* FUNCTION : agc2_fx() */ +/* FUNCTION : agc2_fx() */ /*--------------------------------------------------------------------------------------*/ -/* PURPOSE : AGC post-processing for lower G722.2 modes */ +/* PURPOSE : AGC post-processing for lower G722.2 modes */ /*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*[]) sig_in : postfilter input signal (Q0) */ -/* _ (Word16) l_trm : subframe size */ +/* INPUT ARGUMENTS : */ +/* _ (Word16*[]) sig_in : postfilter input signal (Q0) */ +/* _ (Word16) l_trm : subframe size */ /*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ +/* OUTPUT ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*[]) sig_out : postfilter output signal (Q0) */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16*[]) sig_out : postfilter output signal (Q0) */ /*--------------------------------------------------------------------------------------*/ -/* _ None */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================================*/ static void agc2_fx( const Word16 *sig_in, /* i : postfilter input signal */ @@ -1034,6 +1045,7 @@ static void agc2_fx( #else sig_out[i] = round_fx( L_shl( L_mac( -8192, sig_out[i], g0 ), 2 ) ); #endif + move16(); } } } diff --git a/lib_com/enr_1_az.c b/lib_com/enr_1_az.c index f55d6917bbf72fcbca14e7f44414e36749f39214..3285c515a469368aa8f0d7f366614a5c74b197e1 100644 --- a/lib_com/enr_1_az.c +++ b/lib_com/enr_1_az.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * enr_1_Az() @@ -84,6 +84,7 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 Word32 L_tmp, L_tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Find the impulse response */ @@ -99,12 +100,14 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 /* h1_in Q11, h1_out Q10 */ L_tmp = L_mult( a0, 1 << 13 ); /* Q25 = L_mult(Q11,Q13) */ *y = round_fx( L_tmp ); /* Q25 to Q9 */ - L_tmp2 = L_mult( *y, *y ); /* Q19 = L_mult(Q9,Q9) */ + move16(); + L_tmp2 = L_mult( *y, *y ); /* Q19 = L_mult(Q9,Q9) */ y++; L_tmp = L_msu( 0, Aq[1], y[-1] ); /* Q23 = L_mult(Q14,Q9) */ L_tmp = L_shl( L_tmp, q ); - *y = round_fx( L_tmp ); /* Q25 to Q9 */ + *y = round_fx( L_tmp ); /* Q25 to Q9 */ + move16(); L_tmp2 = L_mac( L_tmp2, *y, *y ); /* Q19 = L_mult(Q9,Q9) */ y++; @@ -124,6 +127,7 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 #ifdef BASOP_NOGLOB L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y = round_fx_o( L_tmp, &Overflow ); + move16(); L_tmp2 = L_mac_o( L_tmp2, *y, *y, &Overflow ); #else L_tmp = L_shl( L_tmp, q ); @@ -148,6 +152,7 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 #ifdef BASOP_NOGLOB L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y = round_fx_o( L_tmp, &Overflow ); + move16(); L_tmp2 = L_mac_o( L_tmp2, *y, *y, &Overflow ); #else L_tmp = L_shl( L_tmp, q ); @@ -158,6 +163,7 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 } #ifdef BASOP_NOGLOB *Overflow_out = Overflow; + move32(); return round_fx_o( L_tmp2, Overflow_out ); /* Q19 to Q3 */ #else return round_fx( L_tmp2 ); /* Q19 to Q3 */ @@ -170,6 +176,7 @@ Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 ) { Flag Overflow = 0; + move32(); return Enr_1_Az_fx_o( Aq, len, &Overflow ); } #endif diff --git a/lib_com/env_adj.c b/lib_com/env_adj.c index e6b6e57bda0551278d00b145b039e555336d267e..39e29e8fa48f220f9b788726f50ed7fb175d300a 100644 --- a/lib_com/env_adj.c +++ b/lib_com/env_adj.c @@ -40,8 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------------* * env_adj() @@ -259,7 +258,8 @@ void env_adj_fx( } ELSE { - adj[i] = MAX_16; /* Q15, 1.0f (saturated) */ + adj[i] = MAX_16; /* Q15, 1.0f (saturated) */ + move16(); IF( EQ_16( att_state, 1 ) ) /* End of attenuation region found */ { /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ @@ -269,7 +269,6 @@ void env_adj_fx( tmp = round_fx( L_shl( L_mult0( s_max( 0, sub( len, ENV_ADJ_START_FX ) ), ENV_ADJ_INV_INCL_FX ), 16 ) ); /* Q15 (15+16-16) */ #endif tmp_diff = sub( MAX_16, tmp ); /* Q15 */ - move16(); FOR( j = start; j < i; j++ ) { /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ diff --git a/lib_com/env_stab.c b/lib_com/env_stab.c index 4140a64dc887f2dec96901aeb3b5f3468637997d..1ccdd1184a130314dc1319c5374a3265e4cc7696 100644 --- a/lib_com/env_stab.c +++ b/lib_com/env_stab.c @@ -43,8 +43,7 @@ #include "rom_com.h" #include "wmc_auto.h" #include "stl.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ @@ -201,6 +200,7 @@ Word16 env_stability_fx( /* in Q15 */ Word16 inv_nb_sfm; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif IF( core_switching_flag ) @@ -377,6 +377,7 @@ Word16 env_stab_smo_fx( /* Q0 */ Word16 tmp, sum, exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* get previous state */ prev_state = maximum_fx( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval ); @@ -415,8 +416,10 @@ Word16 env_stab_smo_fx( /* Q0 */ { #ifdef BASOP_NOGLOB env_stab_state_p[i] = round_fx_o( L_shl_o( L_mult_o( env_stab_state_p[i], tmp, &Overflow ), add( exp, 1 ), &Overflow ), &Overflow ); /* Q15 */ + move16(); #else env_stab_state_p[i] = round_fx( L_shl( L_mult( env_stab_state_p[i], tmp ), add( exp, 1 ) ) ); /* Q15 */ + move16(); #endif } diff --git a/lib_com/env_stab_trans.c b/lib_com/env_stab_trans.c index 2062f4e77d23726ff2c2eed0a5e06003414e51a5..1d1ccff3245ffa8af2fafeacd023e534bc00f356 100644 --- a/lib_com/env_stab_trans.c +++ b/lib_com/env_stab_trans.c @@ -41,8 +41,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------------* * env_stab_transient_detect() * @@ -231,6 +230,7 @@ void env_stab_transient_detect_fx( FOR( blk = 0; blk < NUM_SUBFRAMES; blk++ ) { L_E_sub[blk] = L_deposit_l( 0 ); /* Q9 */ + move32(); FOR( i = 0; i < BANDS_PER_SUBFRAMES; i++ ) /* 9 times -> < 2^4 */ { @@ -291,7 +291,7 @@ void env_stab_transient_detect_fx( *no_att_hangover = ATT_LIM_HANGOVER; move16(); } - ELSE if ( *no_att_hangover > 0 ) + ELSE IF( *no_att_hangover > 0 ) { *no_att_hangover = sub( *no_att_hangover, 1 ); move16(); diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index c556536e4e0489e29be1217cab38950cf60c72d5..6f541c11f3f459016f3637e2d699e7902e8906fe 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" #include "basop_util.h" diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 5e0ec84eda15b64c72f2fb6f354dc58800bfb16c..1243cf6686775b304087ec5c9c8db29ac4d78b31 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -39,7 +39,7 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" @@ -109,7 +109,7 @@ void initFdCngCom_flt( set_f( hFdCngCom->A_cng_flt, 0.0f, M + 1 ); hFdCngCom->A_cng_flt[0] = 1.f; #ifdef IVAS_FLOAT_FIXED - set_s( hFdCngCom->A_cng, 0, M + 1 ); + set16_fx( hFdCngCom->A_cng, 0, M + 1 ); hFdCngCom->A_cng[0] = MAX_16; #endif @@ -957,60 +957,66 @@ void SynthesisSTFT_flt( void SynthesisSTFT_fx( Word32 *fftBuffer, /* i : FFT bins */ - Word16 Q_in, Word32 *timeDomainOutput, Word32 *olapBuffer, const Word16 *olapWin, - const int16_t tcx_transition, + const Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const int16_t element_mode, /* i : element mode */ - const int16_t nchan_out /* i : number of output channels */ + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ ) { - int16_t i; + Word16 i; Word32 buf_fx[M + 1 + 320], tmp_fx; /* Perform IFFT */ RFFTN_fx( fftBuffer, hFdCngCom->fftSineTab_fx, hFdCngCom->fftlen, 1 ); /* Handle overlap in P/S domain for stereo */ - IF( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 ) + test(); + test(); + IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { - mvl2l( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf_fx, hFdCngCom->frameSize + M + 1 ); - set_l( olapBuffer, 0, hFdCngCom->fftlen ); + Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); + set32_fx( olapBuffer, 0, hFdCngCom->fftlen ); } ELSE { - mvl2l( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); - set_l( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ + Copy32( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); + set32_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ } IF( tcx_transition ) { - FOR( i = 0; i < 5 * hFdCngCom->frameSize / 4; i++ ) + FOR( i = 0; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; + move32(); } } ELSE { - FOR( i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++ ) + FOR( i = hFdCngCom->frameSize / 4; i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + move32(); } - FOR( ; i < 5 * hFdCngCom->frameSize / 4; i++ ) + FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; + move32(); } } - FOR( ; i < 7 * hFdCngCom->frameSize / 4; i++ ) + FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4] ); + olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + move32(); } FOR( ; i < hFdCngCom->fftlen; i++ ) { olapBuffer[i] = 0; + move32(); } Word32 fftScale = 0; @@ -1018,44 +1024,50 @@ void SynthesisSTFT_fx( { case 640: fftScale = FFT_SCALING_640; - break; + move32(); + BREAK; case 512: fftScale = FFT_SCALING_512; - break; + move32(); + BREAK; default: assert( !"Not supported FFT length!" ); } /* Get time-domain signal */ // v_multc(olapBuffer + hFdCngCom->frameSize / 4, (float)(hFdCngCom->fftlen / 2), timeDomainOutput, hFdCngCom->frameSize); v_multc_fixed( olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, hFdCngCom->frameSize ); // Q_in - 9 - /* Get excitation */ - IF( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 ) + /* Get excitation */ + test(); + test(); + IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[i + hFdCngCom->frameSize / 4] ); + buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[add( i, shr( hFdCngCom->frameSize, 2 ) )] ); + move32(); } // v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); - v_multc_fixed( buf_fx, fftScale, buf_fx, M + 1 + hFdCngCom->frameSize ); + v_multc_fixed( buf_fx, fftScale, buf_fx, add( M + 1, hFdCngCom->frameSize ) ); } ELSE { // v_multc(olapBuffer + hFdCngCom->frameSize / 4 - (M + 1), (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); - v_multc_fixed( olapBuffer + ( hFdCngCom->frameSize / 4 ) - ( M + 1 ), fftScale, buf_fx, M + 1 + hFdCngCom->frameSize ); + v_multc_fixed( olapBuffer + sub( shr( hFdCngCom->frameSize, 2 ), ( M + 1 ) ), fftScale, buf_fx, add( M + 1, hFdCngCom->frameSize ) ); } tmp_fx = buf_fx[0]; + move32(); // preemph(buf + 1, PREEMPH_FAC_FLT, M + hFdCngCom->frameSize, &tmp); - preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp_fx ); + preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, add( M, hFdCngCom->frameSize ), &tmp_fx ); // residu(hFdCngCom->A_cng_flt, M, buf + 1 + M, hFdCngCom->exc_cng_flt, hFdCngCom->frameSize); // floatToFixed_arr( hFdCngCom->A_cng_flt, hFdCngCom->A_cng, Q13, M + 1 ); // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); residu_ivas_fx( hFdCngCom->A_cng, ( 15 - norm_s( hFdCngCom->A_cng[0] - 1 ) ), M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); - for ( i = 0; i < hFdCngCom->frameSize; i++ ) - { - hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 ); - } + // for ( i = 0; i < hFdCngCom->frameSize; i++ ) + //{ + // hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 ); + // } return; } @@ -1149,7 +1161,8 @@ void SynthesisSTFT_dirac_fx( FOR( i = shr( hFdCngCom->frameSize, 2 ); i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + move32(); } FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { @@ -1186,14 +1199,15 @@ void SynthesisSTFT_dirac_fx( } /* Get time-domain signal */ - v_multc_fixed( olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, samples_out ); // Q_in - 9 + v_multc_fixed( olapBuffer + shr( hFdCngCom->frameSize, 2 ), fftScale, timeDomainOutput, samples_out ); // Q_in - 9 /* Get excitation */ - v_multc_fixed( olapBuffer + ( hFdCngCom->frameSize / 4 ) - ( M + 1 ), fftScale, buf, M + 1 + hFdCngCom->frameSize ); + v_multc_fixed( olapBuffer + sub( shr( hFdCngCom->frameSize, 2 ), ( M + 1 ) ), fftScale, buf, add( M + 1, hFdCngCom->frameSize ) ); tmp = buf[0]; + move32(); preemph_ivas_fx( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); // residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); - residu_ivas_fx( hFdCngCom->A_cng, 15 - norm_s( hFdCngCom->A_cng[0] - 1 ), M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); + residu_ivas_fx( hFdCngCom->A_cng, sub( 15, norm_s( hFdCngCom->A_cng[0] - 1 ) ), M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/ IF( LT_16( samples_out, hFdCngCom->frameSize ) ) @@ -1202,7 +1216,8 @@ void SynthesisSTFT_dirac_fx( } FOR( i = i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4] ); + olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + move32(); } return; @@ -1286,9 +1301,10 @@ Word32 rand_gauss_fx( temp = own_random( seed ); temp = L_add( temp, own_random( seed ) ); temp = L_add( temp, own_random( seed ) ); - temp = L_shr( temp, 15 - q ); + temp = L_shr( temp, sub( 15, q ) ); *x = temp; + move32(); return temp; } @@ -1311,6 +1327,7 @@ Word16 rand_gauss_fix( temp = L_add( temp, shr( own_random( seed ), Q2 ) ); *x = (Word16) temp; + move32(); return (Word16) temp; } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 7125ec40cc4db0d5f111f9f312b5bbfcc6f4a788..16a5ae86940982922c8681a1b6097c0fbd1b1ea3 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -9,8 +9,7 @@ #include "options.h" #include "rom_basop_util.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #define DELTA_SHIFT 2 @@ -36,7 +35,7 @@ ivas_error createFdCngCom( HANDLE_FD_CNG_COM hs; /* Allocate memory */ - hs = (HANDLE_FD_CNG_COM) count_malloc( sizeof( FD_CNG_COM ) ); + hs = (HANDLE_FD_CNG_COM) malloc( sizeof( FD_CNG_COM ) ); if ( hs == NULL ) { @@ -288,7 +287,7 @@ void deleteFdCngCom( HANDLE_FD_CNG_COM *hFdCngCom ) /* i/o: Contains the variabl move16(); IF( hsCom != NULL ) { - count_free( hsCom ); + free( hsCom ); *hFdCngCom = NULL; move16(); } @@ -395,10 +394,12 @@ void compress_range( if ( in_s != 0 ) { out[i] = extract_h( L_tmp ); + move16(); } if ( out[i] == 0 ) { out[i] = 1; + move16(); } } } @@ -417,10 +418,12 @@ void compress_range( if ( in[i] != 0 ) { out[i] = extract_h( L_tmp ); + move16(); } if ( out[i] == 0 ) { out[i] = 1; + move16(); } } } @@ -523,7 +526,7 @@ void expand_range_var_exp( move32(); Word32 tmp_low_lim = L_shr( low_lim, maxOutExp ); - IF( LT_32( out[i], tmp_low_lim ) ) + if ( LT_32( out[i], tmp_low_lim ) ) { out[i] = tmp_low_lim; move32(); @@ -603,6 +606,7 @@ void minimum_statistics( Word16 msNoiseFloor16; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -765,7 +769,7 @@ void minimum_statistics( FOR( j = start; j < stop; j++ ) { - /* Compute optimal smoothing parameter for PSD estimation */ test(); + /* Compute optimal smoothing parameter for PSD estimation */ test(); IF( ( scalar == 0 ) || ( msNoiseFloor[j] == 0 ) ) { @@ -827,6 +831,7 @@ void minimum_statistics( /* Compute the PSD (smoothed periodogram) in each band */ msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ) ); + move16(); } msPsdSum[cnt] = dotp_s_fx( msPsd + start, psize + start, current_len, CNG_HS ); move32(); @@ -1077,6 +1082,7 @@ void minimum_statistics( FOR( j = 0; j < len; j++ ) { msCurrentMinOut[j] = L_deposit_h( msPeriodog[j] ); + move32(); } set32_fx( hFdCngCom->msAlphaCor, 2147483647l /*1.0 Q31*/, cnt ); set32_fx( msAlpha, 0l /*0.0 Q31*/, len ); @@ -1123,6 +1129,7 @@ void minimum_statistics( FOR( j = 0; j < len; j++ ) { msNoiseEst[j] = round_fx( L_mac( L_mult( 31130 /*0.95 Q15*/, msNoiseEst[j] ), 1638 /*0.05 Q15*/, msNoiseFloor[j] ) ); + move16(); } } #ifdef IVAS_CODE_CNG_COM @@ -1221,6 +1228,7 @@ void minimum_statistics_fx( Word16 msNoiseFloor16; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -1352,8 +1360,12 @@ void minimum_statistics_fx( scalar16 = shl( scalar16, s3 ); scalar16 = s_max( scalar16, MSALPHACORMAX ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + hFdCngCom->msAlphaCor[cnt] = Madd_32_16( L_mult( scalar16, msAlphaCorAlpha2 ), hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ); +#else hFdCngCom->msAlphaCor[cnt] = L_add( Mpy_32_16_1( hFdCngCom->msAlphaCor[cnt], msAlphaCorAlpha ), L_mult( scalar16, msAlphaCorAlpha2 ) ); +#endif move32(); } @@ -1379,7 +1391,7 @@ void minimum_statistics_fx( FOR( j = start; j < stop; j++ ) { - /* Compute optimal smoothing parameter for PSD estimation */ test(); + /* Compute optimal smoothing parameter for PSD estimation */ test(); IF( ( scalar == 0 ) || ( msNoiseFloor[j] == 0 ) ) { @@ -1439,8 +1451,13 @@ void minimum_statistics_fx( } /* Compute the PSD (smoothed periodogram) in each band */ +#ifdef IVAS_ENH32_CADENCE_CHANGES + msPsd[j] = round_fx( Madd_32_16( Mpy_32_16_1( msAlpha[j], msPsd[j] ), L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ); +#else msPsd[j] = round_fx( L_add( Mpy_32_16_1( msAlpha[j], msPsd[j] ), Mpy_32_16_1( L_sub( 2147483647l /*1.0 Q31*/, msAlpha[j] ), msPeriodog[j] ) ) ); +#endif + move16(); } msPsdSum[cnt] = dotp_s_fx( msPsd + start, psize + start, current_len, CNG_HS ); move32(); @@ -1518,13 +1535,21 @@ void minimum_statistics_fx( /* Compute bias correction Bmin */ tmp0 = Mpy_32_16_1( scalar, QeqInv ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_win, QeqInv ); +#else tmp1 = L_sub( 1073741824l /*0.5 Q31*/, L_mult( msM_win, QeqInv ) ); +#endif tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), add( s, 7 - 4 ) ) ); move32(); tmp0 = Mpy_32_16_1( scalar2, QeqInv ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + tmp1 = L_msu( 1073741824l /*0.5 Q31*/, msM_subwin, QeqInv ); +#else tmp1 = L_sub( 1073741824l /*0.5 Q31*/, L_mult( msM_subwin, QeqInv ) ); +#endif tmp16 = BASOP_Util_Divide3232_uu_1616_Scale( tmp0, tmp1, &s ); msBminSubWin[j] = L_add( 134217728l /*1.0 Q27*/, L_shl( L_deposit_h( tmp16 ), s ) ); move32(); @@ -1691,6 +1716,7 @@ void minimum_statistics_fx( FOR( j = 0; j < len; j++ ) { msCurrentMinOut[j] = L_deposit_h( msPeriodog[j] ); + move32(); } set32_fx( hFdCngCom->msAlphaCor, 2147483647l /*1.0 Q31*/, cnt ); set32_fx( msAlpha, 0l /*0.0 Q31*/, len ); @@ -1731,12 +1757,14 @@ void minimum_statistics_fx( ELSE { hFdCngCom->msFrCnt = add( hFdCngCom->msFrCnt, 1 ); + move16(); } /* Smooth noise estimate during CNG phases */ FOR( j = 0; j < len; j++ ) { msNoiseEst[j] = round_fx( L_mac( L_mult( 31130 /*0.95 Q15*/, msNoiseEst[j] ), 1638 /*0.05 Q15*/, msNoiseFloor[j] ) ); + move16(); } } if ( enc_dec == DEC && element_mode == IVAS_CPE_TD ) @@ -1804,6 +1832,7 @@ void apply_scale( { *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); + move32(); } } @@ -1837,6 +1866,7 @@ Word16 apply_scale_ind( { *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); + move32(); } return i; } @@ -1864,7 +1894,9 @@ void apply_scale_ivas_fx( assert( i < scaleTableSize ); *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); + move32(); *index = i; + move16(); } #endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- @@ -1961,6 +1993,7 @@ void scalebands( delta = 0; move16(); partpowLD64M1 = 0L; /* to avoid compilation warnings */ + move32(); /* Interpolate the bin/band-wise levels from the partition levels */ IF( EQ_16( nband, npart ) ) @@ -2102,6 +2135,7 @@ void scalebands_fx( delta = 0; move16(); partpowLD64M1 = 0L; /* to avoid compilation warnings */ + move32(); /* Interpolate the bin/band-wise levels from the partition levels */ IF( EQ_16( nband, npart ) ) @@ -2155,7 +2189,14 @@ void scalebands_fx( nint = sub( midband[j], midband[j - 1] ); /* log-linear interpolation */ - partpowLD64 = BASOP_Util_Log2( L_add( partpow[j], DELTA_FX ) ); + IF( NE_32( partpow[j], MAX_32 ) ) + { + partpowLD64 = BASOP_Util_Log2( L_add( partpow[j], DELTA_FX ) ); + } + ELSE + { + partpowLD64 = BASOP_Util_Log2( partpow[j] ); + } tmp = L_sub( partpowLD64, partpowLD64M1 ); tmp = Mpy_32_16_1( tmp, getNormReciprocalWord16( nint ) ); @@ -2208,7 +2249,21 @@ void scalebands_fx( move32(); FOR( ; i <= part[stopPartM1]; i++ ) { - val = L_shl( Mpy_32_16_1( val, delta ), s1 ); + test(); + IF( val != 0 && delta != 0 ) + { + val = L_shl( Mpy_32_16_1( val, delta ), s1 ); + IF( val == 0 ) + { + val = 1; + move32(); + } + } + ELSE + { + val = 0; + move32(); + } bandpow[i] = val; move32(); } @@ -2241,6 +2296,7 @@ static void getmidbands( Word16 j, max_psize, shift; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -2248,6 +2304,7 @@ static void getmidbands( move16(); /* first half partition */ move16(); midband[0] = part[0]; + move16(); psize[0] = add( part[0], 1 ); move16(); psize_inv[0] = getNormReciprocalWord16( psize[0] ); @@ -2401,8 +2458,10 @@ void AnalysisSTFT_fx( FOR( i = 0; i < hFdCngCom->fftlen; i++ ) { fftBuffer[i] = L_shr( fftBuffer[i], 11 ); + move32(); } *fftBuffer_exp = WORD16_BITS + 11; + move16(); /* Perform FFT */ RFFTN_fx( fftBuffer, hFdCngCom->fftSineTab_fx, hFdCngCom->fftlen, -1 ); @@ -2439,9 +2498,11 @@ void SynthesisSTFT( /* Perform IFFT */ scale = 0; + move16(); BASOP_rfft( fftBuffer, hFdCngCom->fftlen, &scale, 1 ); fftBufferExp = add( fftBufferExp, scale ); hFdCngCom->fftBuffer_exp = fftBufferExp; + move16(); fftBufferExp = add( fftBufferExp, hFdCngCom->fftlenShift ); @@ -2465,16 +2526,17 @@ void SynthesisSTFT( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx( L_shl( fftBuffer[i], fftBufferExp - 15 ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + move16(); } } ELSE { FOR( i = 0; i < len4; i++ ) { - olapBuffer[i + 1 * len4] = add_sat( olapBuffer[i + 1 * len4], mult_r( round_fx( L_shl( fftBuffer[i + 1 * len4], fftBufferExp - 15 ) ), olapWin[i].v.im ) ); + olapBuffer[i + 1 * len4] = add_sat( olapBuffer[i + 1 * len4], mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 1 * len4], fftBufferExp - 15 ) ), olapWin[i].v.im ) ); move16(); - olapBuffer[i + 2 * len4] = add_sat( olapBuffer[i + 2 * len4], mult_r( round_fx( L_shl( fftBuffer[i + 2 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.re ) ); + olapBuffer[i + 2 * len4] = add_sat( olapBuffer[i + 2 * len4], mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 2 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.re ) ); move16(); } FOR( i = len3; i < len; i++ ) @@ -2485,9 +2547,9 @@ void SynthesisSTFT( FOR( i = 0; i < len4; i++ ) { - olapBuffer[i + 5 * len4] = mult_r( round_fx( L_shl( fftBuffer[i + 5 * len4], fftBufferExp - 15 ) ), olapWin[i].v.re ); + olapBuffer[i + 5 * len4] = mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 5 * len4], fftBufferExp - 15 ) ), olapWin[i].v.re ); move16(); - olapBuffer[i + 6 * len4] = mult_r( round_fx( L_shl( fftBuffer[i + 6 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.im ); + olapBuffer[i + 6 * len4] = mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 6 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.im ); move16(); } @@ -2685,6 +2747,7 @@ void mhvals( tmp2_m = BASOP_Util_Add_Mant32Exp( tmp2_m, tmp2_e, L_deposit_h( m_array[i] ), 0, &tmp2_e ); assert( tmp2_e == 0 ); *m = extract_h( tmp2_m ); + move32(); } } @@ -2735,9 +2798,12 @@ void lpc_from_spectrum( Word32 *powspec = hFdCngCom->cngNoiseLevel; /*i : pointer to noise levels format Q5.27*/ Word16 powspec_exp = hFdCngCom->cngNoiseLevelExp; + move16(); Word16 fftlen = hFdCngCom->fftlen; /*i : size of fft*/ Word16 *A = hFdCngCom->A_cng; /*o : lpc coefficients format Q3.12*/ + move16(); Word16 lpcorder = M; + move16(); scale = 0; move16(); @@ -2767,6 +2833,7 @@ void lpc_from_spectrum( *ptr = nf; move32(); *pti = L_deposit_l( 0 ); + move32(); ptr += 2; pti += 2; } @@ -2776,6 +2843,7 @@ void lpc_from_spectrum( *ptr = L_max( nf, L_shl( powspec[i - start], s1 ) ); move32(); *pti = L_deposit_l( 0 ); + move32(); ptr += 2; pti += 2; } @@ -2785,6 +2853,7 @@ void lpc_from_spectrum( *ptr = nf; move32(); *pti = L_deposit_l( 0 ); + move32(); ptr += 2; pti += 2; } @@ -2960,6 +3029,7 @@ void FdCng_exc( Word16 i; *CNG_mode = -1; + move16(); FOR( i = 0; i < L_frame / L_SUBFR; i++ ) { diff --git a/lib_com/fft.c b/lib_com/fft.c index 75f54e2c3687db9e255cced18cc3969259efab4a..c40556298afc72ef798433d84e7caf51de974910 100644 --- a/lib_com/fft.c +++ b/lib_com/fft.c @@ -6513,21 +6513,21 @@ static void BASOP_fft8( move32(); im[s * 6] = L_add( s05, s07 ); move32(); - re[s * 3] = L_add( s08, s14 ); + re[i_mult( s, 3 )] = L_add( s08, s14 ); move32(); - re[s * 7] = L_sub( s08, s14 ); + re[i_mult( s, 7 )] = L_sub( s08, s14 ); move32(); - im[s * 3] = L_add( s09, s15 ); + im[i_mult( s, 3 )] = L_add( s09, s15 ); move32(); - im[s * 7] = L_sub( s09, s15 ); + im[i_mult( s, 7 )] = L_sub( s09, s15 ); move32(); re[s * 1] = L_add( s10, s12 ); move32(); - re[s * 5] = L_sub( s10, s12 ); + re[i_mult( s, 5 )] = L_sub( s10, s12 ); move32(); im[s * 1] = L_add( s11, s13 ); move32(); - im[s * 5] = L_sub( s11, s13 ); + im[i_mult( s, 5 )] = L_sub( s11, s13 ); move32(); return; @@ -6581,23 +6581,23 @@ static void BASOP_fftN2( IF( i == 0 ) { - cplxMpy4_8_1( x02, x03, x[2 * i + 2 * 1 * dim1], x[2 * i + 2 * 1 * dim1 + 1] ); - cplxMpy4_8_1( x04, x05, x[2 * i + 2 * 2 * dim1], x[2 * i + 2 * 2 * dim1 + 1] ); - cplxMpy4_8_1( x06, x07, x[2 * i + 2 * 3 * dim1], x[2 * i + 2 * 3 * dim1 + 1] ); - cplxMpy4_8_1( x08, x09, x[2 * i + 2 * 4 * dim1], x[2 * i + 2 * 4 * dim1 + 1] ); - cplxMpy4_8_1( x10, x11, x[2 * i + 2 * 5 * dim1], x[2 * i + 2 * 5 * dim1 + 1] ); - cplxMpy4_8_1( x12, x13, x[2 * i + 2 * 6 * dim1], x[2 * i + 2 * 6 * dim1 + 1] ); - cplxMpy4_8_1( x14, x15, x[2 * i + 2 * 7 * dim1], x[2 * i + 2 * 7 * dim1 + 1] ); + cplxMpy4_8_1( x02, x03, x[add( shl( i, 1 ), i_mult( 2 * 1, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 1, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x04, x05, x[add( shl( i, 1 ), i_mult( 2 * 2, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 2, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x06, x07, x[add( shl( i, 1 ), i_mult( 2 * 3, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 3, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x08, x09, x[add( shl( i, 1 ), i_mult( 2 * 4, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 4, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x10, x11, x[add( shl( i, 1 ), i_mult( 2 * 5, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 5, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x12, x13, x[add( shl( i, 1 ), i_mult( 2 * 6, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 6, dim1 ) ), 1 )] ); + cplxMpy4_8_1( x14, x15, x[add( shl( i, 1 ), i_mult( 2 * 7, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 7, dim1 ) ), 1 )] ); } ELSE { - cplxMpy4_8_0( x02, x03, x[2 * i + 2 * 1 * dim1], x[2 * i + 2 * 1 * dim1 + 1], W[sc * i + sc * 1 * dim1 - Woff], W[sc * i + sc * 1 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x04, x05, x[2 * i + 2 * 2 * dim1], x[2 * i + 2 * 2 * dim1 + 1], W[sc * i + sc * 2 * dim1 - Woff], W[sc * i + sc * 2 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x06, x07, x[2 * i + 2 * 3 * dim1], x[2 * i + 2 * 3 * dim1 + 1], W[sc * i + sc * 3 * dim1 - Woff], W[sc * i + sc * 3 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x08, x09, x[2 * i + 2 * 4 * dim1], x[2 * i + 2 * 4 * dim1 + 1], W[sc * i + sc * 4 * dim1 - Woff], W[sc * i + sc * 4 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x10, x11, x[2 * i + 2 * 5 * dim1], x[2 * i + 2 * 5 * dim1 + 1], W[sc * i + sc * 5 * dim1 - Woff], W[sc * i + sc * 5 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x12, x13, x[2 * i + 2 * 6 * dim1], x[2 * i + 2 * 6 * dim1 + 1], W[sc * i + sc * 6 * dim1 - Woff], W[sc * i + sc * 6 * dim1 + 1 - Woff] ); - cplxMpy4_8_0( x14, x15, x[2 * i + 2 * 7 * dim1], x[2 * i + 2 * 7 * dim1 + 1], W[sc * i + sc * 7 * dim1 - Woff], W[sc * i + sc * 7 * dim1 + 1 - Woff] ); + cplxMpy4_8_0( x02, x03, x[add( shl( i, 1 ), i_mult( 2 * 1, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 1, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 1, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 1, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x04, x05, x[add( shl( i, 1 ), i_mult( 2 * 2, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 2, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 2, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 2, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x06, x07, x[add( shl( i, 1 ), i_mult( 2 * 3, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 3, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 3, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 3, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x08, x09, x[add( shl( i, 1 ), i_mult( 2 * 4, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 4, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 4, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 4, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x10, x11, x[add( shl( i, 1 ), i_mult( 2 * 5, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 5, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 5, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 5, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x12, x13, x[add( shl( i, 1 ), i_mult( 2 * 6, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 6, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 6, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 6, dim1 ) ) ), 1 ), Woff )] ); + cplxMpy4_8_0( x14, x15, x[add( shl( i, 1 ), i_mult( 2 * 7, dim1 ) )], x[add( add( shl( i, 1 ), i_mult( 2 * 7, dim1 ) ), 1 )], W[sub( add( i_mult( sc, i ), i_mult( sc, i_mult( 7, dim1 ) ) ), Woff )], W[sub( add( add( i_mult( sc, i ), i_mult( sc, i_mult( 7, dim1 ) ) ), 1 ), Woff )] ); } t00 = L_shr( L_add( x00, x08 ), SCALEFACTORN2 - 1 ); t02 = L_shr( L_sub( x00, x08 ), SCALEFACTORN2 - 1 ); @@ -6639,37 +6639,37 @@ static void BASOP_fftN2( s13 = Mpy_32_16_1( L_sub( t03, t01 ), C81_FX ); s15 = Mpy_32_16_1( L_add( t01, t03 ), C82_FX ); - re[sx * i + sx * 0 * dim1] = L_add( s00, s02 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 0, dim1 ) ) )] = L_add( s00, s02 ); move32(); - im[sx * i + sx * 0 * dim1] = L_add( s01, s03 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 0, dim1 ) ) )] = L_add( s01, s03 ); move32(); - re[sx * i + sx * 1 * dim1] = L_add( s10, s12 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 1, dim1 ) ) )] = L_add( s10, s12 ); move32(); - im[sx * i + sx * 1 * dim1] = L_add( s11, s13 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 1, dim1 ) ) )] = L_add( s11, s13 ); move32(); - re[sx * i + sx * 2 * dim1] = L_sub( s04, s06 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 2, dim1 ) ) )] = L_sub( s04, s06 ); move32(); - im[sx * i + sx * 2 * dim1] = L_sub( s05, s07 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 2, dim1 ) ) )] = L_sub( s05, s07 ); move32(); - re[sx * i + sx * 3 * dim1] = L_add( s08, s14 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 3, dim1 ) ) )] = L_add( s08, s14 ); move32(); - im[sx * i + sx * 3 * dim1] = L_add( s09, s15 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 3, dim1 ) ) )] = L_add( s09, s15 ); move32(); - re[sx * i + sx * 4 * dim1] = L_sub( s00, s02 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 4, dim1 ) ) )] = L_sub( s00, s02 ); move32(); - im[sx * i + sx * 4 * dim1] = L_sub( s01, s03 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 4, dim1 ) ) )] = L_sub( s01, s03 ); move32(); - re[sx * i + sx * 5 * dim1] = L_sub( s10, s12 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 5, dim1 ) ) )] = L_sub( s10, s12 ); move32(); - im[sx * i + sx * 5 * dim1] = L_sub( s11, s13 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 5, dim1 ) ) )] = L_sub( s11, s13 ); move32(); - re[sx * i + sx * 6 * dim1] = L_add( s04, s06 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 6, dim1 ) ) )] = L_add( s04, s06 ); move32(); - im[sx * i + sx * 6 * dim1] = L_add( s05, s07 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 6, dim1 ) ) )] = L_add( s05, s07 ); move32(); - re[sx * i + sx * 7 * dim1] = L_sub( s08, s14 ); + re[add( i_mult( sx, i ), i_mult( sx, i_mult( 7, dim1 ) ) )] = L_sub( s08, s14 ); move32(); - im[sx * i + sx * 7 * dim1] = L_sub( s09, s15 ); + im[add( i_mult( sx, i ), i_mult( sx, i_mult( 7, dim1 ) ) )] = L_sub( s09, s15 ); move32(); } diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index 6271eea2662614b131ec35080de00a1ac8f7aa99..dcc86b94ffb05cb0962982f9a06badb4f6623ad8 100644 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -37,7 +37,7 @@ #include #include "options.h" #include -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "wmc_auto.h" #include "basop_util.h" @@ -186,7 +186,7 @@ static void fft8_with_cmplx_data( cmplx *inp ) inp[1] = CL_add( s5, s6 ); inp[5] = CL_sub( s5, s6 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 8; #endif } @@ -244,7 +244,7 @@ static void fft5_with_cmplx_data( cmplx *inp ) inp[2] = CL_mac_j( y3, y4 ); inp[3] = CL_msu_j( y3, y4 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 5; #endif } @@ -351,7 +351,7 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) inp_data[3] = CL_sub( y[8], y[9] ); } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 10; #endif } @@ -598,7 +598,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) inp_data[11] = CL_mac_j( t1, t3 ); } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 20; #endif } @@ -1037,7 +1037,7 @@ static void fft30_with_cmplx_data( cmplx *inp ) l += 1; h += 1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 30; #endif } diff --git a/lib_com/fft_evs.c b/lib_com/fft_evs.c index 9f98faaa4f77b3e92d0d503dc6c8114cd36190f5..0a59cbb64e8126ff9963803dddc553e62c18bf56 100644 --- a/lib_com/fft_evs.c +++ b/lib_com/fft_evs.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" #include "rom_com.h" @@ -182,7 +181,7 @@ static void fft5_with_cmplx_data( cmplx *inp ) inp[2] = CL_mac_j( y3, y4 ); inp[3] = CL_msu_j( y3, y4 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 5; #endif } @@ -262,7 +261,7 @@ static void fft8_with_cmplx_data( cmplx *inp ) inp[1] = CL_add( s5, s6 ); inp[5] = CL_sub( s5, s6 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 8; #endif } @@ -371,7 +370,7 @@ static void fft10_with_cmplx_data( cmplx *inp_data ) inp_data[3] = CL_sub( y[8], y[9] ); } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 10; #endif } @@ -522,7 +521,7 @@ static void fft15_with_cmplx_data( cmplx *inp_data ) inp_data[4] = CL_mac_j( c_y1, c_y2 ); inp_data[14] = CL_msu_j( c_y1, c_y2 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 15; #endif } @@ -555,12 +554,15 @@ void fft16( Word32 *re, Word32 *im, Word16 s, Word16 bScale ) FOR( i = 0; i < 16; i++ ) { inp_data[i] = CL_form( re[s * i], im[s * i] ); + move64(); } fft16_with_cmplx_data( inp_data, bScale ); FOR( i = 0; i < 16; i++ ) { re[s * i] = CL_Extract_real( inp_data[i] ); + move32(); im[s * i] = CL_Extract_imag( inp_data[i] ); + move32(); } } } @@ -753,7 +755,7 @@ void fft16_with_cmplx_data( cmplx *input, Word16 bScale ) input[11] = CL_sub( t0, t4 ); input[15] = CL_mac_j( t2, t7 ); } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 16; #endif } @@ -1001,7 +1003,7 @@ static void fft20_with_cmplx_data( cmplx *inp_data ) inp_data[11] = CL_mac_j( t1, t3 ); } } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 20; #endif } @@ -1441,7 +1443,7 @@ static void fft30_with_cmplx_data( cmplx *inp ) l += 1; h += 1; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 30; #endif } @@ -1814,7 +1816,7 @@ static void fft32_with_cmplx_data( cmplx *inp ) inp[23] = CL_sub( t[0], t[2] ); inp[31] = CL_add( t[1], t[3] ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 32; #endif } @@ -1859,7 +1861,7 @@ static void fftN2( FOR( j = 0; j < dim1; j++ ) { x_cmplx[i * dim1 + j] = pComplexBuf[i + j * dim2]; -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move++; #endif } @@ -1927,6 +1929,7 @@ static void fftN2( cmplx s0, s1, s2, s3, s4, s5, s6, s7; i = 0; + move16(); { y0 = CL_shr( x_cmplx[i + 0 * dim1], 1 ); y1 = CL_shr( x_cmplx[i + 1 * dim1], 1 ); @@ -2139,7 +2142,7 @@ static void fftN2( } BREAK; } -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += len; #endif } @@ -2463,7 +2466,9 @@ void BASOP_rfft( Word32 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign ) case 320: case 640: c1 = FFTC( 0x66666680 ); + move16(); c2 = FFTC( 0x99999980 ); + move16(); FOR( i = 0; i < sizeOfFft2; i++ ) { x[2 * i] = Mpy_32_xx( x[2 * i], c1 ); diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 7a0d153eb87f1ff66635ca999d3da60f490d942a..024221ca6cffcc973588886a0ce131cdb5cce31d 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -45,8 +45,7 @@ #include #include "cnst.h" // #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" //#include "cnst_fx.h" #include "rom_com.h" #include "rom_com_fx.h" @@ -188,27 +187,48 @@ static void fft15_shift2( Word32 f4o7, f4o8, f4o9, f4o10, f4o11, f4o12, f4o13, f4o14, f4o15, f4o16, f4o17, f4o18, f4o19; in0 = Idx[0]; + move16(); in8 = Idx[n1]; + move16(); in16 = Idx[n1 * 2]; - in24 = Idx[n1 * 3]; + move16(); + in24 = Idx[i_mult( n1, 3 )]; + move16(); in32 = Idx[n1 * 4]; - in1 = Idx[n1 * 5]; + move16(); + in1 = Idx[i_mult( n1, 5 )]; + move16(); in9 = Idx[n1 * 6]; - in17 = Idx[n1 * 7]; + move16(); + in17 = Idx[i_mult( n1, 7 )]; + move16(); in25 = Idx[n1 * 8]; - in33 = Idx[n1 * 9]; + move16(); + in33 = Idx[i_mult( n1, 9 )]; + move16(); in2 = Idx[n1 * 10]; - in10 = Idx[n1 * 11]; + move16(); + in10 = Idx[i_mult( n1, 11 )]; + move16(); in18 = Idx[n1 * 12]; - in26 = Idx[n1 * 13]; + move16(); + in26 = Idx[i_mult( n1, 13 )]; + move16(); in34 = Idx[n1 * 14]; + move16(); f2i13 = zRe[in0]; + move32(); f2i14 = zIm[in0]; + move32(); f2i21 = zRe[in1]; + move32(); f2i22 = zRe[in2]; + move32(); f2i23 = zIm[in1]; + move32(); f2i24 = zIm[in2]; + move32(); f2i15 = L_add( f2i21, f2i22 ); f2i16 = Mpy_32_16_1( L_sub( f2i22, f2i21 ), FFT_15PONIT_WNK4 ); @@ -225,29 +245,41 @@ static void fft15_shift2( fi6 = L_sub( f2i20, f2i16 ); f3i1 = zRe[in9]; + move32(); f4i2 = zRe[in10]; + move32(); f4i3 = zRe[in8]; + move32(); f3i2 = L_add( f4i2, f4i3 ); f3i3 = L_sub( f3i1, L_shr( f3i2, 1 ) ); f3i4 = Mpy_32_16_1( L_sub( f4i3, f4i2 ), FFT_15PONIT_WNK4 ); f3i5 = zIm[in9]; + move32(); f4i4 = zIm[in10]; + move32(); f4i5 = zIm[in8]; + move32(); f3i6 = L_add( f4i4, f4i5 ); f3i7 = Mpy_32_16_1( L_sub( f4i4, f4i5 ), FFT_15PONIT_WNK4 ); f3i8 = L_sub( f3i5, L_shr( f3i6, 1 ) ); f3i9 = zRe[in33]; + move32(); f4i6 = zRe[in34]; + move32(); f4i7 = zRe[in32]; + move32(); f3i10 = L_add( f4i6, f4i7 ); f3i11 = L_sub( f3i9, L_shr( f3i10, 1 ) ); f3i12 = Mpy_32_16_1( L_sub( f4i7, f4i6 ), FFT_15PONIT_WNK4 ); f3i13 = zIm[in33]; + move32(); f4i8 = zIm[in34]; + move32(); f4i9 = zIm[in32]; + move32(); f3i14 = L_add( f4i8, f4i9 ); f3i15 = Mpy_32_16_1( L_sub( f4i8, f4i9 ), FFT_15PONIT_WNK4 ); f4i1 = L_sub( f3i13, L_shr( f3i14, 1 ) ); @@ -272,29 +304,41 @@ static void fft15_shift2( fi24 = L_add( fi22, fi23 ); f4i10 = zRe[in24]; + move32(); fo6 = zRe[in25]; + move32(); fo7 = zRe[in26]; + move32(); f4i11 = L_add( fo6, fo7 ); f4i12 = L_sub( f4i10, L_shr( f4i11, 1 ) ); f4i13 = Mpy_32_16_1( L_sub( fo7, fo6 ), FFT_15PONIT_WNK4 ); f4i14 = zIm[in24]; + move32(); fo8 = zIm[in25]; + move32(); fo9 = zIm[in26]; + move32(); f4i15 = L_add( fo8, fo9 ); f4i16 = Mpy_32_16_1( L_sub( fo8, fo9 ), FFT_15PONIT_WNK4 ); f4i17 = L_sub( f4i14, L_shr( f4i15, 1 ) ); f4i18 = zRe[in18]; + move32(); f2o10 = zRe[in16]; + move32(); f2o11 = zRe[in17]; + move32(); f4i19 = L_add( f2o10, f2o11 ); f4i20 = L_sub( f4i18, L_shr( f4i19, 1 ) ); fo1 = Mpy_32_16_1( L_sub( f2o11, f2o10 ), FFT_15PONIT_WNK4 ); fo2 = zIm[in18]; + move32(); f2o12 = zIm[in16]; + move32(); f2o13 = zIm[in17]; + move32(); fo3 = L_add( f2o12, f2o13 ); fo4 = Mpy_32_16_1( L_sub( f2o12, f2o13 ), FFT_15PONIT_WNK4 ); fo5 = L_sub( fo2, L_shr( fo3, 1 ) ); @@ -327,12 +371,17 @@ static void fft15_shift2( fo14 = L_add( Mpy_32_16_1( fo15, FFT_15PONIT_WNK3 ), Mpy_32_16_1( fo16, FFT_15PONIT_WNK2 ) ); zRe[in0] = L_add( fi1, fo11 ); + move32(); fo17 = L_add( fo10, fo12 ); zRe[in18] = L_sub( fo17, fo14 ); + move32(); zRe[in24] = L_add( fo17, fo14 ); + move32(); fo18 = L_sub( fo12, fo10 ); zRe[in9] = L_sub( fo18, fo13 ); + move32(); zRe[in33] = L_add( fo18, fo13 ); + move32(); f2o1 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); f2o2 = L_add( f2i3, fi15 ); @@ -342,12 +391,17 @@ static void fft15_shift2( f2o4 = L_sub( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK3 ) ); f2o5 = L_add( Mpy_32_16_1( f2o6, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f2o7, FFT_15PONIT_WNK2 ) ); zIm[in0] = L_add( fi2, f2o2 ); + move32(); f2o8 = L_add( f2o1, f2o3 ); zIm[in24] = L_sub( f2o8, f2o5 ); + move32(); zIm[in18] = L_add( f2o5, f2o8 ); + move32(); f2o9 = L_sub( f2o3, f2o1 ); zIm[in33] = L_sub( f2o9, f2o4 ); + move32(); zIm[in9] = L_add( f2o4, f2o9 ); + move32(); f2o14 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); f2o15 = L_add( fi30, fi12 ); @@ -357,12 +411,17 @@ static void fft15_shift2( f3o2 = L_sub( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o5, FFT_15PONIT_WNK3 ) ); f3o3 = L_add( Mpy_32_16_1( f3o5, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); zRe[in2] = L_add( fi3, f2o15 ); + move32(); f3o6 = L_add( f2o14, f3o1 ); zRe[in17] = L_sub( f3o6, f3o3 ); + move32(); zRe[in26] = L_add( f3o6, f3o3 ); + move32(); f3o7 = L_sub( f3o1, f2o14 ); zRe[in8] = L_sub( f3o7, f3o2 ); + move32(); zRe[in32] = L_add( f3o7, f3o2 ); + move32(); f3o8 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); f3o9 = L_add( f2i6, fi18 ); @@ -372,12 +431,17 @@ static void fft15_shift2( f3o11 = L_sub( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o14, FFT_15PONIT_WNK3 ) ); f3o12 = L_add( Mpy_32_16_1( f3o14, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); zIm[in2] = L_add( fi6, f3o9 ); + move32(); f3o15 = L_add( f3o8, f3o10 ); zIm[in26] = L_sub( f3o15, f3o12 ); + move32(); zIm[in17] = L_add( f3o12, f3o15 ); + move32(); f4o1 = L_sub( f3o10, f3o8 ); zIm[in8] = L_add( f3o11, f4o1 ); + move32(); zIm[in32] = L_sub( f4o1, f3o11 ); + move32(); f4o2 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); f4o3 = L_add( f2i9, fi21 ); @@ -387,13 +451,18 @@ static void fft15_shift2( f4o5 = L_add( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK3 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ) ); f4o6 = L_sub( Mpy_32_16_1( f4o8, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); zIm[in1] = L_add( fi5, f4o3 ); + move32(); f4o9 = L_sub( f4o4, f4o2 ); f4o10 = L_add( f4o2, f4o4 ); zIm[in10] = L_add( f4o6, f4o9 ); + move32(); zIm[in34] = L_sub( f4o9, f4o6 ); + move32(); zIm[in25] = L_sub( f4o10, f4o5 ); + move32(); zIm[in16] = L_add( f4o5, f4o10 ); + move32(); f4o11 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); f4o12 = L_add( f2i12, fi24 ); @@ -403,13 +472,18 @@ static void fft15_shift2( f4o14 = L_add( Mpy_32_16_1( f4o16, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o17, FFT_15PONIT_WNK3 ) ); f4o15 = L_sub( Mpy_32_16_1( f4o17, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o16, FFT_15PONIT_WNK3 ) ); zRe[in1] = L_add( fi4, f4o12 ); + move32(); f4o18 = L_sub( f4o13, f4o11 ); f4o19 = L_add( f4o11, f4o13 ); zRe[in10] = L_sub( f4o18, f4o15 ); + move32(); zRe[in34] = L_add( f4o18, f4o15 ); + move32(); zRe[in16] = L_sub( f4o19, f4o14 ); + move32(); zRe[in25] = L_add( f4o19, f4o14 ); + move32(); return; } @@ -441,20 +515,35 @@ static void fft15_shift8( Word32 f5o8, f5o9, f5o10, f5o11, f5o12, f5o13, f5o14, f5o15, f5o16, f5o17, f5o18, f5o19, f5o21, f5o22; in0 = Idx[0]; + move16(); in8 = Idx[n1]; + move16(); in16 = Idx[n1 * 2]; - in24 = Idx[n1 * 3]; + move16(); + in24 = Idx[i_mult( n1, 3 )]; + move16(); in32 = Idx[n1 * 4]; - in1 = Idx[n1 * 5]; + move16(); + in1 = Idx[i_mult( n1, 5 )]; + move16(); in9 = Idx[n1 * 6]; - in17 = Idx[n1 * 7]; + move16(); + in17 = Idx[i_mult( n1, 7 )]; + move16(); in25 = Idx[n1 * 8]; - in33 = Idx[n1 * 9]; + move16(); + in33 = Idx[i_mult( n1, 9 )]; + move16(); in2 = Idx[n1 * 10]; - in10 = Idx[n1 * 11]; + move16(); + in10 = Idx[i_mult( n1, 11 )]; + move16(); in18 = Idx[n1 * 12]; - in26 = Idx[n1 * 13]; + move16(); + in26 = Idx[i_mult( n1, 13 )]; + move16(); in34 = Idx[n1 * 14]; + move16(); f2i13 = zRe[in0]; f2i14 = zIm[in0]; @@ -478,17 +567,29 @@ static void fft15_shift8( fi6 = L_sub( f3i5, f3i1 ); f3i10 = zRe[in9]; + move32(); f4i11 = zRe[in10]; + move32(); f4i12 = zRe[in8]; + move32(); f3i14 = zIm[in9]; + move32(); f4i13 = zIm[in10]; + move32(); f4i14 = zIm[in8]; + move32(); f4i3 = zRe[in33]; + move32(); f4i15 = zRe[in34]; + move32(); fo1 = zRe[in32]; + move32(); f4i7 = zIm[in33]; + move32(); fo2 = zIm[in34]; + move32(); fo3 = zIm[in32]; + move32(); f3i11 = L_add( f4i11, f4i12 ); @@ -524,17 +625,29 @@ static void fft15_shift8( fi24 = L_add( fi22, fi23 ); fo4 = zRe[in24]; + move32(); f2o5 = zRe[in25]; + move32(); f2o6 = zRe[in26]; + move32(); fo8 = zIm[in24]; + move32(); f2o7 = zIm[in25]; + move32(); f2o8 = zIm[in26]; + move32(); fo12 = zRe[in18]; + move32(); f2o9 = zRe[in16]; + move32(); f2o10 = zRe[in17]; + move32(); f2o1 = zIm[in18]; + move32(); f2o11 = zIm[in16]; + move32(); f2o12 = zIm[in17]; + move32(); fo5 = L_add( f2o5, f2o6 ); @@ -577,12 +690,17 @@ static void fft15_shift8( f3o1 = L_sub( Mpy_32_16_1( f3o3, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o4, FFT_15PONIT_WNK3 ) ); f3o2 = L_add( Mpy_32_16_1( f3o4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o3, FFT_15PONIT_WNK3 ) ); zRe[in0] = L_add( fi1, f2o14 ); + move32(); f3o5 = L_add( f2o13, f2o15 ); zRe[in24] = L_sub( f3o5, f3o2 ); + move32(); zRe[in18] = L_add( f3o5, f3o2 ); + move32(); f3o6 = L_sub( f2o15, f2o13 ); zRe[in33] = L_sub( f3o6, f3o1 ); + move32(); zRe[in9] = L_add( f3o6, f3o1 ); + move32(); f3o7 = Mpy_32_16_1( L_sub( f2i3, fi15 ), FFT_15PONIT_WNK1 ); f3o8 = L_add( f2i3, fi15 ); @@ -592,12 +710,17 @@ static void fft15_shift8( f3o10 = L_sub( Mpy_32_16_1( f3o12, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o13, FFT_15PONIT_WNK3 ) ); f3o11 = L_add( Mpy_32_16_1( f3o13, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f3o12, FFT_15PONIT_WNK3 ) ); zIm[in0] = L_add( fi2, f3o8 ); + move32(); f3o14 = L_add( f3o7, f3o9 ); zIm[in18] = L_sub( f3o14, f3o11 ); + move32(); zIm[in24] = L_add( f3o11, f3o14 ); + move32(); f3o15 = L_sub( f3o9, f3o7 ); zIm[in9] = L_sub( f3o15, f3o10 ); + move32(); zIm[in33] = L_add( f3o10, f3o15 ); + move32(); f4o1 = Mpy_32_16_1( L_sub( fi30, fi12 ), FFT_15PONIT_WNK1 ); f4o2 = L_add( fi30, fi12 ); @@ -607,12 +730,17 @@ static void fft15_shift8( f4o4 = L_sub( Mpy_32_16_1( f4o6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o7, FFT_15PONIT_WNK3 ) ); f4o5 = L_add( Mpy_32_16_1( f4o7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o6, FFT_15PONIT_WNK3 ) ); zRe[in2] = L_add( fi3, f4o2 ); + move32(); f4o8 = L_add( f4o1, f4o3 ); zRe[in26] = L_sub( f4o8, f4o5 ); + move32(); zRe[in17] = L_add( f4o8, f4o5 ); + move32(); f4o9 = L_sub( f4o3, f4o1 ); zRe[in32] = L_sub( f4o9, f4o4 ); + move32(); zRe[in8] = L_add( f4o9, f4o4 ); + move32(); f4o10 = Mpy_32_16_1( L_sub( f2i6, fi18 ), FFT_15PONIT_WNK1 ); f4o11 = L_add( f2i6, fi18 ); @@ -622,12 +750,17 @@ static void fft15_shift8( f4o13 = L_sub( Mpy_32_16_1( f4o15, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o1, FFT_15PONIT_WNK3 ) ); f4o14 = L_add( Mpy_32_16_1( f5o1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f4o15, FFT_15PONIT_WNK3 ) ); zIm[in2] = L_add( fi6, f4o11 ); + move32(); f5o2 = L_add( f4o10, f4o12 ); zIm[in17] = L_sub( f5o2, f4o14 ); + move32(); zIm[in26] = L_add( f4o14, f5o2 ); + move32(); f5o3 = L_sub( f4o12, f4o10 ); zIm[in32] = L_add( f4o13, f5o3 ); + move32(); zIm[in8] = L_sub( f5o3, f4o13 ); + move32(); f5o4 = Mpy_32_16_1( L_sub( f2i9, fi21 ), FFT_15PONIT_WNK1 ); f5o5 = L_add( f2i9, fi21 ); @@ -637,13 +770,18 @@ static void fft15_shift8( f5o7 = L_add( Mpy_32_16_1( f5o9, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o10, FFT_15PONIT_WNK3 ) ); f5o8 = L_sub( Mpy_32_16_1( f5o10, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o9, FFT_15PONIT_WNK3 ) ); zIm[in1] = L_add( fi5, f5o5 ); + move32(); f5o11 = L_sub( f5o6, f5o4 ); f5o12 = L_add( f5o4, f5o6 ); zIm[in34] = L_add( f5o8, f5o11 ); + move32(); zIm[in10] = L_sub( f5o11, f5o8 ); + move32(); zIm[in16] = L_sub( f5o12, f5o7 ); + move32(); zIm[in25] = L_add( f5o7, f5o12 ); + move32(); f5o13 = Mpy_32_16_1( L_sub( f2i12, fi24 ), FFT_15PONIT_WNK1 ); f5o14 = L_add( f2i12, fi24 ); @@ -653,13 +791,18 @@ static void fft15_shift8( f5o16 = L_add( Mpy_32_16_1( f5o18, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o19, FFT_15PONIT_WNK3 ) ); f5o17 = L_sub( Mpy_32_16_1( f5o19, FFT_15PONIT_WNK2 ), Mpy_32_16_1( f5o18, FFT_15PONIT_WNK3 ) ); zRe[in1] = L_add( fi4, f5o14 ); + move32(); f5o21 = L_sub( f5o15, f5o13 ); f5o22 = L_add( f5o13, f5o15 ); zRe[in34] = L_sub( f5o21, f5o17 ); + move32(); zRe[in10] = L_add( f5o21, f5o17 ); + move32(); zRe[in25] = L_sub( f5o22, f5o16 ); + move32(); zRe[in16] = L_add( f5o22, f5o16 ); + move32(); return; } @@ -681,17 +824,28 @@ static void fft5_shift1( Word16 in1, in2, in3, in4, in5; in1 = Idx[0]; + move16(); in2 = Idx[n1]; + move16(); in3 = Idx[n1 * 2]; - in4 = Idx[n1 * 3]; + move16(); + in4 = Idx[i_mult( n1, 3 )]; + move16(); in5 = Idx[n1 * 4]; + move16(); fi1 = zRe[in1]; + move32(); fi2 = zIm[in1]; + move32(); fo3 = zRe[in2]; + move32(); fo4 = zRe[in5]; + move32(); fo6 = zRe[in3]; + move32(); fo7 = zRe[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -701,9 +855,13 @@ static void fft5_shift1( fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; + move32(); fo4 = zIm[in5]; + move32(); fo6 = zIm[in3]; + move32(); fo7 = zIm[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -713,7 +871,9 @@ static void fft5_shift1( fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); zRe[in1] = L_add( fi1, fi3 ); + move32(); zIm[in1] = L_add( fi2, fi8 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); @@ -722,9 +882,13 @@ static void fft5_shift1( fo6 = L_sub( fo7, fi5 ); zRe[in2] = L_add( fo5, fo3 ); + move32(); zRe[in3] = L_sub( fo6, fo4 ); + move32(); zRe[in4] = L_add( fo6, fo4 ); + move32(); zRe[in5] = L_sub( fo5, fo3 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); @@ -733,9 +897,13 @@ static void fft5_shift1( fo6 = L_sub( fo7, fo2 ); zIm[in2] = L_sub( fo5, fo3 ); + move32(); zIm[in3] = L_add( fo4, fo6 ); + move32(); zIm[in4] = L_sub( fo6, fo4 ); + move32(); zIm[in5] = L_add( fo3, fo5 ); + move32(); return; } @@ -757,17 +925,28 @@ static void fft5_shift4( Word16 in1, in2, in3, in4, in5; in1 = Idx[0]; + move16(); in2 = Idx[n1]; + move16(); in3 = Idx[n1 * 2]; - in4 = Idx[n1 * 3]; + move16(); + in4 = Idx[i_mult( n1, 3 )]; + move16(); in5 = Idx[n1 * 4]; + move16(); fi1 = zRe[in1]; + move32(); fi2 = zIm[in1]; + move32(); fo3 = zRe[in2]; + move32(); fo4 = zRe[in5]; + move32(); fo6 = zRe[in3]; + move32(); fo7 = zRe[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -777,9 +956,13 @@ static void fft5_shift4( fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; + move32(); fo4 = zIm[in5]; + move32(); fo6 = zIm[in3]; + move32(); fo7 = zIm[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -789,7 +972,9 @@ static void fft5_shift4( fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); zRe[in1] = L_add( fi1, fi3 ); + move32(); zIm[in1] = L_add( fi2, fi8 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); @@ -798,9 +983,13 @@ static void fft5_shift4( fo6 = L_sub( fo7, fi5 ); zRe[in2] = L_sub( fo5, fo3 ); + move32(); zRe[in4] = L_sub( fo6, fo4 ); + move32(); zRe[in3] = L_add( fo6, fo4 ); + move32(); zRe[in5] = L_add( fo5, fo3 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); @@ -809,9 +998,13 @@ static void fft5_shift4( fo6 = L_sub( fo7, fo2 ); zIm[in3] = L_sub( fo6, fo4 ); + move32(); zIm[in2] = L_add( fo3, fo5 ); + move32(); zIm[in4] = L_add( fo4, fo6 ); + move32(); zIm[in5] = L_sub( fo5, fo3 ); + move32(); return; } @@ -832,17 +1025,28 @@ static void fft5_32( Word16 in1, in2, in3, in4, in5; in1 = Idx[0]; + move16(); in2 = Idx[32]; + move16(); in3 = Idx[64]; + move16(); in4 = Idx[96]; + move16(); in5 = Idx[128]; + move16(); fi1 = zRe[in1]; + move32(); fi2 = zIm[in1]; + move32(); fo3 = zRe[in2]; + move32(); fo4 = zRe[in5]; + move32(); fo6 = zRe[in3]; + move32(); fo7 = zRe[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -852,9 +1056,13 @@ static void fft5_32( fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; + move32(); fo4 = zIm[in5]; + move32(); fo6 = zIm[in3]; + move32(); fo7 = zIm[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -864,7 +1072,9 @@ static void fft5_32( fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); zRe[in1] = L_add( fi1, fi3 ); + move32(); zIm[in1] = L_add( fi2, fi8 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); @@ -873,9 +1083,13 @@ static void fft5_32( fo6 = L_sub( fo7, fi5 ); zRe[in2] = L_add( fo6, fo4 ); + move32(); zRe[in3] = L_add( fo5, fo3 ); + move32(); zRe[in4] = L_sub( fo5, fo3 ); + move32(); zRe[in5] = L_sub( fo6, fo4 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); @@ -884,9 +1098,13 @@ static void fft5_32( fo6 = L_sub( fo7, fo2 ); zIm[in2] = L_sub( fo6, fo4 ); + move32(); zIm[in3] = L_sub( fo5, fo3 ); + move32(); zIm[in4] = L_add( fo3, fo5 ); + move32(); zIm[in5] = L_add( fo4, fo6 ); + move32(); return; } @@ -907,8 +1125,11 @@ static void fft64( FOR( i = 0; i < 64; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 128, z, Ip_fft64, w_fft64_fx ); @@ -916,9 +1137,13 @@ static void fft64( FOR( i = 0; i < 64; i++ ) { jd = Odx_fft64[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -942,8 +1167,11 @@ static void fft32_15( FOR( i = 0; i < 32; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 64, z, Ip_fft32, w_fft32_fx ); @@ -951,9 +1179,13 @@ static void fft32_15( FOR( i = 0; i < 32; i++ ) { jd = Odx_fft32_15[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -976,8 +1208,11 @@ static void fft32_5( FOR( i = 0; i < 32; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 64, z, Ip_fft32, w_fft32_fx ); @@ -985,9 +1220,13 @@ static void fft32_5( FOR( i = 0; i < 32; i++ ) { jd = Odx_fft32_5[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -1010,8 +1249,11 @@ static void fft16_ivas( FOR( i = 0; i < 16; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 32, z, Ip_fft16, w_fft16_fx ); @@ -1019,9 +1261,13 @@ static void fft16_ivas( FOR( i = 0; i < 16; i++ ) { jd = Odx_fft16[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -1044,8 +1290,11 @@ static void fft8( FOR( i = 0; i < 8; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 16, z, Ip_fft8, w_fft8_fx ); @@ -1053,8 +1302,11 @@ static void fft8( FOR( i = 0; i < 8; i++ ) { id = Idx[i]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -1077,8 +1329,11 @@ static void fft8_5( FOR( i = 0; i < 8; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 16, z, Ip_fft8, w_fft8_fx ); @@ -1086,9 +1341,13 @@ static void fft8_5( FOR( i = 0; i < 8; i++ ) { jd = Odx_fft8_5[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; } @@ -1110,17 +1369,28 @@ static void fft5_8( Word16 in1, in2, in3, in4, in5; in1 = Idx[0]; + move16(); in2 = Idx[n1]; + move16(); in3 = Idx[n1 * 2]; - in4 = Idx[n1 * 3]; + move16(); + in4 = Idx[i_mult( n1, 3 )]; + move16(); in5 = Idx[n1 * 4]; + move16(); fi1 = zRe[in1]; + move32(); fi2 = zIm[in1]; + move32(); fo3 = zRe[in2]; + move32(); fo4 = zRe[in5]; + move32(); fo6 = zRe[in3]; + move32(); fo7 = zRe[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -1130,9 +1400,13 @@ static void fft5_8( fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; + move32(); fo4 = zIm[in5]; + move32(); fo6 = zIm[in3]; + move32(); fo7 = zIm[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -1142,7 +1416,9 @@ static void fft5_8( fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); zRe[in1] = L_add( fi1, fi3 ); + move32(); zIm[in1] = L_add( fi2, fi8 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); @@ -1151,9 +1427,13 @@ static void fft5_8( fo6 = L_sub( fo7, fi5 ); zRe[in2] = L_sub( fo6, fo4 ); + move32(); zRe[in3] = L_sub( fo5, fo3 ); + move32(); zRe[in5] = L_add( fo6, fo4 ); + move32(); zRe[in4] = L_add( fo5, fo3 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); @@ -1162,9 +1442,13 @@ static void fft5_8( fo6 = L_sub( fo7, fo2 ); zIm[in2] = L_add( fo4, fo6 ); + move32(); zIm[in3] = L_add( fo3, fo5 ); + move32(); zIm[in4] = L_sub( fo5, fo3 ); + move32(); zIm[in5] = L_sub( fo6, fo4 ); + move32(); return; } @@ -1186,8 +1470,11 @@ static void fft4_5( FOR( i = 0; i < 4; i++ ) { id = Idx[i]; + move16(); z[2 * i] = x[id]; - z[2 * i + 1] = y[id]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[id]; + move32(); } cdftForw( 8, z, Ip_fft4, w_fft4_fx ); @@ -1195,9 +1482,13 @@ static void fft4_5( FOR( i = 0; i < 4; i++ ) { jd = Odx_fft4_5[i]; + move16(); id = Idx[jd]; + move16(); x[id] = z[2 * i]; - y[id] = z[2 * i + 1]; + move32(); + y[id] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; } @@ -1218,17 +1509,28 @@ static void fft5_4( Word16 in1, in2, in3, in4, in5; in1 = Idx[0]; + move16(); in2 = Idx[n1]; + move16(); in3 = Idx[n1 * 2]; - in4 = Idx[n1 * 3]; + move16(); + in4 = Idx[i_mult( n1, 3 )]; + move16(); in5 = Idx[n1 * 4]; + move16(); fi1 = zRe[in1]; + move32(); fi2 = zIm[in1]; + move32(); fo3 = zRe[in2]; + move32(); fo4 = zRe[in5]; + move32(); fo6 = zRe[in3]; + move32(); fo7 = zRe[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -1238,9 +1540,13 @@ static void fft5_4( fi6 = L_sub( fo3, fo4 ); fo3 = zIm[in2]; + move32(); fo4 = zIm[in5]; + move32(); fo6 = zIm[in3]; + move32(); fo7 = zIm[in4]; + move32(); fo5 = L_add( fo3, fo4 ); fo8 = L_add( fo6, fo7 ); @@ -1250,7 +1556,9 @@ static void fft5_4( fo2 = Mpy_32_16_1( L_sub( fo5, fo8 ), FFT_15PONIT_WNK1 ); zRe[in1] = L_add( fi1, fi3 ); + move32(); zIm[in1] = L_add( fi2, fi8 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi7, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fo1, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fo1, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi7, FFT_15PONIT_WNK3 ) ); @@ -1259,9 +1567,13 @@ static void fft5_4( fo6 = L_sub( fo7, fi5 ); zRe[in2] = L_sub( fo5, fo3 ); + move32(); zRe[in4] = L_sub( fo6, fo4 ); + move32(); zRe[in3] = L_add( fo6, fo4 ); + move32(); zRe[in5] = L_add( fo5, fo3 ); + move32(); fo3 = L_add( Mpy_32_16_1( fi6, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi4, FFT_15PONIT_WNK3 ) ); fo4 = L_sub( Mpy_32_16_1( fi4, FFT_15PONIT_WNK2 ), Mpy_32_16_1( fi6, FFT_15PONIT_WNK3 ) ); @@ -1270,9 +1582,13 @@ static void fft5_4( fo6 = L_sub( fo7, fo2 ); zIm[in2] = L_add( fo3, fo5 ); + move32(); zIm[in3] = L_sub( fo6, fo4 ); + move32(); zIm[in4] = L_add( fo4, fo6 ); + move32(); zIm[in5] = L_sub( fo5, fo3 ); + move32(); return; } @@ -1292,7 +1608,7 @@ void DoRTFT80_fx( /* Applying 16-point FFT for 5 times based on the address table Idx_dortft80 */ FOR( j = 0; j < 5; j++ ) { - fft16_ivas( x, y, Idx_dortft80 + 16 * j ); + fft16_ivas( x, y, Idx_dortft80 + shl( j, 4 ) ); } /* Applying 5-point FFT for 16 times based on the address table Idx_dortft80 */ @@ -1319,7 +1635,7 @@ void DoRTFT120_fx( /* Applying 8-point FFT for 15 times based on the address table Idx_dortft120 */ FOR( j = 0; j < 15; j++ ) { - fft8( x, y, Idx_dortft120 + 8 * j ); + fft8( x, y, Idx_dortft120 + shl( j, 3 ) ); } /* Applying 15-point FFT for 8 times based on the address table Idx_dortft120 */ @@ -1346,7 +1662,7 @@ void DoRTFT160_fx( /* Applying 32-point FFT for 5 times based on the address table Idx_dortft160 */ FOR( j = 0; j < 5; j++ ) { - fft32_5( x, y, Idx_dortft160 + 32 * j ); + fft32_5( x, y, Idx_dortft160 + shl( j, 5 ) ); } /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ @@ -1373,7 +1689,7 @@ void DoRTFT320_fx( /* Applying 64-point FFT for 5 times based on the address table Idx_dortft160 */ FOR( j = 0; j < 5; j++ ) { - fft64( x, y, Idx_dortft320 + 64 * j ); + fft64( x, y, Idx_dortft320 + shl( j, 6 ) ); } /* Applying 5-point FFT for 64 times based on the address table Idx_dortft160 */ @@ -1400,7 +1716,7 @@ void DoRTFT480_fx( /* Applying 32-point FFT for 15 times based on the address table Idx_dortft160 */ FOR( j = 0; j < 15; j++ ) { - fft32_15( x, y, Idx_dortft480 + 32 * j ); + fft32_15( x, y, Idx_dortft480 + shl( j, 5 ) ); } /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ @@ -1426,7 +1742,7 @@ void DoRTFT40_fx( /* Applying 8-point FFT for 5 times based on the address table Idx_dortft40 */ FOR( j = 0; j < 5; j++ ) { - fft8_5( x, y, Idx_dortft40 + 8 * j ); + fft8_5( x, y, Idx_dortft40 + shl( j, 3 ) ); } /* Applying 5-point FFT for 8 times based on the address table Idx_dortft40 */ @@ -1453,7 +1769,7 @@ void DoRTFT20_fx( /* Applying 4-point FFT for 5 times based on the address table Idx_dortft20 */ FOR( j = 0; j < 5; j++ ) { - fft4_5( x, y, Idx_dortft20 + 4 * j ); + fft4_5( x, y, Idx_dortft20 + shl( j, 2 ) ); } /* Applying 5-point FFT for 4 times based on the address table Idx_dortft20 */ @@ -1482,17 +1798,23 @@ void DoRTFT128_fx( FOR( i = 0; i < 128; i++ ) { z[2 * i] = x[i]; - z[2 * i + 1] = y[i]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[i]; + move32(); } cdftForw( 256, z, Ip_fft128, w_fft128_fx ); x[0] = z[0]; + move32(); y[0] = z[1]; + move32(); FOR( i = 1; i < 128; i++ ) { x[128 - i] = z[2 * i]; - y[128 - i] = z[2 * i + 1]; + move32(); + y[128 - i] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -1535,22 +1857,30 @@ static void bitrv2_SR( IF( EQ_16( n, 64 ) ) { m = 4; + move16(); l = -1; + move16(); } ELSE IF( EQ_16( n, 256 ) ) { m = 8; + move16(); l = -1; + move16(); } ELSE IF( EQ_16( n, 16 ) ) { m = 2; + move16(); l = -1; + move16(); } ELSE { l = n; + move16(); m = 1; + move16(); WHILE( shl( m, 3 ) < l ) { @@ -1562,7 +1892,7 @@ static void bitrv2_SR( m2 = shl( m, 1 ); - IF( EQ_16( l, 0 ) ) + IF( l == 0 ) { FOR( k = 0; k < m; k++ ) { @@ -1571,55 +1901,95 @@ static void bitrv2_SR( j1 = add( shl( j, 1 ), ip[k] ); k1 = add( shl( k, 1 ), ip[j] ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; - j1 += m2; - k1 += 2 * m2; + move32(); + j1 = add( j1, m2 ); + k1 = add( k1, 2 * m2 ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); j1 = add( j1, m2 ); k1 = sub( k1, m2 ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); j1 = add( j1, m2 ); k1 = add( k1, shl( m2, 1 ) ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); } j1 = add( shl( k, 1 ), add( m2, ip[k] ) ); k1 = add( j1, m2 ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); } } ELSE @@ -1631,23 +2001,39 @@ static void bitrv2_SR( j1 = add( shl( j, 1 ), ip[k] ); k1 = add( shl( k, 1 ), ip[j] ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); j1 = add( j1, m2 ); k1 = add( k1, m2 ); xr = a[j1]; + move32(); xi = a[j1 + 1]; + move32(); yr = a[k1]; + move32(); yi = a[k1 + 1]; + move32(); a[j1] = yr; + move32(); a[j1 + 1] = yi; + move32(); a[k1] = xr; + move32(); a[k1 + 1] = xi; + move32(); } } } @@ -1670,12 +2056,14 @@ static void cftfsub( Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; + move16(); IF( GT_16( n, 8 ) ) { cft1st( n, a, w ); l = 8; + move16(); WHILE( LT_16( shl( l, 2 ), n ) ) { @@ -1700,13 +2088,21 @@ static void cftfsub( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); a[j2] = L_sub( x0r, x2r ); + move32(); a[j2 + 1] = L_sub( x0i, x2i ); + move32(); a[j1] = L_sub( x1r, x3i ); + move32(); a[j1 + 1] = L_add( x1i, x3r ); + move32(); a[j3] = L_add( x1r, x3i ); + move32(); a[j3 + 1] = L_sub( x1i, x3r ); + move32(); } } ELSE @@ -1717,9 +2113,13 @@ static void cftfsub( x0r = L_sub( a[j], a[j1] ); x0i = L_sub( a[j + 1], a[j1 + 1] ); a[j] = L_add( a[j], a[j1] ); + move32(); a[j + 1] = L_add( a[j + 1], a[j1 + 1] ); + move32(); a[j1] = x0r; + move32(); a[j1 + 1] = x0i; + move32(); } } @@ -1750,13 +2150,21 @@ static void cft1st( x3r = L_sub( a[4], a[6] ); x3i = L_sub( a[5], a[7] ); a[0] = L_add( x0r, x2r ); + move32(); a[1] = L_add( x0i, x2i ); + move32(); a[4] = L_sub( x0r, x2r ); + move32(); a[5] = L_sub( x0i, x2i ); + move32(); a[2] = L_sub( x1r, x3i ); + move32(); a[3] = L_add( x1i, x3r ); + move32(); a[6] = L_add( x1r, x3i ); + move32(); a[7] = L_sub( x1i, x3r ); + move32(); wk1r = w[2]; x0r = L_add( a[8], a[10] ); x0i = L_add( a[9], a[11] ); @@ -1767,27 +2175,40 @@ static void cft1st( x3r = L_sub( a[12], a[14] ); x3i = L_sub( a[13], a[15] ); a[8] = L_add( x0r, x2r ); + move32(); a[9] = L_add( x0i, x2i ); + move32(); a[12] = L_sub( x2i, x0i ); + move32(); a[13] = L_sub( x0r, x2r ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[10] = Mpy_32_16_1( L_sub( x0r, x0i ), wk1r ); + move32(); a[11] = Mpy_32_16_1( L_add( x0r, x0i ), wk1r ); + move32(); x0r = L_add( x3i, x1r ); x0i = L_sub( x3r, x1i ); a[14] = Mpy_32_16_1( L_sub( x0i, x0r ), wk1r ); + move32(); a[15] = Mpy_32_16_1( L_add( x0i, x0r ), wk1r ); + move32(); k1 = 0; + move16(); FOR( j = 16; j < n; j += 16 ) { k1 = add( k1, 2 ); k2 = shl( k1, 1 ); wk2r = w[k1]; + move16(); wk2i = w[k1 + 1]; + move16(); wk1r = w[k2]; + move16(); wk1i = w[k2 + 1]; + move16(); wtmp = mult_r( wk2i, wk1i ); wk3r = sub( wk1r, wtmp ); wk3r = sub( wk3r, wtmp ); @@ -1803,21 +2224,31 @@ static void cft1st( x3r = L_sub( a[j + 4], a[j + 6] ); x3i = L_sub( a[j + 5], a[j + 7] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); a[j + 4] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + move32(); a[j + 5] = L_add( Mpy_32_16_1( x0i, wk2r ), Mpy_32_16_1( x0r, wk2i ) ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[j + 2] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + move32(); a[j + 3] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); + move32(); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); a[j + 6] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + move32(); a[j + 7] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + move32(); wk1r = w[k2 + 2]; + move16(); wk1i = w[k2 + 3]; + move16(); wtmp = mult_r( wk2r, wk1i ); wk3r = sub( wk1r, wtmp ); wk3r = sub( wk3r, wtmp ); @@ -1833,19 +2264,26 @@ static void cft1st( x3r = L_sub( a[j + 12], a[j + 14] ); x3i = L_sub( a[j + 13], a[j + 15] ); a[j + 8] = L_add( x0r, x2r ); + move32(); a[j + 9] = L_add( x0i, x2i ); + move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); a[j + 12] = L_negate( L_add( Mpy_32_16_1( x0r, wk2i ), Mpy_32_16_1( x0i, wk2r ) ) ); + move32(); a[j + 13] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[j + 10] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + move32(); a[j + 11] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); a[j + 14] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + move32(); a[j + 15] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + move32(); } return; @@ -1882,16 +2320,25 @@ static void cftmdl( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); a[j2] = L_sub( x0r, x2r ); + move32(); a[j2 + 1] = L_sub( x0i, x2i ); + move32(); a[j1] = L_sub( x1r, x3i ); + move32(); a[j1 + 1] = L_add( x1i, x3r ); + move32(); a[j3] = L_add( x1r, x3i ); + move32(); a[j3 + 1] = L_sub( x1i, x3r ); + move32(); } wk1r = w[2]; + move16(); FOR( j = m; j < l + m; j += 2 ) { j1 = add( j, l ); @@ -1906,29 +2353,42 @@ static void cftmdl( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); a[j2] = L_sub( x2i, x0i ); + move32(); a[j2 + 1] = L_sub( x0r, x2r ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[j1] = Mpy_32_16_1( L_sub( x0r, x0i ), wk1r ); + move32(); a[j1 + 1] = Mpy_32_16_1( L_add( x0r, x0i ), wk1r ); + move32(); x0r = L_add( x3i, x1r ); x0i = L_sub( x3r, x1i ); a[j3] = Mpy_32_16_1( L_sub( x0i, x0r ), wk1r ); + move32(); a[j3 + 1] = Mpy_32_16_1( L_add( x0i, x0r ), wk1r ); + move32(); } k1 = 0; + move16(); m2 = shl( m, 1 ); FOR( k = m2; k < n; k += m2 ) { k1 = add( k1, 2 ); k2 = shl( k1, 1 ); wk2r = w[k1]; + move16(); wk2i = w[k1 + 1]; + move16(); wk1r = w[k2]; + move16(); wk1i = w[k2 + 1]; + move16(); wtmp = mult_r( wk2i, wk1i ); wk3r = sub( wk1r, wtmp ); wk3r = sub( wk3r, wtmp ); @@ -1949,23 +2409,33 @@ static void cftmdl( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); a[j2] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + move32(); a[j2 + 1] = L_add( Mpy_32_16_1( x0i, wk2r ), Mpy_32_16_1( x0r, wk2i ) ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + move32(); a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); + move32(); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + move32(); a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + move32(); } wk1r = w[k2 + 2]; + move16(); wk1i = w[k2 + 3]; + move16(); wtmp = mult_r( wk2r, wk1i ); wk3r = sub( wk1r, wtmp ); wk3r = sub( wk3r, wtmp ); @@ -1986,19 +2456,27 @@ static void cftmdl( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_add( x0i, x2i ); + move32(); x0r = L_sub( x0r, x2r ); x0i = L_sub( x0i, x2i ); a[j2] = L_negate( L_add( Mpy_32_16_1( x0r, wk2i ), Mpy_32_16_1( x0i, wk2r ) ) ); + move32(); a[j2 + 1] = L_sub( Mpy_32_16_1( x0r, wk2r ), Mpy_32_16_1( x0i, wk2i ) ); + move32(); x0r = L_sub( x1r, x3i ); x0i = L_add( x1i, x3r ); a[j1] = L_sub( Mpy_32_16_1( x0r, wk1r ), Mpy_32_16_1( x0i, wk1i ) ); + move32(); a[j1 + 1] = L_add( Mpy_32_16_1( x0i, wk1r ), Mpy_32_16_1( x0r, wk1i ) ); + move32(); x0r = L_add( x1r, x3i ); x0i = L_sub( x1i, x3r ); a[j3] = L_sub( Mpy_32_16_1( x0r, wk3r ), Mpy_32_16_1( x0i, wk3i ) ); + move32(); a[j3 + 1] = L_add( Mpy_32_16_1( x0i, wk3r ), Mpy_32_16_1( x0r, wk3i ) ); + move32(); } } @@ -2015,10 +2493,12 @@ static void cftbsub( Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; + move16(); IF( GT_16( n, 8 ) ) { cft1st( n, a, w ); l = 8; + move16(); WHILE( LT_16( shl( l, 2 ), n ) ) { @@ -2043,13 +2523,21 @@ static void cftbsub( x3r = L_sub( a[j2], a[j3] ); x3i = L_sub( a[j2 + 1], a[j3 + 1] ); a[j] = L_add( x0r, x2r ); + move32(); a[j + 1] = L_sub( x0i, x2i ); + move32(); a[j2] = L_sub( x0r, x2r ); + move32(); a[j2 + 1] = L_add( x0i, x2i ); + move32(); a[j1] = L_sub( x1r, x3i ); + move32(); a[j1 + 1] = L_sub( x1i, x3r ); + move32(); a[j3] = L_add( x1r, x3i ); + move32(); a[j3 + 1] = L_add( x1i, x3r ); + move32(); } } ELSE @@ -2060,9 +2548,13 @@ static void cftbsub( x0r = L_sub( a[j], a[j1] ); x0i = L_sub( a[j1 + 1], a[j + 1] ); a[j] = L_add( a[j], a[j1] ); + move32(); a[j + 1] = L_negate( L_add( a[j + 1], a[j1 + 1] ) ); + move32(); a[j1] = x0r; + move32(); a[j1 + 1] = x0i; + move32(); } } @@ -2080,22 +2572,28 @@ static void rftfsub( Word32 xr, xi, yr, yi; m = shr( n, 1 ); - ks = 2 * nc / m; + ks = idiv1616( shl( nc, 1 ), m ); kk = 0; + move16(); FOR( j = 2; j < m; j += 2 ) { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( (Word16) 0x4000, c[nc - kk] ); + wkr = sub( (Word16) 0x4000, c[sub( nc, kk )] ); wki = c[kk]; + move16(); xr = L_sub( a[j], a[k] ); xi = L_add( a[j + 1], a[k + 1] ); yr = L_sub( Mpy_32_16_1( xr, wkr ), Mpy_32_16_1( xi, wki ) ); yi = L_add( Mpy_32_16_1( xi, wkr ), Mpy_32_16_1( xr, wki ) ); a[j] = L_sub( a[j], yr ); + move32(); a[j + 1] = L_sub( a[j + 1], yi ); + move32(); a[k] = L_add( a[k], yr ); + move32(); a[k + 1] = L_sub( a[k + 1], yi ); + move32(); } return; @@ -2112,23 +2610,29 @@ static void rftbsub( Word16 wkr, wki; Word32 xr, xi, yr, yi; a[1] = L_negate( a[1] ); + move32(); m = shr( n, 1 ); - ks = 2 * nc / m; + ks = idiv1616( shl( nc, 1 ), m ); kk = 0; + move16(); FOR( j = 2; j < m; j += 2 ) { - k = n - j; - kk += ks; - wkr = sub( (Word16) 0x4000, c[nc - kk] ); + k = sub( n, j ); + kk = add( kk, ks ); + wkr = sub( (Word16) 0x4000, c[sub( nc, kk )] ); wki = c[kk]; xr = L_sub( a[j], a[k] ); xi = L_add( a[j + 1], a[k + 1] ); yr = L_add( Mpy_32_16_1( xr, wkr ), Mpy_32_16_1( xi, wki ) ); yi = L_sub( Mpy_32_16_1( xi, wkr ), Mpy_32_16_1( xr, wki ) ); a[j] = L_sub( a[j], yr ); + move32(); a[j + 1] = L_sub( yi, a[j + 1] ); + move32(); a[k] = L_add( a[k], yr ); + move32(); a[k + 1] = L_sub( yi, a[k + 1] ); + move32(); } a[m + 1] = L_negate( a[m + 1] ); @@ -2147,19 +2651,23 @@ static void dctsub( Word32 xr; m = shr( n, 1 ); - ks = nc / n; + ks = idiv1616( nc, n ); kk = 0; + move16(); FOR( j = 1; j < m; j++ ) { k = sub( n, j ); - kk += ks; - wkr = sub( c[kk], c[nc - kk] ); - wki = add( c[kk], c[nc - kk] ); + kk = add( kk, ks ); + wkr = sub( c[kk], c[sub( nc, kk )] ); + wki = add( c[kk], c[sub( nc, kk )] ); xr = L_sub( Mpy_32_16_1( a[j], wki ), Mpy_32_16_1( a[k], wkr ) ); a[j] = L_add( Mpy_32_16_1( a[j], wkr ), Mpy_32_16_1( a[k], wki ) ); + move32(); a[k] = xr; + move32(); } a[m] = Mpy_32_16_1( a[m], c[0] ); + move32(); return; } @@ -2185,26 +2693,34 @@ void edct2_fx_ivas( Copy32( in, a, n ); nw = ip[0]; - IF( GT_16( n, shl( nw, 2 ) ) ) + move16(); + if ( GT_16( n, shl( nw, 2 ) ) ) { nw = shr( n, 2 ); } nc = ip[1]; - IF( GT_16( n, nc ) ) + move16(); + if ( GT_16( n, nc ) ) { nc = n; + move16(); } - IF( LT_16( isgn, 0 ) ) + IF( isgn < 0 ) { xr = a[n - 1]; + move16(); FOR( j = n - 2; j >= 2; j -= 2 ) { a[j + 1] = L_sub( a[j], a[j - 1] ); + move32(); a[j] = L_add( a[j], a[j - 1] ); + move32(); } a[1] = L_sub( a[0], xr ); + move32(); a[0] = L_add( a[0], xr ); + move32(); IF( GT_16( n, 4 ) ) { @@ -2218,14 +2734,15 @@ void edct2_fx_ivas( } } - IF( GE_16( isgn, 0 ) ) + IF( isgn >= 0 ) { a[0] = L_shr( a[0], 1 ); + move32(); } dctsub( n, a, nc, w + nw ); - IF( GE_16( isgn, 0 ) ) + IF( isgn >= 0 ) { IF( GT_16( n, 4 ) ) { @@ -2239,16 +2756,21 @@ void edct2_fx_ivas( } xr = L_sub( a[0], a[1] ); a[0] = L_add( a[0], a[1] ); + move32(); FOR( j = 2; j < n; j += 2 ) { a[j - 1] = L_sub( a[j], a[j + 1] ); + move32(); a[j] = L_add( a[j], a[j + 1] ); + move32(); } a[n - 1] = xr; + move32(); FOR( j = 0; j < n; j++ ) { a[j] = L_shr( a[j], 5 ); + move32(); } } } @@ -2266,7 +2788,9 @@ void DoRTFTn_fx_ivas( FOR( i = 0; i < n; i++ ) { z[2 * i] = x[i]; - z[2 * i + 1] = y[i]; + move32(); + z[add( shl( i, 1 ), 1 )] = y[i]; + move32(); } SWITCH( n ) @@ -2294,11 +2818,15 @@ void DoRTFTn_fx_ivas( } x[0] = z[0]; + move32(); y[0] = z[1]; + move32(); FOR( i = 1; i < n; i++ ) { - x[n - i] = z[2 * i]; - y[n - i] = z[2 * i + 1]; + x[sub( n, i )] = z[2 * i]; + move32(); + y[sub( n, i )] = z[add( shl( i, 1 ), 1 )]; + move32(); } return; @@ -2322,22 +2850,31 @@ void fft3_fx_ivas( /* Determine the order of the transform, the length of decimated */ /* transforms m, and the step for the sine and cosine tables. */ - switch ( n ) + SWITCH( n ) { case 1536: order = 9; + move16(); m = 512; + move16(); step = 1; - break; + move16(); + BREAK; case 384: order = 7; + move16(); m = 128; + move16(); step = 4; - break; + move16(); + BREAK; default: order = 9; + move16(); m = 512; + move16(); step = 1; + move16(); } /* Compose decimated sequences X[3i], X[3i+1],X[3i+2] */ @@ -2352,8 +2889,11 @@ void fft3_fx_ivas( FOR( i = 0; i < n / 3; i++ ) { *z0++ = *x++; /* Z0[i] = X[3i]; */ + move32(); *z1++ = *x++; /* Z1[i] = X[3i+1]; */ + move32(); *z2++ = *x++; /* Z2[i] = X[3i+2]; */ + move32(); } fft_rel_fx32( &Z0[0], m, order ); @@ -2373,49 +2913,59 @@ void fft3_fx_ivas( c1_step = negate( step ); s1_step = step; + move16(); c2_step = negate( shl( step, 1 ) ); s2_step = shl( step, 1 ); c1_ind = add( T_SIN_PI_2, c1_step ); s1_ind = s1_step; + move16(); c2_ind = add( T_SIN_PI_2, c2_step ); s2_ind = s2_step; + move16(); /* special case: i = 0 */ RY[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); + move32(); /* first 3/12 */ - for ( i = 1; i < 3 * m / 8; i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + FOR( i = 1; i < i_mult( 3, shr( m, 3 ) ); ( i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) { RY[i] = L_add( RZ0[i], L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ) ); + move32(); IY[-i] = L_sub( IZ0[-i], L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ); + move32(); } /* next 1/12 */ - for ( ; i < 4 * m / 8; i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) + FOR( ; i < 4 * m / 8; ( i++, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) { RY[i] = L_add( RZ0[i], L_sub( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ); + move32(); IY[-i] = L_sub( IZ0[-i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ) ); + move32(); } /* special case: i = m/2 i.e. 1/3 */ RY[i] = L_add( RZ0[i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ) ) ); + move32(); IY[-i] = L_negate( L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ) ) ); - i++; + move32(); + i = add( i, 1 ); c1_ind = add( c1_ind, c1_step ); s1_ind = add( s1_ind, s1_step ); @@ -2423,69 +2973,81 @@ void fft3_fx_ivas( s2_ind = sub( s2_ind, s2_step ); /* next 2/12 */ - for ( j = i - 2; i < 6 * m / 8; i++, j--, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) + FOR( j = i - 2; i < 6 * m / 8; ( i++, j--, c1_ind = add( c1_ind, c1_step ), s1_ind = add( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) { RY[i] = L_add( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + move32(); IY[-i] = L_negate( L_add( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); + move32(); } /*--------------------------half--------------------------*/ /* next 2/12 */ - for ( ; i < 8 * m / 8; i++, j--, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + FOR( ; i < 8 * m / 8; ( i++, j--, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + move32(); IY[-i] = L_negate( L_add( IZ0[-j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); + move32(); } /* special case: i = m, i.e 2/3 */ RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); - IY[-i++] = L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); + move32(); + IY[-i] = L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), + Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); + move32(); + i = add( i, 1 ); c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ); /* next 1/12 */ - for ( j = 1; i < 9 * m / 8; i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) + FOR( j = 1; i < i_mult( 9, shr( m, 3 ) ); ( i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); + move32(); IY[-i] = L_sub( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), L_sub( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ); + move32(); } /* last 3/12 */ - for ( ; i < 12 * m / 8; i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) + FOR( ; i < 12 * m / 8; ( i++, j++, c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = sub( c2_ind, c2_step ), s2_ind = sub( s2_ind, s2_step ) ) ) { RY[i] = L_sub( RZ0[j], L_sub( L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ) ), L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ); + move32(); IY[-i] = L_sub( IZ0[-j], L_sub( L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ); + move32(); } /* special case: i = 3*m/2 */ RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); + move32(); return; } @@ -2506,22 +3068,31 @@ void ifft3_fx_ivas( /* Determine the order of the transform, the length of decimated */ /* transforms m, and the step for the sine and cosine tables. */ - switch ( n ) + SWITCH( n ) { case 1536: order = 9; + move16(); m = 512; + move16(); step = 1; - break; + move16(); + BREAK; case 384: order = 7; + move16(); m = 128; + move16(); step = 4; - break; + move16(); + BREAK; default: order = 9; + move16(); m = 512; + move16(); step = 1; + move16(); } /* pointer initialization */ @@ -2534,23 +3105,27 @@ void ifft3_fx_ivas( RZ0 = &Z[0]; RZ1 = RZ0 + m; - RZ2 = RZ0 + n / 2 - m / 2; + RZ2 = RZ0 + sub( shr( n, 1 ), shr( m, 1 ) ); IZ0 = &Z[n]; IZ1 = IZ0 - m; - IZ2 = IZ0 - n / 2 + m / 2; + IZ2 = IZ0 - sub( shr( n, 1 ), shr( m, 1 ) ); /* Inverse butterflies of order 3. */ /* Construction of Y0 */ RY0[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); + move32(); FOR( i = 1; i < m / 2; i++ ) { RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); + move32(); IY0[-i] = L_add( IZ0[-i], L_sub( IZ1[-i], IZ2[i] ) ); + move32(); } /* m/2 */ RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); + move32(); /* Construction of Y1 */ c0_ind = T_SIN_PI_2; @@ -2565,6 +3140,7 @@ void ifft3_fx_ivas( L_add( Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ), L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ) ); + move32(); c0_ind = sub( c0_ind, step ); s0_ind = add( s0_ind, step ); @@ -2572,7 +3148,7 @@ void ifft3_fx_ivas( s1_ind = sub( s1_ind, step ); c2_ind = sub( c2_ind, step ); s2_ind = add( s2_ind, step ); - for ( i = 1; i < m / 4; i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = sub( c2_ind, step ), s2_ind = add( s2_ind, step ) ) + FOR( i = 1; i < m / 4; ( i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = sub( c2_ind, step ), s2_ind = add( s2_ind, step ) ) ) { RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), @@ -2580,15 +3156,17 @@ void ifft3_fx_ivas( L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ) ); + move32(); IY1[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + move32(); } - for ( ; i < m / 2; i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = add( c2_ind, step ), s2_ind = sub( s2_ind, step ) ) + FOR( ; i < m / 2; ( i++, c0_ind = sub( c0_ind, step ), s0_ind = add( s0_ind, step ), c1_ind = add( c1_ind, step ), s1_ind = sub( s1_ind, step ), c2_ind = add( c2_ind, step ), s2_ind = sub( s2_ind, step ) ) ) { RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), @@ -2596,12 +3174,14 @@ void ifft3_fx_ivas( L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + move32(); IY1[-i] = L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_sub( L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + move32(); } /* m/2 */ @@ -2611,20 +3191,28 @@ void ifft3_fx_ivas( L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + move32(); /* Construction of Y2 */ c0_ind = T_SIN_PI_2; + move16(); s0_ind = 0; + move16(); c1_ind = T_SIN_PI_2 * 1 / 3; + move16(); s1_ind = T_SIN_PI_2 * 2 / 3; + move16(); c2_ind = T_SIN_PI_2 * 1 / 3; + move16(); s2_ind = T_SIN_PI_2 * 2 / 3; - step2 = 2 * step; + move16(); + step2 = shl( step, 1 ); RY2[0] = L_sub( Mpy_32_16_1( RZ0[0], t_sin[c0_ind] ), L_sub( L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ) ), L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ); + move32(); c0_ind = sub( c0_ind, step2 ); s0_ind = add( s0_ind, step2 ); @@ -2632,7 +3220,7 @@ void ifft3_fx_ivas( s1_ind = add( s1_ind, step2 ); c2_ind = add( c2_ind, step2 ); s2_ind = sub( s2_ind, step2 ); - for ( i = 1; i < m / 8; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = sub( c1_ind, step2 ), s1_ind = add( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) + FOR( i = 1; i < m / 8; ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = sub( c1_ind, step2 ), s1_ind = add( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) ) { RY2[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_add( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), @@ -2640,15 +3228,17 @@ void ifft3_fx_ivas( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + move32(); IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); + move32(); } - for ( ; i < m / 4; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) + FOR( ; i < m / 4; ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = add( c2_ind, step2 ), s2_ind = sub( s2_ind, step2 ) ) ) { RY2[i] = L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), @@ -2656,15 +3246,17 @@ void ifft3_fx_ivas( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); + move32(); IY2[-i] = L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ) ); + move32(); } - for ( ; i < 3 * m / 8; i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) + FOR( ; i < i_mult( 3, shr( m, 3 ) ); ( i++, c0_ind = sub( c0_ind, step2 ), s0_ind = add( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) ) { RY2[i] = L_sub( L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ) ), @@ -2672,15 +3264,17 @@ void ifft3_fx_ivas( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + move32(); IY2[-i] = L_sub( L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ) ) ), L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ); + move32(); } - for ( ; i < m / 2; i++, c0_ind = add( c0_ind, step2 ), s0_ind = sub( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) + FOR( ; i < m / 2; ( i++, c0_ind = add( c0_ind, step2 ), s0_ind = sub( s0_ind, step2 ), c1_ind = add( c1_ind, step2 ), s1_ind = sub( s1_ind, step2 ), c2_ind = sub( c2_ind, step2 ), s2_ind = add( s2_ind, step2 ) ) ) { RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), @@ -2688,12 +3282,14 @@ void ifft3_fx_ivas( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + move32(); IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ) ), L_sub( L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ), L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ); + move32(); } /* m/2 */ @@ -2703,6 +3299,7 @@ void ifft3_fx_ivas( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); + move32(); /* Compute the inverse FFT for all 3 blocks. */ ifft_rel_fx32( RY0, m, order ); @@ -2717,9 +3314,15 @@ void ifft3_fx_ivas( scale = (Word16) ( 0x2AAB ); FOR( i = 0; i < n; ) { - X[i++] = Mpy_32_16_1( ( *y0++ ), scale ); - X[i++] = Mpy_32_16_1( ( *y1++ ), scale ); - X[i++] = Mpy_32_16_1( ( *y2++ ), scale ); + X[i] = Mpy_32_16_1( ( *y0++ ), scale ); + move32(); + i = add( i, 1 ); + X[i] = Mpy_32_16_1( ( *y1++ ), scale ); + move32(); + i = add( i, 1 ); + X[i] = Mpy_32_16_1( ( *y2++ ), scale ); + move32(); + i = add( i, 1 ); } return; @@ -2734,27 +3337,36 @@ static void rfft_post( Word32 tmp1, tmp2, tmp3, tmp4; Word16 s, c; Word16 i = 0; + move16(); tmp1 = L_add( buf[0], buf[1] ); buf[1] = L_sub( buf[0], buf[1] ); + move32(); buf[0] = tmp1; + move32(); - FOR( i = 1; i <= ( len + 2 ) / 4; i++ ) + FOR( i = 1; i <= shr( add( len, 2 ), 2 ); i++ ) { - s = sine_table[i]; /* sin(pi*i/(len/2)) */ - c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */ + s = sine_table[i]; /* sin(pi*i/(len/2)) */ + move16(); + c = sine_table[add( i, shr( len, 2 ) )]; /* cos(pi*i/(len/2)) */ + move16(); - tmp1 = L_sub( buf[2 * i], buf[len - 2 * i] ); - tmp2 = L_add( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp1 = L_sub( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); + tmp2 = L_add( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); tmp3 = L_sub( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ tmp4 = L_add( Mpy_32_16_1( tmp1, c ), Mpy_32_16_1( tmp2, s ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add( buf[2 * i], buf[len - 2 * i] ); - tmp2 = L_sub( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp1 = L_add( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); + tmp2 = L_sub( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); buf[2 * i] = L_shr( L_sub( tmp1, tmp3 ), 1 ); - buf[2 * i + 1] = L_shr( L_sub( tmp2, tmp4 ), 1 ); - buf[len - 2 * i] = L_shr( L_add( tmp1, tmp3 ), 1 ); - buf[len - 2 * i + 1] = L_negate( L_shr( L_add( tmp2, tmp4 ), 1 ) ); + move32(); + buf[add( shl( i, 1 ), 1 )] = L_shr( L_sub( tmp2, tmp4 ), 1 ); + move32(); + buf[sub( len, shl( i, 1 ) )] = L_shr( L_add( tmp1, tmp3 ), 1 ); + move32(); + buf[add( sub( len, shl( i, 1 ) ), 1 )] = L_negate( L_shr( L_add( tmp2, tmp4 ), 1 ) ); + move32(); } } @@ -2770,24 +3382,32 @@ static void rfft_pre( tmp1 = L_add( buf[0], buf[1] ); buf[1] = Mpy_32_16_1( L_sub( buf[0], buf[1] ), scale ); + move32(); buf[0] = Mpy_32_16_1( tmp1, scale ); + move32(); - FOR( i = 1; i <= ( len + 2 ) / 4; i++ ) + FOR( i = 1; i <= shr( add( len, 2 ), 2 ); i++ ) { - s = sine_table[i]; /* sin(pi*i/(len/2)) */ - c = sine_table[i + len / 4]; /* cos(pi*i/(len/2)) */ + s = sine_table[i]; /* sin(pi*i/(len/2)) */ + move16(); + c = sine_table[add( i, shr( len, 2 ) )]; /* cos(pi*i/(len/2)) */ + move16(); - tmp1 = L_sub( buf[2 * i], buf[len - 2 * i] ); - tmp2 = L_add( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp1 = L_sub( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); + tmp2 = L_add( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); tmp3 = L_add( Mpy_32_16_1( tmp1, s ), Mpy_32_16_1( tmp2, c ) ); /* real part of j*W(k,N)*[T(k) - T'(N-k)] */ tmp4 = L_sub( Mpy_32_16_1( tmp2, s ), Mpy_32_16_1( tmp1, c ) ); /* imag part of j*W(k,N)*[T(k) - T'(N-k)] */ - tmp1 = L_add( buf[2 * i], buf[len - 2 * i] ); - tmp2 = L_sub( buf[2 * i + 1], buf[len - 2 * i + 1] ); + tmp1 = L_add( buf[2 * i], buf[sub( len, shl( i, 1 ) )] ); + tmp2 = L_sub( buf[add( shl( i, 1 ), 1 )], buf[add( sub( len, shl( i, 1 ) ), 1 )] ); buf[2 * i] = Mpy_32_16_1( L_add( tmp1, tmp3 ), scale ); - buf[2 * i + 1] = L_negate( Mpy_32_16_1( L_add( tmp2, tmp4 ), scale ) ); - buf[len - 2 * i] = Mpy_32_16_1( L_sub( tmp1, tmp3 ), scale ); - buf[len - 2 * i + 1] = Mpy_32_16_1( L_sub( tmp2, tmp4 ), scale ); + move32(); + buf[add( shl( i, 1 ), 1 )] = L_negate( Mpy_32_16_1( L_add( tmp2, tmp4 ), scale ) ); + move32(); + buf[sub( len, shl( i, 1 ) )] = Mpy_32_16_1( L_sub( tmp1, tmp3 ), scale ); + move32(); + buf[add( sub( len, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_sub( tmp2, tmp4 ), scale ); + move32(); } return; @@ -2814,13 +3434,17 @@ Word16 RFFTN_fx( FOR( i = 0; i < 320; i++ ) { x[i] = data[2 * i]; - y[i] = data[2 * i + 1]; + move32(); + y[i] = data[add( shl( i, 1 ), 1 )]; + move32(); } DoRTFT320_fx( x, y ); FOR( i = 0; i < 320; i++ ) { data[2 * i] = x[i]; - data[2 * i + 1] = y[i]; + move32(); + data[add( shl( i, 1 ), 1 )] = y[i]; + move32(); } IF( EQ_16( sign, -1 ) ) @@ -2834,27 +3458,36 @@ Word16 RFFTN_fx( { Word16 i; const Word16 log2 = 9; + move16(); Word32 reordered_data[512]; IF( EQ_16( sign, -1 ) ) { fft_rel_fx32( data, len, log2 ); reordered_data[0] = data[0]; + move32(); reordered_data[1] = data[len / 2]; + move32(); FOR( i = 1; i < len / 2; i++ ) { reordered_data[2 * i] = data[i]; - reordered_data[2 * i + 1] = data[len - i]; + move32(); + reordered_data[add( shl( i, 1 ), 1 )] = data[sub( len, i )]; + move32(); } } ELSE { reordered_data[0] = data[0]; + move32(); reordered_data[len / 2] = data[1]; + move32(); FOR( i = 1; i < len / 2; i++ ) { reordered_data[i] = data[2 * i]; - reordered_data[len - i] = data[2 * i + 1]; + move32(); + reordered_data[sub( len, i )] = data[add( shl( i, 1 ), 1 )]; + move32(); } ifft_rel_fx32( reordered_data, len, log2 ); } @@ -2876,7 +3509,9 @@ static void butterfly( Word32 *aMinusb ) { *aPlusb = L_add( a, b ); + move32(); *aMinusb = L_sub( a, b ); + move32(); return; } @@ -2892,14 +3527,22 @@ static void fft2( Word32 re2, im2; re1 = pInOut[0]; + move32(); im1 = pInOut[1]; + move32(); re2 = pInOut[2]; + move32(); im2 = pInOut[3]; + move32(); pInOut[0] = L_add( re1, re2 ); + move32(); pInOut[1] = L_add( im1, im2 ); + move32(); pInOut[2] = L_sub( re1, re2 ); + move32(); pInOut[3] = L_sub( im1, im2 ); + move32(); return; } @@ -2917,11 +3560,17 @@ static void fft3_2( Word32 *pInOut ) Word32 tmp3, tmp4; re1 = pInOut[0]; + move32(); im1 = pInOut[1]; + move32(); re2 = pInOut[2]; + move32(); im2 = pInOut[3]; + move32(); re3 = pInOut[4]; + move32(); im3 = pInOut[5]; + move32(); /* FFT MATRIX: 1.0000 1.0000 1.0000 @@ -2934,12 +3583,18 @@ static void fft3_2( Word32 *pInOut ) tmp2 = L_sub( re2, re3 ); tmp4 = L_sub( im2, im3 ); pInOut[0] = L_add( re1, tmp1 ); + move32(); pInOut[1] = L_add( im1, tmp3 ); + move32(); pInOut[2] = L_sub( re1, L_sub( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); + move32(); pInOut[4] = L_sub( re1, L_add( Mpy_32_16_1( tmp1, C31 ), Mpy_32_16_1( tmp4, C32 ) ) ); + move32(); pInOut[3] = L_sub( im1, L_add( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); + move32(); pInOut[5] = L_add( im1, L_sub( Mpy_32_16_1( tmp2, C32 ), Mpy_32_16_1( tmp3, C31 ) ) ); + move32(); } @@ -2957,13 +3612,21 @@ static void fft4( Word32 tmp7, tmp8; re1 = pInOut[0]; + move32(); im1 = pInOut[1]; + move32(); re2 = pInOut[2]; + move32(); im2 = pInOut[3]; + move32(); re3 = pInOut[4]; + move32(); im3 = pInOut[5]; + move32(); re4 = pInOut[6]; + move32(); im4 = pInOut[7]; + move32(); /* 1.0000 1.0000 1.0000 1.0000 @@ -2976,19 +3639,27 @@ static void fft4( tmp5 = L_add( im1, im3 ); tmp7 = L_add( im2, im4 ); pInOut[0] = L_add( tmp1, tmp3 ); + move32(); pInOut[4] = L_sub( tmp1, tmp3 ); + move32(); pInOut[1] = L_add( tmp5, tmp7 ); + move32(); pInOut[5] = L_sub( tmp5, tmp7 ); + move32(); tmp2 = L_sub( re1, re3 ); tmp4 = L_sub( re2, re4 ); tmp6 = L_sub( im1, im3 ); tmp8 = L_sub( im2, im4 ); pInOut[2] = L_add( tmp2, tmp8 ); + move32(); pInOut[6] = L_sub( tmp2, tmp8 ); + move32(); pInOut[3] = L_sub( tmp6, tmp4 ); + move32(); pInOut[7] = L_add( tmp4, tmp6 ); + move32(); return; } @@ -3005,10 +3676,15 @@ static void fft5( cmplx t[4]; x[0] = pInOut[0]; + move32(); x[1] = pInOut[1]; + move32(); x[2] = pInOut[2]; + move32(); x[3] = pInOut[3]; + move32(); x[4] = pInOut[4]; + move32(); /* 1.0000 1.0000 1.0000 1.0000 1.0000 @@ -3019,17 +3695,26 @@ static void fft5( 1.0000 0.3090 + 0.9511i -0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 - 0.9511i */ t[0] = CL_add( x[1], x[4] ); + move32(); t[1] = CL_sub( x[1], x[4] ); + move32(); t[2] = CL_add( x[2], x[3] ); + move32(); t[3] = CL_sub( x[2], x[3] ); + move32(); pInOut[0] = CL_add( x[0], CL_add( t[0], t[2] ) ); + move32(); pInOut[1] = CL_add( CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_scale( t[2], C53 ) ) ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ); + move32(); pInOut[4] = CL_add( x[0], CL_sub( CL_scale( t[0], C51 ), CL_add( CL_scale( t[2], C53 ), CL_add( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C52 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C54 ) ) ) ) ) ); + move32(); pInOut[2] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_scale( t[2], C51 ), CL_sub( CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ) ); + move32(); pInOut[3] = CL_add( CL_sub( x[0], CL_scale( t[0], C53 ) ), CL_add( CL_sub( CL_scale( t[2], C51 ), CL_conjugate( CL_scale( CL_swap_real_imag( t[1] ), C54 ) ) ), CL_conjugate( CL_scale( CL_swap_real_imag( t[3] ), C52 ) ) ) ); + move32(); return; } @@ -3049,9 +3734,13 @@ static void fft8_2( Word32 im3_5p, im3_5m; re0 = pInOut[0]; + move32(); im0 = pInOut[1]; + move32(); re4 = pInOut[8]; + move32(); im4 = pInOut[9]; + move32(); butterfly( pInOut[1 * 2], pInOut[7 * 2], &re1_7p, &re1_7m ); butterfly( pInOut[1 * 2 + 1], pInOut[7 * 2 + 1], &im1_7p, &im1_7m ); butterfly( pInOut[2 * 2], pInOut[6 * 2], &re2_6p, &re2_6m ); @@ -3069,29 +3758,45 @@ static void fft8_2( 6: 1 + 0i - 0 + 1i -1 - 0i 0 - 1i 1 + 0i - 0 + 1i - 1 - 0i - 0 - 1i 7: 1 + 0i C81 + C81i -0 + 1i -C81 + C81i -1 - 0i -C81 - C81i - 0 - 1i C81 - C81i */ - pInOut[0] = re0 + re4 + re1_7p + re2_6p + re3_5p; - pInOut[1] = im0 + im4 + im1_7p + im2_6p + im3_5p; + pInOut[0] = L_add( L_add( L_add( L_add( re0, re4 ), re1_7p ), re2_6p ), re3_5p ); + move32(); + pInOut[1] = L_add( L_add( L_add( L_add( im0, im4 ), im1_7p ), im2_6p ), im3_5p ); + move32(); - pInOut[2] = re0 + Mpy_32_16_1( L_sub( re1_7p, re3_5p ), C81 ) - re4 + Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) + im2_6m; - pInOut[3] = im0 + Mpy_32_16_1( L_sub( im1_7p, im3_5p ), C81 ) - im4 - Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) - re2_6m; + pInOut[2] = L_add( L_add( L_sub( L_add( re0, Mpy_32_16_1( L_sub( re1_7p, re3_5p ), C81 ) ), re4 ), Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) ), im2_6m ); + move32(); + pInOut[3] = L_sub( L_sub( L_sub( L_add( im0, Mpy_32_16_1( L_sub( im1_7p, im3_5p ), C81 ) ), im4 ), Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) ), re2_6m ); + move32(); - pInOut[4] = re0 - re2_6p + re4 + im1_7m - im3_5m; - pInOut[5] = im0 - im2_6p + im4 - re1_7m + re3_5m; + pInOut[4] = L_sub( L_add( L_add( L_sub( re0, re2_6p ), re4 ), im1_7m ), im3_5m ); + move32(); + pInOut[5] = L_add( L_sub( L_add( L_sub( im0, im2_6p ), im4 ), re1_7m ), re3_5m ); + move32(); - pInOut[6] = re0 + Mpy_32_16_1( L_sub( re3_5p, re1_7p ), C81 ) - re4 + Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) - im2_6m; - pInOut[7] = im0 + Mpy_32_16_1( L_sub( im3_5p, im1_7p ), C81 ) - im4 - Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) + re2_6m; + pInOut[6] = L_sub( L_add( L_sub( L_add( re0, Mpy_32_16_1( L_sub( re3_5p, re1_7p ), C81 ) ), re4 ), Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) ), im2_6m ); + move32(); + pInOut[7] = L_add( L_sub( L_sub( L_add( im0, Mpy_32_16_1( L_sub( im3_5p, im1_7p ), C81 ) ), im4 ), Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) ), re2_6m ); + move32(); - pInOut[8] = re0 - re1_7p + re2_6p - re3_5p + re4; - pInOut[9] = im0 - im1_7p + im2_6p - im3_5p + im4; + pInOut[8] = L_add( L_sub( L_add( L_sub( re0, re1_7p ), re2_6p ), re3_5p ), re4 ); + move32(); + pInOut[9] = L_add( L_sub( L_add( L_sub( im0, im1_7p ), im2_6p ), im3_5p ), im4 ); + move32(); - pInOut[10] = re0 + Mpy_32_16_1( L_sub( re3_5p, re1_7p ), C81 ) - re4 - Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) + im2_6m; - pInOut[11] = im0 + Mpy_32_16_1( L_sub( im3_5p, im1_7p ), C81 ) - im4 + Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) - re2_6m; + pInOut[10] = L_add( L_sub( L_sub( L_add( re0, Mpy_32_16_1( L_sub( re3_5p, re1_7p ), C81 ) ), re4 ), Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) ), im2_6m ); + move32(); + pInOut[11] = L_sub( L_add( L_sub( L_add( im0, Mpy_32_16_1( L_sub( im3_5p, im1_7p ), C81 ) ), im4 ), Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) ), re2_6m ); + move32(); - pInOut[12] = re0 - re2_6p + re4 - im1_7m + im3_5m; - pInOut[13] = im0 - im2_6p + im4 + re1_7m - re3_5m; + pInOut[12] = L_add( L_sub( L_add( L_sub( re0, re2_6p ), re4 ), im1_7m ), im3_5m ); + move32(); + pInOut[13] = L_sub( L_add( L_add( L_sub( im0, im2_6p ), im4 ), re1_7m ), re3_5m ); + move32(); - pInOut[14] = re0 + Mpy_32_16_1( L_sub( re1_7p, re3_5p ), C81 ) - re4 - Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) - im2_6m; - pInOut[15] = im0 + Mpy_32_16_1( L_sub( im1_7p, im3_5p ), C81 ) - im4 + Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) + re2_6m; + pInOut[14] = L_sub( L_sub( L_sub( L_add( re0, Mpy_32_16_1( L_sub( re1_7p, re3_5p ), C81 ) ), re4 ), Mpy_32_16_1( L_add( im1_7m, im3_5m ), C81 ) ), im2_6m ); + move32(); + pInOut[15] = L_add( L_add( L_sub( L_add( im0, Mpy_32_16_1( L_sub( im1_7p, im3_5p ), C81 ) ), im4 ), Mpy_32_16_1( L_add( re1_7m, re3_5m ), C81 ) ), re2_6m ); + move32(); return; } @@ -3113,16 +3818,20 @@ static void nextFFT( fft4( x ); BREAK; case 5: - FOR( Word32 i = 0; i < 5; i++ ) + FOR( Word16 i = 0; i < 5; i++ ) { val[i].re = x[2 * i]; - val[i].im = x[2 * i + 1]; + move32(); + val[i].im = x[add( shl( i, 1 ), 1 )]; + move32(); } fft5( val ); - FOR( Word32 i = 0; i < 5; i++ ) + FOR( Word16 i = 0; i < 5; i++ ) { x[2 * i] = val[i].re; - x[2 * i + 1] = val[i].im; + move32(); + x[add( shl( i, 1 ), 1 )] = val[i].im; + move32(); } BREAK; case 8: @@ -3142,16 +3851,19 @@ static __inline Word16 findFactor( const Word16 length ) { Word16 i = 0; + move16(); Word16 factor = 0; + move16(); WHILE( CTFFTfactors[i] != 0 ) { - IF( EQ_16( 0, ( length % CTFFTfactors[i] ) ) ) + IF( ( length % CTFFTfactors[i] ) == 0 ) { factor = CTFFTfactors[i]; + move16(); BREAK; } - i++; + i = add( i, 1 ); } return factor; } @@ -3165,12 +3877,17 @@ static __inline void twiddle( Word16 i, ii; const Word16 *ptr_sin = &sin_twiddle_table_25_5_5[0]; const Word16 *ptr_cos = &cos_twiddle_table_25_5_5[0]; + + test(); + test(); + test(); + test(); IF( EQ_16( length, 16 ) && EQ_16( n1, 8 ) && EQ_16( n2, 2 ) ) { ptr_sin = &sin_twiddle_table_16_8_2[0]; ptr_cos = &cos_twiddle_table_16_8_2[0]; } - ELSE IF( length != 25 || n1 != 5 || n2 != 5 ) + ELSE IF( NE_16( length, 25 ) || NE_16( n1, 5 ) || NE_16( n2, 5 ) ) { assert( 0 ); } @@ -3180,10 +3897,12 @@ static __inline void twiddle( FOR( ii = 1; ii < n2; ii++ ) { Word32 xRe, xIm; - xRe = x[2 * ( i * n2 + ii )]; - xIm = x[2 * ( i * n2 + ii ) + 1]; - x[2 * ( i * n2 + ii )] = (Word32) L_sub( Mpy_32_16_1( xRe, ptr_cos[i * n2 + ii] ), Mpy_32_16_1( xIm, ptr_sin[i * n2 + ii] ) ); - x[2 * ( i * n2 + ii ) + 1] = (Word32) L_add( Mpy_32_16_1( xRe, ptr_sin[i * n2 + ii] ), Mpy_32_16_1( xIm, ptr_cos[i * n2 + ii] ) ); + xRe = x[shl( ( add( i_mult( i, n2 ), ii ) ), 1 )]; + xIm = x[add( shl( ( add( i_mult( i, n2 ), ii ) ), 1 ), 1 )]; + x[shl( ( add( i_mult( i, n2 ), ii ) ), 1 )] = L_sub( Mpy_32_16_1( xRe, ptr_cos[add( i_mult( i, n2 ), ii )] ), Mpy_32_16_1( xIm, ptr_sin[add( i_mult( i, n2 ), ii )] ) ); + move32(); + x[add( shl( ( add( i_mult( i, n2 ), ii ) ), 1 ), 1 )] = L_add( Mpy_32_16_1( xRe, ptr_sin[add( i_mult( i, n2 ), ii )] ), Mpy_32_16_1( xIm, ptr_cos[add( i_mult( i, n2 ), ii )] ) ); + move32(); } } return; @@ -3198,6 +3917,7 @@ static void cooleyTukeyFFT( Word16 i, ii; Word16 n1, n2; Word16 cnt = 0; + move16(); Word32 *src, *dest; cmplx val[5]; @@ -3218,13 +3938,17 @@ static void cooleyTukeyFFT( FOR( i = 0; i < 5; i++ ) { val[i].re = x[2 * i]; - val[i].im = x[2 * i + 1]; + move32(); + val[i].im = x[add( shl( i, 1 ), 1 )]; + move32(); } fft5( val ); FOR( i = 0; i < 5; i++ ) { x[2 * i] = val[i].re; - x[2 * i + 1] = val[i].im; + move32(); + x[add( shl( i, 1 ), 1 )] = val[i].im; + move32(); } BREAK; case 8: @@ -3234,10 +3958,11 @@ static void cooleyTukeyFFT( { factor = findFactor( length ); - IF( GT_16( factor, 0 ) && GT_16( length / factor, 1 ) ) + IF( GT_16( factor, 0 ) && GT_16( idiv1616( length, factor ), 1 ) ) { n1 = factor; - n2 = length / factor; + move16(); + n2 = idiv1616( length, factor ); /* DATA Resorting for stage1 */ dest = scratch; @@ -3249,7 +3974,9 @@ static void cooleyTukeyFFT( /* *dest++ = x[2*(i+ii*n1)]; */ /* *dest++ = x[2*(i+ii*n1)+1]; */ *dest++ = *src; + move32(); *dest++ = *( src + 1 ); + move32(); src += 2 * n1; } } @@ -3258,39 +3985,47 @@ static void cooleyTukeyFFT( FOR( i = 0; i < length; i++ ) { *dest++ = *src++; + move32(); *dest++ = *src++; + move32(); } /* perform n1 ffts of length n2 */ FOR( i = 0; i < n1; i++ ) { - cooleyTukeyFFT( x + 2 * i * n2, n2, scratch + 2 * i * n2 ); + cooleyTukeyFFT( x + shl( i_mult( i, n2 ), 1 ), n2, scratch + shl( i_mult( i, n2 ), 1 ) ); } /*data twiddeling */ twiddle( x, length, n1, n2 ); /* DATA Resorting for stage2 */ cnt = 0; + move16(); FOR( i = 0; i < n2; i++ ) { FOR( ii = 0; ii < n1; ii++ ) { - scratch[2 * cnt] = x[2 * ( i + ii * n2 )]; - scratch[2 * cnt + 1] = x[2 * ( i + ii * n2 ) + 1]; - cnt++; + scratch[2 * cnt] = x[shl( add( i, i_mult( ii, n2 ) ), 1 )]; + move32(); + scratch[add( shl( cnt, 1 ), 1 )] = x[add( shl( add( i, i_mult( ii, n2 ) ), 1 ), 1 )]; + move32(); + cnt = add( cnt, 1 ); } } /* perform n2 ffts of length n1 */ FOR( i = 0; i < n2; i++ ) { - nextFFT( scratch + 2 * i * n1, n1 ); + nextFFT( scratch + shl( i_mult( i, n1 ), 1 ), n1 ); } cnt = 0; + move16(); FOR( i = 0; i < n1; i++ ) { FOR( ii = 0; ii < n2; ii++ ) { - x[2 * cnt] = scratch[2 * ( i + ii * n1 )]; - x[2 * cnt + 1] = scratch[2 * ( i + ii * n1 ) + 1]; - cnt++; + x[2 * cnt] = scratch[shl( add( i, i_mult( ii, n1 ) ), 1 )]; + move32(); + x[add( shl( cnt, 1 ), 1 )] = scratch[add( shl( add( i, i_mult( ii, n1 ) ), 1 ), 1 )]; + move32(); + cnt = add( cnt, 1 ); } } } @@ -3318,38 +4053,52 @@ static void pfaDFT( { Word32 *tmp = scratch1; Word16 n1_inv = 1, n2_inv = 1; + move16(); + move16(); Word16 n2 = factor[0 /*idx*/]; - Word16 n1 = length / n2; + move16(); + Word16 n1 = idiv1616( length, n2 ); Word16 idx, incr; - WHILE( ( ( n1_inv * n1 ) % n2 ) != 1 ) + WHILE( ( i_mult( n1_inv, n1 ) % n2 ) != 1 ) { - n1_inv++; + n1_inv = add( n1_inv, 1 ); } - WHILE( ( ( n2_inv * n2 ) % n1 ) != 1 ) + WHILE( ( i_mult( n2_inv, n2 ) % n1 ) != 1 ) { - n2_inv++; + n2_inv = add( n2_inv, 1 ); } idx = 0; - incr = n1 * n1_inv; + move16(); + incr = i_mult( n1, n1_inv ); + move16(); cnt = 0; + move16(); FOR( i = 0; i < n1; i++ ) { FOR( ii = 0; ii < n2 - 1; ii++ ) { - tmp[cnt++] = x[2 * idx]; - tmp[cnt++] = x[2 * idx + 1]; + tmp[cnt] = x[2 * idx]; + move32(); + cnt = add( cnt, 1 ); + tmp[cnt] = x[add( shl( idx, 1 ), 1 )]; + move32(); + cnt = add( cnt, 1 ); - idx += incr; + idx = add( idx, incr ); IF( GT_16( idx, length ) ) { - idx -= length; + idx = sub( idx, length ); } } - tmp[cnt++] = x[2 * idx]; - tmp[cnt++] = x[2 * idx + 1]; - idx++; + tmp[cnt] = x[2 * idx]; + move32(); + cnt = add( cnt, 1 ); + tmp[cnt] = x[add( shl( idx, 1 ), 1 )]; + move32(); + cnt = add( cnt, 1 ); + idx = add( idx, 1 ); } FOR( cnt = 0; cnt < length; cnt += n2 ) { @@ -3359,35 +4108,45 @@ static void pfaDFT( { FOR( i = 0; i < n2; i++ ) { - x[2 * ( cnt + i * n1 )] = tmp[2 * ( cnt * n2 + i )]; - x[2 * ( cnt + i * n1 ) + 1] = tmp[2 * ( cnt * n2 + i ) + 1]; + x[shl( add( cnt, i_mult( i, n1 ) ), 1 )] = tmp[shl( add( i_mult( cnt, n2 ), i ), 1 )]; + move32(); + x[add( shl( add( cnt, i_mult( i, n1 ) ), 1 ), 1 )] = tmp[add( shl( add( i_mult( cnt, n2 ), i ), 1 ), 1 )]; + move32(); } } FOR( cnt = 0; cnt < length; cnt += n1 ) { - pfaDFT( x + 2 * cnt, n1, tmp, numFactors - 1, &factor[1] ); + pfaDFT( x + 2 * cnt, n1, tmp, sub( numFactors, 1 ), &factor[1] ); } idx = 0; + move16(); cnt = 0; + move16(); FOR( i = 0; i < n2; i++ ) { - idx = i * n1; + idx = i_mult( i, n1 ); FOR( ii = 0; ii < n1; ii++ ) { - tmp[2 * idx] = x[cnt++]; - tmp[2 * idx + 1] = x[cnt++]; - idx += n2; + tmp[2 * idx] = x[cnt]; + move32(); + cnt = add( cnt, 1 ); + tmp[add( shl( idx, 1 ), 1 )] = x[cnt]; + move32(); + cnt = add( cnt, 1 ); + idx = add( idx, n2 ); IF( GT_16( idx, length ) ) { - idx -= length; + idx = sub( idx, length ); } } } FOR( cnt = 0; cnt < length; cnt++ ) { x[2 * cnt] = tmp[2 * cnt]; - x[2 * cnt + 1] = tmp[2 * cnt + 1]; + move32(); + x[add( shl( cnt, 1 ), 1 )] = tmp[add( shl( cnt, 1 ), 1 )]; + move32(); } } ELSE @@ -3405,11 +4164,14 @@ static void fftf_interleave( const Word16 len ) { Word16 i = 0; + move16(); FOR( i = 0; i < len; i++ ) { *out++ = *re++; + move32(); *out++ = *im++; + move32(); } return; @@ -3422,11 +4184,14 @@ static void fftf_deinterleave( const Word16 len ) { Word16 i = 0; + move16(); FOR( i = 0; i < len; i++ ) { *re++ = *in++; + move32(); *im++ = *in++; + move32(); } return; @@ -3439,6 +4204,9 @@ static void DoRTFT600( { Word32 scratch[1200], cmplx[1200]; Word16 factors[3] = { 25, 8, 3 }; + move16(); + move16(); + move16(); fftf_interleave( x, y, cmplx, 600 ); pfaDFT( cmplx, 600, scratch, 3, factors ); @@ -3454,6 +4222,8 @@ static void DoRTFT400( { Word32 scratch[800], cmplx[800]; Word16 factors[2] = { 25, 16 }; + move16(); + move16(); fftf_interleave( x, y, cmplx, 400 ); pfaDFT( cmplx, 400, scratch, 2, factors ); @@ -3470,6 +4240,9 @@ static void DoRTFT240( { Word32 scratch[480], cmplx[480]; Word16 factors[3] = { 16, 5, 3 }; + move16(); + move16(); + move16(); fftf_interleave( x, y, cmplx, 240 ); pfaDFT( cmplx, 240, scratch, 3, factors ); @@ -3485,6 +4258,8 @@ static void DoRTFT200( { Word32 scratch[400], cmplx[400]; Word16 factors[2] = { 25, 8 }; + move16(); + move16(); fftf_interleave( x, y, cmplx, 200 ); pfaDFT( cmplx, 200, scratch, 2, factors ); @@ -3500,6 +4275,8 @@ static void DoRTFT100( { Word32 scratch[200], cmplx[200]; Word16 factors[2] = { 25, 4 }; + move16(); + move16(); fftf_interleave( x, y, cmplx, 100 ); pfaDFT( cmplx, 100, scratch, 2, factors ); @@ -3585,6 +4362,7 @@ static void fft_len5( t = CL_scale( CL_sub( y1, y3 ), FFT_C54 ); y1 = CL_add( y1, y3 ); x[0] = CL_add( x[0], y1 ); + move64(); y1 = CL_add( x[0], CL_shl( CL_scale( y1, FFT_C55 ), 1 ) ); y3 = CL_sub( y1, t ); @@ -3595,9 +4373,13 @@ static void fft_len5( y2 = CL_add( t, CL_scale( y2, FFT_C53 ) ); x[1] = CL_msu_j( y1, y2 ); + move64(); x[4] = CL_mac_j( y1, y2 ); + move64(); x[2] = CL_mac_j( y3, y4 ); + move64(); x[3] = CL_msu_j( y3, y4 ); + move64(); return; } @@ -3608,36 +4390,63 @@ static void fft_len8( cmplx t[8], s[8]; t[0] = CL_add( x[0], x[4] ); + move64(); t[1] = CL_sub( x[0], x[4] ); + move64(); t[2] = CL_add( x[1], x[5] ); + move64(); t[3] = CL_sub( x[1], x[5] ); + move64(); t[4] = CL_add( x[2], x[6] ); + move64(); t[5] = CL_sub( x[2], x[6] ); + move64(); t[6] = CL_add( x[3], x[7] ); + move64(); t[7] = CL_sub( x[3], x[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); + move64(); x[0] = CL_add( s[0], s[1] ); + move64(); x[4] = CL_sub( s[0], s[1] ); + move64(); x[2] = CL_sub( s[2], s[3] ); + move64(); x[6] = CL_add( s[2], s[3] ); + move64(); x[3] = CL_add( s[4], s[7] ); + move64(); x[7] = CL_sub( s[4], s[7] ); + move64(); x[1] = CL_add( s[5], s[6] ); + move64(); x[5] = CL_sub( s[5], s[6] ); + move64(); return; } @@ -3650,58 +4459,100 @@ static void fft_len10( cmplx y[10]; s[0] = CL_add( x[6], x[4] ); + move64(); s[3] = CL_sub( x[6], x[4] ); + move64(); s[2] = CL_add( x[2], x[8] ); + move64(); s[1] = CL_sub( x[2], x[8] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[0] = CL_add( x[0], s[0] ); + move64(); s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); + move64(); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[2] = CL_msu_j( s[0], s[1] ); + move64(); y[8] = CL_mac_j( s[0], s[1] ); + move64(); y[4] = CL_mac_j( s[2], s[3] ); + move64(); y[6] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( x[1], x[9] ); + move64(); s[3] = CL_sub( x[1], x[9] ); + move64(); s[2] = CL_add( x[7], x[3] ); + move64(); s[1] = CL_sub( x[7], x[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[1] = CL_add( x[5], s[0] ); + move64(); s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[3] = CL_msu_j( s[0], s[1] ); + move64(); y[9] = CL_mac_j( s[0], s[1] ); + move64(); + move64(); y[5] = CL_mac_j( s[2], s[3] ); + move64(); y[7] = CL_msu_j( s[2], s[3] ); + move64(); x[0] = CL_add( y[0], y[1] ); + move64(); x[5] = CL_sub( y[0], y[1] ); + move64(); x[2] = CL_add( y[2], y[3] ); + move64(); x[7] = CL_sub( y[2], y[3] ); + move64(); x[4] = CL_add( y[4], y[5] ); + move64(); x[9] = CL_sub( y[4], y[5] ); + move64(); x[6] = CL_add( y[6], y[7] ); + move64(); x[1] = CL_sub( y[6], y[7] ); + move64(); x[8] = CL_add( y[8], y[9] ); + move64(); x[3] = CL_sub( y[8], y[9] ); + move64(); return; } @@ -3714,101 +4565,176 @@ static void fft_len15( cmplx y[15]; s[0] = CL_add( x[3], x[12] ); + move64(); s[3] = CL_sub( x[3], x[12] ); + move64(); s[2] = CL_add( x[6], x[9] ); + move64(); s[1] = CL_sub( x[6], x[9] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[0] = CL_add( x[0], s[0] ); + move64(); s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[1] = CL_msu_j( s[0], s[1] ); + move64(); y[4] = CL_mac_j( s[0], s[1] ); + move64(); y[2] = CL_mac_j( s[2], s[3] ); + move64(); y[3] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( x[8], x[2] ); + move64(); s[3] = CL_sub( x[8], x[2] ); + move64(); s[2] = CL_add( x[11], x[14] ); + move64(); s[1] = CL_sub( x[11], x[14] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[5] = CL_add( x[5], s[0] ); + move64(); s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[6] = CL_msu_j( s[0], s[1] ); + move64(); y[9] = CL_mac_j( s[0], s[1] ); + move64(); y[7] = CL_mac_j( s[2], s[3] ); + move64(); y[8] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( x[13], x[7] ); + move64(); s[3] = CL_sub( x[13], x[7] ); + move64(); s[2] = CL_add( x[1], x[4] ); + move64(); s[1] = CL_sub( x[1], x[4] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[10] = CL_add( x[10], s[0] ); + move64(); s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[11] = CL_msu_j( s[0], s[1] ); + move64(); y[14] = CL_mac_j( s[0], s[1] ); + move64(); y[12] = CL_mac_j( s[2], s[3] ); + move64(); y[13] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( y[5], y[10] ); + move64(); s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + move64(); x[0] = CL_add( y[0], s[0] ); + move64(); s[0] = CL_sub( y[0], CL_shr( s[0], 1 ) ); + move64(); x[10] = CL_mac_j( s[0], s[1] ); + move64(); x[5] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[6], y[11] ); + move64(); s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + move64(); x[6] = CL_add( y[1], s[0] ); + move64(); s[0] = CL_sub( y[1], CL_shr( s[0], 1 ) ); + move64(); x[1] = CL_mac_j( s[0], s[1] ); + move64(); x[11] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[7], y[12] ); + move64(); s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + move64(); x[12] = CL_add( y[2], s[0] ); + move64(); s[0] = CL_sub( y[2], CL_shr( s[0], 1 ) ); + move64(); x[7] = CL_mac_j( s[0], s[1] ); + move64(); x[2] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[8], y[13] ); + move64(); s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + move64(); x[3] = CL_add( y[3], s[0] ); + move64(); s[0] = CL_sub( y[3], CL_shr( s[0], 1 ) ); + move64(); x[13] = CL_mac_j( s[0], s[1] ); + move64(); x[8] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[9], y[14] ); + move64(); s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + move64(); x[9] = CL_add( y[4], s[0] ); + move64(); s[0] = CL_sub( y[4], CL_shr( s[0], 1 ) ); + move64(); x[4] = CL_mac_j( s[0], s[1] ); + move64(); x[14] = CL_msu_j( s[0], s[1] ); + move64(); return; } @@ -3821,137 +4747,242 @@ static void fft_len16( cmplx y[16]; s[0] = CL_shr( x[0], SCALEFACTOR16 ); + move64(); s[1] = CL_shr( x[4], SCALEFACTOR16 ); + move64(); s[2] = CL_shr( x[8], SCALEFACTOR16 ); + move64(); s[3] = CL_shr( x[12], SCALEFACTOR16 ); + move64(); t[0] = CL_add( s[0], s[2] ); + move64(); t[1] = CL_sub( s[0], s[2] ); + move64(); t[2] = CL_add( s[1], s[3] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( s[1] ), CL_conjugate( s[3] ) ) ); + move64(); y[0] = CL_add( t[0], t[2] ); + move64(); y[1] = CL_sub( t[1], t[3] ); + move64(); y[2] = CL_sub( t[0], t[2] ); + move64(); y[3] = CL_add( t[1], t[3] ); + move64(); s[0] = CL_shr( x[1], SCALEFACTOR16 ); + move64(); s[1] = CL_shr( x[5], SCALEFACTOR16 ); + move64(); s[2] = CL_shr( x[9], SCALEFACTOR16 ); + move64(); s[3] = CL_shr( x[13], SCALEFACTOR16 ); + move64(); t[0] = CL_add( s[0], s[2] ); + move64(); t[1] = CL_sub( s[0], s[2] ); + move64(); t[2] = CL_add( s[1], s[3] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( s[1] ), CL_conjugate( s[3] ) ) ); + move64(); y[4] = CL_add( t[0], t[2] ); + move64(); y[5] = CL_sub( t[1], t[3] ); + move64(); y[6] = CL_sub( t[0], t[2] ); + move64(); y[7] = CL_add( t[1], t[3] ); + move64(); s[0] = CL_shr( x[2], SCALEFACTOR16 ); + move64(); s[1] = CL_shr( x[6], SCALEFACTOR16 ); + move64(); s[2] = CL_shr( x[10], SCALEFACTOR16 ); + move64(); s[3] = CL_shr( x[14], SCALEFACTOR16 ); + move64(); t[0] = CL_add( s[0], s[2] ); + move64(); t[1] = CL_sub( s[0], s[2] ); + move64(); t[2] = CL_add( s[1], s[3] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( s[1] ), CL_conjugate( s[3] ) ) ); + move64(); y[8] = CL_add( t[0], t[2] ); + move64(); y[9] = CL_sub( t[1], t[3] ); + move64(); y[10] = CL_swap_real_imag( CL_sub( t[0], t[2] ) ); + move64(); y[10] = CL_conjugate( y[10] ); + move64(); y[11] = CL_add( t[1], t[3] ); + move64(); s[0] = CL_shr( x[3], SCALEFACTOR16 ); + move64(); s[1] = CL_shr( x[7], SCALEFACTOR16 ); + move64(); s[2] = CL_shr( x[11], SCALEFACTOR16 ); + move64(); s[3] = CL_shr( x[15], SCALEFACTOR16 ); + move64(); t[0] = CL_add( s[0], s[2] ); + move64(); t[1] = CL_sub( s[0], s[2] ); + move64(); t[2] = CL_add( s[1], s[3] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( s[1] ), CL_conjugate( s[3] ) ) ); + move64(); y[12] = CL_add( t[0], t[2] ); + move64(); y[13] = CL_sub( t[1], t[3] ); + move64(); y[14] = CL_sub( t[0], t[2] ); + move64(); y[15] = CL_add( t[1], t[3] ); + move64(); s[0] = CL_scale( y[11], FFT_C162 ); + move64(); y[11] = CL_mac_j( s[0], s[0] ); + move64(); s[0] = CL_scale( y[14], FFT_C162 ); + move64(); y[14] = CL_mac_j( s[0], s[0] ); + move64(); s[0] = CL_scale( y[6], FFT_C161 ); + move64(); y[6] = CL_mac_j( s[0], s[0] ); + move64(); y[6] = CL_swap_real_imag( y[6] ); + move64(); y[6] = CL_conjugate( y[6] ); + move64(); s[0] = CL_scale( y[9], FFT_C161 ); + move64(); y[9] = CL_mac_j( s[0], s[0] ); + move64(); y[9] = CL_swap_real_imag( y[9] ); + move64(); y[9] = CL_conjugate( y[9] ); + move64(); s[0] = CL_scale( y[5], FFT_C163 ); + move64(); s[1] = CL_scale( y[5], FFT_C166 ); + move64(); y[5] = CL_mac_j( s[0], s[1] ); + move64(); s[0] = CL_scale( y[7], FFT_C165 ); + move64(); s[1] = CL_scale( y[7], FFT_C164 ); + move64(); y[7] = CL_mac_j( s[0], s[1] ); + move64(); s[0] = CL_scale( y[13], FFT_C165 ); + move64(); s[1] = CL_scale( y[13], FFT_C164 ); + move64(); y[13] = CL_mac_j( s[0], s[1] ); + move64(); s[0] = CL_scale( y[15], FFT_C164 ); + move64(); s[1] = CL_scale( y[15], FFT_C165 ); + move64(); y[15] = CL_mac_j( s[0], s[1] ); + move64(); t[0] = CL_add( y[0], y[8] ); + move64(); t[1] = CL_sub( y[0], y[8] ); + move64(); t[2] = CL_add( y[4], y[12] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[4] ), CL_conjugate( y[12] ) ) ); + move64(); x[0] = CL_add( t[0], t[2] ); + move64(); x[4] = CL_sub( t[1], t[3] ); + move64(); x[8] = CL_sub( t[0], t[2] ); + move64(); x[12] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[1], y[9] ); + move64(); t[1] = CL_sub( y[1], y[9] ); + move64(); t[2] = CL_add( y[5], y[13] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[5] ), CL_conjugate( y[13] ) ) ); + move64(); x[1] = CL_add( t[0], t[2] ); + move64(); x[5] = CL_sub( t[1], t[3] ); + move64(); x[9] = CL_sub( t[0], t[2] ); + move64(); x[13] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[2], y[10] ); + move64(); t[1] = CL_sub( y[2], y[10] ); + move64(); t[2] = CL_add( y[6], y[14] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[6] ), CL_conjugate( y[14] ) ) ); + move64(); x[2] = CL_add( t[0], t[2] ); + move64(); x[6] = CL_sub( t[1], t[3] ); + move64(); x[10] = CL_sub( t[0], t[2] ); + move64(); x[14] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[3], y[11] ); + move64(); t[1] = CL_sub( y[3], y[11] ); + move64(); t[2] = CL_add( y[7], y[15] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[7] ), CL_conjugate( y[15] ) ) ); + move64(); x[3] = CL_add( t[0], t[2] ); + move64(); x[7] = CL_sub( t[1], t[3] ); + move64(); x[11] = CL_sub( t[0], t[2] ); + move64(); x[15] = CL_add( t[1], t[3] ); + move64(); return; } @@ -3966,154 +4997,274 @@ static void fft_len20_fx( cmplx y[20]; xx[0] = CL_shr( x[0], SCALEFACTOR20 ); + move64(); xx[1] = CL_shr( x[16], SCALEFACTOR20 ); + move64(); xx[2] = CL_shr( x[12], SCALEFACTOR20 ); + move64(); xx[3] = CL_shr( x[8], SCALEFACTOR20 ); + move64(); xx[4] = CL_shr( x[4], SCALEFACTOR20 ); + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[0] = CL_add( xx[0], s[0] ); + move64(); s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[4] = CL_msu_j( s[0], s[1] ); + move64(); y[16] = CL_mac_j( s[0], s[1] ); + move64(); y[8] = CL_mac_j( s[2], s[3] ); + move64(); y[12] = CL_msu_j( s[2], s[3] ); + move64(); xx[0] = CL_shr( x[5], SCALEFACTOR20 ); + move64(); xx[1] = CL_shr( x[1], SCALEFACTOR20 ); + move64(); xx[2] = CL_shr( x[17], SCALEFACTOR20 ); + move64(); xx[3] = CL_shr( x[13], SCALEFACTOR20 ); + move64(); xx[4] = CL_shr( x[9], SCALEFACTOR20 ); + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[1] = CL_add( xx[0], s[0] ); + move64(); s[0] = CL_add( y[1], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[5] = CL_msu_j( s[0], s[1] ); + move64(); y[17] = CL_mac_j( s[0], s[1] ); + move64(); y[9] = CL_mac_j( s[2], s[3] ); + move64(); y[13] = CL_msu_j( s[2], s[3] ); + move64(); xx[0] = CL_shr( x[10], SCALEFACTOR20 ); + move64(); xx[1] = CL_shr( x[6], SCALEFACTOR20 ); + move64(); xx[2] = CL_shr( x[2], SCALEFACTOR20 ); + move64(); xx[3] = CL_shr( x[18], SCALEFACTOR20 ); + move64(); xx[4] = CL_shr( x[14], SCALEFACTOR20 ); + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[2] = CL_add( xx[0], s[0] ); + move64(); s[0] = CL_add( y[2], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[6] = CL_msu_j( s[0], s[1] ); + move64(); y[18] = CL_mac_j( s[0], s[1] ); + move64(); y[10] = CL_mac_j( s[2], s[3] ); + move64(); y[14] = CL_msu_j( s[2], s[3] ); + move64(); xx[0] = CL_shr( x[15], SCALEFACTOR20 ); + move64(); xx[1] = CL_shr( x[11], SCALEFACTOR20 ); + move64(); xx[2] = CL_shr( x[7], SCALEFACTOR20 ); + move64(); xx[3] = CL_shr( x[3], SCALEFACTOR20 ); + move64(); xx[4] = CL_shr( x[19], SCALEFACTOR20 ); + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[3] = CL_add( xx[0], s[0] ); + move64(); s[0] = CL_add( y[3], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[7] = CL_msu_j( s[0], s[1] ); + move64(); y[19] = CL_mac_j( s[0], s[1] ); + move64(); y[11] = CL_mac_j( s[2], s[3] ); + move64(); y[15] = CL_msu_j( s[2], s[3] ); + move64(); tt[0] = CL_add( y[0], y[2] ); + move64(); tt[1] = CL_sub( y[0], y[2] ); + move64(); tt[2] = CL_add( y[1], y[3] ); + move64(); tt[3] = CL_swap_real_imag( CL_conjugate( CL_sub( y[1], y[3] ) ) ); + move64(); x[0] = CL_add( tt[0], tt[2] ); + move64(); x[5] = CL_sub( tt[1], tt[3] ); + move64(); x[10] = CL_sub( tt[0], tt[2] ); + move64(); x[15] = CL_add( tt[1], tt[3] ); + move64(); tt[0] = CL_add( y[4], y[6] ); + move64(); tt[1] = CL_sub( y[4], y[6] ); + move64(); tt[2] = CL_add( y[5], y[7] ); + move64(); tt[3] = CL_swap_real_imag( CL_conjugate( CL_sub( y[5], y[7] ) ) ); + move64(); x[4] = CL_add( tt[0], tt[2] ); + move64(); x[9] = CL_sub( tt[1], tt[3] ); + move64(); x[14] = CL_sub( tt[0], tt[2] ); + move64(); x[19] = CL_add( tt[1], tt[3] ); + move64(); tt[0] = CL_add( y[8], y[10] ); + move64(); tt[1] = CL_sub( y[8], y[10] ); + move64(); tt[2] = CL_add( y[9], y[11] ); + move64(); tt[3] = CL_swap_real_imag( CL_conjugate( CL_sub( y[9], y[11] ) ) ); + move64(); x[8] = CL_add( tt[0], tt[2] ); + move64(); x[13] = CL_sub( tt[1], tt[3] ); + move64(); x[18] = CL_sub( tt[0], tt[2] ); + move64(); x[3] = CL_add( tt[1], tt[3] ); + move64(); tt[0] = CL_add( y[12], y[14] ); + move64(); tt[1] = CL_sub( y[12], y[14] ); + move64(); tt[2] = CL_add( y[13], y[15] ); + move64(); tt[3] = CL_swap_real_imag( CL_conjugate( CL_sub( y[13], y[15] ) ) ); + move64(); x[12] = CL_add( tt[0], tt[2] ); + move64(); x[17] = CL_sub( tt[1], tt[3] ); + move64(); x[2] = CL_sub( tt[0], tt[2] ); + move64(); x[7] = CL_add( tt[1], tt[3] ); + move64(); tt[0] = CL_add( y[16], y[18] ); + move64(); tt[1] = CL_sub( y[16], y[18] ); + move64(); tt[2] = CL_add( y[17], y[19] ); + move64(); tt[3] = CL_swap_real_imag( CL_conjugate( CL_sub( y[17], y[19] ) ) ); + move64(); x[16] = CL_add( tt[0], tt[2] ); + move64(); x[1] = CL_sub( tt[1], tt[3] ); + move64(); x[6] = CL_sub( tt[0], tt[2] ); + move64(); x[11] = CL_add( tt[1], tt[3] ); + move64(); return; } @@ -4132,323 +5283,561 @@ static void fft_len30( h = &x[15]; xx[0] = x[0]; + move64(); xx[1] = x[18]; + move64(); xx[2] = x[6]; + move64(); xx[3] = x[24]; + move64(); xx[4] = x[12]; + move64(); xx[5] = x[20]; + move64(); xx[6] = x[8]; + move64(); xx[7] = x[26]; + move64(); xx[8] = x[14]; + move64(); xx[9] = x[2]; + move64(); xx[10] = x[10]; + move64(); xx[11] = x[28]; + move64(); xx[12] = x[16]; + move64(); xx[13] = x[4]; + move64(); xx[14] = x[22]; + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[0] = CL_add( xx[0], s[0] ); s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[1] = CL_msu_j( s[0], s[1] ); + move64(); y[4] = CL_mac_j( s[0], s[1] ); + move64(); y[2] = CL_mac_j( s[2], s[3] ); + move64(); y[3] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( xx[6], xx[9] ); + move64(); s[3] = CL_sub( xx[6], xx[9] ); + move64(); s[2] = CL_add( xx[7], xx[8] ); + move64(); s[1] = CL_sub( xx[7], xx[8] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[5] = CL_add( xx[5], s[0] ); + move64(); s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[6] = CL_msu_j( s[0], s[1] ); + move64(); y[9] = CL_mac_j( s[0], s[1] ); + move64(); y[7] = CL_mac_j( s[2], s[3] ); + move64(); y[8] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( xx[11], xx[14] ); + move64(); s[3] = CL_sub( xx[11], xx[14] ); + move64(); s[2] = CL_add( xx[12], xx[13] ); + move64(); s[1] = CL_sub( xx[12], xx[13] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[10] = CL_add( xx[10], s[0] ); + move64(); s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[11] = CL_msu_j( s[0], s[1] ); + move64(); y[14] = CL_mac_j( s[0], s[1] ); + move64(); y[12] = CL_mac_j( s[2], s[3] ); + move64(); y[13] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( y[5], y[10] ); + move64(); s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + move64(); z[0] = CL_add( y[0], s[0] ); + move64(); s[0] = CL_sub( y[0], CL_shr( s[0], 1 ) ); + move64(); z[10] = CL_mac_j( s[0], s[1] ); + move64(); z[5] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[6], y[11] ); + move64(); s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + move64(); z[6] = CL_add( y[1], s[0] ); + move64(); s[0] = CL_sub( y[1], CL_shr( s[0], 1 ) ); + move64(); z[1] = CL_mac_j( s[0], s[1] ); + move64(); z[11] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[7], y[12] ); + move64(); s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + move64(); z[12] = CL_add( y[2], s[0] ); + move64(); s[0] = CL_sub( y[2], CL_shr( s[0], 1 ) ); + move64(); z[7] = CL_mac_j( s[0], s[1] ); + move64(); z[2] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[8], y[13] ); + move64(); s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + move64(); z[3] = CL_add( y[3], s[0] ); + move64(); s[0] = CL_sub( y[3], CL_shr( s[0], 1 ) ); + move64(); z[13] = CL_mac_j( s[0], s[1] ); + move64(); z[8] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[9], y[14] ); + move64(); s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + move64(); z[9] = CL_add( y[4], s[0] ); + move64(); s[0] = CL_sub( y[4], CL_shr( s[0], 1 ) ); + move64(); z[4] = CL_mac_j( s[0], s[1] ); + move64(); z[14] = CL_msu_j( s[0], s[1] ); + move64(); xx[0] = x[15]; + move64(); xx[1] = x[3]; + move64(); xx[2] = x[21]; + move64(); xx[3] = x[9]; + move64(); xx[4] = x[27]; + move64(); xx[5] = x[5]; + move64(); xx[6] = x[23]; + move64(); xx[7] = x[11]; + move64(); xx[8] = x[29]; + move64(); xx[9] = x[17]; + move64(); xx[10] = x[25]; + move64(); xx[11] = x[13]; + move64(); xx[12] = x[1]; + move64(); xx[13] = x[19]; + move64(); xx[14] = x[7]; + move64(); s[0] = CL_add( xx[1], xx[4] ); + move64(); s[3] = CL_sub( xx[1], xx[4] ); + move64(); s[2] = CL_add( xx[2], xx[3] ); + move64(); s[1] = CL_sub( xx[2], xx[3] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[0] = CL_add( xx[0], s[0] ); + move64(); s[0] = CL_add( y[0], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[1] = CL_msu_j( s[0], s[1] ); + move64(); y[4] = CL_mac_j( s[0], s[1] ); + move64(); y[2] = CL_mac_j( s[2], s[3] ); + move64(); y[3] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( xx[6], xx[9] ); + move64(); s[3] = CL_sub( xx[6], xx[9] ); + move64(); s[2] = CL_add( xx[7], xx[8] ); + move64(); s[1] = CL_sub( xx[7], xx[8] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[5] = CL_add( xx[5], s[0] ); + move64(); s[0] = CL_add( y[5], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[6] = CL_msu_j( s[0], s[1] ); + move64(); y[9] = CL_mac_j( s[0], s[1] ); + move64(); y[7] = CL_mac_j( s[2], s[3] ); + move64(); y[8] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( xx[11], xx[14] ); + move64(); s[3] = CL_sub( xx[11], xx[14] ); + move64(); s[2] = CL_add( xx[12], xx[13] ); + move64(); s[1] = CL_sub( xx[12], xx[13] ); + move64(); t = CL_scale( CL_sub( s[0], s[2] ), FFT_C54 ); s[0] = CL_add( s[0], s[2] ); + move64(); y[10] = CL_add( xx[10], s[0] ); + move64(); s[0] = CL_add( y[10], CL_shl( CL_scale( s[0], FFT_C55 ), 1 ) ); + move64(); s[2] = CL_sub( s[0], t ); + move64(); s[0] = CL_add( s[0], t ); + move64(); t = CL_scale( CL_add( s[3], s[1] ), FFT_C51 ); s[3] = CL_add( t, CL_shl( CL_scale( s[3], FFT_C52 ), 1 ) ); + move64(); s[1] = CL_add( t, CL_scale( s[1], FFT_C53 ) ); + move64(); y[11] = CL_msu_j( s[0], s[1] ); + move64(); y[14] = CL_mac_j( s[0], s[1] ); + move64(); y[12] = CL_mac_j( s[2], s[3] ); + move64(); y[13] = CL_msu_j( s[2], s[3] ); + move64(); s[0] = CL_add( y[5], y[10] ); + move64(); s[1] = CL_scale( CL_sub( y[5], y[10] ), FFT_C31 ); + move64(); z[15] = CL_add( y[0], s[0] ); + move64(); s[0] = CL_sub( y[0], CL_shr( s[0], 1 ) ); + move64(); z[25] = CL_mac_j( s[0], s[1] ); + move64(); z[20] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[6], y[11] ); + move64(); s[1] = CL_scale( CL_sub( y[6], y[11] ), FFT_C31 ); + move64(); z[21] = CL_add( y[1], s[0] ); + move64(); s[0] = CL_sub( y[1], CL_shr( s[0], 1 ) ); + move64(); z[16] = CL_mac_j( s[0], s[1] ); + move64(); z[26] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[7], y[12] ); + move64(); s[1] = CL_scale( CL_sub( y[7], y[12] ), FFT_C31 ); + move64(); z[27] = CL_add( y[2], s[0] ); + move64(); s[0] = CL_sub( y[2], CL_shr( s[0], 1 ) ); + move64(); z[22] = CL_mac_j( s[0], s[1] ); + move64(); z[17] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[8], y[13] ); + move64(); s[1] = CL_scale( CL_sub( y[8], y[13] ), FFT_C31 ); + move64(); z[18] = CL_add( y[3], s[0] ); + move64(); s[0] = CL_sub( y[3], CL_shr( s[0], 1 ) ); + move64(); z[28] = CL_mac_j( s[0], s[1] ); + move64(); z[23] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = CL_add( y[9], y[14] ); + move64(); s[1] = CL_scale( CL_sub( y[9], y[14] ), FFT_C31 ); + move64(); z[24] = CL_add( y[4], s[0] ); + move64(); s[0] = CL_sub( y[4], CL_shr( s[0], 1 ) ); + move64(); z[19] = CL_mac_j( s[0], s[1] ); + move64(); z[29] = CL_msu_j( s[0], s[1] ); + move64(); s[0] = z[0]; + move64(); s[1] = z[15]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[8]; + move64(); s[1] = z[23]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[1]; + move64(); s[1] = z[16]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[9]; + move64(); s[1] = z[24]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[2]; + move64(); s[1] = z[17]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[10]; + move64(); s[1] = z[25]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[3]; + move64(); s[1] = z[18]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[11]; + move64(); s[1] = z[26]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[4]; + move64(); s[1] = z[19]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[12]; + move64(); s[1] = z[27]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[5]; + move64(); s[1] = z[20]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[13]; + move64(); s[1] = z[28]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[6]; + move64(); s[1] = z[21]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[14]; + move64(); s[1] = z[29]; + move64(); *h = CL_add( s[0], s[1] ); + move64(); *l = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; s[0] = z[7]; + move64(); s[1] = z[22]; + move64(); *l = CL_add( s[0], s[1] ); + move64(); *h = CL_sub( s[0], s[1] ); + move64(); l += 1, h += 1; return; @@ -4462,333 +5851,577 @@ static void fft_len32( cmplx ab; xx[0] = x[0]; + move64(); xx[1] = x[4]; + move64(); xx[2] = x[8]; + move64(); xx[3] = x[12]; + move64(); xx[4] = x[16]; + move64(); xx[5] = x[20]; + move64(); xx[6] = x[24]; + move64(); xx[7] = x[28]; + move64(); t[0] = CL_add( xx[0], xx[4] ); + move64(); t[1] = CL_sub( xx[0], xx[4] ); + move64(); t[2] = CL_add( xx[1], xx[5] ); + move64(); t[3] = CL_sub( xx[1], xx[5] ); + move64(); t[4] = CL_add( xx[2], xx[6] ); + move64(); t[5] = CL_sub( xx[2], xx[6] ); + move64(); t[6] = CL_add( xx[3], xx[7] ); + move64(); t[7] = CL_sub( xx[3], xx[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); { s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); + move64(); }; y[0] = CL_add( s[0], s[1] ); + move64(); y[4] = CL_sub( s[0], s[1] ); + move64(); y[2] = CL_sub( s[2], s[3] ); + move64(); y[6] = CL_add( s[2], s[3] ); + move64(); y[3] = CL_add( s[4], s[7] ); + move64(); y[7] = CL_sub( s[4], s[7] ); + move64(); y[1] = CL_add( s[5], s[6] ); + move64(); y[5] = CL_sub( s[5], s[6] ); + move64(); xx[0] = x[1]; + move64(); xx[1] = x[5]; + move64(); xx[2] = x[9]; + move64(); xx[3] = x[13]; + move64(); xx[4] = x[17]; + move64(); xx[5] = x[21]; + move64(); xx[6] = x[25]; + move64(); xx[7] = x[29]; + move64(); t[0] = CL_add( xx[0], xx[4] ); + move64(); t[1] = CL_sub( xx[0], xx[4] ); + move64(); t[2] = CL_add( xx[1], xx[5] ); + move64(); t[3] = CL_sub( xx[1], xx[5] ); + move64(); t[4] = CL_add( xx[2], xx[6] ); + move64(); t[5] = CL_sub( xx[2], xx[6] ); + move64(); t[6] = CL_add( xx[3], xx[7] ); + move64(); t[7] = CL_sub( xx[3], xx[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); { s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); + move64(); }; y[8] = CL_add( s[0], s[1] ); + move64(); y[12] = CL_sub( s[0], s[1] ); + move64(); y[10] = CL_sub( s[2], s[3] ); + move64(); y[14] = CL_add( s[2], s[3] ); + move64(); y[11] = CL_add( s[4], s[7] ); + move64(); y[15] = CL_sub( s[4], s[7] ); + move64(); y[9] = CL_add( s[5], s[6] ); + move64(); y[13] = CL_sub( s[5], s[6] ); + move64(); xx[0] = x[2]; + move64(); xx[1] = x[6]; + move64(); xx[2] = x[10]; + move64(); xx[3] = x[14]; + move64(); xx[4] = x[18]; + move64(); xx[5] = x[22]; + move64(); xx[6] = x[26]; + move64(); xx[7] = x[30]; + move64(); t[0] = CL_add( xx[0], xx[4] ); + move64(); t[1] = CL_sub( xx[0], xx[4] ); + move64(); t[2] = CL_add( xx[1], xx[5] ); + move64(); t[3] = CL_sub( xx[1], xx[5] ); + move64(); t[4] = CL_add( xx[2], xx[6] ); + move64(); t[5] = CL_sub( xx[2], xx[6] ); + move64(); t[6] = CL_add( xx[3], xx[7] ); + move64(); t[7] = CL_sub( xx[3], xx[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); { s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); + move64(); }; y[16] = CL_add( s[0], s[1] ); + move64(); y[20] = CL_sub( s[0], s[1] ); + move64(); y[18] = CL_sub( s[2], s[3] ); + move64(); y[22] = CL_add( s[2], s[3] ); + move64(); y[19] = CL_add( s[4], s[7] ); + move64(); y[23] = CL_sub( s[4], s[7] ); + move64(); y[17] = CL_add( s[5], s[6] ); + move64(); y[21] = CL_sub( s[5], s[6] ); + move64(); xx[0] = x[3]; + move64(); xx[1] = x[7]; + move64(); xx[2] = x[11]; + move64(); xx[3] = x[15]; + move64(); xx[4] = x[19]; + move64(); xx[5] = x[23]; + move64(); xx[6] = x[27]; + move64(); xx[7] = x[31]; + move64(); t[0] = CL_add( xx[0], xx[4] ); + move64(); t[1] = CL_sub( xx[0], xx[4] ); + move64(); t[2] = CL_add( xx[1], xx[5] ); + move64(); t[3] = CL_sub( xx[1], xx[5] ); + move64(); t[4] = CL_add( xx[2], xx[6] ); + move64(); t[5] = CL_sub( xx[2], xx[6] ); + move64(); t[6] = CL_add( xx[3], xx[7] ); + move64(); t[7] = CL_sub( xx[3], xx[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); { s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); + move64(); }; y[24] = CL_add( s[0], s[1] ); + move64(); y[28] = CL_sub( s[0], s[1] ); + move64(); y[26] = CL_sub( s[2], s[3] ); + move64(); y[30] = CL_add( s[2], s[3] ); + move64(); y[27] = CL_add( s[4], s[7] ); + move64(); y[31] = CL_sub( s[4], s[7] ); + move64(); y[25] = CL_add( s[5], s[6] ); + move64(); y[29] = CL_sub( s[5], s[6] ); + move64(); { ab = y[9]; + move64(); y[9] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[0] ), CL_scale( ab, FFT_RotVector_32_fx[1] ) ); + move64(); }; { ab = y[10]; + move64(); y[10] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[2] ), CL_scale( ab, FFT_RotVector_32_fx[3] ) ); + move64(); }; { ab = y[11]; + move64(); y[11] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[4] ), CL_scale( ab, FFT_RotVector_32_fx[5] ) ); + move64(); }; { ab = y[12]; + move64(); y[12] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[6] ), CL_scale( ab, FFT_RotVector_32_fx[7] ) ); + move64(); }; { ab = y[13]; + move64(); y[13] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[8] ), CL_scale( ab, FFT_RotVector_32_fx[9] ) ); + move64(); }; { ab = y[14]; + move64(); y[14] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[10] ), CL_scale( ab, FFT_RotVector_32_fx[11] ) ); + move64(); }; { ab = y[15]; + move64(); y[15] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[12] ), CL_scale( ab, FFT_RotVector_32_fx[13] ) ); + move64(); }; { ab = y[17]; + move64(); y[17] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[14] ), CL_scale( ab, FFT_RotVector_32_fx[15] ) ); + move64(); }; { ab = y[18]; + move64(); y[18] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[16] ), CL_scale( ab, FFT_RotVector_32_fx[17] ) ); + move64(); }; { ab = y[19]; + move64(); y[19] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[18] ), CL_scale( ab, FFT_RotVector_32_fx[19] ) ); + move64(); }; { ab = y[21]; + move64(); y[21] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[20] ), CL_scale( ab, FFT_RotVector_32_fx[21] ) ); + move64(); }; { ab = y[22]; + move64(); y[22] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[22] ), CL_scale( ab, FFT_RotVector_32_fx[23] ) ); + move64(); }; { ab = y[23]; + move64(); y[23] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[24] ), CL_scale( ab, FFT_RotVector_32_fx[25] ) ); + move64(); }; { ab = y[25]; + move64(); y[25] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[26] ), CL_scale( ab, FFT_RotVector_32_fx[27] ) ); + move64(); }; { ab = y[26]; + move64(); y[26] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[28] ), CL_scale( ab, FFT_RotVector_32_fx[29] ) ); + move64(); }; { ab = y[27]; + move64(); y[27] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[30] ), CL_scale( ab, FFT_RotVector_32_fx[31] ) ); + move64(); }; { ab = y[28]; + move64(); y[28] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[32] ), CL_scale( ab, FFT_RotVector_32_fx[33] ) ); + move64(); }; { ab = y[29]; + move64(); y[29] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[34] ), CL_scale( ab, FFT_RotVector_32_fx[35] ) ); + move64(); }; { ab = y[30]; + move64(); y[30] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[36] ), CL_scale( ab, FFT_RotVector_32_fx[37] ) ); + move64(); }; { ab = y[31]; + move64(); y[31] = CL_mac_j( CL_scale( ab, FFT_RotVector_32_fx[38] ), CL_scale( ab, FFT_RotVector_32_fx[39] ) ); + move64(); }; t[0] = CL_add( y[0], y[16] ); + move64(); t[1] = CL_sub( y[0], y[16] ); + move64(); t[2] = CL_add( y[8], y[24] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[8] ), CL_conjugate( y[24] ) ) ); + move64(); x[0] = CL_add( t[0], t[2] ); + move64(); x[8] = CL_sub( t[1], t[3] ); + move64(); x[16] = CL_sub( t[0], t[2] ); + move64(); x[24] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[1], y[17] ); + move64(); t[1] = CL_sub( y[1], y[17] ); + move64(); t[2] = CL_add( y[9], y[25] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[9] ), CL_conjugate( y[25] ) ) ); + move64(); x[1] = CL_add( t[0], t[2] ); + move64(); x[9] = CL_sub( t[1], t[3] ); + move64(); x[17] = CL_sub( t[0], t[2] ); + move64(); x[25] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[2], y[18] ); + move64(); t[1] = CL_sub( y[2], y[18] ); + move64(); t[2] = CL_add( y[10], y[26] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[10] ), CL_conjugate( y[26] ) ) ); + move64(); x[2] = CL_add( t[0], t[2] ); + move64(); x[10] = CL_sub( t[1], t[3] ); + move64(); x[18] = CL_sub( t[0], t[2] ); + move64(); x[26] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[3], y[19] ); + move64(); t[1] = CL_sub( y[3], y[19] ); + move64(); t[2] = CL_add( y[11], y[27] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[11] ), CL_conjugate( y[27] ) ) ); + move64(); x[3] = CL_add( t[0], t[2] ); + move64(); x[11] = CL_sub( t[1], t[3] ); + move64(); x[19] = CL_sub( t[0], t[2] ); + move64(); x[27] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_msu_j( y[4], y[20] ); + move64(); t[1] = CL_mac_j( y[4], y[20] ); + move64(); t[2] = CL_add( y[12], y[28] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[12] ), CL_conjugate( y[28] ) ) ); + move64(); x[4] = CL_add( t[0], t[2] ); + move64(); x[12] = CL_sub( t[1], t[3] ); + move64(); x[20] = CL_sub( t[0], t[2] ); + move64(); x[28] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[5], y[21] ); + move64(); t[1] = CL_sub( y[5], y[21] ); + move64(); t[2] = CL_add( y[13], y[29] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[13] ), CL_conjugate( y[29] ) ) ); + move64(); x[5] = CL_add( t[0], t[2] ); + move64(); x[13] = CL_sub( t[1], t[3] ); + move64(); x[21] = CL_sub( t[0], t[2] ); + move64(); x[29] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[6], y[22] ); + move64(); t[1] = CL_sub( y[6], y[22] ); + move64(); t[2] = CL_add( y[14], y[30] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[14] ), CL_conjugate( y[30] ) ) ); + move64(); x[6] = CL_add( t[0], t[2] ); + move64(); x[14] = CL_sub( t[1], t[3] ); + move64(); x[22] = CL_sub( t[0], t[2] ); + move64(); x[30] = CL_add( t[1], t[3] ); + move64(); t[0] = CL_add( y[7], y[23] ); + move64(); t[1] = CL_sub( y[7], y[23] ); + move64(); t[2] = CL_add( y[15], y[31] ); + move64(); t[3] = CL_swap_real_imag( CL_sub( CL_conjugate( y[15] ), CL_conjugate( y[31] ) ) ); + move64(); x[7] = CL_add( t[0], t[2] ); + move64(); x[15] = CL_sub( t[1], t[3] ); + move64(); x[23] = CL_sub( t[0], t[2] ); + move64(); x[31] = CL_add( t[1], t[3] ); + move64(); return; } @@ -4809,8 +6442,10 @@ static void fft_lenN( { FOR( j = 0; j < dim1; j++ ) { - xx[i * dim1 + j].re = x[i + j * dim2].re; - xx[i * dim1 + j].im = x[i + j * dim2].im; + xx[add( i_mult( i, dim1 ), j )].re = x[add( i, i_mult( j, dim2 ) )].re; + move64(); + xx[add( i_mult( i, dim1 ), j )].im = x[add( i, i_mult( j, dim2 ) )].im; + move64(); } } @@ -4819,56 +6454,56 @@ static void fft_lenN( case 5: FOR( i = 0; i < dim2; i++ ) { - fft_len5( &xx[i * dim1] ); + fft_len5( &xx[i_mult( i, dim1 )] ); } BREAK; case 8: FOR( i = 0; i < dim2; i++ ) { - fft_len8( &xx[i * dim1] ); + fft_len8( &xx[i_mult( i, dim1 )] ); } BREAK; case 10: FOR( i = 0; i < dim2; i++ ) { - fft_len10( &xx[i * dim1] ); + fft_len10( &xx[i_mult( i, dim1 )] ); } BREAK; case 15: FOR( i = 0; i < dim2; i++ ) { - fft_len15( &xx[i * dim1] ); + fft_len15( &xx[i_mult( i, dim1 )] ); } BREAK; case 16: FOR( i = 0; i < dim2; i++ ) { - fft_len16( &xx[i * dim1] ); + fft_len16( &xx[i_mult( i, dim1 )] ); } BREAK; case 20: FOR( i = 0; i < dim2; i++ ) { - fft_len20_fx( &xx[i * dim1] ); + fft_len20_fx( &xx[i_mult( i, dim1 )] ); } BREAK; case 30: FOR( i = 0; i < dim2; i++ ) { - fft_len30( &xx[i * dim1] ); + fft_len30( &xx[i_mult( i, dim1 )] ); } BREAK; case 32: FOR( i = 0; i < dim2; i++ ) { - fft_len32( &xx[i * dim1] ); + fft_len32( &xx[i_mult( i, dim1 )] ); } BREAK; } @@ -4882,100 +6517,145 @@ static void fft_lenN( cmplx s[8]; cmplx y[8]; + test(); + test(); + test(); + test(); IF( EQ_16( dim1, 30 ) || EQ_16( dim1, 20 ) || EQ_16( dim1, 15 ) || EQ_16( dim1, 10 ) || EQ_16( dim1, 5 ) ) { FOR( i = 0; i < dim1; i++ ) { { - y[0] = xx[i + 0 * dim1]; + y[0] = xx[i]; // y[0] = xx[i + 0 * dim1] }; - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { { - y[1] = xx[i + 1 * dim1]; + y[1] = xx[add( i, i_mult( 1, dim1 ) )]; + move64(); }; { - y[2] = xx[i + 2 * dim1]; + y[2] = xx[add( i, i_mult( 2, dim1 ) )]; + move64(); }; { - y[3] = xx[i + 3 * dim1]; + y[3] = xx[add( i, i_mult( 3, dim1 ) )]; + move64(); }; { - y[4] = xx[i + 4 * dim1]; + y[4] = xx[add( i, i_mult( 4, dim1 ) )]; + move64(); }; { - y[5] = xx[i + 5 * dim1]; + y[5] = xx[add( i, i_mult( 5, dim1 ) )]; + move64(); }; { - y[6] = xx[i + 6 * dim1]; + y[6] = xx[add( i, i_mult( 6, dim1 ) )]; + move64(); }; { - y[7] = xx[i + 7 * dim1]; + y[7] = xx[add( i, i_mult( 7, dim1 ) )]; + move64(); }; } ELSE { { - y[1] = CL_mac_j( CL_scale( xx[i + 1 * dim1], W[sc * i + sc * 1 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 1 * dim1], W[sc * i + sc * 1 * dim1 * 2 + 1 - Woff] ) ); + y[1] = CL_mac_j( CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 1 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 1 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[2] = CL_mac_j( CL_scale( xx[i + 2 * dim1], W[sc * i + sc * 2 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 2 * dim1], W[sc * i + sc * 2 * dim1 * 2 + 1 - Woff] ) ); + y[2] = CL_mac_j( CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 2 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 2 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[3] = CL_mac_j( CL_scale( xx[i + 3 * dim1], W[sc * i + sc * 3 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 3 * dim1], W[sc * i + sc * 3 * dim1 * 2 + 1 - Woff] ) ); + y[3] = CL_mac_j( CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 3 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 3 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[4] = CL_mac_j( CL_scale( xx[i + 4 * dim1], W[sc * i + sc * 4 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 4 * dim1], W[sc * i + sc * 4 * dim1 * 2 + 1 - Woff] ) ); + y[4] = CL_mac_j( CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 4 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 4 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[5] = CL_mac_j( CL_scale( xx[i + 5 * dim1], W[sc * i + sc * 5 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 5 * dim1], W[sc * i + sc * 5 * dim1 * 2 + 1 - Woff] ) ); + y[5] = CL_mac_j( CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 5 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 5 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[6] = CL_mac_j( CL_scale( xx[i + 6 * dim1], W[sc * i + sc * 6 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 6 * dim1], W[sc * i + sc * 6 * dim1 * 2 + 1 - Woff] ) ); + y[6] = CL_mac_j( CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 6 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 6 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[7] = CL_mac_j( CL_scale( xx[i + 7 * dim1], W[sc * i + sc * 7 * dim1 * 2 - Woff] ), - CL_scale( xx[i + 7 * dim1], W[sc * i + sc * 7 * dim1 * 2 + 1 - Woff] ) ); + y[7] = CL_mac_j( CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 7 ), dim1 ), 1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( add( i_mult( sc, i ), shl( i_mult( i_mult( sc, 7 ), dim1 ), 1 ) ), 1 ), Woff )] ) ); + move64(); }; } t[0] = CL_add( y[0], y[4] ); + move64(); t[1] = CL_sub( y[0], y[4] ); + move64(); t[2] = CL_add( y[1], y[5] ); + move64(); t[3] = CL_sub( y[1], y[5] ); + move64(); t[4] = CL_add( y[2], y[6] ); + move64(); t[5] = CL_sub( y[2], y[6] ); + move64(); t[6] = CL_add( y[3], y[7] ); + move64(); t[7] = CL_sub( y[3], y[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); - - x[i + 0 * dim1] = CL_add( s[0], s[1] ); - x[i + 1 * dim1] = CL_add( s[5], s[6] ); - x[i + 2 * dim1] = CL_sub( s[2], s[3] ); - x[i + 3 * dim1] = CL_add( s[4], s[7] ); - x[i + 4 * dim1] = CL_sub( s[0], s[1] ); - x[i + 5 * dim1] = CL_sub( s[5], s[6] ); - x[i + 6 * dim1] = CL_add( s[2], s[3] ); - x[i + 7 * dim1] = CL_sub( s[4], s[7] ); + move64(); + + x[i] = CL_add( s[0], s[1] ); /*x[add(i + i_mult(0 , dim1)] = CL_add( s[0], s[1] )*/ + move64(); + x[add( i, i_mult( 1, dim1 ) )] = CL_add( s[5], s[6] ); + move64(); + x[add( i, i_mult( 2, dim1 ) )] = CL_sub( s[2], s[3] ); + move64(); + x[add( i, i_mult( 3, dim1 ) )] = CL_add( s[4], s[7] ); + move64(); + x[add( i, i_mult( 4, dim1 ) )] = CL_sub( s[0], s[1] ); + move64(); + x[add( i, i_mult( 5, dim1 ) )] = CL_sub( s[5], s[6] ); + move64(); + x[add( i, i_mult( 6, dim1 ) )] = CL_add( s[2], s[3] ); + move64(); + x[add( i, i_mult( 7, dim1 ) )] = CL_sub( s[4], s[7] ); + move64(); } } ELSE @@ -4983,95 +6663,137 @@ static void fft_lenN( FOR( i = 0; i < dim1; i++ ) { { - y[0] = xx[i + 0 * dim1]; + y[0] = xx[i]; /* y[0] = xx[i + 0 * dim1] */ + move64(); }; - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { { - y[1] = xx[i + 1 * dim1]; + y[1] = xx[add( i, i_mult( 1, dim1 ) )]; + move64(); }; { - y[2] = xx[i + 2 * dim1]; + y[2] = xx[add( i, i_mult( 2, dim1 ) )]; + move64(); }; { - y[3] = xx[i + 3 * dim1]; + y[3] = xx[add( i, i_mult( 3, dim1 ) )]; + move64(); }; { - y[4] = xx[i + 4 * dim1]; + y[4] = xx[add( i, i_mult( 4, dim1 ) )]; + move64(); }; { - y[5] = xx[i + 5 * dim1]; + y[5] = xx[add( i, i_mult( 5, dim1 ) )]; + move64(); }; { - y[6] = xx[i + 6 * dim1]; + y[6] = xx[add( i, i_mult( 6, dim1 ) )]; + move64(); }; { - y[7] = xx[i + 7 * dim1]; + y[7] = xx[add( i, i_mult( 7, dim1 ) )]; + move64(); }; } ELSE { { - y[1] = CL_mac_j( CL_scale( xx[i + 1 * dim1], W[sc * i + sc * 1 * dim1 - Woff] ), - CL_scale( xx[i + 1 * dim1], W[sc * i + sc * 1 * dim1 + 1 - Woff] ) ); + y[1] = CL_mac_j( CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 1 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 1, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 1 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[2] = CL_mac_j( CL_scale( xx[i + 2 * dim1], W[sc * i + sc * 2 * dim1 - Woff] ), - CL_scale( xx[i + 2 * dim1], W[sc * i + sc * 2 * dim1 + 1 - Woff] ) ); + y[2] = CL_mac_j( CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 2 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 2, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 2 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[3] = CL_mac_j( CL_scale( xx[i + 3 * dim1], W[sc * i + sc * 3 * dim1 - Woff] ), - CL_scale( xx[i + 3 * dim1], W[sc * i + sc * 3 * dim1 + 1 - Woff] ) ); + y[3] = CL_mac_j( CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 3 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 3, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 3 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[4] = CL_mac_j( CL_scale( xx[i + 4 * dim1], W[sc * i + sc * 4 * dim1 - Woff] ), - CL_scale( xx[i + 4 * dim1], W[sc * i + sc * 4 * dim1 + 1 - Woff] ) ); + y[4] = CL_mac_j( CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 4 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 4, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 4 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[5] = CL_mac_j( CL_scale( xx[i + 5 * dim1], W[sc * i + sc * 5 * dim1 - Woff] ), - CL_scale( xx[i + 5 * dim1], W[sc * i + sc * 5 * dim1 + 1 - Woff] ) ); + y[5] = CL_mac_j( CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 5 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 5, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 5 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[6] = CL_mac_j( CL_scale( xx[i + 6 * dim1], W[sc * i + sc * 6 * dim1 - Woff] ), - CL_scale( xx[i + 6 * dim1], W[sc * i + sc * 6 * dim1 + 1 - Woff] ) ); + y[6] = CL_mac_j( CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 6 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 6, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 6 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; { - y[7] = CL_mac_j( CL_scale( xx[i + 7 * dim1], W[sc * i + sc * 7 * dim1 - Woff] ), - CL_scale( xx[i + 7 * dim1], W[sc * i + sc * 7 * dim1 + 1 - Woff] ) ); + y[7] = CL_mac_j( CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, 7 ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( 7, dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, 7 ), dim1 ) ), 1 ), Woff )] ) ); + move64(); }; } t[0] = CL_add( y[0], y[4] ); + move64(); t[1] = CL_sub( y[0], y[4] ); + move64(); t[2] = CL_add( y[1], y[5] ); + move64(); t[3] = CL_sub( y[1], y[5] ); + move64(); t[4] = CL_add( y[2], y[6] ); + move64(); t[5] = CL_sub( y[2], y[6] ); + move64(); t[6] = CL_add( y[3], y[7] ); + move64(); t[7] = CL_sub( y[3], y[7] ); + move64(); s[0] = CL_add( t[0], t[4] ); + move64(); s[2] = CL_sub( t[0], t[4] ); + move64(); s[4] = CL_mac_j( t[1], t[5] ); + move64(); s[5] = CL_msu_j( t[1], t[5] ); + move64(); s[1] = CL_add( t[2], t[6] ); + move64(); s[3] = CL_swap_real_imag( CL_sub( CL_conjugate( t[2] ), CL_conjugate( t[6] ) ) ); + move64(); t[0] = CL_swap_real_imag( CL_add( t[3], t[7] ) ); + move64(); t[1] = CL_sub( t[3], t[7] ); + move64(); s[6] = CL_scale( CL_add( CL_conjugate( t[0] ), t[1] ), FFT_C81 ); + move64(); s[7] = CL_scale( CL_sub( t[0], CL_conjugate( t[1] ) ), FFT_C81 ); + move64(); s[7] = CL_conjugate( s[7] ); - - x[i + 0 * dim1] = CL_add( s[0], s[1] ); - x[i + 1 * dim1] = CL_add( s[5], s[6] ); - x[i + 2 * dim1] = CL_sub( s[2], s[3] ); - x[i + 3 * dim1] = CL_add( s[4], s[7] ); - x[i + 4 * dim1] = CL_sub( s[0], s[1] ); - x[i + 5 * dim1] = CL_sub( s[5], s[6] ); - x[i + 6 * dim1] = CL_add( s[2], s[3] ); - x[i + 7 * dim1] = CL_sub( s[4], s[7] ); + move64(); + + x[i] = CL_add( s[0], s[1] ); /*x[i + 0 * dim1] = CL_add( s[0], s[1] )*/ + move64(); + x[add( i, i_mult( 1, dim1 ) )] = CL_add( s[5], s[6] ); + move64(); + x[add( i, i_mult( 2, dim1 ) )] = CL_sub( s[2], s[3] ); + move64(); + x[add( i, i_mult( 3, dim1 ) )] = CL_add( s[4], s[7] ); + move64(); + x[add( i, i_mult( 4, dim1 ) )] = CL_sub( s[0], s[1] ); + move64(); + x[add( i, i_mult( 5, dim1 ) )] = CL_sub( s[5], s[6] ); + move64(); + x[add( i, i_mult( 6, dim1 ) )] = CL_add( s[2], s[3] ); + move64(); + x[add( i, i_mult( 7, dim1 ) )] = CL_sub( s[4], s[7] ); + move64(); } } BREAK; @@ -5083,32 +6805,35 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + j * dim1]; + y[j] = xx[0 + i_mult( j, dim1 )]; /*y[j] = xx[0 + j * dim1];*/ }; } fft_len10( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + j * dim1] = y[j]; + x[0 + i_mult( j, dim1 )] = y[j]; + move64(); } FOR( i = 1; i < dim1; i++ ) { { y[( 0 + 0 )] = xx[i + ( 0 + 0 ) * dim1]; + move64(); } FOR( j = 1; j < dim2; j++ ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + sc * j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + sc * j * dim1 + 1 - Woff] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), 1 ), Woff )] ) ); + move64(); } } fft_len10( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[i + j * dim1] = y[j]; + x[add( i, i_mult( j, dim1 ) )] = y[j]; } } BREAK; @@ -5120,14 +6845,15 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + j * dim1]; + y[j] = xx[0 + i_mult( j, dim1 )]; + move64(); }; } fft_len16( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + j * dim1] = y[j]; + x[0 + i_mult( j, dim1 )] = y[j]; } FOR( i = 1; i < dim1; i++ ) @@ -5139,14 +6865,16 @@ static void fft_lenN( FOR( j = 1; j < dim2; j++ ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + sc * j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + sc * j * dim1 + 1 - Woff] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( i_mult( sc, j ), dim1 ) ), 1 ), Woff )] ) ); + move64(); } } fft_len16( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[i + j * dim1] = y[j]; + x[add( i, i_mult( j, dim1 ) )] = y[j]; + move64(); } } BREAK; @@ -5158,40 +6886,47 @@ static void fft_lenN( FOR( j = 0; j < dim2; j++ ) { { - y[j] = xx[0 + j * dim1]; + y[j] = xx[0 + i_mult( j, dim1 )]; + move64(); }; } fft_len20_fx( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[0 + j * dim1] = y[j]; + x[0 + i_mult( j, dim1 )] = y[j]; + move64(); } FOR( i = 1; i < dim1; i++ ) { { - y[( 0 + 0 )] = xx[i + ( 0 + 0 ) * dim1]; + y[( 0 + 0 )] = xx[add( i, ( 0 + 0 ) * dim1 )]; + move64(); } { - y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[i + ( 0 + 1 ) * dim1], W[len + sc * i + 0 * dim1 - Woff] ), - CL_scale( xx[i + ( 0 + 1 ) * dim1], W[len + sc * i + 0 * dim1 + 1 - Woff] ) ); + y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( len, i_mult( sc, i ) ) + 0 * dim1, Woff )] ), + CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ) + 0 * dim1, 1 ), Woff )] ) ); + move64(); } FOR( j = 2; j < dim2; j = j + 2 ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + j * dim1 + 1 - Woff] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( j, dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + move64(); } { - y[( j + 1 )] = CL_mac_j( CL_scale( xx[i + ( j + 1 ) * dim1], W[len + sc * i + j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 1 ) * dim1], W[len + sc * i + j * dim1 + 1 - Woff] ) ); + y[( j + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + move64(); } } fft_len20_fx( &y[0] ); FOR( j = 0; j < dim2; j++ ) { x[i + j * dim1] = y[j]; + move64(); } } BREAK; @@ -5204,39 +6939,46 @@ static void fft_lenN( { { y[j] = xx[0 + j * dim1]; + move64(); }; } fft_len32( &y[0] ); FOR( j = 0; j < dim2; j++ ) { x[0 + j * dim1] = y[j]; + move64(); } FOR( i = 1; i < dim1; i++ ) { { y[( 0 + 0 )] = xx[i + ( 0 + 0 ) * dim1]; + move64(); } { - y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[i + ( 0 + 1 ) * dim1], W[len + sc * i + 0 * dim1 - Woff] ), - CL_scale( xx[i + ( 0 + 1 ) * dim1], W[len + sc * i + 0 * dim1 + 1 - Woff] ) ); + y[( 0 + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( len, i_mult( sc, i ) ) + 0 * dim1, Woff )] ), + CL_scale( xx[add( i, i_mult( ( 0 + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ) + 0 * dim1, 1 ), Woff )] ) ); + move64(); } FOR( j = 2; j < dim2; j = j + 2 ) { { - y[( j + 0 )] = CL_mac_j( CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 0 ) * dim1], W[sc * i + j * dim1 + 1 - Woff] ) ); + y[( j + 0 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( i_mult( sc, i ), i_mult( j, dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 0 ), dim1 ) )], W[sub( add( add( i_mult( sc, i ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + move64(); } { - y[( j + 1 )] = CL_mac_j( CL_scale( xx[i + ( j + 1 ) * dim1], W[len + sc * i + j * dim1 - Woff] ), - CL_scale( xx[i + ( j + 1 ) * dim1], W[len + sc * i + j * dim1 + 1 - Woff] ) ); + y[( j + 1 )] = CL_mac_j( CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), Woff )] ), + CL_scale( xx[add( i, i_mult( ( j + 1 ), dim1 ) )], W[sub( add( add( add( len, i_mult( sc, i ) ), i_mult( j, dim1 ) ), 1 ), Woff )] ) ); + move64(); } } fft_len32( &y[0] ); FOR( j = 0; j < dim2; j++ ) { - x[i + j * dim1] = y[j]; + x[add( i, i_mult( j, dim1 ) )] = y[j]; + move64(); } } BREAK; @@ -5260,10 +7002,12 @@ void fft_fx( { cmplx x[960]; - FOR( Word32 j = 0; j < length; j++ ) + FOR( Word16 j = 0; j < length; j++ ) { - x[j].re = re[s * j]; - x[j].im = im[s * j]; + x[j].re = re[i_mult( s, j )]; + move32(); + x[j].im = im[i_mult( s, j )]; + move32(); } SWITCH( length ) @@ -5323,10 +7067,12 @@ void fft_fx( assert( !"fft length is not supported!" ); } - FOR( Word32 j = 0; j < length; j++ ) + FOR( Word16 j = 0; j < length; j++ ) { - re[s * j] = x[j].re; - im[s * j] = x[j].im; + re[i_mult( s, j )] = x[j].re; + move32(); + im[i_mult( s, j )] = x[j].im; + move32(); } return; @@ -5343,33 +7089,63 @@ void rfft_fx( Word32 tmp, t1, t2, t3, t4; Word16 s1, s2; - sizeOfFft2 = length >> 1; - sizeOfFft4 = length >> 2; + sizeOfFft2 = shr( length, 1 ); + sizeOfFft4 = shr( length, 2 ); SWITCH( sizeOfFft2 ) { case 80: s1 = 409; + move16(); s2 = -409; + move16(); BREAK; case 128: s1 = 256; + move16(); s2 = -256; + move16(); BREAK; case 160: s1 = 204; + move16(); s2 = -204; + move16(); + BREAK; + case 256: + s1 = 128; + move16(); + s2 = -128; + move16(); BREAK; case 320: s1 = 102; + move16(); s2 = -102; + move16(); BREAK; case 480: s1 = 68; + move16(); s2 = -68; + move16(); + BREAK; + case 640: + s1 = 51; + move16(); + s2 = -51; + move16(); + BREAK; + case 960: + s1 = 34; + move16(); + s2 = -34; + move16(); BREAK; default: s1 = -1; + move16(); s2 = -1; + move16(); printf( "Configuration not supported" ); assert( 0 ); } @@ -5383,21 +7159,27 @@ void rfft_fx( tmp = L_add( x[0], x[1] ); x[1] = L_sub( x[0], x[1] ); + move32(); x[0] = tmp; + move32(); FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub( x[2 * i], x[length - 2 * i] ); - t2 = L_add( x[2 * i + 1], x[length - 2 * i + 1] ); + t1 = L_sub( x[2 * i], x[sub( length, shl( i, 1 ) )] ); + t2 = L_add( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); t3 = L_sub( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); t4 = L_add( Mpy_32_16_1( t1, w[i + sizeOfFft4] ), Mpy_32_16_1( t2, w[i] ) ); - t1 = L_add( x[2 * i], x[length - 2 * i] ); - t2 = L_sub( x[2 * i + 1], x[length - 2 * i + 1] ); + t1 = L_add( x[2 * i], x[sub( length, shl( i, 1 ) )] ); + t2 = L_sub( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); - x[2 * i + 1] = Mpy_32_16_1( L_sub( t2, t4 ), 16384 ); - x[length - 2 * i] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); - x[length - 2 * i + 1] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 ); + move32(); + x[add( shl( i, 1 ), 1 )] = Mpy_32_16_1( L_sub( t2, t4 ), 16384 ); + move32(); + x[sub( length, shl( i, 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + move32(); + x[add( sub( length, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_negate( L_add( t2, t4 ) ), 16384 ); + move32(); } BREAK; @@ -5406,21 +7188,27 @@ void rfft_fx( tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384 ); x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384 ); + move32(); x[0] = tmp; + move32(); FOR( i = 1; i <= sizeOfFft4; i++ ) { - t1 = L_sub( x[2 * i], x[length - 2 * i] ); - t2 = L_add( x[2 * i + 1], x[length - 2 * i + 1] ); - t3 = L_add( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[i + sizeOfFft4] ) ); - t4 = L_sub( Mpy_32_16_1( t2, w[i] ), Mpy_32_16_1( t1, w[i + sizeOfFft4] ) ); - t1 = L_add( x[2 * i], x[length - 2 * i] ); - t2 = L_sub( x[2 * i + 1], x[length - 2 * i + 1] ); + t1 = L_sub( x[2 * i], x[sub( length, shl( i, 1 ) )] ); + t2 = L_add( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); + t3 = L_add( Mpy_32_16_1( t1, w[i] ), Mpy_32_16_1( t2, w[add( i, sizeOfFft4 )] ) ); + t4 = L_sub( Mpy_32_16_1( t2, w[i] ), Mpy_32_16_1( t1, w[add( i, sizeOfFft4 )] ) ); + t1 = L_add( x[2 * i], x[sub( length, shl( i, 1 ) )] ); + t2 = L_sub( x[add( shl( i, 1 ), 1 )], x[add( sub( length, shl( i, 1 ) ), 1 )] ); x[2 * i] = Mpy_32_16_1( L_sub( t1, t3 ), 16384 ); - x[2 * i + 1] = Mpy_32_16_1( L_sub( t4, t2 ), 16384 ); - x[length - 2 * i] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); - x[length - 2 * i + 1] = Mpy_32_16_1( L_add( t2, t4 ), 16384 ); + move32(); + x[add( shl( i, 1 ), 1 )] = Mpy_32_16_1( L_sub( t4, t2 ), 16384 ); + move32(); + x[sub( length, shl( i, 1 ) )] = Mpy_32_16_1( L_add( t1, t3 ), 16384 ); + move32(); + x[add( sub( length, shl( i, 1 ) ), 1 )] = Mpy_32_16_1( L_add( t2, t4 ), 16384 ); + move32(); } fft_fx( x, x + 1, sizeOfFft2, 2 ); @@ -5428,7 +7216,9 @@ void rfft_fx( FOR( i = 0; i < length; i += 2 ) { x[i] = Mpy_32_16_1( x[i], s1 ); + move32(); x[i + 1] = Mpy_32_16_1( x[i + 1], s2 ); + move32(); } BREAK; @@ -5439,28 +7229,45 @@ void rfft_fx( Word16 find_guarded_bits_fx( Word32 n ) { - return n <= 1 ? 0 : n <= 2 ? 1 - : n <= 4 ? 2 - : n <= 8 ? 3 - : n <= 16 ? 4 - : n <= 32 ? 5 - : n <= 64 ? 6 - : n <= 128 ? 7 - : n <= 256 ? 8 - : n <= 512 ? 9 - : n <= 1024 ? 10 - : n <= 2048 ? 11 - : n <= 4096 ? 12 - : n <= 8192 ? 13 - : n <= 16384 ? 14 - : 15; + // return n <= 1 ? 0 : n <= 2 ? 1 + // : n <= 4 ? 2 + // : n <= 8 ? 3 + // : n <= 16 ? 4 + // : n <= 32 ? 5 + // : n <= 64 ? 6 + // : n <= 128 ? 7 + // : n <= 256 ? 8 + // : n <= 512 ? 9 + // : n <= 1024 ? 10 + // : n <= 2048 ? 11 + // : n <= 4096 ? 12 + // : n <= 8192 ? 13 + // : n <= 16384 ? 14 + // : 15; + /*Word16 val = 0; + move32(); + test(); + WHILE( GT_32( n, L_shl( 1, val ) ) && LT_32( val, 16 ) ) + { + val = add( val, 1 ); + }*/ + IF( LE_32( n, 1 ) ) + { + return 0; + } + ELSE + { + + return sub( 31, norm_l( L_sub( n, 1 ) ) ); + } } Word16 L_norm_arr( Word32 *arr, Word16 size ) { Word16 q = 31; - FOR( int i = 0; i < size; i++ ) - if ( arr[i] != 0 ) + move16(); + FOR( Word16 i = 0; i < size; i++ ) + IF( arr[i] != 0 ) { q = s_min( q, norm_l( arr[i] ) ); } @@ -5470,15 +7277,17 @@ Word16 L_norm_arr( Word32 *arr, Word16 size ) Word16 get_min_scalefactor( Word32 x, Word32 y ) { Word16 scf = Q31; - IF( EQ_32( x, 0 ) && EQ_32( y, 0 ) ) + move16(); + test(); + IF( x == 0 && y == 0 ) { return 0; } - IF( NE_32( x, 0 ) ) + IF( x != 0 ) { scf = s_min( scf, norm_l( x ) ); } - IF( NE_32( y, 0 ) ) + IF( y != 0 ) { scf = s_min( scf, norm_l( y ) ); } @@ -5487,8 +7296,8 @@ Word16 get_min_scalefactor( Word32 x, Word32 y ) Flag is_zero_arr( Word32 *arr, Word16 size ) { - FOR( int i = 0; i < size; i++ ) - if ( arr[i] != 0 ) + FOR( Word16 i = 0; i < size; i++ ) + IF( arr[i] != 0 ) { return 0; } diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index b36bac55fd931ea25aba39c6fbd2e1e9b43cb2a3..c17de364316b9a4093286ce66ae45358534f4300 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "stl.h" #include @@ -808,10 +807,8 @@ static void cftbsub_fx( move32(); a[j1] = x0r; move32(); - move32(); a[j1 + 1] = x0i; move32(); - move32(); } } } @@ -842,7 +839,7 @@ static void rftfsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( 8192, c[nc - kk] ); + wkr = sub( 8192, c[sub( nc, kk )] ); wki = c[kk]; move16(); xr = L_sub( a[j], a[k] ); @@ -888,7 +885,7 @@ static void rftbsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( 8192, c[nc - kk] ); + wkr = sub( 8192, c[sub( nc, kk )] ); wki = c[kk]; move16(); xr = L_sub( a[j], a[k] ); @@ -936,8 +933,8 @@ static void dctsub_fx( { k = sub( n, j ); kk = add( kk, ks ); - wkr = sub( c[kk], c[nc - kk] ); - wki = add( c[kk], c[nc - kk] ); + wkr = sub( c[kk], c[sub( nc, kk )] ); + wki = add( c[kk], c[sub( nc, kk )] ); xr = L_sub( Mult_32_16( L_shl( a[j], 1 ), wki ), Mult_32_16( L_shl( a[k], 1 ), wkr ) ); a[j] = L_add( Mult_32_16( L_shl( a[j], 1 ), wkr ), Mult_32_16( L_shl( a[k], 1 ), wki ) ); move32(); @@ -945,6 +942,7 @@ static void dctsub_fx( move32(); } a[m] = Mult_32_16( L_shl( a[m], 1 ), c[0] ); + move16(); } /*-----------------------------------------------------------------* @@ -967,7 +965,9 @@ void edct2_fx( Word32 xr; *q = Exp16Array( n, in ); + move16(); *q = add( *q, 6 ); + move16(); FOR( j = 0; j < n; j++ ) { a[j] = L_shl( (Word32) in[j], *q ); @@ -1264,6 +1264,7 @@ static void fft5_32_16fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif i0 = Idx[0]; move16(); @@ -1509,7 +1510,6 @@ static void fft32_5_16fx( Word16 i, id, jd; Word16 z[64]; - move16(); /*penalty for 1 ptr init */ FOR( i = 0; i < 32; i++ ) { id = Idx[i]; @@ -1522,7 +1522,6 @@ static void fft32_5_16fx( cdftForw_16fx( 64, z, Ip_fft32, w_fft32_16fx ); - move16(); /*penalty for 1 ptr init */ FOR( i = 0; i < 32; i++ ) { jd = Odx_fft32_5[i]; @@ -1604,7 +1603,6 @@ void DoRTFT128_16fx( Word16 i; Word16 z[256]; - move16(); /*penalty for 1 ptr init */ FOR( i = 0; i < 128; i++ ) { z[2 * i] = x[i]; @@ -1619,8 +1617,6 @@ void DoRTFT128_16fx( move16(); y[0] = z[1]; move16(); - move16(); /*penalty for 1 ptr init */ - move16(); /*penalty for 1 ptr init */ FOR( i = 1; i < 128; i++ ) { x[128 - i] = z[2 * i]; @@ -1840,6 +1836,7 @@ static void cftfsub_16fx( Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif l = 2; @@ -1940,6 +1937,7 @@ static void cft1st_16fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif #ifdef BASOP_NOGLOB @@ -2042,20 +2040,24 @@ static void cft1st_16fx( #ifdef BASOP_NOGLOB a[10] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = add_o( x0r, x0i, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[11] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ + move16(); x0r = add_o( x3i, x1r, &Overflow ); x0i = sub_o( x3r, x1i, &Overflow ); tmp = sub_o( x0i, x0r, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[14] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = add_o( x0i, x0r, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[15] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else a[10] = round_fx( L_shl( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ @@ -2114,30 +2116,36 @@ static void cft1st_16fx( L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 4] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 5] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = sub_o( x1r, x3i, &Overflow ); x0i = add_o( x1i, x3r, &Overflow ); L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = add_o( x1r, x3i, &Overflow ); x0i = sub_o( x1i, x3r, &Overflow ); L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 6] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 7] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); wk1r = w[k2 + 2]; move32(); @@ -2168,21 +2176,25 @@ static void cft1st_16fx( L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 12] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = negate( x0i ); L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 13] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = sub_o( x1r, x3i, &Overflow ); x0i = add_o( x1i, x3r, &Overflow ); L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 10] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 11] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = add_o( x1r, x3i, &Overflow ); x0i = sub_o( x1i, x3r, &Overflow ); @@ -2190,10 +2202,12 @@ static void cft1st_16fx( L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ a[j + 14] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 15] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else x0r = add( a[j], a[j + 2] ); x0i = add( a[j + 1], a[j + 3] ); @@ -2318,9 +2332,9 @@ static void cftmdl_16fx( Word32 L_x0r, L_x0i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif m = shl( l, 2 ); - move16(); FOR( j = 0; j < l; j += 2 ) { #ifdef BASOP_NOGLOB @@ -2413,20 +2427,24 @@ static void cftmdl_16fx( tmp = sub_o( x0r, x0i, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = add_o( x0r, x0i, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = add_o( x3i, x1r, &Overflow ); x0i = sub_o( x3r, x1i, &Overflow ); tmp = sub_o( x0i, x0r, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = add_o( x0i, x0r, &Overflow ); L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else j1 = add( j, l ); j2 = add( j1, l ); @@ -2517,10 +2535,12 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ a[j2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ a[j2 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = sub_o( x1r, x3i, &Overflow ); x0i = add_o( x1i, x3r, &Overflow ); @@ -2528,10 +2548,12 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_x0r = L_add( (Word32) x1r, (Word32) x3i ); L_x0i = L_sub( (Word32) x1i, (Word32) x3r ); @@ -2540,10 +2562,12 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else j1 = add( j, l ); j2 = add( j1, l ); @@ -2641,11 +2665,13 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ a[j2] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); tmp = negate( x0i ); L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ a[j2 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = sub_o( x1r, x3i, &Overflow ); x0i = add_o( x1i, x3r, &Overflow ); @@ -2653,10 +2679,12 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ a[j1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ a[j1 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); x0r = add_o( x1r, x3i, &Overflow ); x0i = sub_o( x1i, x3r, &Overflow ); @@ -2664,10 +2692,12 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ a[j3] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ + move16(); #else j1 = add( j, l ); j2 = add( j1, l ); @@ -2843,6 +2873,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). */ + move16(); acc = L_shl( *IZ0--, 15 ); acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); @@ -2850,6 +2881,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = add( c1_ind, c1_step ); s1_ind = add( s1_ind, s1_step ); @@ -2867,6 +2899,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_shl( *IZ0--, 15 ); acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); @@ -2874,6 +2907,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = add( c1_ind, c1_step ); s1_ind = add( s1_ind, s1_step ); @@ -2886,11 +2920,14 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = 0; + move32(); acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); *IY-- = round_fx( acc ); + move16(); IZ0++; IZ1++; IZ2++; @@ -2910,6 +2947,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0++, -32768 ); acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); @@ -2917,6 +2955,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = add( c1_ind, c1_step ); s1_ind = add( s1_ind, s1_step ); @@ -2935,6 +2974,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0++, -32768 ); acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); @@ -2942,6 +2982,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = sub( c1_ind, c1_step ); s1_ind = sub( s1_ind, s1_step ); @@ -2954,11 +2995,13 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_deposit_l( 0 ); acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); *IY-- = round_fx( acc ); + move16(); IZ0--; /* Just decrement the address counter */ IZ1--; IZ2--; @@ -2978,6 +3021,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_shl( *IZ0--, 15 ); acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); @@ -2985,6 +3029,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = sub( c1_ind, c1_step ); s1_ind = sub( s1_ind, s1_step ); @@ -3002,6 +3047,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY++ = round_fx( acc ); + move16(); acc = L_shl( *IZ0--, 15 ); acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); @@ -3009,6 +3055,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); *IY-- = round_fx( acc ); + move16(); c1_ind = sub( c1_ind, c1_step ); s1_ind = sub( s1_ind, s1_step ); @@ -3021,6 +3068,7 @@ void fft3_fx( const Word16 X[], Word16 Y[], const Word16 n ) acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); *RY = round_fx( acc ); + move16(); return; } @@ -3151,6 +3199,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *IZ1--, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2++, t_sin[s2_ind] ); *RY1++ = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step ); s0_ind = add( s0_ind, step ); @@ -3170,6 +3219,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY1++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0--, t_sin[c0_ind] ); acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); @@ -3178,6 +3228,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); *IY1-- = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step ); s0_ind = add( s0_ind, step ); @@ -3198,6 +3249,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY1++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0--, t_sin[c0_ind] ); acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); @@ -3206,6 +3258,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); *IY1-- = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step ); s0_ind = add( s0_ind, step ); @@ -3223,6 +3276,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY1++ = round_fx( acc ); + move16(); /* Construction of Y2 */ c0_ind = T_SIN_PI_2; @@ -3246,6 +3300,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1--, t_sin[s1_ind] ); acc = L_mac0( acc, *IZ2++, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step2 ); s0_ind = add( s0_ind, step2 ); @@ -3265,6 +3320,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0--, t_sin[c0_ind] ); acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); @@ -3273,6 +3329,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); *IY2-- = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step2 ); s0_ind = add( s0_ind, step2 ); @@ -3293,6 +3350,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0--, t_sin[c0_ind] ); acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); @@ -3301,6 +3359,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); *IY2-- = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step2 ); s0_ind = add( s0_ind, step2 ); @@ -3321,6 +3380,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ0--, t_sin[c0_ind] ); acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); @@ -3329,6 +3389,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); *IY2-- = round_fx( acc ); + move16(); c0_ind = sub( c0_ind, step2 ); s0_ind = add( s0_ind, step2 ); @@ -3349,6 +3410,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); acc = L_mult0( *IZ1--, t_sin[c1_ind] ); acc = L_msu0( acc, *IZ0--, t_sin[c0_ind] ); @@ -3357,6 +3419,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); *IY2-- = round_fx( acc ); + move16(); c0_ind = add( c0_ind, step2 ); s0_ind = sub( s0_ind, step2 ); @@ -3374,6 +3437,7 @@ void ifft3_fx( const Word16 Z[], Word16 X[], const Word16 n ) acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); *RY2++ = round_fx( acc ); + move16(); /* Compute the inverse FFT for all 3 blocks. */ RY0 = &Y[0]; /* Rewind the pointers. */ diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c index 0891367c612e3114a60dc949556c16815d38540d..4682fb65e5522f1f7bbed3284118dfea8c70d7aa 100644 --- a/lib_com/fft_rel.c +++ b/lib_com/fft_rel.c @@ -39,8 +39,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*---------------------------------------------------------------------* * Local constants @@ -317,6 +316,7 @@ void fft_rel_fx( Word16 *xi2, *xi3, *xi4, *xi1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -357,7 +357,7 @@ void fft_rel_fx( move16(); x1 = &x[1]; move16(); - FOR( i = 0; i < n / 2; i++ ) + FOR( i = 0; i < shr( n, 1 ); i++ ) { xt = *x0; move16(); @@ -400,7 +400,7 @@ void fft_rel_fx( n2 = shl( n4, 1 ); n1 = shl( n2, 1 ); - step = N_MAX_SAS / n1; + step = idiv1616( N_MAX_SAS, n1 ); x0 = x; x1 = x + n2; @@ -679,6 +679,8 @@ void fft_rel_fx32( Word32 *x2even, *x2odd; Word32 temp[512]; + test(); + test(); IF( EQ_16( n, 128 ) || EQ_16( n, 256 ) || EQ_16( n, 512 ) ) { idx = fft256_read_indexes; @@ -690,10 +692,14 @@ void fft_rel_fx32( FOR( i = 0; i < 64; i++ ) { j = *idx++; + move16(); k = *idx++; + move16(); *x2++ = L_add( x[shr( j, 1 )], x[shr( k, 1 )] ); + move16(); *x2++ = L_sub( x[shr( j, 1 )], x[shr( k, 1 )] ); + move16(); } } ELSE IF( EQ_16( n, 256 ) ) @@ -702,10 +708,14 @@ void fft_rel_fx32( FOR( i = 0; i < 128; i++ ) { j = *idx++; + move16(); k = *idx++; + move16(); *x2++ = L_add( x[j], x[k] ); + move16(); *x2++ = L_sub( x[j], x[k] ); + move16(); } } ELSE IF( EQ_16( n, 512 ) ) @@ -721,11 +731,15 @@ void fft_rel_fx32( idx++; *x2even++ = L_add( x[j], x[k] ); + move16(); *x2even++ = L_sub( x[j], x[k] ); - j++; - k++; + move16(); + j = add( j, 1 ); + k = add( k, 1 ); *x2odd++ = L_add( x[j], x[k] ); + move16(); *x2odd++ = L_sub( x[j], x[k] ); + move16(); } } @@ -746,11 +760,15 @@ void fft_rel_fx32( FOR( i = 0; i < n; i += 4 ) { *x2++ = L_add( *x0++, *x1 ); /* x[i] = xt + x[i+n2]; */ + move16(); *x2++ = *x0; + move16(); x0--; *x2++ = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + move16(); x1++; *x2++ = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + move16(); x0 += 4; x1 += 3; /* x1 has already advanced */ @@ -764,23 +782,27 @@ void fft_rel_fx32( *-----------------------------------------------------------------*/ j = 0; + move16(); x0 = &x[0]; - FOR( i = 0; i < n - 1; i++ ) + FOR( i = 0; i < sub( n, 1 ); i++ ) { IF( LT_16( i, j ) ) { xt = x[j]; + move32(); x[j] = *x0; + move32(); *x0 = xt; + move32(); } x0++; - k = n / 2; + k = shr( n, 1 ); WHILE( LE_16( k, j ) ) { - j -= k; + j = sub( j, k ); k = shr( k, 1 ); } - j += k; + j = add( j, k ); } /*-----------------------------------------------------------------* @@ -789,10 +811,12 @@ void fft_rel_fx32( x0 = &x[0]; x1 = &x[1]; - FOR( i = 0; i < n / 2; i++ ) + FOR( i = 0; i < shr( n, 1 ); i++ ) { *x1 = L_sub( *x0, *x1 ); + move32(); *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); + move32(); x0++; x0++; @@ -813,9 +837,12 @@ void fft_rel_fx32( FOR( i = 0; i < n; i += 4 ) { - *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + move32(); *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ - *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + move32(); + *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + move32(); x0 += 4; x1 += 3; /* x1 has already advanced */ @@ -835,10 +862,14 @@ void fft_rel_fx32( *-----------------------------------------------------------------*/ n4 = 1; + move16(); n2 = 2; + move16(); n1 = 4; + move16(); step = N_MAX_DIV4; + move16(); FOR( k = 3; k <= m; k++ ) { @@ -853,9 +884,12 @@ void fft_rel_fx32( FOR( i = 0; i < n; i += n1 ) { - *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + move32(); *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ - *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + move32(); + *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + move32(); s = sincos_t_ext_fx; c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 */ @@ -878,9 +912,13 @@ void fft_rel_fx32( t2 = L_sub( Mpy_32_16_1( *xi3, *s ), Mpy_32_16_1( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ *xi4 = L_sub( *xi2, t2 ); + move32(); *xi2 = L_sub( *xi1, t1 ); + move32(); *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); + move32(); *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); + move32(); } x1 += n1; diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 405c500b5906579f5526f6fe2cbd0942010cabf1..b07cb3acbe15034a5f13a05cf1d6a35a8892c708 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "stl.h" #include "stdint.h" @@ -85,6 +84,7 @@ static void c_fft_fx( const Word16 *table_ptr; const Word16 *input_ptr1, *input_ptr2, *input_ptr3, *input_ptr4; Word16 shift = 0; + move16(); /* Setup Reorder Variables */ table_ptr = NULL; table_ptr = FFT_REORDER_1024; @@ -92,18 +92,23 @@ static void c_fft_fx( { case 1024: shift = 0; + move16(); BREAK; case 512: shift = 1; + move16(); BREAK; case 256: shift = 2; + move16(); BREAK; case 128: shift = 3; + move16(); BREAK; case 64: shift = 4; + move16(); BREAK; } /* The FFT part */ diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index 7571b03bacef420e60286d56db29685364c559f7..b75a670178eb0e4d3a550d826b3bd856cd5ffbef 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -40,8 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c index c04b13a4d09fb5871b3fd31b7762fe8507c1edd1..e7104810c704a825563f95c3115307041f222f5a 100644 --- a/lib_com/findpulse.c +++ b/lib_com/findpulse.c @@ -40,8 +40,7 @@ #include "prot.h" #include "cnst.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*----------------------------------------------------------------------------------* * findpulse() diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index e2f1dd8c7873eab7ff0028401634a48a61f4c03a..627eda6e0a29878d2a104cd2c356d7a560093fc2 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 7cf76a7cf329e7d33bb8cd300f9ee2061a12ec4c..7a081f35137dabf9796d96f7fcb8f07e9e3b1018 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -4,27 +4,28 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" +#define WMC_TOOL_SKIP + Word32 floatToFixed( float f, Word16 Q ) { + Word64 result_32; if ( f == 1.0f && Q == Q15 ) return MAX16B; if ( f == 1.0f && Q == Q31 ) return MAXVAL_WORD32; if ( Q < 0 ) - return (Word32) ( (float) ( f ) / (double) ( 1llu << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); + result_32 = (Word64) ( (float) ( f ) / (double) ( (unsigned Word64) 1 << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); else - { - Word64 result_32; - result_32 = (Word64) ( f * (double) ( 1llu << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); - if ( result_32 > MAX_32 ) - return MAX_32; - if ( result_32 < MIN_32 ) - return MIN_32; - return (Word32) result_32; - } + result_32 = (Word64) ( f * (double) ( (unsigned Word64) 1 << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); + if ( result_32 > MAX_32 ) + return MAX_32; + if ( result_32 < MIN_32 ) + return MIN_32; + return (Word32) result_32; } + float fixedToFloat( Word32 i, Word16 Q ) { if ( Q < 0 ) @@ -37,7 +38,7 @@ void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ) for ( int j = 0; j < l; j++ ) { #if 0 - i[j] = floatToFixed(f[j], Q); + i[j] = floatToFixed(f[j], Q); #else Word64 i64_val = floatToFixed( f[j], Q ); IF( i64_val > MAX_32 ) @@ -151,7 +152,7 @@ void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l ) for ( int j = 0; j < l; j++ ) { #if 0 - i[j] = (Word16)floatToFixed(f[j], Q); + i[j] = (Word16)floatToFixed(f[j], Q); #else Word32 i32_val = floatToFixed( f[j], Q ); IF( i32_val > MAX_16 ) @@ -297,3 +298,4 @@ Word16 L_get_q_buf1( float *ptr_flt, Word16 length ) } } #endif +#undef WMC_TOOL_SKIP diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index 4fa6e41baeaf2379cb9cb4e46f17597c06150fce..5af9eed54817734d963c4fbfe5bcad03f66bedfc 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -40,8 +40,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*----------------------------------------------------------------------------------* * fer_energy() * diff --git a/lib_com/gain_inov_fx.c b/lib_com/gain_inov_fx.c index 7f767c0280cec81306d84c54e7b143c867a5396e..e2f65421a479a918a98a3a884910e849f324fbe0 100644 --- a/lib_com/gain_inov_fx.c +++ b/lib_com/gain_inov_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c index 43d39ae318a9b1a0b31b35d0507412cfecb45767..5f9c8f56a0f67b4355d6af240da3134733a56b38 100644 --- a/lib_com/get_gain.c +++ b/lib_com/get_gain.c @@ -38,8 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*----------------------------------------------------------------------------------* * get_gain() diff --git a/lib_com/gs_bitallocation.c b/lib_com/gs_bitallocation.c index 6d24ab7bb39fa5a77e7288aea37c1c94a069469c..3898daf95cbc7f98a1b03ebd47ac57050ba1832d 100644 --- a/lib_com/gs_bitallocation.c +++ b/lib_com/gs_bitallocation.c @@ -43,6 +43,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" + /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -51,6 +52,29 @@ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); +#ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING +#define Q15_0_33 10922 /* 0.33 */ +#define Q18_0_1 26214 /* 0.1 */ +#define Q18_0_50 131072 /* 0.50 */ +#define Q18_0_75 196608 /* 0.75 */ +#define Q18_0_76 199229 /* 76/100 */ +#define Q18_1_0 262144 /* 1.0 */ +#define Q18_1_2 314573 /* 1.2 */ +#define Q18_112 29360128 /* 112 */ +#define Q18_DSR_NB_PULSE 1179648 /* 4.5 */ +#define Q18_1_5xDSR_NB_PULSE 1769472 /* 1.5x4.5 */ +#define Q18_2_0xDSR_NB_PULSE ( Q18_DSR_NB_PULSE << 1 ) /* 2.0x4.5 */ + +#define Q31_0_00125 2684355 /* 0.125/100 */ +#define Q31_0_0125 26843546 /* 0.0125 */ +#define Q31_0_015 32212255 /* 0.0125 */ +#define Q31_0_02 42949673 /* 0.02 */ +#define Q31_0_17 365072220 /* 0.17 */ +#define Q31_0_23 493921239 /* 0.23 */ +static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ); +static Word16 Find_bit_alloc_IVAS_int( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, const Word16 L_frame, Word16 *bit, Word16 *max_ener_band, float *ener_vec, float *bits_per_bands ); +static Word16 maximum_fx( const Word16 *vec_fx, const Word16 lvec_fx, Word16 *max_fx ); +#endif /*-------------------------------------------------------------------* * bands_and_bit_alloc() @@ -89,8 +113,12 @@ void bands_and_bit_alloc( int16_t pos, band; float SWB_bit_budget; float bits_per_bands[MBANDS_GN_BITALLOC16k]; +#ifndef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING float fzero_val, mp, mb, nb_bands_adj, bit_adj; int16_t nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; +#else + float fzero_val; +#endif /* initializations */ nb_tot_bands = 16; @@ -190,6 +218,7 @@ void bands_and_bit_alloc( { if ( GSC_IVAS_mode > 0 ) { +#ifndef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING SWB_bit_budget = *bit; st_band = 5; @@ -368,6 +397,10 @@ void bands_and_bit_alloc( bits_per_bands[i] += sum_bit; } } +#else + nb_tot_bands = Find_bit_alloc_IVAS_int( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, L_frame, bit, max_ener_band, ener_vec, bits_per_bands ); + nb_bands = nb_tot_bands; +#endif } else if ( GSC_noisy_speech ) { @@ -927,3 +960,304 @@ static float Find_bit_frac( return ( var_out ); } + +#ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING +static Word16 Find_bit_alloc_IVAS_int( /* o : Number of band to encode */ + const Word32 core_brate, /* i : core bit rate */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/ + const Word16 nb_tot_bands_in, /* i : total number of band */ + const Word16 L_frame, /* i : frame length */ + Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ + Word16 *max_ener_band, /* i/o: Energy based sorted order */ + float *ener_vec_io, /* i/o: Energy per band order */ + float *bits_per_bands_o /* o : Number of bit allowed per allowed sub-band Q3 */ +) +{ + Word32 mp, mb, nb_bands_adj, bit_adj; + Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; + Word32 SWB_bit_budget; // Q0 -> Q18 + Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp; + Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; + Word16 d_tmp, e_div, tmp16, ener_vec[MBANDS_GN_BITALLOC16k]; + Word32 Ltmp, etmp_32fx, bits_per_bands[MBANDS_GN_BITALLOC16k]; + + SWB_bit_budget = *bit; // Q0 + st_band = 5; + nb_bands_max = nb_tot_bands_in; + + for ( i = 0; i < MBANDS_GN; i++ ) + { + ener_vec[i] = (short) ( ener_vec_io[i] ); /* Q12 -> Q12 */ + } + + if ( L_frame == L_FRAME16k ) + { + for ( i = MBANDS_GN; i < MBANDS_GN_BITALLOC16k; i++ ) + { + ener_vec[i] = (short) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ + } + } + + set_l( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); + + /* Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ + /* bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100; */ + bit_fracf = L_add( Mpy_32_32( -Q31_0_00125, L_shl( Diff_len, 18 ) ), Q18_0_76 ); /* Q18 */ + + /* bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f); */ + bit_fracf = min( max( bit_fracf, Q18_0_50 ), Q18_0_75 ); + + /* Adjusment of the bitrate between LF and HF base on the content type */ + /* 1 = new GSC bit alloc + 2 = GSC bit alloc for tc frame + 3 = more music like (should not happen often given music is coded with dft) */ + + if ( GSC_IVAS_mode <= 3 ) + { + nb_bands_max -= 6; + } + + if ( GSC_IVAS_mode == 2 ) + { + /* bit_fracf += 0.1f; */ + bit_fracf += Q18_0_1; /* Q18*/ + nb_bands_max -= 1; + } + + if ( GSC_IVAS_mode == 3 ) + { + /* bit_fracf -= 0.1f; */ + bit_fracf -= Q18_0_1; /* Q18*/ + nb_bands_max += 3; + } + + /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ + /* Adjust the number of band based on the content type and bitrate */ + + /* nb_bands_adj = 1.0f; */ + nb_bands_adj = Q18_1_0; + if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) + { + /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ + nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); // Q18 + } + else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) + { + /*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/ + nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); // Q18 + } + /*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/ + + nb_bands_max = round_fx( Mpy_32_16_1( L_shl( nb_bands_adj, 5 ), shl( nb_bands_max, 10 - 2 ) ) ); /* Q0 */ + nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands_in ); + + /* bit_fracf *= SWB_bit_budget;*/ + /* At this point bit_fracf has a value below 1.0 */ + bit_fracf = Mpy_32_16_1( L_shl( bit_fracf, 10 ), extract_l( L_shl( SWB_bit_budget, 5 ) ) ); /* (Q(18+10)*Q(0+5) + 1 - 16 = Q18 */ + + /* Estimation of the number of bit used in HF */ + /* with only the first weighting The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ + /* mb = .17f * bit_fracf;*/ + mb = Mpy_32_32( Q31_0_17, bit_fracf ); /* Q18 */ + + /* mp = 2 * DSR_NB_PULSE;*/ + mp = Q18_2_0xDSR_NB_PULSE; + if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 ) + { + /* mp = 1.5f * DSR_NB_PULSE;*/ + mp = Q18_1_5xDSR_NB_PULSE; + } + else if ( core_brate < GSC_L_RATE_STG ) + { + /* mp = DSR_NB_PULSE;*/ + mp = Q18_DSR_NB_PULSE; + } + + /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ + /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ + /* compute the total possible number of band to be coded */ + + /* nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); */ + d_tmp = Find_norm_inv( L_add( mp, mb ), &e_div ); + Ltmp = Mpy_32_16_1( L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ), d_tmp ); /* Perform mult by 1/den */ + nb_tot_bands_loc = extract_h( L_shl( Ltmp, sub( 1, e_div ) ) ); /* adjust exponent: 1 is to take into account the / 2.0f, and e_div for the num and den of the division*/ + + mp = min( mp, mb ); + tmp16 = sub( add( nb_tot_bands_loc, st_band ), nb_bands_max ); + if ( tmp16 > 0 ) + { + /* bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands_loc + st_band - nb_bands_max ); */ + bit_adj = Mpy_32_16_1( L_shl( L_add( mb, mp ), 5 ), shl( tmp16, 10 - 1 ) ); /* Q18+5 * Q0+10 + 1 -1 - 16 = Q18 (-1 is to cover for the /2 in the equation) */ + bit_adj = L_max( 0, bit_adj ); + nb_tot_bands_loc = nb_bands_max - st_band; + bit_fracf += bit_adj; /* Q18 */ + } + nb_tot_bands_loc += st_band; + + /* Allocate bits to LF */ + /* etmp = 0.23f; */ + etmp_32fx = Q31_0_23; + for ( j = 0; j < st_band; j++ ) + { + i = j; + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + /* bits_per_bands[j] = etmp * bit_fracf; */ + bits_per_bands[j] = Mpy_32_32( bit_fracf, etmp_32fx ); /* 18 + 31 + 1 - 32 = Q18 */ + /* etmp -= 0.015f; */ + etmp_32fx -= Q31_0_015; /* Q18 */ + } + + /* SWB_bit_budget -= bit_fracf; */ + SWB_bit_budget = L_sub( L_shl( SWB_bit_budget, 18 ), bit_fracf ); /* Q0->Q18 */ + + /* Find low energy band in HF */ + set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k ); + for ( i = st_band + 2; i < nb_tot_bands_loc - 1; i++ ) + { + if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) /* i +1 and i -1 can be considered as 2 ptrs */ + { + nb_pulse_per_band[i] = 1; + } + } + + for ( j = st_band; j < nb_tot_bands_loc; j++ ) + { + if ( j > 6 ) + { + i = maximum_fx( ener_vec, nb_tot_bands_loc, &etmp ); + } + else + { + i = j; + } + max_ener_band[j] = i; + ener_vec[i] = MIN16B; + } + + /* Recompute the final bit distribution for HF */ + if ( nb_tot_bands_loc > st_band ) + { + /* This is not bit exact because of the precision lost */ + /* mb = ( SWB_bit_budget * 2 / ( nb_tot_bands_loc - st_band ) ) - mp; */ + d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, st_band ) ), &e_div ); + mb = L_sub( L_shr( Mpy_32_16_1( L_shl( SWB_bit_budget, 1 ), d_tmp ), e_div ), mp ); /* Q18 */ + /* bit_fracf = ( mb - mp ) / ( nb_tot_bands_loc - st_band ); */ + bit_fracf = L_shr( Mpy_32_16_1( L_sub( mb, mp ), d_tmp ), e_div ); /* Q18 */ + + mb -= bit_fracf; + /* Do the distribution */ + for ( j = st_band; j < nb_tot_bands_loc; j++ ) + { + bits_per_bands[max_ener_band[j]] = Q18_DSR_NB_PULSE; + if ( nb_pulse_per_band[max_ener_band[j]] > 1 ) + { + bits_per_bands[max_ener_band[j]] = mb; + } + mb -= bit_fracf; + SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; // Q18 + } + } + + /* Series of verification in case bit allocated != the budget */ + if ( SWB_bit_budget > 0 ) + { + i = st_band - 1; + while ( SWB_bit_budget > 0 ) + { + /* bits_per_bands[i]++; */ + bits_per_bands[i] += Q18_1_0; + /* SWB_bit_budget--; */ + SWB_bit_budget -= Q18_1_0; + i--; + if ( i == -1 ) + { + i = st_band - 1; + } + } + } + + /*nb_bands = nb_tot_bands_loc;*/ + + sum_bit = 0; + j = 0; + for ( i = 0; i < nb_tot_bands_loc; i++ ) + { + /* if (bits_per_bands[i] > 112) */ + if ( bits_per_bands[i] > Q18_112 ) + { + /* sum_bit += bits_per_bands[i] - 112; */ + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], Q18_112 ) ); + /* bits_per_bands[i] = 112; */ + bits_per_bands[i] = Q18_112; + j = add( j, add( i, 1 ) ); + } + + /* safety check for overage bit reallocation */ + /* else if (bits_per_bands[i] + sum_bit / 3 > 112) */ + else if ( L_add( bits_per_bands[i], Mpy_32_16_1( sum_bit, Q15_0_33 ) ) > Q18_112 ) + { + j = add( j, add( i, 1 ) ); + } + } + + if ( sum_bit != 0 ) + { + /* sum_bit /= (nb_bands - j); */ + d_tmp = Find_norm_inv( L_deposit_h( sub( nb_tot_bands_loc, j ) ), &e_div ); + sum_bit = L_shr( Mpy_32_16_1( sum_bit, d_tmp ), e_div ); /* Q18 */ + for ( i = j; i < nb_tot_bands_loc; i++ ) + { + bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); + } + } + + for ( i = 0; i < MBANDS_GN_BITALLOC16k; i++ ) + { + bits_per_bands_o[i] = (float) bits_per_bands[i] / 262144.0f; /* Q18 -> float */ + } + + return nb_tot_bands_loc; +} + +/* Find normalized 1 / ToDivide */ +static Word16 Find_norm_inv( + const Word32 ToDivide, + Word16 *e_div ) +{ + Word16 d_tmp, e_tmp; + + e_tmp = norm_l( ToDivide ); + d_tmp = round_fx( L_shl( ToDivide, e_tmp ) ); + d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */ + *e_div = sub( 14, e_tmp ); + + return d_tmp; +} + +static Word16 maximum_fx( /* o : index of the maximum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *max_fx /* o : maximum value in the input vector */ +) +{ + Word16 j, ind; + Word16 tmp; + + ind = 0; + tmp = vec_fx[0]; + + for ( j = 1; j < lvec_fx; j++ ) + { + if ( vec_fx[j] > tmp ) + { + ind = j; + } + tmp = s_max( tmp, vec_fx[j] ); + } + *max_fx = tmp; + + return ind; +} +#endif diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index b3da54d2a8e66bc9cfc828fb9135d244dece5a0e..943291cec8a416278ca5dc4f6b0449bc29e3f95a 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "assert.h" /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "assert.h" /* Debug prototypes */ #include "stl.h" /*==================================================================================*/ @@ -579,7 +578,7 @@ void bands_and_bit_alloc_fx( #endif test(); - if ( EQ_16( bwidth, NB ) && GT_16( nb_bands_max, 10 ) ) + if ( ( bwidth == NB ) && GT_16( nb_bands_max, 10 ) ) { nb_bands_max = 10; move16(); @@ -588,8 +587,10 @@ void bands_and_bit_alloc_fx( /*------------------------------------------------------------------------ * Find extra number of band to code according to bit rate availables *-----------------------------------------------------------------------*/ + test(); WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) ) { + test(); bit_tmp = sub( bit_tmp, bit_new_bands ); nb_bands = add( nb_bands, 1 ); } diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index 107236eb6f8e25779bf22027f73600d6b84cbc8b..e13d04495275d45b83e3864bde6c1f8ed23ef755 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -6,8 +6,7 @@ #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 */ +#include "prot_fx.h" /* Function prototypes */ #include "ivas_prot.h" /* Function prototypes */ #include "assert.h" /* Debug prototypes */ #include "stl.h" @@ -121,7 +120,7 @@ void bands_and_bit_alloc_ivas_fx( #endif nb_tot_bands = MBANDS_GN; move16(); - IF( EQ_16( L_frame, L_FRAME16k ) ) + if ( EQ_16( L_frame, L_FRAME16k ) ) { nb_tot_bands = MBANDS_GN_BITALLOC16k; move16(); @@ -137,6 +136,7 @@ void bands_and_bit_alloc_ivas_fx( #else /* BASOP_NOGLOB */ ener_vec[0] = add( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ #endif + move16(); Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; move16(); @@ -162,7 +162,8 @@ void bands_and_bit_alloc_ivas_fx( bit_new_bands = 5; move16(); #if 1 // def ADD_LRTD - IF( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) ) + test(); + if ( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) ) { bit_new_bands = 7; move16(); @@ -185,8 +186,11 @@ void bands_and_bit_alloc_ivas_fx( i = add( i, 1 ); } - IF( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) && - LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + test(); + test(); + test(); + if ( ( element_mode > EVS_MONO ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { i = sub( i, 1 ); } @@ -200,7 +204,7 @@ void bands_and_bit_alloc_ivas_fx( test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && ( bwidth == NB ) ) { IF( GE_32( core_brate, ACELP_9k60 ) ) { @@ -231,14 +235,17 @@ void bands_and_bit_alloc_ivas_fx( } #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - *bit -= 8; + *bit = sub( *bit, 8 ); + move16(); } - IF( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */ + test(); + IF( coder_type == INACTIVE && LE_32( core_brate, GSC_LRES_GAINQ_LIMIT ) ) /* can happen only for 2nd channel inactive */ { - *bit += GSC_LRES_NB_NITS; + *bit = add( *bit, GSC_LRES_NB_NITS ); + move16(); } IF( *bit > 0 ) @@ -247,7 +254,9 @@ void bands_and_bit_alloc_ivas_fx( { #ifndef FIX_802_1137_1137_GSC_IVAS_FXFLT_DECODING SWB_bit_budget = *bit; // Q0 + move16(); st_band = 5; + move16(); set_l( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); @@ -262,45 +271,48 @@ void bands_and_bit_alloc_ivas_fx( 2 = GSC bit alloc for tc frame 3 = more music like (should not happen often given music is coded with dft) */ - IF( GSC_IVAS_mode <= 3 ) + if ( LE_16( GSC_IVAS_mode, 3 ) ) { - nb_bands_max -= 6; + nb_bands_max = sub( nb_bands_max, 6 ); } - IF( GSC_IVAS_mode == 2 ) + IF( EQ_16( GSC_IVAS_mode, 2 ) ) { // bit_fracf += 0.1f; bit_fracf = L_add( bit_fracf, 26214 ); // Q18 - nb_bands_max--; + nb_bands_max = sub( nb_bands_max, 1 ); } - IF( GSC_IVAS_mode == 3 ) + IF( EQ_16( GSC_IVAS_mode, 3 ) ) { // bit_fracf -= 0.1f; bit_fracf = L_sub( bit_fracf, 26214 ); // Q18 - nb_bands_max += 3; + nb_bands_max = add( nb_bands_max, 3 ); } /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/ /* Adjust the number of band based on the content type and bitrate */ // nb_bands_adj = 1.0f; nb_bands_adj = ONE_IN_Q18; - IF( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) + move32(); + test(); + test(); + IF( EQ_16( GSC_IVAS_mode, 1 ) && LT_32( core_brate, GSC_L_RATE_STG ) ) { // nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f; nb_bands_adj = L_sub( Mpy_32_32( 26843546, L_shl( SWB_bit_budget, Q18 ) ), 196608 ); // Q18 } - ELSE IF( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) + ELSE IF( NE_16( GSC_IVAS_mode, 2 ) && GT_32( core_brate, GSC_H_RATE_STG ) ) { // nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; nb_bands_adj = L_sub( Mpy_32_32( 42949673, L_shl( SWB_bit_budget, Q18 ) ), 314572 ); // Q18 } // nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f); - nb_bands_max = (Word16) L_shr_r( nb_bands_max * nb_bands_adj, Q18 ); // Q0 + nb_bands_max = extract_l( L_shr_r( nb_bands_max * nb_bands_adj, Q18 ) ); // Q0 nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands ); // bit_fracf *= SWB_bit_budget; - bit_fracf = bit_fracf * SWB_bit_budget; // Q18 + bit_fracf = imult3216( bit_fracf, extract_l( SWB_bit_budget ) ); // Q18 /* Estimation of the number of bit used in HF */ /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */ @@ -308,43 +320,52 @@ void bands_and_bit_alloc_ivas_fx( mb = Mpy_32_32( 365072220, bit_fracf ); // Q18 // mp = 2 * DSR_NB_PULSE); mp = 2359296; // Q18 - IF( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 ) + move32(); + test(); + IF( LT_32( core_brate, GSC_L_RATE_STG ) && EQ_16( GSC_IVAS_mode, 3 ) ) { // mp = 1.5f * DSR_NB_PULSE; mp = 1769472; // Q18 + move32(); } - ELSE IF( core_brate < GSC_L_RATE_STG ) + ELSE IF( LT_32( core_brate, GSC_L_RATE_STG ) ) { // mp = DSR_NB_PULSE; mp = DSR_NB_PULSE_Q18; + move32(); } /* We want max_ener_band[st_band] <= max_ener_band[st_band-1] and max_ener_band[nb_bands_max-1] <= max_ener_band[st_band]*/ /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */ /* compute the total possible number of band to be coded */ // nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); - nb_tot_bands = (Word16) ( L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ) / L_add( mp, L_shr( L_sub( mb, mp ), 1 ) ) ); - mp = min( mp, mb ); - IF( nb_tot_bands + st_band > nb_bands_max ) + nb_tot_bands = extract_l( L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ) / L_add( mp, L_shr( L_sub( mb, mp ), 1 ) ) ); + mp = L_min( mp, mb ); + IF( GT_16( add( nb_tot_bands, st_band ), nb_bands_max ) ) { - bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max ); - bit_adj = max( 0, bit_adj ); - nb_tot_bands = nb_bands_max - st_band; + bit_adj = imult3216( L_shr( L_add( mb, mp ), 1 ), sub( add( nb_tot_bands, st_band ), nb_bands_max ) ); + bit_adj = L_max( 0, bit_adj ); + nb_tot_bands = sub( nb_bands_max, st_band ); // bit_fracf += bit_adj; bit_fracf = L_add( bit_fracf, bit_adj ); // Q18 } - nb_tot_bands += st_band; + nb_tot_bands = add( nb_tot_bands, st_band ); /* Allocate bits to LF */ // etmp = 0.23f; Word32 etmp_32fx = 493921239; // Q15 + move32(); FOR( j = 0; j < st_band; j++ ) { i = j; + move16(); max_ener_band[j] = i; + move16(); ener_vec[i] = MIN16B; + move16(); // bits_per_bands[j] = etmp * bit_fracf; bits_per_bands[j] = Mpy_32_32( bit_fracf, etmp_32fx ); // 33 - 15 = Q18 + move32(); // etmp -= 0.015f; etmp_32fx = L_sub( etmp_32fx, 32212255 ); } @@ -356,44 +377,51 @@ void bands_and_bit_alloc_ivas_fx( set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k ); FOR( i = st_band + 2; i < nb_tot_bands - 1; i++ ) { - IF( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] ) + test(); + if ( LT_16( ener_vec[i], ener_vec[i - 1] ) && LT_16( ener_vec[i], ener_vec[i + 1] ) ) { nb_pulse_per_band[i] = 1; + move16(); } } FOR( j = st_band; j < nb_tot_bands; j++ ) { - IF( j > 6 ) + IF( GT_16( j, 6 ) ) { i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); } ELSE { i = j; + move16(); } max_ener_band[j] = i; + move16(); ener_vec[i] = MIN16B; + move16(); } /* Recompute the final bit distribution for HF */ - IF( nb_tot_bands > st_band ) + IF( GT_16( nb_tot_bands, st_band ) ) { // bit_fracf = DSR_NB_PULSE; - mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp; // Q18 - bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band ); + mb = ( L_shl( SWB_bit_budget, 1 ) / sub( nb_tot_bands, st_band ) ) - mp; // Q18 + bit_fracf = L_sub( mb, mp ) / sub( nb_tot_bands, st_band ); mb = L_sub( mb, bit_fracf ); /* Do the distribution */ FOR( j = st_band; j < nb_tot_bands; j++ ) { - IF( nb_pulse_per_band[max_ener_band[j]] > 1 ) + IF( GT_16( nb_pulse_per_band[max_ener_band[j]], 1 ) ) { bits_per_bands[max_ener_band[j]] = mb; + move32(); } ELSE { // bits_per_bands[max_ener_band[j]] = 4.5f; bits_per_bands[max_ener_band[j]] = 1179648; + move32(); } mb = L_sub( mb, bit_fracf ); SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); // Q18 @@ -403,52 +431,56 @@ void bands_and_bit_alloc_ivas_fx( /* Series of verification in case bit allocated != the budget */ IF( SWB_bit_budget > 0 ) { - i = st_band - 1; + i = sub( st_band, 1 ); WHILE( SWB_bit_budget > 0 ) { // bits_per_bands[i]++; bits_per_bands[i] = L_add( bits_per_bands[i], 262144 ); // SWB_bit_budget--; SWB_bit_budget = L_sub( SWB_bit_budget, 262144 ); - i--; - IF( i == -1 ) + i = sub( i, 1 ); + IF( EQ_16( i, -1 ) ) { - i = st_band - 1; + i = sub( st_band, 1 ); } } } nb_bands = nb_tot_bands; + move16(); sum_bit = 0; + move32(); j = 0; + move16(); FOR( i = 0; i < nb_bands; i++ ) { // if (bits_per_bands[i] > 112) - IF( bits_per_bands[i] > 29360128 ) + IF( GT_32( bits_per_bands[i], 29360128 ) ) { - sum_bit += bits_per_bands[i] - 112; + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 112 ) ); sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 ) ); // bits_per_bands[i] = 112; bits_per_bands[i] = 29360128; - j = i + 1; + move32(); + j = add( i, 1 ); } /* safety check for overage bit reallocation */ // else if (bits_per_bands[i] + sum_bit / 3 > 112) - ELSE IF( bits_per_bands[i] + sum_bit / 3 > 29360128 ) + ELSE IF( GT_32( L_add( bits_per_bands[i], divide3216( L_shl( sum_bit, 1 ), 3 ) ), 29360128 ) ) { - j = i + 1; + j = add( i, 1 ); } } IF( sum_bit != 0 ) { // sum_bit /= (nb_bands - j); - sum_bit = sum_bit / ( nb_bands - j ); + sum_bit = divide3216( L_shl( sum_bit, 1 ), sub( nb_bands, j ) ); FOR( i = j; i < nb_bands; i++ ) { - bits_per_bands[i] += sum_bit; + bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); } } #else @@ -461,7 +493,7 @@ void bands_and_bit_alloc_ivas_fx( IF( EQ_16( GSC_noisy_speech, 1 ) ) { SWB_bit_budget = *bit; - move16(); + move32(); nb_bands = 5; move16(); @@ -469,22 +501,30 @@ void bands_and_bit_alloc_ivas_fx( // fzero_val = 0.0f; fzero_val = 0; - IF( element_mode > EVS_MONO ) + move16(); + + if ( element_mode > EVS_MONO ) { fzero_val = MIN16B; + move16(); } - IF( coder_type == UNVOICED && element_mode > EVS_MONO ) + test(); + IF( EQ_16( coder_type, UNVOICED ) && element_mode > EVS_MONO ) { nb_bands = 3; - IF( SWB_bit_budget > 20 ) + move16(); + + if ( GT_32( SWB_bit_budget, 20 ) ) { nb_bands = 5; + move16(); } } - ELSE IF( bwidth < SWB ) + ELSE IF( LT_16( bwidth, SWB ) ) { nb_bands = 7; + move16(); } #endif @@ -513,11 +553,13 @@ void bands_and_bit_alloc_ivas_fx( move16(); } #if 1 // def ADD_LRTD - IF( bwidth < SWB ) + IF( LT_16( bwidth, SWB ) ) { - IF( coder_type == UNVOICED && element_mode > EVS_MONO ) + test(); + if ( EQ_16( coder_type, UNVOICED ) && element_mode > EVS_MONO ) { nb_tot_bands = 5; + move16(); } #endif FOR( ; j < nb_bands; j++ ) @@ -537,7 +579,9 @@ void bands_and_bit_alloc_ivas_fx( { i = maximum_fx( ener_vec, nb_tot_bands, &etmp ); max_ener_band[j] = i; + move16(); ener_vec[i] = fzero_val; + move16(); } } #endif @@ -545,24 +589,28 @@ void bands_and_bit_alloc_ivas_fx( } ELSE { - bit_index++; + bit_index = add( bit_index, 1 ); bit_tmp = sub( *bit, GSC_freq_bits[bit_index] ); - bit_index++; + bit_index = add( bit_index, 1 ); nb_bands_max = add( nb_bands_max, GSC_freq_bits[bit_index] ); - bit_index++; + bit_index = add( bit_index, 1 ); *pvq_len = 112; move16(); st_band = 7; move16(); #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) + test(); + IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_16k40 ) ) { *pvq_len = 160; + move16(); st_band = 10; - nb_bands = *pvq_len / 16; - bit_tmp -= 35; + move16(); + nb_bands = shr( *pvq_len, 4 ); + bit_tmp = sub( bit_tmp, 35 ); bit_new_bands = 5; + move16(); } #endif IF( LE_32( core_brate, ACELP_9k60 ) ) @@ -587,7 +635,7 @@ void bands_and_bit_alloc_ivas_fx( nb_bands = shr( *pvq_len, 4 ); #if 1 // def ADD_LRTD - nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k ); + nb_bands_max = s_min( nb_bands_max, MBANDS_GN_BITALLOC16k ); #endif /*------------------------------------------------------------------------ * Ajustement of the maximum number of bands in function of the @@ -597,17 +645,17 @@ void bands_and_bit_alloc_ivas_fx( test(); test(); test(); - IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) + IF( coder_type == INACTIVE || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) { /* Probably classification error -> concentrate bits on LF */ #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 ) + IF( EQ_16( L_frame, L_FRAME16k ) && GE_32( core_brate, ACELP_24k40 ) ) { - nb_bands_max = nb_tot_bands - 2; + nb_bands_max = sub( nb_tot_bands, 2 ); } - ELSE IF( core_brate >= ACELP_16k40 ) + ELSE IF( GE_32( core_brate, ACELP_16k40 ) ) { - nb_bands_max = nb_bands + 2; + nb_bands_max = add( nb_bands, 2 ); } ELSE #endif @@ -631,29 +679,30 @@ void bands_and_bit_alloc_ivas_fx( nb_bands_max = sub( nb_bands_max, 1 ); } #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { - IF( core_brate < ACELP_24k40 ) + IF( LT_32( core_brate, ACELP_24k40 ) ) { - nb_bands_max -= 4; + nb_bands_max = sub( nb_bands_max, 4 ); } - ELSE IF( core_brate < ACELP_32k ) + ELSE IF( LT_32( core_brate, ACELP_32k ) ) { - IF( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 ) + test(); + IF( GT_16( Diff_len, 0 ) || GE_16( noise_lev, NOISE_LEVEL_SP2 ) ) { - nb_bands_max -= 2; - bit_new_bands *= 2; + nb_bands_max = sub( nb_bands_max, 2 ); + bit_new_bands = shl( bit_new_bands, 1 ); } } ELSE IF( core_brate >= ACELP_32k ) { - bit_new_bands *= 2; + bit_new_bands = shl( bit_new_bands, 1 ); } } #endif test(); - IF( EQ_16( bwidth, NB ) && GT_16( nb_bands_max, 10 ) ) + if ( ( bwidth == NB ) && GT_16( nb_bands_max, 10 ) ) { nb_bands_max = 10; move16(); @@ -662,8 +711,10 @@ void bands_and_bit_alloc_ivas_fx( /*------------------------------------------------------------------------ * Find extra number of band to code according to bit rate availables *-----------------------------------------------------------------------*/ + test(); WHILE( GE_16( bit_tmp, bit_new_bands ) && LE_16( nb_bands, sub( nb_bands_max, 1 ) ) ) { + test(); bit_tmp = sub( bit_tmp, bit_new_bands ); nb_bands = add( nb_bands, 1 ); } @@ -672,9 +723,11 @@ void bands_and_bit_alloc_ivas_fx( * Fractional bits to distribute on the first x bands *-----------------------------------------------------------------------*/ #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k && core_brate > ACELP_32k ) + test(); + IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) ) { bit_fracf = 0; + move32(); } ELSE #endif @@ -703,20 +756,22 @@ void bands_and_bit_alloc_ivas_fx( bit_index = add( bit_index, 1 ); } #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k && core_brate > ACELP_16k40 ) + IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_16k40 ) ) { bit_index = 0; - i = imax - 1; + move16(); + i = sub( imax, 1 ); // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index]; bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); - i++; - bit_index++; + i = add( i, 1 ); + bit_index = add( bit_index, 1 ); FOR( ; i < 10; i++ ) { // bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf; bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); - bit_index++; + move32(); + bit_index = add( bit_index, 1 ); } } #endif @@ -735,7 +790,8 @@ void bands_and_bit_alloc_ivas_fx( { FOR( j = 0; j < nb_tot_bands; j++ ) { - bits_per_bands[j] = max( bits_per_bands[j], 0 ); + bits_per_bands[j] = L_max( bits_per_bands[j], 0 ); + move32(); } } @@ -744,26 +800,28 @@ void bands_and_bit_alloc_ivas_fx( * Complete the bit allocation per frequency band for 16kHz high brate mode *--------------------------------------------------------------------------*/ #if 1 // def ADD_LRTD - IF( L_frame == L_FRAME16k && core_brate > ACELP_32k ) + IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) ) { FOR( j = st_band; j < nb_bands; j++ ) { // bits_per_bands[j] = bit_new_bands; bits_per_bands[j] = L_shl( bit_new_bands, Q18 ); + move32(); } // bit_fracf = (1.0f / nb_bands) * (bit_tmp); - bit_fracf = ( 262144 / nb_bands ) * ( bit_tmp ); + bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); // etmp = 2.0f * bit_fracf / (nb_bands + 1); - etmp = (Word16) L_shr( L_shl( bit_fracf, Q1 ) / ( nb_bands + 1 ), Q3 ); // Q15 + etmp = divide3216( L_shr( bit_fracf, Q2 ), add( nb_bands, 1 ) ); // Q15 // bit_fracf = etmp; bit_fracf = L_shl( etmp, Q3 ); // Q18 - FOR( j = nb_bands - 1; j >= 0; j-- ) + FOR( j = sub( nb_bands, 1 ); j >= 0; j-- ) { // bits_per_bands[j] = etmp; // etmp += bit_fracf; bits_per_bands[j] = L_add( bits_per_bands[j], L_shl( etmp, Q3 ) ); // Q18 + move32(); etmp = (Word16) L_add( etmp, L_shr( bit_fracf, Q3 ) ); } } @@ -927,15 +985,17 @@ void bands_and_bit_alloc_ivas_fx( { // bits_per_bands[i] = (float)floor(bits_per_bands[i]); bits_per_bands[i] = L_shl( L_shr( bits_per_bands[i], Q18 ), Q18 ); + move32(); sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); } - IF( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */ + test(); + IF( GSC_IVAS_mode != 0 && LT_32( sum_bit, *bit ) ) /* If we need to add bits, we are doing it on the LF */ { - reajust_bits_fx( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit ); + reajust_bits_fx( bits_per_bands, 0, nb_bands, (Word16) sum_bit, *bit ); } ELSE { - reajust_bits_fx( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit ); + reajust_bits_fx( bits_per_bands, sub( nb_bands, 1 ), 0, (Word16) sum_bit, *bit ); } w_sum_bit = 0; move16(); @@ -984,9 +1044,11 @@ void bands_and_bit_alloc_ivas_fx( } ELSE /* *bit == 0 */ { - set_s( out_bits_per_bands, 0, nb_tot_bands ); + set16_fx( out_bits_per_bands, 0, nb_tot_bands ); *nb_subbands = 0; + move16(); *pvq_len = 0; + move16(); } #endif return; @@ -1019,19 +1081,19 @@ static void reajust_bits_fx( IF( LT_16( bit_bdgt_in, sum_bit_in ) ) { amount_to_add = -1; - bit_bdgt = sum_bit_in; - sum_bit = bit_bdgt_in; move16(); + bit_bdgt = sum_bit_in; move16(); + sum_bit = bit_bdgt_in; move16(); } ELSE { bit_bdgt = bit_bdgt_in; - sum_bit = sum_bit_in; - amount_to_add = 1; move16(); + sum_bit = sum_bit_in; move16(); + amount_to_add = 1; move16(); } @@ -1051,7 +1113,7 @@ static void reajust_bits_fx( } i = add( i, incr ); - IF( EQ_16( i, end_band ) ) + if ( EQ_16( i, end_band ) ) { i = st_band; move16(); diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index e81af00c84eb13cd4b23adbb046224ba712281ae..4de024088b91d5d005196915898c47bd143487d6 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -37,8 +37,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stl.h" /*-------------------------------------------------------------------* @@ -111,6 +110,7 @@ void Comp_and_apply_gain_fx( L32 = L_shl( L_mult( exc_diffQ[i], y_gain ), tmp_exp ); /*Q_exc+16 */ exc_diffQ[i] = round_fx( L32 ); /*Q_exc */ #endif /* BASOP_NOGLOB */ + move16(); } } ELSE @@ -223,7 +223,7 @@ void Ener_per_band_comp_fx( IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); move16(); pt_fx += 32; } @@ -237,7 +237,7 @@ void Ener_per_band_comp_ivas_fx( const Word16 Q_exc, /* i : frame length */ const Word16 Mband, /* i : Max band */ const Word16 Eflag, /* i : flag of highest band */ - const int16_t L_frame /* i : frame length */ + const Word16 L_frame /* i : frame length */ ) { const Word16 *pt_fx; @@ -260,12 +260,12 @@ void Ener_per_band_comp_ivas_fx( IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); move16(); pt_fx += 32; } - if ( L_frame == L_FRAME16k ) + IF( EQ_16( L_frame, L_FRAME16k ) ) { y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); move16(); @@ -296,7 +296,7 @@ static void GSC_gain_adj( /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ Word16 Gain_off, i; - IF( NE_16( coder_type, INACTIVE ) ) + IF( coder_type != INACTIVE ) { FOR( i = 0; i < MBANDS_GN; i++ ) { @@ -369,6 +369,7 @@ static void GSC_gain_adj_ivas_fx( /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ Word16 Gain_off, i; + test(); IF( NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) { FOR( i = 0; i < Mbands_gn; i++ ) @@ -383,6 +384,8 @@ static void GSC_gain_adj_ivas_fx( { Gain_off = 0; move16(); + + test(); IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) { Gain_off = 18432; @@ -467,27 +470,27 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai test(); IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } ELSE { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 7 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); @@ -515,7 +518,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai } ELSE { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); @@ -524,10 +527,10 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai /*--------------------------------------------------------------------------------------* * UQ of the first 8 bands and half of the last 8 bands *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); /*----------------------------------------------------------------------* @@ -535,7 +538,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai * And scaling *----------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); @@ -568,16 +571,16 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai } ELSE { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4 ); } } @@ -631,27 +634,26 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc test(); IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); - move16(); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } ELSE { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 7 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } test(); @@ -679,7 +681,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc } ELSE { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); @@ -688,10 +690,10 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc /*--------------------------------------------------------------------------------------* * UQ of the first 8 bands and half of the last 8 bands *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); /*----------------------------------------------------------------------* @@ -699,7 +701,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc * And scaling *----------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); @@ -717,6 +719,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc { /*y_gainQ_fx[i] *= 1.41f;*/ y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ + move16(); } /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands @@ -732,35 +735,35 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc } ELSE { - if ( st_fx->L_frame == L_FRAME ) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - idx_g_fx = (Word16) get_next_indice( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 5 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 ); - idx_g_fx = (Word16) get_next_indice( st_fx, 4 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4 ); } - else + ELSE { - idx_g_fx = get_next_indice( st_fx, 7 ); + idx_g_fx = get_next_indice_fx( st_fx, 7 ); VDQ_vec_fx( y_gainQ_fx, YG_mean16HR_fx, YG_dicHR_1_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice( st_fx, 6 ); + idx_g_fx = get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16HR_fx + 4, YG_dicHR_2_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice( st_fx, 6 ); + idx_g_fx = get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16HR_fx + 8, YG_dicHR_3_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice( st_fx, 6 ); + idx_g_fx = get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16HR_16kHz_fx, YG_dicHR_4_16kHz_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice( st_fx, 3 ); + idx_g_fx = get_next_indice_fx( st_fx, 3 ); VDQ_vec_fx( y_gainQ_fx + 16, YG_meanL2G_16kHz_fx, YG_dicL2G_16kHz_fx, idx_g_fx, 2 ); } } @@ -799,7 +802,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && ( bwidth == NB ) ) { /*ftmp1 = mean(y_gain4, 10)-0.6f;*/ @@ -827,6 +830,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ /* Quantized mean gain without clipping */ mean_4g[0] = round_fx( L_tmp ); + move16(); idx_g = vquant_fx( mean_4g, Gain_meanNB_fx, mean_4g, Gain_mean_dicNB_fx, 1, 64 ); push_indice_fx( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); @@ -863,12 +867,18 @@ Word16 gsc_gainQ_fx( /*Q12*/ /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ y_gain_tmp[10] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[6], 8192 ), y_gain_tmp[7], 8192 ), y_gain_tmp[8], 8192 ) ); + move16(); y_gain_tmp[11] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[7], 8192 ), y_gain_tmp[8], 8192 ), y_gain_tmp[9], 8192 ) ); + move16(); y_gain_tmp[12] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[8], 8192 ), y_gain_tmp[9], 8192 ), y_gain_tmp[10], 8192 ) ); + move16(); y_gain_tmp[13] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[9], 8192 ), y_gain_tmp[10], 8192 ), y_gain_tmp[11], 8192 ) ); + move16(); y_gain_tmp[14] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[10], 8192 ), y_gain_tmp[11], 8192 ), y_gain_tmp[12], 8192 ) ); + move16(); y_gain_tmp[15] = round_fx( L_mac( L_mac( L_mult( y_gain_tmp[11], 8192 ), y_gain_tmp[12], 8192 ), y_gain_tmp[13], 8192 ) ); + move16(); } ELSE { @@ -880,6 +890,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ /*ftmp1 = mean(y_gain4, 16);*/ L_tmp = 0; + move32(); FOR( cnt = 0; cnt < 16; cnt++ ) { L_tmp = L_mac( L_tmp, y_gain4[cnt], 2048 ); @@ -889,6 +900,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ tmp1 = sub( tmp16, 4915 ); tmp2 = add( tmp16, 4915 ); L_tmp = 0; + move32(); FOR( i = 0; i < 16; i++ ) { y_gain_tmp2[i] = y_gain4[i]; @@ -904,8 +916,10 @@ Word16 gsc_gainQ_fx( /*Q12*/ FOR( ; i < Mbands_gn; i++ ) { y_gain_tmp2[i] = y_gain4[i]; + move16(); /*if(y_gain4[i] < ftmp1-0.6f)*/ y_gain_tmp2[i] = s_max( y_gain_tmp2[i], tmp1 ); /* Just the last move is needed, because s_max and s_min could be done in 1 line*/ + move16(); /*else if(y_gain4[i] > ftmp1+0.6f)*/ y_gain_tmp2[i] = s_min( y_gain_tmp2[i], tmp2 ); move16(); @@ -913,6 +927,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ /* Quantized mean gain without clipping */ mean_4g[0] = round_fx( L_tmp ); + move16(); /*idx_g = (short)vquant(mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64);*/ @@ -940,6 +955,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ move16(); idx_g = 0; + move16(); /*idx_g = (short)vquant(y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32);*/ idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); @@ -962,6 +978,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 ); y_gain_tmp[15] = y_gain_tmp2[11]; + move16(); ifft_rel_fx( y_gain_tmp + 8, 8, 3 ); FOR( i = 8; i < 16; i++ ) diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 16fbddb4136c31409f816a86fbdd27766235ee4b..01a0556208933370f8cb507ed705e700f5df5b3d 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* @@ -137,6 +136,7 @@ void Inac_swtch_ematch_fx( L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx( L_tmp ); #endif + move16(); pt_exc++; } } @@ -152,6 +152,7 @@ void Inac_swtch_ematch_fx( L_tmp = L_shl( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ *pt_exc = round_fx( L_tmp ); /*Q_exc*/ #endif + move16(); pt_exc++; } } @@ -243,6 +244,7 @@ void Inac_switch_ematch_ivas_fx( L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ + move16(); ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ @@ -263,6 +265,7 @@ void Inac_switch_ematch_ivas_fx( L_tmp = L_mult0( *pt_exc, ftmp ); L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/ *pt_exc = round_fx_sat( L_tmp ); /*Q_exc - 1*/ + move16(); pt_exc++; } } @@ -273,6 +276,7 @@ void Inac_switch_ematch_ivas_fx( L_tmp = L_mult0( *pt_exc, ftmp ); L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/ *pt_exc = round_fx_sat( L_tmp ); /*Q_exc - 1*/ + move16(); pt_exc++; } } diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 1809a1f6f2320e2e13c4c65da33983fec3c3e008..2dea2adef957003bf5943d58b7576da6feb92116 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * gs_noisf() @@ -96,17 +95,17 @@ static void EstimateNoiseLevel_inner_fx( noise_offset = 8192; move16(); /*0.25f * 32768 */ - IF( bitrate > ACELP_24k40 ) + IF( GT_32( bitrate, ACELP_24k40 ) ) { noise_offset = 6554; move16(); /*.2f * 32768 */ } - ELSE IF( bitrate >= ACELP_22k60 ) + ELSE IF( GE_32( bitrate, ACELP_22k60 ) ) { noise_offset = 9830; move16(); /*.3f * 32768 */ } - ELSE IF( bitrate >= ACELP_9k60 ) + ELSE IF( GE_32( bitrate, ACELP_9k60 ) ) { noise_offset = 11469; move16(); /*0.35f * 32768 */ @@ -194,6 +193,7 @@ static void EstimateNoiseLevel_fx( } } test(); + test(); IF( ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) ) { FOR( i_band = 9; i_band < Mbands_gn; i_band++ ) @@ -280,8 +280,7 @@ static void Apply_NoiseFill_fx( FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { - StartBin += NB_Qbins; - move16(); + StartBin = add( StartBin, NB_Qbins ); NB_Qbins = freq_nsbin_per_band[i_band]; move16(); @@ -333,7 +332,7 @@ void freq_dnw_scaling_fx( start_sc = L_frame; move16(); test(); - IF( LE_32( core_brate, ACELP_8k00 ) && EQ_16( coder_type, INACTIVE ) ) + IF( LE_32( core_brate, ACELP_8k00 ) && ( coder_type == INACTIVE ) ) { sc_dyn = mult_r( sc_dyn, 4915 ); /*Q15 (0.15 in Q15) */ start_sc = 64; @@ -357,6 +356,7 @@ void freq_dnw_scaling_fx( } } + test(); IF( EQ_16( L_frame, L_FRAME16k ) && LE_32( core_brate, ACELP_24k40 ) ) { /*sc_dyn += 0.125f;*/ @@ -411,12 +411,15 @@ static void Decreas_freqPeak_fx( Word16 tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif move16(); /*ptr init*/ lsf_new_diff[0] = 0; /* prevent unitialized value */ + move16(); FOR( j = 1; j < ( M - 1 ); j++ ) { lsf_new_diff[j] = sub( lsf_new[j], lsf_new[j - 1] ); /*Qx2.56 */ + move16(); } avrg = 0; @@ -479,6 +482,7 @@ static void Decreas_freqPeak_fx( tmp1 = negate( tmp ); tmp2 = *src; + move16(); *( src ) = tmp1; move16(); if ( tmp2 > 0 ) @@ -528,6 +532,7 @@ static void envelop_modify_fx( Word16 Q_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif start_band = i_mult( last_bin, 16 ); @@ -550,7 +555,8 @@ static void envelop_modify_fx( move16(); Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */ - weight_fx = 16384; /*Q15 */ + weight_fx = 16384; /*Q15 */ + move16(); src_fx = &exc_diffQ_fx[start_band]; /*Q_exc */ FOR( i = last_bin; i < last_bin + 4; i++ ) { @@ -578,7 +584,7 @@ static void envelop_modify_fx( L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ tmp1 = round_fx( L_shr( L_tmp, 2 ) ); - L_exc_diffQ_fx[16 * i + j] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -609,7 +615,7 @@ static void envelop_modify_fx( L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ tmp1 = round_fx( L_shr( L_tmp, 2 ) ); /*Q12 */ - L_exc_diffQ_fx[16 * i + j] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -618,7 +624,7 @@ static void envelop_modify_fx( move16(); FOR( i = start_band; i < L_FRAME; i++ ) { - IF( GT_32( L_abs( L_exc_diffQ_fx[i] ), exc_diffQ_max ) ) + if ( GT_32( L_abs( L_exc_diffQ_fx[i] ), exc_diffQ_max ) ) { exc_diffQ_max = L_abs( L_exc_diffQ_fx[i] ); } @@ -632,6 +638,7 @@ static void envelop_modify_fx( FOR( i = start_band; i < L_FRAME; i++ ) { exc_diffQ_fx[i] = extract_l( L_exc_diffQ_fx[i] ); + move16(); } } ELSE @@ -641,6 +648,7 @@ static void envelop_modify_fx( FOR( i = start_band; i < L_FRAME; i++ ) { exc_diffQ_fx[i] = extract_l( L_shr( L_exc_diffQ_fx[i], Q_tmp ) ); + move16(); } } @@ -783,11 +791,13 @@ void highband_exc_dct_in_fx( } test(); - + test(); + test(); IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { set16_fx( noisepb, 3277, MBANDS_GN ); } + test(); IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) { FOR( i = 0; i < L_frame; i++ ) @@ -829,6 +839,7 @@ void highband_exc_dct_in_fx( tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ + move16(); } } } @@ -1211,6 +1222,10 @@ void highband_exc_dct_in_ivas_fx( move16(); } + test(); + test(); + test(); + test(); IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) { set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ @@ -1229,12 +1244,15 @@ void highband_exc_dct_in_ivas_fx( Copy( exc_diffQ, exc_wo_nf, L_frame ); } + test(); test(); IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { set16_fx( noisepb, 3277, MBANDS_GN ); } + + test(); IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) { FOR( i = 0; i < L_frame; i++ ) @@ -1268,6 +1286,7 @@ void highband_exc_dct_in_ivas_fx( { Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); + test(); IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) { FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) @@ -1276,6 +1295,7 @@ void highband_exc_dct_in_ivas_fx( tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ + move16(); } } } @@ -1328,23 +1348,30 @@ void highband_exc_dct_in_ivas_fx( { // float scale_factLF = 0.9f; Word16 scale_factLF = 29491; + move16(); // float scale_factHF = 0.9f; Word16 scale_factHF = 29491; + move16(); - IF( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 ) + test(); + test(); + IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 ) { // scale_factHF = 0.8f; scale_factHF = 26214; + move16(); } - ELSE IF( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 ) + ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) ) { // scale_factHF = 0.71f; scale_factHF = 23265; + move16(); } - ELSE IF( GSC_IVAS_mode == 3 ) + ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) ) { // scale_factHF = 0.9f; scale_factHF = 29491; + move16(); } FOR( i = 0; i < pit_band_idx * 16; i++ ) { @@ -1355,44 +1382,51 @@ void highband_exc_dct_in_ivas_fx( { // exc_diffQ[i] *= scale_factHF; exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF ); + move16(); } } ELSE IF( GSC_noisy_speech ) { // float scale_fact = 0.9f; Word16 scale_fact = 29491; + move16(); - IF( element_mode == IVAS_CPE_TD ) + IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { IF( coder_type == INACTIVE ) { // scale_fact = 1.0f; scale_fact = 32767; + move16(); } ELSE { // scale_fact = 0.95f; scale_fact = 31129; + move16(); } } - ELSE IF( element_mode > IVAS_SCE ) + ELSE IF( GT_16( element_mode, IVAS_SCE ) ) { // scale_fact = 0.71f; scale_fact = 23265; + move16(); } FOR( i = 0; i < L_frame; i++ ) { // exc_diffQ[i] *= scale_fact; exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact ); + move16(); } } - IF( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 ) + IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) ) { FOR( i = 80; i < L_frame; i++ ) { // exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ ); + move16(); } } #else @@ -1421,7 +1455,7 @@ void highband_exc_dct_in_ivas_fx( Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame ); test(); - IF( core_brate == ACELP_8k00 && bwidth != NB ) + IF( EQ_32( core_brate, ACELP_8k00 ) && bwidth != NB ) { IF( EQ_16( bwe_flag, 1 ) ) { diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 36487d90fc51331bed25deeb7f12b4a09ab57ad7..1c3c3ccfebe23fc6a268c80417435302aad0e5c1 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -41,8 +41,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * Local constants @@ -159,7 +158,7 @@ void pre_echo_att_fx( Word16 att_len; test(); - IF( GT_16( gsc_attack_flag_fx, 0 ) && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ + IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ { /*-------------------------------------------------------------------------* * Find where the onset (attack) occurs by computing the energy per section @@ -167,9 +166,11 @@ void pre_echo_att_fx( * gradual onset *-------------------------------------------------------------------------*/ att_len = ATT_LENGHT; - if ( L_frame == L_FRAME16k ) + move16(); + if ( EQ_16( L_frame, L_FRAME16k ) ) { att_len = ATT_LENGHT16k; + move16(); } FOR( i = 0; i < att_len; i++ ) { @@ -210,6 +211,7 @@ void pre_echo_att_fx( /* = isqrt(etmp/(*Last_frame_ener)) */ etmp_fx = L_max( etmp_fx, 1 ); *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); + move32(); n1 = norm_l( etmp_fx ); n2 = norm_l( *Last_frame_ener_fx ); @@ -234,6 +236,7 @@ void pre_echo_att_fx( { /*exc_fx[i] *= ratio_fx;*/ exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) ); + move16(); } } *Last_frame_ener_fx = etmp1_fx; diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index 87ab481438797fde15361be6dfddd7e690d51d9c..2610a7693db6701bbede427b8115aacb58e30e2f 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" #include "rom_basop_util.h" @@ -71,6 +70,7 @@ void updateLSFForConcealment( L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); + move16(); decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; move16(); decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; @@ -96,7 +96,6 @@ void getConcealedLP( Word16 lsp[( NB_DIV + 1 ) * M]; Word32 int_fs; - move16(); lsf = memDecState->lsf_con; diff --git a/lib_com/hp50.c b/lib_com/hp50.c index b080d0431eb53527d8b9af7f07afb761bdbcf47d..dbabd5632224e2cabe735a9c4b6a333e6289b703 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -39,8 +39,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /* * hp20 @@ -200,7 +199,7 @@ static void filter_2nd_order( BASOP_SATURATE_ERROR_ON_EVS L_sum = HP50_Mpy_32_32_fix( b2, mem[2] ); /* b2*x2 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( b1, mem[3] ) ); /* b1*x1 */ - x2 = shr( signal[0 * stride], prescale ); + x2 = shr( signal[0], prescale ); L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x2 ) ); /* b2*x0 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[0], a2 ) ); /* y2*a2 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a1 ) ); /* y1*a1 */ @@ -213,16 +212,16 @@ static void filter_2nd_order( BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[0 * stride] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); + signal[0] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - signal[0 * stride] = round_fx( L_shl( L_y2, prescale ) ); + signal[0] = round_fx( L_shl( L_y2, prescale ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS BASOP_SATURATE_ERROR_ON_EVS L_sum = HP50_Mpy_32_32_fix( b2, mem[3] ); /* b2*x2 */ L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b1, x2 ) ); /* b1*x1 */ - x1 = shr( signal[1 * stride], prescale ); + x1 = shr( signal[stride], prescale ); L_sum = L_add( L_sum, HP50_Mode2_Mpy_32_16_fix( b2, x1 ) ); /* b2*x0 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a2 ) ); /* y2*a2 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); /* y1*a1 */ @@ -235,11 +234,12 @@ static void filter_2nd_order( BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[1 * stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); + signal[stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - signal[1 * stride] = round_fx( L_shl( L_y1, prescale ) ); + signal[stride] = round_fx( L_shl( L_y1, prescale ) ); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS + move16(); /* New we use a trick and toggle x1/x2 and L_y1/L_y2 to save a few cycles unrolling the loop by 2 */ FOR( i = 2; i < lg; i += 2 ) @@ -261,9 +261,10 @@ static void filter_2nd_order( BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[i * stride] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); + signal[i_mult( i, stride )] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - signal[i * stride] = round_fx( L_shl( L_y2, prescale ) ); + signal[i_mult( i, stride )] = round_fx( L_shl( L_y2, prescale ) ); + move16(); #endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */ @@ -283,11 +284,12 @@ static void filter_2nd_order( BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - signal[( i + 1 ) * stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); + signal[i_mult( add( i, 1 ), stride )] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); #else /* BASOP_NOGLOB */ - signal[( i + 1 ) * stride] = round_fx( L_shl( L_y1, prescale ) ); + signal[i_mult( add( i, 1 ), stride )] = round_fx( L_shl( L_y1, prescale ) ); #endif BASOP_SATURATE_WARNING_ON_EVS + move16(); } /* update static filter memory from variables */ mem[0] = L_y2; @@ -295,7 +297,9 @@ static void filter_2nd_order( mem[1] = L_y1; move32(); mem[2] = L_deposit_h( x2 ); + move32(); mem[3] = L_deposit_h( x1 ); + move32(); return; diff --git a/lib_com/hq2_bit_alloc.c b/lib_com/hq2_bit_alloc.c index cd7f17aab8c611f11186312ce45654a53bb71d70..3b1cda25de708b46d32206c16c3813d4a9590fc8 100644 --- a/lib_com/hq2_bit_alloc.c +++ b/lib_com/hq2_bit_alloc.c @@ -38,6 +38,7 @@ #include "options.h" #include #include "prot.h" +#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" #include "stl.h" @@ -61,7 +62,7 @@ #define BITS_FACT_0p92 ( Word16 )( 0.92f * (float) pow( 2, Qbf ) + 0.5f ) #define L_Comp( hi, lo ) L_mac( L_deposit_h( hi ), lo, 1 ) - +#if 0 // functions already present in hq2_bit_alloc_fx.c /*------------------------------------------------------------------- * div_s_ss() * @@ -216,7 +217,7 @@ static void Bits2indvsb_fx( th_5_fx = shl( 5, QRavg ); FOR( j = 0; j < be_cnt_fx; j++ ) { - IF( sub( abs_s( sub( Ravg_fx, shl( y_index_fx[j], QRavg ) ) ), th_5_fx ) > 0 ) + if ( sub( abs_s( sub( Ravg_fx, shl( y_index_fx[j], QRavg ) ) ), th_5_fx ) > 0 ) { enr_diffcnt_fx = add( enr_diffcnt_fx, 1 ); } @@ -308,7 +309,7 @@ static void Bits2indvsb_fx( return; } - +#endif /*-------------------------------------------------------------------* * hq2_bit_alloc_har() * @@ -388,7 +389,7 @@ void hq2_bit_alloc_har( L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); - set_val_Word16( Bits_grp_fx, 0, GRP_SB ); + set16_fx( Bits_grp_fx, 0, GRP_SB ); /* Initialize subbands bits allocation vector based on harmonic bands */ harmonic_band_fx = add( sub( N_fx, p2a_bands_fx ), 1 ); @@ -461,10 +462,12 @@ void hq2_bit_alloc_har( } gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + move16(); } ELSE { gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + move16(); } } @@ -477,7 +480,7 @@ void hq2_bit_alloc_har( } grp_bound_fx[i] = harmonic_band_fx; move16(); - grp_bound_fx[i + 1] = N_fx; + grp_bound_fx[add( i, 1 )] = N_fx; move16(); @@ -575,7 +578,7 @@ void hq2_bit_alloc_har( FOR( i = 0; i < sub( N_fx, harmonic_band_fx ); i++ ) { - y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); + y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[add( harmonic_band_fx, i )], sub( 16, SWB_BWE_LR_Qbe ) ) ); move16(); index_fx[i] = add( harmonic_band_fx, i ); move16(); @@ -643,6 +646,7 @@ void hq2_bit_alloc_har( #ifdef BASOP_NOGLOB lf_hf_ge_r_fx = round_fx_o( L_shl_o( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ), &Overflow ), &Overflow ); Overflow = 0; /* reset BASOP Overflow */ + move16(); #else lf_hf_ge_r_fx = round_fx( L_shl( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) ); #endif @@ -694,24 +698,30 @@ void hq2_bit_alloc_har( L_temp = Mpy_32_16_1( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); L_temp = Mpy_32_16_1( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); L_temp = Mpy_32_16_1( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); L_temp = Mpy_32_16_1( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); + move16(); } ELSE { L_temp = Mpy_32_16_1( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); L_temp = Mpy_32_16_1( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); L_temp = Mpy_32_16_1( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); L_temp = Mpy_32_16_1( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); + move16(); } IF( sub( Bits_grp_fx[2], THR2 ) < 0 ) @@ -730,10 +740,10 @@ void hq2_bit_alloc_har( } ELSE { - set_val_Word32( L_Rsubband + grp_bound_fx[i], 0x0L, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); + set32_fx( L_Rsubband + grp_bound_fx[i], 0x0L, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); IF( sub( i, GRP_SB - 1 ) == 0 ) { - set_val_Word16( p2a_flags_fx + grp_bound_fx[i], 0, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); + set16_fx( p2a_flags_fx + grp_bound_fx[i], 0, sub( grp_bound_fx[i + 1], grp_bound_fx[i] ) ); } } } @@ -794,7 +804,7 @@ void hq2_bit_alloc( /* Init Rk to non-zero values for bands to be allocated bits */ IF( sub( num_bits, HQ_16k40_BIT ) <= 0 ) { - set_val_Word32( L_Rk, (Word32) ( C1_QRk ), bands ); /* 1< #include "options.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #define MIN_BITS_FIX 0 /* QRk=18 */ @@ -100,6 +100,7 @@ void Bits2indvsb_fx( FOR( i = 0; i < band_num_fx; i++ ) { y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); + move16(); index_fx[i] = i; move16(); } @@ -120,6 +121,7 @@ void Bits2indvsb_fx( y_index_fx[j] = 0; move16(); L_R_temp[j] = L_deposit_l( 0 ); + move32(); } ELSE { @@ -310,6 +312,12 @@ void hq2_bit_alloc_har_fx( Word16 exp_shift; +#ifdef BASOP_NOGLOB + Flag Overflow; + Overflow = 0; + move32(); +#endif + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); @@ -370,14 +378,13 @@ void hq2_bit_alloc_har_fx( { FOR( temp_fx = 2; temp_fx <= k_fx; ) { - IF( LT_32( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) + IF( LT_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) { BREAK; } - ELSE IF( GE_32( L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) + ELSE IF( GE_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) { temp_fx = add( temp_fx, 1 ); - ; IF( GT_16( temp_fx, k_fx ) ) { temp_fx = sub( temp_fx, 1 ); @@ -405,7 +412,7 @@ void hq2_bit_alloc_har_fx( } grp_bound_fx[i] = harmonic_band_fx; move16(); - grp_bound_fx[i + 1] = N_fx; + grp_bound_fx[add( i, 1 )] = N_fx; move16(); @@ -441,6 +448,7 @@ void hq2_bit_alloc_har_fx( G1_BE_DIFF_POS_fx = j; move16(); L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + move32(); } } @@ -502,6 +510,7 @@ void hq2_bit_alloc_har_fx( FOR( i = 0; i < j; i++ ) { y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); + move16(); index_fx[i] = add( harmonic_band_fx, i ); move16(); } @@ -563,7 +572,13 @@ void hq2_bit_alloc_har_fx( L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ +#ifdef BASOP_NOGLOB + lf_hf_ge_r_fx = round_fx_o( L_shl_o( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ), &Overflow ), &Overflow ); + Overflow = 0; /* reset BASOP Overflow */ + move32(); +#else lf_hf_ge_r_fx = round_fx( L_shl( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) ); +#endif exp_normn = norm_s( norm_sum_fx ); exp_normn = sub( exp_normn, 1 ); @@ -592,6 +607,7 @@ void hq2_bit_alloc_har_fx( L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); + move16(); Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); move16(); @@ -613,10 +629,12 @@ void hq2_bit_alloc_har_fx( L_temp = Mult_32_16( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); move16(); @@ -626,10 +644,12 @@ void hq2_bit_alloc_har_fx( L_temp = Mult_32_16( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + move16(); Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); move16(); @@ -721,13 +741,21 @@ Word32 hq2_bit_alloc_fx( IF( is_transient && EQ_16( bands, 32 ) ) { L_Rk[6] = L_deposit_l( 0 ); + move32(); L_Rk[7] = L_deposit_l( 0 ); + move32(); L_Rk[14] = L_deposit_l( 0 ); + move32(); L_Rk[15] = L_deposit_l( 0 ); + move32(); L_Rk[22] = L_deposit_l( 0 ); + move32(); L_Rk[23] = L_deposit_l( 0 ); + move32(); L_Rk[30] = L_deposit_l( 0 ); + move32(); L_Rk[31] = L_deposit_l( 0 ); + move32(); } } ELSE @@ -736,6 +764,7 @@ Word32 hq2_bit_alloc_fx( FOR( k = 0; k < bands; k++ ) { L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); + move32(); } } @@ -814,6 +843,7 @@ Word32 hq2_bit_alloc_fx( IF( LT_32( L_Rk[k], MIN_BITS_FIX ) ) { L_Rk[k] = L_deposit_l( 0 ); + move32(); negflag = 1; move16(); } @@ -846,9 +876,10 @@ Word32 hq2_bit_alloc_fx( } /* prune worst allocation and recalculate total allocation */ - if ( GT_16( maxdex_fx, -1 ) ) + IF( GT_16( maxdex_fx, -1 ) ) { L_Rk[maxdex_fx] = L_deposit_l( 0 ); + move32(); } FOR( k = 0; k < bands; k++ ) { @@ -875,14 +906,17 @@ Word32 hq2_bit_alloc_fx( IF( LT_16( k, 11 ) && LT_32( L_Rk[k], L_THR1 ) ) { L_Rk[k] = L_deposit_l( 0 ); + move32(); } ELSE IF( GE_16( k, 11 ) && LT_16( k, 16 ) && LT_32( L_Rk[k], L_THR2 ) ) { L_Rk[k] = L_deposit_l( 0 ); + move32(); } ELSE if ( GE_16( k, 16 ) && LT_16( k, bands ) && LT_32( L_Rk[k], L_THR3 ) ) { L_Rk[k] = L_deposit_l( 0 ); + move32(); } L_dummy = L_add( L_dummy, L_Rk[k] ); @@ -898,9 +932,9 @@ Word32 hq2_bit_alloc_fx( FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { test(); - IF( p2a_flags[bands - NB_SWB_SUBBANDS + k] == 1 && L_Rk[bands - NB_SWB_SUBBANDS + k] == 0 ) + IF( EQ_16( p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )], 1 ) && L_Rk[add( sub( bands, NB_SWB_SUBBANDS ), k )] == 0 ) { - p2a_flags[bands - NB_SWB_SUBBANDS + k] = 0; + p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )] = 0; move16(); bit_budget_temp_fx = sub( bit_budget_temp_fx, bits_lagIndices_modeNormal[k] ); } diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index b00a25aaa6eb4fc79dfc088dfddec8cbc90ad168..206a37bc84924d96ff41c9e14031da2686bf6314 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -35,7 +35,7 @@ #include "options.h" #include "cnst.h" /* Audio core constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------------* diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index c47bb5cfdc986221e43db90caf26669764cdef6c..c7326bd8e6b89b48cd25cae686d473677ceedc28 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -32,7 +32,7 @@ #include #include "options.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "oper_32b.h" #include "move.h" #include "count.h" diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index 8b476fb073f840ab6e851c7c741e775bfbc72c1b..4ac2252f840d40a1b38e68171127c7698e8d20aa 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "stl.h" /* required for wmc_tool */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "stl.h" /* required for wmc_tool */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_com/hq_conf.c b/lib_com/hq_conf.c index 4dfe55d80573342be9894ee43f2fd5df814cb953..d96448b02f216491c3fce4087f508b2b84de9d75 100644 --- a/lib_com/hq_conf.c +++ b/lib_com/hq_conf.c @@ -40,8 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------------* * hq_configure() diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index bed185ae137f3046b79091592a31002331cfcd0f..eb675986b941327f64030740700e97dcf40ef763 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -4,10 +4,9 @@ #include #include "options.h" -#include "cnst.h" /* Audio core constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Audio core constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index ae3468c9ae1f3d10c65be8a422e96b96a90629c4..d9f95a06b41553a518ce2dbf7c50e9f5315c5177 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -38,7 +38,7 @@ #include "options.h" /* Compilation switches */ #include "rom_com.h" /* Static table prototypes FIP version */ #include "stl.h" /* required for wmc_tool */ -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -1892,7 +1892,7 @@ Word16 get_nor_delta_hf_fx( move16(); IF( GE_16( core_sfm, num_env_bands ) ) { - bitsforDelta = (Word16) get_next_indice( st, 2 ); + bitsforDelta = (Word16) get_next_indice_fx( st, 2 ); bitsforDelta = add( bitsforDelta, 2 ); add_bits_denv = add( add_bits_denv, 2 ); @@ -1900,7 +1900,7 @@ Word16 get_nor_delta_hf_fx( { IF( Rsubband[i] != 0 ) { - delta = (Word16) get_next_indice( st, bitsforDelta ); + delta = (Word16) get_next_indice_fx( st, bitsforDelta ); ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); move16(); diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index 487aaf2ea8f2448aba21fca1e06946d0747fda3d..4775f1b7822e808553fe60c62d10bf39ec7a6315 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -5,9 +5,8 @@ #include "options.h" /* Compilation switches */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ /*--------------------------------------------------------------------------*/ /* Function hvq_pvq_bitalloc */ diff --git a/lib_com/ifft_rel.c b/lib_com/ifft_rel.c index c1e8687164023acb56bfb7058aa975788b939c0b..43aa3f122860712ab0f33bb466f36ad5bbd2c492 100644 --- a/lib_com/ifft_rel.c +++ b/lib_com/ifft_rel.c @@ -39,8 +39,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ diff --git a/lib_com/igf_base.c b/lib_com/igf_base.c index 658707947596e3ea302bdc14adcb938822c7d3dd..637dd0270ff48384dddfc988071a41b7ae7e3284 100644 --- a/lib_com/igf_base.c +++ b/lib_com/igf_base.c @@ -41,7 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif /*---------------------------------------------------------------------* diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index ac1a1bcdeeb86a66761814c1376634393e0f47fc..022720707b89f513cd299cc8eeba1b5c2fb3f740 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -8,8 +8,7 @@ #include #include "options.h" #include "stl.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c index 2f75d8ac8233234b8294532ce0e91d59fc149e75..3ca87f63825890d0c13eb85534e52d95ee28d7b5 100644 --- a/lib_com/index_pvq_opt_fx.c +++ b/lib_com/index_pvq_opt_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */ diff --git a/lib_com/int_lsp.c b/lib_com/int_lsp.c index a340281f7b2e553b09996f374e751676f3fefc85..b6528030e17949b4ff1af298ed0996668d5d87ae 100644 --- a/lib_com/int_lsp.c +++ b/lib_com/int_lsp.c @@ -40,8 +40,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*---------------------------------------------------------------------* * int_lsp() @@ -130,13 +129,17 @@ void int_lsp_fx( move16(); fold = sub( 32767, fnew ); /* 1.0 - fac_new */ if ( fold != 0 ) + { fold = add( fold, 1 ); + } FOR( i = 0; i < m; i++ ) { L_tmp = L_mult( lsp_old[i], fold ); L_tmp = L_mac( L_tmp, lsp_new[i], fnew ); - if ( fold == 0 ) + IF( fold == 0 ) + { L_tmp = L_mac( L_tmp, lsp_new[i], 1 ); /* 'fnew' should have been 32768 */ + } lsp[i] = round_fx( L_tmp ); } IF( Opt_AMR_WB ) @@ -302,7 +305,7 @@ void int_lsp4_fx( move16(); E_LPC_f_lsp_a_conversion( lsp, Aq, m ); - Aq += ( m + 1 ); + Aq += add( m, 1 ); move16(); } diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c index 12e628fb79fb90dbbbd5a725276c2894eb69cf3b..9fdba4c77be73760a2090220daecf80eb3a7304f 100644 --- a/lib_com/interleave_spectrum.c +++ b/lib_com/interleave_spectrum.c @@ -40,8 +40,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -321,6 +320,7 @@ void ivas_de_interleave_spectrum_fx( grps = N_INTL_GRP_48; move16(); l_frame = L_FRAME48k; + move16(); p2 = coefs_out + sublen[2]; /* 240, length/4 */ p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */ p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */ diff --git a/lib_com/interpol.c b/lib_com/interpol.c index 2dfab173b28ffbc49195a1f17ec9b0f89198a8aa..f4e42de2c1b484589ca1fd06d5f677b15a00a7c3 100644 --- a/lib_com/interpol.c +++ b/lib_com/interpol.c @@ -39,8 +39,7 @@ #include "prot.h" #include "wmc_auto.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot_fx_enc.h" /*-------------------------------------------------------------------* diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c index b97bee56d07f80ab684993511aef38cbeef96c21..a054e08ca647166ba149d94525374f38cd1f98c5 100644 --- a/lib_com/isf_dec_amr_wb_fx.c +++ b/lib_com/isf_dec_amr_wb_fx.c @@ -31,10 +31,10 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #ifdef _MSC_VER void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m ); @@ -67,15 +67,15 @@ void isf_dec_amr_wb_fx( IF( EQ_32( st->core_brate, SID_1k75 ) ) { - indice[0] = (Word16) get_next_indice( st, 6 ); + indice[0] = (Word16) get_next_indice_fx( st, 6 ); move16(); - indice[1] = (Word16) get_next_indice( st, 6 ); + indice[1] = (Word16) get_next_indice_fx( st, 6 ); move16(); - indice[2] = (Word16) get_next_indice( st, 6 ); + indice[2] = (Word16) get_next_indice_fx( st, 6 ); move16(); - indice[3] = (Word16) get_next_indice( st, 5 ); + indice[3] = (Word16) get_next_indice_fx( st, 5 ); move16(); - indice[4] = (Word16) get_next_indice( st, 5 ); + indice[4] = (Word16) get_next_indice_fx( st, 5 ); move16(); disf_ns_28b_fx( indice, isf_new ); @@ -93,34 +93,34 @@ void isf_dec_amr_wb_fx( IF( EQ_32( st->core_brate, ACELP_6k60 ) ) { - indice[0] = (Word16) get_next_indice( st, 8 ); + indice[0] = (Word16) get_next_indice_fx( st, 8 ); move16(); - indice[1] = (Word16) get_next_indice( st, 8 ); + indice[1] = (Word16) get_next_indice_fx( st, 8 ); move16(); - indice[2] = (Word16) get_next_indice( st, 7 ); + indice[2] = (Word16) get_next_indice_fx( st, 7 ); move16(); - indice[3] = (Word16) get_next_indice( st, 7 ); + indice[3] = (Word16) get_next_indice_fx( st, 7 ); move16(); - indice[4] = (Word16) get_next_indice( st, 6 ); + indice[4] = (Word16) get_next_indice_fx( st, 6 ); move16(); disf_2s_36b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 ); } ELSE { - indice[0] = (Word16) get_next_indice( st, 8 ); + indice[0] = (Word16) get_next_indice_fx( st, 8 ); move16(); - indice[1] = (Word16) get_next_indice( st, 8 ); + indice[1] = (Word16) get_next_indice_fx( st, 8 ); move16(); - indice[2] = (Word16) get_next_indice( st, 6 ); + indice[2] = (Word16) get_next_indice_fx( st, 6 ); move16(); - indice[3] = (Word16) get_next_indice( st, 7 ); + indice[3] = (Word16) get_next_indice_fx( st, 7 ); move16(); - indice[4] = (Word16) get_next_indice( st, 7 ); + indice[4] = (Word16) get_next_indice_fx( st, 7 ); move16(); - indice[5] = (Word16) get_next_indice( st, 5 ); + indice[5] = (Word16) get_next_indice_fx( st, 5 ); move16(); - indice[6] = (Word16) get_next_indice( st, 5 ); + indice[6] = (Word16) get_next_indice_fx( st, 5 ); move16(); disf_2s_46b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 ); @@ -146,7 +146,7 @@ void isf_dec_amr_wb_fx( * A(z) calculation *-------------------------------------------------------------------------------------*/ - if ( st->rate_switching_reset ) + IF( st->rate_switching_reset ) { /*extrapolation instead of interpolation*/ Copy( isp_new, st->lsp_old_fx, M ); @@ -160,13 +160,15 @@ void isf_dec_amr_wb_fx( * Check ISF stability : distance between old ISF and current ISF *------------------------------------------------------------------*/ - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); + move16(); } - else + ELSE { st->stab_fac_fx = lsf_stab_ivas_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); + move16(); } return; diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c index 3b8a95e9320edc52aeedc7c8257da5986e5cb67e..c173e79a24766c24a6d67ee00564a0027e354c65 100644 --- a/lib_com/ivas_agc_com_fx.c +++ b/lib_com/ivas_agc_com_fx.c @@ -45,9 +45,9 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#define SQRKMAX ( 1.5f ) -#define NBITS_DIFFG ( 2 ) -#define DBSTEP ( -6.f ) /* desired dB step value in dB*/ +//#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*/ @@ -70,6 +70,7 @@ void ivas_agc_initWindowFunc_fx( const Word16 *cos_val; a = A_FX; /* for DBSTEP -6.f */ + move16(); SWITCH( length ) { @@ -87,9 +88,10 @@ void ivas_agc_initWindowFunc_fx( BREAK; } - for ( i = 0; i < length; i++ ) + 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 ) ); + pWinFunc[i] = add( MAX_16, extract_l( Mpy_32_16_1( L_sub( cos_val[i], MAX_16 ), a ) ) ); + move16(); } return; @@ -112,12 +114,14 @@ void ivas_agc_calcGainParams_fx( // Word16 nbits; // nbits = NBITS_DIFFG; - assert( EQ_16( numCoeffs, IVAS_SPAR_MAX_DMX_CHS ) ); + assert( numCoeffs == IVAS_SPAR_MAX_DMX_CHS ); *absEmin = s_max( ABS_EMIN_MAX, LOG2_NUMCOEFF_SQRKMAX ); + move16(); // totExp = add( add( *absEmin, AGC_EMAX ), 1 ); /**betaE = (UWord16)ceilf(logf(totExp) * INV_LOG_2);*/ *betaE = (UWord16) LOG2_4; + move16(); /*Bm = (UWord16)ceilf(logf((AGC_EMAX + 1 + 1)) * INV_LOG_2);*/ // Bm = 1; @@ -130,6 +134,8 @@ void ivas_agc_calcGainParams_fx( /**maxAttExp = ((UWord16) powf( 2, Bm ) ) - 2;*/ *maxAttExp = sub( shl( 2, 1 ), 2 ); *maxAttExp = s_min( MAXATTEXP, *maxAttExp ); + move16(); + move16(); return; } diff --git a/lib_com/ivas_arith.c b/lib_com/ivas_arith.c index 852ddee0d678f21a979b1ebeef57daf75d1fce1b..166c8e0ede355e306f7730b479cfea4b48b5f6fe 100644 --- a/lib_com/ivas_arith.c +++ b/lib_com/ivas_arith.c @@ -35,6 +35,8 @@ #include "wmc_auto.h" #include "prot.h" #include "ivas_prot.h" +#include "prot_fx.h" +#include "ivas_prot_fx.h" #include "stat_dec.h" /*-----------------------------------------------------------------------------------------* @@ -45,6 +47,39 @@ * Similar to ari_start_decoding_14bits_fx(), but do not read past frame boundary. *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ari_start_decoding_14bits_ext_1_lfe( + Decoder_State *st, + Tastat *s, + Word16 *extra_bits_read ) +{ + Word32 val; + + IF( GE_16( st->bits_frame, add( st->next_bit_pos, cbitsnew ) ) ) + { + val = get_next_indice_fx( st, cbitsnew ); + } + ELSE + { + Word16 rem_bits; + rem_bits = sub( st->bits_frame, st->next_bit_pos ); + val = get_next_indice_fx( st, rem_bits ); + val = L_shl( val, sub( cbitsnew, rem_bits ) ); + *extra_bits_read = add( *extra_bits_read, sub( cbitsnew, rem_bits ) ); + move16(); + } + + s->low = 0; + s->high = ari_q4new; + s->value = val; + + move32(); + move32(); + move32(); + + return; +} +#else void ivas_ari_start_decoding_14bits_ext_1_lfe( Decoder_State *st, Tastat *s, @@ -71,9 +106,28 @@ void ivas_ari_start_decoding_14bits_ext_1_lfe( return; } - +#endif /* Helper function to determine the symbol. */ +#ifdef IVAS_FLOAT_FIXED +static UWord16 ivas_ari_get_symbol( + const UWord16 *p, + UWord32 range, + UWord32 cum ) +{ + UWord16 symbol; + + symbol = 0; + move16(); + + WHILE( GT_64( W_mult0_32_32( p[symbol + 1], range ), cum ) ) + { + symbol = u_extract_l( UL_addNsD( symbol, 1 ) ); + } + + return symbol; +} +#else static uint16_t ivas_ari_get_symbol( const uint16_t *p, uint32_t range, @@ -91,6 +145,7 @@ static uint16_t ivas_ari_get_symbol( return symbol; } +#endif /*--------------------------------------------------------------- * Function ivas_ari_decode_14bits_bit_ext_1_lfe() @@ -98,6 +153,86 @@ static uint16_t ivas_ari_get_symbol( * *-------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, + Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read ) +{ + UWord16 symbol; + UWord32 low, high, range, value; + UWord32 cum; + + /* read s->low,high,value sequentially */ + low = s->low; + high = s->high; + value = s->value; + + move32(); + move32(); + move32(); + + range = UL_addNsD( UL_subNsD( high, low ), 1 ); + cum = UL_subNsD( UL_lshl( ( UL_addNsD( UL_subNsD( value, low ), 1 ) ), stat_bitsnew ), 1 ); + + symbol = ivas_ari_get_symbol( cum_freq, range, cum ); + + high = UL_subNsD( UL_addNsD( low, mul_sbc_14bits_ivas( range, cum_freq[symbol] ) ), 1 ); + low = UL_addNsD( low, mul_sbc_14bits_ivas( range, cum_freq[symbol + 1] ) ); + + FOR( ;; ) + { + IF( GE_32( high, ari_q2new ) ) + { + IF( GE_32( low, ari_q2new ) ) + { + value = UL_subNsD( value, ari_q2new ); + low = UL_subNsD( low, ari_q2new ); + high = UL_subNsD( high, ari_q2new ); + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) ) + { + value = UL_subNsD( value, ari_q1new ); + low = UL_subNsD( low, ari_q1new ); + high = UL_subNsD( high, ari_q1new ); + } + ELSE + { + BREAK; + } + } + } + + low = UL_addNsD( low, low ); + high = UL_addNsD( high, UL_addNsD( high, 1 ) ); + + IF( GE_16( st->next_bit_pos, st->bits_frame ) ) + { + value = UL_lshl( value, 1 ); + *extra_bits_read = add( *extra_bits_read, 1 ); + move16(); + } + ELSE + { + value = UL_or( UL_lshl( value, 1 ), get_next_indice_1_fx( st ) ); + } + } + + s->low = low; + s->high = high; + s->value = value; + + move32(); + move32(); + move32(); + + return symbol; +} +#else uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, @@ -166,6 +301,7 @@ uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( return symbol; } +#endif /*--------------------------------------------------------------- * Function ivas_ari_done_decoding_14bits_ext_1_lfe() @@ -173,6 +309,16 @@ uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( * *-------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ari_done_decoding_14bits_ext_1_lfe( + Decoder_State *st, + const Word16 extra_bits_read ) +{ + get_next_indice_tmp( st, negate( sub( cbitsnew - 2, extra_bits_read ) ) ); + + return; +} +#else void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const int16_t extra_bits_read ) @@ -181,6 +327,7 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( return; } +#endif /*--------------------------------------------------------------- @@ -188,7 +335,7 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( * * Arith encoding of last table entry *-------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_ari_done_encoding_14bits( BSTR_ENC_HANDLE hBstr, Tastat *s ) @@ -224,14 +371,51 @@ void ivas_ari_done_encoding_14bits( return; } +#else +void ivas_ari_done_encoding_14bits_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s ) +{ + Word32 low; + Word32 bits_to_follow; + + /* not needed, s points to s->low */ + low = s->low; + move32(); + bits_to_follow = L_add( s->bits_to_follow, 1 ); + + IF( LT_32( low, ari_q1new ) ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + } + } + ELSE + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + } + } + /*It is done so no need to save values-> no counting*/ + /*s->low = low; + s->bits_to_follow = bits_to_follow;*/ + + return; +} +#endif /*--------------------------------------------------------------- * Function ivas_ari_encode_14bits_ext() * * Arith encode function for extended proba tables *-------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_ari_encode_14bits_ext( BSTR_ENC_HANDLE hBstr, Tastat *s, @@ -300,3 +484,80 @@ void ivas_ari_encode_14bits_ext( return; } +#else +void ivas_ari_encode_14bits_ext_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s, + Word32 symbol, + const UWord16 *cum_freq ) +{ + Word32 low, high, range; + Word32 bits_to_follow; + + /*for all operation using bit_ptr=&ptr[bp] */ + /* for reading s->high,low,bits_to_follow sequentially */ + high = s->high; + low = s->low; + range = L_add( L_sub( high, low ), 1 ); + move32(); + move32(); + + high = L_sub( L_add( low, mul_sbc_14bits_ivas( range, cum_freq[symbol] ) ), 1 ); + low = L_add( low, mul_sbc_14bits_ivas( range, cum_freq[L_add( symbol, 1 )] ) ); + + bits_to_follow = s->bits_to_follow; + move32(); + + FOR( ;; ) + { + IF( LT_32( high, ari_q2new ) ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + } + } + ELSE + { + IF( GE_32( low, ari_q2new ) ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + } + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + } + ELSE + { + /* Output an opposite bit */ + test(); + IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) ) /* Output an opposite bit */ + { + /* later if in middle half. */ + bits_to_follow = L_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; + s->high = high; + s->bits_to_follow = bits_to_follow; + move32(); + move32(); + move32(); + + return; +} +#endif diff --git a/lib_com/ivas_avq_pos_reorder_com.c b/lib_com/ivas_avq_pos_reorder_com.c index 27878028d835f33db183da0ad5aa5fcc722d1fa2..692e89f8662aa6da0b0cc7dcd5c834dc0bf37af5 100644 --- a/lib_com/ivas_avq_pos_reorder_com.c +++ b/lib_com/ivas_avq_pos_reorder_com.c @@ -41,6 +41,7 @@ * *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ordr_esti( const int16_t svLength, /* i : sub-vector index */ int16_t *Mpos, /* i/o: dominant sub-vector position from ACV */ @@ -61,3 +62,31 @@ void ordr_esti( return; } +#else +void ordr_esti( + const Word16 svLength, /* i : sub-vector index */ + Word16 *Mpos, /* i/o: dominant sub-vector position from ACV */ + Word16 svOrder[], /* i/o: AVQ sub-vector order */ + const Word16 Nsv /* i : total sub-vectors in a sub-frames */ +) +{ + Word16 i, tmp; + + tmp = svOrder[0]; + svOrder[0] = *Mpos; + *Mpos = sub( Nsv, 1 ); + + move16(); + move16(); + move16(); + + FOR( i = 1; i < svLength; ( tmp++, i++ ) ) + { + svOrder[i] = tmp; + move16(); + } + + return; +} + +#endif diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 62183974c6d12e5030d84a3cafb91b7857be8f86..b56c3d35b18d9c7a64691bed6dff7d443194e563 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -586,8 +586,14 @@ typedef enum #define STEREO_DFT_FLAG_BITS 1 #define STEREO_DFT_SIDEGAIN_NBITS 5 #define STEREO_DFT_FEC_THRESHOLD 10 +#ifdef IVAS_FLOAT_FIXED +#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) +#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ +#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) /* Constant to set tendency for selecting absolute coding mode */ +#else #define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ #define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ +#endif #define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ #define STEREO_DFT_BITDIFF_INIT_FX (12288) /* Init value for low-pass bit difference in Q10*/ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index b7f195b9c79bbaa01e55bbef960af32c3046f123..73e17fe0b29c074a30d5dd513b0bd91b12fba120 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -36,7 +36,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------------------------* * Local constants @@ -56,6 +56,7 @@ static Word32 ivas_calculate_update_factor_fx( Word16 active_bins ) { Word32 update_factor_temp = 0; + move32(); Word16 k; FOR( k = 0; k < active_bins; k++ ) @@ -107,6 +108,8 @@ static void ivas_calculate_smoothning_factor_fx( { Word32 smooth_fact, L_tmp = 0; Word16 tmp, exp_diff = 0; + move32(); + move16(); tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // (Q15 - exp_diff) *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q16, exp_diff ) ); // Q31 @@ -204,9 +207,9 @@ static void ivas_set_up_cov_smoothing_fx( FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; + move16(); update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = fixedToFloat( hCovState->pSmoothing_factor_fx[j], Q31 ); } } ELSE @@ -215,9 +218,9 @@ static void ivas_set_up_cov_smoothing_fx( { Word32 *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[j]; Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; + move16(); update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = fixedToFloat( hCovState->pSmoothing_factor_fx[j], Q31 ); } } @@ -270,78 +273,65 @@ static void ivas_set_up_cov_smoothing( #endif +#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_spar_covar_smooth_enc_open() + * ivas_spar_covar_smooth_enc_open_fx() * * Allocate and initialize SPAR Covar. smoothing handle *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_smooth_enc_open( +ivas_error ivas_spar_covar_smooth_enc_open_fx( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ ivas_filterbank_t *pFb, /* i/o: FB handle */ - const int16_t nchan_inp, /* i : number of input channels */ + const Word16 nchan_inp, /* i : number of input channels */ const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { ivas_cov_smooth_state_t *hCovState; - int16_t i, j; + Word16 i, j; - if ( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL ) + IF( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } -#ifdef IVAS_FLOAT_FIXED IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } -#endif - if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); - } - for ( i = 0; i < nchan_inp; i++ ) + FOR( i = 0; i < nchan_inp; i++ ) { - for ( j = 0; j < nchan_inp; j++ ) + FOR( j = 0; j < nchan_inp; j++ ) { - if ( ( hCovState->pPrior_cov_real[i][j] = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); - } - set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands ); -#ifdef IVAS_FLOAT_FIXED - if ( ( hCovState->pPrior_cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + IF( ( hCovState->pPrior_cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } set_zero_fx( hCovState->pPrior_cov_real_fx[i][j], cov_smooth_cfg->max_bands ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hCovState->q_cov_real_per_band[i][j] = (Word16 *) malloc( sizeof( Word16 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + IF( ( hCovState->q_cov_real_per_band[i][j] = (Word16 *) malloc( sizeof( Word16 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( hCovState->q_cov_real_per_band[i][j], Q31, cov_smooth_cfg->max_bands ); -#endif + set16_fx( hCovState->q_cov_real_per_band[i][j], Q31, cov_smooth_cfg->max_bands ); } } -#ifdef IVAS_FLOAT_FIXED ivas_set_up_cov_smoothing_fx( hCovState, pFb, cov_smooth_cfg->max_update_rate_fx, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); -#else - ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); -#endif *hCovState_out = hCovState; return IVAS_ERR_OK; } #else +/*------------------------------------------------------------------------- + * ivas_spar_covar_smooth_enc_open() + * + * Allocate and initialize SPAR Covar. smoothing handle + *------------------------------------------------------------------------*/ + ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -384,46 +374,36 @@ ivas_error ivas_spar_covar_smooth_enc_open( } #endif +#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_spar_covar_smooth_enc_close() + * ivas_spar_covar_smooth_enc_close_fx() * * Deallocate SPAR Covar. smoothing handle *------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_covar_smooth_enc_close( +void ivas_spar_covar_smooth_enc_close_fx( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ - const int16_t nchan_inp /* i : number of input channels */ + const Word16 nchan_inp /* i : number of input channels */ ) { ivas_cov_smooth_state_t *hCovState; - int16_t i, j; + Word16 i, j; hCovState = *hCovState_out; - if ( hCovState != NULL ) + IF( hCovState != NULL ) { -#ifdef IVAS_FLOAT_FIXED free( hCovState->pSmoothing_factor_fx ); hCovState->pSmoothing_factor_fx = NULL; -#endif - free( hCovState->pSmoothing_factor ); - hCovState->pSmoothing_factor = NULL; - for ( i = 0; i < nchan_inp; i++ ) + FOR( i = 0; i < nchan_inp; i++ ) { - for ( j = 0; j < nchan_inp; j++ ) + FOR( j = 0; j < nchan_inp; j++ ) { - free( hCovState->pPrior_cov_real[i][j] ); - hCovState->pPrior_cov_real[i][j] = NULL; -#ifdef IVAS_FLOAT_FIXED free( hCovState->pPrior_cov_real_fx[i][j] ); hCovState->pPrior_cov_real_fx[i][j] = NULL; -#endif -#ifdef IVAS_FLOAT_FIXED free( hCovState->q_cov_real_per_band[i][j] ); hCovState->q_cov_real_per_band[i][j] = NULL; -#endif } } @@ -434,6 +414,12 @@ void ivas_spar_covar_smooth_enc_close( return; } #else +/*------------------------------------------------------------------------- + * ivas_spar_covar_smooth_enc_close() + * + * Deallocate SPAR Covar. smoothing handle + *------------------------------------------------------------------------*/ + void ivas_spar_covar_smooth_enc_close( ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle */ const int16_t nchan_inp /* i : number of input channels */ @@ -495,16 +481,19 @@ static void ivas_compute_smooth_cov_fx( sm_b = BAND_SMOOTH_REST_START_IDX; move16(); + move16(); + move32(); - assert( LE_16( end_band, pFb->filterbank_num_bands ) ); + assert( end_band <= pFb->filterbank_num_bands ); + test(); IF( EQ_16( prev_idx, -1 ) || EQ_16( transient_det[1], 1 ) ) { FOR( i = 0; i < num_ch; i++ ) { FOR( j = 0; j < num_ch; j++ ) { - set_s( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], pFb->filterbank_num_bands ); } } FOR( i = 0; i < num_ch; i++ ) @@ -535,7 +524,7 @@ static void ivas_compute_smooth_cov_fx( move32(); } - set_s( q_tmp, q_cov[i][j], sub( end_band, start_band ) ); + set16_fx( q_tmp, q_cov[i][j], sub( end_band, start_band ) ); FOR( k = start_band; k < non_sm_b_idx; k++ ) { L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] @@ -561,7 +550,7 @@ static void ivas_compute_smooth_cov_fx( } } } - ELSE IF( EQ_16( prev_idx, 0 ) ) + ELSE IF( prev_idx == 0 ) { FOR( i = 0; i < num_ch; i++ ) { @@ -597,9 +586,7 @@ static void ivas_compute_smooth_cov_fx( return; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_compute_smooth_cov() * @@ -691,6 +678,7 @@ static void ivas_compute_smooth_cov( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -719,7 +707,7 @@ void ivas_cov_smooth_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - mvl2l( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); + Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); } } @@ -728,9 +716,7 @@ void ivas_cov_smooth_process_fx( return; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_cov_smooth_process() * @@ -763,3 +749,4 @@ void ivas_cov_smooth_process( return; } +#endif diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index e2d4abf3f6628a805e85c4f86db947bb8c3f67aa..c265cad784837aa2d3d953c84274b6b792af57f8 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -40,8 +40,7 @@ #include "prot.h" #include "cnst.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" @@ -121,14 +120,19 @@ ivas_error ivas_dirac_config_fx( Word16 *dirac_to_spar_md_bands; error = IVAS_ERR_OK; + move32(); - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { ivas_format = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_format; + move32(); element_mode = &( (Encoder_Struct *) st_ivas )->hEncoderConfig->element_mode_init; sba_order = ( (Encoder_Struct *) st_ivas )->sba_analysis_order; + move16(); ivas_total_brate = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->ivas_total_brate; + move32(); Fs = ( (Encoder_Struct *) st_ivas )->hEncoderConfig->input_Fs; + move32(); band_grouping = ( (Encoder_Struct *) st_ivas )->hDirAC->band_grouping; hConfig = ( (Encoder_Struct *) st_ivas )->hDirAC->hConfig; hQMetaData = ( (Encoder_Struct *) st_ivas )->hQMetaData; @@ -148,8 +152,11 @@ ivas_error ivas_dirac_config_fx( ivas_format = ( (Decoder_Struct *) st_ivas )->ivas_format; element_mode = &( (Decoder_Struct *) st_ivas )->element_mode_init; sba_order = ( (Decoder_Struct *) st_ivas )->sba_analysis_order; + move16(); ivas_total_brate = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->ivas_total_brate; + move32(); Fs = ( (Decoder_Struct *) st_ivas )->hDecoderConfig->output_Fs; + move32(); band_grouping = ( (Decoder_Struct *) st_ivas )->hDirAC->band_grouping; hConfig = ( (Decoder_Struct *) st_ivas )->hDirAC->hConfig; hQMetaData = ( (Decoder_Struct *) st_ivas )->hQMetaData; @@ -166,45 +173,61 @@ ivas_error ivas_dirac_config_fx( ( (Decoder_Struct *) st_ivas )->hDirAC->hFbMdft = hFbMdft; } - IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { hConfig->nbands = IVAS_MAX_NUM_BANDS; + move16(); spar_dirac_split_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); IF( ivas_get_hodirac_flag_fx( ivas_total_brate, sba_order ) ) // add call after merge of 100861_dirac_dec { spar_dirac_split_band = 0; + move16(); } } ELSE { hConfig->nbands = 5; spar_dirac_split_band = 0; + + move16(); + move16(); } hConfig->enc_param_start_band = 0; hConfig->dec_param_estim = FALSE; - IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) /* skip for MASA decoder */ + + move16(); + move16(); + + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) /* skip for MASA decoder */ { - IF( ( error = ivas_dirac_sba_config_fx( hQMetaData, element_mode, ivas_total_brate, sba_order, hConfig->nbands - spar_dirac_split_band, - ivas_format ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_sba_config_fx( hQMetaData, element_mode, ivas_total_brate, sba_order, sub( hConfig->nbands, spar_dirac_split_band ), + ivas_format ) ), + IVAS_ERR_OK ) ) { return error; } IF( hQMetaData != NULL ) { - IF( enc_dec == ENC ) + if ( enc_dec == ENC ) { hConfig->nbands = hQMetaData->q_direction[0].cfg.nbands; + move16(); } hConfig->enc_param_start_band = add( hQMetaData->q_direction[0].cfg.start_band, spar_dirac_split_band ); + move16(); } hConfig->dec_param_estim = TRUE; - IF( hConfig->dec_param_estim == TRUE ) + move16(); + if ( EQ_16( hConfig->dec_param_estim, TRUE ) ) { hConfig->enc_param_start_band = spar_dirac_split_band; + move16(); } IF( ivas_get_hodirac_flag_fx( ivas_total_brate, sba_order ) ) @@ -212,12 +235,16 @@ ivas_error ivas_dirac_config_fx( hConfig->dec_param_estim = FALSE; hConfig->enc_param_start_band = 0; - set_c( (int8_t *) hQMetaData->twoDirBands, (int8_t) 1, hQMetaData->q_direction[0].cfg.nbands ); - hQMetaData->numTwoDirBands = (uint8_t) hQMetaData->q_direction[0].cfg.nbands; + move16(); + move16(); + + set_c( (Word8 *) hQMetaData->twoDirBands, (Word8) 1, hQMetaData->q_direction[0].cfg.nbands ); + hQMetaData->numTwoDirBands = (UWord8) hQMetaData->q_direction[0].cfg.nbands; } } - IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { // 100861_dirac_dec ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft ); @@ -590,55 +617,83 @@ void ivas_get_dirac_sba_max_md_bits_fx( const Word16 nbands, IVAS_FORMAT ivas_format ) { - IF( sba_total_brate <= IVAS_13k2 ) + IF( LE_32( sba_total_brate, IVAS_13k2 ) ) { *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; *metadata_max_bits = 70; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_16k4 ) + ELSE IF( LE_32( sba_total_brate, IVAS_16k4 ) ) { *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; *metadata_max_bits = 80; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_24k4 ) + ELSE IF( LE_32( sba_total_brate, IVAS_24k4 ) ) { *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; *metadata_max_bits = 103; + + move16(); + move16(); /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ - IF( ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { ( *metadata_max_bits ) = sub( ( *metadata_max_bits ), 3 ); + move16(); } } - ELSE IF( sba_total_brate <= IVAS_32k ) + ELSE IF( LE_32( sba_total_brate, IVAS_32k ) ) { *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; *metadata_max_bits = 214; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_48k ) + ELSE IF( LE_32( sba_total_brate, IVAS_48k ) ) { *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC; *metadata_max_bits = 240; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_64k ) + ELSE IF( LE_32( sba_total_brate, IVAS_64k ) ) { *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC; *metadata_max_bits = 200; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_80k ) + ELSE IF( LE_32( sba_total_brate, IVAS_80k ) ) { *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC; *metadata_max_bits = 200; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_96k ) + ELSE IF( LE_32( sba_total_brate, IVAS_96k ) ) { *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC; *metadata_max_bits = 200; + + move16(); + move16(); } - ELSE IF( sba_total_brate <= IVAS_128k ) + ELSE IF( LE_32( sba_total_brate, IVAS_128k ) ) { *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC; *metadata_max_bits = 250; + + move16(); + move16(); } ELSE { @@ -653,6 +708,9 @@ void ivas_get_dirac_sba_max_md_bits_fx( Word32 var2_32 = L_deposit_h( var2 ); Word32 var4 = var2_32; + move16(); + move32(); + Word16 exp_res = 0; IF( var1 % 5 != 0 ) { @@ -661,19 +719,25 @@ void ivas_get_dirac_sba_max_md_bits_fx( } Word16 flag = BASOP_Util_Cmp_Mant32Exp( MAX16B, 31, var4, exp ); Word32 tmp; - if ( flag == 1 ) + IF( EQ_16( flag, 1 ) ) { tmp = var4; + move32(); } - else + ELSE { tmp = MAX16B; exp = 31; + + move32(); + move16(); } *metadata_max_bits = (Word16) L_shr( tmp, 31 - exp ); - ; *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1; + move16(); + move16(); + return; } #else @@ -769,12 +833,19 @@ ivas_error ivas_dirac_sba_config_fx( Word32 tmp1 = IVAS_192k; Word32 tmp2 = SPAR_DIRAC_SPLIT_START_BAND; Word16 exp = 0; + + move32(); + move32(); + move16(); Word16 tmp3 = BASOP_Util_Divide3232_Scale( tmp1, tmp2, &exp ); - Word32 res = L_shr( L_deposit_h( tmp3 ), 31 - exp ); + Word32 res = L_shr( L_deposit_h( tmp3 ), sub( 31, exp ) ); error = IVAS_ERR_OK; hQMetaData->is_masa_ivas_format = 0; - hodirac_flag = ivas_get_hodirac_flag( sba_total_brate, sba_order ); // implemented on 100861_dirac_dec + move32(); + move16(); + + hodirac_flag = ivas_get_hodirac_flag_fx( sba_total_brate, sba_order ); // implemented on 100861_dirac_dec /* map the bitrate for SID frame */ IF( EQ_32( sba_total_brate, IVAS_SID_5k2 ) ) @@ -782,10 +853,12 @@ ivas_error ivas_dirac_sba_config_fx( IF( EQ_16( *element_mode, IVAS_SCE ) ) { sba_total_brate = ACELP_24k40; + move32(); } ELSE { sba_total_brate = ACELP_48k; + move32(); } } @@ -794,10 +867,12 @@ ivas_error ivas_dirac_sba_config_fx( IF( LE_32( sba_total_brate, IVAS_16k4 ) ) { hQMetaData->useLowerRes = 1; + move16(); } ELSE { hQMetaData->useLowerRes = 0; + move16(); } nbands_coded = nbands; @@ -806,25 +881,31 @@ ivas_error ivas_dirac_sba_config_fx( { hQMetaData->useLowerBandRes = 1; Word16 tmp = nbands % 2; + + move16(); + move16(); nbands_coded = add( shr( nbands, 1 ), tmp ); } ELSE { hQMetaData->useLowerBandRes = 0; + move16(); IF( hodirac_flag == 0 ) { - nbands_coded = nbands - 1; /* always combine the last two bands */ + nbands_coded = sub( nbands, 1 ); /* always combine the last two bands */ } } { Word16 no_dirs = 1; + move16(); IF( hodirac_flag ) { no_dirs = 2; + move16(); } - IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, nbands_coded, no_dirs, 0 ) ) != IVAS_ERR_OK ) // WIP + IF( NE_32( ( error = ivas_qmetadata_allocate_memory( hQMetaData, nbands_coded, no_dirs, 0 ) ), IVAS_ERR_OK ) ) // WIP { return error; } @@ -933,7 +1014,7 @@ void computeDirectionVectors_fixed( Word16 norm_x, norm_y, norm_z; Word32 scaled_x, scaled_y, scaled_z; Word16 e_x, e_y, e_z; - for ( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) + FOR( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) { norm_x = norm_l( *intensity_real_x ); norm_y = norm_l( *intensity_real_y ); @@ -941,9 +1022,9 @@ void computeDirectionVectors_fixed( scaled_x = L_shl( *intensity_real_x, norm_x ); scaled_y = L_shl( *intensity_real_y, norm_y ); scaled_z = L_shl( *intensity_real_z, norm_z ); - e_x = i_e - norm_x; - e_y = i_e - norm_y; - e_z = i_e - norm_z; + e_x = sub( i_e, norm_x ); + e_y = sub( i_e, norm_y ); + e_z = sub( i_e, norm_z ); temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), 2 * e_x, Mult_32_32( scaled_y, scaled_y ), 2 * e_y, &exp1 ); intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), 2 * e_z, &intensityNorm_e ); @@ -953,6 +1034,10 @@ void computeDirectionVectors_fixed( *( direction_vector_x++ ) = ONE_IN_Q30; *( direction_vector_y++ ) = 0; *( direction_vector_z++ ) = 0; + + move32(); + move32(); + move32(); intensity_real_x++; intensity_real_y++; intensity_real_z++; @@ -966,6 +1051,10 @@ void computeDirectionVectors_fixed( intensity_real_y++; *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), e_z + intensityNorm_e - 1 ); /*Q30*/ intensity_real_z++; + + move32(); + move32(); + move32(); } } @@ -992,48 +1081,55 @@ void computeDirectionVectors_fx( Word16 i; Word32 intensityNorm; - Word16 sq = 31 - ( 2 * ( *i_q ) - 31 ); - Word16 sq1 = ( 2 * ( *i_q ) - 31 ); + Word16 sq = sub( 31, sub( 2 * ( *i_q ), 31 ) ); + Word16 sq1 = sub( 2 * ( *i_q ), 31 ); Word16 exp = sq; Word16 local_i_q = sq1; Word16 min_factor = 30; + + move16(); + move16(); + move16(); + Word32 *init_x = intensity_real_x; Word32 *init_y = intensity_real_y; Word32 *init_z = intensity_real_z; // First loop to determine the Q for the direction vector - for ( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) + FOR( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) { intensityNorm = L_add( L_add( Mpy_32_32_r( *( intensity_real_x ), *( intensity_real_x ) ), Mpy_32_32_r( *( intensity_real_y ), *( intensity_real_y ) ) ), Mpy_32_32_r( *( intensity_real_z ), *( intensity_real_z ) ) ); /*Q (2*i_q - 31) */ exp = sq; - if ( intensityNorm <= EPSILON_FX ) + move16(); + IF( LE_32( intensityNorm, EPSILON_FX ) ) { intensity_real_x++; intensity_real_y++; intensity_real_z++; } - else + ELSE { intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp intensity_real_x++; // i_q + Q31-exp -31 = i_q -exp intensity_real_y++; // i_q + Q31-exp -31 = i_q -exp intensity_real_z++; // i_q + Q31-exp-31 = i_q -exo - local_i_q = *i_q - exp; - min_factor = min( min_factor, local_i_q ); + local_i_q = sub( *i_q, exp ); + min_factor = s_min( min_factor, local_i_q ); } } intensity_real_x = init_x; intensity_real_y = init_y; intensity_real_z = init_z; // Actual processing loop for the direction vector - for ( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) + FOR( i = enc_param_start_band; i < enc_param_start_band + num_frequency_bands; ++i ) { intensityNorm = L_add( L_add( Mpy_32_32_r( *( intensity_real_x ), *( intensity_real_x ) ), Mpy_32_32_r( *( intensity_real_y ), *( intensity_real_y ) ) ), Mpy_32_32_r( *( intensity_real_z ), *( intensity_real_z ) ) ); /*Q (2*i_q - 31) */ exp = sq; - if ( intensityNorm <= EPSILON_FX ) + move16(); + IF( LE_32( intensityNorm, EPSILON_FX ) ) { intensityNorm = L_shl( 1, min_factor ); *( direction_vector_x++ ) = L_shl( 1, min_factor ); @@ -1042,8 +1138,12 @@ void computeDirectionVectors_fx( intensity_real_x++; intensity_real_y++; intensity_real_z++; + + move32(); + move32(); + move32(); } - else + ELSE { intensityNorm = ISqrt32( intensityNorm, &exp ); // Q31-exp Word32 temp = L_shr( Mpy_32_32( *( intensity_real_x++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); @@ -1052,9 +1152,14 @@ void computeDirectionVectors_fx( *( direction_vector_y++ ) = temp; // i_q + Q31-exp -31 = i_q -exp temp = L_shr( Mpy_32_32( *( intensity_real_z++ ), intensityNorm ), ( *i_q - exp - min_factor ) ); *( direction_vector_z++ ) = temp; // i_q + Q31-exp-31 = i_q -exp + + move32(); + move32(); + move32(); } } *i_q = min_factor; + move16(); return; } #endif @@ -1127,67 +1232,93 @@ void computeDiffuseness_fx( Word32 energy_slow[CLDFB_NO_CHANNELS_MAX]; Word16 i, j, k; Word32 tmp = 0, tmp_1; + move32(); Word32 *p_tmp; const Word32 *p_tmp_c; /* Compute Intensity slow and energy slow */ - set_val_Word32( intensity_slow, 0, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ); - set_val_Word32( intensity_slow_abs, 0, CLDFB_NO_CHANNELS_MAX ); - set_val_Word32( energy_slow, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( intensity_slow, 0, DIRAC_NUM_DIMS * CLDFB_NO_CHANNELS_MAX ); + set32_fx( intensity_slow_abs, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( energy_slow, 0, CLDFB_NO_CHANNELS_MAX ); - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) + FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) { /* Energy slow */ p_tmp_c = buffer_energy + i * num_freq_bands; - for ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { energy_slow[k] = L_add( *( p_tmp_c++ ), energy_slow[k] ); // Q(q_factor_energy) + move32(); } /* Intensity slow */ - for ( j = 0; j < DIRAC_NUM_DIMS; ++j ) + FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { p_tmp = buffer_intensity[j][i]; - for ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { intensity_slow[j * num_freq_bands + k] = L_add( *( p_tmp++ ), intensity_slow[j * num_freq_bands + k] ); + move32(); } } } /* intensity_slow.^2 + intensity_slow_abs*/ - for ( j = 0; j < DIRAC_NUM_DIMS; ++j ) + FOR( j = 0; j < DIRAC_NUM_DIMS; ++j ) { - p_tmp = intensity_slow + j * num_freq_bands; + p_tmp = intensity_slow + imult1616( j, num_freq_bands ); - for ( k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { *( p_tmp ) = Mpy_32_32( *p_tmp, *( p_tmp ) ); // Q( 2*(q_factor_intensity + scale_fact - 1) -31 ) intensity_slow_abs[k] = L_add( *( p_tmp++ ), intensity_slow_abs[k] ); + move32(); + move32(); } } - Word16 init_exp = 31 - ( ( 2 * ( q_factor_intensity ) ) - 31 ), exp; + Word16 init_exp = sub( 31, sub( ( ( 2 * ( q_factor_intensity ) ) ), 31 ) ), exp; Word16 exp1 = 0, exp2; + move16(); /* Compute Diffuseness */ p_tmp = intensity_slow_abs; - for ( i = 0; i < num_freq_bands; ++i ) + FOR( i = 0; i < num_freq_bands; ++i ) { exp = init_exp; Word32 temp = *( p_tmp++ ); + move32(); tmp_1 = Sqrt32( temp, &exp ); tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp_1, L_add( energy_slow[i], 1 ), &exp1 ) ); - exp2 = 31 - exp1 + ( 31 - exp - q_factor_energy ); - if ( exp2 > 30 ) + exp2 = add( sub( 31, exp1 ), sub( sub( 31, exp ), q_factor_energy ) ); + IF( GT_32( exp2, 30 ) ) { - tmp = L_shr( tmp, ( exp2 - 30 ) ); - exp2 -= ( exp2 - 30 ); + tmp = L_shr( tmp, sub( exp2, 30 ) ); + exp2 = sub( exp2, sub( exp2, 30 ) ); } tmp = L_sub( L_shl( 1, exp2 ), tmp ); - diffuseness[i] = ( ( tmp < L_shl( 1, exp2 ) ) ? ( ( tmp < 0 ) ? 0 : tmp ) : L_shl( 1, exp2 ) ); + // diffuseness[i] = ( ( tmp < L_shl( 1, exp2 ) ) ? ( ( tmp < 0 ) ? 0 : tmp ) : L_shl( 1, exp2 ) ); + + IF( LT_32( tmp, L_shl( 1, exp2 ) ) ) + { + IF( tmp < 0 ) + { + diffuseness[i] = 0; + } + ELSE + { + diffuseness[i] = tmp; + } + } + ELSE + { + diffuseness[i] = L_shl( 1, exp2 ); + } out_exp[i] = exp2; + + move32(); + move16(); } return; } @@ -1319,7 +1450,7 @@ void computeDiffuseness_fixed( tmp = Sqrt32( p_tmp[i], &exp1 ); tmp = BASOP_Util_Divide3232_Scale_cadence( tmp, L_add( energy_slow[i], EPSILLON_FX ), &exp2 ); - q_tmp = sub( 31, exp2 ) + sub( sub( 31, exp1 ), q_ene ); + q_tmp = add( sub( 31, exp2 ), sub( sub( 31, exp1 ), q_ene ) ); IF( LT_16( q_tmp, Q30 ) ) { @@ -1329,6 +1460,7 @@ void computeDiffuseness_fixed( { tmp = L_sub( ONE_IN_Q30, L_shr( tmp, sub( q_tmp, Q30 ) ) ); q_tmp = Q30; + move16(); } IF( GE_32( tmp, L_shl( 1, q_tmp ) ) ) @@ -1336,7 +1468,7 @@ void computeDiffuseness_fixed( diffuseness[i] = ONE_IN_Q30; move32(); } - ELSE IF( LE_32( tmp, 0 ) ) + ELSE IF( tmp <= 0 ) { diffuseness[i] = 0; move32(); @@ -1498,9 +1630,10 @@ Word32 deindex_azimuth_fx( test(); IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) && EQ_16( no_bits, 2 ) ) { - IF( EQ_16( s_and( id_phi, 1 ), 0 ) ) + IF( s_and( id_phi, 1 ) == 0 ) { phi_hat_fx = cb_azi_chan_fx[shr( id_phi, 1 )]; + move32(); } ELSE { @@ -1508,7 +1641,7 @@ Word32 deindex_azimuth_fx( } return phi_hat_fx; } - flag_delta = (Word16) EQ_16( s_and( id_th, 1 ), 1 ); + flag_delta = extract_l( EQ_16( s_and( id_th, 1 ), 1 ) ); IF( remap ) { @@ -1625,9 +1758,11 @@ void deindex_spherical_component_fx( *az_idx = sph_idx; move16(); *az_fx = deindex_azimuth_fx( *az_idx, no_bits, 0, 0, mc_format ); + move16(); BREAK; default: *el_idx = deindex_sph_idx_general_fx( sph_idx, no_bits, el_fx, az_fx, az_idx, mc_format ); + move16(); BREAK; } @@ -2060,14 +2195,15 @@ static UWord16 deindex_sph_idx_general_fx( } } - IF( EQ_32( id_th, 0 ) ) + IF( id_th == 0 ) { id_phi = idx_sph; move16(); } ELSE { - IF( EQ_32( id_th, sub( no_th, 1 ) ) && GT_16( no_bits, 4 ) ) + test(); + if ( EQ_32( id_th, sub( no_th, 1 ) ) && GT_16( no_bits, 4 ) ) { id_phi = 0; move16(); @@ -2077,10 +2213,12 @@ static UWord16 deindex_sph_idx_general_fx( q_id_th = norm_l( id_th ); id_th_fx = L_shl( id_th, q_id_th ); *theta_dec_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[no_bits - 3] ), sub( 31, q_id_th ) ); + move32(); - IF( GE_32( *theta_dec_fx, L_shl( 90, Q22 ) ) ) + IF( GE_32( *theta_dec_fx, 90 << Q22 ) ) { - *theta_dec_fx = L_shl( 90, 22 ) * sign_theta; + *theta_dec_fx = 90 << 22 * sign_theta; + move32(); *phi_dec_fx = 0; move32(); *p_id_phi = 0; @@ -2091,6 +2229,7 @@ static UWord16 deindex_sph_idx_general_fx( *theta_dec_fx *= sign_theta; *phi_dec_fx = deindex_azimuth_fx( id_phi, no_bits, id_th, 0, mc_format ); + move32(); *p_id_phi = id_phi; move16(); } diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index a72aba04a7540e4d9723522fcf3f24a3fcfc9cb3..d3fd6af808d49688820668557f4b48713fc79cb4 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -39,8 +39,7 @@ #include #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif @@ -57,7 +56,7 @@ static void ivas_get_ld_fb_resp_fx( Word32 **ppIdeal_FRs_re_fx, Word32 **ppIdeal #endif static ivas_error ivas_filterbank_setup( IVAS_FB_MIXER_HANDLE hFbMixer, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, const int32_t sampling_rate, Word16 *index ); +static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, const Word32 sampling_rate, Word16 *index ); #endif static ivas_error ivas_fb_mixer_get_window( const int16_t fade_len, const int32_t sampling_rate, const float **pWindow ); #ifdef IVAS_FLOAT_FIXED @@ -80,7 +79,7 @@ Word16 ivas_get_num_bands_from_bw_idx( Word16 num_active_bands; assert( bwidth > 0 ); /*NB BW is not supported*/ - num_active_bands = ivas_num_active_bands[bwidth - 1]; + num_active_bands = ivas_num_active_bands[sub( bwidth, 1 )]; move16(); return num_active_bands; @@ -117,7 +116,11 @@ int16_t ivas_get_num_bands_from_bw_idx( static Word16 ivas_get_num_bands( const Word32 sampling_rate ) { +#ifdef IVAS_FLOAT_FIXED + Word16 bwidth = ivas_get_bw_idx_from_sample_rate_fx( sampling_rate ); +#else Word16 bwidth = ivas_get_bw_idx_from_sample_rate( sampling_rate ); +#endif Word16 num_active_bands = ivas_get_num_bands_from_bw_idx( bwidth ); return num_active_bands; @@ -166,31 +169,54 @@ ivas_error ivas_fb_set_cfg( pFb_cfg->active_w_mixing = active_w_mixing; pFb_cfg->windowed_fr_offset = 0; - IF( ivas_format == ISM_FORMAT ) + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + IF( EQ_16( ivas_format, ISM_FORMAT ) ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_4_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS ); + + move16(); + move16(); + move16(); } - ELSE IF( ivas_format == SBA_FORMAT ) + ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, FRAME_SIZE_NS ); pFb_cfg->windowed_fr_offset = (Word16) ( (float) ( sampling_rate / FRAMES_PER_SEC ) * 3.0f / 4.0f ) - NS2SA( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS ); + + move16(); + move16(); + move16(); } - ELSE IF( ivas_format == MASA_FORMAT ) + ELSE IF( EQ_16( ivas_format, MASA_FORMAT ) ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS ); + + move16(); + move16(); + move16(); } - ELSE IF( ivas_format == MC_FORMAT ) + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) { pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS ); pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, PARAM_MC_SLOT_ENC_NS ); + + move16(); + move16(); + move16(); } *pFb_cfg_out = pFb_cfg; @@ -467,13 +493,15 @@ ivas_error ivas_FB_mixer_open_fx( ) { IVAS_FB_MIXER_HANDLE hFbMixer; - int16_t i, j, frame_len, num_bands; - int16_t num_chs_alloc; + Word16 i, j, frame_len, num_bands; + Word16 num_chs_alloc, exp; ivas_error error; error = IVAS_ERR_OK; + move32(); - frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); + frame_len = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); + frame_len = shr( frame_len, sub( 15, exp ) ); hFbMixer = *hFbMixer_out; @@ -497,18 +525,19 @@ ivas_error ivas_FB_mixer_open_fx( } } - IF( fb_cfg->active_w_mixing == -1 ) + IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) { num_chs_alloc = 0; move16(); } ELSE IF( fb_cfg->active_w_mixing ) { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + num_chs_alloc = s_max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } ELSE { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ + move16(); } #ifndef IVAS_FLOAT_FIXED /////////////////////////////// FLOAT /////////////////////////////////////////////// @@ -535,23 +564,23 @@ ivas_error ivas_FB_mixer_open_fx( } } #else - for ( i = 0; i < num_chs_alloc; i++ ) + FOR( i = 0; i < num_chs_alloc; i++ ) { - if ( fb_cfg->num_out_chans == 0 ) + IF( fb_cfg->num_out_chans == 0 ) { hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; } - else + ELSE { j = fb_cfg->remix_order[i]; - if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) + IF( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } - if ( ( hFbMixer->ppFilterbank_inFR_im_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) + IF( ( hFbMixer->ppFilterbank_inFR_im_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } @@ -559,14 +588,14 @@ ivas_error ivas_FB_mixer_open_fx( } #endif - IF( fb_cfg->active_w_mixing == -1 ) + IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) { num_chs_alloc = 0; move16(); } ELSE { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + num_chs_alloc = s_max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } #ifndef IVAS_FLOAT_FIXED //////////////////////////// Float ////////////////////////////////////// @@ -589,7 +618,8 @@ ivas_error ivas_FB_mixer_open_fx( } #endif - IF( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + test(); + IF( ( NE_16( fb_cfg->active_w_mixing, -1 ) ) && ( fb_cfg->num_out_chans > 0 ) ) { #ifndef IVAS_FLOAT_FIXED ////////////////////////////////////////// FLOAT ////////////////////////////////////////////////////// float *pTemp_mem; @@ -628,13 +658,13 @@ ivas_error ivas_FB_mixer_open_fx( { IF( fb_cfg->num_out_chans > 0 ) { - const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; + const Word16 *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; num_bands = ivas_get_num_bands( sampling_rate ); ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); - IF( fb_cfg->active_w_mixing != -1 ) + IF( NE_16( fb_cfg->active_w_mixing, -1 ) ) { FOR( i = 0; i < num_bands; i++ ) { @@ -651,16 +681,18 @@ ivas_error ivas_FB_mixer_open_fx( } } - IF( sampling_rate != 48000 ) + IF( NE_32( sampling_rate, 48000 ) ) { - int16_t num_diff_bands, start_diff_band_non48k; + Word16 num_diff_bands, start_diff_band_non48k; num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K; - start_diff_band_non48k = num_bands - num_diff_bands; + move16(); + start_diff_band_non48k = sub( num_bands, num_diff_bands ); hFbMixer->num_diff_bands = num_diff_bands; + move16(); - for ( j = start_diff_band_non48k; j < num_bands; j++ ) + FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { #if 0 ////////////////////////////////// FLOAT //////////////////////// if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) @@ -694,10 +726,10 @@ ivas_error ivas_FB_mixer_open_fx( } hFbMixer->fb_cfg = fb_cfg; - set_s( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans ); - set_s( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - hFbMixer->fb_cfg->num_out_chans ); + set16_fx( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans ); + set16_fx( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, sub( IVAS_SPAR_MAX_CH, hFbMixer->fb_cfg->num_out_chans ) ); - if ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { #ifdef IVAS_FLOAT_FIXED #if 1 /*********************Intermediate Conversion that needs to remove *****************************/ @@ -722,7 +754,7 @@ ivas_error ivas_FB_mixer_open_fx( // } /************************************* Float table is gettin assigned here **************************************/ - if ( ( error = ivas_fb_mixer_get_window( hFbMixer->fb_cfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_fb_mixer_get_window( hFbMixer->fb_cfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -777,7 +809,7 @@ ivas_error ivas_FB_mixer_open_fx( set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); #endif /*********************Intermediate Conversion that needs to remove *****************************/ - IF( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ), IVAS_ERR_OK ) ) { return error; } @@ -875,6 +907,7 @@ ivas_error ivas_FB_mixer_open_fx( * Deallocate FB mixer handle *------------------------------------------------------------------------*/ + void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate in Hz */ @@ -1007,32 +1040,35 @@ void ivas_FB_mixer_close( return; } + #ifdef IVAS_FLOAT_FIXED void ivas_FB_mixer_close_fx( IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate in Hz */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word32 sampling_rate, /* i : sampling rate in Hz */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { IVAS_FB_MIXER_HANDLE hFbMixer; IVAS_FB_CFG *fb_cfg; - int16_t i, j, num_bands; - int16_t num_chs_alloc; + Word16 i, j, num_bands; + Word16 num_chs_alloc; hFbMixer = *hFbMixer_in; fb_cfg = hFbMixer->fb_cfg; - IF( fb_cfg->active_w_mixing == -1 ) + IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) { num_chs_alloc = 0; + move16(); } ELSE IF( fb_cfg->active_w_mixing ) { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + num_chs_alloc = s_max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } ELSE { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ + move16(); } IF( hFbMixer != NULL ) @@ -1042,6 +1078,7 @@ void ivas_FB_mixer_close_fx( IF( fb_cfg->num_out_chans > 0 ) { j = fb_cfg->remix_order[i]; + move16(); free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; @@ -1051,13 +1088,14 @@ void ivas_FB_mixer_close_fx( } } - IF( fb_cfg->active_w_mixing == -1 ) + IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) { num_chs_alloc = 0; + move16(); } ELSE { - num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + num_chs_alloc = s_max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } FOR( i = 0; i < num_chs_alloc; i++ ) @@ -1066,7 +1104,8 @@ void ivas_FB_mixer_close_fx( hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; } - IF( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + test(); + IF( NE_16( fb_cfg->active_w_mixing, -1 ) && ( fb_cfg->num_out_chans > 0 ) ) { free( hFbMixer->prior_mixer_fx[0][0] ); hFbMixer->prior_mixer_fx[0][0] = NULL; @@ -1078,7 +1117,7 @@ void ivas_FB_mixer_close_fx( { num_bands = hFbMixer->pFb->filterbank_num_bands; - IF( fb_cfg->active_w_mixing != -1 ) + IF( NE_16( fb_cfg->active_w_mixing, -1 ) ) { FOR( i = 0; i < num_bands; i++ ) { @@ -1087,10 +1126,10 @@ void ivas_FB_mixer_close_fx( } } - IF( sampling_rate != 48000 ) + IF( NE_32( sampling_rate, 48000 ) ) { - int16_t start_diff_band_non48k; - start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; + Word16 start_diff_band_non48k; + start_diff_band_non48k = sub( num_bands, hFbMixer->num_diff_bands ); FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { @@ -1125,7 +1164,6 @@ void ivas_FB_mixer_close_fx( return; } #endif - /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_pcm_ingest() * @@ -1305,33 +1343,40 @@ void ivas_fb_mixer_cross_fading_fx( { Word16 k, fade_start_offset, fade_end_offset; - if ( hFbMixer->first_frame[ch] == 0 ) + IF( hFbMixer->first_frame[ch] == 0 ) { fade_start_offset = hFbMixer->cross_fade_start_offset; fade_end_offset = hFbMixer->cross_fade_end_offset; + move16(); + move16(); - for ( k = 0; k < fade_start_offset; k++ ) + FOR( k = 0; k < fade_start_offset; k++ ) { ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; + move32(); } - for ( k = fade_start_offset; k < fade_end_offset; k++ ) + FOR( k = fade_start_offset; k < fade_end_offset; k++ ) { - ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], ( ONE_IN_Q15 - hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); + ppOut_pcm_fx[ch][k] = L_add( Mpy_32_16_1( pMdft_out_new_fx[k + cf_offset], hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ), Mpy_32_16_1( pMdft_out_old_fx[k + cf_offset], sub( 32767, hFbMixer->pFilterbank_cross_fade_fx[k - fade_start_offset] ) ) ); + move32(); } - for ( k = fade_end_offset; k < frame_len; k++ ) + FOR( k = fade_end_offset; k < frame_len; k++ ) { ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + move32(); } } - else + ELSE { hFbMixer->first_frame[ch] = 0; + move32(); - for ( k = 0; k < frame_len; k++ ) + FOR( k = 0; k < frame_len; k++ ) { ppOut_pcm_fx[ch][k] = pMdft_out_new_fx[k + cf_offset]; + move32(); } } @@ -1512,7 +1557,7 @@ static int16_t ivas_calculate_abs_fr( /*loop over all stored Filter Bank Response MDFT coefficients*/ set_f( short_stride_pow_spec, 0, MDFT_FB_BANDS_240 ); #ifdef IVAS_FLOAT_FIXED - set_l( short_stride_pow_spec_fx, 0, MDFT_FB_BANDS_240 ); + set32_fx( short_stride_pow_spec_fx, 0, MDFT_FB_BANDS_240 ); #endif for ( j = start_offset; j < num_bins + start_offset; j++ ) { @@ -1632,7 +1677,7 @@ static int16_t ivas_calculate_abs_fr( set_f( ppFilterbank_FRs_s, 0, frame_len ); #ifdef IVAS_FLOAT_FIXED - set_l( ppFilterbank_FRs_s_fx, 0, frame_len ); + set32_fx( ppFilterbank_FRs_s_fx, 0, frame_len ); #endif /*Commented logic is for calculating number of active bands, can be removed if not needed */ @@ -1758,6 +1803,7 @@ static Word16 ivas_calculate_abs_fr_fx( Word32 cldfb_nrg_fx = 0; Word16 cldfb_nrg_e = 0; move16(); + move16(); Word16 short_stride = pFb->fb_bin_to_band.short_stride; move16(); const Word16 num_bins_per_short_stride_bin = ( const Word16 )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); @@ -1768,7 +1814,7 @@ static Word16 ivas_calculate_abs_fr_fx( /*loop over all stored Filter Bank Response MDFT coefficients*/ - set_l( short_stride_pow_spec_fx, 0, MDFT_FB_BANDS_240 ); + set32_fx( short_stride_pow_spec_fx, 0, MDFT_FB_BANDS_240 ); FOR( j = start_offset; j < num_bins + start_offset; j++ ) { @@ -1802,7 +1848,7 @@ static Word16 ivas_calculate_abs_fr_fx( /* accumulate bin energies within a short stride bin */ - short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, Q22 - ( Q31 - sq_abs_e ) ) ); + short_stride_nrg_fx = L_add( short_stride_nrg_fx, L_shl( sq_abs_fx, sub( Q22, sub( Q31, sq_abs_e ) ) ) ); move32(); IF( !( ( j + 1 ) % num_bins_per_short_stride_bin ) ) @@ -1818,7 +1864,6 @@ static Word16 ivas_calculate_abs_fr_fx( /* accumulate bin energies within a CLDFB band */ cldfb_nrg_fx = BASOP_Util_Add_Mant32Exp( cldfb_nrg_fx, cldfb_nrg_e, sq_abs_fx, sq_abs_e, &cldfb_nrg_e ); - move32(); IF( !( ( j + 1 ) % num_bins_per_cldfb_band ) ) { @@ -1828,6 +1873,7 @@ static Word16 ivas_calculate_abs_fr_fx( move32(); pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j / num_bins_per_cldfb_band][i] = temp; cldfb_nrg_fx = 0; + move32(); cldfb_nrg_e = 0; move16(); } @@ -1840,17 +1886,17 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); - short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], (Word32) ( 0.3f * ONE_IN_Q22 ) ), 0 ); + short_stride_pow_spec_fx[j] = L_max( L_sub( short_stride_pow_spec_fx[j], 1258291 ), 0 ); // 0.3f * ONE_IN_Q22c move32(); - tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], (Word32) ( 0.7f * ONE_IN_Q22 ), &exp_diff ); + tmp = BASOP_Util_Divide3232_Scale( short_stride_pow_spec_fx[j], 2936012, &exp_diff ); // 0.7f * ONE_IN_Q22 move16(); short_stride_pow_spec_fx[j] = L_shl( L_deposit_l( tmp ), add( Q7, exp_diff ) ); // Q22 move32(); - IF( GT_32( short_stride_pow_spec_fx[j], 0 ) ) + IF( short_stride_pow_spec_fx[j] > 0 ) { assert( idx_short_stride_bin_to_band < 2 * MDFT_FB_BANDS_240 ); /* array size of p_short_stride_bin_to_band */ - IF( short_mdft_start_bin == -1 ) + IF( EQ_16( short_mdft_start_bin, -1 ) ) { short_mdft_start_bin = j; move16(); @@ -1859,13 +1905,15 @@ static Word16 ivas_calculate_abs_fr_fx( pFb->fb_bin_to_band.pp_short_stride_bin_to_band_fx[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band]; index[i] = idx_short_stride_bin_to_band; + move16(); } pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx[idx_short_stride_bin_to_band] = short_stride_pow_spec_fx[j]; move32(); - idx_short_stride_bin_to_band++; + idx_short_stride_bin_to_band = add( idx_short_stride_bin_to_band, 1 ); - pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i]++; + pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i] = add( pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i], 1 ); + move16(); } } } @@ -1897,14 +1945,15 @@ static Word16 ivas_calculate_abs_fr_fx( } } - sum_over_spar_bands_fx = max( sum_over_spar_bands_fx, EPSILON_FX ); + sum_over_spar_bands_fx = L_max( sum_over_spar_bands_fx, EPSILON_FX ); move32(); FOR( i = 0; i < bands; i++ ) { + test(); IF( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[j][i] == 0 && !any_non_zero ) { - spar_start++; + spar_start = add( spar_start, 1 ); } ELSE { @@ -1923,9 +1972,11 @@ static Word16 ivas_calculate_abs_fr_fx( move16(); } - frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); + Word16 exp; + frame_len = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); + frame_len = shr( frame_len, sub( 15, exp ) ); - set_l( ppFilterbank_FRs_s_fx, 0, frame_len ); + set32_fx( ppFilterbank_FRs_s_fx, 0, frame_len ); /*Commented logic is for calculating number of active bands, can be removed if not needed */ FOR( i = 0; i < bands; i++ ) @@ -1981,13 +2032,15 @@ static Word16 ivas_calculate_abs_fr_fx( temp_fx = L_sub( temp_fx, 1258291 ); move32(); - IF( temp_fx < 0 ) + if ( temp_fx < 0 ) { temp_fx = 0; move32(); } - IF( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 ) + test(); + test(); + IF( LT_16( j, add( abs_active_bins, abs_start_offset ) ) && GE_16( j, abs_start_offset ) && NE_16( alloc_fb_resp, -1 ) ) { pFb->fb_bin_to_band.pFb_bin_to_band_fx[i][idx] = temp_fx; move32(); @@ -2002,13 +2055,14 @@ static Word16 ivas_calculate_abs_fr_fx( FOR( i = 0; i < frame_len; i++ ) { - IF( ppFilterbank_FRs_s_fx[i] < 0 ) + if ( ppFilterbank_FRs_s_fx[i] < 0 ) { ppFilterbank_FRs_s_fx[i] = 419430; + move32(); } } - IF( alloc_fb_resp != -1 ) + IF( NE_16( alloc_fb_resp, -1 ) ) { FOR( j = 0; j < bands; j++ ) { @@ -2016,6 +2070,10 @@ static Word16 ivas_calculate_abs_fr_fx( Word16 abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j]; Word16 exp_diff = 0, tmp; + move16(); + move16(); + move16(); + FOR( i = 0; i < abs_active_bins; i++ ) { tmp = BASOP_Util_Divide3232_Scale( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j][i], ppFilterbank_FRs_s_fx[i + abs_start_offset], &exp_diff ); @@ -2148,7 +2206,7 @@ static ivas_error ivas_filterbank_setup( pFb->fb_bin_to_band.short_stride = (int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); set_f( pFb->fb_bin_to_band.p_short_stride_bin_to_band, 0.0f, 2 * MDFT_FB_BANDS_240 ); #ifdef IVAS_FLOAT_FIXED - set_l( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); + set32_fx( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); #endif set_s( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX ); set_s( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX ); @@ -2236,10 +2294,10 @@ static ivas_error ivas_filterbank_setup( #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_filterbank_setup_fx( IVAS_FB_MIXER_HANDLE hFbMixer, - const int32_t sampling_rate, + const Word32 sampling_rate, Word16 *index ) { - Word16 i, j; + Word16 i, j, exp, tmp; const Word32 *pAll_fb_fr_fx[2]; const Word16 *pAll_bins_start_offset = NULL; const Word16 *pAll_bins_per_band = NULL; @@ -2250,14 +2308,16 @@ static ivas_error ivas_filterbank_setup_fx( IVAS_FB_CFG *pCfg = hFbMixer->fb_cfg; error = IVAS_ERR_OK; + move32(); IF( pCfg->num_out_chans > 0 ) { hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate ); + move16(); ivas_get_active_bins( &pAll_bins_per_band, &pAll_bins_per_band_abs, &pAll_bins_start_offset, &pAll_bins_start_offset_abs, sampling_rate ); - IF( pCfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) ) + IF( EQ_16( pCfg->fb_latency, NS2SA( sampling_rate, DELAY_FB_1_NS ) ) ) { pAll_fb_fr_fx[0] = ivas_fb_fr_12band_1ms_re_fx; // Q30 move32(); @@ -2273,19 +2333,19 @@ static ivas_error ivas_filterbank_setup_fx( } } - hFbMixer->cross_fade_end_offset = pCfg->fade_len + pCfg->pcm_offset; + hFbMixer->cross_fade_end_offset = add( pCfg->fade_len, pCfg->pcm_offset ); move16(); - hFbMixer->cross_fade_start_offset = hFbMixer->cross_fade_end_offset - pCfg->fade_len; + hFbMixer->cross_fade_start_offset = sub( hFbMixer->cross_fade_end_offset, pCfg->fade_len ); move16(); - hFbMixer->ana_window_offset = pCfg->fb_latency + pCfg->pcm_offset; + hFbMixer->ana_window_offset = add( pCfg->fb_latency, pCfg->pcm_offset ); move16(); - IF( ( error = ivas_fb_mixer_get_window_fx( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window_fx ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_fb_mixer_get_window_fx( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window_fx ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_fb_mixer_get_window_fx( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade_fx ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_fb_mixer_get_window_fx( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade_fx ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2294,6 +2354,7 @@ static ivas_error ivas_filterbank_setup_fx( { ivas_filterbank_t *pFb = hFbMixer->pFb; Word16 offset = 0; + move16(); pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band; pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset; @@ -2306,24 +2367,28 @@ static ivas_error ivas_filterbank_setup_fx( case 48000: pFb->fb_bin_to_band.num_cldfb_bands = 60; /* sampling_rate * 1.0f / 800.0f */ move16(); - break; + BREAK; case 32000: pFb->fb_bin_to_band.num_cldfb_bands = 40; move16(); - break; + BREAK; case 16000: pFb->fb_bin_to_band.num_cldfb_bands = 20; move16(); - break; + BREAK; } /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/ - pFb->fb_bin_to_band.short_stride = extract_l( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); + // pFb->fb_bin_to_band.short_stride = extract_l( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); + tmp = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); + pFb->fb_bin_to_band.short_stride = shr( tmp, sub( 15, exp ) + 2 ); - set_l( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); + move16(); - set_s( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX ); - set_s( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); + + set16_fx( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX ); + set16_fx( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX ); FOR( j = 0; j < IVAS_MAX_NUM_FB_BANDS; j++ ) { @@ -2341,7 +2406,7 @@ static ivas_error ivas_filterbank_setup_fx( move32(); } } - IF( sampling_rate == 48000 ) + IF( EQ_32( sampling_rate, 48000 ) ) { FOR( j = 0; j < pFb->filterbank_num_bands; j++ ) { @@ -2400,6 +2465,8 @@ static ivas_error ivas_filterbank_setup_fx( active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j]; start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j]; + move16(); + move16(); } ivas_get_ld_fb_resp_fx( ppFilterbank_FRs_re_temp_fx, ppFilterbank_FRs_im_temp_fx, ppFilterbank_FRs_re_temp_fx, ppFilterbank_FRs_im_temp_fx, @@ -2491,6 +2558,7 @@ static ivas_error ivas_fb_mixer_get_window_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); IF( EQ_16( fade_len, NS2SA( sampling_rate, DELAY_FB_4_NS ) ) ) { @@ -2501,10 +2569,10 @@ static ivas_error ivas_fb_mixer_get_window_fx( BREAK; case 32000: *pWindow = ivas_fb_cf_4ms_32k_fx; - break; + BREAK; case 16000: *pWindow = ivas_fb_cf_4ms_16k_fx; - break; + BREAK; default: return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" ); } @@ -2566,10 +2634,10 @@ static const Word32 *ivas_get_cheby_ramp_fx( { case IVAS_FB_1MS_32K_SAMP: pCheby_fx = ivas_fb_resp_cheby_ramp_32del_fx; - break; + BREAK; case IVAS_FB_1MS_16K_SAMP: pCheby_fx = ivas_fb_resp_cheby_ramp_16del_fx; - break; + BREAK; default: assert( !"Unsupported cheby ramp length!" ); } @@ -2726,6 +2794,7 @@ static void ivas_get_ld_fb_resp_fx( Word16 b, s, frame_len; const Word32 *pCheby_fx; frame_len = 0; + move16(); /*common scratch buffers for computing impulse/frequency responses, pre-ring, post-ring and circular shifted outputs to optimize stack*/ Word32 scratch1_fx[L_FRAME32k * 2]; @@ -2740,22 +2809,27 @@ static void ivas_get_ld_fb_resp_fx( { case 48000: frame_len = 960; + move16(); han_win_fx = ivas_han_win_48k_fx; // Q31 - break; + BREAK; case 32000: frame_len = 640; + move16(); han_win_fx = ivas_han_win_32k_fx; // Q31 - break; + BREAK; case 16000: frame_len = 320; + move16(); han_win_fx = ivas_han_win_16k_fx; // Q31 - break; + BREAK; } pCheby_fx = ivas_get_cheby_ramp_fx( delay ); // Q31 b = 0; s = 0; + move16(); + move16(); assert( sampling_rate == 32000 || sampling_rate == 16000 ); @@ -2766,7 +2840,7 @@ static void ivas_get_ld_fb_resp_fx( Copy32( ppIdeal_FRs_re_fx[b], &scratch2_fx[pStart_offset[b]], pActive_bins[b] ); Copy32( ppIdeal_FRs_im_fx[b], &scratch2_fx[frame_len + pStart_offset[b]], pActive_bins[b] ); // Q30 - Word16 guard_bits = L_norm_arr( scratch2_fx, shl( L_FRAME32k, 1 ) ) - find_guarded_bits_fx( shl( frame_len, 1 ) ); + Word16 guard_bits = sub( L_norm_arr( scratch2_fx, shl( L_FRAME32k, 1 ) ), find_guarded_bits_fx( shl( frame_len, 1 ) ) ); Scale_sig32( scratch2_fx, shl( L_FRAME32k, 1 ), guard_bits ); ivas_imdft_fx( scratch2_fx, &scratch2_fx[frame_len], scratch1_fx, frame_len ); @@ -2775,6 +2849,9 @@ static void ivas_get_ld_fb_resp_fx( { scratch2_fx[x] = L_shr( scratch2_fx[x], guard_bits ); scratch1_fx[x] = L_shr( scratch1_fx[x], guard_bits ); + + move32(); + move32(); } /*apply circular shift and hanning window*/ @@ -2783,18 +2860,21 @@ static void ivas_get_ld_fb_resp_fx( { scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], L_sub( ONE_IN_Q31, han_win_fx[sub( s, delay )] ) ); // Q(30 + 31 - 31) == Q30 + move32(); } FOR( ; s < 2 * frame_len; s++ ) { scratch2_fx[sub( s, delay )] = Mpy_32_32( scratch1_fx[s], han_win_fx[sub( s, add( frame_len, delay ) )] ); // Q30 + move32(); } FOR( s = 0; s < delay; s++ ) { scratch2_fx[add( sub( shl( frame_len, 1 ), delay ), s )] = L_negate( Mpy_32_32( scratch1_fx[s], han_win_fx[add( sub( frame_len, delay ), s )] ) ); // Q30 + move32(); } /*apply heavy/cheby ramp window and compute pre ring*/ @@ -2802,6 +2882,7 @@ static void ivas_get_ld_fb_resp_fx( FOR( s = 0; s < delay + 1; s++ ) { scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], pCheby_fx[sub( delay, s )] ); // Q30 + move32(); } FOR( ; s < frame_len; s++ ) @@ -2813,27 +2894,32 @@ static void ivas_get_ld_fb_resp_fx( FOR( ; s < 2 * frame_len - delay; s++ ) { scratch1_fx[s] = scratch2_fx[s]; + move32(); } FOR( ; s < 2 * frame_len; s++ ) { scratch1_fx[s] = Mpy_32_32( scratch2_fx[s], L_sub( ONE_IN_Q31, pCheby_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] ) ); // Q30 + move32(); } /*IR - pre ring + post ring*/ FOR( s = 1; s < 2 * frame_len; s++ ) { scratch2_fx[s] = L_sub( L_sub( scratch2_fx[s] /*pre ring*/, scratch1_fx[s] /*post ring*/ ), scratch1_fx[sub( shl( frame_len, 1 ), s )] ); + move32(); } FOR( s = 0; s < 2 * frame_len - delay; s++ ) { scratch1_fx[add( s, delay )] = scratch2_fx[s]; + move32(); } FOR( ; s < 2 * frame_len; s++ ) { scratch1_fx[sub( s, sub( shl( frame_len, 1 ), delay ) )] = L_negate( scratch2_fx[s] ); + move32(); } /* apply final window*/ @@ -2841,21 +2927,28 @@ static void ivas_get_ld_fb_resp_fx( Word16 offset = 1; Word16 delay_16 = 0; - IF( delay == IVAS_FB_1MS_16K_SAMP ) + move16(); + move16(); + + if ( EQ_16( delay, IVAS_FB_1MS_16K_SAMP ) ) { delay_16 = 1; + move16(); } FOR( s = 0; s < delay; s++ ) { - scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[s + ( offset * delay_16 )] ); + scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_delay[add( s, imult1616( offset, delay_16 ) )] ); offset = add( offset, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 + + move32(); + move32(); } const Word32 *sine_till_frame_len = NULL; - IF( delay == IVAS_FB_1MS_16K_SAMP ) + IF( EQ_16( delay, IVAS_FB_1MS_16K_SAMP ) ) { sine_till_frame_len = ivas_sine_frame_len_640_del_16_fx; // Q30 } @@ -2864,18 +2957,24 @@ static void ivas_get_ld_fb_resp_fx( sine_till_frame_len = ivas_sine_frame_len_640_del_32_fx; // Q30 } Word16 iterator = 0; + move16(); FOR( s = 2 * delay; s < frame_len + 1; s++ ) { scratch1_fx[s] = Mpy_32_32( scratch1_fx[s], sine_till_frame_len[iterator] ); iterator = add( iterator, 1 ); scratch1_fx[s] = L_shl( scratch1_fx[s], 1 ); // Q30 + move32(); + move32(); + // assert(fabs(scratch1[s]) - fabs(fix_to_float(scratc h1_fx[s], 30)) < 0.00001); } FOR( ; s < 2 * frame_len; s++ ) { scratch1_fx[s] = 0; + + move32(); } /*compute frequency response*/ diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index 69a4e13c1aa953ecfa529ba3d6572fff6a33861f..21ec2a2a4896fd890a4dc424fe7fc24452b82245 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -43,8 +43,9 @@ /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 q_fcator ); #endif /*-----------------------------------------------------------------------------------------* @@ -52,7 +53,7 @@ static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Wo * * Initialisation call for filtering a signal *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_filters_init( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const float *filt_coeff, /* i : filter coefficients */ @@ -98,48 +99,99 @@ void ivas_filters_init( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const Word32 *filt_coeff_fx, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order ) /* i : filter order */ { Word16 i; filter_state->order = order; + move16(); + + test(); IF( EQ_16( order, IVAS_FILTER_ORDER_2 ) || EQ_16( order, IVAS_FILTER_ORDER_1 ) ) { filter_state->filt_len = add( order, 1 ); + move16(); FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; + filter_state->num_e[IVAS_FILTER_STAGE_0][i] = 1; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->den_e[IVAS_FILTER_STAGE_0][i] = 1; + move32(); + move32(); + move16(); + move16(); } filter_state->state_fx[0][0] = 0; + filter_state->state_e[0][0] = 0; filter_state->state_fx[0][1] = 0; + filter_state->state_e[0][1] = 0; filter_state->state_fx[0][2] = 0; + filter_state->state_e[0][2] = 0; + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); } ELSE { filter_state->filt_len = IVAS_BIQUAD_FILT_LEN; + move16(); FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; - filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 2 ) )]; - filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 3 ) )]; + filter_state->num_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i]; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->den_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 2]; + filter_state->num_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 2]; + filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 3]; + filter_state->den_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 3]; + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); } filter_state->state_fx[0][0] = 0; + filter_state->state_e[0][0] = 0; filter_state->state_fx[0][1] = 0; + filter_state->state_e[0][1] = 0; filter_state->state_fx[0][2] = 0; + filter_state->state_e[0][2] = 0; filter_state->state_fx[1][0] = 0; + filter_state->state_e[1][0] = 0; filter_state->state_fx[1][1] = 0; + filter_state->state_e[1][1] = 0; filter_state->state_fx[1][2] = 0; + filter_state->state_e[1][2] = 0; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } return; @@ -152,6 +204,7 @@ void ivas_filters_init_fx( * * Process call for selecting the type filter *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_filter_process( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ float *pIn_Out, /* i/o: signal subject to filtering */ @@ -177,7 +230,7 @@ void ivas_filter_process( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_filter_process_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ @@ -210,6 +263,7 @@ void ivas_filter_process_fx( * * Process call for filtering a signal *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, @@ -235,7 +289,7 @@ static void ivas_iir_2_filter( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, @@ -247,92 +301,47 @@ static void ivas_iir_2_filter_fx( Word32 *pIn_fx = pIn_Out_fx; Word32 *pOut_fx = pIn_Out_fx; + Word16 pOut_e; Word32 tmp_pIn_buf_i_fx; - Word32 L_tmp, L_tmp_1; - Word64 L_tmp_2; - Word16 L_tmp_q_factor, L_tmp_2_q_factor, L_tmp_3_q_factor, L_tmp_4_q_factor, L_tmp_5_q_factor, L_tmp_6_q_factor; + Word32 L_tmp_prod, L_tmp; + Word16 L_prod_e, L_tmp_e; - Word16 q_factor_diff; - - Word16 q_factor_filter_num = 30; - Word16 q_factor_filter_den = 30; + move16(); + move16(); FOR( i = 0; i < length; i++ ) { tmp_pIn_buf_i_fx = pIn_fx[i]; + move32(); - /*L_tmp = Mpy_32_32(pIn_fx[i], filter_state->num_fx[stage][0]);*/ + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); + L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][0] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][0] ) ) - 31 ) - L_tmp_q_factor = sub( add( q_factor, q_factor_filter_num ), 31 ); + pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pOut_e ); + move32(); - IF( GE_16( L_tmp_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_q_factor, q_factor ); - pOut_fx[i] = L_add( ( filter_state->state_fx[stage][0] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ), q_factor_diff ) ); - L_tmp_2_q_factor = q_factor; - } - ELSE + FOR( j = 1; j < filter_state->filt_len; j++ ) { - q_factor_diff = sub( q_factor, L_tmp_q_factor ); - pOut_fx[i] = L_add( L_shr( filter_state->state_fx[stage][0], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ) ) ); - pOut_fx[i] = L_shl( pOut_fx[i], q_factor_diff ); - L_tmp_2_q_factor = q_factor; - } + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); + L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][j] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][j] ) ) - 31 ) + L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); - FOR( j = 1; j < filter_state->filt_len; j++ ) + L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); + L_prod_e = add( pOut_e, filter_state->den_e[stage][j] ); // 31 - ( ( ( 31 - pOut_e ) + ( 31 - filter_state->den_e[stage][j] ) ) - 31 ); + + filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); + move32(); + } + + /* Scaling pOut_fx to Q11 */ + pOut_fx[i] = L_shr_sat( pOut_fx[i], sub( sub( 31, q_factor ), pOut_e ) ); + move32(); + IF( pOut_fx[i] < 0 ) { - /*L_tmp_1 = filter_state->num_fx[stage][j] * tmp_pIn_buf_i_fx;*/ - - L_tmp_3_q_factor = sub( add( q_factor_filter_num, q_factor ), 31 ); - - IF( GE_16( L_tmp_3_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_3_q_factor, q_factor ); - L_tmp = L_add( ( filter_state->state_fx[stage][j] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ), q_factor_diff ) ); - L_tmp_4_q_factor = q_factor; - } - ELSE - { - q_factor_diff = sub( q_factor, L_tmp_3_q_factor ); - L_tmp = L_add( L_shr( filter_state->state_fx[stage][j], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ) ) ); - L_tmp_4_q_factor = L_tmp_3_q_factor; - } - - /*L_tmp_3 = filter_state->den_fx[stage][j] * pOut_fx[i];*/ - - L_tmp_5_q_factor = sub( add( q_factor_filter_den, L_tmp_2_q_factor ), 31 ); - - - IF( GE_16( L_tmp_5_q_factor, L_tmp_4_q_factor ) ) - { - q_factor_diff = sub( L_tmp_5_q_factor, L_tmp_4_q_factor ); - L_tmp_1 = L_sub( L_tmp, L_shr( Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ), q_factor_diff ) ); - L_tmp_6_q_factor = L_tmp_4_q_factor; - } - ELSE - { - q_factor_diff = sub( L_tmp_4_q_factor, L_tmp_5_q_factor ); - L_tmp_1 = L_sub( L_shr( L_tmp, q_factor_diff ), Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ) ); - L_tmp_6_q_factor = L_tmp_5_q_factor; - } - - IF( GE_16( L_tmp_6_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_6_q_factor, q_factor ); - L_tmp_2 = W_shr( (Word64) L_tmp_1, q_factor_diff ); - } - ELSE - { - q_factor_diff = sub( q_factor, L_tmp_6_q_factor ); - L_tmp_2 = W_shl( (Word64) L_tmp_1, q_factor_diff ); - } - - - filter_state->state_fx[stage][j - 1] = W_extract_l( L_tmp_2 ); - - // filter_state->state[stage][j - 1] = WORD322FL_SCALE(filter_state->state_fx[stage][j - 1], sub(31, q_factor)); + pOut_fx[i] = L_add( pOut_fx[i], 1 ); + move32(); } } } diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index aab90fab53304318ef4087e885e5ac89b32f0eff..8935bc904ec569c41a260f5658d81c6ef9dc6dee 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -41,8 +41,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #define IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -73,6 +72,7 @@ * Convert bit-budget to bitrate *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( const Word16 x[], /* i : bitbudgets */ Word32 y[], /* o : bitrates */ @@ -84,10 +84,29 @@ void bitbudget_to_brate( FOR( i = 0; i < N; i++ ) { y[i] = FRAMES_PER_SEC * x[i]; + move32(); } return; } +#else +void bitbudget_to_brate( + const int16_t x[], /* i : bitbudgets */ + int32_t y[], /* o : bitrates */ + const int16_t N /* i : number of entries to be converted */ +) +{ + int16_t i; + + for ( i = 0; i < N; i++ ) + { + y[i] = FRAMES_PER_SEC * x[i]; + } + + return; +} + +#endif /*-------------------------------------------------------------------* @@ -417,7 +436,7 @@ ivas_error ivas_ism_config_fx( ivas_error error; error = IVAS_ERR_OK; - move16(); + move32(); IF( combined_format_flag ) { n_ISms = nchan_ism; @@ -449,8 +468,9 @@ ivas_error ivas_ism_config_fx( // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); - set_s( bits_element, shr( tmp1, ( 15 - exp ) ), n_ISms ); + set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + move16(); /* ISM common signaling bits are counted in MASA MD bit-budget */ } @@ -462,22 +482,26 @@ ivas_error ivas_ism_config_fx( //(Q31 +Q0) - Q31 --> Q0 bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); - set_s( bits_element, shr( tmp1, ( 15 - exp ) ), n_ISms ); + set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + move16(); bitbudget_to_brate( bits_element, element_brate, n_ISms ); /* count ISm common signaling bits */ IF( hIsmMeta != NULL ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], add( n_ISms * ISM_METADATA_FLAG_BITS, nchan_ism ) ); + move16(); IF( GE_32( ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_EXTENDED_METADATA_BITS ); + move16(); IF( ism_extended_metadata_flag ) { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_IS_NDP_BITS ); + move16(); } } @@ -487,6 +511,9 @@ ivas_error ivas_ism_config_fx( { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_MD_FLAG_BITS ); nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_FLAG_BITS ); + + move16(); + move16(); } ELSE { @@ -494,6 +521,9 @@ ivas_error ivas_ism_config_fx( { nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_MD_FLAG_BITS ); nb_bits_metadata[0] = add( nb_bits_metadata[0], ISM_METADATA_INACTIVE_FLAG_BITS ); + + move16(); + move16(); } } } @@ -505,8 +535,9 @@ ivas_error ivas_ism_config_fx( { bits_side = sum_s( nb_bits_metadata, n_ISms ); tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); - set_s( nb_bits_metadata, shr( tmp1, ( 15 - exp ) ), n_ISms ); + set16_fx( nb_bits_metadata, shr( tmp1, ( 15 - exp ) ), n_ISms ); nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); + move16(); v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms ); bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); @@ -518,7 +549,7 @@ ivas_error ivas_ism_config_fx( { Word16 diff, n_higher, flag_higher[MAX_NUM_OBJECTS]; - set_s( flag_higher, 1, MAX_NUM_OBJECTS ); + set16_fx( flag_higher, 1, MAX_NUM_OBJECTS ); diff = 0; move16(); @@ -529,21 +560,24 @@ ivas_error ivas_ism_config_fx( diff = add( diff, sub( bits_CoreCoder[ch], BITS_ISM_INACTIVE ) ); bits_CoreCoder[ch] = BITS_ISM_INACTIVE; flag_higher[ch] = 0; + move16(); + move16(); } } n_higher = sum_s( flag_higher, n_ISms ); test(); - IF( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) + IF( diff > 0 && n_higher > 0 ) { tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); - tmp = shr( tmp, ( 15 - exp ) ); + tmp = shr( tmp, sub( 15, exp ) ); FOR( ch = 0; ch < n_ISms; ch++ ) { IF( flag_higher[ch] ) { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); + move16(); } } @@ -551,11 +585,12 @@ ivas_error ivas_ism_config_fx( move16(); ch = 0; move16(); - WHILE( EQ_16( flag_higher[ch], 0 ) ) + WHILE( flag_higher[ch] == 0 ) { ch = add( ch, 1 ); } bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); + move16(); } bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); @@ -609,15 +644,16 @@ ivas_error ivas_ism_config_fx( } test(); - IF( GT_16( diff, 0 ) && GT_16( n_higher, 0 ) ) + IF( diff > 0 && n_higher > 0 ) { tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); - tmp = shr( tmp, ( 15 - exp ) ); + tmp = shr( tmp, sub( 15, exp ) ); FOR( ch = 0; ch < n_ISms; ch++ ) { IF( flag_higher[ch] ) { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); + move16(); } } @@ -625,11 +661,12 @@ ivas_error ivas_ism_config_fx( move16(); ch = 0; move16(); - WHILE( EQ_16( flag_higher[ch], 0 ) ) + WHILE( flag_higher[ch] == 0 ) { ch = add( ch, 1 ); } bits_CoreCoder[ch] = add( bits_CoreCoder[ch], tmp ); + move16(); } /* verify for the maximum bitrate @12.8kHz core */ @@ -639,7 +676,7 @@ ivas_error ivas_ism_config_fx( { limit_high = BITS_IVAS_512k; move16(); - IF( LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ + if ( LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */ { limit_high = BITS_ACELP_12k8_HIGH_LIMIT; move16(); @@ -670,13 +707,13 @@ ivas_error ivas_ism_config_fx( } } - IF( GT_16( diff, 0 ) ) + IF( diff > 0 ) { ch = 0; move16(); FOR( ch = 0; ch < n_ISms; ch++ ) { - IF( EQ_16( flag_higher[ch], 0 ) ) + IF( flag_higher[ch] == 0 ) { IF( GT_16( diff, limit_high ) ) { @@ -687,8 +724,9 @@ ivas_error ivas_ism_config_fx( ELSE { bits_CoreCoder[ch] = add( bits_CoreCoder[ch], diff ); + move16(); - IF( combined_format_flag ) + if ( combined_format_flag ) { diff = 0; move16(); @@ -701,7 +739,7 @@ ivas_error ivas_ism_config_fx( IF( combined_format_flag ) { - IF( GT_16( diff, 0 ) ) + IF( diff > 0 ) { FOR( ch = 0; ch < n_ISms; ch++ ) { @@ -853,7 +891,7 @@ Word16 ism_quant_meta_fx( Word32 qlow_fx, step_fx; Word16 tmp, tmp_e; - IF( val <= borders_fx[1] ) + IF( LE_32( val, borders_fx[1] ) ) { qlow_fx = borders_fx[0]; move32(); @@ -862,7 +900,7 @@ Word16 ism_quant_meta_fx( step_fx = q_step_border_fx; move32(); } - ELSE IF( val <= borders_fx[2] ) + ELSE IF( LE_32( val, borders_fx[2] ) ) { qlow_fx = borders_fx[1]; move32(); @@ -890,6 +928,7 @@ Word16 ism_quant_meta_fx( // idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow_fx ) / step_fx + 0.5f ) ) ); *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); + move32(); return idx; } @@ -949,29 +988,48 @@ Word32 ism_dequant_meta_fx( const Word16 cbsize /* i : codebook size */ ) { - Word16 idx_start; + Word16 idx_start, tmp1, tmp2, exp1, exp2; Word32 qlow_fx, step_fx, valQ_fx; - IF( idx <= L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ) / L_shr( q_step_border_fx, 21 ) ) + tmp1 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp1 ); + tmp1 = shr( tmp1, sub( 15, exp1 ) ); + + tmp2 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp2 ); + tmp2 = shr( tmp2, sub( 15, exp2 ) ); + + + IF( LE_16( idx, tmp1 ) ) { qlow_fx = borders_fx[0]; idx_start = 0; step_fx = q_step_border_fx; + + move32(); + move32(); + move16(); } - ELSE IF( idx <= cbsize - 1 - L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ) / L_shr( q_step_border_fx, 21 ) ) + ELSE IF( LE_16( idx, sub( sub( cbsize, 1 ), tmp2 ) ) ) { qlow_fx = borders_fx[1]; - idx_start = (Word16) ( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ) / L_shr( q_step_border_fx, 21 ) ); + idx_start = tmp1; step_fx = q_step_fx; + + move32(); + move32(); + move16(); } ELSE { qlow_fx = borders_fx[2]; - idx_start = (Word16) ( cbsize - 1 - L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ) / L_shr( q_step_border_fx, 21 ) ); + idx_start = (Word16) sub( sub( cbsize, 1 ), tmp2 ); step_fx = q_step_border_fx; + + move32(); + move32(); + move16(); } - valQ_fx = sub( idx, idx_start ) * step_fx + qlow_fx; + valQ_fx = L_add( sub( idx, idx_start ) * step_fx, qlow_fx ); return valQ_fx; } @@ -1094,6 +1152,7 @@ void ivas_param_ism_config_fx( * ---------------------------------------------------------------*/ /*! r : ISM format mode */ +#ifdef IVAS_FLOAT_FIXED ISM_MODE ivas_ism_mode_select( const Word16 nchan_inp, /* i : number of input objects */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -1116,7 +1175,27 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } +#else +ISM_MODE ivas_ism_mode_select( + const int16_t nchan_inp, /* i : number of input objects */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +) +{ + ISM_MODE ism_mode = ISM_MODE_NONE; + + if ( nchan_inp > 2 && ivas_total_brate <= ACELP_32k ) + { + ism_mode = ISM_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_DISC; + } + + return ism_mode; +} +#endif /*--------------------------------------------------------------- * ivas_ism_metadata_close() @@ -1253,13 +1332,26 @@ void ivas_get_ism_sid_quan_bitbudget_fx( *nBits_coh = ISM_DTX_COH_SCA_BITS; *nBits_sce_id = 1; - IF( nchan_ism >= 3 ) + move16(); + move16(); + move16(); + move16(); + move32(); + move32(); + + IF( GE_16( nchan_ism, 3 ) ) { *nBits_azimuth = ISM_DTX_AZI_BITS_LOW; *nBits_elevation = ISM_DTX_ELE_BITS_LOW; *q_step_fx = ISM_Q_STEP_LOW_FX; *q_step_border_fx = ISM_Q_STEP_BORDER_LOW_FX; *nBits_sce_id = 2; + + move16(); + move16(); + move16(); + move16(); + move32(); } return; diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c index 99c7741c31556781b8601f8146ea743fa19d3342..95797ef84776d97010d71414045be9b63ee70d2a 100644 --- a/lib_com/ivas_lfe_com.c +++ b/lib_com/ivas_lfe_com.c @@ -54,7 +54,7 @@ * * Selects LFE filter coeff based on config. *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_lpf_select_filt_coeff( const int32_t sampling_rate, /* i : sampling rate */ const int16_t order, /* i : filter order */ @@ -102,11 +102,12 @@ void ivas_lfe_lpf_select_filt_coeff( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_lfe_lpf_select_filt_coeff_fx( - const Word32 sampling_rate, /* i : sampling rate */ - const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 order, /* i : filter order */ + const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ + const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ ) { SWITCH( order ) @@ -132,12 +133,15 @@ void ivas_lfe_lpf_select_filt_coeff_fx( { case 16000: *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_16k_sos_e; BREAK; case 32000: *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_32k_sos_e; BREAK; case 48000: *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_48k_sos_e; BREAK; default: BREAK; @@ -185,15 +189,24 @@ void ivas_lfe_window_init_fx( /* 10ms stride, MDCT will be done in two iterations */ hLFEWindow->dct_len = shr( frame_len, 1 ); + move16(); /* 8ms of latency */ - hLFEWindow->fade_len = NS2SA( sampling_rate, IVAS_LFE_FADE_NS ); + hLFEWindow->fade_len = NS2SA_FX2( sampling_rate, IVAS_LFE_FADE_NS ); hLFEWindow->zero_pad_len = ( mult( IVAS_ZERO_PAD_LEN_MULT_FAC_fx, sub( hLFEWindow->dct_len, hLFEWindow->fade_len ) ) ); hLFEWindow->full_len = add( add( hLFEWindow->zero_pad_len, hLFEWindow->fade_len ), hLFEWindow->dct_len ); + move16(); + move16(); + move16(); + + move16(); + move16(); + move16(); + move16(); return; } -#endif +#else void ivas_lfe_window_init( LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */ const int32_t sampling_rate, /* i : sampling rate */ @@ -228,3 +241,4 @@ void ivas_lfe_window_init( return; } +#endif diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index dbcda4b56a94d6c119c323b159274ec4d0d9fa34..e0005e4b8bcd34e69c6f72da85649de46e69213d 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -41,7 +41,7 @@ #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "ivas_rom_com_fx.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" @@ -1460,7 +1460,7 @@ void deindex_sph_idx( return; } - +#ifdef IVAS_FLOAT_FIXED void deindex_sph_idx_fx( const UWord16 sphIndex, /* i : Spherical index */ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ @@ -1683,7 +1683,7 @@ void deindex_sph_idx_fx( } return; } - +#endif /*--------------------------------------------------------------- * valid_ratio_index() * diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 5297d332a8439b961b9b884a87f1f35acfd9490d..1b19b9037c75678cec3b28759ed605fddecd0c68 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -36,7 +36,7 @@ #include "options.h" #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_stat_com.h" #include "ivas_rom_com.h" diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com.c index f68f576f90a209fae0f66c8584e6a7c18b8c744c..dd79107482c4fb69974d810720acd6fbca5e5fab 100644 --- a/lib_com/ivas_mct_com.c +++ b/lib_com/ivas_mct_com.c @@ -35,7 +35,6 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" -#include "prot_fx1.h" #include "wmc_auto.h" #include diff --git a/lib_com/ivas_mdct_core_com.c b/lib_com/ivas_mdct_core_com.c index a715790b8f2554e12acf62f890d19de54ba6c417..7e7a00cfc71e19746759cf9ed1da0852d1d4ecfe 100644 --- a/lib_com/ivas_mdct_core_com.c +++ b/lib_com/ivas_mdct_core_com.c @@ -37,8 +37,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index 730a2fe7e92fc0914abc1772da6e6e02362d6a08..c25f4fab4bdcba6f02162341aa654d2fec309cc9 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -32,7 +32,7 @@ #include #include "options.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com_fx.h" #ifdef DEBUGGING @@ -355,7 +355,6 @@ void ivas_imdct_fx( * * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ - void ivas_get_twid_factors_fx1( const Word16 length, const Word16 **pTwid_re, @@ -389,7 +388,6 @@ void ivas_get_twid_factors_fx1( return; } - /*-----------------------------------------------------------------------------------------* * Function ivas_get_mdct_scaling_gain_fx() * diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft.c index 2a785bd342fc48f803b07c18bb150efee7cefea9..564285b094a41ecc65afedfdacf4ca53345fea1c 100644 --- a/lib_com/ivas_mdft_imdft.c +++ b/lib_com/ivas_mdft_imdft.c @@ -41,8 +41,7 @@ #ifdef IVAS_FLOAT_FIXED #include #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index d7f25bfbb4fd0470c82e493f62a6cf50ff957d34..5dbe0386623a0845e217207edbca48b86f06bfe9 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -36,11 +36,10 @@ #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "prot.h" -#include "prot_fx1.h" #include "ivas_rom_com.h" #include "rom_com.h" #include -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------- * Local constants diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index 2fa1f11f013381709393ebbff8db49a5b27f08a1..f2c6d8d0e96fbc851d878ed4e01c0edef0c3de50 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -40,7 +40,7 @@ #include "wmc_auto.h" #include "prot.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" +#include "prot_fx.h" #endif /*---------------------------------------------------------------------* diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d085e06beac5ffc1aab24a1dc563016f6286e449..80cdef0de6b716f2b10f53bc9d421ef990fad39c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -45,6 +45,10 @@ #include "ivas_stat_com.h" #include "ivas_error_utils.h" +#ifdef IVAS_FLOAT_FIXED +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif // IVAS_FLOAT_FIXED + /* clang-format off */ /*----------------------------------------------------------------------------------* @@ -162,8 +166,8 @@ ivas_error ivas_sce_enc( ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ - const float data_f_ch0[], /* i : input signal for channel 0 */ - const float data_f_ch1[], /* i : input signal for channel 1 */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ const int16_t input_frame, /* i : input frame length per channel */ const int16_t nb_bits_metadata /* i : number of metadata bits */ ); @@ -221,6 +225,51 @@ ivas_error pre_proc_front_ivas( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +ivas_error pre_proc_front_ivas_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int32_t element_brate, /* i : SCE/CPE element bitrate */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int16_t input_frame, /* i : frame length */ + const int16_t n, /* i : channel number */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float *relE, /* o : frame relative energy */ + float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + int16_t *vad_hover_flag, /* o : VAD hangover flag */ + int16_t *attack_flag, /* o : flag signaling attack */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ + float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ + int16_t *loc_harm, /* o : harmonicity flag */ + float *cor_map_sum, /* o : speech/music clasif. parameter */ + int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ + const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ + const float currFlatness, /* i : flatness parameter */ + const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel */ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +); ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ @@ -533,7 +582,7 @@ ivas_error ivas_core_enc( const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_core_dec( +ivas_error ivas_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -675,7 +724,27 @@ int16_t ivas_smc_gmm( int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ ); - +#ifdef IVAS_FLOAT_FIXED +/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ +Word16 ivas_smc_gmm_fx( + Encoder_State *st, /* i/o: state structure */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 Etot_fx, /* i : total frame energy */ + Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ + Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ + Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ + Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ + const Word16 non_sta_fx, /* i : unbound non-stationarity */ + const Word16 relE_fx, /* i : relative frame energy */ + Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ + const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + , + Word16 Qfact_PS, + Word16 Q_esp, + Word16 Qfact_PS_past +); +#endif void ivas_smc_mode_selection( Encoder_State *st, /* i/o: encoder state structure */ const int32_t element_brate, /* i : element bitrate */ @@ -822,7 +891,7 @@ void smooth_dft2td_transition( void smooth_dft2td_transition_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const int16_t output_frame /* i : output frame lenght */ + const Word16 output_frame /* i : output frame lenght */ ); /*! r: flag indicating a valid bitrate */ int16_t is_IVAS_bitrate( @@ -862,8 +931,8 @@ void ivas_mdft_fx( const Word32 *pIn, /* i : input time-domain signal */ Word32 *pOut_re, /* o : Real part of MDFT signal */ Word32 *pOut_im, /* o : Imag. part of MDFT signal */ - const int16_t length, /* i : signal length */ - const int16_t mdft_length /* i : MDFT length */ + const Word16 length, /* i : signal length */ + const Word16 mdft_length /* i : MDFT length */ ); void ivas_imdft_fx( @@ -923,7 +992,7 @@ Word16 rand_triangular_signed_fx( #endif Word64 var_32_fx( const Word32 *x, /* i : input vector */ - const int16_t len, /* i : length of inputvector */ + const Word16 len, /* i : length of inputvector */ Word16 q /* q : q-factor for the array */ ); @@ -1135,11 +1204,19 @@ ivas_error ivas_ism_config( const int16_t combined_format_flag /* i : flag indicating combined format */ ); +#ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( const Word16 x[], /* i : bitbudgets */ Word32 y[], /* o : bitrates */ const Word16 N /* i : number of entries to be converted */ ); +#else +void bitbudget_to_brate( + const int16_t x[], /* i : bitbudgets */ + int32_t y[], /* o : bitrates */ + const int16_t N /* i : number of entries to be converted */ +); +#endif void ivas_ism_reset_metadata( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ @@ -1153,6 +1230,17 @@ void ivas_ism_reset_metadata_API( ); /*! r: index of the winning codeword */ +#ifdef IVAS_FLOAT_FIXED +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize */ + Word32 *valQ, /* o : quantized value */ + const Word32 borders_fx[], /* i : level borders */ + const Word32 q_step_fx, /* i : quantization step */ + const Word32 q_step_border_fx, /* i : quantization step at the border */ + const Word16 cbsize /* i : codebook size */ +); +#endif + int16_t ism_quant_meta( const float val, /* i : scalar value to quantize */ float *valQ, /* o : quantized value */ @@ -1171,6 +1259,17 @@ float ism_dequant_meta( const int16_t cbsize /* i : codebook size */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation value */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag */ +); +#else ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -1180,7 +1279,7 @@ ivas_error ivas_set_ism_metadata( const float pitch, /* i : pitch */ const int16_t non_diegetic_flag /* i : non-diegetic object flag */ ); - +#endif ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ @@ -1201,6 +1300,25 @@ ivas_error ivas_ism_enc( const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_ism_metadata_enc( + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 localVAD[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word32 lp_noise_CPE, /* i : LP filtered total noise estimation */ + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame +); +#else ivas_error ivas_ism_metadata_enc( int32_t *ism_total_brate, /* i/o: ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -1218,7 +1336,7 @@ ivas_error ivas_ism_metadata_enc( int16_t *omasa_stereo_sw_cnt, const int16_t ini_frame ); - +#endif ivas_error ivas_ism_metadata_dec( const int32_t ism_total_brate, /* i : ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -1241,10 +1359,17 @@ ivas_error ivas_ism_metadata_dec( *----------------------------------------------------------------------------------*/ /*! r: ISM format mode */ +#ifdef IVAS_FLOAT_FIXED ISM_MODE ivas_ism_mode_select( const Word16 nchan_inp, /* i : number of input objects */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); +#else +ISM_MODE ivas_ism_mode_select( + const int16_t nchan_inp, /* i : number of input objects */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +); +#endif ivas_error ivas_param_ism_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ @@ -1368,9 +1493,9 @@ void ivas_param_ism_dec_render( #ifdef IVAS_FLOAT_FIXED void ivas_param_ism_dec_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ - uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ - uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ Word32 *output_f_fx[] ); void ivas_param_ism_params_to_masa_param_mapping_fx( @@ -1390,6 +1515,19 @@ void ivas_param_ism_params_to_masa_param_mapping( ivas_error ivas_ism_dtx_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +); +#endif // IVAS_FLOAT_FIXED /*! r: indication of DTX frame */ int16_t ivas_ism_dtx_enc( @@ -1440,6 +1578,14 @@ void ivas_ism_metadata_sid_dec( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ int16_t nb_bits_metadata[] /* o : number of metadata bits */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +); +#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -1452,6 +1598,14 @@ void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +); +#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -1846,6 +2000,16 @@ void filter_with_allpass( ); /*! r: used GR order */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +); +#else int16_t write_bitstream_adapt_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t Indice, /* i : identifier for bitstream index */ @@ -1854,8 +2018,27 @@ int16_t write_bitstream_adapt_GR( const int16_t GR_ord, /* i : GR order to be used */ const int16_t sp_aud_decision /* i : speech/music 0/1 */ ); +#endif /*! r: used GR order */ +#ifdef IVAS_FLOAT_FIXED +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); +#else int16_t adapt_GR_ief( const int16_t *in, /* i : vector to encode */ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */ @@ -1871,7 +2054,23 @@ int16_t adapt_GR_ief( float *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ const int16_t try_diff /* i : diff coding allowed 1/0 */ ); +#endif +#ifdef IVAS_FLOAT_FIXED +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); +#else /*! r: used GR order */ int16_t adapt_GR_rpg1_ief( const int16_t *in, /* i : res pred gains input vector */ @@ -1886,16 +2085,35 @@ int16_t adapt_GR_rpg1_ief( const int16_t no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ const int16_t try_diff /* i : diff coding allowed 1/0 */ ); +#endif /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); +#else int16_t write_GR1( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ const int16_t *in, /* i : input vector */ const int16_t len /* i : vector length */ ); +#endif /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +); +#else int16_t write_bitstream_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -1903,6 +2121,7 @@ int16_t write_bitstream_GR( const int16_t len, /* i : input data length */ const int16_t GR_ord /* i : GR order to be used */ ); +#endif #ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ @@ -2207,7 +2426,7 @@ void stereo_tca_dec( void stereo_tca_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *synth[CPE_CHANNELS], /* i/o: output synth */ - const int16_t output_frame /* i : length of a frame per channel */ + const Word16 output_frame /* i : length of a frame per channel */ ); void stereo_tca_scale_R_channel( @@ -2219,7 +2438,7 @@ void stereo_tca_scale_R_channel( void stereo_tca_scale_R_channel_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx, /* i/o: output synthesis, R channel */ - const int16_t output_frame /* i : frame length */ + const Word16 output_frame /* i : frame length */ ); void adjustTargetSignal( @@ -2232,10 +2451,10 @@ void adjustTargetSignal( void adjustTargetSignal_fx( Word32 *target_fx, - const int16_t prevShift, - const int16_t currShift, - const int16_t L_shift_adapt, - const int16_t method); + const Word16 prevShift, + const Word16 currShift, + const Word16 L_shift_adapt, + const Word16 method); /*----------------------------------------------------------------------------------* * IC-BWE Stereo prototypes *----------------------------------------------------------------------------------*/ @@ -2393,7 +2612,7 @@ void stereo_td_init_dec( void stereo_td_init_dec_fx( STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const int16_t last_element_mode /* i : last element mode */ + const Word16 last_element_mode /* i : last element mode */ ); void tdm_configure_dec( @@ -2423,9 +2642,9 @@ void tdm_upmix_plain_fx( const Word32 SCh_2_R_fx[], /* i : secondary channel */ const Word32 LR_ratio_fx, /* i : mixing ratio */ const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const int16_t start_index, /* i : start index */ - const int16_t end_index, /* i : end index */ - const int16_t plus_minus_flag /* i : plus/minus flag */ + const Word16 start_index, /* i : start index */ + const Word16 end_index, /* i : end index */ + const Word16 plus_minus_flag /* i : plus/minus flag */ ); void stereo_tdm_combine( @@ -2441,9 +2660,9 @@ void stereo_tdm_combine_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel*/ - const int16_t output_frame, /* i : Number of samples */ - const int16_t flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ - const int16_t tdm_ratio_idx /* i : TDM ratio index */ + const Word16 output_frame, /* i : Number of samples */ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ + const Word16 tdm_ratio_idx /* i : TDM ratio index */ ); /*! r: replication decision; 1 = Use old LP */ @@ -2575,7 +2794,6 @@ void tdm_low_rate_dec( float *bwe_exc, /* o : excitation for SWB TBE */ const float *lsf_new /* i : ISFs at the end of the frame */ ); - #ifdef IVAS_FLOAT_FIXED void tdm_SCh_LSF_intra_pred_fx( const Word32 element_brate, /* i : element bitrate */ @@ -2583,7 +2801,6 @@ void tdm_SCh_LSF_intra_pred_fx( Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ ); #endif - void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ @@ -2604,13 +2821,13 @@ void tdm_SCh_lsf_reuse_fx( void tdm_SCh_lsf_reuse_ivas_fx( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t element_brate, /* i : element bitrate */ + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word32 element_brate, /* i : element bitrate */ Word16 lsf_new[M], /* i/o: LSFs at the end of the frame */ Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */ const Word16 tdm_lsfQ_PCh[M], /* i : primary channel LSFs (log2(2.56)) */ const Word16 lsf_wgts[M], /* i : LSF weights Q15? */ - int16_t *beta_index /* i/o: quantization index */ + Word16 *beta_index /* i/o: quantization index */ ); void tdm_SCh_lsf_reuse( @@ -2763,11 +2980,6 @@ ivas_error initMdctItdHandling( const int32_t input_Fs /* i : input sampling rate */ ); -ivas_error initMdctItdHandling_fx( - STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word32 input_Fs /* i : input sampling rate */ -); - void stereo_mdct_enc_destroy( STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ ); @@ -3058,17 +3270,19 @@ void parse_stereo_from_bitstream( ); #endif +#ifndef IVAS_FLOAT_FIXED void FindSplitRatio( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ Encoder_State **sts /* i/o: Encoder state structure */ ); +#endif void ComputeSpectrumNoiseMeasure( const float *powerSpec, const int16_t L_frame, const int16_t startLine, const int16_t resetMemory, - int16_t *noiseFlags, + int8_t *noiseFlags, const int16_t lowpassLine ); @@ -3119,7 +3333,32 @@ void dequantize_sns( float snsQ_out[CPE_CHANNELS][NB_DIV][M], Decoder_State **sts ); +#ifdef IVAS_FLOAT_FIXED +void sns_avq_cod_fx( + const Word32 *sns_fx, /* i : Input sns vectors */ + Word16 exp_sns, + const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ + Word16 exp_snsmid, + Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ + Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ + Word16 *index, /* o : Quantization indices */ + const Word16 core, /* i : core */ + const Word16 L_frame, + const Word16 low_brate_mode /* i : flag low bit operating mode */ +); +void sns_avq_cod_stereo_fx( + const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ + Word16 exp_snl, + const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ + Word16 exp_snr, + const Word16 L_frame, + Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ + Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ + Word16 *indexl, /* o : Quantization indices (left channel) */ + Word16 *indexr /* o : Quantization indices (right channel) */ +); +#else void sns_avq_cod( const float *sns, /* i : Input sns vectors */ const float *snsmid, /* i : Input mid-sns vectors */ @@ -3130,7 +3369,6 @@ void sns_avq_cod( const int16_t L_frame, const int16_t low_brate_mode /* i : flag low bit operating mode */ ); - void sns_avq_cod_stereo( const float *snsl, /* i : Input sns vector (left channel) */ const float *snsr, /* i : Input sns vector (right channel) */ @@ -3140,6 +3378,7 @@ void sns_avq_cod_stereo( int16_t *indexl, /* o : Quantization indices (left channel) */ int16_t *indexr /* o : Quantization indices (right channel) */ ); +#endif void sns_avq_dec( int16_t *index, /* i : Quantization indices */ @@ -3214,7 +3453,7 @@ void applyDmxMdctStereo( void applyDmxMdctStereo_fx( const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder */ - const int16_t output_frame /* i : output frame length */ + const Word16 output_frame /* i : output frame length */ ); @@ -3305,8 +3544,8 @@ void stereo_cna_update_params( void stereo_cna_update_params_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const int16_t output_frame, /* i : Output frame length */ - const int16_t tdm_ratio_idx /* i : TDM ratio index */ + const Word16 output_frame, /* i : Output frame length */ + const Word16 tdm_ratio_idx /* i : TDM ratio index */ ); void dtx_enc_init( Encoder_State *st, /* i : Encoder state handle */ @@ -3377,6 +3616,20 @@ void v_add_inc_fx( const Word16 y_inc, /* i : increment for vector y[] */ const Word16 N /* i : Vector length */ ); +Word32 logsumexp_fx( + const Word32 x[], /* i : input array x */ + const Word16 x_e, + const Word16 N /* i : number of elements in array x */ +); +Word32 lin_interp32_fx( + const Word32 x, /* i : the value to be mapped */ + const Word32 x1, /* i : source range interval: low end */ + const Word32 y1, /* i : source range interval: high end */ + const Word32 x2, /* i : target range interval: low */ + const Word32 y2, /* i : target range interval: high */ + const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ + Word16 *Q_io /*i/o : i/o Q factor of the output*/ +); #endif void v_mult_inc( @@ -3485,8 +3738,15 @@ float dot_product_cholesky( Word32 dot_product_cholesky_fx( const Word32 *x, /* i : vector x */ const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N /* i : vector & matrix size */ + const Word16 N /* i : vector & matrix size */ ); +Word32 dot_product_cholesky_fixed( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N, /* i : vector & matrix size */ + const Word16 exp_x, + const Word16 exp_A, + Word16 *exp_sum ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3500,6 +3760,14 @@ void v_mult_mat_fx( const Word16 N, /* i : number of rows */ const Word16 C /* i : number of columns */ ); +void v_mult_mat_fixed( + Word32 *y, /* o : the product x*A */ + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : matrix A */ + const Word16 Nr, /* i : number of rows */ + const Word16 Nc, /* i : number of columns */ + Word16 guardbits +); #endif void v_mult_mat( @@ -3588,11 +3856,11 @@ void stereo_td2dft_update( void stereo_td2dft_update_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int16_t n, /* i : channel number */ + const Word16 n, /* i : channel number */ Word32 output_fx[], /* i/o: synthesis @internal Fs */ Word32 synth_fx[], /* i/o: synthesis @output Fs */ Word32 hb_synth_fx[], /* i/o: hb synthesis */ - const int16_t output_frame /* i : frame length */ + const Word16 output_frame /* i : frame length */ ); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -3606,12 +3874,21 @@ void stereo_mdct2dft_update_fx( Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ ); /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); +#else int16_t write_GR0( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ const int16_t *in, /* i : data to be encoded */ const int16_t len /* i : input data length */ ); +#endif #ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ @@ -3689,6 +3966,23 @@ void getChannelEnergies( float nrg[MCT_MAX_CHANNELS], /* o : energies */ const int16_t nchan /* i : number of channels */ ); +#ifdef IVAS_FLOAT_FIXED +void mctStereoIGF_enc_fx( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2], /* i : MDCT spectrum for ITF */ + Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate*/ + Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect.*/ + Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + float *orig_spectrum[MCT_MAX_CHANNELS][2], /* i : MDCT spectrum for ITF */ + float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate*/ + float *powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect.*/ + float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ +#endif + const Word16 sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */ +); +#endif // IVAS_FLOAT_FIXED void mctStereoIGF_enc( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ @@ -3831,7 +4125,7 @@ void deindex_sph_idx( float *phi /* o : Azimuth */ ); void deindex_sph_idx_fx( - const uint16_t sphIndex, /* i : Spherical index */ + const UWord16 sphIndex, /* i : Spherical index */ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ Word32 *theta_fx, /* o : Elevation */ Word32 *phi_fx /* o : Azimuth */ @@ -4757,7 +5051,7 @@ void ivas_param_mc_dec_digest_tc( void ivas_param_mc_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ Word32 *transport_channels_f_fx[], Word16 transport_f_e ); @@ -5224,11 +5518,19 @@ ivas_error ivas_spar_dec_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_close( SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ const int32_t output_Fs, /* i : output sampling rate */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +#else +void ivas_spar_dec_close_fx( + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); +#endif ivas_error ivas_spar_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ @@ -5236,13 +5538,13 @@ ivas_error ivas_spar_dec( ); void ivas_spar_config( - int32_t ivas_total_brate, /* i : codec total bitrate */ - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - int16_t *nchan_transport, /* o : number of transport channels */ - int16_t *nSCE, /* o : number of SCEs */ - int16_t *nCPE, /* o : number of CPEs */ - int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ - const int16_t sid_format /* i : IVAS format indicator from SID frame */ + int32_t ivas_total_brate, /* i : codec total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + int16_t *nchan_transport, /* o : number of transport channels */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE, /* o : number of CPEs */ + int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ + const int16_t sid_format /* i : IVAS format indicator from SID frame */ ); #ifdef IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer_fx( @@ -5265,13 +5567,13 @@ ivas_error ivas_sba_linear_renderer( ); #ifdef IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ - const Word16 bfi, /* i : BFI flag */ - const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix */ - const Word16 Q_p_Output /* i : number of subframes in mixing matrix */ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + Word32 *output_fx[], /* i/o: transport/output audio channels */ + const Word16 bfi, /* i : BFI flag */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame, /* i : output frame length */ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ ); #endif // IVAS_FLOAT_FIXED @@ -5691,18 +5993,18 @@ void ivas_get_spar_md_from_dirac_fx( Word32 azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], Word32 ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], Word32 diffuseness[IVAS_MAX_NUM_BANDS], - const int16_t n_ts, + const Word16 n_ts, Word32 ***mixer_mat, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, - const int16_t start_band, - const int16_t end_band, - const int16_t order, - const int16_t dtx_vad, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, Word32 Wscale_d[IVAS_MAX_NUM_BANDS], - const uint8_t useLowerRes, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ); #endif void ivas_get_spar_md_from_dirac( @@ -5765,10 +6067,10 @@ void ivas_spar_md_dec_close( void ivas_spar_get_parameters_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t ts, /* i : time slot index */ - const int16_t num_ch_out, /* i : number of channels out */ - const int16_t num_ch_in, /* i : number of channels in */ - const int16_t num_spar_bands, /* i : number of SPAR bands */ + const Word16 ts, /* i : time slot index */ + const Word16 num_ch_out, /* i : number of channels out */ + const Word16 num_ch_in, /* i : number of channels in */ + const Word16 num_spar_bands, /* i : number of SPAR bands */ Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); void ivas_spar_get_parameters( @@ -5806,10 +6108,10 @@ void ivas_spar_to_dirac( void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t dtx_vad, /* i : DTX frame flag */ - const int16_t num_bands_out, /* i : number of output bands */ - const int16_t bw, /* i : band joining factor */ - const int16_t dyn_active_w_flag /* i : dynamic active W flag */ + const Word16 dtx_vad, /* i : DTX frame flag */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bw, /* i : band joining factor */ + const Word16 dyn_active_w_flag /* i : dynamic active W flag */ ); void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ @@ -5852,6 +6154,21 @@ void ivas_spar_dec_gen_umx_mat( const int16_t num_md_sub_frames ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_spar_covar_enc_open_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_spar_covar_enc_close_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +); +#else /* Covariance module */ ivas_error ivas_spar_covar_enc_open( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ @@ -5866,6 +6183,7 @@ void ivas_spar_covar_enc_close( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ const int16_t nchan_inp /* i : number of input channels */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_enc_cov_handler_process_fx( @@ -5890,8 +6208,7 @@ void ivas_enc_cov_handler_process_fx( const Word16 nchan_transport, const Word16 is_sba ); -#endif - +#else void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -5911,8 +6228,9 @@ void ivas_enc_cov_handler_process( const int16_t nchan_transport, const int16_t is_sba ); +#endif -#ifdef IVAS_FLOAT_FIXED_ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_spar_covar_smooth_enc_open_fx( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -5926,8 +6244,7 @@ void ivas_spar_covar_smooth_enc_close_fx( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ const Word16 nchan_inp /* i : number of input channels */ ); -#endif - +#else ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -5941,6 +6258,7 @@ void ivas_spar_covar_smooth_enc_close( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ const int16_t nchan_inp /* i : number of input channels */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_cov_smooth_process_fx( @@ -5953,8 +6271,7 @@ void ivas_cov_smooth_process_fx( const Word16 transient_det[2], Word16 *q_cov[IVAS_SPAR_MAX_CH] ); -#endif - +#else void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -5964,6 +6281,7 @@ void ivas_cov_smooth_process( const int16_t num_ch, const int16_t transient_det[2] ); +#endif /* Transient detector module */ ivas_error ivas_transient_det_open( @@ -6223,22 +6541,45 @@ void ivas_arith_decode_cmplx_cell_array( int16_t *pSymbol_re_old ); +#ifndef IVAS_FLOAT_FIXED void ivas_ari_start_decoding_14bits_ext_1_lfe( Decoder_State *st, Tastat *s, int16_t *extra_bits_read ); +#else +void ivas_ari_start_decoding_14bits_ext_1_lfe( + Decoder_State *st, + Tastat *s, + Word16 *extra_bits_read +); +#endif +#ifndef IVAS_FLOAT_FIXED uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, const uint16_t *cum_freq, int16_t *extra_bits_read ); +#else +UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read +); +#endif +#ifndef IVAS_FLOAT_FIXED void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const int16_t extra_bits_read ); +#else +void ivas_ari_done_decoding_14bits_ext_1_lfe( + Decoder_State *st, + const Word16 extra_bits_read +); +#endif void ivas_ari_done_encoding_14bits( BSTR_ENC_HANDLE hBstr, Tastat *s @@ -6289,12 +6630,12 @@ void ivas_quantise_real_values( ); void ivas_quantise_real_values_fx( const Word32 *values_fx, - const int16_t q_levels, + const Word16 q_levels, const Word32 min_value_fx, const Word32 max_value_fx, - int16_t *index, + Word16 *index, Word32 *quant_fx, - const int16_t dim); + const Word16 dim); void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, @@ -7152,7 +7493,8 @@ void ivas_lfe_lpf_select_filt_coeff( void ivas_lfe_lpf_select_filt_coeff_fx( const Word32 sampling_rate, /* i : sampling rate */ const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ + const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ + const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ ); #endif @@ -7167,6 +7509,7 @@ void ivas_filters_init( void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const Word32 *filt_coeff, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order /* i : filter order */ ); #endif @@ -7333,6 +7676,17 @@ void ivas_set_surplus_brate_dec( int32_t *ism_total_brate /* i : ISM total bitrate */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ + Word16 ism_imp[] /* o : ISM importance flags */ +); +#endif + void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ const int16_t nchan_transport, /* i : number of transported channels */ @@ -7555,6 +7909,15 @@ ivas_error ivas_FB_mixer_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_FB_mixer_close_fx( + IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ + const Word32 sampling_rate, /* i : sampling rate in Hz */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +#endif + void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate in Hz */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 56709404a54f25ff3b968d6200baa6a7dae60dff..4cde97344461936ff7bd58ee2bea1d17a0288397 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -776,12 +776,15 @@ void destroy_cpe_dec( ); ivas_error ivas_cpe_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - Word32 *output[CPE_CHANNELS], /* o : output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - Word16 *q_output /* i/o : Q of output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 *output[CPE_CHANNELS], /* o : output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + , + Word16 *q_output /* i/o : Q of output synthesis signal */ +#endif ); void ivas_post_proc_fx( @@ -1123,6 +1126,20 @@ void stereo_dft_dec_fx( const Word16 num_md_sub_frames /* i : number of MD subframes */ ); +// ivas_stereo_dft_enc.c +#ifdef IVAS_FLOAT_FIXED +Word32 stereo_dft_enc_synthesize_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ + // float *output, /* o : output synthesis */ + Word32 *output_fx, /* o : output synthesis Q16 */ + Word16 *output_start_index, + Word16 *output_end_index, + const Word16 chan, /* i : channel number */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word32 output_sampling_rate, /* i : output sampling rate */ + const Word16 L_frame, /* i : frame length at internal Fs */ + Word16 *nrg_out_fx_e ); +#endif void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ @@ -1312,8 +1329,11 @@ void stereo_icBWE_decproc_fx( Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ const Word16 last_core, /* i : last core, primary channel */ const Word16 last_bwidth, /* i : last bandwidth */ - const Word16 output_frame, /* i : frame length */ - Word16 q_output /* i : Q-fac of output */ + const Word16 output_frame /* i : frame length */ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + , + Word16 q_output /* i : Q-fac of output */ +#endif ); void add_HB_to_mono_dmx_fx( @@ -1388,7 +1408,8 @@ void decoder_tcx_tns_fx( STnsData *tnsData, const Word16 bfi, /* i : Bad frame indicator */ const Word16 frame_cnt, /* i : frame counter in the super frame */ - const Word16 whitenedDomain ); + const Word16 whitenedDomain, + Word16 *length ); void ivas_mdct_core_tns_ns_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -2100,9 +2121,9 @@ void td_bwe_dec_init_ivas_fx( ); void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const int16_t nchan_transport, /* i : number of transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ); @@ -2116,15 +2137,15 @@ void ivas_dirac_dec_render_fx( ); void ivas_dirac_dec_read_BS_fx( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Decoder_State *st, /* i/o: decoder Core state structure */ DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */ - int16_t *nb_bits, /* o : number of bits read */ - const int16_t last_bit_pos, /* i : last read bitstream position */ - const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + Word16 *nb_bits, /* o : number of bits read */ + const Word16 last_bit_pos, /* i : last read bitstream position */ + const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); ivas_error ivas_dirac_dec_config_fx( @@ -2166,23 +2187,23 @@ ivas_error ivas_ism_metadata_dec_create_fx( Word32 element_brate_tmp[] /* o : element bitrate per object */ ); ivas_error ivas_sba_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - uint16_t *nSamplesFlushed, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesFlushed, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ ); ivas_error ivas_spar_md_dec_matrix_open_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels, /* i : number of internal channels */ - const int16_t num_md_sub_frames /* i : number of MD subframes */ + const Word16 num_channels, /* i : number of internal channels */ + const Word16 num_md_sub_frames /* i : number of MD subframes */ ); void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const Word16 num_channels /* i : number of internal channels */ ); ivas_error ivas_spar_dec_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); void ivas_param_mc_dec_read_BS_fx( @@ -2226,8 +2247,8 @@ ivas_error ivas_FB_mixer_open_fx( void ivas_FB_mixer_close_fx( IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ - const int32_t sampling_rate, /* i : sampling rate in Hz */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const Word32 sampling_rate, /* i : sampling rate in Hz */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); void ivas_fb_mixer_cross_fading_fx( @@ -2235,9 +2256,9 @@ void ivas_fb_mixer_cross_fading_fx( Word32 **ppOut_pcm_fx, Word32 *pMdft_out_old_fx, Word32 *pMdft_out_new_fx, - const int16_t ch, - const int16_t frame_len, - const int16_t cf_offset ); + const Word16 ch, + const Word16 frame_len, + const Word16 cf_offset ); // ivas_omasa_dec.c ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( @@ -2393,6 +2414,11 @@ Word16 ism_quant_meta_fx( const Word16 cbsize /* i : codebook size */ ); +/*! r: number of channels to be analysed */ +Word16 getNumChanAnalysis_fx( + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +); + ivas_error ivas_limiter_open_fx( IVAS_LIMITER_HANDLE *hLimiter_out, /* o : limiter struct handle */ const Word16 max_num_channels, /* i : maximum number of I/O channels to be processed */ @@ -2411,4 +2437,149 @@ void copy_masa_descriptive_meta_fx( void efap_free_data_fx( EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ ); + +void tdm_SCh_LSF_intra_pred_fx( + const Word32 element_brate, /* i : element bitrate */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ +); + +ivas_error ivas_create_lfe_lpf_enc_fx( + ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ + const Word32 input_Fs /* i : input sampling rate */ +); + +void ivas_lfe_lpf_enc_apply_fx( + ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ + Word32 data_lfe_ch[], /* i/o: LFE signal */ + const Word16 input_frame /* i : input frame length per channel */ +); + +// ivas_arith.c +void ivas_ari_done_encoding_14bits_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s ); + +void ivas_ari_encode_14bits_ext_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s, + Word32 symbol, + const UWord16 *cum_freq ); + +void ms_inv_mask_processing_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const int16_t iSubframe, /* i : subframe number */ + const Word32 x_0_fx[], /* i : spectrum 1 */ + const Word32 x_1_fx[], /* i : spectrum 2 */ + Word32 x_inv_0_fx[], /* o : inverse spectrum 1 */ + Word32 x_inv_1_fx[], /* o : inverse spectrum 2 */ + int16_t maxSfb /* i : number of stereo frequency bands */ +); + +void ms_processing_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const int16_t iSubframe, /* i : subframe number */ + Word32 x_0_fx[], /* i/o: spectrum 1 */ + Word32 x_1_fx[], /* i/o: spectrum 1 */ + Word16 maxSfb /* i : number of stereo frequency bands*/ +); + +void convertToMS_fx( + const int16_t L_frame, /* i : frame length */ + Word32 x0[], /* i/o: mid/left channel coefficients */ + Word32 x1[], /* i/o: side/right channel coefficients */ + const Word32 norm_fac /* i : normalization factor */ +); + +void FindSplitRatio_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + Encoder_State **sts /* i/o: Encoder state structure */ +); + +void IGFEncStereoEncoder_fx( + STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */ + const Word32 *mdctSpectrumL_fx, /* i : left spectrum */ + const Word32 *mdctSpectrumR_fx, /* i : right spectrum */ + Word16 q_mdctSpectrum, + Word16 *msMask, /* i/o: MS mask */ + Word16 *igfStereoMode, /* o : IGF stereo mode */ + const Word16 mdct_stereo_mode, /* i : MDCT stereo mode */ + const Word16 isTCX20, /* i : flag for indicating TCX20 */ + const Word16 isTransition /* i : flag for transtition */ +); + +void stereo_coder_tcx_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ + Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ + Word16 q_spec ); + +// bw_detect_fx.c +Word16 set_bw_mct_fx( + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ + const Word16 nCPE /* i : number of CPEs */ +); + + +// ivas_mct_enc_mct.c +void write_mct_bitstream_fx( + Encoder_State **sts, /* i/o: encoder state structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const Word16 nchan /* i : number of channels */ +); + +void getChannelEnergies_fx( + Encoder_State **sts, /* i/o: Encoder state structure */ + Word32 nrg[MCT_MAX_CHANNELS], /* o : buffer with energies for each channel */ + Word16 nrg_e[MCT_MAX_CHANNELS], /* o : exponents of energies for each channel */ + const Word16 nchan /* i : number of channels */ +); + +void apply_MCT_enc_fx( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + Word32 *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ + Word32 *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ + Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + const Word16 nchan /* i : number of channels */ +); #endif + +void ivas_spar_config_fx( + Word32 ivas_total_brate, /* i : codec total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 *nchan_transport, /* o : number of transport channels */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word32 *core_nominal_brate, /* o : core-coding nominal bitrate */ + const Word16 sid_format /* i : IVAS format indicator from SID frame */ +); + +Word16 ivas_get_bw_idx_from_sample_rate_fx( + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_spar_bitrate_dist_fx( + Word32 core_brates_act[], /* o : bitrates per core-coder */ + const Word16 nAvailBits, /* i : number of available bits */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth /* i : audio bandwidth */ +); + +void tdm_configure_dec_fx( + const Word16 ivas_format, /* i : IVAS format */ + const Word16 ism_mode, /* i : ISM mode in combined format */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 *tdm_ratio_idx, /* o : ratio index */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index dcd68f04b8e062c677f4df9d026aab957a932cac..3bcec831e87b6d4ee95bb86a0a08d6c5d6df389d 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -38,11 +38,10 @@ #include "ivas_rom_com.h" #include "ivas_prot.h" #include "prot.h" -#include "prot_fx1.h" #include "cnst.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index cc37a8565a2468f95f72555cc8e176f1725c40e7..8733ad0bd32caf5461105d5b01d8886153668b2d 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -6836,5 +6836,3 @@ const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9] = { +0.000000e+000f, +5.937500e-002f, +1.375000e-001f, +2.343750e-001f, +3.500000e-001f, +4.843750e-001f, +6.375000e-001f, +8.093750e-001f, +1.000000e+000f } /* data */ } }; - -/* clang-format on */ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 85bd01c215d49e21493dc19b814809a93ccc8c9d..a897454522c6c08fbefcf421d174b9137c64ffa2 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -106,6 +106,23 @@ extern const float tdm_den_ratio_tabl[]; extern const int16_t tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ +#ifdef IVAS_FLOAT_FIXED +extern const Word16 tdm_LSF_MEAN_RE_USE_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_fx[M]; + +extern const Word16 tdm_Beta_Q1bit_re_use_13k2_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_16k4_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_48k_fx[2]; + +extern const Word16 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15]; + +extern const Word16 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_fx[M]; +extern const Word16 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15]; +#endif extern const float tdm_LSF_MEAN_RE_USE_OUT[M]; extern const float tdm_LSF_MEAN_RE_USE_IN[M]; extern const float tdm_LSF_MEAN_RE_USE[M]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 31e156bcd5ff2e7767df5db1a44031a18cfe763c..affd420b94eb44e1325d8fb7fdcd7c3bad5380f4 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1288,6 +1288,7 @@ const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[128] = { * TD Stereo ROM tables *----------------------------------------------------------------------------------*/ +// Q31 const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1] = { 0, 0, 23407572, 52613348, 92771296, 143881408, 205084688, 275736896, 355193792, 442596384, 536870912, @@ -1297,6 +1298,14 @@ const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1] = { 2147483647, 2147483647, 2147483647 }; +// Q24 +const Word32 tdm_ratio_tabl_fx_Q24[TDM_NQ + 1] = { + 0, 0, 182871, 411041, 724775, 1124073, 1602224, 2154194, + 2774951, 3457784, 4194304, 4976122, 5796528, 6643777, 7511159, 8388608, + 9266056, 10133438, 10980688, 11801094, 12582912, 13319432, 14002264, 14623021, + 15174992, 15653143, 16052440, 16366174, 16594344, 16777216, 16777216, 16777216 +}; + const UWord32 tdm_den_ratio_tabl_fx[TDM_NQ + 1] = { 1073741824, 1073741824, 1097471488, 1127536256, 1170593280, 1227179520, 1297939072, 1383409024, 1483374336, 1596009856, 1717986944, @@ -1664,33 +1673,46 @@ const Word32 ism_elevation_borders_fx[4] = { *----------------------------------------------------------------------------------*/ const Word32 ivas_lpf_4_butter_16k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x1ab, 0x356, 0x1ab, 0x40000000, + // 0x1ab, 0x356, 0x1ab, 0x40000000, + 0x3558C94E, 0x3558C95D, 0x3558C94E, 0x40000000, 0x85ec0b80, 0x3a3cb940, 0x40000000, 0x7fffffff, 0x40000000, 0x40000000, 0x829d8180, 0x3d8c5e40 }; +const Word16 ivas_lpf_4_butter_16k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -20, -19, -20, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; const Word32 ivas_lpf_4_butter_32k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x1c, 0x37, 0x1c, 0x40000000, + // 0x1c, 0x37, 0x1c, 0x40000000, + 0x371ED5AA, 0x371ED5BA, 0x371ED5AA, 0x40000000, 0x82fd4b80, 0x3d0d2280, 0x40000000, 0x7fffffff, 0x40000000, 0x40000000, 0x81478600, 0x3ec30c00 }; +const Word16 ivas_lpf_4_butter_32k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -24, -23, -24, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; const Word32 ivas_lpf_4_butter_48k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x6, 0xb, 0x6, 0x40000000, - 0x81ffd700, 0x3e04d500, 0x40000000, 0x7fffff80, - 0x40000000, 0x40000000, 0x80d8b600, 0x3f2c0080 + // 6, 11, 6, 1073741824, /* Q30 */ + 1477520448, 1477520448, 1477520448, 1073741824, + -2113939767, 1040504054, 1073741824, 2147483480, + 1073741829, 1073741824, -2133281237, 1059848324 +}; +const Word16 ivas_lpf_4_butter_48k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -27, -26, -27, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; -const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0xa4d0c, 0x149a17, 0xa4d0c, 0x40000000, 0x849e6300, 0x3b8ad140 +const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + 0xa4d0c, 0x149a17, 0xa4d0c, 0x40000000, 0x849e6300, 0x3b8ad140 }; -const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0x53e1a, 0x29f0d, 0x40000000, 0x824f6000, 0x3dbb1c80, 0x29f0d +const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + // 0x53e1a, 0x29f0d, 0x40000000, 0x824f6000, 0x3dbb1c80, 0x29f0d + 0x29F0D, 0x53E1A, 0x29F0D, 0x40000000, 0x824F5FC3, 0x3DBB1C71 }; -const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 +const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 }; const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { @@ -3516,7 +3538,7 @@ const Word16 *const ivas_sns_cdbks_side_tcx10_fx[SNS_MSVQ_NSTAGES_SIDE] = { /*----------------------------------------------------------------------* * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED const ACPL_QUANT_TABLE_FX ivas_mc_paramupmix_alpha_quant_table_fx = { 33, /* nquant */ 16, /* offset */ @@ -3583,7 +3605,7 @@ const ACPL_QUANT_TABLE_FX ivas_mc_paramupmix_beta_quant_table_fx[9] = { { 0, 15938355, 36909876, 62914560, 93952408, 130023424, 171127600, 217264944, 268435456 } /* data in Q28 */ } }; - +#endif /* Q Factor is 31*/ const Word32 ivas_han_win_48k_fx[L_FRAME32k] = { 5760, 22976, 51712, 91904, 143552, 206784, 281408, 367552, 465216, diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 26940e6765802c9073f6bcf06e0d87e78f91689d..6692f0afd9713eac8bd2f0078baadd5a04cb058a 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -40,7 +40,6 @@ #include "stat_com.h" #include "ivas_stat_com.h" -#ifdef IVAS_FLOAT_FIXED extern const Word16 ivas_sin_twiddle_480_fx[IVAS_480_PT_LEN >> 1]; extern const Word16 ivas_cos_twiddle_480_fx[IVAS_480_PT_LEN >> 1]; @@ -50,6 +49,7 @@ extern const Word16 ivas_sin_twiddle_160_fx[IVAS_160_PT_LEN >> 1]; extern const Word16 ivas_cos_twiddle_160_fx[IVAS_160_PT_LEN >> 1]; extern const Word16 ivas_sin_twiddle_80_fx[IVAS_80_PT_LEN >> 1]; extern const Word16 ivas_cos_twiddle_80_fx[IVAS_80_PT_LEN >> 1]; +#ifdef IVAS_FLOAT_FIXED extern const Word16 nf_tw_smoothing_coeffs_fx[N_LTP_GAIN_MEMS]; extern const Word32 dft_res_gains_q_fx[][2]; extern const Word16 dft_res_cod_alpha_fx[STEREO_DFT_BAND_MAX]; @@ -106,6 +106,7 @@ extern const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[]; *----------------------------------------------------------------------------------*/ extern const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1]; +extern const Word32 tdm_ratio_tabl_fx_Q24[TDM_NQ + 1]; extern const UWord32 tdm_den_ratio_tabl_fx[]; /* LSFs Intra-frame prediction tables */ @@ -206,8 +207,11 @@ extern const Word32 ism_elevation_borders_fx[4]; *----------------------------------------------------------------------------------*/ extern const Word32 ivas_lpf_4_butter_16k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_16k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_4_butter_32k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_32k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_4_butter_48k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_48k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1]; diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index d053e957ff1d0a281af475524815344c2d27024e..ee29a001dd2266263cb97a95f0838ef75f8e5ce4 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -34,8 +34,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "rom_com.h" #include "ivas_rom_com.h" @@ -280,14 +279,14 @@ void sns_interpolate_scalefactors_fx( FOR( n = 0; n <= M - 2; n++ ) { - scf_int[add( n * 4, 2 )] = L_add( scf[n], Mpy_32_16_1( L_sub( scf[n + 1], scf[n] ), 4096 ) ); /* 4096 -> 1/8 in Q15 */ - scf_int[add( n * 4, 3 )] = L_add( scf[n], Mpy_32_16_1( L_sub( scf[n + 1], scf[n] ), 12288 ) ); /* 12288 -> 3/8 in Q15 */ - scf_int[add( n * 4, 4 )] = L_add( scf[n], Mpy_32_16_1( L_sub( scf[n + 1], scf[n] ), 20480 ) ); /* 20480 -> 5/8 in Q15 */ - scf_int[add( n * 4, 5 )] = L_add( scf[n], Mpy_32_16_1( L_sub( scf[n + 1], scf[n] ), 28672 ) ); /* 28672 -> 7/8 in Q15 */ + scf_int[add( n * 4, 2 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 ); /* 4096 -> 1/8 in Q15 */ + scf_int[add( n * 4, 3 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 ); /* 12288 -> 3/8 in Q15 */ + scf_int[add( n * 4, 4 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 ); /* 20480 -> 5/8 in Q15 */ + scf_int[add( n * 4, 5 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 ); /* 28672 -> 7/8 in Q15 */ } - scf_int[FDNS_NPTS - 2] = L_add( scf[M - 1], Mpy_32_16_1( L_sub( scf[M - 1], scf[M - 2] ), 4096 ) ); - scf_int[FDNS_NPTS - 1] = L_add( scf[M - 1], Mpy_32_16_1( L_sub( scf[M - 1], scf[M - 2] ), 12288 ) ); + scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 ); + scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 ); /* Inversion at encoder-side */ IF( encoder_side == ENC ) diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 36938507a21808b4f96c83a81bc46fe51dd8e9ac..2a29c60740faa3f6efef218431b67ca0645a28a4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -36,8 +36,7 @@ #include "basop_util.h" #include "ivas_stat_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "rom_com.h" #include "ivas_rom_com.h" @@ -129,6 +128,7 @@ static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int1 *-----------------------------------------------------------------------------------------*/ /*! r: audio BW index */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_bw_idx_from_sample_rate( const int32_t sampling_rate /* i : sampling rate */ ) @@ -153,6 +153,35 @@ int16_t ivas_get_bw_idx_from_sample_rate( return bwidth; } +#else +Word16 ivas_get_bw_idx_from_sample_rate_fx( + const Word32 sampling_rate /* i : sampling rate */ +) +{ + Word16 bwidth = 0; + move16(); + + SWITCH( sampling_rate ) + { + case 16000: + bwidth = WB; + move16(); + BREAK; + case 32000: + bwidth = SWB; + move16(); + BREAK; + case 48000: + bwidth = FB; + move16(); + BREAK; + default: + assert( !"Unsupported sample rate!" ); + } + + return bwidth; +} +#endif /*------------------------------------------------------------------------- * ivas_spar_config() @@ -160,6 +189,7 @@ int16_t ivas_get_bw_idx_from_sample_rate( * SPAR configuration function *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_config( int32_t ivas_total_brate, /* i : codec total bitrate */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -218,6 +248,84 @@ void ivas_spar_config( return; } +#else +void ivas_spar_config_fx( + Word32 ivas_total_brate, /* i : codec total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 *nchan_transport, /* o : number of transport channels */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word32 *core_nominal_brate, /* o : core-coding nominal bitrate */ + const Word16 sid_format /* i : IVAS format indicator from SID frame */ +) +{ + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + IF( EQ_16( sid_format, SID_SBA_1TC ) ) + { + *nchan_transport = 1; + move16(); + } + ELSE + { + *nchan_transport = 2; + move16(); + } + } + ELSE + { + *nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_order ); + move16(); + } + + IF( GT_16( *nchan_transport, 1 ) ) + { + *nCPE = shr( add( *nchan_transport, 1 ), 1 ); + move16(); + } + ELSE + { + *nCPE = 0; + move16(); + } + + *nSCE = max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); + move16(); + + IF( EQ_16( *nchan_transport, 1 ) ) + { + /* map SPAR SID bitrate to SPAR active bitrate */ + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + ivas_total_brate = IVAS_32k; + move32(); + } + assert( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_24k4 || ivas_total_brate == IVAS_16k4 || ivas_total_brate == IVAS_13k2 ); + IF( EQ_32( ivas_total_brate, IVAS_32k ) ) + { + *core_nominal_brate = ACELP_24k40; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_24k4 ) ) + { + *core_nominal_brate = ACELP_16k40; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_16k4 ) ) + { + *core_nominal_brate = ACELP_13k20; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) + { + *core_nominal_brate = ACELP_9k60; + move32(); + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_spar_table_idx() @@ -284,14 +392,21 @@ Word16 ivas_get_spar_table_idx_fx( { Word16 table_idx = 0, ind1[IVAS_SPAR_BR_TABLE_LEN]; Word16 i, j = 0, ind2 = -1; + move16(); + move16(); + move16(); FOR( i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++ ) { ind1[j] = 0; + move16(); + test(); IF( ( EQ_32( ivas_spar_br_table_consts[i].ivas_total_brate, ivas_total_brate ) ) && ( EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) ) { - ind1[j++] = i; + ind1[j] = i; + j = add( j, 1 ); + move16(); } } @@ -300,6 +415,7 @@ Word16 ivas_get_spar_table_idx_fx( IF( EQ_16( ivas_spar_br_table_consts[ind1[i]].bwidth, bwidth ) ) { ind2 = i; + move16(); BREAK; } } @@ -307,15 +423,18 @@ Word16 ivas_get_spar_table_idx_fx( assert( ind2 >= 0 ); /* to check if bw entry is present */ table_idx = ind1[ind2]; + move16(); IF( ind != NULL ) { *ind = ind2; + move16(); } IF( bitlen != NULL ) { - *bitlen = ivas_get_bits_to_encode( j - 1 ); + *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); + move16(); } return table_idx; @@ -353,6 +472,7 @@ Word16 ivas_get_sba_num_TCs_fx( table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); return nchan_transport; } @@ -601,46 +721,67 @@ static void ivas_get_pred_coeffs_fx( Word16 pred_dim = sub( in_chans, 1 ); Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; - w_norm_fac = EQ_16( from_dirac, 1 ) ? ONE_IN_Q29 : 3 * ONE_IN_Q29; // Q29 + IF( EQ_16( from_dirac, 1 ) ) + { + w_norm_fac = ONE_IN_Q29; + move32(); + } + ELSE + { + w_norm_fac = 3 * ONE_IN_Q29; + move32(); + } tmp_shift = Q30; - IF( EQ_16( active_w, 0 ) ) + move16(); + IF( active_w == 0 ) { Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; Word16 q_pred_temp; prev_tmp_shift = 31; + move16(); set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { div_factor[k] = L_max( 1, cov_real[0][0][k] ); + move32(); tmp_shift = Q30; + move16(); IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) { div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move16(); IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } } @@ -649,68 +790,87 @@ static void ivas_get_pred_coeffs_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + move32(); // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 + move32(); } } - *q_pred_coeffs = tmp_shift - 1; + *q_pred_coeffs = sub( tmp_shift, 1 ); + move16(); + FOR( k = start_band; k < end_band; k++ ) { - q_pred_temp = 31 - ( 2 * ( *q_pred_coeffs ) - 31 ); + q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + move32(); IF( LT_16( q_pred_temp, 1 ) ) { - pPred_temp[k] = L_shr( pPred_temp[k], abs_s( q_pred_temp ) + 1 ); // Q30 + pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); q_pred_temp = 1; + move16(); } ELSE IF( GT_16( q_pred_temp, 1 ) ) { - pPred_temp[k] = L_shl( pPred_temp[k], abs_s( q_pred_temp ) - 1 ); // Q30 + pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); q_pred_temp = 1; + move16(); } - one_in_q = L_shl( 1, ( 31 - q_pred_temp ) ); + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); IF( LT_32( one_in_q, pPred_temp[k] ) ) { div_factor[k] = pPred_temp[k]; + move32(); div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); } ELSE { div_factor[k] = one_in_q; - tmp_shift = ( 31 - q_pred_temp ); + move32(); + tmp_shift = sub( 31, q_pred_temp ); } IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } @@ -719,11 +879,14 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 + move32(); ppDM_Fv_re[i][k] = 0; + move32(); } } - *q_pred_coeffs = *q_pred_coeffs + tmp_shift - 31; + *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); *q_dm_fv_re = 0; + move16(); } ELSE { @@ -738,14 +901,21 @@ static void ivas_get_pred_coeffs_fx( prev_tmp_shift = 31; dm_alpha_e = 0; Word16 dm_beta_re_e = 0; + move32(); + move16(); + move16(); + move16(); + IF( EQ_16( dyn_active_w_flag, 1 ) ) { activew_quad_thresh = ONE_IN_Q29; + move32(); } ELSE { activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -758,50 +928,65 @@ static void ivas_get_pred_coeffs_fx( // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 + move32(); } } FOR( k = start_band; k < end_band; k++ ) { - dm_alpha_e = 31 - Q29; + dm_alpha_e = sub( 31, Q29 ); dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); - IF( LT_16( dm_alpha_e, 0 ) ) + move32(); + IF( dm_alpha_e < 0 ) { dm_alpha[k] = L_shr( dm_alpha[k], abs_s( dm_alpha_e ) ); + move32(); dm_alpha_e = 0; + move16(); } - ELSE IF( GT_16( dm_alpha_e, 0 ) ) + ELSE IF( dm_alpha_e > 0 ) { dm_alpha[k] = L_shl( dm_alpha[k], abs_s( dm_alpha_e ) ); + move32(); dm_alpha_e = 0; + move16(); } div_factor[k] = L_max( dm_alpha[k], 1 ); + move32(); div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } @@ -810,16 +995,27 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 + move32(); } } - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + move32(); } ELSE { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR_Q30 : IVAS_ACTIVEW_DM_F_Q30; + IF( active_w_vlbr ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + move32(); + } } FOR( b = start_band; b < end_band; b++ ) @@ -833,11 +1029,13 @@ static void ivas_get_pred_coeffs_fx( Word32 re; // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 + re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 + move32(); } } dm_beta_re = 0; + move32(); FOR( k = 0; k < pred_dim; k++ ) { Word32 re; @@ -846,37 +1044,45 @@ static void ivas_get_pred_coeffs_fx( dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 } - dm_beta_re_e = 31 - ( 2 * tmp_shift - 3 - 31 ); + dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); dm_w = cov_real[0][0][b]; // Q30 + move32(); den_f = L_max( dm_w, 1 ); passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); - div_shift = 15 - ( 31 - dm_alpha_e - Q30 ) + s_div - 1; + div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); passive_g = L_shl( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; + move32(); dm_w = 0; + move32(); FOR( i = 0; i < pred_dim; i++ ) { dm_v_re[i][b] = 0; + move32(); } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + move32(); } ELSE { - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); } passive_g = activew_quad_thresh; + move32(); } IF( LT_32( passive_g, activew_quad_thresh ) ) { /*linear activeW*/ dm_y = 0; + move32(); FOR( k = 1; k < in_chans; k++ ) { @@ -886,31 +1092,37 @@ static void ivas_get_pred_coeffs_fx( den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 + move32(); - div_shift = 15 - ( 30 - (dm_alpha_e) -28 ) + s_div; + div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + move32(); L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = 29 + 2 * tmp_shift - 65; // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, ( 29 - L_tmp2_q ) ); + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); den_f = L_add( L_tmp1, L_tmp2 ); // Q29 den_f = L_max( den_f, 1 ); den_f_e = 29; + move16(); L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); - L_tmp2_q = 30 + 2 * tmp_shift - 34 - 31; - L_tmp2 = L_shl( L_tmp2, ( 30 - dm_alpha_e - L_tmp2_q ) ); - L_tmp1 = L_shr( dm_alpha[b], ( 31 - dm_alpha_e - 30 ) ); + L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 30, dm_alpha_e ) ), L_tmp2_q ) ) ); + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 30 ) ) ); L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q30 dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q30 + den_f_e - 31 - div_shift = 15 - ( 30 - ( den_f_e ) ) + s_div; + move32(); + div_shift = add( sub( 15, ( sub( 30, den_f_e ) ) ), s_div ); dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + move32(); } ELSE { @@ -924,18 +1136,21 @@ static void ivas_get_pred_coeffs_fx( sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ val_e = 4; + move16(); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); - IF( LT_16( val_e, 0 ) ) + IF( val_e < 0 ) { sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); } - ELSE IF( GT_16( val_e, 0 ) ) + ELSE IF( val_e > 0 ) { sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); val_e = 0; + move16(); } num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); @@ -943,10 +1158,13 @@ static void ivas_get_pred_coeffs_fx( den_f_e = add( dm_beta_re_e, 4 ); den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 + move32(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + move32(); s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ div_shift = sub( s_dm_f, 1 ); DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); } } @@ -955,11 +1173,15 @@ static void ivas_get_pred_coeffs_fx( FOR( b = start_band; b < end_band; b++ ) { ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + move32(); ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + move32(); } } - *q_pred_coeffs = tmp_shift - 2; - *q_dm_fv_re = tmp_shift - 2; + *q_pred_coeffs = sub( tmp_shift, 2 ); + move16(); + *q_dm_fv_re = sub( tmp_shift, 2 ); + move16(); } return; @@ -1071,12 +1293,12 @@ static void ivas_get_Wscaling_factor_fx( set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); } - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 move32(); } - ELSE IF( NE_16( active_w_vlbr, 0 ) ) + ELSE IF( active_w_vlbr != 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 move32(); @@ -1093,7 +1315,7 @@ static void ivas_get_Wscaling_factor_fx( move32(); test(); - IF( EQ_16( active_w, 1 ) && EQ_16( dyn_active_w_flag, 0 ) ) + IF( EQ_16( active_w, 1 ) && ( dyn_active_w_flag == 0 ) ) { Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; Word32 Gw_sq, g_sq, tmp; @@ -1111,7 +1333,7 @@ static void ivas_get_Wscaling_factor_fx( guard_bits = find_guarded_bits_fx( num_ch ); - FOR( ch = 0; ch < num_ch - 1; ch++ ) + FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); g_sq = L_add( g_sq, abs_val ); @@ -1144,6 +1366,7 @@ static void ivas_get_Wscaling_factor_fx( tmp = L_shr( tmp, sub( q_tmp, q_min ) ); pWscale[b] = Mpy_32_32( L_add( Gw_sq, tmp ), ONE_IN_Q30 /* 0.5 in Q31*/ ); + move32(); q_pWscale[b] = q_Gw_sq; move16(); } @@ -1324,7 +1547,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[sub( j, 1 )][b] ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); } @@ -1352,7 +1575,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + tmp_p1_re[0][j][b] = dm_fv_re[sub( j, 1 )][b]; move32(); max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); } @@ -1377,6 +1600,7 @@ void ivas_create_fullr_dmx_mat_fx( } } *q_mixer_mat = sub( add( q_dm_fv_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + move16(); } ELSE { @@ -1392,6 +1616,7 @@ void ivas_create_fullr_dmx_mat_fx( } } *q_mixer_mat = q_pred_coeffs_re; + move16(); } IF( NE_16( remix_unmix_order, 3 ) ) @@ -1594,13 +1819,15 @@ static void ivas_calc_post_pred_per_band_fx( FOR( j = 0; j < num_ch; j++ ) { tmp_re = 0; + move64(); FOR( k = 0; k < num_ch; k++ ) { tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); } - IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { tmp_re = 0; + move64(); } temp_mat[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); // Q = (q_cov_real - guard_bits) move32(); @@ -1634,7 +1861,7 @@ static void ivas_calc_post_pred_per_band_fx( tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); } - IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { tmp_re = 0; move64(); @@ -1646,6 +1873,7 @@ static void ivas_calc_post_pred_per_band_fx( } *q_postpred_cov_re = sub( q_temp_mat, guard_bits ); + move16(); FOR( i = 0; i < num_ch; i++ ) { @@ -1889,29 +2117,29 @@ static void ivas_calc_p_coeffs_per_band_fx( set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0; move16(); - FOR( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + FOR( i = 0; i < sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ); i++ ) { - set32_fx( recon_uu_re[i], 0, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + set32_fx( recon_uu_re[i], 0, sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ) ); } FOR( i = num_dmx; i < num_ch; i++ ) { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; move32(); } } q_cov_uu_re = q_postpred_cov_re; move16(); - IF( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { FOR( i = 1; i < num_dmx; i++ ) { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; move32(); } } @@ -1930,6 +2158,10 @@ static void ivas_calc_p_coeffs_per_band_fx( recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); + move32(); + move32(); + move32(); + move32(); FOR( i = 0; i < 2; i++ ) { @@ -1961,8 +2193,10 @@ static void ivas_calc_p_coeffs_per_band_fx( move32(); re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + move32(); cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) { @@ -1993,7 +2227,7 @@ static void ivas_calc_p_coeffs_per_band_fx( } /* Step 2: cov_uu - recon_uu */ - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { FOR( j = 0; j < num_ch - num_dmx; j++ ) { @@ -2008,7 +2242,7 @@ static void ivas_calc_p_coeffs_per_band_fx( move32(); test(); - IF( EQ_16( dtx_vad, 0 ) && EQ_16( num_dmx, 1 ) ) + if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; move32(); @@ -2019,7 +2253,7 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); + trace = L_add( trace, L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); @@ -2038,7 +2272,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), 15 ) ); + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), 15 ) ); move32(); } ELSE @@ -2055,8 +2289,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); - cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = L_shl( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); move32(); move32(); } @@ -2068,7 +2302,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )]; move32(); } } @@ -2202,9 +2436,9 @@ static void ivas_calc_c_coeffs_per_band_fx( b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); return; @@ -2214,7 +2448,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; move32(); } } @@ -2223,7 +2457,8 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); } } @@ -2241,40 +2476,40 @@ static void ivas_calc_c_coeffs_per_band_fx( IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { /* protection from cases when variance of residual channels is very small */ - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); } ELSE { - FOR( i = 0; i < num_dmx - 1; i++ ) + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); move32(); } test(); - IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1 ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) + IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ) ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) { - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); } ELSE { - ivas_calc_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1, cov_dd_re_inv, &q_cov_dd_re_inv ); + ivas_calc_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ), cov_dd_re_inv, &q_cov_dd_re_inv ); Word16 tmp; Word64 max_val = 1; move64(); Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { C_re_fx[i][j] = 0; move64(); - FOR( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); move64(); @@ -2288,15 +2523,16 @@ static void ivas_calc_c_coeffs_per_band_fx( tmp = s_max( sub( 32, W_norm( max_val ) ), 0 ); - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); move32(); } } pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub( add( q_cov_dd_re_inv, q_post_pred_cov_re ), tmp ); + move16(); } } @@ -2399,15 +2635,15 @@ void ivas_calc_c_p_coeffs_fx( IF( dyn_active_w_flag ) { - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; move32(); } } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; move16(); } IF( EQ_16( compute_p_flag, 1 ) ) @@ -2419,10 +2655,10 @@ void ivas_calc_c_p_coeffs_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; move32(); } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; move16(); } } @@ -2512,6 +2748,7 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); *det_re = W_sub_nosat( *det_re, re1 ); + move64(); re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); @@ -2520,8 +2757,10 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); *det_re = W_add_nosat( *det_re, re1 ); + move64(); *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) { @@ -2529,7 +2768,9 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); *det_re = W_sub_nosat( re1, re2 ); + move64(); *q_det_re = add( q_in_re, q_in_re ); + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { @@ -2775,13 +3016,18 @@ static void ivas_calc_mat_inv_fx( out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); - out_re[0][1] = -Mpy_32_16_1( in_re[0][1], one_by_det ); + out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); - out_re[1][0] = -Mpy_32_16_1( in_re[1][0], one_by_det ); + out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + move32(); + move32(); + move32(); + move32(); *q_out_re = sub( q_in_re, add( q_tmp, q_det_re ) ); // Q = (15-(q_tmp + q_det_re)) + q_in_re - 15 + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) { @@ -2799,7 +3045,7 @@ static void ivas_calc_mat_inv_fx( det_re = W_shr( det_re, q_tmp ); q_det_re = sub( q_det_re, q_tmp ); - IF( EQ_64( det_re, 0 ) ) + if ( det_re == 0 ) { det_re = 1; move64(); @@ -2833,6 +3079,7 @@ static void ivas_calc_mat_inv_fx( } } *q_out_re = sub( add( sub( q_W_tmp, 32 ), q_one_by_det ), 15 ); + move16(); } ELSE { @@ -2902,7 +3149,7 @@ static Word16 ivas_is_mat_inv_fx( det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); - IF( LE_64( det, IVAS_FIX_EPS ) ) + if ( LE_64( det, IVAS_FIX_EPS ) ) { is_det_zero = 1; move16(); @@ -3014,25 +3261,24 @@ void ivas_compute_spar_params_fx( q_tmp = sub( 15, tmp_exp ); tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); - FOR( i = 0; i < num_ch - 1; i++ ) + FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); move32(); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { - tmp = -tmp; - move16(); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], add( tmp, 22 ) ); + tmp = negate( tmp ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], add( tmp, 22 ) ); move32(); } ELSE { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], sub( tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], sub( tmp, 22 ) ); move32(); } } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q22; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -3044,22 +3290,22 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; + ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; move16(); IF( NE_16( ndm, num_ch ) ) { ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - Word16 q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx; + Word16 q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx; IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX - FOR( i = 0; i < num_ch - ndm; i++ ) + FOR( i = 0; i < sub( num_ch, ndm ); i++ ) { - FOR( int j = 0; j < ndm - 1; j++ ) + FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j], sub( q_tmp, 22 ) ); move32(); } } @@ -3072,16 +3318,20 @@ void ivas_compute_spar_params_fx( } } #endif - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = Q22; + move16(); } - q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx; + q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx; + move16(); - for ( int j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j], sub( q_tmp, 22 ) ); + move32(); } - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = Q22; + move16(); } } @@ -3121,515 +3371,490 @@ void ivas_get_spar_md_from_dirac_fx( const int16_t dyn_active_w_flag ) { - int16_t num_ch, band, i, j; - int16_t block, ch; + Word16 num_ch, band, i, j; + Word16 block, ch; - // float response_avg[MAX_OUTPUT_CHANNELS]; Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; - // float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; - // float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - // float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - // float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 q_dm_fv_re_fx = 0; - // float Wscale[IVAS_MAX_NUM_BANDS]; - Word16 q_Wscale[IVAS_MAX_NUM_BANDS] = { 0 }; - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS] = { 0 }; - // float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; - // float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; - // float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_ppMixer_mat = 0; - // float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; - int16_t active_w; + Word16 active_w; + move16(); + move16(); - int16_t ndm, foa_ch, hoa2_ch; - // float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; + Word16 ndm, foa_ch, hoa2_ch; Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; - const int16_t *remix_order; + const Word16 *remix_order; + set16_fx( q_Wscale, 0, IVAS_MAX_NUM_BANDS ); + set32_fx( Wscale_fx, 0, IVAS_MAX_NUM_BANDS ); remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; num_ch = ivas_sba_get_nchan_metadata_fx( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); hoa2_ch = ivas_sba_get_nchan_metadata_fx( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - // hoa2_ch max 6 foa_ch = FOA_CHANNELS; - // foa_ch 4; - // diff_norm_order1 = 3.0f; + move16(); diff_norm_order1_fx = 3; - // diff_norm_order2 = 5.0f; + move32(); diff_norm_order2_fx = 5; - // diff_norm_order3 = 7.0f; + move32(); diff_norm_order3_fx = 7; + move32(); - for ( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) + FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) { - for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) + FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { - // pMixer_mat[i][j] = mixer_mat_local[i][j]; pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; + move32(); } - // ppMixer_mat[i] = pMixer_mat[i]; ppMixer_mat_fx[i] = pMixer_mat_fx[i]; + move32(); } - if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GE_16( start_band, 6 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) || ( useLowerRes && GE_16( start_band, 3 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) ) { - // float P_norm[3]; Word32 P_norm_fx[3]; - int16_t idx; + Word16 idx; - ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; - // ndm max value of 4 - // P_norm[0] = 0.0f; + ndm = hSpar_md_cfg->num_dmx_chans_per_band[sub( start_band, 1 )]; + move16(); P_norm_fx[0] = 0; - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + move32(); + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - // use 64bit if low precission - // P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[0] = P_norm_fx[0] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - // P_norm_fx[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, foa_ch - ndm ) )] ); + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); + move32(); - // P_norm[1] = 0.0f; P_norm_fx[1] = 0; - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + move32(); + FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - // P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[1] = P_norm_fx[1] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - // P_norm_fx[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, min( num_ch, hoa2_ch ) - ndm ) )] ); - + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); + move32(); - // P_norm[2] = 0.0f; P_norm_fx[2] = 0; - for ( ; i < num_ch - ndm; i++ ) + move32(); + FOR( ; i < sub( num_ch, ndm ); i++ ) { - // P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[2] = P_norm_fx[2] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - // P_norm_fx[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, num_ch - ndm ) )] ); + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, sub( num_ch, ndm ) ) )] ); + move32(); - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + move32(); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[0], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[1], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } - for ( ; i < num_ch - ndm; i++ ) + FOR( ; i < sub( num_ch, ndm ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + move32(); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[2], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } } - for ( int16_t i_ts = 0; i_ts < n_ts; i_ts++ ) + FOR( Word16 i_ts = 0; i_ts < n_ts; i_ts++ ) { - for ( band = start_band; band < end_band; band++ ) + FOR( band = start_band; band < end_band; band++ ) { ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); /*SPAR from DirAC*/ - // set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); set32_fx( response_avg_fx, 0, MAX_OUTPUT_CHANNELS ); - if ( n_ts > 1 ) + IF( GE_16( n_ts, 1 ) ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][i_ts], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][i_ts], Q22 ), response_avg_fx, order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ), response_avg_fx, order, Q30 ); } - else if ( useLowerRes ) + ELSE IF( useLowerRes ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][0], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][0], Q22 ), response_avg_fx, order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ), response_avg_fx, order, Q30 ); } - else + ELSE { - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][block], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][block], Q22 ), &( response_fx[block][0] ), order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response[block][l] = (float) response_fx[block][l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ), &( response_fx[block][0] ), order, Q30 ); } /* average responses in all subframes*/ { - // float norm; Word32 norm_fx; Word16 norm_q; - int16_t num_ch_order, hoa2_ch_order; + Word16 num_ch_order, hoa2_ch_order; num_ch_order = ivas_sba_get_nchan_fx( order, 0 ); hoa2_ch_order = ivas_sba_get_nchan_fx( SBA_HOA2_ORDER, 0 ); - for ( ch = 0; ch < num_ch_order; ch++ ) + FOR( ch = 0; ch < num_ch_order; ch++ ) { Word64 temp = 0; - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + move64(); + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - // response_avg[ch] += response[block][ch]; - temp = temp + response_fx[block][ch]; + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); } - // response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); + move32(); } /*normalize 1st order*/ - // norm = 0.0f; norm_fx = 0; + move32(); norm_q = 0; - for ( ch = 1; ch < foa_ch; ch++ ) + move16(); + FOR( ch = 1; ch < foa_ch; ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 30 + 30 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q <= 0 ) { - norm_fx = L_shr( norm_fx, ( -1 * norm_q ) ); + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = 1; ch < foa_ch; ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = 1; ch < foa_ch; ch++ ) { - // response_avg[ch] /= norm; - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - if ( response_avg_fx[ch] != 0 ) + IF( response_avg_fx[ch] != 0 ) { response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); + move32(); } response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + move32(); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } /*normalize 2nd order*/ - // norm = 0.0f; norm_fx = 0; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + move32(); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 29 + 29 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, -1 * norm_q ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { response_avg_fx[ch] = response_avg_fx[ch]; response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); } - // response_avg[ch] = (float)response_avg_fx[ch] / (1 << 30); } /*normalize 3rd order*/ - // norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 29 + 29 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, -1 * norm_q ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - // response_avg[ch] /= norm; - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { response_avg_fx[ch] = response_avg_fx[ch]; response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + move32(); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } } } - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) + FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) { - // response_avg[i] = response_avg[HOA_keep_ind[i]]; response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; + move32(); } - // en_ratio_fac = ( 1.0f - diffuseness[band] ); - en_ratio_fac_fx = ( ONE_IN_Q31 - L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 - for ( i = 0; i < num_ch; i++ ) + en_ratio_fac_fx = L_sub( ONE_IN_Q31, L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 + + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { - if ( i == 0 ) + IF( i == 0 ) { - // cov_real_dirac[i][i][band] = 1.0f; cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; + move32(); } - else + ELSE { Word32 en_ratio_fac_sq = 0; - // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; + move32(); cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); + move32(); - if ( hSpar_md_cfg->nchan_transport <= 2 ) + IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) { - - // cov_real_dirac[i][j][band] *= en_ratio_fac; cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); - if ( ( i >= ndm ) && ( dtx_vad == 1 ) ) + move32(); + test(); + IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[sub( i, ndm )] ) ); + move32(); } - else + ELSE { - if ( i < foa_ch ) + IF( LT_16( i, foa_ch ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } - else if ( i < hoa2_ch ) + ELSE IF( LT_16( i, hoa2_ch ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } - else + ELSE { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } } } - else + ELSE { - if ( i < foa_ch ) + IF( LT_16( i, foa_ch ) ) { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ) ); + move32(); } - else if ( i < hoa2_ch ) + ELSE IF( LT_16( i, hoa2_ch ) ) { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ) ); + move32(); } - else + ELSE { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ) ); + move32(); } } } } - else + ELSE { - // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; cov_real_dirac_fx[i][j][band] = L_shl_sat( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + move32(); } } } } - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - // pCov_real[i][j] = cov_real_dirac[i][j]; pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; + move32(); } } - /*static int frame_counter; - frame_counter++; - if (frame_counter > 500) - { - frame_counter = frame_counter; - }*/ - - active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); - - // #ifdef IVAS_FLOAT_FIXED + test(); + active_w = ( EQ_16( dyn_active_w_flag, 1 ) ) || ( EQ_16( hSpar_md_cfg->active_w, 1 ) ); ivas_compute_spar_params_fx( pCov_real_fx, Q30, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); - // #else - // for (int i = 0; i < num_ch; i++) - // { - // for (int j = 0; j < num_ch; j++) - // { - // for (int k = start_band; k < end_band; k++) - // { - // cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); - // } - // } - // } - - // ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); - // - //#endif // IVAS_FLOAT_FIXED - - if ( mixer_mat_fx != NULL ) + IF( mixer_mat_fx != NULL ) { - for ( band = start_band; band < end_band; band++ ) + FOR( band = start_band; band < end_band; band++ ) { ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); - for ( i = 0; i < ndm; i++ ) + FOR( i = 0; i < ndm; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat_fx[i][j][band]; + mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = ppMixer_mat_fx[i][j][band]; + move32(); } } - for ( i = ndm; i < num_ch; i++ ) + FOR( i = ndm; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0; + mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = 0; + move32(); } } - if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) + test(); + IF( ( EQ_16( ndm, 1 ) ) && ( Wscale_d != NULL ) ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] = Mpy_32_32( mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS], Wscale_d[band] ); + mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mpy_32_32( mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], Wscale_d[band] ); + move32(); } } } @@ -6084,147 +6309,140 @@ void ivas_dirac_dec_get_response_fx( const Word16 ambisonics_order, Word16 Q_out ) { - // float response[MAX_OUTPUT_CHANNELS]; - int16_t index_azimuth, index_elevation; - int16_t el, e, az; - // float cos_1, cos_2, sin_1, cos_az[3]; + Word16 index_azimuth, index_elevation; + Word16 el, e, az; Word32 cos_1_fx, cos_2_fx, sin_1_fx, cos_az_fx[3]; - // float sin_az[3]; Word32 sin_az_fx[3]; - // float f, c; Word32 f_fx; Word32 c_fx_better; - int16_t l, m; - int16_t b, b1, b_2, b1_2, a; + Word16 l, m; + Word16 b, b1, b_2, b1_2, a; - index_azimuth = ( azimuth + 180 ) % 360; - index_elevation = elevation + 90; - e = index_elevation > 90 ? -1 : 1; - el = index_elevation > 90 ? 180 - index_elevation : index_elevation; - az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - // f = index_azimuth > 180 ? -1.0f : 1.0f; - f_fx = index_azimuth > 180 ? -1 : 1; - // cos_1 = dirac_gains_trg_term[az][0]; + index_azimuth = add( azimuth, 180 ) % 360; + move16(); + index_elevation = add( elevation, 90 ); + IF( GT_16( index_elevation, 90 ) ) + { + e = -1; + move16(); + } + ELSE + { + e = 1; + move16(); + } + + IF( GT_16( index_elevation, 90 ) ) + { + el = sub( 180, index_elevation ); + move16(); + } + ELSE + { + el = index_elevation; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + az = sub( 360, index_azimuth ); + move16(); + } + ELSE + { + az = index_azimuth; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + f_fx = -1; + move16(); + } + ELSE + { + f_fx = 1; + move16(); + } cos_1_fx = dirac_gains_trg_term_fx[az][0]; - // cos_2 = cos_1 * cos_1; + move32(); cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - // sin_1 = f * dirac_gains_trg_term[az][1]; sin_1_fx = dirac_gains_trg_term_fx[az][1]; - if ( f_fx == -1 ) + move32(); + + if ( EQ_32( f_fx, -1 ) ) { sin_1_fx = L_negate( sin_1_fx ); + move32(); } - // cos_az[0] = cos_1; cos_az_fx[0] = cos_1_fx; - // cos_az[1] = 2.0f * cos_2 - 1.0f; - cos_az_fx[1] = L_shl_sat( ( cos_2_fx - ONE_IN_Q30 ), 1 ); - // cos_az[2] = 2.0f * cos_1 * cos_az[1] - cos_az[0]; - cos_az_fx[2] = L_shl_sat( ( Mpy_32_32( cos_1_fx, cos_az_fx[1] ) - L_shr( cos_az_fx[0], 1 ) ), 1 ); - // sin_az[0] = sin_1; + move32(); + cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 ), 1 ); + move32(); + cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) ), 1 ); + move32(); sin_az_fx[0] = sin_1_fx; - // sin_az[1] = sin_1 * 2.0f * cos_1; + move32(); sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); - // sin_az[2] = sin_1 * ( 4.0f * cos_2 - 1.0f ); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, ( cos_2_fx - ONE_IN_Q29 ) ), 2 ); + move32(); + sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 ) ), 2 ); + move32(); - // response[0] = 1.0f; response_fx[0] = L_shl_sat( 1, Q_out ); - /* Un-optimized code - for reference */ - /* for( l = 1; l<= ambisonics_order; l++ ) */ - /* { */ - /* int16_t b, b1, a; */ - /* float c; */ - /* for( m = 0; m < l; m++ ) */ - /* { */ - /* b = l*l+m; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - - /* if( m%2 == 1 ) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c * sin_az[l-m-1]; */ - - /* b1 = l*l+2*l-m; */ - /* response[b1] = c * cos_az[l-m-1]; */ - - /* } */ - - /* b = l*l+l; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - /* if( l%2 == 1) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c; */ - /* } */ + move32(); - for ( l = 1; l <= ambisonics_order; l++ ) + FOR( l = 1; l <= ambisonics_order; l++ ) { - b_2 = l * l; - b1_2 = l * l + 2 * l; - for ( m = 0; m < l; m += 2 ) + b_2 = imult1616( l, l ); + b1_2 = add( imult1616( l, l ), shl( l, 1 ) ); + FOR( m = 0; m < l; m += 2 ) { - b = b_2 + m; + b = add( b_2, m ); a = dirac_gains_P_idx[b]; - // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + move16(); c_fx_better = local_result_table[el][a]; - // response[b] = c * sin_az[l - m - 1]; - // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + move32(); + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); - b1 = b1_2 - m; - // response[b1] = c * cos_az[l - m - 1]; - // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + b1 = sub( b1_2, m ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); } - for ( m = 1; m < l; m += 2 ) + FOR( m = 1; m < l; m += 2 ) { - b = b_2 + m; + b = add( b_2, m ); a = dirac_gains_P_idx[b]; - // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + move16(); c_fx_better = local_result_table[el][a]; - if ( e == -1 ) + move32(); + if ( EQ_16( e, -1 ) ) { - // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); } - // c = c * e; - - // response[b] = c * sin_az[l - m - 1]; - // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out - b1 = b1_2 - m; - // response[b1] = c * cos_az[l - m - 1]; - // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); + b1 = sub( b1_2, m ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); } - b = b_2 + l; + b = add( b_2, l ); a = dirac_gains_P_idx[b]; - // c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ); + move16(); c_fx_better = local_result_table_2[el][a]; - if ( l % 2 == 1 ) + move32(); + IF( EQ_16( ( l % 2 ), 1 ) ) { - // c = c * e; - if ( e == -1 ) + if ( EQ_16( e, -1 ) ) { - // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); + move32(); } } - - // response[b] = c; - // response_fx[b] = L_shl( c_fx, 2 ); response_fx[b] = L_shl_sat( c_fx_better, sub( Q_out, 30 ) ); // Q_out + move32(); } return; @@ -6248,7 +6466,7 @@ Word16 ivas_get_bits_to_encode( WHILE( val ) { - bits_req++; + bits_req = add( bits_req, 1 ); val = L_shr( val, 1 ); } @@ -6446,39 +6664,45 @@ void ivas_spar_set_bitrate_config_fx( Word16 bands_bw; pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs; + move16(); } pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; + move16(); pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; -#ifdef IVAS_FLOAT_FIXED + move16(); + ivas_spar_get_uniform_quant_strat_fx( pSpar_md_cfg, table_idx ); -#else - ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); -#endif + pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS ); + move16(); /* BLOCK: getEntropyCoderModels */ pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str; + move16(); /* bits per block*/ total_bits = 0; + move16(); max_bits = 0; + move16(); ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; + move32(); sba_order = ivas_spar_br_table_consts[table_idx].sba_order; + move16(); ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code ); Word16 temp; Word16 div1; FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { - /* total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); */ total_bits = add( total_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); - /* max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC ); */ max_bits = add( max_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][1], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } @@ -6486,28 +6710,36 @@ void ivas_spar_set_bitrate_config_fx( div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); pSpar_md_cfg->tgt_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); pSpar_md_cfg->max_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); + move16(); + move16(); md_coding_bits_header = add( SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits ); pSpar_md_cfg->tgt_bits_per_blk = sub( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = sub( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); + move16(); + move16(); IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { bands_bw = 2; + move16(); } ELSE { bands_bw = 1; + move16(); } - /* pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->tgt_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); - /* pSpar_md_cfg->max_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->max_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); + move16(); + move16(); + move16(); + move16(); IF( enc_flag ) { @@ -6515,13 +6747,24 @@ void ivas_spar_set_bitrate_config_fx( IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { quant_strat = QUANT_STRAT_0; + move16(); } ELSE { quant_strat = QUANT_STRAT_2; + move16(); } - num_PR_bits_dirac_bands = ( EQ_16( dirac2spar_md_flag, 1 ) ) ? sub( num_bands, SPAR_DIRAC_SPLIT_START_BAND ) : 0; + IF( EQ_16( dirac2spar_md_flag, 1 ) ) + { + num_PR_bits_dirac_bands = sub( num_bands, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); + } + ELSE + { + num_PR_bits_dirac_bands = 0; + move16(); + } div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); @@ -6529,8 +6772,10 @@ void ivas_spar_set_bitrate_config_fx( n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); n_dec = sub( n_input, n_dmx ); bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; + move16(); num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, bits_PR ); bits_PR = i_mult( bits_PR, sub( n_input, 1 ) ); bits_C = i_mult( ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][1], i_mult( sub( n_dmx, 1 ), n_dec ) ); @@ -6553,6 +6798,7 @@ void ivas_spar_set_bitrate_config_fx( IF( EQ_16( pSpar_md_cfg->nchan_transport, 1 ) ) { agc_bits = AGC_BITS_PER_CH; + move16(); } ELSE { @@ -6562,11 +6808,14 @@ void ivas_spar_set_bitrate_config_fx( ELSE { agc_bits = AGC_SIGNALLING_BITS; + move16(); } + test(); IF( EQ_32( ivas_total_brate, PCA_BRATE ) && EQ_32( sba_order, SBA_FOA_ORDER ) ) { pca_bits = 1; + move16(); IF( pca_flag ) { pca_bits = add( pca_bits, sub( add( IVAS_PCA_QBITS, IVAS_PCA_QBITS ), 1 ) ); @@ -6575,9 +6824,11 @@ void ivas_spar_set_bitrate_config_fx( ELSE { pca_bits = 0; + move16(); } pSpar_md_cfg->max_md_bits_spar = add( add( pSpar_md_cfg->max_bits_per_blk, agc_bits ), pca_bits ); + move16(); } return; @@ -6589,6 +6840,7 @@ void ivas_spar_set_bitrate_config_fx( * Set SPAR bitrate distribution *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -6672,3 +6924,99 @@ void ivas_spar_bitrate_dist( return; } + +#else +void ivas_spar_bitrate_dist_fx( + Word32 core_brates_act[], /* o : bitrates per core-coder */ + const Word16 nAvailBits, /* i : number of available bits */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth /* i : audio bandwidth */ +) +{ + Word16 i, nchan_transport, table_idx, bitlen; + Word16 core_bits_act[FOA_CHANNELS], core_range_bits[FOA_CHANNELS]; + Word16 sum_core_act_bits, residual_bits, overflow_bits; + + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, bwidth, &bitlen, NULL ); + + nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); + + sum_core_act_bits = 0; + move16(); + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 ) ); + move16(); + + sum_core_act_bits = add( sum_core_act_bits, core_bits_act[i] ); + } + + residual_bits = sub( nAvailBits, sum_core_act_bits ); + + /* First compute core-coder bits as per bitrate distribution table and MD bitrate*/ + IF( residual_bits > 0 ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 ) ); + move16(); + core_bits_act[i] = add( core_bits_act[i], min( residual_bits, core_range_bits[i] ) ); + move16(); + residual_bits = sub( residual_bits, core_range_bits[i] ); + + IF( residual_bits <= 0 ) + { + BREAK; + } + } + } + ELSE + { + FOR( i = 0; i < nchan_transport; i++ ) + { + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 ) ); + move16(); + } + + overflow_bits = negate( residual_bits ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[sub( sub( nchan_transport, 1 ), i )] = sub( core_bits_act[sub( sub( nchan_transport, 1 ), i )], min( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ) ); + move16(); + overflow_bits = sub( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ); + + IF( overflow_bits <= 0 ) + { + BREAK; + } + } + + IF( overflow_bits > 0 ) + { + Word16 overflow_bits_ch; + overflow_bits_ch = idiv1616( overflow_bits, nchan_transport ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[i] = sub( core_bits_act[i], overflow_bits_ch ); + move16(); + overflow_bits = sub( overflow_bits, overflow_bits_ch ); + } + + core_bits_act[sub( nchan_transport, 1 )] = sub( core_bits_act[sub( nchan_transport, 1 )], max( 0, overflow_bits ) ); + move16(); + } + } + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_brates_act[i] = L_mult0( core_bits_act[i], FRAMES_PER_SEC ); + move32(); + } + + return; +} +#endif diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 667d21b7f0627d1217a589d654b8edbe5e0fa0fd..78541fd9dcde361cf2c1e00ae763e569a3806aff 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -34,13 +34,11 @@ #include "options.h" #include "math.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include #include "wmc_auto.h" -#include "prot_fx1.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 78227e56bed0d76d2b357ad5e3461a035bd4307c..0b7519f441694e1336280dc1b428773d2a1ba7e8 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -93,10 +93,17 @@ typedef struct int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ float last_true_radius; /* last true Q radius value */ +#ifdef IVAS_FLOAT_FIXED + Word16 last_true_radius_fx; /* last true Q radius value */ +#endif int16_t ism_imp; /* ISM importance flag */ int16_t ism_md_null_flag; int16_t ism_md_lowrate_flag; +#ifdef IVAS_FLOAT_FIXED + Word32 q_azimuth_old_fx; + Word32 q_elevation_old_fx; +#endif float q_azimuth_old; float q_elevation_old; @@ -367,24 +374,28 @@ typedef struct ivas_agc_com_state_t /* Covariance structures */ typedef struct ivas_cov_smooth_state_t { - float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t prior_bank_idx; - float *pSmoothing_factor; - int16_t num_bins; #ifdef IVAS_FLOAT_FIXED Word32 *pPrior_cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; Word16 *q_cov_real_per_band[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#else + float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#endif + int16_t prior_bank_idx; +#ifdef IVAS_FLOAT_FIXED Word32 *pSmoothing_factor_fx; /* Q31 */ +#else + float *pSmoothing_factor; #endif + int16_t num_bins; } ivas_cov_smooth_state_t; typedef struct ivas_cov_smooth_cfg_t { - float max_update_rate; #ifdef IVAS_FLOAT_FIXED Word32 max_update_rate_fx; /* Q31 */ +#else + float max_update_rate; #endif int16_t min_pool_size; int16_t max_bands; @@ -727,12 +738,14 @@ typedef struct ivas_filters_process_state_t Word32 num_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 den_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 state_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word32 state_fx_q_factor[IVAS_FILTER_MAX_STAGES]; -#endif + Word16 num_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 den_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 state_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; +#else float num[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; float den[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; float state[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - +#endif } ivas_filters_process_state_t; diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index 595d8f1db0799b243267ea60382473af8e42745b..b315083d87481a970d5fae9b891647c85fb22fee 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,6 +43,7 @@ #include "ivas_prot_fx.h" #endif +#define INV_FPS 655 // Q15 /*------------------------------------------------------------------------- * stereo_dft_config() * @@ -73,7 +74,7 @@ void stereo_dft_config_fx( move16(); /* ITD, IPD and residual coding is not used in SID/No data */ - IF( EQ_32( brate, FRAME_NO_DATA ) ) + IF( brate == FRAME_NO_DATA ) { *bits_frame_nominal = FRAME_NO_DATA; move16(); @@ -324,15 +325,16 @@ Word16 stereo_dft_band_config_fx( Word16 nbands; /*sanity check*/ - assert( ( EQ_16( band_res, 1 ) || EQ_16( band_res, 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); + assert( ( EQ_16( band_res, 1 ) || ( band_res == 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); band_limits[0] = 1; move16(); nbands = 0; move16(); - WHILE( LT_16( band_limits[nbands++], shr( NFFT, 1 ) ) ) + WHILE( LT_16( band_limits[nbands], shr( NFFT, 1 ) ) ) { - IF( EQ_16( band_res, 0 ) ) + nbands = add( nbands, 1 ); + IF( band_res == 0 ) { assert( 0 && "stereo DFT: band config failed!\n" ); } @@ -367,7 +369,7 @@ Word16 stereo_dft_band_config_fx( assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" ); } } - nbands = sub( nbands, 1 ); + band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ move16(); diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index 1fd3ce5a461e8c189992106a956fc2de5194b03b..c72cc55100ae423916ec2e8dd95634d40fe113fa 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -54,8 +54,11 @@ void ECSQ_init_instance_fx( void *ac_handle ) { ecsq_inst->config_index = config_index; + move16(); ecsq_inst->encoding_active = 1; + move16(); ecsq_inst->bit_count_estimate = 0; + move32(); ecsq_inst->ac_handle = ac_handle; return; @@ -73,6 +76,7 @@ Word32 ECSQ_dequantize_gain_fx( Word32 global_gain; Word32 L_tmp, L_prod; Word16 gg_e, tmp_e = 16; + move16(); /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ @@ -103,6 +107,7 @@ void ECSQ_dequantize_vector_fx( FOR( i = 0; i < N; ++i ) { output[i] = Mpy_32_16_1( global_gain, input[i] ); + move32(); } return; diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 0b3920c8ef7b9727c1a0ffefd9f7665221a8e560..f5f4c423d4ad1522e641dddaa8aa683f3aad3161 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -37,8 +37,7 @@ #include "cnst.h" #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "wmc_auto.h" #include "rom_com.h" @@ -118,6 +117,7 @@ Word32 inv_table_145[N_MAX_SHIFT_CHANGE + 1] = { Word32 tableD1_145[N_MAX_SHIFT_CHANGE + 1] = { 0, 15027, 120219, 405740, 961755, 1878428, 3245924, 5154407, 7694041, 10954993, 15027425, 20001503, 25967392, 33015256, 41235259, 50717555, 61552334, 73829752, 87639951, 103073111, 120219402 }; +#ifdef IVAS_FLOAT_FIXED static void interpTargetChannel_fx( Word32 *target_fx, const Word16 prevShift, @@ -133,11 +133,19 @@ static void interpTargetChannel_fx( Word32 spread_factor2_fx; Word64 tempD1_fx, tempD2_fx; - d = sub( prevShift, currShift ); - signShift = GE_16( d, 0 ) ? ( 1 ) : ( -1 ); - move16(); + d = negate( sub( currShift, prevShift ) ); + IF( d >= 0 ) + { + signShift = 1; + move16(); + } + ELSE + { + signShift = -1; + move16(); + } - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { /* this can happen in DFT->TD switching */ return; @@ -187,21 +195,21 @@ static void interpTargetChannel_fx( ptr1_fx = target_fx; ptr2_fx = tempBuff1_fx + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; - FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ ) + FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < imult1616( ( add( add( N, N_MAX_SHIFT_CHANGE ), 1 ) ), INTERP_FACTOR1 ); i++ ) { - IF( i & 0x1 ) + IF( s_and( i, 0x1 ) ) { ptr2_fx[i] = 0; move32(); /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */ - lim1 = add( shr( ( i - SINC_ORDER1 ), 1 ), 1 ); + lim1 = add( shr( sub( i, SINC_ORDER1 ), 1 ), 1 ); - lim2 = shr( ( i + SINC_ORDER1 ), 1 ); + lim2 = shr( add( i, SINC_ORDER1 ), 1 ); FOR( j = lim1; j <= lim2; j++ ) { - ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); + ptr2_fx[i] = L_add( Mpy_32_32( win_fx[sub( imult1616( j, INTERP_FACTOR1 ), i )], ptr1_fx[j] ), ptr2_fx[i] ); move32(); } } @@ -216,17 +224,35 @@ static void interpTargetChannel_fx( ptr1_fx = ptr2_fx; ptr2_fx = tempBuff2_fx; - tempD1_fx = table_D1_pointer[L_abs( d )]; - move64(); - tempD2_fx = 3 * table_D1_pointer[L_abs( d )]; - move64(); + tempD1_fx = W_deposit32_l( table_D1_pointer[L_abs( d )] ); + tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[L_abs( d )] ); - tempF1_fx = L_sub( d * factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ); - FOR( k = 0; k < N - 1; k++ ) + IF( EQ_16( signShift, 1 ) ) + { + tempF1_fx = ONE_IN_Q12; + move32(); + } + ELSE { - Word32 local = ( ( (Word64) tempF1_fx * spread_factor2_fx ) >> 31 ) - ONE_IN_Q12; - Word32 sign_local = GT_32( local, 0 ) ? 1 : -1; - Word32 local_int = (Word32) W_shr( W_abs( local ), 12 ); + tempF1_fx = -ONE_IN_Q12; + move32(); + } + tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); + FOR( k = 0; k < sub( N, 1 ); k++ ) + { + Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); + Word32 sign_local; + IF( local > 0 ) + { + sign_local = 1; + move32(); + } + ELSE + { + sign_local = -1; + move32(); + } + Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); Word32 res_a1, res_a2, res_a3; Word32 res_b1, res_b2, res_b3; Word32 res_c1, res_c2, res_c3; @@ -235,24 +261,24 @@ static void interpTargetChannel_fx( Word64 res_a, res_b, res_c, res_d; Word64 tempa, tempb; Word64 mult_a_D1, mult_b_D2; - local_int = sign_local * local_int; - local_int_scaled = local_int << 12; - lim1 = (Word16) local_int; - IF( local_int_scaled > local ) + local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); + local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); + lim1 = extract_l( local_int ); + if ( W_sub( local_int_scaled, local ) > 0 ) { - lim1--; + lim1 = sub( lim1, 1 ); } y_fx[0] = ptr1_fx[lim1]; move32(); - y_fx[1] = ptr1_fx[lim1 + 1]; + y_fx[1] = ptr1_fx[add( lim1, 1 )]; move32(); - y_fx[2] = ptr1_fx[lim1 + 2]; + y_fx[2] = ptr1_fx[add( lim1, 2 )]; move32(); - y_fx[3] = ptr1_fx[lim1 + 3]; + y_fx[3] = ptr1_fx[add( lim1, 3 )]; move32(); - x_fx[0] = lim1 * interp_factor2_fx; + x_fx[0] = imult3216( interp_factor2_fx, lim1 ); move32(); x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); move32(); @@ -265,49 +291,60 @@ static void interpTargetChannel_fx( res_a1 = L_sub( tempF1_fx, x_fx[0] ); res_a2 = L_sub( tempF1_fx, x_fx[1] ); res_a3 = L_sub( tempF1_fx, x_fx[2] ); - res_a = ( ( (Word64) res_a1 * res_a2 ) >> 12 ) * res_a3; - res_a = ( y_fx[3] * ( res_a >> 16 ) ); + res_a = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; + res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); res_b1 = L_sub( tempF1_fx, x_fx[1] ); res_b2 = L_sub( tempF1_fx, x_fx[2] ); res_b3 = L_sub( tempF1_fx, x_fx[3] ); - res_b = ( ( (Word64) res_b1 * res_b2 ) >> 12 ) * res_b3; - res_b = ( y_fx[0] * ( res_b >> 16 ) ); + res_b = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; + res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); res_c1 = L_sub( tempF1_fx, x_fx[0] ); res_c2 = L_sub( tempF1_fx, x_fx[2] ); res_c3 = L_sub( tempF1_fx, x_fx[3] ); - res_c = ( ( (Word64) res_c1 * res_c2 ) >> 12 ) * res_c3; - res_c = ( y_fx[1] * ( res_c >> 16 ) ); + res_c = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; + res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); res_d1 = L_sub( tempF1_fx, x_fx[0] ); res_d2 = L_sub( tempF1_fx, x_fx[1] ); res_d3 = L_sub( tempF1_fx, x_fx[3] ); - res_d = ( ( (Word64) res_d1 * res_d2 ) >> 12 ) * res_d3; - res_d = ( y_fx[2] * ( res_d >> 16 ) ); + res_d = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; + res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); tempa = W_sub( res_a, res_b ); tempb = W_sub( res_c, res_d ); - mult_a_D1 = ( tempD1_fx * ( tempa >> 14 ) ) >> 15; - mult_b_D2 = ( tempD2_fx * ( tempb >> 14 ) ) >> 15; - ptr2_fx[k] = (Word32) ( ( mult_a_D1 + mult_b_D2 ) >> 14 ); // 38-14 - tempF1_fx = (Word32) W_add( tempF1_fx, L_sub( factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ) ); + mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); + mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); + ptr2_fx[k] = W_extract_l( ( W_shr( W_add( mult_a_D1, mult_b_D2 ), 14 ) ) ); // 38-14 + move32(); + + IF( EQ_16( signShift, 1 ) ) + { + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); + move32(); + } + ELSE + { + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); + move32(); + } } ptr1_fx = target_fx; - Copy32( ptr2_fx, ptr1_fx, N - 1 ); + Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); return; } - +#endif /*--------------------------------------------------------------- * Function targetCh_AlignStereoDFT() * * Align target channel in DFT stereo to correct FOR shift variations * ---------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED static void targetCh_AlignStereoDFT_fx( Word32 *target_fx, const Word16 prevShift, @@ -321,15 +358,14 @@ static void targetCh_AlignStereoDFT_fx( Word32 fadeOutBuff_fx[L_SHIFT_ADAPT_MAX]; Word32 fadeInBuff_fx[L_SHIFT_ADAPT_MAX]; - d = sub( prevShift, currShift ); + d = negate( sub( currShift, prevShift ) ); Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); - IF( GT_16( L_shift_adapt, 0 ) ) + IF( L_shift_adapt > 0 ) { alpha_fx = 0; - move32(); SWITCH( L_shift_adapt ) { case 596: @@ -368,14 +404,14 @@ static void targetCh_AlignStereoDFT_fx( return; } - +#endif /*--------------------------------------------------------------- * adjustTargetSignal() * * Target signal correction FOR shift variations. * ---------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void adjustTargetSignal_fx( Word32 *target_fx, const Word16 prevShift, @@ -385,7 +421,7 @@ void adjustTargetSignal_fx( { /* inter-frame shift variation and target shifting */ - IF( EQ_16( method, 0 ) ) + IF( method == 0 ) { interpTargetChannel_fx( target_fx, prevShift, currShift, L_shift_adapt ); } @@ -396,3 +432,4 @@ void adjustTargetSignal_fx( return; } +#endif diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index 3c06612c415706e90d39bbe5b3486f20ecd1a42b..1cc5694616fcbb5605fc44fde4d5ca7a8ba253cc 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -40,8 +40,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -85,13 +84,22 @@ void stereo_mdct_init_bands_fx( { tcx_mode = tmp_tcx_mode; move16(); - L_frameTCX = EQ_16( tcx_mode, TCX_20_CORE ) ? L_frame : ( L_frame / 2 ); - move16(); + + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + L_frameTCX = L_frame; + move16(); + } + ELSE + { + L_frameTCX = shr( L_frame, 1 ); + move16(); + } } ELSE { /*transition frame*/ - L_frameTCX = add( L_frame, L_frame / 4 ); + L_frameTCX = add( L_frame, shr( L_frame, 2 ) ); tcx_mode = TCX_20_CORE; move16(); } @@ -101,10 +109,27 @@ void stereo_mdct_init_bands_fx( { sfbParam.steBands = mdctStereoBands_32000_640; - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[0] : sfbParam.steBands->bndCnt_TCX10[0]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[0]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[0]; + move16(); + } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.steBands->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.steBands->bandLengthsTCX10; + move16(); + } } ELSE { @@ -115,15 +140,40 @@ void stereo_mdct_init_bands_fx( SWITCH( L_frame ) { case L_FRAME32k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[1] : sfbParam.steBands->bndCnt_TCX10[1]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[1]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[1]; + move16(); + } BREAK; case L_FRAME25_6k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[2] : sfbParam.steBands->bndCnt_TCX10[2]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[2]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[2]; + move16(); + } BREAK; case L_FRAME16k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[3] : sfbParam.steBands->bndCnt_TCX10[3]; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[3]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[3]; + move16(); + } move16(); BREAK; default: @@ -131,7 +181,16 @@ void stereo_mdct_init_bands_fx( return; } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.steBands->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.steBands->bandLengthsTCX10; + move16(); + } } ELSE { @@ -152,7 +211,16 @@ void stereo_mdct_init_bands_fx( return; } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.lpcBndsParam->bandLengthsTCX20 : sfbParam.lpcBndsParam->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX10; + move16(); + } cnt = 64; move16(); } @@ -182,7 +250,17 @@ void stereo_mdct_init_bands_fx( IF( igf ) { Word16 sfbOldCnt = *sfbCnt; - Word16 igfSfbStep = hIgfGrid->infoIsRefined ? 2 : 1; + Word16 igfSfbStep; + IF( hIgfGrid->infoIsRefined ) + { + igfSfbStep = 2; + move16(); + } + ELSE + { + igfSfbStep = 1; + move16(); + } Word16 k; move16(); move16(); @@ -214,7 +292,7 @@ void stereo_mdct_init_bands_fx( move16(); /* better save than sorry, overwrite anything that is left above */ - FOR( i = *sfbCnt + 1; i < sfbOldCnt + 1; i++ ) + FOR( i = add( *sfbCnt, 1 ); i < add( sfbOldCnt, 1 ); i++ ) { sfbOffset[i] = 0; move16(); @@ -225,9 +303,9 @@ void stereo_mdct_init_bands_fx( IF( LT_16( sfbOffset[*sfbCnt], L_frameTCX ) ) { Word16 nMissingBins = sub( L_frameTCX, sfbOffset[*sfbCnt] ); - if ( LT_16( sfbWidths[i] / 2, nMissingBins ) ) + if ( LT_16( shr( sfbWidths[i], 1 ), nMissingBins ) ) { - ( *sfbCnt )++; + *sfbCnt = add( *sfbCnt, 1 ); } sfbOffset[*sfbCnt] = L_frameTCX; move16(); diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c index 28e22b28c46911ae3bf26a510969af724673cac1..f28c69b2242ed7775b9755bac96c22786618f093 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com.c +++ b/lib_com/ivas_stereo_mdct_stereo_com.c @@ -37,8 +37,7 @@ #include "wmc_auto.h" #include #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -57,10 +56,10 @@ void splitAvailableBits_fx( Word16 *bits_ch1 /* o : bits for channel 1 */ ) { - assert( split_ratio >= 1 && split_ratio < SMDCT_BITRATE_RATIO_RANGE ); + assert( split_ratio >= 1 && LT_16( split_ratio, SMDCT_BITRATE_RATIO_RANGE ) ); /* *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE; */ - *bits_ch0 = extract_l( L_mult0( split_ratio, total_bits ) / SMDCT_BITRATE_RATIO_RANGE ); + *bits_ch0 = extract_l( L_shr( L_mult0( split_ratio, total_bits ), 3 ) ); move16(); /* for SBA mode bias the distribution towards the W channel */ test(); diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index fce1f62abed1c0b1cf0cb288280008536a229267..33b6c20db4642e0d100593d2348d2a7788e9674e 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -84,6 +84,8 @@ ivas_error PsychoacousticParameters_Init( pPsychParams->nBins = nBins; pPsychParams->nBands = nBands; + move16(); + move16(); IF( !isWarped ) { @@ -164,14 +166,22 @@ void SetCurrentPsychParams( const Word16 last_frame_was_concealed_cng, TCX_CONFIG_HANDLE hTcxCfg ) { - IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) && EQ_16( last_frame_was_concealed_cng, 0 ) ) + test(); + IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) && ( last_frame_was_concealed_cng == 0 ) ) { assert( core == TCX_20_CORE ); hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20AfterACELP; } ELSE { - hTcxCfg->psychParamsCurrent = ( EQ_16( core, TCX_10_CORE ) ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20; + IF( EQ_16( core, TCX_10_CORE ) ) + { + hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX10; + } + ELSE + { + hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20; + } } return; diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 7378308270226bd71c91c592d96d582d38aaf56d..ed136930da3b397328c569c864f9a25a93e5c627 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -41,8 +41,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED @@ -439,373 +438,477 @@ void tdm_bit_alloc( #else void tdm_bit_alloc( - const Word16 ivas_format, /* i : IVAS format */ - const Word16 ism_mode, /* i : ISM mode in combined format */ - const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag */ - Word32 *total_brate_pri, /* o : Allocated primary channel bitrate */ - Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate */ - Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/ - const Word16 coder_type, /* i : secondary channel coder type */ - const Word16 ener_ratio_idx, /* i : correlation ratio indexe */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 bwidth_pri, /* i : bandwidth of the primary channel */ - const Word16 bwidth_sec, /* i : bandwidth of the secondary channel */ - const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ - const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ + const Word16 ivas_format, /* i : IVAS format */ + const Word16 ism_mode, /* i : ISM mode in combined format */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag */ + Word32 *total_brate_pri, /* o : Allocated primary channel bitrate */ + Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate */ + Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/ + const Word16 coder_type, /* i : secondary channel coder type */ + const Word16 ener_ratio_idx, /* i : correlation ratio indexe */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 bwidth_pri, /* i : bandwidth of the primary channel */ + const Word16 bwidth_sec, /* i : bandwidth of the secondary channel */ + const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ + const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ ) { Word16 idx, four_subfr_fcb, two_subfr_fcb; Word32 bit_rate_diff_fx; - Word16 BWE_brate, tmp_bits; + Word32 BWE_brate; + Word16 tmp_bits; Word16 tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref; - IF( tdm_inst_ratio_idx == TDM_NQ ) + move16(); + if ( EQ_16( tdm_inst_ratio_idx, TDM_NQ ) ) { tdm_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Bit rate almost split half and half*/ + move16(); } /* Decision on using the low rate mode or the normal mode */ /* default is using the low rate mode for the secondary channel coding*/ /* UC and IC are automatically coded with low rate mode */ *tdm_low_rate_mode = 1; + move16(); /* Allocating different bitrate to channels */ idx = 0; - IF( element_brate_wo_meta <= IVAS_13k2 ) + move16(); + IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) ) { idx = 0; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_16k4 ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) { idx = 1; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_24k4 ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) ) { idx = 2; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_32k ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_32k ) ) { idx = 3; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_48k ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_48k ) ) { idx = 4; + move16(); } - IF( coder_type == UNVOICED && tdm_bit_allc_tbl[idx][coder_type] >= 4200 ) + test(); + if ( EQ_16( coder_type, UNVOICED ) && GE_16( tdm_bit_allc_tbl[idx][coder_type], 4200 ) ) { *tdm_low_rate_mode = 0; + move16(); } /* Secondary channel based bitrate allocation */ *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; - + move16(); + + test(); + test(); + test(); + test(); + test(); + test(); /* secondary channel bitrate allocation based on the energy scaling ratio */ - IF( ( ( ivas_format != MASA_ISM_FORMAT || ism_mode == ISM_MODE_NONE ) && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && coder_type > UNVOICED ) ) + IF( ( ( NE_16( ivas_format, MASA_ISM_FORMAT ) || ism_mode == ISM_MODE_NONE ) && ( ( NE_16( coder_type, UNVOICED ) ) || EQ_16( tdm_LRTD_flag, 1 ) ) ) || ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ism_mode != ISM_MODE_NONE && GT_16( coder_type, UNVOICED ) ) ) { - bit_rate_diff_fx = ( element_brate_wo_meta - 2 * *total_brate_sec ); + bit_rate_diff_fx = L_sub( element_brate_wo_meta, L_shl( *total_brate_sec, 1 ) ); - IF( tdm_LRTD_flag == 1 ) /* > element_brate > STEREO_22k or CT0 not used */ + IF( EQ_16( tdm_LRTD_flag, 1 ) ) /* > element_brate > STEREO_22k or CT0 not used */ { /* further adjustment in function of the energy/correlation ratio */ IF( coder_type == INACTIVE ) { Word32 res_fix = 0; - res_fix = Mpy_32_32( 644245095, ( element_brate_wo_meta - 500 ) ); - res_fix = ( ( res_fix / 100 ) * 100 ); + move32(); + res_fix = Mpy_32_32( 644245095, L_sub( element_brate_wo_meta, 500 ) ); + res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 ), 100 ); + if ( res_fix < 0 ) + { + res_fix = L_negate( res_fix ); + } *total_brate_sec = max( *total_brate_sec, res_fix ); + move32(); - //*total_brate_sec = max(*total_brate_sec, (int16_t)(0.3f * (element_brate_wo_meta - 500) / 100) * 100); - tmp_bits = (Word16) ( -abs( tdm_inst_ratio_idx - 16 ) * 200 * idx ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( idx, 200 ) ); } ELSE { Word32 res_fix = 0; - res_fix = Mpy_32_32( 1073741824, ( element_brate_wo_meta - 500 ) ); - res_fix = ( ( res_fix / 100 ) * 100 ); + move32(); + res_fix = Mpy_32_32( 1073741824, L_sub( element_brate_wo_meta, 500 ) ); + res_fix = imult3216( Mpy_32_32( L_abs( res_fix ), 21474837 ), 100 ); + if ( res_fix < 0 ) + { + res_fix = L_negate( res_fix ); + } *total_brate_sec = max( *total_brate_sec, res_fix ); + move32(); - //*total_brate_sec = max(*total_brate_sec, (int16_t)(0.5f * (element_brate_wo_meta - 500) / 100) * 100); - /* tmp_bits = -abs(tdm_inst_ratio_idx-16)*200*idx; */ - tmp_bits = (Word16) ( -abs( tdm_inst_ratio_idx - 16 ) * 100 * idx ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( 100, idx ) ); } /* tmp_bits should be subtract from the secondary channel bitrate */ /* IF the primary channel doesn't correspond to the channel having the highest correlation to the mono- inverse the bitrate compensation */ - IF( ( ener_ratio_idx >= LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx < LRTD_STEREO_MID_IS_PRIM ) || ( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx >= LRTD_STEREO_MID_IS_PRIM ) ) + test(); + test(); + test(); + if ( ( GE_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && LT_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) || ( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && GE_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) ) { - tmp_bits *= -1; + tmp_bits = negate( tmp_bits ); } bit_rate_diff_fx = tmp_bits; + move16(); } - ELSE{ - IF( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM ){ - - bit_rate_diff_fx = ( LRTD_STEREO_MID_IS_PRIM - ener_ratio_idx ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } - ELSE - { - bit_rate_diff_fx = ( ener_ratio_idx - LRTD_STEREO_MID_IS_PRIM ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } -} -/*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ -*total_brate_sec += ( (Word16) ( bit_rate_diff_fx / 100 ) * 100 ); -*total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); + ELSE + { + IF( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) + { -IF( coder_type == INACTIVE && tdm_LRTD_flag == 0 ) -{ - *total_brate_sec = min( *total_brate_sec, MIN_BRATE_SWB_BWE ); -} + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( LRTD_STEREO_MID_IS_PRIM, ener_ratio_idx ) ); + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + if ( bit_rate_diff_fx < 0 ) + { + bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); + } + } + ELSE + { + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ); + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + if ( bit_rate_diff_fx < 0 ) + { + bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); + } + } + } + /*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ + Word32 temp = imult3216( Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 328 ), 100 ); + if ( bit_rate_diff_fx < 0 ) + { + temp = L_negate( temp ); + } + *total_brate_sec = L_add( *total_brate_sec, temp ); + move32(); -IF( ( ener_ratio_idx <= 1 || ener_ratio_idx >= 29 ) && coder_type >= UNVOICED ) -{ - Word16 delta_brate = 0; + *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); + move32(); - IF( bwidth_pri > WB ) - { - delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */ - IF( element_brate_wo_meta <= IVAS_16k4 ) + test(); + IF( ( coder_type == INACTIVE ) && tdm_LRTD_flag == 0 ) { - delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */ + *total_brate_sec = min( *total_brate_sec, MIN_BRATE_SWB_BWE ); + move32(); } - } - IF( element_brate_wo_meta <= IVAS_13k2 ) - { - *total_brate_sec = max( *total_brate_sec, 5600 + delta_brate ); /* ~42-47 % of the total bitrate */ - } - ELSE IF( element_brate_wo_meta <= IVAS_16k4 ) - { - *total_brate_sec = max( *total_brate_sec, 6500 + delta_brate ); /* ~40-43 % of the total bitrate */ - } - ELSE IF( element_brate_wo_meta <= IVAS_24k4 ) - { - *total_brate_sec = max( *total_brate_sec, 9000 + delta_brate ); /* ~37-39 % of the total bitrate */ - } - ELSE - { - *total_brate_sec = max( *total_brate_sec, 9600 + delta_brate ); /* ~30-32% of the total bitrate */ - } -} -ELSE -{ - *total_brate_sec = min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); -} + test(); + test(); + IF( ( LE_16( ener_ratio_idx, 1 ) || GE_16( ener_ratio_idx, 29 ) ) && GE_16( coder_type, UNVOICED ) ) + { + Word16 delta_brate = 0; + move16(); -*total_brate_sec = min( *total_brate_sec, 18000 ); -} -ELSE IF( coder_type == UNVOICED ) -{ - IF( tdm_lp_reuse_flag == 0 ) - { - *total_brate_sec += ( 31 + 5 ) * FRAMES_PER_SEC; - } -} + IF( GT_16( bwidth_pri, WB ) ) + { + delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */ + move16(); + if ( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) + { + delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */ + move16(); + } + } -IF( coder_type <= UNVOICED ) -{ - *total_brate_sec = min( *total_brate_sec, MAX_TDM_UC_BRATE ); + IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 5600, delta_brate ) ); /* ~42-47 % of the total bitrate */ + move32(); + } + ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 6500, delta_brate ) ); /* ~40-43 % of the total bitrate */ + move32(); + } + ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 9000, delta_brate ) ); /* ~37-39 % of the total bitrate */ + move32(); + } + ELSE + { + *total_brate_sec = max( *total_brate_sec, add( 9600, delta_brate ) ); /* ~30-32% of the total bitrate */ + move32(); + } + } + ELSE + { + *total_brate_sec = min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); + move32(); + } - IF( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE && tdm_lp_reuse_flag == 0 ) - { - *tdm_low_rate_mode = 0; - } - ELSE IF( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE_LP_R ) - { - *tdm_low_rate_mode = 0; + *total_brate_sec = min( *total_brate_sec, 18000 ); + move32(); } - ELSE IF( ( tdm_lp_reuse_flag == 0 && *total_brate_sec < TDM_UC_NORMAL_MODE_MINBR_LP_R && coder_type == UNVOICED ) || ( tdm_lp_reuse_flag == 0 && *total_brate_sec < ( tdm_bit_allc_tbl[idx][0] + MID_LP_BRATE ) ) ) + ELSE IF( coder_type == UNVOICED ) { - *total_brate_sec += MID_LP_BRATE; + IF( tdm_lp_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, imult3216( FRAMES_PER_SEC, 36 ) ); + move32(); + } } -} -/* verify that primary channel bitrate is higher than the minimum supported bitrate */ -IF( flag_ACELP16k_pri ) -{ - BWE_brate = SWB_TBE_1k75; - IF( element_brate_wo_meta < IVAS_24k4 ) + IF( coder_type <= UNVOICED ) { - BWE_brate = SWB_TBE_1k10; + *total_brate_sec = min( *total_brate_sec, MAX_TDM_UC_BRATE ); + move32(); + + test(); + test(); + test(); + test(); + test(); + IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE ) && tdm_lp_reuse_flag == 0 ) + { + *tdm_low_rate_mode = 0; + move16(); + } + ELSE IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE_LP_R ) ) + { + *tdm_low_rate_mode = 0; + move16(); + } + ELSE IF( ( tdm_lp_reuse_flag == 0 && LT_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MINBR_LP_R ) && EQ_16( coder_type, UNVOICED ) ) || ( tdm_lp_reuse_flag == 0 && LE_32( *total_brate_sec, L_deposit_l( add( tdm_bit_allc_tbl[idx][0], MID_LP_BRATE ) ) ) ) ) + { + *total_brate_sec = L_add( *total_brate_sec, MID_LP_BRATE ); + move32(); + } } - IF( bwidth_pri > WB && tdm_LRTD_flag == 0 ) - { - BWE_brate += ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC; - } - IF( bwidth_pri > SWB && tdm_LRTD_flag == 1 ) + /* verify that primary channel bitrate is higher than the minimum supported bitrate */ + IF( flag_ACELP16k_pri ) { - BWE_brate += 300; - } + BWE_brate = SWB_TBE_1k75; + move32(); - IF( bwidth_pri == FB ) - { - BWE_brate += ( FB_TBE_1k8 - SWB_TBE_1k75 ); - } + test(); + test(); + if ( LT_32( element_brate_wo_meta, IVAS_24k4 ) ) + { + BWE_brate = SWB_TBE_1k10; + move32(); + } - IF( element_brate_wo_meta - *total_brate_sec - BWE_brate < 14000 ) - { - *total_brate_sec = element_brate_wo_meta - 14000 - BWE_brate; - } -} -ELSE -{ - BWE_brate = SWB_TBE_1k75; - IF( bwidth_pri == WB ) - { - BWE_brate = WB_BWE_0k35; - IF( tdm_LRTD_flag == 0 ) + test(); + if ( GT_16( bwidth_pri, WB ) && tdm_LRTD_flag == 0 ) { - BWE_brate += 250; /* ICA Brate */ + BWE_brate = L_add( BWE_brate, ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC ); + } + test(); + if ( GT_16( bwidth_pri, SWB ) && EQ_16( tdm_LRTD_flag, 1 ) ) + { + BWE_brate = L_add( BWE_brate, 300 ); } - } - ELSE IF( tdm_LRTD_flag == 0 ) - { - BWE_brate += 350; /* ICA Brate */ - } -} -IF( coder_type0 == TRANSITION ) -{ - IF( element_brate_wo_meta > IVAS_13k2 ) - { - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_8k00 + BWE_brate ) ); + if ( EQ_16( bwidth_pri, FB ) ) + { + BWE_brate = L_add( BWE_brate, ( FB_TBE_1k8 - SWB_TBE_1k75 ) ); + } + + IF( LT_32( ( L_sub( ( L_sub( element_brate_wo_meta, *total_brate_sec ) ), BWE_brate ) ), 14000 ) ) + { + *total_brate_sec = L_sub( element_brate_wo_meta, L_add( 14000, BWE_brate ) ); + move32(); + } } ELSE { - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_7k20 + BWE_brate ) ); - } -} -ELSE -{ - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( 5900 + BWE_brate ) ); -} - -IF( coder_type == INACTIVE ) -{ - *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ -} -ELSE -{ - *total_brate_sec = max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ -} - -/* Secondary channel bitrate adjusment */ -/* First, adjust the bitrate depending of what is transmitted */ -/* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */ -/* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */ -IF( coder_type == GENERIC /* || coder_type == AUDIO*/ ) -{ - /* Adjust the bitrate depending of what is transmitted */ - /* IF LPC are transmitted, ensure enough bits are used */ - IF( tdm_lp_reuse_flag == 0 ) - { - /* Pitch is transmitted as well, further increase the bitrate */ - IF( tdm_Pitch_reuse_flag == 0 ) + BWE_brate = SWB_TBE_1k75; + move32(); + IF( EQ_16( bwidth_pri, WB ) ) { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); - - IF( tdm_LRTD_flag == 1 && bwidth_sec == SWB ) + BWE_brate = WB_BWE_0k35; + move32(); + if ( tdm_LRTD_flag == 0 ) { - /* ensure that there are enough bits to code SWB TBE_1k10 as well */ - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); + BWE_brate = L_add( BWE_brate, 250 ); /* ICA Brate */ } } - ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */ + ELSE IF( tdm_LRTD_flag == 0 ) { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + BWE_brate = L_add( BWE_brate, 350 ); /* ICA Brate */ } } - ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 ) - { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); - } - /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */ - IF( tdm_LRTD_flag == 1 ) + IF( EQ_16( coder_type0, TRANSITION ) ) { - four_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); - two_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); + IF( GT_32( element_brate_wo_meta, IVAS_13k2 ) ) + { + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_8k00, BWE_brate ) ) ); + move32(); + } + ELSE + { + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_7k20, BWE_brate ) ) ); + move32(); + } } ELSE { - four_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); - two_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( 5900, BWE_brate ) ) ); + move32(); } - IF( tdm_lp_reuse_flag == 0 ) + IF( coder_type == INACTIVE ) { - four_subfr_fcb -= MIN_SEC_LPC_RATE; - two_subfr_fcb -= MIN_SEC_LPC_RATE; + *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + move32(); } - - IF( tdm_Pitch_reuse_flag == 0 ) + ELSE { - four_subfr_fcb -= ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ); - two_subfr_fcb -= MIN_SEC_ACB_RATE; + *total_brate_sec = max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + move32(); } - /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */ - IF( two_subfr_fcb > 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC && four_subfr_fcb < MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC ) + /* Secondary channel bitrate adjusment */ + /* First, adjust the bitrate depending of what is transmitted */ + /* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */ + /* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */ + IF( EQ_16( coder_type, GENERIC ) /* || coder_type == AUDIO*/ ) { - IF( tdm_LRTD_flag == 1 ) + /* Adjust the bitrate depending of what is transmitted */ + /* IF LPC are transmitted, ensure enough bits are used */ + IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + /* Pitch is transmitted as well, further increase the bitrate */ + IF( tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + move32(); + + test(); + IF( EQ_16( tdm_LRTD_flag, 1 ) && EQ_16( bwidth_sec, SWB ) ) + { + /* ensure that there are enough bits to code SWB TBE_1k10 as well */ + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); + move32(); + } + } + ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */ + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + move32(); + } + } + ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); + move32(); + } + + /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */ + IF( EQ_16( tdm_LRTD_flag, 1 ) ) + { + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); } ELSE { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); } IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec += MIN_SEC_LPC_RATE; + four_subfr_fcb = sub( four_subfr_fcb, MIN_SEC_LPC_RATE ); + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_LPC_RATE ); } IF( tdm_Pitch_reuse_flag == 0 ) { - *total_brate_sec += MIN_SEC_ACB_RATE; + four_subfr_fcb = sub( four_subfr_fcb, ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ) ); + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_ACB_RATE ); } - } - ELSE IF( four_subfr_fcb >= ( 40 ) * FRAMES_PER_SEC ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB */ - { - *tdm_low_rate_mode = 0; /* Use normal rate mode */ - } - ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */ - { - Word16 tmp_rate, i; - tmp_rate = two_subfr_fcb; - idx = NB_RATE_POSS - 2; - for ( i = 0; i < NB_RATE_POSS; i++ ) + /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */ + test(); + IF( GT_16( two_subfr_fcb, 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC ) && LT_16( four_subfr_fcb, MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC ) ) { - IF( tmp_rate <= fast_FCB_rates_2sfr[i] ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { - idx = i; - break; + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + move32(); + } + ELSE + { + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + move32(); + } + + IF( tdm_lp_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_LPC_RATE ); + move32(); + } + + IF( tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_ACB_RATE ); + move32(); } } - *total_brate_sec += ( fast_FCB_rates_2sfr[idx] - tmp_rate ); - } - /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ - IF( element_brate_wo_meta - *total_brate_sec == ACELP_13k20 ) - { - *total_brate_sec += 100; + ELSE IF( GE_16( four_subfr_fcb, 40 * FRAMES_PER_SEC ) ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB */ + { + *tdm_low_rate_mode = 0; /* Use normal rate mode */ + move16(); + } + ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */ + { + Word16 tmp_rate, i; + tmp_rate = two_subfr_fcb; + move16(); + idx = sub( NB_RATE_POSS, 2 ); + + FOR( i = 0; i < NB_RATE_POSS; i++ ){ + IF( LE_16( tmp_rate, fast_FCB_rates_2sfr[i] ) ){ + idx = i; + move16(); + BREAK; + } } + *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); + move32(); +} +/* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ +IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) ) +{ + *total_brate_sec = L_add( *total_brate_sec, 100 ); + move32(); +} } /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ -IF( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) +test(); +IF( EQ_32( *total_brate_sec, PPP_NELP_2k80 ) || EQ_32( *total_brate_sec, SID_2k40 ) ) { - *total_brate_sec -= 100; + *total_brate_sec = L_sub( *total_brate_sec, 100 ); + move32(); } -*total_brate_pri = element_brate_wo_meta - *total_brate_sec; +*total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); +move32(); return; } @@ -883,13 +986,13 @@ void td_stereo_param_updt_fx( { Word16 i; /* Copy some primary channel information into the secondary channel structure for later usage */ - IF( tdm_use_IAWB_Ave_lpc == 1 ) + IF( EQ_16( tdm_use_IAWB_Ave_lpc, 1 ) ) { /*not being assert*/ Copy( IAWB_Ave_fx, tdm_lsfQ_PCh_fx, M ); lsf2lsp_fx( tdm_lsfQ_PCh_fx, tdm_lspQ_PCh_fx, M, INT_FS_12k8 ); } - ELSE IF( flag_ACELP16k == 1 ) + ELSE IF( EQ_16( flag_ACELP16k, 1 ) ) { Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); lsp_convert_poly_fx( tdm_lspQ_PCh_fx, L_FRAME, 0 ); @@ -905,6 +1008,7 @@ void td_stereo_param_updt_fx( { Word16 tmp16; Word16 mult_factor = 26214 /*0.8f in Q15*/; + move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values */ @@ -967,6 +1071,7 @@ static void tdm_SCh_LSF_intra_pred_zero_bits_fx( FOR( i = 0; i < M; i++ ) { pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + move16(); } return; @@ -1022,29 +1127,38 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( v_sub_16( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M ); lsf_tmp_ptr1_fx = lsf_tmp_fx; + lsf_SCh_ptr_fx = lsf_SCh_fx; + lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + move16(); *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) ); // Q2.56 + 15 -15 + move16(); lsf_SCh_ptr_fx++; - FOR( i = 1; i < M - 1; i++ ) + FOR( i = 1; i < sub( M, 1 ); i++ ) { lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; // Q2.56 *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + move16(); lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); + move16(); ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); + move16(); lsf_SCh_ptr_fx++; } lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); + move16(); lsf_tmp_ptr1_fx++; prd_ptr_fx++; *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); + move16(); v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); @@ -1115,25 +1229,30 @@ void tdm_SCh_LSF_intra_pred_fx( { Word16 fixed_beta; - IF( element_brate <= IVAS_13k2 ) + IF( LE_32( element_brate, IVAS_13k2 ) ) { fixed_beta = 28508; // 0.87f in Q15 + move16(); } - ELSE IF( element_brate <= IVAS_16k4 ) + ELSE IF( LE_32( element_brate, IVAS_16k4 ) ) { fixed_beta = 30801; // 0.94f in Q15 + move16(); } ELSE IF( element_brate <= IVAS_24k4 ) { fixed_beta = 29818; // 0.91f in Q15 + move16(); } - ELSE IF( element_brate <= IVAS_32k ) + ELSE IF( LE_32( element_brate, IVAS_32k ) ) { fixed_beta = 30146; // 0.92f in Q15 + move16(); } ELSE { fixed_beta = 29818; // 0.91f in Q15 + move16(); } tdm_SCh_LSF_intra_pred_zero_bits_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_fx, fixed_beta ); @@ -1205,11 +1324,13 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( Word16 beta_fx; beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q15 + move16(); /* pulling the LSFs closer to the avergae */ FOR( i = 0; i < M; i++ ) { pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + move16(); } return; @@ -1265,11 +1386,15 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( Word16 A_temp_fx[M]; Word16 B_temp_fx[M]; Word32 WD_fx[2] = { 0 }; + move32(); + move32(); FOR( i = 0; i < M; i++ ) { A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); + move16(); B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); + move16(); } FOR( i = 0; i < M; i++ ) @@ -1281,16 +1406,20 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ); // Q31 WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); + move32(); WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); + move32(); } - IF( WD_fx[0] < WD_fx[1] ) + IF( LT_32( WD_fx[0], WD_fx[1] ) ) { *beta_index = 0; + move16(); } ELSE { *beta_index = 1; + move16(); } tdm_SCh_LSF_intra_pred_one_bit_dec_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_RE_USE_fx, Beta_Q_x_fx, *beta_index ); @@ -1383,7 +1512,7 @@ void tdm_SCh_lsf_reuse_fx( Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; } - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index ); } diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 39de3240eb6a2060a81bb410b755e573ccdcc5f5..7f6c56bbfafb5c5f0942333c8b723a0814059f44 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -35,12 +35,10 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx1.h" #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -182,7 +180,9 @@ UWord32 ivas_syn_output_fx( { Word16 i, n; Word16 synth_loc[MAX_JBM_L_FRAME48k]; + UWord32 tmp; UWord32 noClipping = 0; + move32(); /*-----------------------------------------------------------------* * float to integer conversion with saturation control @@ -190,11 +190,13 @@ UWord32 ivas_syn_output_fx( FOR( n = 0; n < n_channels; n++ ) { - noClipping += mvl2s_r( synth[n], q_synth, synth_loc, output_frame ); + tmp = mvl2s_r( synth[n], q_synth, synth_loc, output_frame ); + noClipping = UL_addNsD( noClipping, tmp ); FOR( i = 0; i < output_frame; i++ ) { - synth_out[i * n_channels + n] = synth_loc[i]; + synth_out[L_add( imult1616( i, n_channels ), n )] = synth_loc[i]; + move16(); } } @@ -253,7 +255,8 @@ void ivas_syn_output_f_fx( { FOR( i = 0; i < output_frame; i++ ) { - synth_out[i * n_channels + n] = synth[n][i]; + synth_out[L_add( imult1616( i, n_channels ), n )] = synth[n][i]; + move16(); } } @@ -289,25 +292,29 @@ void mvr2r_inc_fixed_one( IF( y_fx < x_fx ) { ix = 0; + move16(); iy = 0; + move16(); FOR( i = 0; i < n; i++ ) { y_fx[iy] = x_fx[ix]; + move32(); - ix += x_inc; - iy += y_inc; + ix = add( ix, x_inc ); + iy = add( iy, y_inc ); } } ELSE { - ix = ( n - 1 ) * x_inc; - iy = ( n - 1 ) * y_inc; - FOR( i = n - 1; i >= 0; i-- ) + ix = imult1616( sub( n, 1 ), x_inc ); + iy = imult1616( sub( n, 1 ), y_inc ); + FOR( i = sub( n, 1 ); i >= 0; i-- ) { y_fx[iy] = x_fx[ix]; + move32(); - ix -= x_inc; - iy -= y_inc; + ix = sub( ix, x_inc ); + iy = sub( iy, y_inc ); } } @@ -351,7 +358,7 @@ void mvr2r_inc_fixed( { ix = i_mult( sub( n, 1 ), x_inc ); iy = i_mult( sub( n, 1 ), y_inc ); - FOR( i = n - 1; i >= 0; i-- ) + FOR( i = sub( n, 1 ); i >= 0; i-- ) { y_fx[iy] = x_fx[ix]; move32(); @@ -457,12 +464,16 @@ void v_add_inc_fx( Word16 ix1 = 0; Word16 ix2 = 0; Word16 iy = 0; + move16(); + move16(); + move16(); FOR( i = 0; i < N; i++ ) { y[iy] = L_add( x1[ix1], x2[ix2] ); - ix1 += x_inc; - ix2 += x2_inc; - iy += y_inc; + move32(); + ix1 = add( ix1, x_inc ); + ix2 = add( ix2, x2_inc ); + iy = add( iy, y_inc ); } return; } @@ -493,10 +504,16 @@ void v_mult_inc_fx( Word16 ix2 = 0; Word16 iy = 0; + move16(); + move16(); + move16(); + FOR( i = 0; i < N; i++ ) { y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); + move32(); y_q_fx[iy] = sub( add( x1_q_fx[ix1], x2_q_fx[ix2] ), 31 ); + move16(); ix1 = add( ix1, x1_inc ); ix2 = add( ix2, x2_inc ); @@ -522,9 +539,14 @@ void v_mult_inc_fixed( Word16 ix2 = 0; Word16 iy = 0; + move16(); + move16(); + move16(); + FOR( i = 0; i < N; i++ ) { y_fx[iy] = Mpy_32_32( x1_fx[ix1], x2_fx[ix2] ); + move32(); ix1 = add( ix1, x1_inc ); ix2 = add( ix2, x2_inc ); @@ -556,44 +578,6 @@ void v_mult_inc( int16_t ix2 = 0; int16_t iy = 0; -#ifdef IVAS_FLOAT_FIXED - ///////////////// to be removed //////////////////////////////// - Word32 x1_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - Word32 x2_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - Word32 y_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - Word16 y_q_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - Word16 x1_q_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - Word16 x2_q_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; - FOR( i = 0; i < N; i++ ) - { - x1_q_fx[ix1] = Q_factor_L( x1[ix1] ); - x1_fx[ix1] = (Word32) ( x1[ix1] * ( W_shl( 1, x1_q_fx[ix1] ) ) ); - x2_q_fx[ix2] = Q_factor_L( x2[ix2] ); - x2_fx[ix2] = (Word32) ( x2[ix2] * ( W_shl( 1, x2_q_fx[ix2] ) ) ); - ix1 = add( ix1, x1_inc ); - ix2 = add( ix2, x2_inc ); - iy = add( iy, y_inc ); - } - //////////////////////////////////////////////////////////////////// - - v_mult_inc_fx( x1_fx, x1_q_fx, x1_inc, x2_fx, x2_q_fx, x2_inc, y_fx, y_q_fx, y_inc, N ); - - /////////////////////// to be removed /////////////////////////////// - iy = 0; - FOR( i = 0; i < N; i++ ) - { - IF( LT_16( y_q_fx[iy], 0 ) ) - { - y[iy] = (Float32) y_fx[iy] * ( W_shl( 1, ( -y_q_fx[iy] ) ) ); - } - ELSE - { - y[iy] = (Float32) y_fx[iy] / ( W_shl( 1, y_q_fx[iy] ) ); - } - iy = add( iy, y_inc ); - } - /////////////////////////////////////////////////////////////////////// -#else for ( i = 0; i < N; i++ ) { y[iy] = x1[ix1] * x2[ix2]; @@ -601,7 +585,7 @@ void v_mult_inc( ix2 += x2_inc; iy += y_inc; } -#endif + return; } @@ -624,6 +608,7 @@ void v_addc_fx( FOR( i = 0; i < N; i++ ) { y_fx[i] = L_add( c_fx, x_fx[i] ); + move32(); } return; @@ -647,6 +632,7 @@ void v_addc_fixed( FOR( i = 0; i < N; i++ ) { y[i] = L_add( c, x[i] ); + move32(); } return; @@ -662,32 +648,11 @@ void v_addc( { int16_t i; -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[CLDFB_NO_CHANNELS_MAX]; - Word32 y_fx[CLDFB_NO_CHANNELS_MAX]; - const Word32 c_fx = (Word32) ( c * L_shl( 1, 29 ) ); - - //////////////////////////// to be removed ////////////////////// - FOR( i = 0; i < N; i++ ) - { - x_fx[i] = (Word32) ( x[i] * L_shl( 1, 29 ) ); - } - ///////////////////////////////////////////////////////////////// - - v_addc_fx( (const Word32 *) x_fx, c_fx, y_fx, N ); - - ///////////////////////////// to be removed ////////////////////// - FOR( i = 0; i < N; i++ ) - { - y[i] = (Float32) y_fx[i] / L_shl( 1, 29 ); - } - /////////////////////////////////////////////////////////////////// -#else for ( i = 0; i < N; i++ ) { y[i] = c + x[i]; } -#endif + return; } @@ -717,12 +682,16 @@ void v_min_fx( IF( LT_32( L_shr( x1_fx[i], sub( x1_q_fx[i], x2_q_fx[i] ) ), x2_fx[i] ) ) { y_fx[i] = x1_fx[i]; + move32(); y_q_fx[i] = x1_q_fx[i]; + move16(); } ELSE { y_fx[i] = x2_fx[i]; + move32(); y_q_fx[i] = x2_q_fx[i]; + move16(); } } ELSE @@ -730,12 +699,16 @@ void v_min_fx( IF( LT_32( x1_fx[i], L_shr( x2_fx[i], sub( x2_q_fx[i], x1_q_fx[i] ) ) ) ) { y_fx[i] = x1_fx[i]; + move32(); y_q_fx[i] = x1_q_fx[i]; + move16(); } ELSE { y_fx[i] = x2_fx[i]; + move32(); y_q_fx[i] = x2_q_fx[i]; + move16(); } } } @@ -758,37 +731,11 @@ void v_min( { int16_t i; -#ifdef IVAS_FLOAT_FIXED - //////////////////////// to be removed /////////////////////////////// - Word32 x1_fx[MASA_FREQUENCY_BANDS]; - Word32 x2_fx[MASA_FREQUENCY_BANDS]; - Word32 y_fx[MASA_FREQUENCY_BANDS]; - Word16 x1_q_fx[MASA_FREQUENCY_BANDS]; - Word16 x2_q_fx[MASA_FREQUENCY_BANDS]; - Word16 y_q_fx[MASA_FREQUENCY_BANDS]; - FOR( i = 0; i < N; i++ ) - { - x1_q_fx[i] = Q_factor_L( x1[i] ); - x1_fx[i] = (Word32) ( x1[i] * ( W_shl( 1, x1_q_fx[i] ) ) ); - x2_q_fx[i] = Q_factor_L( x2[i] ); - x2_fx[i] = (Word32) ( x2[i] * ( W_shl( 1, x2_q_fx[i] ) ) ); - } - ///////////////////////////////////////////////////////////////////////// - - v_min_fx( (const Word32 *) x1_fx, x1_q_fx, (const Word32 *) x2_fx, x2_q_fx, y_fx, y_q_fx, N ); - - //////////////////////// to be removed //////////////////////////////// - FOR( i = 0; i < N; i++ ) - { - y[i] = (Float32) y_fx[i] / ( W_shl( 1, y_q_fx[i] ) ); - } - /////////////////////////////////////////////////////////////////////// -#else for ( i = 0; i < N; i++ ) { y[i] = ( x1[i] < x2[i] ) ? x1[i] : x2[i]; } -#endif + return; } @@ -811,6 +758,7 @@ void v_sqrt_fx( FOR( i = 0; i < N; i++ ) { y[i] = Sqrt32( x[i], &exp[i] ); + move32(); } return; @@ -853,11 +801,33 @@ void v_sub_s16_fx( FOR( i = 0; LT_16( i, N ); i++ ) { y[i] = sub( x1[i], x2[i] ); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED + + +#ifdef IVAS_FLOAT_FIXED +void v_sub32_fx( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + + FOR( i = 0; LT_16( i, N ); i++ ) + { + y[i] = L_sub( x1[i], x2[i] ); } return; } #endif // IVAS_FLOAT_FIXED + void v_sub_s( const int16_t x1[], /* i : Input vector 1 */ const int16_t x2[], /* i : Input vector 2 */ @@ -904,7 +874,8 @@ float dot_product_cholesky( pt_x = x; for ( j = 0; j <= i; j++ ) { - tmp_sum += *pt_x++ * *pt_A++; + float mul = *pt_x++ * *pt_A++; + tmp_sum += mul; } suma += tmp_sum * tmp_sum; @@ -912,8 +883,73 @@ float dot_product_cholesky( return suma; } +#ifdef IVAS_FLOAT_FIXED +Word32 dot_product_cholesky_fixed( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N, /* i : vector & matrix size */ + const Word16 exp_x, + const Word16 exp_A, + Word16 *exp_sum ) +{ + Word16 i, j; + Word32 suma, tmp_sum, mul; + const Word32 *pt_x, *pt_A; + Word16 mul_exp, tmp_sum_exp; + mul_exp = add( exp_x, exp_A ); + pt_A = A; + suma = 0; + move32(); + FOR( i = 0; i < N; i++ ) + { + tmp_sum = 0; + move32(); + tmp_sum_exp = 0; + move16(); + pt_x = x; + FOR( j = 0; j <= i; j++ ) + { + mul = Mpy_32_32( *pt_x++, *pt_A++ ); + tmp_sum = BASOP_Util_Add_Mant32Exp( tmp_sum, tmp_sum_exp, mul, mul_exp, &tmp_sum_exp ); // exp_x+exp_A + } + + suma = BASOP_Util_Add_Mant32Exp( suma, *exp_sum, Mpy_32_32( tmp_sum, tmp_sum ), shl( tmp_sum_exp, 1 ), exp_sum ); + } + + return suma; +} +#endif #ifdef IVAS_FLOAT_FIXED +void v_mult_mat_fixed( + Word32 *y, /* o : the product x*A */ + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : matrix A */ + const Word16 Nr, /* i : number of rows */ + const Word16 Nc, /* i : number of columns */ + Word16 guardbits ) +{ + Word16 i, j; + const Word32 *pt_x, *pt_A; + Word32 tmp_y[MAX_V_MULT_MAT]; + Word32 *pt_y; + + pt_y = tmp_y; + pt_A = A; + + FOR( i = 0; i < Nc; i++ ) + { + pt_x = x; + *pt_y = 0; + FOR( j = 0; j < Nr; j++ ) + { + *pt_y = L_add( *pt_y, L_shr( Mpy_32_32( ( *pt_x++ ), ( *pt_A++ ) ), guardbits ) ); + } + pt_y++; + } + + MVR2R_WORD32( tmp_y, y, Nc ); +} Word32 dot_product_cholesky_fx( const Word32 *x, /* i : vector x */ const Word32 *A, /* i : Cholesky matrix A */ @@ -981,7 +1017,9 @@ void v_mult_mat_fx( { pt_x_fx = x_fx; *pt_y_fx = 0; + move32(); y_q_fx[i] = 0; + move32(); FOR( j = 0; j < Nr; j++ ) { temp = Mpy_32_32( *pt_x_fx++, *pt_A_fx++ ); @@ -989,25 +1027,30 @@ void v_mult_mat_fx( IF( EQ_16( j, 0 ) ) { *pt_y_fx = temp; + move32(); y_q_fx[i] = temp_q; + move16(); } ELSE { IF( GT_16( y_q_fx[i], temp_q ) ) { *pt_y_fx = L_add( L_shr( *pt_y_fx, sub( y_q_fx[i], temp_q ) ), temp ); + move32(); y_q_fx[i] = temp_q; + move16(); } ELSE { *pt_y_fx = L_add( *pt_y_fx, L_shr( temp, sub( temp_q, y_q_fx[i] ) ) ); + move32(); } } } pt_y_fx++; } - mvr2r_Word32( tmp_y_fx, y_fx, Nc ); + MVR2R_WORD32( tmp_y_fx, y_fx, Nc ); return; } @@ -1030,55 +1073,6 @@ void v_mult_mat( { int16_t i, j; -#ifdef IVAS_FLOAT_FIXED - //////////////////// to be removed ////////////////////// - Word32 y_fx[NB_MEL_BANDS]; - Word32 x_fx[NB_MEL_BANDS]; - Word32 A_fx[NB_MEL_BANDS * NB_MEL_COEF]; - Word16 y_q_fx[NB_MEL_BANDS]; - Word16 x_q_fx[NB_MEL_BANDS]; - Word16 A_q_fx[NB_MEL_BANDS * NB_MEL_COEF]; - Word32 *pt_x_fx, *pt_A_fx; - const Float32 *pt_x, *pt_A; - Word16 *pt_x_q_fx, *pt_A_q_fx; - - pt_A_fx = A_fx; - pt_A_q_fx = A_q_fx; - pt_A = A; - - FOR( i = 0; i < Nc; i++ ) - { - pt_x = x; - pt_x_fx = x_fx; - pt_x_q_fx = x_q_fx; - FOR( j = 0; j < Nr; j++ ) - { - IF( EQ_16( i, 0 ) ) - { - *pt_x_q_fx = sub( Q_factor_L( *pt_x ), 3 ); - *pt_x_fx++ = (Word32) ( *pt_x++ * ( W_shl( 1, *pt_x_q_fx++ ) ) ); - } - *pt_A_q_fx = sub( Q_factor_L( *pt_A ), 3 ); - *pt_A_fx++ = (Word32) ( *pt_A++ * ( W_shl( 1, *pt_A_q_fx++ ) ) ); - } - } - - v_mult_mat_fx( y_fx, y_q_fx, (const Word32 *) x_fx, x_q_fx, (const Word32 *) A_fx, A_q_fx, Nr, Nc ); - - ////////////////////////////// to be removed //////////////////////// - FOR( i = 0; i < Nc; i++ ) - { - IF( LT_16( y_q_fx[i], 0 ) ) - { - y[i] = (Float32) y_fx[i] * W_shl( 1, -y_q_fx[i] ); - } - ELSE - { - y[i] = (Float32) y_fx[i] / W_shl( 1, y_q_fx[i] ); - } - } - //////////////////////////////////////////////////////////////////// -#else const float *pt_x, *pt_A; float tmp_y[MAX_V_MULT_MAT]; float *pt_y; @@ -1098,7 +1092,7 @@ void v_mult_mat( } mvr2r( tmp_y, y, Nc ); -#endif + return; } @@ -1136,14 +1130,98 @@ float logsumexp( return logf( sum ) + max_exp; } +#ifdef IVAS_FLOAT_FIXED +Word32 logsumexp_fx( + const Word32 x[], /* i : input array x */ + const Word16 x_e, + const Word16 N /* i : number of elements in array x */ +) +{ + Word32 max_exp, temp32_sub; + Word32 sum, temp32, pow_temp; + Word32 log2_e_fx = 1549082005; // Q30 of log2(e); + Word16 log2_e_fx_e = 1; + move16(); + move16(); + Word16 i; + Word16 pow_e, sum_e = 0; + move16(); + max_exp = x[0]; + move32(); + sum = 0; + move32(); + FOR( i = 1; i < N; i++ ) + { + IF( GT_32( x[i], max_exp ) ) + { + max_exp = x[i]; + move32(); + } + } + FOR( i = 0; i < N; i++ ) + { + temp32_sub = L_sub( x[i], max_exp ); + pow_e = 0; + move16(); + temp32 = Mpy_32_32( log2_e_fx, temp32_sub ); + pow_temp = BASOP_util_Pow2( temp32, add( x_e, log2_e_fx_e ), &pow_e ); + sum = BASOP_Util_Add_Mant32Exp( sum, sum_e, pow_temp, pow_e, &sum_e ); + } + temp32 = L_add( BASOP_Util_Log2( sum ), L_shl( sum_e, Q25 ) ); + temp32 = Mpy_32_32( temp32, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ + temp32 = L_add( L_shr( temp32, sub( x_e, 6 ) ), max_exp ); // q = 31-x_e + return temp32; +} +#endif /*---------------------------------------------------------------------* * lin_interp() * * Linearly maps x from source range to the target range *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*! r: mapped output value */ +Word32 lin_interp32_fx( + const Word32 x, /* i : the value to be mapped */ + const Word32 x1, /* i : source range interval: low end */ + const Word32 y1, /* i : source range interval: high end */ + const Word32 x2, /* i : target range interval: low */ + const Word32 y2, /* i : target range interval: high */ + const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ + Word16 *Q_io /*i/o : i/o Q factor of the output*/ +) +{ + Word32 temp32; + Word32 temp_div; + Word16 temp_e = 0; + Word16 exp_out = 0; + move16(); + move16(); + IF( L_sub( x2, x1 ) == 0 ) + { + return y1; + } + ELSE IF( flag_sat ) + { + IF( GE_32( x, L_max( x1, x2 ) ) ) + { + return GT_32( x1, x2 ) ? y1 : y2; + } + ELSE IF( LE_32( x, L_min( x1, x2 ) ) ) + { + return LT_32( x1, x2 ) ? y1 : y2; + } + } + temp32 = Mpy_32_32( L_sub( x, x1 ), L_sub( y2, y1 ) ); // Qin*2 -31 + temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, L_sub( x2, x1 ), &temp_e ) ); // 31-temp_e + 2*Qin -31 - Qin = Qin-temp_e + temp32 = BASOP_Util_Add_Mant32Exp( y1, sub( 31, *Q_io ), temp_div, sub( 31, sub( *Q_io, temp_e ) ), &exp_out ); // Qin-temp_e + *Q_io = sub( 31, exp_out ); + return temp32; +} + +#endif /*! r: mapped output value */ float lin_interp( const float x, /* i : the value to be mapped */ @@ -1380,12 +1458,13 @@ Word16 matrix_product_mant_exp_fx( Word16 out_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 *Zp_fx_e = out_e; Word16 row, col; + Word16 x_idx, y_idx; /* Processing */ test(); test(); test(); - IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 0 ) ) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) && transpY == 0 ) /* We use X transpose */ { IF( NE_16( rowsX, rowsY ) ) { @@ -1401,16 +1480,21 @@ Word16 matrix_product_mant_exp_fx( move16(); FOR( k = 0; k < rowsX; ++k ) { - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + move32(); } Zp_fx++; Zp_fx_e++; } } row = colsY; + move16(); col = colsX; + move16(); } - ELSE IF( EQ_16( transpX, 0 ) && EQ_16( transpY, 1 ) ) /* We use Y transpose */ + ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ { IF( NE_16( colsX, colsY ) ) { @@ -1426,14 +1510,19 @@ Word16 matrix_product_mant_exp_fx( move16(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + move32(); } Zp_fx++; Zp_fx_e++; } } row = rowsY; + move16(); col = rowsX; + move16(); } ELSE IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 1 ) ) /* We use both transpose */ { @@ -1451,7 +1540,10 @@ Word16 matrix_product_mant_exp_fx( move16(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + move32(); } Zp_fx++; @@ -1459,7 +1551,9 @@ Word16 matrix_product_mant_exp_fx( } } row = rowsY; + move16(); col = colsX; + move16(); } ELSE /* Regular case */ { @@ -1478,18 +1572,24 @@ Word16 matrix_product_mant_exp_fx( move16(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp_fx ) = BASOP_Util_Add_Mant32Exp( *Zp_fx, *Zp_fx_e, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ), add( X_fx_e, Y_fx_e ), Zp_fx_e ); + move32(); } Zp_fx++; Zp_fx_e++; } } row = colsY; + move16(); col = rowsX; + move16(); } Zp_fx = Z_fx; Zp_fx_e = out_e; Word16 max_exp = -31; + move16(); FOR( j = 0; j < row; ++j ) { FOR( i = 0; i < col; ++i ) @@ -1500,11 +1600,13 @@ Word16 matrix_product_mant_exp_fx( } Zp_fx_e = out_e; *Z_fx_e = max_exp; + move16(); FOR( j = 0; j < row; ++j ) { FOR( i = 0; i < col; ++i ) { *Zp_fx = L_shr_r( *Zp_fx, sub( *Z_fx_e, *Zp_fx_e ) ); + move32(); Zp_fx++; Zp_fx_e++; } @@ -1526,13 +1628,14 @@ Word16 matrix_product_fx( ) { Word16 i, j, k; + Word16 x_idx, y_idx; Word32 *Zp_fx = Z_fx; /* Processing */ test(); test(); test(); - IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 0 ) ) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) && transpY == 0 ) /* We use X transpose */ { IF( NE_16( rowsX, rowsY ) ) { @@ -1546,13 +1649,16 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < rowsX; ++k ) { - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + move32(); } Zp_fx++; } } } - ELSE IF( EQ_16( transpX, 0 ) && EQ_16( transpY, 1 ) ) /* We use Y transpose */ + ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ { IF( NE_16( colsX, colsY ) ) { @@ -1566,7 +1672,10 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + move32(); } Zp_fx++; } @@ -1586,7 +1695,10 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + move32(); } Zp_fx++; @@ -1608,7 +1720,10 @@ Word16 matrix_product_fx( move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); + move32(); } Zp_fx++; } @@ -1631,6 +1746,7 @@ Word16 matrix_product_q30_fx( ) { Word16 i, j, k; + Word16 x_idx, y_idx; Word32 *Zp_fx = Z_fx; Word64 W_tmp; @@ -1638,7 +1754,7 @@ Word16 matrix_product_q30_fx( test(); test(); test(); - IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 0 ) ) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) && transpY == 0 ) /* We use X transpose */ { IF( NE_16( rowsX, rowsY ) ) { @@ -1654,15 +1770,18 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < rowsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); - W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); // Q56 + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = L_sub( W_round64_L( W_tmp ), 64 ); // adjusting for precision + ( *Zp_fx ) = W_round64_L( W_tmp ); + move32(); Zp_fx++; } } } - ELSE IF( EQ_16( transpX, 0 ) && EQ_16( transpY, 1 ) ) /* We use Y transpose */ + ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ { IF( NE_16( colsX, colsY ) ) { @@ -1678,10 +1797,13 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); - W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); // Q56 + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = L_sub( W_round64_L( W_tmp ), 64 ); // adjusting for precision + ( *Zp_fx ) = W_round64_L( W_tmp ); + move32(); Zp_fx++; } } @@ -1702,11 +1824,14 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); // Q56 } W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = L_sub( W_round64_L( W_tmp ), 64 ); // adjusting for precision + ( *Zp_fx ) = W_round64_L( W_tmp ); + move32(); Zp_fx++; } } @@ -1728,10 +1853,13 @@ Word16 matrix_product_q30_fx( FOR( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); - W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); // Q56 + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + W_tmp = W_add( W_tmp, W_mult0_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); // Q56 } W_tmp = W_shl( W_tmp, 6 ); - ( *Zp_fx ) = L_sub( W_round64_L( W_tmp ), 64 ); // adjusting for precision + ( *Zp_fx ) = W_round64_L( W_tmp ); + move32(); Zp_fx++; } } @@ -1760,12 +1888,13 @@ Word16 matrix_product_mant_exp( Word16 *Zp_e = Z_e; Word32 L_tmp; Word16 tmp_e; + Word16 x_idx, y_idx; /* Processing */ test(); test(); test(); - IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 0 ) ) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) && transpY == 0 ) /* We use X transpose */ { IF( NE_16( rowsX, rowsY ) ) { @@ -1781,11 +1910,14 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < rowsX; ++k ) { + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); //( *Zp ) += X[k + i * rowsX] * Y[k + j * rowsY]; - L_tmp = Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ); - tmp_e = add( X_e[k + i * rowsX], Y_e[k + j * rowsY] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); + move32(); ( *Zp_e ) = tmp_e; move16(); } @@ -1794,7 +1926,7 @@ Word16 matrix_product_mant_exp( } } } - ELSE IF( EQ_16( transpX, 0 ) && EQ_16( transpY, 1 ) ) /* We use Y transpose */ + ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ { IF( NE_16( colsX, colsY ) ) { @@ -1810,9 +1942,11 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); //( *Zp ) += X_fx[i + k * rowsX] * Y_fx[j + k * rowsY]; - L_tmp = Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ); - tmp_e = add( X_e[i + k * rowsX], Y_e[j + k * rowsY] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); ( *Zp_e ) = tmp_e; @@ -1839,11 +1973,14 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { + x_idx = add( k, imult1616( i, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); //( *Zp ) += X_fx[k + i * rowsX] * Y_fx[j + k * rowsY]; - L_tmp = Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ); - tmp_e = add( X_e[k + i * rowsX], Y_e[j + k * rowsY] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); + move32(); ( *Zp_e ) = tmp_e; move16(); } @@ -1870,11 +2007,14 @@ Word16 matrix_product_mant_exp( move16(); FOR( k = 0; k < colsX; ++k ) { + x_idx = add( i, imult1616( k, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); //( *Zp ) += X_fx[i + k * rowsX] * Y_fx[k + j * rowsY]; - L_tmp = Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ); - tmp_e = add( X_e[i + k * rowsX], Y_e[k + j * rowsY] ); + L_tmp = Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); + tmp_e = add( X_e[x_idx], Y_e[y_idx] ); ( *Zp ) = BASOP_Util_Add_Mant32Exp( *Zp, *Zp_e, L_tmp, tmp_e, &tmp_e ); + move32(); ( *Zp_e ) = tmp_e; move16(); } @@ -1959,6 +2099,7 @@ Word16 matrix_diag_product_fx( { Word16 i, j; Word32 *Zp = Z; + Word16 tmp; /* Processing */ IF( EQ_16( transpX, 1 ) ) /* We use X transpose */ @@ -1971,7 +2112,9 @@ Word16 matrix_diag_product_fx( { FOR( i = 0; i < colsX; ++i ) { - *( Zp ) = Mpy_32_32( X[j + i * rowsX], Y[j] ); + tmp = add( j, imult1616( i, rowsX ) ); + *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); + move32(); Zp++; } } @@ -1988,6 +2131,7 @@ Word16 matrix_diag_product_fx( FOR( i = 0; i < rowsX; ++i ) { *( Zp ) = Mpy_32_32( *( X ), Y[j] ); + move32(); Zp++; X++; } @@ -1995,6 +2139,7 @@ Word16 matrix_diag_product_fx( } *Z_e = add( X_e, Y_e ); + move16(); return EXIT_SUCCESS; } @@ -2015,6 +2160,7 @@ Word16 diag_matrix_product_fx( { Word16 i, j; Word32 *Zp = Z; + Word16 tmp; /* Processing */ IF( EQ_16( transpX, 1 ) ) /* We use X transpose */ @@ -2027,7 +2173,9 @@ Word16 diag_matrix_product_fx( { FOR( j = 0; j < entriesY; ++j ) { - *( Zp ) = Mpy_32_32( X[i + j * rowsX], Y[j] ); + tmp = add( i, imult1616( j, rowsX ) ); + *( Zp ) = Mpy_32_32( X[tmp], Y[j] ); + move32(); Zp++; } } @@ -2043,6 +2191,7 @@ Word16 diag_matrix_product_fx( FOR( j = 0; j < entriesY; ++j ) { *( Zp ) = Mpy_32_32( *( X ), Y[j] ); + move32(); Zp++; X++; } @@ -2050,6 +2199,7 @@ Word16 diag_matrix_product_fx( } *Z_e = add( Y_e, X_e ); + move16(); return EXIT_SUCCESS; } @@ -2126,12 +2276,13 @@ Word16 matrix_product_diag_fx( { Word16 j, k; Word32 *Zp = Z; + Word16 y_idx, x_idx; /* Processing */ test(); test(); test(); - IF( EQ_16( transpX, 1 ) && EQ_16( transpY, 0 ) ) /* We use X transpose */ + IF( EQ_16( transpX, 1 ) && transpY == 0 ) /* We use X transpose */ { IF( NE_16( rowsX, rowsY ) ) { @@ -2141,14 +2292,18 @@ Word16 matrix_product_diag_fx( FOR( j = 0; j < colsY; ++j ) { ( *Zp ) = 0; + move32(); FOR( k = 0; k < rowsX; ++k ) { - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[k + j * rowsX], Y[k + j * rowsY] ) ); + x_idx = add( k, imult1616( j, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + move32(); } Zp++; } } - ELSE IF( EQ_16( transpX, 0 ) && EQ_16( transpY, 1 ) ) /* We use Y transpose */ + ELSE IF( transpX == 0 && EQ_16( transpY, 1 ) ) /* We use Y transpose */ { IF( NE_16( colsX, colsY ) ) { @@ -2157,9 +2312,13 @@ Word16 matrix_product_diag_fx( FOR( j = 0; j < rowsY; ++j ) { ( *Zp ) = 0; + move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[j + k * rowsX], Y[j + k * rowsY] ) ); + x_idx = add( j, imult1616( k, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + move32(); } Zp++; } @@ -2175,9 +2334,13 @@ Word16 matrix_product_diag_fx( { ( *Zp ) = 0; + move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[k + j * rowsX], Y[j + k * rowsY] ) ); + x_idx = add( k, imult1616( j, rowsX ) ); + y_idx = add( j, imult1616( k, rowsY ) ); + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + move32(); } Zp++; @@ -2193,15 +2356,20 @@ Word16 matrix_product_diag_fx( FOR( j = 0; j < colsY; ++j ) { ( *Zp ) = 0; + move32(); FOR( k = 0; k < colsX; ++k ) { - ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[j + k * rowsX], Y[k + j * rowsY] ) ); + x_idx = add( j, imult1616( k, rowsX ) ); + y_idx = add( k, imult1616( j, rowsY ) ); + ( *Zp ) = L_add( ( *Zp ), Mpy_32_32( X[x_idx], Y[y_idx] ) ); + move32(); } Zp++; } } *Z_e = add( X_e, Y_e ); + move16(); return EXIT_SUCCESS; } @@ -2317,6 +2485,7 @@ void cmplx_matrix_square_fx( Word16 i, j, k; Word32 *realZp, *imagZp; const Word32 *p_real1, *p_real2, *p_imag1, *p_imag2; + Word16 tmp1, tmp2; /* resulting matrix is hermitean, we only need to calc the upper triangle */ /* we assume transposition needed */ @@ -2326,12 +2495,12 @@ void cmplx_matrix_square_fx( { FOR( j = i; j < nCols; j++ ) { - p_real1 = realX + i * mRows; - p_imag1 = imagX + i * mRows; - p_real2 = realX + j * mRows; - p_imag2 = imagX + j * mRows; - realZp = realZ + ( i + nCols * j ); - imagZp = imagZ + ( i + nCols * j ); + p_real1 = realX + imult1616( i, mRows ); + p_imag1 = imagX + imult1616( i, mRows ); + p_real2 = realX + imult1616( j, mRows ); + p_imag2 = imagX + imult1616( j, mRows ); + realZp = realZ + add( i, imult1616( nCols, j ) ); + imagZp = imagZ + add( i, imult1616( nCols, j ) ); *( realZp ) = 0; move32(); *( imagZp ) = 0; @@ -2340,7 +2509,9 @@ void cmplx_matrix_square_fx( FOR( k = 0; k < mRows; k++ ) { *( imagZp ) = L_add( *( imagZp ), L_sub( Mpy_32_32( *( p_real1 ), *( p_imag2 ) ), Mpy_32_32( *( p_real2 ), *( p_imag1 ) ) ) ); + move32(); *( realZp ) = L_add( *( realZp ), L_add( Mpy_32_32( *( p_real1 ), *( p_real2 ) ), Mpy_32_32( *( p_imag1 ), *( p_imag2 ) ) ) ); + move32(); p_real1++; p_real2++; p_imag1++; @@ -2354,9 +2525,11 @@ void cmplx_matrix_square_fx( { FOR( j = 0; j < i; j++ ) { - realZ[i + nCols * j] = realZ[j + nCols * i]; + tmp1 = add( i, imult1616( nCols, j ) ); + tmp2 = add( j, imult1616( nCols, i ) ); + realZ[tmp1] = realZ[tmp2]; move32(); - imagZ[i + nCols * j] = imagZ[j + nCols * i]; + imagZ[tmp1] = imagZ[tmp2]; move32(); } } @@ -2463,6 +2636,7 @@ void v_multc_acc_32_16( FOR( i = 0; i < N; i++ ) { y[i] = L_add( y[i], Mpy_32_16_1( x[i], c ) ); + move32(); } return; @@ -2479,6 +2653,7 @@ void v_multc_acc_32_32( FOR( i = 0; i < N; i++ ) { y[i] = L_add( y[i], Mpy_32_32( x[i], c ) ); + move32(); } return; @@ -2549,54 +2724,109 @@ void lls_interp_n_fx( { Word16 i; const Word16 n_i_fx[11] = { 0, 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480 }; // Q11 + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + const Word16 one_by_n_fx[11] = { 0, 32767, 16384, 10911, 8192, 6553, 5459, 4681, 4096, 3640, 3276 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + const Word16 sum_i_fx[12] = { 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); // 1.0f/ ( N * sum_ii[N] - sum_i[N] * sum_i[N] ) const Word32 res_table[12] = { 0, 0, 0, 357913952, 107374184, 42949672, 20452226, 10956549, 6391320, 3976821, 2603010, 385 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word32 sum_x_fx, sum_ix_fx, slope_fx, offset_fx; Word16 dot_exp = 0, sum_ix_q = 0; - ; + move16(); + move16(); + Word32 num; - assert( N > 0 && N <= 10 ); + assert( N > 0 && LE_16( N, 10 ) ); sum_x_fx = 0; + move32(); FOR( int idx = 0; idx < N; idx++ ) { - sum_x_fx = (Word32) sum_x_fx + x_fx[idx]; + sum_x_fx = L_add( sum_x_fx, x_fx[idx] ); } sum_ix_fx = dotp_fx( x_fx, n_i_fx, N, &dot_exp ); - sum_ix_q = 30 - ( dot_exp - ( 11 + 15 ) ); + sum_ix_q = sub( 30, sub( dot_exp, ( 11 + 15 ) ) ); - sum_ix_fx = L_shr( sum_ix_fx, sum_ix_q - 15 ); - num = L_sub( ( sum_ix_fx * N ), ( sum_x_fx * sum_i_fx[N] ) ); + sum_ix_fx = L_shr( sum_ix_fx, sub( sum_ix_q, 15 ) ); + num = L_sub( imult3216( sum_ix_fx, N ), imult3216( sum_x_fx, sum_i_fx[N] ) ); slope_fx = Mpy_32_32( num, res_table[N] ); - offset_fx = Mpy_32_16_1( L_sub( sum_x_fx, ( slope_fx * sum_i_fx[N] ) ), one_by_n_fx[N] ); + offset_fx = Mpy_32_16_1( L_sub( sum_x_fx, imult3216( slope_fx, sum_i_fx[N] ) ), one_by_n_fx[N] ); IF( upd ) { FOR( i = 0; i < N; i++ ) { - IF( slope_fx * i > MAX_WORD16 ) + IF( GT_32( imult3216( slope_fx, i ), MAX_WORD16 ) ) { x_fx[i] = MAX_WORD16; + move16(); } ELSE { - x_fx[i] = (Word16) L_add_sat( ( slope_fx * i ), offset_fx ); + x_fx[i] = extract_l( L_add_sat( imult3216( slope_fx, i ), offset_fx ) ); + move16(); } } } IF( a_fx != NULL ) { - *a_fx = (Word16) slope_fx; + *a_fx = extract_l( slope_fx ); + move16(); } IF( b_fx != NULL ) { - *b_fx = (Word16) offset_fx; + *b_fx = extract_l( offset_fx ); + move16(); } return; @@ -2628,6 +2858,7 @@ static Word32 wrap_azi_fixed( const Word32 azi_deg ) { Word32 azi = azi_deg; + move32(); /* Wrap azimuth value */ WHILE( GT_32( azi, ANGLE_180_DEG_Q22 ) ) @@ -2730,12 +2961,16 @@ void panning_wrap_angles_fixed( Word32 azi, ele; azi = azi_deg; + move32(); ele = ele_deg; + move32(); - IF( L_abs( ele ) < ANGLE_90_DEG_Q22 ) + IF( LT_32( L_abs( ele ), ANGLE_90_DEG_Q22 ) ) { *ele_wrapped = ele; + move32(); *azi_wrapped = wrap_azi_fixed( azi ); + move32(); return; } ELSE @@ -2744,36 +2979,40 @@ void panning_wrap_angles_fixed( IF( ( ( ele % ANGLE_90_DEG_Q22 ) == 0 ) && ( ( ele % ANGLE_180_DEG_Q22 ) != 0 ) ) { *azi_wrapped = 0; - WHILE( ele > ANGLE_90_DEG_Q22 ) + move32(); + WHILE( GT_32( ele, ANGLE_90_DEG_Q22 ) ) { - ele -= ANGLE_360_DEG_Q22; + ele = L_sub( ele, ANGLE_360_DEG_Q22 ); } - WHILE( ele < -ANGLE_90_DEG_Q22 ) + WHILE( LT_32( ele, -ANGLE_90_DEG_Q22 ) ) { - ele += ANGLE_360_DEG_Q22; + ele = L_add( ele, ANGLE_360_DEG_Q22 ); } *ele_wrapped = ele; + move32(); } ELSE { /* Wrap elevation and adjust azimuth accordingly */ - WHILE( L_abs( ele ) > ANGLE_90_DEG_Q22 ) + WHILE( GT_32( L_abs( ele ), ANGLE_90_DEG_Q22 ) ) { /* Flip to other hemisphere */ - azi += ANGLE_180_DEG_Q22; + azi = L_add( azi, ANGLE_180_DEG_Q22 ); /* Compensate elevation accordingly */ - IF( ele > ANGLE_90_DEG_Q22 ) + IF( GT_32( ele, ANGLE_90_DEG_Q22 ) ) { - ele = ANGLE_180_DEG_Q22 - ele; + ele = L_sub( ANGLE_180_DEG_Q22, ele ); } - ELSE IF( ele < -ANGLE_90_DEG_Q22 ) + ELSE IF( LT_32( ele, -ANGLE_90_DEG_Q22 ) ) { - ele = -ANGLE_180_DEG_Q22 - ele; + ele = L_sub( -ANGLE_180_DEG_Q22, ele ); } } *azi_wrapped = wrap_azi_fixed( azi ); + move32(); *ele_wrapped = ele; + move32(); } return; @@ -2840,19 +3079,28 @@ void v_sort_ind_fixed( FOR( i = 0; i < len; i++ ) { idx[i] = i; + move16(); } FOR( i = len - 2; i >= 0; i-- ) { tempr = x[i]; + move32(); tempi = idx[i]; - FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + move16(); + test(); + FOR( j = add( i, 1 ); LT_16( j, len ) && GT_32( tempr, x[j] ); j++ ) { + test(); x[j - 1] = x[j]; + move32(); idx[j - 1] = idx[j]; + move16(); } x[j - 1] = tempr; + move32(); idx[j - 1] = tempi; + move16(); } return; @@ -2893,12 +3141,16 @@ Word16 is_IVAS_bitrate_fx( Word16 j; j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ + move16(); + + test(); WHILE( LE_16( j, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[j] ) ) { - j++; + test(); + j = add( j, 1 ); } - IF( j >= SIZE_IVAS_BRATE_TBL ) + IF( GE_16( j, SIZE_IVAS_BRATE_TBL ) ) { return 0; } @@ -2961,9 +3213,9 @@ Word16 is_SIDrate( test(); test(); - IF( EQ_32( ivas_total_brate, SID_1k75 ) || - EQ_32( ivas_total_brate, SID_2k40 ) || - EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( EQ_32( ivas_total_brate, SID_1k75 ) || + EQ_32( ivas_total_brate, SID_2k40 ) || + EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { sid_rate_flag = 1; move16(); @@ -3023,7 +3275,7 @@ Word16 rand_triangular_signed_fx( Word16 tmp1, tmp2; Word16 exp1, exp = 1; move16(); - IF( LE_16( rand_val, 0 ) ) + IF( rand_val <= 0 ) { /* rand_val in [-1, 0] */ /*0.5f * (sqrtf(rand_val + 1.0f) - 1)*/ @@ -3056,7 +3308,6 @@ Word16 rand_triangular_signed_fx( * * calculates ceil(log2(val)) *-------------------------------------------------------------------*/ - Word16 ceil_log_2( UWord64 val ) { @@ -3065,70 +3316,263 @@ Word16 ceil_log_2( { assert( 0 ); } - return val <= 1 ? 0 : val <= 2 ? 1 - : val <= 4 ? 2 - : val <= 8 ? 3 - : val <= 16 ? 4 - : val <= 32 ? 5 - : val <= 64 ? 6 - : val <= 128 ? 7 - : val <= 256 ? 8 - : val <= 512 ? 9 - : val <= 1024 ? 10 - : val <= 2048 ? 11 - : val <= 4096 ? 12 - : val <= 8192 ? 13 - : val <= 16384 ? 14 - : val <= 32768 ? 15 - : val <= 65536 ? 16 - : val <= 131072 ? 17 - : val <= 262144 ? 18 - : val <= 524288 ? 19 - : val <= 1048576 ? 20 - : val <= 2097152 ? 21 - : val <= 4194304 ? 22 - : val <= 8388608 ? 23 - : val <= 16777216 ? 24 - : val <= 33554432 ? 25 - : val <= 67108864 ? 26 - : val <= 134217728 ? 27 - : val <= 268435456 ? 28 - : val <= 536870912 ? 29 - : val <= 1073741824 ? 30 - : val <= 2147483648 ? 31 - : val <= 4294967296 ? 32 - : val <= 8589934592 ? 33 - : val <= 17179869184 ? 34 - : val <= 34359738368 ? 35 - : val <= 68719476736 ? 36 - : val <= 137438953472 ? 37 - : val <= 274877906944 ? 38 - : val <= 549755813888 ? 39 - : val <= 1099511627776 ? 40 - : val <= 2199023255552 ? 41 - : val <= 4398046511104 ? 42 - : val <= 8796093022208 ? 43 - : val <= 17592186044416 ? 44 - : val <= 35184372088832 ? 45 - : val <= 70368744177664 ? 46 - : val <= 140737488355328 ? 47 - : val <= 281474976710656 ? 48 - : val <= 562949953421312 ? 49 - : val <= 1125899906842624 ? 50 - : val <= 2251799813685248 ? 51 - : val <= 4503599627370496 ? 52 - : val <= 9007199254740992 ? 53 - : val <= 18014398509481984 ? 54 - : val <= 36028797018963968 ? 55 - : val <= 72057594037927936 ? 56 - : val <= 144115188075855872 ? 57 - : val <= 288230376151711744 ? 58 - : val <= 576460752303423488 ? 59 - : val <= 1152921504606846976 ? 60 - : val <= 2305843009213693952 ? 61 - : val <= 4611686018427387904 ? 62 - : val <= 9223372036854775807 ? 63 - : 64; + ELSE IF( LE_64( val, 1 ) ) + { + return 0; + } + ELSE IF( LE_64( val, 2 ) ) + { + return 1; + } + ELSE IF( LE_64( val, 4 ) ) + { + return 2; + } + ELSE IF( LE_64( val, 8 ) ) + { + return 3; + } + ELSE IF( LE_64( val, 16 ) ) + { + return 4; + } + ELSE IF( LE_64( val, 32 ) ) + { + return 5; + } + ELSE IF( LE_64( val, 64 ) ) + { + return 6; + } + ELSE IF( LE_64( val, 128 ) ) + { + return 7; + } + ELSE IF( LE_64( val, 256 ) ) + { + return 8; + } + ELSE IF( LE_64( val, 512 ) ) + { + return 9; + } + ELSE IF( LE_64( val, 1024 ) ) + { + return 10; + } + ELSE IF( LE_64( val, 2048 ) ) + { + return 11; + } + ELSE IF( LE_64( val, 4096 ) ) + { + return 12; + } + ELSE IF( LE_64( val, 8192 ) ) + { + return 13; + } + ELSE IF( LE_64( val, 16384 ) ) + { + return 14; + } + ELSE IF( LE_64( val, 32768 ) ) + { + return 15; + } + ELSE IF( LE_64( val, 65536 ) ) + { + return 16; + } + ELSE IF( LE_64( val, 131072 ) ) + { + return 17; + } + ELSE IF( LE_64( val, 262144 ) ) + { + return 18; + } + ELSE IF( LE_64( val, 524288 ) ) + { + return 19; + } + ELSE IF( LE_64( val, 1048576 ) ) + { + return 20; + } + ELSE IF( LE_64( val, 2097152 ) ) + { + return 21; + } + ELSE IF( LE_64( val, 4194304 ) ) + { + return 22; + } + ELSE IF( LE_64( val, 8388608 ) ) + { + return 23; + } + ELSE IF( LE_64( val, 16777216 ) ) + { + return 24; + } + ELSE IF( LE_64( val, 33554432 ) ) + { + return 25; + } + ELSE IF( LE_64( val, 67108864 ) ) + { + return 26; + } + ELSE IF( LE_64( val, 134217728 ) ) + { + return 27; + } + ELSE IF( LE_64( val, 268435456 ) ) + { + return 28; + } + ELSE IF( LE_64( val, 536870912 ) ) + { + return 29; + } + ELSE IF( LE_64( val, 1073741824 ) ) + { + return 30; + } + ELSE IF( LE_64( val, 2147483648 ) ) + { + return 31; + } + ELSE IF( LE_64( val, 4294967296 ) ) + { + return 32; + } + ELSE IF( LE_64( val, 8589934592 ) ) + { + return 33; + } + ELSE IF( LE_64( val, 17179869184 ) ) + { + return 34; + } + ELSE IF( LE_64( val, 34359738368 ) ) + { + return 35; + } + ELSE IF( LE_64( val, 68719476736 ) ) + { + return 36; + } + ELSE IF( LE_64( val, 137438953472 ) ) + { + return 37; + } + ELSE IF( LE_64( val, 274877906944 ) ) + { + return 38; + } + ELSE IF( LE_64( val, 549755813888 ) ) + { + return 39; + } + ELSE IF( LE_64( val, 1099511627776 ) ) + { + return 40; + } + ELSE IF( LE_64( val, 2199023255552 ) ) + { + return 41; + } + ELSE IF( LE_64( val, 4398046511104 ) ) + { + return 42; + } + ELSE IF( LE_64( val, 8796093022208 ) ) + { + return 43; + } + ELSE IF( LE_64( val, 17592186044416 ) ) + { + return 44; + } + ELSE IF( LE_64( val, 35184372088832 ) ) + { + return 45; + } + ELSE IF( LE_64( val, 70368744177664 ) ) + { + return 46; + } + ELSE IF( LE_64( val, 140737488355328 ) ) + { + return 47; + } + ELSE IF( LE_64( val, 281474976710656 ) ) + { + return 48; + } + ELSE IF( LE_64( val, 562949953421312 ) ) + { + return 49; + } + ELSE IF( LE_64( val, 1125899906842624 ) ) + { + return 50; + } + ELSE IF( LE_64( val, 2251799813685248 ) ) + { + return 51; + } + ELSE IF( LE_64( val, 4503599627370496 ) ) + { + return 52; + } + ELSE IF( LE_64( val, 9007199254740992 ) ) + { + return 53; + } + ELSE IF( LE_64( val, 18014398509481984 ) ) + { + return 54; + } + ELSE IF( LE_64( val, 36028797018963968 ) ) + { + return 55; + } + ELSE IF( LE_64( val, 72057594037927936 ) ) + { + return 56; + } + ELSE IF( LE_64( val, 144115188075855872 ) ) + { + return 57; + } + ELSE IF( LE_64( val, 288230376151711744 ) ) + { + return 58; + } + ELSE IF( LE_64( val, 576460752303423488 ) ) + { + return 59; + } + ELSE IF( LE_64( val, 1152921504606846976 ) ) + { + return 60; + } + ELSE IF( LE_64( val, 2305843009213693952 ) ) + { + return 61; + } + ELSE IF( LE_64( val, 4611686018427387904 ) ) + { + return 62; + } + ELSE IF( LE_64( val, 9223372036854775807 ) ) + { + return 63; + } + return 64; } @@ -3141,32 +3585,34 @@ Word16 ceil_log_2( *-------------------------------------------------------------------*/ Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const int16_t len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ + const Word32 *x, /* i : input vector */ + const Word16 len, /* i : length of inputvector */ + Word16 q /* q : q-factor for the array */ ) { Word64 mean, var; mean = 0; + move64(); var = 0; + move64(); FOR( int i = 0; i < len; i++ ) { - mean = mean + x[i]; + mean = W_add( mean, x[i] ); } - mean = mean / len; + mean = mean / len; /* NOTE: No BASOP for 64 bit division */ FOR( int i = 0; i < len; i++ ) { - var = var + Mpy_32_32( L_sub( x[i], (Word32) mean ), L_sub( x[i], (Word32) mean ) ); + var = W_add( var, Mpy_32_32( L_sub( x[i], W_extract_l( mean ) ), L_sub( x[i], W_extract_l( mean ) ) ) ); } - var = var << ( 31 - q ); + var = W_shl( var, sub( 31, q ) ); - var = var / len; + var = var / len; /* NOTE: No BASOP for 64 bit division */ return var; } diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 54539e3838ee7f05bca45d0e718f490cf96f7674..86093edcd64bb4058d253e161f8159eb2e922de3 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -39,7 +39,7 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" +#include "prot_fx.h" #endif #include "ivas_stat_com.h" @@ -134,11 +134,14 @@ static void ivas_transient_det_init( float filt_coeff_arr[3][IVAS_BIQUAD_FILT_LEN << 1]; #else Word32 filt_coeff_arr_fx[3][IVAS_BIQUAD_FILT_LEN << 1]; + const Word16 *filt_coeff_arr_e = NULL; #endif #ifdef IVAS_FLOAT_FIXED - hTranDet->in_duck_gain = 1073741824; // Q30 + hTranDet->in_duck_gain = 1073741824; // Q30 + move32(); hTranDet->out_duck_gain = 1073741824; // Q30 + move32(); #else hTranDet->in_duck_gain = 1.0f; hTranDet->out_duck_gain = 1.0f; @@ -211,68 +214,104 @@ static void ivas_transient_det_init( case 48000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_48k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_48k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_48k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_48k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_48k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_48k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_48k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_48k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_48k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_48k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_48k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_48k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; + move32(); BREAK; case 32000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_32k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_32k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_32k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_32k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_32k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_32k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_32k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_32k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_32k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_32k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_32k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_32k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; + move32(); BREAK; case 16000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_16k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_16k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_16k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_16k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_16k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_16k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_16k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_16k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_16k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_16k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_16k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_16k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; + move32(); BREAK; @@ -284,13 +323,14 @@ static void ivas_transient_det_init( ivas_filters_init( &hTranDet->env_fast, (const float *) filt_coeff_arr[1], IVAS_FILTER_ORDER_1 ); ivas_filters_init( &hTranDet->env_slow, (const float *) filt_coeff_arr[2], IVAS_FILTER_ORDER_1 ); #else - ivas_filters_init_fx( &hTranDet->env_hpf, (const Word32 *) filt_coeff_arr_fx[0], IVAS_FILTER_ORDER_1 ); - ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], IVAS_FILTER_ORDER_1 ); - ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_hpf, (const Word32 *) filt_coeff_arr_fx[0], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); #endif hTranDet->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC; + move32(); return; } @@ -332,6 +372,7 @@ void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ) { + test(); IF( hTranDet == NULL || *hTranDet == NULL ) { return; @@ -360,25 +401,32 @@ void ivas_transient_det_process_fx( Word32 in_duck_gain[L_FRAME48k]; Word16 num_sf, sf, sf_samp, idx; Word32 mem = hTranDet->in_duck_gain; + move32(); ivas_td_decorr_get_ducking_gains_fx( hTranDet, pIn_pcm, in_duck_gain, NULL, frame_len, IVAS_TDET_ONLY ); transient_det[0] = 0; + move16(); transient_det[1] = 0; - IF( GT_32( L_sub( mem, hTranDet->in_duck_gain ), IVAS_TDET_PARM_TRANS_THR ) ) + move16(); + if ( GT_32( L_sub( mem, hTranDet->in_duck_gain ), IVAS_TDET_PARM_TRANS_THR ) ) { transient_det[0] = 1; + move16(); } num_sf = 16; - sf_samp = frame_len / num_sf; + move16(); + sf_samp = idiv1616( frame_len, num_sf ); FOR( sf = 1; sf <= num_sf; sf++ ) { - idx = ( sf_samp * sf ) - 1; - IF( GT_32( L_sub( mem, in_duck_gain[idx] ), IVAS_POINT_ONE_ONE_IN_Q30 ) ) + idx = sub( imult1616( sf_samp, sf ), 1 ); + if ( GT_32( L_sub( mem, in_duck_gain[idx] ), IVAS_POINT_ONE_ONE_IN_Q30 ) ) { transient_det[1] = 1; + move16(); } mem = in_duck_gain[idx]; + move32(); } return; @@ -470,11 +518,13 @@ static Word32 ivas_calc_duck_gain_fx( IF( LT_32( Mpy_32_32( duck_mult_fac, env_1 ), Mpy_32_32( L_shr( duck_gain_out, 1 ), env_2 ) ) ) { - IF( EQ_32( env_1, 0 ) || EQ_32( env_2, 0 ) ) + test(); + IF( ( env_1 == 0 ) || ( env_2 == 0 ) ) { duck_gain_out = 0; + move32(); } - else + ELSE { duck_gain_out = Mpy_32_32( duck_mult_fac, L_shl( (Word32) ( divide3232( env_1, env_2 ) ), Q16 ) ); duck_gain_out = L_shl( duck_gain_out, Q1 ); @@ -565,14 +615,20 @@ void ivas_td_decorr_get_ducking_gains_fx( const Word16 tdet_flag ) { Word16 i, q = Q14; + move16(); Word32 e_fast_fx[L_FRAME48k], e_slow_fx[L_FRAME48k]; Word32 in_duck_gain = hTranDet->in_duck_gain; + move32(); Word32 out_duck_gain = hTranDet->out_duck_gain; + move32(); Word32 in_duck_coeff = hTranDet->in_duck_coeff; + move32(); Word32 out_duck_coeff = hTranDet->out_duck_coeff; + move32(); Word32 duck_mult_fac = hTranDet->duck_mult_fac; + move32(); - mvl2l( pIn_pcm, e_fast_fx, frame_len ); + Copy32( pIn_pcm, e_fast_fx, frame_len ); /* env hpf */ ivas_filter_process_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, q ); @@ -582,7 +638,9 @@ void ivas_td_decorr_get_ducking_gains_fx( FOR( i = 0; i < frame_len; i++ ) { e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); + move32(); e_slow_fx[i] = e_fast_fx[i]; + move32(); } /* env fast*/ @@ -597,8 +655,10 @@ void ivas_td_decorr_get_ducking_gains_fx( { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; + move32(); } hTranDet->in_duck_gain = in_duck_gain; + move32(); } ELSE { @@ -606,11 +666,15 @@ void ivas_td_decorr_get_ducking_gains_fx( { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; + move32(); out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, e_fast_fx[i], e_slow_fx[i], duck_mult_fac ); pOut_duck_gains[i] = out_duck_gain; + move32(); } hTranDet->in_duck_gain = in_duck_gain; + move32(); hTranDet->out_duck_gain = out_duck_gain; + move32(); } return; diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index e7fe28882f226c80bfe275a1408adbd5dc6c8184..9cd51345a1f09d77c8426c761ed077b86cc44c5f 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -38,8 +38,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" #include "rom_com.h" #include "wmc_auto.h" @@ -231,7 +230,7 @@ void lag_wind( FOR( i = 1; i <= m; i++ ) { - tmp = Mpy_32( r_h[i], r_l[i], wnd_h[i - 1], wnd_l[i - 1] ); + tmp = Mpy_32( r_h[i], r_l[i], wnd_h[sub( i, 1 )], wnd_l[sub( i, 1 )] ); L_Extract( tmp, &r_h[i], &r_l[i] ); } } @@ -284,7 +283,8 @@ void lag_wind_32( FOR( i = 1; i <= m; i++ ) { - r[i] = Mpy_32_32( r[i], wnd[i - 1] ); + r[i] = Mpy_32_32( r[i], wnd[sub( i, 1 )] ); + move32(); } } diff --git a/lib_com/lerp.c b/lib_com/lerp.c index eea745b81edefae07087ca009f5f33361b4b1c93..80e789c4cac102b2aa5a24d95599d4b71157f5fc 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -37,8 +37,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "wmc_auto.h" diff --git a/lib_com/limit_t0_fx.c b/lib_com/limit_t0_fx.c index 97aa4fd8fdfea28183d1b6f04b73e26638cb3285..6573a7925e67489aedcc548a2a4ace59b060e66b 100644 --- a/lib_com/limit_t0_fx.c +++ b/lib_com/limit_t0_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" diff --git a/lib_com/log2.c b/lib_com/log2.c index 4e70862d1097ec3b12b6baf4ab0bc0c368dcbbe0..9e1cb14ae62c97d917d4cc97b79557922ff88ca2 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -78,8 +78,11 @@ Word32 log10_fx( Word32 Linput ) Word32 Ltemp1, Ltemp2; Word32 L_tmp; - if ( Linput <= 0 ) + IF( Linput <= 0 ) + { return ( LW_MIN ); + } + n1 = norm_l( Linput ); Ltemp1 = (Word32) L_shl( Linput, n1 ); diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 902a120b421e5dcf5f9a70b646f5d69646f00780..fbbf2a464eb2bfcd1f18fcf59b8d327d66fdf2b0 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -31,10 +31,10 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "cnst.h" /* Common constants */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "cnst.h" /* Common constants */ /*--------------------------------------------------------------------------* * Local constants diff --git a/lib_com/longarith.c b/lib_com/longarith.c index 2617034d9c7a3887b3e9db84f60a0e2970345caa..65070f093f6bec177b9f5ce288efbb94772e7ce8 100644 --- a/lib_com/longarith.c +++ b/lib_com/longarith.c @@ -41,7 +41,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx2.h" +#include "prot_fx.h" #endif diff --git a/lib_com/low_rate_band_att.c b/lib_com/low_rate_band_att.c index 288a11d863a67e94cd358e505bb9753c7ec6893d..33265c6a54bd0fb753c4e4ef9c11cb19b31ba9ba 100644 --- a/lib_com/low_rate_band_att.c +++ b/lib_com/low_rate_band_att.c @@ -155,6 +155,7 @@ void get_max_pulses( return; } +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * fine_gain_dec() * @@ -190,3 +191,4 @@ void fine_gain_dec( return; } +#endif diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index a71311f38bc8bf395c3d91907bc99afe02e721a1..e7bf741169db3c51a61944e19a5c0d2b0bbd7050 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" /* Compilation switches */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -330,7 +329,7 @@ void fine_gain_dec_fx( { IF( fg_pred[band] != 0 ) { - idx = get_next_indice( st, gbits ); + idx = get_next_indice_fx( st, gbits ); gain_dbq = finegain_fx[gbits - 1][idx]; move16(); diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index 382ca06d860d5da4fd1c3e1254471b57265ecd07..ff6dfea48adcedcbb8899a9a1b0ad6f853f25c10 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -42,7 +42,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------* * Local constants diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 83b59079a24a1b49c75a0dceb9669df0beb208cd..d4c01f46c0108504026973ebc7a6a048f748c6b7 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -38,7 +38,7 @@ #include #include "options.h" /* Compilation switches */ #include "ivas_cnst.h" /* Common constants */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" #include "basop_util.h" diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 4c10059d0b2e627d80316ad3381ecf1801e2e76b..14b842115cd75cafc4fee5c9675d5c3ee66e189b 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -8,8 +8,7 @@ #include "basop_util.h" #include "rom_com.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*---------------------------------------------------------------------* diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index a423cb9512264ae1056c1cd266b403ead40723a1..409566ddcc351bd7ab99b75eebebeac74cd707c1 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" #include "options.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifndef swap diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 0b92239224777d3e99ccbf09c7de2a087781f2e5..ddce7c19914bfb70759d3366d1443d750a205aa8 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -44,8 +44,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #endif /*-------------------------------------------------------------------* diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index c0f7bd613b0bdba16ec5bb4634f881aec93ac07e..5b6b612cade3ff8493a5cf6741b881dcc23e6a1c 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -36,7 +36,7 @@ #include "basop_util.h" #include "rom_com.h" #include "ivas_cnst.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_error.h" @@ -2865,7 +2865,7 @@ void lsf_syn_mem_backup_fx( move16(); *streaklimit = st_fx->streaklimit_fx; move16(); - *pstreaklen = st_fx->pstreaklen_fx; + *pstreaklen = st_fx->pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) @@ -3005,7 +3005,7 @@ void lsf_syn_mem_restore_fx( move16(); st_fx->streaklimit_fx = streaklimit; move16(); - st_fx->pstreaklen_fx = pstreaklen; + st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 0cda281eaa64f36ebdc362f643cc933700f085f7..70b9190027ffde618edbea070a1a3624122db200 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -10,7 +10,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * Local constants diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 4bccd568b93c66dca6e1e7aac5f04bbec9a3643c..4df5f351db8888425669a365c1aea43c24b1de0d 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -41,7 +41,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * modify_Fs() @@ -537,6 +537,53 @@ void Interpolate_allpass_steep_32( int16_t n, k; Word32 temp_fx[ALLPASSSECTIONS_STEEP - 1]; +#ifdef IVAS_ENH32_CADENCE_CHANGES + /* upper allpass filter chain */ + FOR( k = 0; k < N; k++ ) + { + temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); + move32(); + mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); + move32(); + + /* for better performance, unroll this loop */ + FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) + { + temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); + move32(); + mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); + move32(); + } + + out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + move32(); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + move32(); + } + + /* lower allpass filter chain */ + FOR( k = 0; k < N; k++ ) + { + temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); + move32(); + mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); + move32(); + + /* for better performance, unroll this loop */ + FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) + { + temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); + move32(); + mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); + move32(); + } + + out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + move32(); + mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + move32(); + } +#else /* upper allpass filter chain */ FOR( k = 0; k < N; k++ ) { @@ -554,9 +601,9 @@ void Interpolate_allpass_steep_32( move32(); } - out_fx[2 * k + 1] = L_add( mem_fx[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + out_fx[add( shl( k, 1 ), 1 )] = L_add( mem_fx[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); move32(); - mem_fx[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp_fx[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp_fx[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out_fx[add( shl( k, 1 ), 1 )], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); move32(); } @@ -582,6 +629,7 @@ void Interpolate_allpass_steep_32( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp_fx[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); move32(); } +#endif return; } @@ -732,9 +780,9 @@ void Decimate_allpass_steep_fx32( FOR( k = 1; k < N / 2; k++ ) { - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[2 * k - 1], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( in[2 * k - 1], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); move32(); /* for better performance, unroll this loop */ diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index fa12252ad3f05abe34c972676f7b2e6782ddebc1..1e64cc13b18b0ea9e9c9ae25bc3772bb1aa8a912 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /* Static table prototypes */ #include #include "rom_enc.h" /* prototypes */ @@ -47,7 +46,9 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 sigOut_fx[], /* o : decimated signal Q0 */ const Word32 fout, /* i : frequency of output Q0 */ Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, // TO be removed + Word16 *mem_decim_size // TO be removed ) { Word16 i; @@ -79,13 +80,14 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /*-------------------------------------------------------------------* * Find the resampling configuration *-------------------------------------------------------------------*/ - + *Q_new_inp = 0; /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { /* just copy the signal_fx and quit */ Copy( sigIn_fx, sigOut_fx, lg ); - + *mem_decim_size = 0; + *Q_new_inp = 0; return lg; } ELSE @@ -150,6 +152,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } mem_len = shl( filt_len, 1 ); + *mem_decim_size = mem_len; signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; @@ -187,7 +190,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - preemph_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); + PREEMPH_FX( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ @@ -254,6 +257,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } /* rescaling */ test(); + IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) { IF( LT_16( fac_num, fac_den ) ) @@ -266,6 +270,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < lg_out; i++ ) { sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ + *Q_new_inp = -1; } } ELSE @@ -277,6 +282,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { #ifdef BASOP_NOGLOB num_den = shl_o( num_den, 1, &Overflow ); + //*Q_new_inp = 2; #else num_den = shl( num_den, 1 ); #endif @@ -286,6 +292,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q0*/ move16(); } + *Q_new_inp = -1; } } ELSE @@ -298,6 +305,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q-1*/ move16(); + *Q_new_inp = -2; } } ELSE @@ -306,6 +314,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < lg_out; i++ ) { sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ + *Q_new_inp = -1; } } } @@ -316,6 +325,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = mult_r( sigOut_fx[i], 16384 ); move16(); /*Q-1*/ + *Q_new_inp = -2; } } /* update the filter memory */ diff --git a/lib_com/move.h b/lib_com/move.h index 2afeb1ccba1f040d729bf6aaa9370527d643856d..a6f5b353e8aba360d4ff04ad456f62cc960a9873 100644 --- a/lib_com/move.h +++ b/lib_com/move.h @@ -39,7 +39,7 @@ #include "stl.h" /* BASOP -> FLC brigde: data move counting */ -#if ( WMOPS ) +#ifdef WMOPS extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #endif /* ifdef WMOPS */ diff --git a/lib_com/mslvq_com.c b/lib_com/mslvq_com.c index 00b77cebfad6178cf4e12d4411ff4506153ef2fc..d7d4c427be231228e23c01dcdf7beb0f7448e97c 100644 --- a/lib_com/mslvq_com.c +++ b/lib_com/mslvq_com.c @@ -41,7 +41,7 @@ #include "prot.h" #include "wmc_auto.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" /*-----------------------------------------------------------------* diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index b2e0e0b2387d5d9d54af6956f42d58b0036f267d..bb1913497c67e604b5682be7427085c692c7fe95 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -32,7 +32,7 @@ #include "options.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "stl.h" #include "rom_com.h" @@ -1250,13 +1250,13 @@ void deindex_lvq_SHB_fx( IF( mode == 0 ) { - p_no_lead = &no_lead_BWE[( nbits - mslvq_SHB_min_bits[0] ) * 3]; - p_scales = &scales_BWE_fx[( nbits - mslvq_SHB_min_bits[0] ) * 3]; + p_no_lead = &no_lead_BWE[i_mult( sub( nbits, mslvq_SHB_min_bits[0] ), 3 )]; + p_scales = &scales_BWE_fx[i_mult( sub( nbits, mslvq_SHB_min_bits[0] ), 3 )]; } ELSE { - p_no_lead = &no_lead_BWE_3b[( nbits - mslvq_SHB_min_bits[1] ) * 3]; - p_scales = &scales_BWE_3b_fx[( nbits - mslvq_SHB_min_bits[1] ) * 3]; + p_no_lead = &no_lead_BWE_3b[i_mult( sub( nbits, mslvq_SHB_min_bits[1] ), 3 )]; + p_scales = &scales_BWE_3b_fx[i_mult( sub( nbits, mslvq_SHB_min_bits[1] ), 3 )]; } @@ -1271,14 +1271,16 @@ void deindex_lvq_SHB_fx( move32(); FOR( i = 0; i < MAX_NO_SCALES; i++ ) { - offsets[i + 1] = table_no_cv[p_no_lead[i]] + offsets[i]; + offsets[i + 1] = UL_addNsD( table_no_cv[p_no_lead[i]], offsets[i] ); move32(); } /* find idx_scale */ idx_scale = 0; - WHILE( (Word16) i <= MAX_NO_SCALES && index >= offsets[idx_scale] ) + test(); + WHILE( LE_32( i, MAX_NO_SCALES ) && index >= offsets[idx_scale] ) { + test(); idx_scale = add( idx_scale, 1 ); } idx_scale = sub( idx_scale, 1 ); @@ -1286,6 +1288,7 @@ void deindex_lvq_SHB_fx( /* find idx_leader */ i = 1; + move16(); WHILE( GT_32( index, table_no_cv[i] ) ) { i = add( i, 1 ); @@ -1295,15 +1298,17 @@ void deindex_lvq_SHB_fx( decode_comb_fx( (Word32) ( L_sub( L_sub( index, table_no_cv[i] ), 1 ) ), out, i ); scale = p_scales[idx_scale]; + move16(); FOR( i = 0; i < LATTICE_DIM; i++ ) { - Word32 temp = Mpy_32_16_1( sigma_BWE_fx[mode * LATTICE_DIM + i], scale ); + Word32 temp = Mpy_32_16_1( sigma_BWE_fx[add( i_mult( mode, LATTICE_DIM ), i )], scale ); temp = Mpy_32_16_1( temp, out[i] ); #ifndef FIX_800_PROPOSAL_HB_LPC_COEFFICIENT out[i] = extract_h( temp ); #else out[i] = extract_l( temp ); /* Q15 output*/ #endif + move16(); // out[i] *= scale * sigma_BWE_fx[mode * LATTICE_DIM + i]; } } diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index f0420e3dbf30cbd1cd9bd0c2bd74bec7b429285b..690db58652d44357ae0ccff452100c9099c0f741 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -33,7 +33,7 @@ #include #include "options.h" #include "rom_com.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*===================================================================*/ diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c index 9f1ce2157155e7d0a29a05db7fe5b0228eb54705..30b97811b61ad883e8d08dfe5587ade950a34ac6 100644 --- a/lib_com/oper_32b.c +++ b/lib_com/oper_32b.c @@ -25,6 +25,8 @@ #include "stl.h" #include "basop32.h" +#define WMC_TOOL_SKIP + /***************************************************************************** * * * Function L_Extract() * @@ -407,3 +409,4 @@ Word32 Div_32( Word32 L_num, Word16 denom_hi, Word16 denom_lo ) #endif return ( L_32 ); } +#undef WMC_TOOL_SKIP diff --git a/lib_com/options.h b/lib_com/options.h index 7a446867dfe8d141fe2e99c13c5b75e5f6500eb8..b27eb7ad7e113cebb76ab79accd330856a1926c5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -1,163 +1,162 @@ -/****************************************************************************************************** - - (C) 2022-2024 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.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#ifndef OPTIONS_H -#define OPTIONS_H -//#define DEBUGGING /*allows message printed out during run time */ -#ifdef DEBUGGING -#include "debug.h" -#endif - -#include "stl.h" - -/* clang-format off */ - /* ################### Start compiler switches ######################## */ - -#define SUPPORT_JBM_TRACEFILE /* support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ - -/* #################### End compiler switches ######################### */ - -/* ################### Start compiler switches ######################## */ -/* */ -#ifdef _MSC_VER -#pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ -#endif - -/*#define WMOPS 1 --> activation or deactivation in count.h*/ /* Activate FIXED-POINT complexity counters */ -/*#define DONT_COUNT */ /* To prevent the complexity counting */ - -#ifdef WMOPS_FLT -/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ -/*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ -/*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ -/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ -#endif - -/* #################### End DEBUGGING switches ############################ */ - -/* ################### Start FIXES switches ########################### */ - -#define NON_BE_FIX_1048_THRESHOLD_COH_BASOP /* Nokia: Fix 1048 replace comparison with 0 with comparison to threshold, to align with BASOP*/ -#define NONBE_FIX_1054_NEGATIVE_LVQ_INDEX /* Nokia: issue 1054: Input to decode_comb in deindex_lvq_SHB should be positive */ -#define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ -#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ -#define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ -#define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ -#define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ - -/* #################### End FIXES switches ############################ */ - -#define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ - - -/* ################### Start BE switches ################################# */ -/* only BE switches wrt selection floating point code */ - -/*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ - -#define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ -#define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ -#define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ -#define FIX_901_PARAMMC_DEAD_CODE /* FhG: issue 901: remove dead ParamMC code */ - -/* #################### End BE switches ################################## */ - - -/* #################### Start NON-BE switches ############################ */ -/* any switch which is non-be wrt selection floating point code */ -/* all switches in this category should start with "NONBE_" */ - -#define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */ -#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ -#define BE_FIX_832_ASAN_ERROR_EFAP_OSBA /* FhG: issue #832: fix ASAN error caused by re-allocating EFAP memories in OSBA*/ -#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */ -#define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ -#define NONBE_FIX_738_QUATERNION_SLERP_PRECISION /* Quaternion slerp changes*/ -#define IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -#define MSAN_FIX -#endif -#define ISM_DISABLE -#define FIX_TMP_714 -#define BASOP_NOGLOB_TMP_715 -#define EVS_FUNC_MODIFIED -//#define DEBUGGING -//#define DBG_WAV_WRITER -#define EVS_FLOAT_ENC -//#define DUMPS_ENABLED -//#define WMOPS -#define FIX_667_DISABLE_INITIAL_PLC_SUPPRESSION -#define IVAS_CNST -#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused EVS parameters to remove warnings, these parameters will be used in IVAS */ - -#define MOD_BIT_ALLOC_ROM_TABLE // Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/ -#define SIMPLIFY_CODE_BE // Simplify synthesis loop - -#define CR_2109_to_2112_cd0_ce0 /* This is related to the CRs include in the 26.444 package of 21-12. Concerns lead_deindexing and */ - -#define FIX_ISSUE_723_INFO_TCX_NOISE /*FhG: Issue 723: fix for IGF that introduces wrong noise filling behavion*/ - -#define FIX_QMETADATA_PENALTY /* Nokia: transform penalty calculation in qmetadata into integer operations */ - -/* ##################### End NON-BE switches ########################### */ -#define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE -#define FIX_746 // proposed fix to solve low bit-rate frame boundaries issues -#define FIX_SATURATION_725 // Propose fix for saturation in AVQ -#define FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR /* Eri: Proposed fix for issue 737: scaling error in excitation memory after HQ->ACELP switch */ -#define FIX_736_BWE_SECT_C // Solves an issue where the BWE was disappearing, problem related to wrong scaling in ic-BWE -#define FIX_734_MISSING_SUBFR_LOW_RATE_ACELP -#define FIX_747_TDBWE_ENERGY_BURST -#define FIX_770_DISCONTINUITIES_SW_TCX2ACELP // Fix discontinuities when switching from TCX to ACELP -#define FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step was right shift by 2, which made the OVA wrong */ -#define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ -#define FIX_778_STEREO_BRATE_SWITCHING -#define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ -#define FIX_729_MISSING_RESCALING -#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ -#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ -#define FIX_800_PROPOSAL_HB_LPC_COEFFICIENT /* Proposal to fix wrong shape of TDBWE, #800 */ - -#define FIX_802__NON_BE_DECODING /* Fix possible difference float and fixed point when computing the GSC bit allocation */ -#define FIX_802_1137_1137_GSC_IVAS_FXFLT_DECODING /* VA: ISSUES 802 and 1137 Made sure that float and fixed point GCS bit allocation is the same during IVAS modes */ - -/* ################## End DEVELOPMENT switches ######################### */ - -/* clang-format on */ -#define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO - -#define UNUSED_PARAM( ... ) (void) ( __VA_ARGS__ ) - -#endif +/****************************************************************************************************** + + (C) 2022-2024 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.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 + ====================================================================================*/ + +#ifndef OPTIONS_H +#define OPTIONS_H + +/* clang-format off */ + +/* ################### Start DEBUGGING switches ######################## */ + +#ifdef _MSC_VER +#pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ +#endif + +/*#define DEBUGGING*/ /* Allows debugging message to be printed out during runtime */ +#ifdef DEBUGGING +/*#define DBG_WAV_WRITER*/ +#endif + +#define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ + +/*#define WMOPS*/ /* Activate complexity and memory counters */ +#ifdef WMOPS +/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ +/*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ +/*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ +/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ +#endif + +/* #################### End DEBUGGING switches ############################ */ + +/* ################### Start FIXES switches ########################### */ + +#define NON_BE_FIX_1048_THRESHOLD_COH_BASOP /* Nokia: Fix 1048 replace comparison with 0 with comparison to threshold, to align with BASOP*/ +#define NONBE_FIX_1054_NEGATIVE_LVQ_INDEX /* Nokia: issue 1054: Input to decode_comb in deindex_lvq_SHB should be positive */ +#define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ +#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ +#define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ +#define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ +#define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ +#define NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /* VA: Add fix point bit allocation for special GSC mode such that float and fixed point have the same final bit allocation */ +#define NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE /* VA: issue 1132: prevent division by extremely low energy value in SWB TBE */ +#define NON_BE_FIX_807_MASA_DTX_BRSW /* Nokia: adds fix to check existence of DTX encoder for secondary channel in TD mode */ + +/* #################### End FIXES switches ############################ */ + +#define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ + + +/* ################### Start BE switches ################################# */ +/* only BE switches wrt selection floating point code */ + +/*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ + +#define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ +#define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ +#define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ +#define FIX_901_PARAMMC_DEAD_CODE /* FhG: issue 901: remove dead ParamMC code */ +#define IVAS_ENH32_CADENCE_CHANGES + +/* #################### End BE switches ################################## */ + + +/* #################### Start NON-BE switches ############################ */ +/* any switch which is non-be wrt selection floating point code */ +/* all switches in this category should start with "NONBE_" */ + +#define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */ +#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ +#define BE_FIX_832_ASAN_ERROR_EFAP_OSBA /* FhG: issue #832: fix ASAN error caused by re-allocating EFAP memories in OSBA*/ +#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */ +#define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ +#define NONBE_FIX_738_QUATERNION_SLERP_PRECISION /* Quaternion slerp changes*/ +#define IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +#define MSAN_FIX +#define FIX_818_COMPLEXITY_IMPROV /* Fix for issue 818 */ +#endif +#define ISM_DISABLE +#define FIX_TMP_714 +#define BASOP_NOGLOB_TMP_715 +#define EVS_FUNC_MODIFIED +#define EVS_FLOAT_ENC +#define FIX_667_DISABLE_INITIAL_PLC_SUPPRESSION +#define IVAS_CNST +#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused EVS parameters to remove warnings, these parameters will be used in IVAS */ + +#define MOD_BIT_ALLOC_ROM_TABLE // Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/ +#define SIMPLIFY_CODE_BE // Simplify synthesis loop + +#define CR_2109_to_2112_cd0_ce0 /* This is related to the CRs include in the 26.444 package of 21-12. Concerns lead_deindexing and */ + +#define FIX_ISSUE_723_INFO_TCX_NOISE /*FhG: Issue 723: fix for IGF that introduces wrong noise filling behavion*/ + +#define FIX_QMETADATA_PENALTY /* Nokia: transform penalty calculation in qmetadata into integer operations */ + +#define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ +#define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ + +/* ##################### End NON-BE switches ########################### */ +#define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE +#define FIX_746 // proposed fix to solve low bit-rate frame boundaries issues +#define FIX_SATURATION_725 // Propose fix for saturation in AVQ +#define FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR /* Eri: Proposed fix for issue 737: scaling error in excitation memory after HQ->ACELP switch */ +#define FIX_736_BWE_SECT_C // Solves an issue where the BWE was disappearing, problem related to wrong scaling in ic-BWE +#define FIX_734_MISSING_SUBFR_LOW_RATE_ACELP +#define FIX_747_TDBWE_ENERGY_BURST +#define FIX_770_DISCONTINUITIES_SW_TCX2ACELP // Fix discontinuities when switching from TCX to ACELP +#define FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step was right shift by 2, which made the OVA wrong */ +#define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ +#define FIX_778_STEREO_BRATE_SWITCHING +#define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ +#define FIX_729_MISSING_RESCALING +#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ +#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ +#define FIX_800_PROPOSAL_HB_LPC_COEFFICIENT /* Proposal to fix wrong shape of TDBWE, #800 */ + +#define FIX_802__NON_BE_DECODING /* Fix possible difference float and fixed point when computing the GSC bit allocation */ +#define FIX_802_1137_1137_GSC_IVAS_FXFLT_DECODING /* VA: ISSUES 802 and 1137 Made sure that float and fixed point GCS bit allocation is the same during IVAS modes */ +#define FIX_810_PREVENT_UNECESSARY_SAT_IN_TC /* VA : Prevent an unnecessary saturation that can happen in TC, have a minimal impact on most cases. Significant improvement for the last segment of LTV when TC is triggered */ +#define FIX_826_PRECISION_LOST_AND_COMPL /* VA : Fix lost of precision that leads to unnecessary high noise floor and to some framing artifacts */ +/* ################## End DEVELOPMENT switches ######################### */ + +/* clang-format on */ +#define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO + +#define UNUSED_PARAM( ... ) (void) ( __VA_ARGS__ ) + +#endif diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index 5b6374ee038e7e6a43e406dffa2b1d84a5d2b167..aae7af5f06c04bd14721a18fd2f4fd7107889b87 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -39,7 +39,7 @@ #include "options.h" #include "stat_com.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "wmc_auto.h" @@ -326,7 +326,9 @@ void WriteToBitstream_fx( nBits = param->nBits; IF( param->nBits == 0 ) { +#define WMC_TOOL_SKIP nBits = param->GetNumberOfBits( **pStream, index ); +#undef WMC_TOOL_SKIP } test(); diff --git a/lib_com/parameter_bitmaping_fx.c b/lib_com/parameter_bitmaping_fx.c index ee5dd7d73761190a476adef39d200af70f4b7ac1..e66d7b60342f8ea86197d8aae57f22814e2bf24a 100644 --- a/lib_com/parameter_bitmaping_fx.c +++ b/lib_com/parameter_bitmaping_fx.c @@ -2,7 +2,7 @@ #include #include "options.h" #include "stat_com.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "wmc_auto.h" /** Get nBits long value from bitstream into *pStream. */ diff --git a/lib_com/phase_dispersion_fx.c b/lib_com/phase_dispersion_fx.c index 74ae7708c645fb5e067e09b8aab574f80b17cbd6..b7ca7b739b9f8a93a780a2843c59f0c065b142ce 100644 --- a/lib_com/phase_dispersion_fx.c +++ b/lib_com/phase_dispersion_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" /* EV-VBR compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index 673ffd469acf8650234cc94293239085ee064d24..390c0a47ce1b5ec84c118f3911a939ba84baeb83 100644 --- a/lib_com/ppp_fx.c +++ b/lib_com/ppp_fx.c @@ -33,7 +33,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*===================================================================*/ /* FUNCTION : Interpol_delay_fx () */ diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index a6672c2b221e24e4768449b60f2653ec8cf061fe..21bd9f541e420387a60b6e141a80cc2bd6ef7250 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index e610e9fd784e70c861195804ace9161d905b2275..63de35dca4110d2b0c9948e50d1bf04d11878c1f 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------* * preemph_copy_fx() * diff --git a/lib_com/prot.h b/lib_com/prot.h index 03ce573b9a9a7ceb8841221144de86f4de4d0e89..12828f0ddefb815916f911f64691e616fcb22b2f 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -166,18 +166,6 @@ float sum2_f( const int16_t lvec /* i : length of input vector */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 sum2_f_32_fx( - const Word32 *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ - Word16 gb ); - -Word32 sum2_32_fx( - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word16 *e ); -#endif - void set_c( int8_t y[], /* i/o: Vector to set */ const int8_t a, /* i : Value to set the vector to */ @@ -276,14 +264,12 @@ int16_t minimum( float *min_val /* o : minimum value in the input vector */ ); -#ifndef IVAS_FLOAT_FIXED /*! r: index of the minimum value in the input vector */ int16_t minimum_s( const int16_t *vec, /* i : Input vector */ const int16_t lvec, /* i : Vector length */ int16_t *min_val /* o : minimum value in the input vector */ ); -#endif /*! r: return index with max energy value in vector */ int16_t emaximum( @@ -336,15 +322,6 @@ void v_sub( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_mult_fixed( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ -); -#endif - void v_mult( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -365,14 +342,6 @@ void v_sub_s( int16_t y[], /* o : Output vector that contains vector 1 - vector 2 */ const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_sub_s16_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ -); -#endif // IVAS_FLOAT_FIXED /*! r: index of the winning codeword */ int16_t squant( @@ -499,22 +468,6 @@ void delay_signal_float( const int16_t delay /* i : delay in samples */ ); -#ifdef IVAS_FLOAT_FIXED -void delay_signal_fx( - Word32 x[], /* i/o: signal to be delayed */ - const int16_t len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ - const int16_t delay /* i : delay in samples */ -); -void delay_signal_q_adj_fx( - Word32 x[], /* i/o: signal to be delayed */ - const int16_t len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ - const int16_t delay, /* i : delay in samples */ - const Word16 q_x, - const Word16 q_mem ); -#endif - ivas_error push_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t id, /* i : ID of the indice */ @@ -522,17 +475,33 @@ ivas_error push_indice( int16_t nb_bits /* i : number of bits used to quantize the indice */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error push_next_indice( + BSTR_ENC_HANDLE hBstr, + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ +); +#else ivas_error push_next_indice( BSTR_ENC_HANDLE hBstr, uint16_t value, /* i : value of the quantized indice */ int16_t nb_bits /* i : number of bits used to quantize the indice */ ); +#endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +ivas_error push_next_bits( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const UWord16 bits[], /* i : bit buffer to pack, sequence of single bits */ + const Word16 nb_bits /* i : number of bits to pack */ +); +#else ivas_error push_next_bits( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const uint16_t bits[], /* i : bit buffer to pack, sequence of single bits */ const int16_t nb_bits /* i : number of bits to pack */ ); +#endif // IVAS_FLOAT_FIXED /*! r: maximum number of indices */ int16_t get_ivas_max_num_indices( @@ -1748,7 +1717,6 @@ void diff_envelope_coding( int16_t *difidx /* o : differential code */ ); -#ifndef IVAS_FLOAT_FIXED /*! r: Number of bits */ int16_t decode_envelope_indices( Decoder_State *st, /* i/o: decoder state structure */ @@ -1759,9 +1727,7 @@ int16_t decode_envelope_indices( const int16_t flag_HQ2, /* i : indicator of HQ2 core */ const int16_t is_transient /* i : transient flag */ ); -#endif -#ifndef IVAS_FLOAT_FIXED /*! r: Number of bits */ void dequantize_norms( Decoder_State *st, /* i/o: decoder state structure */ @@ -1771,7 +1737,6 @@ void dequantize_norms( int16_t *ynrm, /* o : Decoded norm indices */ int16_t *normqlg2 /* o : Log2 of decoded norms */ ); -#endif void hq_configure( const int16_t length, /* i : Frame length */ @@ -1818,7 +1783,6 @@ int16_t hq_classifier_enc( int16_t *hqswb_clas /* o : HQ class */ ); -#ifndef IVAS_FLOAT_FIXED /*! r: Consumed bits */ int16_t hq_classifier_dec( Decoder_State *st, /* i/o: decoder state structure */ @@ -1827,7 +1791,6 @@ int16_t hq_classifier_dec( int16_t *is_transient, /* o : Transient flag */ int16_t *hqswb_clas /* o : HQ class */ ); -#endif void hq_bit_allocation( const int32_t core_brate, /* i : Core bitrate */ @@ -2355,7 +2318,7 @@ void pre_proc( float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ int16_t *hq_core_type /* o : HQ core type */ ); -#endif + /*! r: HQ_CORE/TCX_20_CORE decision */ int16_t mdct_classifier( @@ -2670,19 +2633,7 @@ void swb_tbe_enc( float *White_exc16k, /* o : shaped white excitation for the FB TBE */ const float pitch_buf[] /* i : pitch for each subframe */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ - Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, - Word16 *Q_white_exc ); -#endif + void swb_tbe_dec( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -2931,18 +2882,6 @@ void swb_bwe_dec_flt( const int16_t output_frame /* i : frame length */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ -); -#endif // IVAS_FLOAT_FIXED - - void hr_bwe_dec_init_flt( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ); @@ -3710,7 +3649,19 @@ void speech_music_classif( int16_t *high_lpn_flag, /* o : sp/mus LPN flag */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ ); - +void ivas_find_wsp( + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_subfr, /* i : length of subframe */ + const Word16 nb_subfr, /* i : number of subframes */ + const Word16 *A_fx, /* i : A(z) filter coefficients */ + Word16 *Aw_fx, /* o : weighted A(z) filter coefficients */ + const Word16 *speech_fx, /* i : pointer to the denoised speech frame */ + const Word16 tilt_fact, /* i : tilt factor */ + Word16 *wsp_fx, /* o : poitnter to the weighted speech frame */ + Word16 *mem_wsp_fx, /* i/o: W(Z) denominator memory */ + const Word16 gamma, /* i : weighting factor */ + const Word16 L_look /* i : look-ahead */ +); void find_wsp( const int16_t L_frame, /* i : length of the frame */ const int16_t L_subfr, /* i : length of subframe */ @@ -4621,7 +4572,6 @@ void signaling_enc_rf( Encoder_State *st /* i/o: encoder state structure */ ); -#ifndef IVAS_FLOAT_FIXED ivas_error acelp_core_dec( Decoder_State *st, /* i/o: Decoder state structure */ float output[], /* o : synthesis @internal Fs */ @@ -4645,33 +4595,6 @@ ivas_error acelp_core_dec( STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ const int16_t read_sid_info /* i : read SID info flag */ ); -#endif - -#ifdef IVAS_FLOAT_FIXED -ivas_error acelp_core_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - const int16_t sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ - int16_t *unbits, /* o : number of unused bits */ - int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t last_element_brate, /* i : last element bitrate */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - const int16_t nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const int16_t read_sid_info /* i : read SID info flag */ -); -#endif void bass_psfilter_init( BPF_DEC_HANDLE hBPF /* o : BPF data handle */ @@ -5287,12 +5210,6 @@ ivas_error init_decoder( const MC_MODE mc_mode /* i : MC mode */ ); -#ifdef IVAS_FLOAT_FIXED -void destroy_cldfb_decoder_ivas_fx( - Decoder_State *st /* o : Decoder static variables structure */ -); -#endif // IVAS_FLOAT_FIXED - void destroy_cldfb_decoder_flt( Decoder_State *st /* o : Decoder static variables structure */ ); @@ -5370,17 +5287,6 @@ void wtda( const int16_t L /* i : length */ ); -#ifdef IVAS_FLOAT_FIXED -void wtda_fx32( - const Word32 *new_audio, /* i : input audio Q11 */ - Word32 *wtda_audio, /* o : windowed audio Q11 */ - Word32 *old_wtda, /* i/o: windowed audio from previous frame Q11 */ - const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ - const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L /* i : length */ -); -#endif - void wtda_ext( const float *new_audio, /* i : input audio */ float *wtda_audio, /* o : windowed audio */ @@ -5438,7 +5344,6 @@ void logqnorm( const int16_t N, /* i : sub-vector size */ const float *thren ); -#ifndef IVAS_FLOAT_FIXED void huff_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t N, /* i : Number of codewords to decode */ @@ -5449,7 +5354,6 @@ void huff_dec( const int16_t *huff_tab, /* i : Huffman table order by codeword lengths */ int16_t *index /* o : Decoded index */ ); -#endif void calc_norm( const float *x, /* i : Input vector. */ @@ -5590,38 +5494,30 @@ void hq_hr_dec( ); -#ifndef IVAS_FLOAT_FIXED void hdecnrm_context( Decoder_State *st, /* i/o: decoder state structure */ const int16_t N, /* i : number of norms */ int16_t *index, /* o : indices of quantized norms */ int16_t *n_length /* o : decoded stream length */ ); -#endif -#ifndef IVAS_FLOAT_FIXED void hdecnrm_tran( Decoder_State *st, /* i/o: decoder state structure */ const int16_t N, /* i : number of norms */ int16_t *index /* o : indices of quantized norms */ ); -#endif -#ifndef IVAS_FLOAT_FIXED void hdecnrm_resize( Decoder_State *st, /* i/o: decoder state structure */ const int16_t N, /* i : number of SFMs */ int16_t *index /* o : norm quantization index vector */ ); -#endif -#ifndef IVAS_FLOAT_FIXED void hdecnrm( Decoder_State *st, /* i/o: decoder state structure */ const int16_t N, /* i : number of norms */ int16_t *index /* o : indices of quantized norms */ ); -#endif /*! r: index of last band */ int16_t find_last_band( @@ -6061,18 +5957,6 @@ ivas_error core_switching_post_dec( const int16_t nchan_out, /* i : number of output channels */ const int16_t last_element_mode /* i : element mode of previous frame */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error core_switching_pre_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 output_frame, /* i : frame length */ - const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ - const Word16 nchan_out, /* i : number of output channels */ - const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth, - Word16 *Q_olapBufferSynth2 ); -#endif // IVAS_FLOAT_FIXED ivas_error core_switching_pre_dec( Decoder_State *st, /* i/o: decoder state structure */ @@ -6910,14 +6794,6 @@ void hp20_flt( Float32 mem[], const Word32 Fs ); -#ifdef IVAS_FLOAT_FIXED -void hp20_fix32( - Word32 signal_fx[], - const Word16 lg, - Word32 mem_fx[], - const Word32 Fs ); -#endif // IVAS_FLOAT_FIXED - void ham_cos_window_flt( float *fh, const int16_t n1, @@ -6957,21 +6833,6 @@ void enc_acelp_tcx_main( const int16_t vad_hover_flag /* i : VAD hangover flag */ ); -#ifdef IVAS_FLOAT_FIXED -void getTCXMode_ivas_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Decoder_State *st0, /* i : bitstream */ - const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ -); - -void getTCXWindowing_ivas_fx( - const Word16 core, /* i : current frame mode */ - const Word16 last_core, /* i : last frame mode */ - const Word16 element_mode, /* i : element mode */ - TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ - Decoder_State *st0 /* i : bitstream */ -); -#else void getTCXMode_ivas( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0, /* i : bitstream */ @@ -6985,7 +6846,7 @@ void getTCXWindowing_ivas( TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ Decoder_State *st0 /* i : bitstream */ ); -#endif +//#endif void getLPCparam_ivas( Decoder_State *st, /* i/o: decoder memory state */ @@ -7399,7 +7260,7 @@ void TNSAnalysis( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const float ltp_gain, /* i : ltp gain */ STnsData *pTnsData, /* o : TNS data */ - int16_t *pfUseTns, /* o : Flag indicating if TNS is used */ + int8_t *pfUseTns, /* o : Flag indicating if TNS is used */ float *predictionGain /* o : TNS prediction gain */ ); @@ -7417,7 +7278,7 @@ void ShapeSpectrum( const int16_t L_frame_glob, /* i : frame length */ int16_t L_spec, /* i : length of the spectrum */ float spectrum[], /* i/o: MDCT spectrum */ - const int16_t fUseTns, /* i : Flag indicating if TNS is used */ + const int8_t fUseTns, /* i : Flag indicating if TNS is used */ Encoder_State *st, /* i/o: encoder state structure */ float *scf /* i : scale factors */ ); @@ -7463,7 +7324,6 @@ void ACcontextMapping_encode2_no_mem_s17_LC( int16_t resQMaxBits, CONTEXT_HM_CONFIG *hm_cfg ); -#ifndef IVAS_FLOAT_FIXED int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ @@ -7472,7 +7332,6 @@ int16_t ACcontextMapping_decode2_no_mem_s17_LC_ivas( int16_t resQMaxBits, /* i : residual coding maximum bits */ CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration */ ); -#endif int16_t ACcontextMapping_encode2_estimate_no_mem_s17_LC( const int16_t *x, @@ -7492,7 +7351,6 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( const int16_t resQMaxBits, CONTEXT_HM_CONFIG *hm_cfg ); -#ifndef IVAS_FLOAT_FIXED int16_t RCcontextMapping_decode2_no_mem_s17_LCS( Decoder_State *st, /* i/o: decoder state */ int16_t *x, /* o : decoded spectrum */ @@ -7501,7 +7359,6 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS( const int16_t resQMaxBits, /* i : residual coding maximum bits */ CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration */ ); -#endif int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( int16_t *x, /* Spectral coefficients */ @@ -7673,12 +7530,12 @@ float SQ_gain_estimate( void tcx_scalar_quantization( - float *x, /* i : input coefficients */ - int16_t *xq, /* o : quantized coefficients */ - const int16_t L_frame, /* i : frame length */ - const float gain, /* i : quantization gain */ - const float offset, /* i : rounding offset (deadzone) */ - int16_t *memQuantZeros, /* o : coefficients set to 0 */ + float *x, /* i : input coefficients */ + int16_t *xq, /* o : quantized coefficients */ + const int16_t L_frame, /* i : frame length */ + const float gain, /* i : quantization gain */ + const float offset, /* i : rounding offset (deadzone) */ + int8_t *memQuantZeros, /* o : coefficients set to 0 */ const int16_t tcxonly ); int16_t tcx_scalar_quantization_rateloop( @@ -7687,7 +7544,7 @@ int16_t tcx_scalar_quantization_rateloop( const int16_t L_frame, /* i : frame length */ float *gain, /* i/o: quantization gain */ float offset, /* i : rounding offset (deadzone) */ - int16_t *memQuantZeros, /* o : coefficients set to 0 */ + int8_t *memQuantZeros, /* o : coefficients set to 0 */ int16_t *lastnz_out, /* i/o: last nonzero coeff index */ const int16_t target, /* i : target number of bits */ int16_t *nEncoded, /* o : number of encoded coeff */ @@ -7852,13 +7709,6 @@ int16_t ari_start_decoding_14bits_prm_ivas( int16_t bp, Tastat *s ); -#ifdef IVAS_FLOAT_FIXED -Word16 ari_start_decoding_14bits_prm_ivas_fx( - const Word16 *ptr, - Word16 bp, - Tastat *s ); -#endif - void ari_decode_14bits_s17_ext_ivas( Decoder_State *st, uint16_t *res, @@ -7889,7 +7739,7 @@ void powfp_odd2_evs( Word16 *pout2 /* Q15 */ ); -void tcx_arith_scale_envelope_flt( +void tcx_arith_scale_envelope_ivas( const Word16 L_spec_core, /* i : number of lines to scale Q0 */ Word16 L_frame, /* i : number of lines Q0 */ const Word32 env[], /* i : unscaled envelope Q16 */ @@ -7899,7 +7749,7 @@ void tcx_arith_scale_envelope_flt( Word16 *s_env_e /* o : scaled envelope exponent Q0 */ ); -void tcx_arith_render_envelope_flt( +void tcx_arith_render_envelope_ivas( const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ const Word16 L_frame, /* i : number of spectral lines */ const Word16 L_spec, /* i : length of the coded spectrum */ @@ -8898,21 +8748,6 @@ void generate_masking_noise( const int16_t nchan_out /* i : number of output channels */ ); -#ifdef IVAS_FLOAT_FIXED -void generate_masking_noise_ivas_fx( - Word32 *timeDomainBuffer, /* i/o: time-domain signal */ - Word16 *exp_out, /* o : time-domain signal exp */ - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const Word16 length, /* i : frame size */ - const Word16 core, /* i : core */ - const Word16 return_noise, /* i : noise is returned instead of added */ - const Word16 secondary, /* i : flag to indicate secondary noise generation */ - const Word16 element_mode, /* i : element mode */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 nchan_out /* i : number of output channels */ -); -#endif - void generate_masking_noise_update_seed( HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); @@ -8930,16 +8765,7 @@ void SynthesisSTFT_dirac_flt( const int16_t samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); -#ifdef IVAS_FLOAT_FIXED -void SynthesisSTFT_dirac_fx( - Word32 *fftBuffer, /* i : FFT bins */ - Word32 *timeDomainOutput, - Word32 *olapBuffer, - const Word16 *olapWin, - const Word16 samples_out, - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ -); -#endif + void generate_masking_noise_dirac( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ @@ -8961,19 +8787,6 @@ void generate_stereo_masking_noise( const int16_t nchan_out /* i : number of output channels */ ); -#ifdef IVAS_FLOAT_FIXED -void generate_stereo_masking_noise_fx( - Word16 *syn, /* i/o: time-domain signal */ - Word16 Q_syn, - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - const int16_t fadeOut, /* i : only fade out of previous state */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out /* i : number of output channels */ -); -#endif - void apply_scale_flt( float *scale, /* i : scale factor */ const int16_t bwidth, /* i : audio bandwidth */ @@ -9028,20 +8841,6 @@ void SynthesisSTFT_flt( const int16_t nchan_out /* i : number of output channels */ ); -#ifdef IVAS_FLOAT_FIXED -void SynthesisSTFT_fx( - Word32 *fftBuffer, /* i : FFT bins */ - Word16 Q_in, - Word32 *timeDomainOutput, - Word32 *olapBuffer, - const Word16 *olapWin, - const int16_t tcx_transition, - HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const int16_t element_mode, /* i : element mode */ - const int16_t nchan_out /* i : number of output channels */ -); -#endif - float rand_gauss_flt( float *x, int16_t *seed ); @@ -9100,12 +8899,6 @@ void FdCng_decodeSID( Decoder_State *st /* i/o: decoder state structure */ ); -#ifdef IVAS_FLOAT_FIXED -void FdCng_decodeSID_ivas_fx( - Decoder_State *st /* i/o: decoder state structure */ -); -#endif - void FdCng_exc_flt( HANDLE_FD_CNG_COM hFdCngCom, int16_t *CNG_mode, @@ -9347,6 +9140,11 @@ void configureCldfb_ivas( const int32_t sampling_rate /* i : sampling rate */ ); +void configureCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ + const int32_t sampling_rate /* i : sampling rate */ +); + void analysisCldfbEncoder_ivas( Encoder_State *st, /* i/o: encoder state structure */ const float *timeIn, @@ -9355,6 +9153,17 @@ void analysisCldfbEncoder_ivas( float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float *ppBuf_Ener ); +void analysisCldfbEncoder_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *timeIn, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + Word32 *ppBuf_Ener, + Word16 *enerBuffSum_exp, + CLDFB_SCALE_FACTOR *scale ); + ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -9362,24 +9171,21 @@ ivas_error openCldfb_ivas( CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); +ivas_error openCldfb_ivas_enc( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + const int32_t sampling_rate, /* i : sampling rate */ + CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ +); + void resampleCldfb_ivas( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const int32_t newSamplerate /* i : new samplerate to operate */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error cldfb_save_memory_ivas_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ -); -#endif // IVAS_FLOAT_FIXED ivas_error cldfb_save_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ); -#ifdef IVAS_FLOAT_FIXED -void cldfb_restore_memory_ivas_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ -); -#endif // IVAS_FLOAT_FIXED void cldfb_restore_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ @@ -9442,7 +9248,6 @@ ivas_error config_acelp1_IVAS( /*! r: ACELP16k flag */ -#ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ const int32_t element_brate, /* i : element bitrate */ @@ -9452,7 +9257,6 @@ int16_t set_ACELP_flag_IVAS( const int16_t bwidth, /* i : audio bandwidth */ const int16_t cng_type /* i : CNG type */ ); -#endif void FEC_clas_estim( const float *syn, @@ -9695,7 +9499,7 @@ void tcxInvertWindowGrouping_flt( float xn_buf[], float spectrum[], const int16_t L_frame, - const int16_t fUseTns, + const int8_t fUseTns, const int16_t last_core, const int16_t index, const int16_t frame_cnt, @@ -9910,14 +9714,12 @@ int16_t GetPLCModeDecision( Decoder_State *st /* i/o: decoder memory state pointer */ ); -#ifndef IVAS_FLOAT_FIXED void addBassPostFilter( const float *harm_timeIn, const int16_t samplesToProcess, float **rAnalysis, float **iAnalysis, HANDLE_CLDFB_FILTER_BANK cldfb ); -#endif ivas_error TonalMDCTConceal_Init_ivas( TonalMDCTConcealPtr hTonalMDCTConc, @@ -10107,15 +9909,11 @@ int16_t getRestrictedMode( int16_t getMdctWindowLength( const int16_t fscale ); -#ifdef IVAS_FLOAT_FIXED -Word16 sr2fscale( - const Word32 sr_core /* i : internal sampling rate */ -); -#else + int16_t sr2fscale( const int32_t sr_core /* i : internal sampling rate */ ); -#endif + int32_t getCoreSamplerateMode2_flt( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ @@ -10182,7 +9980,7 @@ void IGFEncApplyMono( float *pMDCTSpectrum, /* i/o: MDCT spectrum */ float *pPowerSpectrum, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ const int16_t isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const int16_t isTNSActive, /* i : flag indicating if the TNS is active */ + const int8_t isTNSActive, /* i : flag indicating if the TNS is active */ const int16_t sp_aud_decision0, /* i : first stage switching decision */ const int16_t vad_hover_flag /* i : VAD hangover flag */ ); @@ -10266,7 +10064,6 @@ void IGFDecReadData_flt( const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */ ); -#ifndef IVAS_FLOAT_FIXED /*! r: return igfAllZero flag indicating if no envelope is transmitted */ int16_t IGFDecReadLevel_flt( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Deccoder */ @@ -10274,7 +10071,6 @@ int16_t IGFDecReadLevel_flt( const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */ ); -#endif void IGFDecRestoreTCX10SubFrameData_flt( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o : instance handle of IGF Decoder */ @@ -10378,7 +10174,6 @@ void IGFSCFEncoderRestoreContextState( const int16_t igfGridIdx /* i : igf grid index see declaration of IGF_GRID_IDX for details */ ); -#ifndef IVAS_FLOAT_FIXED void IGFSCFDecoderOpen_ivas( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data */ H_IGF_INFO hIgfInfo, /* i : IGF info handle */ @@ -10386,15 +10181,11 @@ void IGFSCFDecoderOpen_ivas( const int16_t bwidth, const int16_t element_mode, const int16_t rf_mode ); -#endif -#ifndef IVAS_FLOAT_FIXED void IGFSCFDecoderReset_ivas( IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i : handle to public data or NULL in case there was no instance created */ ); -#endif -#ifndef IVAS_FLOAT_FIXED void IGFSCFDecoderDecode_ivas( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ Decoder_State *st, /* i/o: pointer to decoder state */ @@ -10403,7 +10194,6 @@ void IGFSCFDecoderDecode_ivas( const int16_t indepFlag /* i : if 1 on input the decoder will be forced to reset, if 0 on input the decoder will be forced to encode without a reset */ ); -#endif /*! r: offset value */ int16_t tbe_celp_exc_offset_flt( @@ -10450,3 +10240,5 @@ void init_tcx_cfg( const int16_t ini_frame, const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ); + +#endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx.h similarity index 90% rename from lib_com/prot_fx2.h rename to lib_com/prot_fx.h index 131a12285d012ee49e84671c2a3c4f3cbb9e3ee6..96d4354bd66c6b3eaee30170d01a7e2e5f46c9ed 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx.h @@ -36,23 +36,20 @@ * Prototypes of RAM counting tool macros *----------------------------------------------------------------------------------*/ -#ifdef RAM_COUNTING_TOOL -#define count_malloc( n1 ) MALLOC_FCT_CALL( n1 ) -#define count_calloc( n1, n2 ) CALLOC_FCT_CALL( n1, n2 ) -#define count_free( ptr ) FREE_FCT_CALL( ptr ) -#else -#define count_malloc( n1 ) malloc( n1 ) -#define count_calloc( n1, n2 ) calloc( n1, n2 ) -#define count_free( ptr ) free( ptr ) -#endif - -#define dynamic_malloc( n1 ) malloc( n1 ) -#define dynamic_calloc( n1, n2 ) calloc( n1, n2 ) -#define dynamic_free( n1 ) free( n1 ) - +#define MVR2R_WORD32( x, y, n ) Copy32( x, y, n ) +#define MVR2R_WORD16( x, y, n ) Copy( x, y, n ) + +#include +#include +#include +#include "options.h" +#include "typedef.h" +#include "cnst.h" +#include "stl.h" #include "ivas_cnst.h" #include "stat_enc.h" #include "stat_dec.h" +#include "ivas_stat_enc.h" #include "ivas_stat_dec.h" #include "ivas_error.h" #include "ivas_error_utils.h" @@ -60,7 +57,9 @@ #define TCX_IMDCT_SCALE 15 #define TCX_IMDCT_HEADROOM 1 +/*================================================================================*/ /* conversion functions: */ +/*================================================================================*/ // Float to Word32 Word32 float_to_fix( float number, Word32 Q ); @@ -123,6 +122,12 @@ Word16 L_get_q_buf( float *ptr_flt, Word16 length ); Word16 L_get_q_buf1( float *ptr_flt, Word16 length ); #endif +/*================================================================================*/ +/* conversion functions: */ +/*================================================================================*/ + +Word16 norm_ul( UWord32 UL_var1 ); + Word32 Mult_32_16( Word32 a, Word16 b ); @@ -144,6 +149,12 @@ void Vr_add( Word16 Len /* i : Vector lenght */ ); +void set8_fx( + Word8 y[], /* i/o: Vector to set */ + const Word8 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ +); + void set16_fx( Word16 y[], /* i/o: Vector to set */ const Word16 a, /* i : Value to set the vector to */ @@ -220,6 +231,14 @@ void deindex_lvq_SHB_fx( const Word16 nbits, const Word16 mode ); +Word16 deindex_lvq_ivas_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + Word16 sf_flag, /* i : safety net flag */ + Word16 no_bits /* i : number of bits for lattice */ +); + void permute_fx( Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ @@ -881,6 +900,13 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability const Word16 L_frame /* i : frame length */ ); +Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ +); + void reorder_isf_fx( Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ const Word16 min_dist, /* i : minimum required distance */ @@ -925,6 +951,17 @@ Word16 vq_dec_lvq_fx( Word16 *p_no_scales, Word16 *p_no_scales_p ); +Word16 vq_dec_lvq_ivas_fx( + Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + Word16 stages, /* i : Number of stages */ + Word16 N, /* i : Vector dimension */ + Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ + Word16 no_bits /* (i): no. bits for lattice */ +); +void a2rc_fx( const Word16 *a, Word16 *refl, Word16 lpcorder ); + Word16 vq_dec_lvq_ivas_fx( Word16 sf_flag, /* i : safety net flag */ Word16 x[], /* o : Decoded vector Q(x2.56)*/ @@ -2271,7 +2308,9 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 sigOut_fx[], /* o : decimated signal Q0 */ const Word32 fout, /* i : frequency of output Q0 */ Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, // TO be removed + Word16 *mem_decim_size // TO be removed ); Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ @@ -2364,7 +2403,7 @@ void lag_wind_32( ); // preemp_fx.c -#define preemph_fx( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) +#define PREEMPH_FX( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) void preemph_copy_fx( const Word16 x[], /* i : i signal Qx */ @@ -2734,7 +2773,7 @@ void ScaleShapedSHB_fx( Word16 prev_Q_bwe_syn2 ); void ScaleShapedSHB_32( - const int16_t length, /* i : SHB overlap length */ + const Word16 length, /* i : SHB overlap length */ Word32 *synSHB_fx, /* i/o: synthesized shb signal Qx */ Word32 *overlap_fx, /* i/o: buffer for overlap-add Qx */ const Word16 *subgain_fx, /* i : subframe gain Q15 */ @@ -5597,12 +5636,29 @@ Word32 dotp_fixed_o( const Word16 n, /* i : vector length */ const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */ Word16 *res_q ); + +Word32 dotp_fixed_32( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */ + Word16 *res_q /*stores resultant Q*/ +); + #ifdef IVAS_FLOAT_FIXED Word32 dotp_fixed_guarded( const Word32 x[], /* i : vector x[] */ const Word32 y[], /* i : vector y[] */ const Word16 n /* i : vector length */ ); + +Word32 dotp_me_fx( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + Word16 exp_x, + Word16 exp_y, + Word16 *exp_suma ); #endif void lsf_end_dec_fx( @@ -6350,6 +6406,16 @@ void lp_gain_updt_fx( Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ const Word16 L_frame /* i : length of the frame */ ); + +void lp_gain_updt_ivas_fx( + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ +); + Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ Word16 index, /* i : quantization index */ const Word16 bits, /* i : number of bits to quantize */ @@ -7004,6 +7070,16 @@ void generate_comfort_noise_dec_fx( const Word16 nchan_out /* i : number of output channels */ ); +void generate_comfort_noise_dec_ivas_fx( + Word32 **bufferReal, /* o : matrix to real part of i bands */ + Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ + Decoder_State *stdec, + Word16 *Q_new, + Word16 gen_exc, + const Word16 nchan_out /* i : number of output channels */ +); + void generate_comfort_noise_dec_hf_fx( Word32 **bufferReal, /* o : matrix to real part of i bands */ Word32 **bufferImag, /* o : matrix to imaginary part of i bands */ Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of i bands */ @@ -8885,6 +8961,14 @@ void delay_signal_fx( const Word16 delay /* i : delay in samples */ ); +void delay_signal_q_adj_fx( + Word32 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const Word16 delay, /* i : delay in samples */ + const Word16 q_x, + const Word16 q_mem ); + Word32 anint_fixed( Word32 x, /* i: Round to the nearest integer */ Word16 exp /* i: Exponent for round step */ @@ -9144,6 +9228,10 @@ Word32 sum2_f_16_fx( const Word16 *vec, /* i : input vector */ const Word16 lvec /* i : length of input vector */ ); +Word32 sum2_f_16_gb_fx( + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 gb ); Word16 vq_dec_lvq_ivas_fx( Word16 sf_flag, /* i : safety net flag */ @@ -9163,7 +9251,6 @@ Word16 deindex_lvq_ivas_fx( Word16 no_bits /* i : number of bits for lattice */ ); -#endif void deleteCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ @@ -9187,11 +9274,11 @@ void ivas_bw_switching_pre_proc_fx( Word16 Q, Word16 Q_audio ); -uint32_t mvl2s_r( +UWord32 mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q, - int16_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ + Word16 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ); void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, @@ -9221,3 +9308,832 @@ void ivas_mdct_core_reconstruct_fx( const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ Word16 q_x, Word16 e_sig ); + +void ari_start_encoding_14bits_ivas_fx( + Tastat *s ); + +void tcx_scalar_quantization_ivas_fx( + Word32 *x, /* i: input coefficients */ + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, /* i: quantization gain */ + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ + const Word16 alfe_flag ); + +Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS( + Word16 *x, /* Spectral coefficients */ + const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) */ + Word16 *lastnz_out, + Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */ + const Word16 target, /* Target bits */ + Word16 *stop, + Word16 mode, + CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ +); + +Word16 usdequant_fx( /* Qx*/ + const Word16 idx, /* i: quantizer index Q0*/ + const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ + const Word16 delta /* i: quantization step Qy*/ +); + +Word16 usquant_fx( /* o: index of the winning codeword */ + const Word16 x, /* i: scalar value to quantize Qx*/ + Word16 *xq, /* o: quantized value Qx*/ + const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ + const Word16 delta, /* i: quantization step Qx-1*/ + const Word16 cbsize /* i: codebook size */ +); + +Word32 Dot_product( /* o : Sum */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg /* i : vector length */ +); + +Word32 dotp_fx( /* o : dot product of x[] and y[] */ + const Word16 x[], /* i : vector x[] */ + const Word16 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ +); + +Word32 sum2_fx_mod( /* o : sum of all squared vector elements Q(2x+1)*/ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ +); + +void Copy_Scale_sig( + const Word16 x[], /* i : signal to scale i Qx */ + Word16 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + +void Scale_sig32( + Word32 x[], /* i/o: signal to scale Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + +void Copy_Scale_sig_16_32( + const Word16 x[], /* i : signal to scale i Qx */ + Word32 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + +void Copy_Scale_sig_16_32_no_sat( + const Word16 x[], /* i : signal to scale input Qx */ + Word32 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + +void Copy_Scale_sig_32_16( + const Word32 x[], /* i : signal to scale i Qx */ + Word16 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + +void Random_Fill( + Word16 *seed, /* i/o: random seed */ + Word16 n, /* i : number of values */ + Word16 *y, /* o : output values */ + Word16 scaling /* i : scaling of values */ +); + +Word16 mean_fx( /* o : mean of vector */ + const Word16 *vec_fx, /* i : i vector */ + const Word16 lvec_fx /* i : length of i vector */ +); + +void sort( + UWord16 *x, /* i/o: Vector to be sorted */ + UWord16 len /* i/o: vector length */ +); + +void sort_fx( + Word16 *r, /* i/o: Vector to be sorted in place */ + Word16 lo, /* i : Low limit of sorting range */ + Word16 up /* I : High limit of sorting range */ +); + +void sort_32_fx( + Word32 *r, /* i/o: Vector to be sorted in place */ + const Word16 lo, /* i : Low limit of sorting range */ + const Word16 up /* I : High limit of sorting range */ +); + +Word16 minimum_fx( /* o : index of the minimum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *min_fx /* o : minimum value in the input vector */ +); + +Word16 maximum_fx( /* o : index of the maximum value in the input vector */ + const Word16 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word16 *max_fx /* o : maximum value in the input vector */ +); + +Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +); + +Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +); + +Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max_val /* o : maximum value in the input vector */ +); + +Word16 maximum_abs_32_fx( /* o : index of the maximum value in the input vector */ + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max_val /* o : maximum value in the input vector */ +); + +/*! r: index of the maximum value in the input vector */ +Word16 maximum_s( + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *max /* o : maximum value in the input vector */ +); + +/*! r: index of the minimum value in the input vector */ +Word16 minimum_s( + const Word16 *vec, /* i : Input vector */ + const Word16 lvec, /* i : Vector length */ + Word16 *min_val /* o : minimum value in the input vector */ +); + +Word16 Exp16Array( + const Word16 n, /* (i): Array size */ + const Word16 *sx /* (i): Data array */ +); + +Word16 Exp32Array( + const Word16 n, /* (i): Array size */ + const Word32 *sx /* (i): Data array */ +); + +Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ +); + +Word32 sum32_sat( /* o : sum of all vector elements Qx*/ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ +); + +Word32 var_fx_32( /* o: variance of vector Qx+16*/ + const Word16 *x, /* i: input vector Qx*/ + const Word16 Qx, + const Word16 len /* i: length of inputvector */ +); + +Word16 var_fx( /* o: variance of vector Qx*/ + const Word16 *x, /* i: input vector Qx*/ + const Word16 Qx, + const Word16 len /* i: length of inputvector */ +); + +Word16 std_fx( /* o: standard deviation */ + const Word16 x[], /* i: input vector */ + const Word16 len /* i: length of the input vector */ +); + +Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ + const Word16 *x, /* i : vector x Q15 */ + const Word32 *A, /* i : matrix A Q0*/ + const Word16 m /* i : vector & matrix size */ + +); + +void Vr_subt( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ + Word16 N /* i : Vector lenght */ +); + +Word16 vquant_fx( /* o: index of the winning codevector */ + Word16 x[], /* i: vector to quantize Q13 */ + const Word16 x_mean[], /* i: vector mean to subtract (0 if none)Q13*/ + Word16 xq[], /* o: quantized vector Q13 */ + const Word16 cb[], /* i: codebook Q13 */ + const Word16 dim, /* i: dimension of codebook vectors */ + const Word16 cbsize /* i: codebook size */ +); + +Word16 w_vquant_fx( + Word16 x[], /* i: vector to quantize in Q10 */ + Word16 Qx, + const Word16 weights[], /* i: error weights in Q0 */ + Word16 xq[], /* o: quantized vector in Q15 */ + const Word16 cb[], /* i: codebook in Q15 */ + const Word16 cbsize, /* i: codebook size */ + const Word16 rev_vect /* i: reverse codebook vectors */ +); + +Word16 emaximum_fx( /* o : return index with max energy value in vector Q0 */ + const Word16 Qvec, /* i : Q of input vector Q0 */ + const Word16 *vec, /* i : input vector Qx */ + const Word16 lvec, /* i : length of input vector Q0 */ + Word32 *ener_max /* o : maximum energy value Q0 */ +); + +Word16 emaximum_32fx( /* o : return index with max energy value in vector Q0 */ + const Word16 Qvec, /* i : Q of input vector Q0 */ + const Word32 *vec, /* i : input vector Qx */ + const Word16 lvec, /* i : length of input vector Q0 */ + Word32 *ener_max /* o : maximum energy value Q0 */ +); + +Word32 Mean32( /* o : mean of the elements of the vector */ + const Word32 in[], /* i : input vector */ + const Word16 L /* i : length of input vector */ +); + +Word32 sum32_fx( /* o : sum of all vector elements Qx*/ + const Word32 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ +); + +Word16 sum16_fx( /* o : sum of all vector elements Qx*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ +); + +Word16 own_random2_fx( Word16 seed ); + +void iDiv_and_mod_32( + const Word32 Numer, /* i : 32 bits numerator */ + const Word16 Denom, /* i : 16 bits denominator */ + Word32 *Int_quotient, /* o : integer result of the division (int)(num/den) */ + Word32 *Int_mod, /* o : modulo result of the division num-((int)(num/den)*den)*/ + const Word16 rshift /* i : 0 if no right shift / 1 if the denom is right shifted by 1 */ +); + +void pz_filter_sp_fx( + const Word16 b[], + const Word16 a[], + Word16 x[], + Word16 y[], + Word16 buf[], + Word16 PNR, + Word16 PDR, + Word16 N, + Word16 Qa ); + +Word32 root_a_fx( + Word32 a, + Word16 Q_a, + Word16 *exp_out ); + +Word32 root_a_over_b_fx( + Word32 a, + Word16 Q_a, + Word32 b, + Word16 Q_b, + Word16 *exp_out ); + +void fir_fx( const Word16 x[], /* i : input vector Qx*/ + const Word16 h[], /* i : impulse response of the FIR filter Q12*/ + Word16 y[], /* o : output vector (result of filtering) Qx*/ + Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ + const Word16 L, /* i : input vector size */ + const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ + const Word16 upd /* i : 1 = update the memory, 0 = not */ + , + Word16 shift /* i : difference between Q15 and scaling of h[] */ +); +void v_add_32( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N /* i : Vector length */ +); + +void v_shr_32( + Word32 x1[], /* i : Input vector 1 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N, /* i : Vector length */ + Word16 shift /*shift value*/ +); + +void v_sub_32( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ +); + + +void v_add_16( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 N /* i : Vector length */ +); + +void v_sub_16( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ +); + + +Word16 squant_fx( /* o: index of the winning codeword */ + const Word16 x, /* i: scalar value to quantize */ + Word16 *xq, /* o: quantized value */ + const Word16 cb[], /* i: codebook */ + const Word16 cbsize /* i: codebook size */ +); + +void pz_filter_dp_fx( + const Word16 b[], + const Word16 a[], + Word16 x[], + Word16 y[], + Word32 buf[], + Word16 PNR, + Word16 PDR, + Word16 N, + Word16 Qa ); + +void Copy_Scale_sig32_16( + const Word32 *src, /* i : signal to scale Qx */ + Word16 *dst, /* o : scaled signal Qx */ + Word16 len, /* i : size of x[] Q0 */ + Word16 exp0 ); /* i : exponent: x = round(x << exp) Qx ?exp */ + +void v_multc_att( + const Word16 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word16 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +); + +void v_multc_att32( + const Word32 x[], /* i : Input vector Qx */ + const Word16 att, /* i : Constant Q15, <= MAX_16 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +); + +void v_multc_att3232( + const Word32 x[], /* i : Input vector Qx */ + const Word32 att, /* i : Constant Q32, <= MAX_32 */ + Word32 y[], /* o : Output vector that contains att*x */ + const Word16 N /* i : Vector length */ +); + +void v_L_mult_1616( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 N /* i : Vector length */ +); + +void v_L_mult_3216( + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 N /* i : Vector length */ +); + +void add_vec_fx( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 Qx1, /* i : SCaling of input 1 */ + const Word16 x2[], /* i : Input vector 2 */ + const Word16 Qx2, /* i : SCaling of input 1 */ + Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 Qy, /* i : SCaling of output 1 */ + const Word16 N /* i : Vector lenght */ +); + +Word32 Add_flt32_flt32( /* o: Result (Normalized) */ + Word32 a, /* i: 1st Value */ + Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ + Word32 b, /* i: 2nd Value */ + Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ + Word16 *exp_out /* o: Exponent of Result */ +); + +Word32 Mul_flt32_Q15( /* o: Result (Normalized) */ + Word32 value, /* i: Pseudo_float Value */ + Word16 *exp_v, /*i/o: Exponent of Value (Q of Value) */ + Word16 frac /* i: Q15 value */ +); + +Word32 Div_flt32_flt32( /* o: Result (Normalized) */ + Word32 a, /* i: 1st Value */ + Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ + Word32 b, /* i: 2nd Value */ + Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ + Word16 *exp_out /* o: Exponent of Result */ +); + +Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) */ + const Word16 *signal, /* i: Signal */ + Word16 signal_exp, /* i: Exponent of Signal (Q of Signal) */ + Word16 len, /* i: Frame Length */ + Word16 *energy_exp /* o: Exponent of Energy (Q of Energy) */ +); + +Word16 Find_Max_Norm16( const Word16 *src, Word16 len ); + +Word16 Find_Max_Norm32( const Word32 *src, Word16 len ); + +Word32 Sqrt_Ratio32( /* o: Result in Q31 */ + Word32 L_val1, /* i: Mantisa of Val1 */ + Word16 exp1, /* i: Exp of Val1 (>0: Val was Left Shifted, <0:Right Shifted) */ + Word32 L_val2, /* i: Mantisa of Val2 */ + Word16 exp2, /* i: Exp of Val2 (same as exp1) */ + Word16 *exp /* o: Exp of Result (# of 'L_shl' Req to get to Final Value) */ +); + +Word16 Invert16( /* result in Q'15 + 'exp' */ + Word16 val, + Word16 *exp ); + +Word16 find_rem( Word16 n, Word16 m, Word16 *r ); + +Word32 find_remd( Word32 n, Word32 m, Word32 *r ); + +Word16 rint_new_fx( + Word32 x /*Q16 */ +); + +Word16 erb_diff_search_fx( Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, Word16 *pow_spec, const Word16 *cb_fx, Word16 cb_size, Word16 cb_dim, Word16 offset ); + +void Acelp_dec_total_exc( + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + const Word16 gain_code16, /* i : Gain code Q0 */ + const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ + const Word16 i_subfr, /* i ; subfr */ + const Word16 *code_fx, /* i : code in Q9 */ + const Word16 L_subfr /* i : Subframne lenght */ +); + +UWord32 UL_inverse( const UWord32 UL_val, Word16 *exp ); + +UWord32 UL_div( const UWord32 UL_num, const UWord32 UL_den ); + +Word16 ratio( const Word32 numer, const Word32 denom, Word16 *expo ); + +void hp400_12k8_fx( + Word16 signal[], /* i/o: input signal / output is divided by 16 */ + const Word16 lg, /* i : lenght of signal */ + Word16 mem[] /* i/o: filter memory [6] */ +); + +Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ); + +void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size ); + +void floating_point_add( + Word32 *mx, /* io: mantissa of the addend Q31 */ + Word16 *ex, /* io: exponent of the addend Q0 */ + const Word32 my, /* i: mantissa of the adder Q31 */ + const Word16 ey /* i: exponent of the adder Q0 */ +); +/*delay_signal_fx is also present*/ +void delay_signal( + Word16 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word16 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ +); + +void delay_signal32( + Word32 x[], /* i/o: signal to be delayed */ + const Word16 len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const Word16 delay /* i : delay in samples */ +); + +Word16 lin_interp_fx( + const Word16 x, /* i : the value to be mapped */ + const Word16 x1, /* i : source range interval: low end */ + const Word16 y1, /* i : source range interval: high end */ + const Word16 x2, /* i : target range interval: low */ + const Word16 y2, /* i : target range interval: high */ + const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ +); + +Word16 ceil_log_2( UWord64 val ); + +Word32 imax_pos_fx( + const Word32 *y /* i : Input vector for peak interpolation */ +); + +void msvq_dec_fx( + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ + const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 maxN, /* i : Codebook dimension */ + const Word16 Idx[], /* i : Indices */ + const Word16 applyIDCT_flag, /* i : applyIDCT flag */ + const Word32 *invTrfMatrix, /* i : synthesis matrix */ + Word32 *uq, /* o : quantized vector */ + Word16 *uq_ind, /* o : quantized vector (fixed point) */ + Word16 exp ); + +void dec_FDCNG_MSVQ_stage1_fx( + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ +); + +void dctT2_N_apply_matrix_fx( + const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain */ + Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain */ + const Word16 dct_dim, /* i : dct processing dim possibly truncated */ + const Word16 fdcngvq_dim, /* i : fdcng domain length */ + const Word32 *matrix, /* i : IDCT matrix */ + const Word16 matrix_row_dim, /* i : */ + const DCTTYPE dcttype /* i : matrix operation type */ +); + +Word32 sum2_f_32_fx( + const Word32 *vec, /* i : input vector */ + const int16_t lvec, /* i : length of input vector */ + Word16 gb ); + +Word32 sum2_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ); + +void v_mult_fixed( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 N /* i : Vector length */ +); + +void v_sub_s16_fx( + const Word16 x1[], /* i : Input vector 1 */ + const Word16 x2[], /* i : Input vector 2 */ + Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ +); + +void v_sub32_fx( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N /* i : Vector length */ +); + +void ivas_swb_tbe_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Word16 Q_exc, + const Word16 voice_factors_fx[], /* i : voicing factors */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *pitch_buf_fx, + Word16 *Q_white_exc ); + +Word16 swb_bwe_dec_fx32( + Decoder_State *st, /* i/o: decoder state structure */ + Word32 output[], /* i : synthesis @internal Fs Q11 */ + Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ + Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ +); + +ivas_error acelp_core_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 output[], /* o : synthesis @internal Fs */ + Word16 synth[], /* o : synthesis */ + Word16 save_hb_synth[], /* o : HB synthesis */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + Word16 *voice_factors, /* o : voicing factors */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + const int16_t sharpFlag, /* i : formant sharpening flag */ + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + int16_t *unbits, /* o : number of unused bits */ + int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t last_element_brate, /* i : last element bitrate */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + const int16_t nchan_out, /* i : number of output channels */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const int16_t read_sid_info /* i : read SID info flag */ +); + +void destroy_cldfb_decoder_ivas_fx( + Decoder_State *st /* o : Decoder static variables structure */ +); + +void wtda_fx32( + const Word32 *new_audio, /* i : input audio Q11 */ + Word32 *wtda_audio, /* o : windowed audio Q11 */ + Word32 *old_wtda, /* i/o: windowed audio from previous frame Q11 */ + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ +); + +ivas_error core_switching_pre_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 last_element_mode, /* i : last_element_mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + Word16 Q_old_synthFB, + Word16 *Q_olapBufferSynth, + Word16 *Q_olapBufferSynth2 ); + +void hp20_fix32( + Word32 signal_fx[], + const Word16 lg, + Word32 mem_fx[], + const Word32 Fs ); + +void getTCXMode_ivas_fx( + Decoder_State *st, /* i/o: decoder memory state */ + Decoder_State *st0, /* i : bitstream */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ +); + +void getTCXWindowing_ivas_fx( + const Word16 core, /* i : current frame mode */ + const Word16 last_core, /* i : last frame mode */ + const Word16 element_mode, /* i : element mode */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ + Decoder_State *st0 /* i : bitstream */ +); + +Word16 ari_start_decoding_14bits_prm_ivas_fx( + const Word16 *ptr, + Word16 bp, + Tastat *s ); + +void generate_masking_noise_ivas_fx( + Word32 *timeDomainBuffer, /* i/o: time-domain signal */ + Word16 *exp_out, /* o : time-domain signal exp */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const Word16 length, /* i : frame size */ + const Word16 core, /* i : core */ + const Word16 return_noise, /* i : noise is returned instead of added */ + const Word16 secondary, /* i : flag to indicate secondary noise generation */ + const Word16 element_mode, /* i : element mode */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ + const Word16 nchan_out /* i : number of output channels */ +); + +void SynthesisSTFT_dirac_fx( + Word32 *fftBuffer, /* i : FFT bins */ + Word32 *timeDomainOutput, + Word32 *olapBuffer, + const Word16 *olapWin, + const Word16 samples_out, + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void generate_stereo_masking_noise_fx( + Word16 *syn, /* i/o: time-domain signal */ + Word16 Q_syn, + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + const int16_t fadeOut, /* i : only fade out of previous state */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const int16_t nchan_out /* i : number of output channels */ +); + +void SynthesisSTFT_fx( + Word32 *fftBuffer, /* i : FFT bins */ + Word32 *timeDomainOutput, + Word32 *olapBuffer, + const Word16 *olapWin, + const int16_t tcx_transition, + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const int16_t element_mode, /* i : element mode */ + const int16_t nchan_out /* i : number of output channels */ +); + +void FdCng_decodeSID_ivas_fx( + Decoder_State *st /* i/o: decoder state structure */ +); + +void cldfb_restore_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +); + +ivas_error cldfb_save_memory_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ +); + +void ordr_esti( + const Word16 k, /* i : sub-vector index */ + Word16 *Mpos, /* i/o: dominant sub-vector position from ACV */ + Word16 svOrder[], /* i/o: AVQ sub-vector order */ + const Word16 Nsv /* i : total sub-vectors in a sub-frames */ +); + +Word16 sr2fscale( + const Word32 sr_core /* i : internal sampling rate */ +); + +// pre_proc functions +/*full implementation pending*/ +void swb_pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + float *new_swb_speech, /* o : original input signal at 32kHz */ + Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz */ + float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer */ + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +); + +// tools.c +Word32 sum2_f_32_fx( /* o : Q(2x - 31 - gb) */ + const Word32 *vec, /* i : input vector, Qx */ + const Word16 lvec, /* i : length of input vector */ + Word16 gb /* i : guard bits */ +); + +Word32 sum2_32_exp_fx( + const Word32 *vec, /* i : input vector, Qx */ + const Word16 lvec, /* i : length of input vector */ + Word16 *exp, /* i/o: exponent of vector */ + Word16 gb /* i : guard bits */ +); + +Word32 sum2_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ); +#ifdef IVAS_FLOAT_FIXED +void ProcessStereoIGF_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ +#if 1 + Word32 *pITFMDCTSpectrum_fx[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ +#endif + float *pITFMDCTSpectrum[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ + float *pPowerSpectrum[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + float *pPowerSpectrumMsInv[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const int16_t frameno, /* i : flag indicating index of current subfr. */ + const int16_t sp_aud_decision0, /* i : sp_aud_decision0 */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ +); +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 */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on /* i : flag mct block (1) or stereo (0) */ +); + +#endif // IVAS_FLOAT_FIXED + +#endif diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h deleted file mode 100644 index d560a67a78f86c39ace4866f0d241f6045bf6cb1..0000000000000000000000000000000000000000 --- a/lib_com/prot_fx1.h +++ /dev/null @@ -1,630 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 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. - -*******************************************************************************************************/ - -#ifndef PROT_FX1_H -#define PROT_FX1_H - -#include -#include -#include -#include "options.h" -#include "typedef.h" -#include "cnst.h" -#include "stl.h" -#define mvr2r_Word32( x, y, n ) Copy32( x, y, n ) -#define mvr2r_Word16( x, y, n ) Copy( x, y, n ) - -int16_t norm_ul( uint32_t UL_var1 ); -Word16 usdequant_fx( /* Qx*/ - const Word16 idx, /* i: quantizer index Q0*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta /* i: quantization step Qy*/ -); - -Word16 usquant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize Qx*/ - Word16 *xq, /* o: quantized value Qx*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta, /* i: quantization step Qx-1*/ - const Word16 cbsize /* i: codebook size */ -); - -Word32 Dot_product( /* o : Sum */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg /* i : vector length */ -); - -Word32 dotp_fx( /* o : dot product of x[] and y[] */ - const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n, /* i : vector length */ - Word16 *exp /* (o) : exponent of result (0..+30) */ -); - -Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : i vector Qx*/ - const Word16 lvec /* i : length of i vector */ -); - -Word32 sum2_fx_mod( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : i vector Qx*/ - const Word16 lvec /* i : length of i vector */ -); - -void Copy( - const Word16 x[], /* i : i vector */ - Word16 y[], /* o : output vector */ - const Word16 L /* i : vector length */ -); - -void Copy32( - const Word32 x[], /* i : i vector */ - Word32 y[], /* o : output vector */ - const Word16 L /* i : vector length */ -); - -void set16_fx( - Word16 y[], /* i/o: Vector to set */ - const Word16 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ -); - -void set32_fx( - Word32 y[], /* i/o: Vector to set */ - const Word32 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ -); - -void Copy_Scale_sig( - const Word16 x[], /* i : signal to scale i Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig_16_32( - const Word16 x[], /* i : signal to scale i Qx */ - Word32 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig_16_32_no_sat( - const Word16 x[], /* i : signal to scale input Qx */ - Word32 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig_32_16( - const Word32 x[], /* i : signal to scale i Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Random_Fill( - Word16 *seed, /* i/o: random seed */ - Word16 n, /* i : number of values */ - Word16 *y, /* o : output values */ - Word16 scaling /* i : scaling of values */ -); - -void Scale_sig( - Word16 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -Word16 mean_fx( /* o : mean of vector */ - const Word16 *vec_fx, /* i : i vector */ - const Word16 lvec_fx /* i : length of i vector */ -); - -void Vr_add( - const Word16 *in1, /* i : Input vector 1 */ - const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ -); -void sort_fx( - Word16 *r, /* i/o: Vector to be sorted in place */ - Word16 lo, /* i : Low limit of sorting range */ - Word16 up /* I : High limit of sorting range */ -); -void sort_32_fx( - Word32 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ -); -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ -); -Word16 maximum_fx( /* o : index of the maximum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *max_fx /* o : maximum value in the input vector */ -); -Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ -); -Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ -); -Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max_val /* o : maximum value in the input vector */ -); -Word16 maximum_abs_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max_val /* o : maximum value in the input vector */ -); -#ifdef IVAS_FLOAT_FIXED -/*! r: index of the maximum value in the input vector */ -Word16 maximum_s( - const Word16 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word16 *max /* o : maximum value in the input vector */ -); - -/*! r: index of the minimum value in the input vector */ -Word16 minimum_s( - const Word16 *vec, /* i : Input vector */ - const Word16 lvec, /* i : Vector length */ - Word16 *min_val /* o : minimum value in the input vector */ -); -#endif -Word16 Exp16Array( - const Word16 n, /* (i): Array size */ - const Word16 *sx /* (i): Data array */ -); -Word16 Exp32Array( - const Word16 n, /* (i): Array size */ - const Word32 *sx /* (i): Data array */ -); -Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); -Word32 sum32_sat( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); -Word32 var_fx_32( /* o: variance of vector Qx+16*/ - const Word16 *x, /* i: input vector Qx*/ - const Word16 Qx, - const Word16 len /* i: length of inputvector */ -); -Word16 var_fx( /* o: variance of vector Qx*/ - const Word16 *x, /* i: input vector Qx*/ - const Word16 Qx, - const Word16 len /* i: length of inputvector */ -); -Word16 std_fx( /* o: standard deviation */ - const Word16 x[], /* i: input vector */ - const Word16 len /* i: length of the input vector */ -); -Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ - const Word16 *x, /* i : vector x Q15 */ - const Word32 *A, /* i : matrix A Q0*/ - const Word16 m /* i : vector & matrix size */ - -); -void Vr_subt( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - Word16 N /* i : Vector lenght */ -); -Word16 vquant_fx( /* o: index of the winning codevector */ - Word16 x[], /* i: vector to quantize Q13 */ - const Word16 x_mean[], /* i: vector mean to subtract (0 if none)Q13*/ - Word16 xq[], /* o: quantized vector Q13 */ - const Word16 cb[], /* i: codebook Q13 */ - const Word16 dim, /* i: dimension of codebook vectors */ - const Word16 cbsize /* i: codebook size */ -); -Word16 w_vquant_fx( - Word16 x[], /* i: vector to quantize in Q10 */ - Word16 Qx, - const Word16 weights[], /* i: error weights in Q0 */ - Word16 xq[], /* o: quantized vector in Q15 */ - const Word16 cb[], /* i: codebook in Q15 */ - const Word16 cbsize, /* i: codebook size */ - const Word16 rev_vect /* i: reverse codebook vectors */ -); -Word16 emaximum_fx( /* o : return index with max energy value in vector Q0 */ - const Word16 Qvec, /* i : Q of input vector Q0 */ - const Word16 *vec, /* i : input vector Qx */ - const Word16 lvec, /* i : length of input vector Q0 */ - Word32 *ener_max /* o : maximum energy value Q0 */ -); -Word16 emaximum_32fx( /* o : return index with max energy value in vector Q0 */ - const Word16 Qvec, /* i : Q of input vector Q0 */ - const Word32 *vec, /* i : input vector Qx */ - const Word16 lvec, /* i : length of input vector Q0 */ - Word32 *ener_max /* o : maximum energy value Q0 */ -); -Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ -); -Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); -Word16 sum16_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); -Word16 Random( /* o : output random value */ - Word16 *seed /* i/o: random seed */ -); -Word16 own_random2_fx( Word16 seed ); -void iDiv_and_mod_32( - const Word32 Numer, /* i : 32 bits numerator */ - const Word16 Denom, /* i : 16 bits denominator */ - Word32 *Int_quotient, /* o : integer result of the division (int)(num/den) */ - Word32 *Int_mod, /* o : modulo result of the division num-((int)(num/den)*den)*/ - const Word16 rshift /* i : 0 if no right shift / 1 if the denom is right shifted by 1 */ -); -void pz_filter_sp_fx( - const Word16 b[], - const Word16 a[], - Word16 x[], - Word16 y[], - Word16 buf[], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa ); -Word32 root_a_fx( - Word32 a, - Word16 Q_a, - Word16 *exp_out ); -Word32 root_a_over_b_fx( - Word32 a, - Word16 Q_a, - Word32 b, - Word16 Q_b, - Word16 *exp_out ); -void fir_fx( const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ - , - Word16 shift /* i : difference between Q15 and scaling of h[] */ -); - -void fir_fx( const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ - , - Word16 shift /* i : difference between Q15 and scaling of h[] */ -); - -void v_add_32( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N /* i : Vector length */ -); - -void v_shr_32( - Word32 x1[], /* i : Input vector 1 */ - Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N, /* i : Vector length */ - Word16 shift /*shift value*/ -); - -void v_sub_32( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ -); - - -void v_add_16( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 N /* i : Vector length */ -); - -void v_sub_16( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N /* i : Vector length */ -); - - -Word16 squant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize */ - Word16 *xq, /* o: quantized value */ - const Word16 cb[], /* i: codebook */ - const Word16 cbsize /* i: codebook size */ -); -void pz_filter_dp_fx( - const Word16 b[], - const Word16 a[], - Word16 x[], - Word16 y[], - Word32 buf[], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa ); -void Copy_Scale_sig32_16( - const Word32 *src, /* i : signal to scale Qx */ - Word16 *dst, /* o : scaled signal Qx */ - Word16 len, /* i : size of x[] Q0 */ - Word16 exp0 ); /* i : exponent: x = round(x << exp) Qx ?exp */ - -void v_multc_att( - const Word16 x[], /* i : Input vector Qx */ - const Word16 att, /* i : Constant Q15, <= MAX_16 */ - Word16 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ -); -void v_multc_att32( - const Word32 x[], /* i : Input vector Qx */ - const Word16 att, /* i : Constant Q15, <= MAX_16 */ - Word32 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ -); -void v_multc_att3232( - const Word32 x[], /* i : Input vector Qx */ - const Word32 att, /* i : Constant Q32, <= MAX_32 */ - Word32 y[], /* o : Output vector that contains att*x */ - const Word16 N /* i : Vector length */ -); -void v_L_mult_1616( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ -); -void v_L_mult_3216( - const Word32 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ -); -void add_vec_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 Qx1, /* i : SCaling of input 1 */ - const Word16 x2[], /* i : Input vector 2 */ - const Word16 Qx2, /* i : SCaling of input 1 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 Qy, /* i : SCaling of output 1 */ - const Word16 N /* i : Vector lenght */ -); -Word32 Add_flt32_flt32( /* o: Result (Normalized) */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ -); -Word32 Mul_flt32_Q15( /* o: Result (Normalized) */ - Word32 value, /* i: Pseudo_float Value */ - Word16 *exp_v, /*i/o: Exponent of Value (Q of Value) */ - Word16 frac /* i: Q15 value */ -); -Word32 Div_flt32_flt32( /* o: Result (Normalized) */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ -); -Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) */ - const Word16 *signal, /* i: Signal */ - Word16 signal_exp, /* i: Exponent of Signal (Q of Signal) */ - Word16 len, /* i: Frame Length */ - Word16 *energy_exp /* o: Exponent of Energy (Q of Energy) */ -); -Word16 Find_Max_Norm16( const Word16 *src, Word16 len ); - -Word16 Find_Max_Norm32( const Word32 *src, Word16 len ); - -Word32 Sqrt_Ratio32( /* o: Result in Q31 */ - Word32 L_val1, /* i: Mantisa of Val1 */ - Word16 exp1, /* i: Exp of Val1 (>0: Val was Left Shifted, <0:Right Shifted) */ - Word32 L_val2, /* i: Mantisa of Val2 */ - Word16 exp2, /* i: Exp of Val2 (same as exp1) */ - Word16 *exp /* o: Exp of Result (# of 'L_shl' Req to get to Final Value) */ -); - -Word16 Invert16( /* result in Q'15 + 'exp' */ - Word16 val, - Word16 *exp ); - -Word16 find_rem( Word16 n, Word16 m, Word16 *r ); -Word32 find_remd( Word32 n, Word32 m, Word32 *r ); - -Word16 rint_new_fx( - Word32 x /*Q16 */ -); - -Word16 erb_diff_search_fx( Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, Word16 *pow_spec, const Word16 *cb_fx, Word16 cb_size, Word16 cb_dim, Word16 offset ); - -void Acelp_dec_total_exc( - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - const Word16 gain_code16, /* i : Gain code Q0 */ - const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ - const Word16 i_subfr, /* i ; subfr */ - const Word16 *code_fx, /* i : code in Q9 */ - const Word16 L_subfr /* i : Subframne lenght */ -); - -UWord32 UL_inverse( const UWord32 UL_val, Word16 *exp ); - -UWord32 UL_div( const UWord32 UL_num, const UWord32 UL_den ); - -Word16 ratio( const Word32 numer, const Word32 denom, Word16 *expo ); - -void hp400_12k8_fx( - Word16 signal[], /* i/o: input signal / output is divided by 16 */ - const Word16 lg, /* i : lenght of signal */ - Word16 mem[] /* i/o: filter memory [6] */ -); - -#if 0 -void hp400_12k8_ivas_fx( - Word16 signal[], /* i/o: input signal / output is divided by 16 */ - const Word16 lg, /* i : lenght of signal */ - Word16 mem[] /* i/o: filter memory [6] */ -); -#endif -Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ); - -void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size ); - -void floating_point_add( - Word32 *mx, /* io: mantissa of the addend Q31 */ - Word16 *ex, /* io: exponent of the addend Q0 */ - const Word32 my, /* i: mantissa of the adder Q31 */ - const Word16 ey /* i: exponent of the adder Q0 */ -); - - -#ifdef IVAS_FLOAT_FIXED -void fft_fx( - Word32 *re, /* i/o: real part */ - Word32 *im, /* i/o: imag part */ - const Word16 length, /* i : length of fft */ - const Word16 s /* i : sign */ -); - -#endif -void delay_signal( - Word16 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word16 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ -); - -void delay_signal32( - Word32 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ - const Word16 delay /* i : delay in samples */ -); - -Word16 lin_interp_fx( - const Word16 x, /* i : the value to be mapped */ - const Word16 x1, /* i : source range interval: low end */ - const Word16 y1, /* i : source range interval: high end */ - const Word16 x2, /* i : target range interval: low */ - const Word16 y2, /* i : target range interval: high */ - const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ -); - -Word16 ceil_log_2( UWord64 val ); - -Word32 imax_pos_fx( - const Word32 *y /* i : Input vector for peak interpolation */ -); - -#ifdef IVAS_FLOAT_FIXED -void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ -); - -void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ -); - -void msvq_dec_fx( - const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - const Word16 applyIDCT_flag, /* i : applyIDCT flag */ - const Word32 *invTrfMatrix, /* i : synthesis matrix */ - Word32 *uq, /* o : quantized vector */ - Word16 *uq_ind, /* o : quantized vector (fixed point) */ - Word16 exp ); - -void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ -); - -void dctT2_N_apply_matrix_fx( - const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain */ - Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain */ - const Word16 dct_dim, /* i : dct processing dim possibly truncated */ - const Word16 fdcngvq_dim, /* i : fdcng domain length */ - const Word32 *matrix, /* i : IDCT matrix */ - const Word16 matrix_row_dim, /* i : */ - const DCTTYPE dcttype /* i : matrix operation type */ -); - -#endif -#endif diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 2a7e9a8ecdabb3544f45d50353e2d5688ca32780..23c42119bc8bef6c19e295fa0e4eff816d51db35 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ /*! r: Approximate integer division for positive input using lookup table */ UWord32 intLimCDivPos_fx( diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c index 0b46d73359df1e3dd8f21d53ad9c87138e1ba06f..22a7fb8eaf75a13955baba8ca1a0b919f223614c 100644 --- a/lib_com/range_com_fx.c +++ b/lib_com/range_com_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_com/re8_ppv_fx.c b/lib_com/re8_ppv_fx.c index a786f99362ad656953fb2128d5e1ddd84c4977c0..f330f22c2070006ab76240ea118b83e868c1ce10 100644 --- a/lib_com/re8_ppv_fx.c +++ b/lib_com/re8_ppv_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" /*-------------------------------------------------------------------* diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index db58c3fae5da1da710b78215498462ac6771703b..00909e2f5b6a48602dc439213ba30568fb7b4a19 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_com/recovernorm_fx.c b/lib_com/recovernorm_fx.c index e5b72fc51010adc4f8b23990074a364c12b52c4c..a61e1f1839391144f9e9611ab813593c6c953260 100644 --- a/lib_com/recovernorm_fx.c +++ b/lib_com/recovernorm_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ /*--------------------------------------------------------------------------* * recovernorm_fx() diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c index a26480626f0b2419b49dd9c2debfa067261250dd..07bc21bc836e768a71efb553917fdb12828158ca 100644 --- a/lib_com/reordvct_fx.c +++ b/lib_com/reordvct_fx.c @@ -31,8 +31,8 @@ *******************************************************************************************************/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ /*--------------------------------------------------------------------------* diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 5849fb815170fe1b578122ca7d45949294559351..e06ef40eae5ed94fecd78ecca9673fc1e3dfec09 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------------* * Residu3_lc_fx: diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 22589b96f2965fb423f85bd3e09cba7d58ccd649..8bc681806d99d042251973bbbb5a46c9b233bc72 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -41,7 +41,7 @@ #include "prot.h" #include "basop_util.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /* clang-format off */ @@ -2627,9 +2627,21 @@ const float interpol_frac2_mid[NB_SUBFR*3] = { 0.0f, 0.25f, 0.75f }; +const Word16 interpol_frac2_mid_fx[NB_SUBFR * 3] = { + 8191, 24575, 0, + 8191, 24575, 0, + 0, 8191, 24575, + 0, 8191, 24575 +}; + const float interpol_frac_12k8[NB_SUBFR] = { 0.25f, 0.5f, 0.75f, 1.0f }; + +const Word16 interpol_frac_12k8_fx[NB_SUBFR] = { + 8191, 16383, 24575, 32767 +}; + const Word16 interpol_frac_fx[NB_SUBFR] = { 8192, 16384, 24576,32767 }; const float interpol_isp_amr_wb[NB_SUBFR] = { @@ -10093,6 +10105,512 @@ const Word16 CLDFB80_60[] = W16(0x0002), W16(0x0020), W16(0xff00), W16(0xe05e), W16(0x00a9) }; +const Word16 CLDFB80_30[] = +{ + 0, -5, -30, 278, 8546, + 0, -4, -33, 306, 9141, + 0, -2, -29, 334, 9735, + 0, -1, -17, 363, 10324, + 0, -1, -13, 397, 10904, + 0, -1, -9, 435, 11474, + 0, -1, -2, 478, 12028, + 0, 0, 6, 525, 12566, + 0, 0, 12, 578, 13083, + 0, 0, 19, 637, 13579, + 0, 0, 26, 701, 14050, + 0, 0, 28, 771, 14493, + 0, 0, 30, 846, 14906, + 0, 0, 28, 927, 15285, + 0, 0, 4, 1012, 15630, + 0, -1, 27, 1105, 15937, + 0, -1, 26, 1201, 16209, + 0, 0, 29, 1299, 16442, + 0, 1, 31, 1399, 16638, + 0, 0, 36, 1498, 16794, + 0, 0, 41, 1594, 16911, + 0, -1, 45, 1687, 16990, + 0, 0, 46, 1774, 17036, + 0, 0, 49, 1853, 17052, + 0, 0, 50, 1922, 17040, + 0, 0, 50, 1981, 16999, + 0, 0, 45, 2027, 16924, + 0, -1, 39, 2061, 16809, + 0, -4, 27, 2080, 16651, + 0, -10, 12, 2084, 16463, + 0, -17, -10, 2075, 16161, + 0, -16, -23, 2054, 15746, + 0, -10, -31, 2012, 15307, + 0, -4, -32, 1949, 14834, + 0, -2, -26, 1862, 14334, + 0, -3, -15, 1752, 13816, + 0, -2, -1, 1616, 13288, + 0, 0, 13, 1454, 12753, + 0, -1, 25, 1267, 12212, + 0, 0, 35, 1054, 11663, + 0, 0, 42, 815, 11104, + 0, 1, 45, 552, 10536, + 0, -2, 42, 263, 9960, + 0, -3, 37, -51, 9379, + 0, 9, 33, -391, 8795, + 0, -12, 25, -755, 8207, + 0, 3, 4, -1144, 7616, + 0, 2, -14, -1557, 7022, + 0, -2, -34, -1992, 6427, + 0, 0, -54, -2449, 5833, + 0, 1, -73, -2927, 5244, + 0, 1, -90, -3425, 4659, + 0, 0, -107, -3942, 4072, + 0, 1, -123, -4476, 3479, + 0, 1, -139, -5026, 2877, + 0, -1, -156, -5590, 2272, + 0, 0, -176, -6167, 1684, + 0, 6, -199, -6754, 1144, + 0, 18, -223, -7348, 682, + 0, 32, -249, -7947, 282 +}; + +const Word16 LDQMF_10_enc_fx[] = +{ + 2, -21, 79, -1890, 8640, + 1, -35, -5, -3186, 7299, + -1, -49, -126, -4597, 5995, + -3, -62, -285, -6085, 4767, + -5, -74, -484, -7607, 3646, + -6, -84, -721, -9114, 2656, + -7, -92, -989, -10557, 1815, + -7, -99, -1279, -11885, 1125, + -8, -104, -1579, -13052, 583, + -10, -108, -1869, -14017, 175, + -15, -112, -2129, -14742, -104, + -21, -117, -2336, -15204, -267, + -27, -123, -2462, -15389, -354, + -31, -132, -2482, -15293, -380, + -33, -144, -2370, -14926, -359, + -32, -156, -2104, -14306, -304, + -27, -166, -1668, -13461, -230, + -18, -169, -1049, -12429, -152, + -7, -160, -246, -11250, -82, + 6, -132, 739, -9972, -31 +}; + +const Word16 LDQMF_16_enc_fx[] = +{ + 2, -18, 91, -1662, 8892, + 2, -27, 46, -2441, 8051, + 1, -36, -12, -3271, 7216, + 0, -45, -84, -4146, 6396, + -2, -53, -171, -5056, 5602, + -3, -61, -274, -5991, 4841, + -5, -69, -392, -6940, 4121, + -6, -76, -526, -7892, 3449, + -6, -82, -674, -8835, 2831, + -7, -88, -835, -9756, 2270, + -7, -93, -1007, -10643, 1767, + -7, -97, -1187, -11485, 1324, + -7, -101, -1373, -12269, 941, + -8, -104, -1560, -12985, 613, + -9, -106, -1744, -13622, 338, + -11, -109, -1921, -14172, 111, + -14, -111, -2084, -14626, -64, + -17, -114, -2228, -14977, -185, + -21, -117, -2346, -15223, -274, + -25, -121, -2433, -15361, -334, + -28, -126, -2481, -15389, -368, + -31, -132, -2484, -15307, -380, + -33, -139, -2436, -15119, -373, + -33, -146, -2332, -14828, -350, + -32, -154, -2167, -14440, -316, + -30, -161, -1935, -13962, -273, + -26, -166, -1635, -13402, -225, + -21, -169, -1263, -12769, -176, + -15, -168, -818, -12074, -128, + -8, -161, -301, -11328, -86, + 0, -147, 286, -10541, -50, + 9, -124, 942, -9725, -23 +}; + +const Word16 LDQMF_20_enc_fx[] = +{ + 2, -17, 95, -1588, 8976, + 2, -24, 61, -2202, 8303, + 1, -32, 19, -2850, 7632, + 1, -39, -32, -3530, 6968, + 0, -46, -92, -4236, 6316, + -2, -53, -162, -4964, 5680, + -3, -59, -241, -5708, 5065, + -4, -65, -331, -6464, 4475, + -5, -71, -431, -7226, 3914, + -6, -76, -540, -7987, 3385, + -6, -81, -658, -8741, 2890, + -7, -86, -785, -9482, 2432, + -7, -90, -919, -10205, 2011, + -7, -94, -1060, -10901, 1628, + -7, -97, -1205, -11566, 1283, + -7, -100, -1354, -12194, 976, + -7, -103, -1504, -12778, 706, + -8, -105, -1653, -13314, 470, + -9, -107, -1798, -13797, 266, + -11, -109, -1938, -14222, 90, + -14, -111, -2068, -14585, -49, + -16, -113, -2187, -14883, -153, + -19, -115, -2290, -15114, -234, + -22, -118, -2376, -15276, -295, + -25, -121, -2439, -15369, -338, + -28, -125, -2478, -15391, -365, + -30, -130, -2488, -15343, -378, + -32, -135, -2467, -15226, -378, + -33, -141, -2411, -15042, -368, + -33, -147, -2319, -14794, -347, + -32, -153, -2186, -14483, -320, + -31, -159, -2012, -14114, -286, + -28, -164, -1794, -13691, -249, + -25, -167, -1531, -13219, -210, + -21, -169, -1221, -12702, -171, + -16, -168, -866, -12146, -133, + -10, -164, -464, -11556, -98, + -4, -155, -16, -10938, -67, + 3, -141, 476, -10298, -41, + 9, -121, 1012, -9642, -21, +}; +const Word16 LDQMF_30_enc_fx[] = +{ + 2, -16, 100, -1489, 9088, + 2, -21, 79, -1890, 8640, + 2, -26, 55, -2307, 8191, + 2, -30, 27, -2740, 7744, + 1, -35, -5, -3186, 7299, + 0, -40, -41, -3646, 6858, + 0, -45, -81, -4116, 6423, + -1, -49, -126, -4597, 5995, + -2, -54, -174, -5087, 5576, + -3, -58, -227, -5583, 5166, + -3, -62, -285, -6085, 4767, + -4, -66, -347, -6591, 4380, + -5, -70, -413, -7099, 4006, + -5, -74, -484, -7607, 3646, + -6, -77, -559, -8113, 3300, + -6, -81, -638, -8616, 2970, + -6, -84, -721, -9114, 2656, + -7, -87, -807, -9604, 2359, + -7, -89, -896, -10086, 2078, + -7, -92, -989, -10557, 1815, + -7, -94, -1084, -11015, 1568, + -7, -97, -1181, -11458, 1338, + -7, -99, -1279, -11885, 1125, + -7, -101, -1379, -12294, 929, + -7, -102, -1479, -12684, 748, + -8, -104, -1579, -13052, 583, + -8, -105, -1677, -13398, 433, + -9, -107, -1774, -13720, 297, + -10, -108, -1869, -14017, 175, + -11, -109, -1960, -14287, 63, + -13, -110, -2047, -14529, -30, + -15, -112, -2129, -14742, -104, + -17, -113, -2205, -14926, -168, + -19, -115, -2274, -15080, -222, + -21, -117, -2336, -15204, -267, + -23, -118, -2388, -15296, -303, + -25, -121, -2430, -15358, -332, + -27, -123, -2462, -15389, -354, + -28, -126, -2482, -15388, -369, + -30, -129, -2489, -15356, -377, + -31, -132, -2482, -15293, -380, + -32, -136, -2460, -15200, -377, + -33, -140, -2423, -15078, -370, + -33, -144, -2370, -14926, -359, + -33, -148, -2299, -14746, -343, + -33, -152, -2211, -14539, -325, + -32, -156, -2104, -14306, -304, + -31, -160, -1979, -14047, -281, + -29, -163, -1833, -13765, -256, + -27, -166, -1668, -13461, -230, + -24, -168, -1482, -13136, -204, + -22, -169, -1276, -12791, -177, + -18, -169, -1049, -12429, -152, + -15, -168, -802, -12050, -127, + -11, -165, -534, -11657, -103, + -7, -160, -246, -11250, -82, + -3, -153, 63, -10833, -62, + 1, -144, 391, -10406, -45, + 6, -132, 739, -9972, -31, + 11, -117, 1105, -9532, -17 +}; + +const Word16 LDQMF_32_enc_fx[] = +{ + 2, -16, 101, -1477, 9102, + 2, -20, 81, -1852, 8682, + 2, -25, 59, -2241, 8261, + 2, -29, 33, -2644, 7841, + 1, -34, 4, -3059, 7424, + 1, -38, -28, -3486, 7009, + 0, -43, -64, -3924, 6599, + -1, -47, -104, -4371, 6195, + -1, -51, -148, -4826, 5798, + -2, -55, -195, -5288, 5408, + -3, -59, -247, -5755, 5027, + -4, -63, -302, -6227, 4657, + -4, -67, -361, -6702, 4297, + -5, -71, -424, -7178, 3948, + -5, -74, -491, -7654, 3613, + -6, -77, -561, -8129, 3290, + -6, -80, -635, -8600, 2980, + -6, -83, -713, -9067, 2685, + -7, -86, -793, -9528, 2404, + -7, -89, -877, -9981, 2138, + -7, -91, -963, -10425, 1887, + -7, -94, -1051, -10859, 1651, + -7, -96, -1141, -11280, 1430, + -7, -98, -1233, -11687, 1223, + -7, -100, -1326, -12079, 1031, + -7, -101, -1420, -12455, 854, + -7, -103, -1513, -12813, 690, + -8, -104, -1606, -13152, 540, + -9, -106, -1699, -13471, 402, + -9, -107, -1789, -13768, 277, + -10, -108, -1878, -14043, 164, + -12, -109, -1963, -14295, 60, + -13, -110, -2045, -14522, -27, + -15, -112, -2122, -14724, -97, + -17, -113, -2194, -14899, -158, + -18, -114, -2260, -15049, -211, + -20, -116, -2319, -15172, -255, + -22, -118, -2371, -15268, -292, + -24, -120, -2414, -15337, -321, + -26, -122, -2449, -15378, -344, + -27, -124, -2473, -15392, -361, + -29, -127, -2486, -15379, -373, + -30, -130, -2488, -15338, -379, + -31, -133, -2477, -15270, -380, + -32, -137, -2453, -15176, -376, + -33, -140, -2416, -15056, -369, + -33, -144, -2364, -14910, -357, + -33, -148, -2297, -14740, -343, + -33, -152, -2214, -14546, -325, + -32, -156, -2115, -14329, -306, + -31, -159, -1999, -14089, -284, + -29, -162, -1867, -13829, -261, + -27, -165, -1716, -13549, -237, + -25, -167, -1548, -13250, -213, + -23, -169, -1362, -12933, -188, + -20, -169, -1158, -12601, -164, + -17, -169, -936, -12253, -140, + -13, -167, -696, -11892, -117, + -10, -163, -437, -11518, -96, + -6, -158, -161, -11134, -76, + -2, -151, 133, -10741, -58, + 2, -142, 444, -10339, -43, + 6, -131, 772, -9931, -29, + 11, -117, 1117, -9518, -17 +}; + +const Word16 LDQMF_40_enc_fx[] = +{ + 2, -15, 102, -1440, 9144, + 2, -19, 87, -1738, 8808, + 2, -22, 70, -2045, 8472, + 2, -26, 51, -2361, 8135, + 2, -30, 30, -2685, 7800, + 1, -33, 7, -3017, 7465, + 1, -37, -18, -3357, 7133, + 0, -41, -46, -3704, 6804, + 0, -44, -76, -4057, 6477, + -1, -48, -108, -4416, 6155, + -1, -51, -143, -4780, 5837, + -2, -54, -181, -5148, 5524, + -3, -57, -220, -5521, 5216, + -3, -61, -263, -5896, 4915, + -4, -64, -308, -6274, 4620, + -4, -67, -355, -6654, 4332, + -5, -69, -405, -7035, 4052, + -5, -72, -457, -7416, 3779, + -6, -75, -512, -7797, 3514, + -6, -78, -569, -8176, 3258, + -6, -80, -628, -8553, 3011, + -6, -83, -689, -8928, 2772, + -6, -85, -753, -9299, 2543, + -7, -87, -818, -9665, 2323, + -7, -89, -885, -10026, 2113, + -7, -91, -954, -10381, 1912, + -7, -93, -1024, -10730, 1720, + -7, -95, -1096, -11071, 1538, + -7, -96, -1169, -11403, 1366, + -7, -98, -1242, -11727, 1203, + -7, -99, -1317, -12041, 1050, + -7, -101, -1391, -12344, 905, + -7, -102, -1466, -12636, 770, + -8, -103, -1541, -12917, 644, + -8, -104, -1616, -13185, 526, + -8, -106, -1690, -13440, 416, + -9, -107, -1762, -13681, 314, + -10, -107, -1834, -13909, 219, + -11, -108, -1904, -14121, 132, + -12, -109, -1971, -14319, 50, + -13, -110, -2037, -14501, -20, + -14, -111, -2099, -14666, -77, + -16, -112, -2158, -14815, -129, + -17, -113, -2214, -14947, -175, + -19, -115, -2266, -15063, -215, + -20, -116, -2314, -15161, -251, + -22, -117, -2356, -15242, -281, + -23, -119, -2394, -15306, -307, + -25, -120, -2426, -15352, -329, + -26, -122, -2451, -15381, -346, + -27, -124, -2471, -15392, -360, + -29, -126, -2483, -15386, -370, + -30, -129, -2488, -15362, -376, + -31, -131, -2486, -15320, -379, + -32, -134, -2475, -15262, -379, + -32, -136, -2456, -15187, -377, + -33, -139, -2429, -15095, -371, + -33, -142, -2392, -14986, -363, + -33, -145, -2345, -14862, -353, + -33, -148, -2289, -14722, -341, + -33, -151, -2223, -14566, -327, + -32, -154, -2147, -14396, -312, + -31, -157, -2059, -14212, -295, + -30, -160, -1961, -14013, -277, + -29, -163, -1852, -13802, -259, + -28, -165, -1732, -13578, -240, + -26, -167, -1601, -13342, -220, + -24, -168, -1458, -13094, -200, + -22, -169, -1303, -12835, -181, + -20, -169, -1137, -12567, -161, + -17, -169, -959, -12288, -142, + -14, -167, -770, -12002, -124, + -12, -165, -569, -11707, -106, + -9, -162, -356, -11404, -90, + -6, -158, -132, -11095, -74, + -2, -152, 103, -10780, -60, + 1, -145, 349, -10460, -47, + 4, -137, 606, -10136, -36, + 8, -127, 874, -9808, -26, + 11, -115, 1152, -9476, -15 +}; + +const Word16 LDQMF_60_enc_fx[] = +{ + 2, -14, 105, -1391, 9200, + 2, -17, 95, -1588, 8976, + 2, -19, 85, -1788, 8752, + 2, -22, 73, -1993, 8528, + 2, -24, 61, -2202, 8303, + 2, -27, 48, -2414, 8079, + 2, -29, 34, -2630, 7855, + 1, -32, 19, -2850, 7632, + 1, -34, 3, -3073, 7410, + 1, -36, -14, -3300, 7188, + 1, -39, -32, -3530, 6968, + 0, -41, -51, -3762, 6749, + 0, -44, -71, -3998, 6531, + 0, -46, -92, -4236, 6316, + -1, -48, -114, -4476, 6102, + -1, -50, -137, -4719, 5890, + -2, -53, -162, -4964, 5680, + -2, -55, -187, -5210, 5472, + -2, -57, -214, -5458, 5267, + -3, -59, -241, -5708, 5065, + -3, -61, -270, -5959, 4865, + -4, -63, -300, -6211, 4669, + -4, -65, -331, -6464, 4475, + -4, -67, -363, -6718, 4285, + -5, -69, -396, -6972, 4098, + -5, -71, -431, -7226, 3914, + -5, -73, -466, -7480, 3734, + -5, -75, -502, -7733, 3558, + -6, -76, -540, -7987, 3385, + -6, -78, -578, -8239, 3216, + -6, -80, -618, -8491, 3051, + -6, -81, -658, -8741, 2890, + -6, -83, -700, -8990, 2733, + -6, -84, -742, -9237, 2581, + -7, -86, -785, -9482, 2432, + -7, -87, -829, -9726, 2287, + -7, -89, -874, -9966, 2147, + -7, -90, -919, -10205, 2011, + -7, -91, -966, -10440, 1879, + -7, -93, -1012, -10672, 1751, + -7, -94, -1060, -10901, 1628, + -7, -95, -1108, -11127, 1509, + -7, -96, -1156, -11349, 1394, + -7, -97, -1205, -11566, 1283, + -7, -98, -1255, -11780, 1177, + -7, -99, -1304, -11989, 1075, + -7, -100, -1354, -12194, 976, + -7, -101, -1404, -12394, 882, + -7, -102, -1454, -12589, 792, + -7, -103, -1504, -12778, 706, + -8, -104, -1554, -12962, 623, + -8, -104, -1603, -13141, 545, + -8, -105, -1653, -13314, 470, + -9, -106, -1702, -13481, 398, + -9, -106, -1750, -13642, 330, + -9, -107, -1798, -13797, 266, + -10, -108, -1845, -13945, 204, + -11, -108, -1892, -14087, 146, + -11, -109, -1938, -14222, 90, + -12, -110, -1982, -14351, 38, + -13, -110, -2026, -14472, -9, + -14, -111, -2068, -14585, -49, + -14, -111, -2109, -14692, -86, + -15, -112, -2149, -14791, -121, + -16, -113, -2187, -14883, -153, + -17, -114, -2223, -14967, -182, + -18, -114, -2258, -15044, -209, + -19, -115, -2290, -15114, -234, + -20, -116, -2321, -15176, -256, + -21, -117, -2350, -15230, -277, + -22, -118, -2376, -15276, -295, + -23, -119, -2399, -15315, -311, + -24, -120, -2421, -15346, -326, + -25, -121, -2439, -15369, -338, + -26, -123, -2455, -15384, -349, + -27, -124, -2468, -15391, -358, + -28, -125, -2478, -15391, -365, + -29, -127, -2485, -15383, -371, + -30, -128, -2488, -15367, -375, + -30, -130, -2488, -15343, -378, + -31, -132, -2485, -15312, -380, + -31, -133, -2478, -15273, -380, + -32, -135, -2467, -15226, -378, + -32, -137, -2452, -15172, -376, + -33, -139, -2434, -15111, -372, + -33, -141, -2411, -15042, -368, + -33, -143, -2385, -14967, -362, + -33, -145, -2354, -14884, -355, + -33, -147, -2319, -14794, -347, + -33, -149, -2279, -14697, -339, + -33, -151, -2235, -14593, -330, + -32, -153, -2186, -14483, -320, + -32, -155, -2133, -14366, -309, + -32, -157, -2075, -14243, -298, + -31, -159, -2012, -14114, -286, + -30, -161, -1944, -13979, -274, + -29, -162, -1871, -13838, -262, + -28, -164, -1794, -13691, -249, + -27, -165, -1711, -13539, -236, + -26, -166, -1623, -13382, -223, + -25, -167, -1531, -13219, -210, + -24, -168, -1433, -13051, -197, + -22, -169, -1330, -12879, -184, + -21, -169, -1221, -12702, -171, + -19, -169, -1108, -12521, -158, + -18, -169, -990, -12335, -145, + -16, -168, -866, -12146, -133, + -14, -167, -737, -11953, -121, + -12, -166, -603, -11756, -109, + -10, -164, -464, -11556, -98, + -8, -161, -320, -11353, -87, + -6, -158, -170, -11147, -77, + -4, -155, -16, -10938, -67, + -2, -151, 143, -10727, -58, + 0, -146, 307, -10514, -49, + 3, -141, 476, -10298, -41, + 5, -135, 650, -10081, -34, + 7, -129, 829, -9862, -27, + 9, -121, 1012, -9642, -21, + 12, -113, 1199, -9421, -13 +}; /*! * \brief CLDFB rRotVectr @@ -10170,6 +10688,29 @@ const Word16 iRotVectr_20[] = W16(0xbec1), W16(0xb5bf), W16(0xae90), W16(0xa963), W16(0xa658) }; +/*! + * \brief CLDFB rRotVectr + * + * cldfb bands: 30 + * global gain: 2.50 + * scale: sqrt(1.0/4.00) + */ +const Word16 rRotVectr_30[] = +{ + 25902, 25725, 25265, 24529, 23525, 22262, 20756, 19022, 17080, 14950, 12657, 10226, 7682, 5054, 2370 +}; + +/*! + * \brief CLDFB iRotVectr + * + * cldfb bands: 30 + * global gain: 2.50 + * scale: sqrt(1.0/4.00) + */ +const Word16 iRotVectr_30[] = +{ + -339, -3045, -5717, -8327, -10845, -13245, -15499, -17584, -19476, -21154, -22601, -23801, -24739, -25406, -25796 +}; /*! * \brief CLDFB rRotVectr * @@ -10266,11 +10807,11 @@ const Word16 iRotVectr_60[] = const Word16 cldfb_anaScale[] = { - SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60 + SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60, SCALE_CLDFB_ANA_30 }; const Word16 cldfb_synScale[] = { - SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60 + SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60, SCALE_CLDFB_SYN_30 }; const Word16 cldfb_synGain[] = { @@ -10284,8 +10825,14 @@ const Word16 cldfb_synGain[] = const Word16 *cldfb_protoFilter_2_5ms[] = { - CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60 + CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60, CLDFB80_30 +}; +#ifdef IVAS_FLOAT_FIXED +const Word16 *cldfb_protoFilter_5_0ms[] = +{ + LDQMF_10_enc_fx, LDQMF_16_enc_fx, LDQMF_20_enc_fx, LDQMF_32_enc_fx, LDQMF_40_enc_fx, LDQMF_60_enc_fx, LDQMF_30_enc_fx }; +#endif const Word16 cldfb_scale_2_5ms[7] = { 22603/*88.293854 Q8*/, /* 10 bands */ @@ -10293,8 +10840,22 @@ const Word16 cldfb_scale_2_5ms[7] = 22605/*88.300926 Q8*/, /* 20 bands */ 22606/*88.303848 Q8*/, /* 32 bands */ 22606/*88.304718 Q8*/, /* 40 bands */ - 22535/*88.028412 Q8*/ /* 60 bands */ + 22535/*88.028412 Q8*/, /* 60 bands */ + 22588/*88.234489 Q8*/ /* 30 bands */ }; + +#ifdef IVAS_FLOAT_FIXED +const Word16 cldfb_scale_5_0ms[7] = +{ + 21649/*88.293854 Q8*/, /* 10 bands */ + 21649/*88.299622 Q8*/, /* 16 bands */ + 21649/*88.300926 Q8*/, /* 20 bands */ + 21649/*88.303848 Q8*/, /* 32 bands */ + 21649/*88.304718 Q8*/, /* 40 bands */ + 22535/*88.028412 Q8*/, /* 60 bands */ + 21581/*88.028412 Q8*/ /* 30 bands */ +}; +#endif const float rot_vec_syn_re_L10[5] = { 0.1117172025f,0.1048929802f,0.0878011021f,0.0621146404f,0.0303479649f, @@ -19813,7 +20374,6 @@ const float SVWB2_SN1[256] = { -91.02f, -115.23f, -227.34f, -448.05f, -339.84f, 30.08f, 56.25f, 130.86f, 105.08f, 196.09f, 249.22f, 280.86f, 240.23f, 146.88f, 85.55f, 67.19f }; -/* An 16-by-16 matrix */ const Word16 SVWB2_SN1_fx[256] = { -257, -385, -673, 926, 1408, 874, 735, 512, 624, 587, 493, 688, 845, 521, 428, 95, -32, -90, 1046, 666, 329, -59, -324, -282, -712, -783, -229, 28, -354, -434, -497, -351, @@ -19896,6 +20456,30 @@ const float SVWB2_AR2[128] = { 0.78f, -1.17f, 28.91f, 67.19f, 26.56f, -1.56f, -13.67f, -9.77f, -60.94f, -85.55f, -168.75f, -112.50f, -71.09f, -14.06f, 44.53f, 44.14f }; +/* SVWB2_AR1 * 2.56f */ +const Word16 SVWB2_AR1_fx[128] = { + -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320, + -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64, + -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32, + 108, 106, 102, 37, -14, -17, -61, -144, -161, -160, -257, -404, -540, -316, -124, 18, + 22, 12, 34, -14, -52, -106, -144, -266, -346, -472, -401, -30, -4, -43, -88, -10, + -52, -117, -203, 415, 324, 171, 121, -31, 48, -31, -60, -65, 128, 193, 141, 67, + -47, -86, 430, 334, 193, 136, 85, 82, 1, -34, 47, 84, 2, -30, -77, -45, + -4, -14, -9, -38, -136, -242, -217, -54, -38, 179, 191, 61, 42, -3, 5, -37 +}; + +/* SVWB2_AR2 * 2.56f */ +const Word16 SVWB2_AR2_fx[128] = { + 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16, + -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14, + -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8, + 33, 38, 139, 157, 31, 65, -14, 52, 63, 30, -8, -1, -182, -341, -344, -258, + 14, 16, 46, 6, -54, -64, -136, -132, -318, -303, 261, 146, -19, -57, -30, 30, + -34, -34, 21, 93, 163, 201, 290, 257, 225, 296, 209, 197, 72, 26, 57, 1, + 33, 66, 73, -8, -104, 44, 31, -13, 70, 72, -17, -48, 430, 373, 218, 92, + 1, -2, 74, 172, 67, -3, -34, -25, -156, -219, -432, -288, -181, -35, 113, 112 +}; + /*----------------------------------------------------------------------------------* * LSF quantization - LSF mode/codebook selection tables *----------------------------------------------------------------------------------*/ @@ -20649,30 +21233,6 @@ const Word16 AUWB2_MA1_fx[512] = -19, 43, 35, 40, 42, 55, 63, 101, 133, 194, 222, 152, 117, 145, 133, 213 }; -/* SVWB2_AR1 * 2.56f */ -const Word16 SVWB2_AR1_fx[128] = { - -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320, - -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64, - -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32, - 108, 106, 102, 37, -14, -17, -61, -144, -161, -160, -257, -404, -540, -316, -124, 18, - 22, 12, 34, -14, -52, -106, -144, -266, -346, -472, -401, -30, -4, -43, -88, -10, - -52, -117, -203, 415, 324, 171, 121, -31, 48, -31, -60, -65, 128, 193, 141, 67, - -47, -86, 430, 334, 193, 136, 85, 82, 1, -34, 47, 84, 2, -30, -77, -45, - -4, -14, -9, -38, -136, -242, -217, -54, -38, 179, 191, 61, 42, -3, 5, -37 -}; - -/* SVWB2_AR2 * 2.56f */ -const Word16 SVWB2_AR2_fx[128] = { - 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16, - -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14, - -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8, - 33, 38, 139, 157, 31, 65, -14, 52, 63, 30, -8, -1, -182, -341, -344, -258, - 14, 16, 46, 6, -54, -64, -136, -132, -318, -303, 261, 146, -19, -57, -30, 30, - -34, -34, 21, 93, 163, 201, 290, 257, 225, 296, 209, 197, 72, 26, 57, 1, - 33, 66, 73, -8, -104, 44, 31, -13, 70, 72, -17, -48, 430, 373, 218, 92, - 1, -2, 74, 172, 67, -3, -34, -25, -156, -219, -432, -288, -181, -35, 113, 112 -}; - const Word16 *const Quantizers_fx[] = { SVNB_SN1_fx, SVNB_SN2_fx, GETRNB_SN1_fx, GETRNB_SN2_fx, AUNB_SN1_fx,SVWB_SN1_fx, SVWB_SN2_fx, GETRWB_SN1_fx, GETRWB_SN2_fx, AUWB_SN1_fx,/* U13, */ TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx, SVWB2_SN1_fx, SVWB2_SN2_fx @@ -21626,6 +22186,7 @@ const Word16 scales_fx[][6] = {2267, 5315, 0, 2666, 1237, 1802}, /* CNG */ };/* An 6-by-146 matrix in Scale = 2048.00f */ + const Word16 scales_p_fx[][6] = { {2998, 4862, 0, 0, 0, 0, }, @@ -21785,7 +22346,6 @@ const Word16 scales_p_fx[][6] = }; - /* An 16-by-34 matrix in Scale = 20.48f */ const float sigma_MSLVQ[][16] = { @@ -22751,7 +23311,7 @@ const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17 const int16_t min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; -const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16 }; +const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16 }; const int16_t offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, 112 @@ -37923,6 +38483,13 @@ const Word32 sigma_BWE_fx[] = { 19499580, 20916386, 22705246, 39204284, 40792208 }; /* for 3 bits first stage */ +const Word16 sigma_BWE16_fx[] = { +260, 255, 268, +267, 294, 315, 598, +622, 289, 288, 297, +298, 319, 346, 598, +622 }; /* for 3 bits first stage */ + const float inv_sigma_BWE[] = { 126.2392994665869f, 128.5766227364854f, 122.2856952550425f, 122.8889356808437f, 111.5502335749417f, 104.0176806054527f, 54.7767591108706f, 52.6444584512409f, /* for 4 bits first stage */ @@ -41240,13 +41807,13 @@ const Word16 Gamma_29491_Tbl[] = { * NB post-filter tables *---------------------------------------------------------------------*/ -const Word16 Tab_hup_s[SIZ_TAB_HUP_S] = { +const Word16 tab_hup_s_fx[SIZ_TAB_HUP_S] = { -188, 2873, 31650, -1597, -484, 7041, 28469, -2147, -933, 12266, 23705, -1992, -1492, 18050, 18050, -1492, -1992, 23705, 12266, -933, -2147, 28469, 7041, -484, -1597, 31650, 2873, -188 }; -const Word16 Tab_hup_l[SIZ_TAB_HUP_L] = { +const Word16 tab_hup_l_fx[SIZ_TAB_HUP_L] = { -40, 72, -156, 315, -579, 1023, -1874, 4439, 31915, -3390, 1595, -887, 501, -266, 130, -59, -77, 147, -317, 631, -1150, 2030, -3773, 9639, @@ -41476,7 +42043,7 @@ const Word16 pwf78_fx[17] = { 25559, 19936, 15550, 12129, 9460, 7379, 5755, 4489 * lag window for windowing the autocorrelations in LP analysis * Used in lib_enc\analy_lp_fx.c *------------------------------------------------------------------------------*/ -const Word16 Hamcos_Window[L_LP_AMR_WB] = { +const Word16 hamcos_window_fx[L_LP_AMR_WB] = { 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 0d5c159c532d7ec9b223013dc2829d12577d9d45..43384b6f0c4e3ba827eec12626114f3ae8922a17 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -236,10 +236,12 @@ extern const Word32 lag_window_16k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16]; extern const Word32 lag_window_48k_32[16]; -extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ -extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ -extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */ +extern const Word16 interpol_frac2_mid_fx[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */ +extern const Word16 interpol_frac_12k8_fx[]; /* LPC interpolation coefficients */ extern const Word16 interpol_frac_fx[NB_SUBFR]; extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ @@ -638,6 +640,8 @@ extern const Word16 inv_sigma_p_fx[][16]; extern const float scales[][MAX_NO_SCALES * 2]; extern const float scales_p[][MAX_NO_SCALES * 2]; extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; +extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; extern const int16_t predmode_tab_float[][6]; extern const Word16 predmode_tab[][6]; @@ -1611,7 +1615,16 @@ extern const Word16 CLDFB80_20[200]; extern const Word16 CLDFB80_32[320]; extern const Word16 CLDFB80_40[400]; extern const Word16 CLDFB80_60[600]; - +extern const Word16 CLDFB80_30[300]; +#ifdef IVAS_FLOAT_FIXED +extern const Word16 LDQMF_10_enc_fx[100]; +extern const Word16 LDQMF_16_enc_fx[160]; +extern const Word16 LDQMF_20_enc_fx[200]; +extern const Word16 LDQMF_30_enc_fx[300]; +extern const Word16 LDQMF_32_enc_fx[320]; +extern const Word16 LDQMF_40_enc_fx[400]; +extern const Word16 LDQMF_60_enc_fx[600]; +#endif extern const Word16 rRotVectr_10[]; extern const Word16 iRotVectr_10[]; @@ -1625,12 +1638,16 @@ extern const Word16 rRotVectr_40[]; extern const Word16 iRotVectr_40[]; extern const Word16 rRotVectr_60[]; extern const Word16 iRotVectr_60[]; +extern const Word16 rRotVectr_30[]; +extern const Word16 iRotVectr_30[]; extern const Word16 cldfb_anaScale[]; extern const Word16 cldfb_synScale[]; extern const Word16 cldfb_synGain[]; extern const Word16 *cldfb_protoFilter_2_5ms[]; +extern const Word16 *cldfb_protoFilter_5_0ms[]; extern const Word16 cldfb_scale_2_5ms[7]; +extern const Word16 cldfb_scale_5_0ms[7]; extern const float rot_vec_syn_re_L10[5]; @@ -1990,6 +2007,7 @@ extern const Word16 tcx_mdct_window_trans_48_fx[60]; extern const float sigma_BWE[]; extern const Word32 sigma_BWE_fx[]; +extern const Word16 sigma_BWE16_fx[]; extern const float inv_sigma_BWE[]; extern const float scales_BWE[]; extern const Word8 no_lead_BWE[]; @@ -2085,8 +2103,8 @@ extern const Word16 Gamma_29491_Tbl[]; * NB post-filter tables *---------------------------------------------------------------------*/ -extern const Word16 Tab_hup_s[]; -extern const Word16 Tab_hup_l[]; +extern const Word16 tab_hup_s_fx[]; +extern const Word16 tab_hup_l_fx[]; extern const Word16 mfreq_loc_Q2fx[]; extern const Word16 mfreq_loc_div_25[]; @@ -2142,7 +2160,7 @@ enum FUNC_GAIN_ENC FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ }; -extern const Word16 Hamcos_Window[]; +extern const Word16 hamcos_window_fx[]; extern const Word16 CNG_burst_att_fx[6][8]; extern const Word16 lpc_weights_fx[]; extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ diff --git a/lib_com/rom_com_fx.h b/lib_com/rom_com_fx.h index a077741060617855a57a28b8de3d48988d5abf2a..ac6a0ef466454b142454964902582182753984c7 100644 --- a/lib_com/rom_com_fx.h +++ b/lib_com/rom_com_fx.h @@ -85,6 +85,14 @@ extern const Word16 LDQMF_32_fx[320]; extern const Word16 LDQMF_40_fx[400]; extern const Word16 LDQMF_60_fx[600]; +extern const Word16 LDQMF_10_enc_fx[100]; +extern const Word16 LDQMF_16_enc_fx[160]; +extern const Word16 LDQMF_20_enc_fx[200]; +extern const Word16 LDQMF_30_enc_fx[300]; +extern const Word16 LDQMF_32_enc_fx[320]; +extern const Word16 LDQMF_40_enc_fx[400]; +extern const Word16 LDQMF_60_enc_fx[600]; + extern const Word32 rot_vec_delay_re_LDQMF_fx[60]; extern const Word32 rot_vec_delay_im_LDQMF_fx[60]; diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index e6ca64931dc6f2a2a3f7c8207dfb7fb3e1ea9227..2e61cb93851f6c4ecd3d80bc635244242a40b630 100644 --- a/lib_com/scale_mem_fx.c +++ b/lib_com/scale_mem_fx.c @@ -34,8 +34,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Common prototypes */ -#include "prot_fx2.h" /* Common prototypes */ +#include "options.h" /* Common prototypes */ +#include "prot_fx.h" /* Common prototypes */ #include "ivas_cnst.h" #include "stl.h" diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index 52998bbae6e5f2790a034ca8f89eff6192b96980..e0c75e5632b0fff6ffb0633acc7b22b627126f23 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 05fd4b64332dedbbd11896aad51010a403aa9b70..d9baadc351334c476df28a069cf6df8b27ca7946 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -782,6 +782,7 @@ typedef struct cldfb_filter_bank_struct float scale_flt; /* scaling of frequency domain */ Word16 scale; /* scaling of frequency domain */ /* Q8 */ + Word16 q_scale; } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 8d8949758e6cf25a8b9868d9130daa00c8b8c9df..e91ea907e3085529012cd2d9b505d6a8ec7f1242 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local function prototypes @@ -77,6 +76,7 @@ void stat_noise_uv_mod_fx( Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*---------------------------------------------------------* @@ -171,7 +171,7 @@ void stat_noise_uv_mod_fx( exctilt = mult( shl( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ #endif /* BASOP_NOGLOB */ - preemph_fx( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); + PREEMPH_FX( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); } } @@ -188,7 +188,7 @@ void stat_noise_uv_mod_fx( ELSE { *uv_count = s_min( *uv_count, FULL_NG ); - + move16(); tmp_nom = sub( *uv_count, START_NG ); tmp_den = sub( FULL_NG, START_NG ); tmp_shift = norm_s( tmp_den ); @@ -228,6 +228,7 @@ void stat_noise_uv_mod_fx( IF( EQ_16( *uv_count, 1 ) ) { *ge_sm = L_shr( L_Ge, Q_local ); + move32(); } ELSE { @@ -300,8 +301,10 @@ void stat_noise_uv_mod_fx( L_tmp = L_add( L_tmp3, L_shl( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ #endif Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ + move16(); } - *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ + *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ + move16(); Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); Copy( Exc2_local, exc2, L_FRAME ); @@ -376,7 +379,6 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ r0 = L_deposit_l( 0 ); r1 = L_deposit_l( 0 ); xi = shr( x[0], Q_shift ); - move16(); FOR( i = 0; i < len - 1; i++ ) { @@ -403,7 +405,6 @@ static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ } tmp_shift = norm_l( r0 ); - move16(); r0 = L_shl( r0, tmp_shift ); tmp_sign = 1; move16(); diff --git a/lib_com/stl.h b/lib_com/stl.h index ad437e3b29c950ab41996a738f07124aafda58f2..77e55b8668b86fcea757e21530eda7ea030e0e71 100644 --- a/lib_com/stl.h +++ b/lib_com/stl.h @@ -71,7 +71,7 @@ #include "typedef.h" #include "basop32.h" #include "count.h" -//#include "wmc_auto.h" +#include "wmc_auto.h" #include "move.h" #include "control.h" #include "oper_32b.h" diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index f194355bf878e5148a44e131a9f0d4f59b7dc730..0ecd34e83db660fac977521d98ec20e75aeb18dc 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -32,8 +32,7 @@ #include #include "options.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" @@ -81,8 +80,10 @@ Word16 WB_BWE_gain_pred_fx( Word32 enerL; Word16 n_freq, mode, pitch; Word16 ener_var_flag = 0; + move16(); Word16 voice_factor, enerL_16, enerL_40, enerL_64; Word16 env_var_flag = 0; + move16(); Word16 exp; Word16 tmp, tmp1; Word32 L_tmp; @@ -128,7 +129,7 @@ Word16 WB_BWE_gain_pred_fx( voice_factor = extract_l( L_shr( L_tmp, 2 ) ); /*Q13 */ Copy_Scale_sig( pitch_buf, pitch_buf_tmp, 4, -1 ); pitch = sum16_fx( pitch_buf_tmp, 4 ); - move16(); /*Q5 */ + /*Q5 */ L_tmp = L_shr( enerL, 4 ); test(); @@ -201,6 +202,7 @@ Word16 WB_BWE_gain_pred_fx( #ifdef BASOP_NOGLOB WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ + move16(); #else WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* Q3 */ #endif @@ -252,12 +254,14 @@ Word16 WB_BWE_gain_pred_fx( tmp = s_min( tmp, 16384 ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q15 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ + move16(); } IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + move16(); } } @@ -308,11 +312,12 @@ Word16 WB_BWE_gain_pred_fx( tmp = s_min( tmp, 16384 ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q3 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ - + move16(); IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + move16(); } } @@ -332,12 +337,14 @@ Word16 WB_BWE_gain_pred_fx( L_tmp = L_mult( WB_fenv[0], tmp ); /*Q(21-exp) */ WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q3 */ - tmp1 = mult_r( 328, pitch ); /*Q7 */ - tmp = s_min( s_max( tmp1, 16 ), 256 ); /*Q7 */ - L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ + move16(); + tmp1 = mult_r( 328, pitch ); /*Q7 */ + tmp = s_min( s_max( tmp1, 16 ), 256 ); /*Q7 */ + L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ + /*WB_fenv[0] = saturate(L_tmp); //Q3 */ #ifdef BASOP_NOGLOB WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q3 */ + move16(); #else WB_fenv[0] = round_fx( L_shl( L_tmp, 16 ) ); /*Q3 */ #endif @@ -347,11 +354,13 @@ Word16 WB_BWE_gain_pred_fx( { /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ WB_fenv[0] = round_fx( L_mac( L_mult( 29491, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ + move16(); } IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 ) ) { WB_fenv[0] = mult_r( s_min( 16384, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); + move16(); } IF( env_var_flag == 1 ) @@ -620,6 +629,7 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ Word16 exp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif BASOP_SATURATE_WARNING_OFF_EVS @@ -742,18 +752,17 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ Word32 L_ener, L_ener_tot, L_temp; Word32 tmp1, tmp2; Word16 sign = 0; + move16(); const Word32 *ptr; Word16 exp2, tmp_exp; BASOP_SATURATE_WARNING_OFF_EVS /* this is required for adaptative precision energy summation loop, do not remove */ - move16(); exp2 = 0; move16(); - ptr = sp; - move16(); + L_ener_tot = L_deposit_l( 1 ); /* Divide Frame Length by 32 */ @@ -796,6 +805,7 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ } L_temp = L_ener_tot; + move32(); tmp_exp = sub( Q31, sub( shl( exp_sp, 1 ), Q31 ) ); L_temp = Sqrt32( L_temp, &tmp_exp ); L_temp = L_shl( L_temp, sub( exp_sp, sub( Q31, tmp_exp ) ) ); @@ -805,6 +815,7 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ IF( GT_16( sub( exp2, 4 ), norm_l( L_temp ) ) ) { L_temp = MAX_16; + move32(); } ELSE { @@ -833,7 +844,6 @@ void calc_norm_envelop_fx( Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; lookback = shr( L_swb_norm, 1 ); - move16(); env_index = add( swb_bwe_subband[0], st_offset ); n_lag_now = L_swb_norm; move16(); @@ -937,6 +947,8 @@ void WB_BWE_decoding_fx( Word16 alfa, beta; Word16 flag = 0; Word16 core_type = 1; + move16(); + move16(); Word16 tmp, tmp1, exp, tmp2; Word32 L_tmp, L_tmp1, L_tmp2; Word32 prev_ener_alpha, prev_ener_beta; @@ -984,6 +996,7 @@ void WB_BWE_decoding_fx( FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) { signum[n_freq] = 1; + move16(); IF( WB_signal[n_freq] < 0 ) { signum[n_freq] = -1; @@ -996,10 +1009,12 @@ void WB_BWE_decoding_fx( L_tmp1 = L_deposit_l( WB_signal[n_freq] ); /* Q_syn */ L_tmp = L_sub( L_tmp1, L_tmp ); /* Q_syn */ WB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */ + move16(); IF( L_tmp > 0 ) { tmp = sub( 18022, weight ); /* Q15 */ WB_signal[n_freq] = extract_l( Mult_32_16( L_tmp, tmp ) ); /* Q_syn */ + move16(); } IF( NE_16( signum[n_freq], 1 ) ) @@ -1021,6 +1036,7 @@ void WB_BWE_decoding_fx( tmp = div_s( 16384, tmp ); L_tmp = L_shr( L_mult0( WB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */ WB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */ + move16(); } ELSE { @@ -1188,15 +1204,19 @@ void WB_BWE_decoding_fx( { /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */ + move16(); /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */ + move16(); } ELSE { /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ wfenv[0] = round_fx( L_mac( L_mult( 16384, WB_fenv[0] ), 16384, prev_WB_fenv[0] ) ); /*Q3 */ + move16(); /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ wfenv[1] = round_fx( L_mac( L_mult( 13108, WB_fenv[1] ), 13108, prev_WB_fenv[1] ) ); /*Q3 */ + move16(); } } ELSE IF( EQ_16( last_extl, WB_BWE ) && LT_32( L_tmp1, L_tmp2 ) && GT_16( WB_fenv[0], prev_WB_fenv[0] ) && @@ -1204,16 +1224,20 @@ void WB_BWE_decoding_fx( { /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ wfenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv[0] ) ); /*Q3 */ + move16(); /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ wfenv[1] = round_fx( L_mac( L_mult( 9830, WB_fenv[1] ), 22938, prev_WB_fenv[1] ) ); /*Q3 */ + move16(); } ELSE IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, prev_ener_alpha ) && GT_32( prev_ener_beta, EnergyL ) && NE_16( prev_coder_type, UNVOICED ) ) { /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ wfenv[0] = round_fx( L_mac( L_mult( WB_fenv[0], 16384 ), prev_WB_fenv[0], 16384 ) ); /*Q3 */ + move16(); /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ wfenv[1] = round_fx( L_mac( L_mult( WB_fenv[1], 16384 ), prev_WB_fenv[1], 16384 ) ); /*Q3 */ + move16(); } ELSE { @@ -1309,6 +1333,7 @@ void WB_BWE_decoding_fx( move32(); } *Q_syn_hb = add( Q_syn, add( tmp, 3 ) ); + move16(); return; } @@ -1475,6 +1500,7 @@ void SWB_BWE_decoding_fx( tmp = div_s( 16384, tmp ); /*Q(15+exp) */ L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */ SWB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */ + move16(); } ELSE { @@ -1535,12 +1561,14 @@ void SWB_BWE_decoding_fx( { L_tmp = L_mult( SWB_fenv[n_band / 4], SWB_fenv[n_band / 4] ); /*Q3 */ prev_SWB_fenv[n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */ + move16(); } FOR( n_band = 0; n_band < 6; n_band++ ) { L_tmp = L_mult( SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3] ); /*Q3 */ prev_SWB_fenv[8 + n_band] = round_fx( L_shl( L_tmp, 14 ) ); /*Q1 */ + move16(); } *prev_weight = 16384; @@ -1582,6 +1610,7 @@ void SWB_BWE_decoding_fx( FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 ); + move16(); } fenvL_16 = mult_r( fenvL_16, 6554 ); } @@ -1611,6 +1640,7 @@ void SWB_BWE_decoding_fx( FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp; n_freq++ ) { *Seed = extract_l( L_mac0( 20101L, 12345, *Seed ) ); + move16(); SWB_signal[n_freq] = mult_r( *Seed, 32767 ); move16(); /*Q15 */ } @@ -1693,7 +1723,7 @@ void SWB_BWE_decoding_fx( } pit1 = &SWB_signal[367 + st_offset]; - move16(); + IF( GT_16( mult_r( tmp1, 6554 ), tmp2 ) ) { /*20480 = 5 in Q12 */ @@ -1704,6 +1734,7 @@ void SWB_BWE_decoding_fx( #else *pit1 = round_fx( L_shl( L_mult( *pit1, tmp3 ), 3 ) ); /*Q_syn */ #endif + move16(); pit1--; } } @@ -1716,7 +1747,6 @@ void SWB_BWE_decoding_fx( tmp2 = add( add( abs_s( SWB_signal[492 + st_offset] ), abs_s( SWB_signal[493 + st_offset] ) ), add( abs_s( SWB_signal[494 + st_offset] ), abs_s( SWB_signal[495 + st_offset] ) ) ); #endif pit1 = &SWB_signal[496 + st_offset]; - move16(); test(); IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) @@ -1775,6 +1805,7 @@ void SWB_BWE_decoding_fx( { L_tmp = Mult_32_16( L_tmp3, *pit1 ); /*Q(16-exp) */ *pit1-- = round_fx( L_shl( L_tmp, exp ) ); /*Q_syn */ + move16(); L_tmp3 = L_sub( L_tmp3, L_tmp4 ); } @@ -1807,6 +1838,7 @@ void SWB_BWE_decoding_fx( FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ) { signum[n_freq] = 1; + move16(); IF( SWB_signal[n_freq] < 0 ) { signum[n_freq] = -1; @@ -1827,7 +1859,7 @@ void SWB_BWE_decoding_fx( { SWB_signal[n_freq] = extract_l( L_tmp ); /* Q_syn */ } - + move16(); IF( NE_16( signum[n_freq], 1 ) ) { SWB_signal[n_freq] = negate( SWB_signal[n_freq] ); @@ -1843,7 +1875,8 @@ void SWB_BWE_decoding_fx( exp = sub( sub( 30, exp ), Q_syn ); tmp = div_s( 16384, tmp ); /* Q(15+exp) */ L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */ - SWB_signal[n_freq] = extract_l( L_tmp ); /* Q15 */ + SWB_signal[n_freq] = extract_l( L_tmp ); + move16(); /* Q15 */ } ELSE { @@ -1852,6 +1885,7 @@ void SWB_BWE_decoding_fx( } } *prev_weight = weight; + move16(); } ELSE { @@ -1859,6 +1893,7 @@ ELSE tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ tmp = add( shl( tmp, 1 ), tmp ); *prev_weight = s_max( s_min( tmp, 16384 ), 6554 ); /* Q15 */ + move16(); } IF( EQ_16( mode, HARMONIC ) ) @@ -1875,7 +1910,6 @@ IF( EQ_16( mode, HARMONIC ) ) } mean = extract_l( Mult_32_16( L_mean, 2048 ) ); /*Q15 */ pit1 -= 16; - move16(); FOR( n_freq = 0; n_freq < 16; n_freq++ ) { if ( LT_16( abs_s( *pit1 ), mean ) ) @@ -1921,6 +1955,7 @@ FOR( n_band = 0; n_band < SWB_FENV; n_band += L ) FOR( n_freq = add( swb_bwe_subband[n_band], st_offset ); n_freq < tmp; n_freq++ ) { SWB_signal_32[n_freq] = L_shl( L_mult( tmp_ener, SWB_signal[n_freq] ), tmp_exp ); /*Qsyn */ + move32(); } } ELSE @@ -2120,7 +2155,6 @@ void time_envelop_shaping_fx( Word32 L_tmp; pit = werr; - move16(); exp_L = norm_s( L ); inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */ FOR( i = 0; i < SWB_TENV; i++ ) @@ -2189,6 +2223,7 @@ void time_envelop_shaping_fx( #else *pit = round_fx( L_shl( L_mult( tmp, *pit ), sub( exp, 1 ) ) ); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ #endif + move16(); pit++; } } @@ -2270,7 +2305,6 @@ void time_reduce_pre_echo_fx( FOR( i = 0; i < 3; i++ ) { L_tmp = Mult_32_16( energyL[i], 29491 ); /*Q14 */ - test(); IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 ) ) { pos = add( i, 1 ); @@ -2287,7 +2321,6 @@ void time_reduce_pre_echo_fx( } energy = L_deposit_l( 0 ); j = i_mult( L, pos ); - move16(); FOR( i = 0; i < j; i++ ) { #ifdef BASOP_NOGLOB @@ -2340,6 +2373,7 @@ void time_reduce_pre_echo_fx( #else error[i] = round_fx( L_shl( Mult_32_16( L_tmp, error[i] ), tmp_exp ) ); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ #endif + move16(); } energy = L_deposit_l( 0 ); @@ -2394,6 +2428,7 @@ void time_reduce_pre_echo_fx( tmp = round_fx( L_shl( Mult_32_16( L_tmp, *pit ), add( 1, exp ) ) ); /*Q0 */ #endif *pit++ = tmp; + move16(); } } @@ -2519,6 +2554,7 @@ void calc_normal_length_fx_32( *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 ), *prev_L_swb_norm, 29491 ), 32768 ) ); *prev_L_swb_norm = L_swb_norm_cur; move16(); + move16(); } return; @@ -2700,6 +2736,7 @@ void hq_generic_decoding_fx( IF( EQ_16( tmp, 0 ) ) { nband_lf = 0; + move16(); } ELSE { diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index da8997a26b5e0f8b844a929b3ad3e54fee7408cd..cac0ed123cd0d564bd19cd0b8ad47764dca36ea0 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * swb_hr_nonzero_subband_noise_fill() diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 738cff5915f600eafe6dbb6b6bdbb0a31cd3035b..adc98d36aa4bc8813e5f1680346db2d359492d53 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -33,7 +33,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include @@ -87,12 +87,14 @@ static void est_freq_har_decis_fx( ) { Word16 temp_hfe2 = 0; + move16(); Word16 har_freq_est2_2; Word16 prev_frm_hfe2_2; IF( k != 0 ) { *har_freq_est1 = div_s_ss( sharp, k ); + move16(); } test(); @@ -100,6 +102,7 @@ static void est_freq_har_decis_fx( IF( GT_16( k1, 1 ) ) { *har_freq_est2 = div_s_ss( sharp1, k1 ); + move16(); } ELSE IF( LT_16( k1, 2 ) && ( k2 != 0 || GT_16( k, 1 ) ) ) { @@ -257,6 +260,7 @@ Word16 har_est_fx( FOR( i = N; i < temp; i++ ) { L_input_abs[i] = L_deposit_l( 0 ); + move16(); } q = start_pos; @@ -315,6 +319,7 @@ Word16 har_est_fx( IF( GT_32( *p_L_blk_peak, *pm1_L_blk_peak ) ) { *pm1_L_blk_peak = L_deposit_l( 0 ); + move32(); *pm1_blk_peak_pos = 0; move16(); } @@ -325,6 +330,7 @@ Word16 har_est_fx( *p_blk_peak_pos = *pm1_blk_peak_pos; move16(); *pm1_L_blk_peak = L_deposit_l( 0 ); + move32(); *pm1_blk_peak_pos = 0; move16(); } @@ -569,7 +575,6 @@ Word16 har_est_fx( blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i]; move16(); ct_hfsb2 = add( ct_hfsb2, 1 ); - move16(); } } @@ -580,9 +585,11 @@ Word16 har_est_fx( FOR( i = 1; i < ct_hfsb2; i++ ) { diff_peak_pos_hfsb2[i - 1] = sub( blk_peak_pos_hfsb2[i], blk_peak_pos_hfsb2[i - 1] ); + move16(); sum_diff = add( sum_diff, diff_peak_pos_hfsb2[i - 1] ); } *har_freq_est2 = div_s_ss( sum_diff, ct_hfsb2 ); + move16(); } ELSE { @@ -648,7 +655,7 @@ void genhf_noise_fx( FOR( k = 0; k < 2; k++ ) { nlags[k] = shl( 1, bits_lagIndices_mode0_Har[k] ); - + move16(); l = 0; move16(); WHILE( LT_16( st_last_peakpos, add( fLenLow, subband_offsets[k] ) ) ) @@ -665,7 +672,7 @@ void genhf_noise_fx( FOR( j = 0; j < sbWidth[k]; j++ ) { L_xSynth_har[j] = L_shl( L_deposit_l( noise_flr_fx[st_pos + j] ), sub( QsL, Qss ) ); - + move32(); L_tmpbuf[j] = L_xSynth_har[j]; move32(); IF( predBuf_fx[st_pos + j] != 0x0 ) @@ -692,6 +699,7 @@ void genhf_noise_fx( /*xSynth_har[ii] = noise_flr[j];*/ L_xSynth_har[ii] = L_shl( L_deposit_l( noise_flr_fx[j] ), sub( QsL, Qss ) ); + move32(); L_tmpbuf[ii] = L_xSynth_har[ii]; move32(); IF( predBuf_fx[j] != 0x0 ) @@ -749,6 +757,8 @@ void genhf_noise_fx( { st_last_peakpos = add( st_last_peakpos, har_freq_est2 ); } + test(); + test(); WHILE( LT_16( st_last_peakpos, hfband_end[k] ) && LT_16( pul_res[k], pul_res[2 - l] ) && LE_16( l, 2 ) ) { test(); @@ -813,7 +823,7 @@ static void SmoothSpec_fx( lo = L_Extract_lc( L_sum, &hi ); *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, inItems ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - + move16(); L_sum = L_mac0( L_sum, 0x0001, *newPtr++ ); /* nItems += 2, * only used value is 5 --> @@ -831,6 +841,7 @@ static void SmoothSpec_fx( lo = L_Extract_lc( L_sum, &hi ); /* 4681 (in Q15) = 0.1428 = 1/7 */ *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, 4681 ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + move16(); i = add( i, 1 ); /*-- Moving average. --*/ @@ -843,6 +854,7 @@ static void SmoothSpec_fx( lo = L_Extract_lc( L_sum, &hi ); /* 4681 (in Q15) = 0.1428 = 1/7 */ *outBuf++ = round_fx( L_shl( Mpy_32_16( hi, lo, 4681 ), 16 ) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ + move16(); inBuf++; } @@ -921,10 +933,11 @@ void SpectrumSmoothing_fx( Word16 exp_norm; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif *Qss = 10; - + move16(); num_subband_smooth_pre_fx = mult( fLen, 21845 ); /* 1/L_SB = 1/12 = 21845(Q18) Q = exp_normn-18 */ num_subband_smooth_fx = shr( num_subband_smooth_pre_fx, 18 - 15 ); IF( NE_16( num_subband_smooth_pre_fx, shl( num_subband_smooth_fx, 18 - 15 ) ) ) @@ -943,14 +956,17 @@ void SpectrumSmoothing_fx( FOR( i = fLen; i < fLen + ( num_subband_smooth_fx * L_SB - fLen ); i++ ) { L_inBuf_pss[i] = L_deposit_l( 0 ); + move32(); outBuf_pss_fx[i] = 0; move16(); } j = 0; + move16(); FOR( i = 0; i < num_subband_smooth_fx; i++ ) { L_max_val[i] = L_deposit_l( 0 ); + move32(); FOR( k = 0; k < L_SB; k++ ) { L_inBuf_abs = L_abs( L_inBuf_pss[j] ); @@ -966,6 +982,7 @@ void SpectrumSmoothing_fx( /* convert to maximum amplitude frequency log scale envelope */ j = 0; + move16(); FOR( i = 0; i < num_subband_smooth_fx; i++ ) { /* max_val_norm = 10.0f / (max_val[i] + 0.001f); */ @@ -1017,6 +1034,7 @@ void SpectrumSmoothing_fx( #else outBuf_pss_fx[j] = negate( round_fx( L_shl( Mpy_32_16_r( L_shl( L_abs( L_inBuf_pss[j] ), exp_norm ), max_val_norm_fx ), sub( exp_shift, exp_norm ) ) ) ); #endif + move16(); } } ELSE @@ -1154,6 +1172,7 @@ void Get20Log10Spec_fx( L_tmp = Mpy_32_16_1( L_tmp, 24660 ); /* 6.0206 in Q12 */ L_tmp = L_shl( L_tmp, 2 + 8 ); /* Q7 */ *outBuf_fx++ = round_fx( L_tmp ); + move16(); } return; @@ -1318,9 +1337,11 @@ void SpectrumSmoothing_nss_fx( Word16 exp_shift; L_tmp[0] = L_deposit_l( 0 ); + move32(); FOR( i = 0; i < fLen; i++ ) { L_tmp[0] = L_or( L_tmp[0], L_abs( L_inBuf[i] ) ); + move32(); } exp_norm = norm_l( L_tmp[0] ); Qm = sub( exp_norm, 4 ); /* Qm = sub(add(12, exp_norm), 16); */ @@ -1330,6 +1351,7 @@ void SpectrumSmoothing_nss_fx( L_tmp[i] = L_shl( L_inBuf[i], exp_norm ); /* Q(12+exp_norm) */ move32(); inBuf_fx[i] = round_fx( L_tmp[i] ); /* Qm */ + move16(); } num_subband_smooth_fx = shr( fLen, 3 ); /* L_SB_NSS=8 shr(target, 3); */ @@ -1404,7 +1426,8 @@ void SpectrumSmoothing_nss_fx( { L_temp_sum_1[i] = L_deposit_l( 0 ); L_temp_sum_2[i] = L_deposit_l( 0 ); - + move32(); + move32(); FOR( k = 0; k < L_SB_NSS_HALF; k++ ) { L_temp_sum_1[i] = L_add( L_temp_sum_1[i], extract_l( abs_s( inBufw_fx[k + L_SB_NSS * i] ) ) ); /* Qm */ @@ -1444,7 +1467,9 @@ void SpectrumSmoothing_nss_fx( L_temp1 = L_negate( L_temp1 ); temp_lo = L_Extract_lc( L_temp1, &temp_hi ); Qsumdiv[i] = sub( 14, temp_hi ); + move16(); temp_sum_div_fx[i] = extract_l( Pow2( 14, temp_lo ) ); /* Qsumdiv[i] */ + move16(); exp_norm = norm_s( temp_sum_div_fx[i] ); temp_sum_div_fx[i] = shl( temp_sum_div_fx[i], exp_norm ); move16(); @@ -1457,6 +1482,7 @@ void SpectrumSmoothing_nss_fx( FOR( i = 0; i < num_subband_smooth_fx; i++ ) { Qo[i] = add( add( Qm, Qsumdiv[i] ), 1 ); + move16(); L_temp1 = 0x0L; FOR( k = 0; k < L_SB_NSS; k++ ) { @@ -1489,6 +1515,7 @@ void SpectrumSmoothing_nss_fx( L_outBufw[k + L_SB_NSS * i] = L_shl( L_outBufw[k + L_SB_NSS * i], exp_shift ); move16(); outBufw_fx[k + L_SB_NSS * i] = round_fx( L_outBufw[k + L_SB_NSS * i] ); + move16(); } } *Qss = sub( *Qss, 16 ); @@ -1652,7 +1679,6 @@ void post_hq2_swb_fx( ELSE { k = sub( bands_fx, NB_SWB_SUBBANDS ); - move16(); } FOR( ; k < bands_fx; k++ ) @@ -1709,7 +1735,8 @@ void GetSynthesizedSpecThinOut_fx( { fLen_fx = sbWidth_fx[sb]; lag_fx = lagIndices_fx[sb]; - + move16(); + move16(); if ( GT_16( add( lag_fx, fLen_fx ), predBufLen_fx ) ) { /* should never happen */ @@ -1963,6 +1990,7 @@ void GetlagGains_fx( /* Sqrt part sqrt(pow (2.0f, band_energy[i])/lagEnergy) */ QlagGains[sb] = add( Qdiv, 16 ); + move16(); IF( s_and( Qdiv, 1 ) == 0 ) /* Qdiv % 2 == 0 */ { L_temp = Sqrt_l( L_shr( L_deposit_h( temp_fx ), 1 ), &exp_norm ); @@ -1970,6 +1998,7 @@ void GetlagGains_fx( QlagGains[sb] = sub( shr( QlagGains[sb], 1 ), 1 ); move16(); lagGains_fx[sb] = round_fx( L_temp ); + move16(); } ELSE { @@ -1978,6 +2007,7 @@ void GetlagGains_fx( QlagGains[sb] = shr( QlagGains[sb], 1 ); move16(); lagGains_fx[sb] = round_fx( L_temp ); + move16(); } } ELSE @@ -2022,6 +2052,7 @@ void noise_extr_corcod_fx( SpectrumSmoothing_nss_fx( L_spectra, sspectra_fx, &Qss_s, fLenLow_fx ); Copy( sspectra_fx, sspectra_ni_fx, fLenLow_fx ); tmp_fx = 0; + move16(); FOR( i = 0; i < fLenLow_fx; i++ ) { tmp_fx |= abs_s( sspectra_fx[i] ); @@ -2043,6 +2074,7 @@ void noise_extr_corcod_fx( } SpectrumSmoothing_nss_fx( L_spectra_diff, sspectra_diff_fx, &Qss_d, fLenLow_fx ); tmp_fx = 0; + move16(); FOR( i = 0; i < fLenLow_fx; i++ ) { tmp_fx |= abs_s( sspectra_diff_fx[i] ); @@ -2083,7 +2115,7 @@ void noise_extr_corcod_fx( /*Smoothing the noise components*/ br_adj_fx = 29491; /* br_adj = 0.9f; Q15 */ - + move16(); pulse_num_fx = 0; move16(); FOR( i = 0; i < fLenLow_fx; i++ ) @@ -2211,6 +2243,7 @@ void ton_ene_est_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif *QbeL = 3; @@ -2241,6 +2274,7 @@ void ton_ene_est_fx( QsN = sub( add( QsL, 11 ), 15 ); exp_safe = 4; /*move16();*/ + move16(); norm_vec_32_16_scale_fx( L_xSynth_har, QsN, fLenHigh, xSynth_har_fx, &QxSynth, exp_safe ); pos = 0; @@ -2302,6 +2336,7 @@ void ton_ene_est_fx( #else L_band_energy_Linear[i] = L_shl( L_band_energy_Linear[i], sub( *QbeL, exp_pow ) ); #endif + move32(); /* Div Part */ E_r_fx = 0x7fff; move16(); @@ -2320,7 +2355,7 @@ void ton_ene_est_fx( L_E = L_shl( L_E, sub( *QbeL, QE ) ); QE = *QbeL; - + move16(); /* 0.06=15729(Q18) */ exp_shift = sub( 18, QE_r ); #ifdef BASOP_NOGLOB @@ -2339,6 +2374,7 @@ void ton_ene_est_fx( sqrt_32n_16_fx( L_temp, Qtemp, &avg_pe_fx[k], &Qavg_pe[k] ); fac_fx = 19661; /* 0.6(Q15) */ + move16(); IF( pul_res_bnd[k] != 0 ) { /* Div Part */ @@ -2376,9 +2412,10 @@ void ton_ene_est_fx( Overflow = 0; move16(); ni_gain_fx[k] = shl( ni_gain_fx[k], sub( Qni_gain, Qavg_pe[k] ) ); + move16(); assert( Qni_gain == 8 ); /* 358 is '(short)(1.4*pow(2,Qni_gain))' */ ni_gain_fx[k] = s_max( ni_gain_fx[k], 358 ); /* 1.4 -> 22938(Q14) */ - + move16(); exp_shift = QsL - ( QxSynth + Qni_gain + 1 ); /* QsL - (QxSynth+Qni_gain+1) */ FOR( j = band_start[i]; j <= band_end[i]; j++ ) { @@ -2387,6 +2424,7 @@ void ton_ene_est_fx( } exp_safe = 4; /* move16(); */ + move16(); norm_vec_32_16_scale_fx( &L_xSynth_har[band_start[i] - fLenLow], QsL, band_width[i], &xSynth_har_fx[band_start[i] - fLenLow], &QxSynth_sft, exp_safe ); L_E = sum2_fx( &xSynth_har_fx[sub( band_start[i], fLenLow )], band_width[i] ); @@ -2398,6 +2436,7 @@ void ton_ene_est_fx( L_E = L_shl( L_E, sub( *QbeL, QE ) ); #endif QE = *QbeL; + move16(); } ELSE { @@ -2412,7 +2451,7 @@ void ton_ene_est_fx( k = add( k, 1 ); L_be_tonal[i] = L_sub( L_band_energy_Linear[i], L_E ); - + move32(); IF( L_be_tonal[i] < 0x0L ) { L_E = L_deposit_l( 0 ); @@ -2523,6 +2562,7 @@ void Gettonl_scalfact_fx( band_pos_fx = add( k_fx, harmonic_band ); count_pos_st_fx = pos_fx; move16(); + test(); WHILE( LE_16( sb_ton_loc_fx[pos_fx], sub( band_end[band_pos_fx], fLenLow ) ) && sb_ton_loc_fx[pos_fx] >= 0 ) { test(); @@ -2532,6 +2572,7 @@ void Gettonl_scalfact_fx( move16(); exp_safe = 2; /* move16(); */ + move16(); QetEne = add( shl( sub( Qss, exp_safe ), 1 ), 1 ); L_temp = L_add( L_est_ton_ene[k_fx], 0 ); FOR( i = count_pos_st_fx; i < count_pos_end_fx; i++ ) @@ -2607,6 +2648,7 @@ void Gettonl_scalfact_fx( #else L_band_energy_Linear[band_pos_fx] = L_shl( L_band_energy_Linear[band_pos_fx], sub( QbeL, exp_pow ) ); #endif + move32(); /* Div Part */ exp_normd = norm_l( L_be_tonal[band_pos_fx] ); exp_normd = sub( exp_normd, 1 ); @@ -2691,6 +2733,7 @@ void sqrt_32n_16_fx( L_in_t = L_shr( L_in_t, exp_norm ); *Qout = shr( Qin_t, 1 ); } + move16(); *out_fx = round_fx( L_in_t ); } @@ -2724,6 +2767,7 @@ void norm_vec_32_16_scale_fx( FOR( i = 0; i < length_fx; i++ ) { vec_out_fx[i] = round_fx( L_shl( L_vec_in[i], exp_shift ) ); + move16(); } } @@ -2771,6 +2815,7 @@ void get_sigma_fx_har( FOR( i = 0; i < length_fx; i++ ) { L_x_abs_sh[i] = L_shl( L_x_abs[i], exp_norm ); + move32(); } L_d = L_deposit_l( 0 ); @@ -2830,7 +2875,8 @@ void get_sigma_fx_har( *Qsigma = shr( Qd, 1 ); *sigma_fx = round_fx( L_temp ); } - + move16(); + move16(); return; } @@ -2870,7 +2916,8 @@ void FindNBiggest2_simple_fx_har( { L_abs_in[j] = L_abs( L_inBuf[j] ); /* Qabs_in */ L_abs_in_sft[j] = L_shr( L_abs_in[j], 8 ); /* 8 is safe shift */ - + move32(); + move32(); if ( LT_32( L_max_in, L_abs_in_sft[j] ) ) { L_max_in = L_abs_in_sft[j]; @@ -2923,6 +2970,7 @@ void FindNBiggest2_simple_fx_har( IF( GT_32( L_abs_in[j], L_thr ) ) { pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx( L_abs_in[j] ); /* Qabs_in-16 */ + move16(); pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; move16(); L_abs_in[j] = L_deposit_l( 0 ); @@ -3026,6 +3074,7 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_ Word32 L_temp; Word32 L_spectra_rm[L_FRAME32k]; Word32 L_cut_input = 410; + move32(); Word16 rand_a_fx[L_FRAME32k]; @@ -3033,6 +3082,7 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_ FOR( i = 0; i < fLenLow_fx; i++ ) { rand_a_fx[i] = Random( ni_seed_fx ); + move16(); } @@ -3090,6 +3140,7 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_ FOR( i = 0; i < fLenLow_fx; i++ ) { L_spectra_rm[i] = L_deposit_l( 0 ); + move32(); if ( GE_32( L_abs( L_spectra_diff[i] ), L_cut_input ) ) { L_spectra_rm[i] = L_spectra_diff[i]; @@ -3114,6 +3165,7 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_ { /*sspectra[i] = sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min);*/ sspectra_fx[i] = add( mult_r( ratio_fx, abs_s( sspectra_fx[i] ) ), ss_min_fx ); + move16(); IF( sign_fx != 0 ) { sspectra_fx[i] = negate( sspectra_fx[i] ); @@ -3137,6 +3189,7 @@ Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_ L_temp = L_mult( ni_ratio_fx, 20480 ); /* ni_ratio*5 */ L_temp = Mult_32_16( L_temp, rand_a_fx[i] ); /* Q28 */ sspectra_ni_fx[i] = round_fx( L_shr( L_temp, 2 ) ); /* Qss */ + move16(); } } @@ -3166,11 +3219,12 @@ void noiseinj_hf_fx( Word16 *p_prev_En_sb_fx; Word16 QbeL = 7; /* Don't need 3, because this E only use under th samples */ /* QsEn=3 */ - + move16(); Word16 map_pulse_t_fx[L_FRAME32k]; Word16 map_pulse_fx[L_FRAME32k]; Word16 QsEn = 4; /* kiken */ + move16(); Word32 L_En[NB_SWB_SUBBANDS]; Word32 *p_L_En; Word16 QE; @@ -3196,20 +3250,24 @@ void noiseinj_hf_fx( Word16 Qdiv; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif set16_fx( map_pulse_t_fx, 0, band_end_fx[BANDS_fx - 1] + 1 ); set16_fx( map_pulse_fx, 0, band_end_fx[BANDS_fx - 1] + 1 ); /*level adjust the missing bands in the core coder */ exp_safe = 4; /*move16();*/ + move16(); norm_vec_32_16_scale_fx( L_xSynth_har, Qs, fLenHigh_fx, xSynth_har_fx, &QxSynth, exp_safe ); QE = add( shl( QxSynth, 1 ), 1 ); p_L_En = L_En; + move32(); p_sqrt_En_fx = sqrt_En_fx; FOR( k = sub( BANDS_fx, NB_SWB_SUBBANDS ); k < BANDS_fx; k++ ) { *p_L_En = L_deposit_l( 0 ); + move32(); IF( p2a_flags_fx[k] == 0 ) { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) @@ -3217,6 +3275,7 @@ void noiseinj_hf_fx( IF( LE_32( L_abs( L_xSynth_har[i - fLenLow_fx] ), L_th_g[k - ( BANDS_fx - NB_SWB_SUBBANDS )] ) ) { *p_L_En = L_mac( *p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx] ); + move32(); } ELSE { @@ -3267,6 +3326,7 @@ void noiseinj_hf_fx( /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */ *p_Enn_sm_sb_fx = round_fx( L_mac( L_mult( *p_sqrt_En_fx, 26214 ), *p_prev_En_sb_fx, 6554 ) ); } + move16(); } p_Enn_sm_sb_fx++; diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index ede212bb13841aa67fbec6363525de17c183edd4..aec2805a07fb4ec07fc468433241b4dcfc9853dc 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -39,8 +39,7 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" #include "ivas_prot.h" @@ -1218,11 +1217,11 @@ void GenSHBSynth_fx_32( Word32 *shb_syn_speech_32k, /* o : output highband component Qx*/ Word32 Hilbert_Mem[], /* i/o: memory Qx*/ Word32 state_lsyn_filt_shb_local[], /* i/o: memory Qx*/ - const int16_t L_frame, /* i : ACELP frame length */ - int16_t *syn_dm_phase ) + const Word16 L_frame, /* i : ACELP frame length */ + Word16 *syn_dm_phase ) { Word32 speech_buf_32k[L_FRAME32k]; - int16_t i; + Word16 i; Interpolate_allpass_steep_32( input_synspeech, state_lsyn_filt_shb_local, L_FRAME16k, speech_buf_32k ); @@ -1235,14 +1234,15 @@ void GenSHBSynth_fx_32( FOR( i = 0; i < L_FRAME32k; i++ ) { // shb_syn_speech_32k[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_32k[i] ) : ( speech_buf_32k[i] ); - IF( EQ_16( i % 2, 0 ) ) + IF( i % 2 == 0 ) { - shb_syn_speech_32k[i] = -speech_buf_32k[i]; + shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); } ELSE { shb_syn_speech_32k[i] = speech_buf_32k[i]; } + move32(); } } @@ -1364,7 +1364,7 @@ void ScaleShapedSHB( } #ifdef IVAS_FLOAT_FIXED void ScaleShapedSHB_32( - const int16_t length, /* i : SHB overlap length */ + const Word16 length, /* i : SHB overlap length */ Word32 *synSHB_fx, /* i/o: synthesized shb signal Q_inp/Q_new */ Word32 *overlap_fx, /* i/o: buffer for overlap-add Q_inp/Q_new */ const Word16 *subgain_fx, /* i : subframe gain Q15 */ @@ -1383,26 +1383,33 @@ void ScaleShapedSHB_32( /* initilaization */ l_frame = L_FRAME16k; l_shb_lahead = L_SHB_LAHEAD; + move16(); + move16(); skip = skip_bands_SWB_TBE; - IF( length == SHB_OVERLAP_LEN / 2 ) + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) { skip = skip_bands_WB_TBE; l_frame = L_FRAME16k / 4; l_shb_lahead = L_SHB_LAHEAD / 4; + move16(); + move16(); } /* apply gain for each subframe, and store noise output signal using overlap-add */ set32_fx( mod_syn_fx, 0, l_frame + l_shb_lahead ); - IF( length == SHB_OVERLAP_LEN / 2 ) + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) { sum_gain_fx = 0; - FOR( k = 0; k < length / 2; k++ ) + move16(); + FOR( k = 0; k < shr( length, 1 ); k++ ) { sum_gain_fx = mult_r( subwin_fx[2 * k + 2], subgain_fx[0] ); - mod_syn_fx[skip[0] + k] = Mpy_32_16_1( synSHB_fx[skip[0] + k], sum_gain_fx ); // Qx - mod_syn_fx[skip[0] + k + length / 2] = Mpy_32_16_1( synSHB_fx[skip[0] + k + length / 2], subgain_fx[0] ); // Qx + mod_syn_fx[add( skip[0], k )] = Mpy_32_16_1( synSHB_fx[add( skip[0], k )], sum_gain_fx ); + move32(); // Qx + mod_syn_fx[add( add( skip[0], k ), shr( length, 1 ) )] = Mpy_32_16_1( synSHB_fx[add( add( skip[0], k ), shr( length, 1 ) )], subgain_fx[0] ); // Qx + move32(); } FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) { @@ -1410,13 +1417,15 @@ void ScaleShapedSHB_32( { L_tmp = L_mult0( subwin_fx[k + 1], subgain_fx[i] ); sum_gain_fx = round_fx( L_mac0( L_tmp, subwin_fx[length - k - 1], subgain_fx[i - 1] ) ); - mod_syn_fx[skip[i] + k] = L_shl( Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ), 1 ); // Qx + mod_syn_fx[add( skip[i], k )] = L_shl( Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ), 1 ); // Qx + move32(); } } - FOR( k = 0; k < length / 2; k++ ) + FOR( k = 0; k < shr( length, 1 ); k++ ) { - sum_gain_fx = mult_r( subwin_fx[length - 2 * k - 2], subgain_fx[i - 1] ); - mod_syn_fx[skip[i] + k] = Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ); // Qx + sum_gain_fx = mult_r( subwin_fx[sub( sub( length, shl( k, 1 ) ), 2 )], subgain_fx[i - 1] ); + mod_syn_fx[add( skip[i], k )] = Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ); // Qx + move32(); } } ELSE @@ -1424,52 +1433,61 @@ void ScaleShapedSHB_32( num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; join_length = i_mult( num_join, length ); j = 0; + move16(); + move16(); FOR( k = 0; k < length; k++ ) { mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[k + 1], subgain_fx[0] ) ); // Qx - j++; + move32(); + j = add( j, 1 ); } FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) { FOR( k = 0; k < join_length - length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i * num_join] ); // Qx - j++; + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i_mult( i, num_join )] ); // Qx + move32(); + j = add( j, 1 ); } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i * num_join] ); - mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[( i + 1 ) * num_join] ) ) ), 1 ); // Qx - j++; + L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i_mult( i, num_join )] ); + mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[i_mult( ( i + 1 ), num_join )] ) ) ), 1 ); // Qx + move32(); + j = add( j, 1 ); } } FOR( k = 0; k < join_length - length; k++ ) { mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); // Qx - j++; + move32(); + j = add( j, 1 ); } FOR( k = 0; k < length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[length - k - 1], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx - j++; + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[sub( sub( length, k ), 1 )], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx + move32(); + j = add( j, 1 ); } } Word16 norm_shift = norm_l( frame_gain_fx ); - IF( frame_gain_fx == 0 ) + if ( frame_gain_fx == 0 ) { norm_shift = 31; + move16(); } norm_shift = s_min( norm_shift, 14 ); norm_shift = sub( norm_shift, 1 ); *Q_new = add( *Q_inp, sub( norm_shift, 13 ) ); // Q_new = Q_inp + min(norm_shift,14) - 14; - + move16(); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - overlap_fx[i] = L_shl( overlap_fx[i], *Q_new - *Q_inp ); + overlap_fx[i] = L_shl( overlap_fx[i], sub( *Q_new, *Q_inp ) ); + move32(); } FOR( i = 0; i < l_shb_lahead; i++ ) @@ -1477,21 +1495,27 @@ void ScaleShapedSHB_32( synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[i] ) ); // Q_new synSHB_fx[i] = L_add( synSHB_fx[i], overlap_fx[i] ); synSHB_fx[i + l_shb_lahead] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new + move32(); + move32(); + move32(); } FOR( ; i < l_frame; i++ ) { synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new + move32(); } FOR( ; i < l_frame + l_shb_lahead; i++ ) { - synSHB_fx[i] = L_shl( synSHB_fx[i], *Q_new - *Q_inp ); + synSHB_fx[i] = L_shl( synSHB_fx[i], sub( *Q_new, *Q_inp ) ); overlap_fx[i - l_frame] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[l_frame + l_shb_lahead - 1 - i] ) ); // Q_new + move32(); + move32(); } *Q_inp = *Q_new; - + move16(); return; } #endif diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index fe77f49185cc8aa3b197088d25a5d18a34fe780c..b5f418fc6fcab569153193caffa1eed8f5fac008 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -8,8 +8,7 @@ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" @@ -204,6 +203,7 @@ void tbe_celp_exc( tmp_fx = extract_l( L_mult( tmp_fx, 5 ) ); /*Q5, 2.5 in Q1*/ tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*Q5*/ *error_fx = add( *error_fx, tmp_fx ); /*Q5*/ + move16(); } ELSE { @@ -233,6 +233,7 @@ void tbe_celp_exc( tmp_fx = shl( tmp_fx, 2 ); /*now above tmp_fx in Q5*/ tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/ *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ + move16(); } } @@ -290,6 +291,7 @@ void tbe_celp_exc_ivas( tmp_fx = extract_l( L_mult( tmp_fx, 5 ) ); /*Q5, 2.5 in Q1*/ tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*Q5*/ *error_fx = add( *error_fx, tmp_fx ); /*Q5*/ + move16(); } ELSE { @@ -319,6 +321,7 @@ void tbe_celp_exc_ivas( tmp_fx = shl( tmp_fx, 2 ); /*now above tmp_fx in Q5*/ tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/ *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ + move16(); } } @@ -398,6 +401,7 @@ void flip_and_downmix_generic_fx( FOR( i = 0; i < HILBERT_ORDER1; i++ ) { tmp_16[i] = extract_h( mem1_ext[i] ); /* mem1_ext (Qx+16) tmp16 (Qx) */ + move16(); } /* Hilber transform stage - 0 - single precision */ @@ -411,6 +415,7 @@ void flip_and_downmix_generic_fx( FOR( i = 0; i < HILBERT_ORDER1; i++ ) { mem1_ext[i] = L_deposit_h( tmp_16[i + length] ); /* mem1_ext (Qx+16) tmp16 (Qx) */ + move32(); } Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); @@ -467,6 +472,7 @@ void flip_and_downmix_generic_fx( L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ output[i] = round_fx( L_tmp ); /*Qx */ + move16(); i++; j++; } @@ -854,6 +860,7 @@ static void filt_mu_fx( Word16 tmp, exp; #ifdef FIX_729_MISSING_RESCALING Flag Overflow = 0; + move32(); #endif @@ -897,13 +904,6 @@ static void filt_mu_fx( temp = add( temp, *ptrs ); /*Q12 */ #ifdef FIX_729_MISSING_RESCALING sig_out[n] = shl_o( mult_r( ga, temp ), 1, &Overflow ); -#ifdef DEBUGGING - if ( Overflow ) - { - fprintf( stderr, "Saturation in filt_mu_fx for ga = %d, temp = %d, result = %.2f at frame %d\n\n", ga, temp, (float) ga * temp * 4.0 / 65536.0, frame ); - Overflow = 0; - } -#endif #else sig_out[n] = shl( mult_r( ga, temp ), 1 ); #endif @@ -1012,6 +1012,7 @@ static void scale_st_swb( L_temp = L_shl( L_temp, 1 ); /*14 + Q_bwe_exc +1 */ sig_out_fx[i] = round_fx( L_temp ); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ #endif + move16(); } *gain_prec_fx = gain_fx; move16(); @@ -1240,6 +1241,7 @@ void ivas_GenShapedWBExcitation_fx( FOR( i = 0; i < L_FRAME16k / 4; i++ ) { exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) ); /*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */ + move16(); } } } @@ -1266,6 +1268,7 @@ void ivas_GenShapedWBExcitation_fx( /* Ensure pow1 is greater than zero when computing normalization */ max_val = 0; + move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { excTmp2[i] = abs_s( exc4kWhtnd[i] ); @@ -1295,6 +1298,7 @@ void ivas_GenShapedWBExcitation_fx( } n1 = sub( sub( 14, n1 ), Q_bwe_exc ); pow1 = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1348,9 +1352,11 @@ void ivas_GenShapedWBExcitation_fx( #else exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ #endif + move16(); } n2 = 30 - n2 - ( Q_bwe_exc + 6 ); pow22 = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1381,6 +1387,7 @@ void ivas_GenShapedWBExcitation_fx( #else exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ #endif + move16(); } } ELSE @@ -1433,6 +1440,7 @@ void ivas_GenShapedWBExcitation_fx( L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */ #endif + move16(); k++; } } @@ -1487,6 +1495,7 @@ void GenShapedWBExcitation_fx( Word16 avg_voice_fac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ @@ -1528,6 +1537,7 @@ void GenShapedWBExcitation_fx( FOR( i = 0; i < L_FRAME16k / 4; i++ ) { exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) ); /*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */ + move16(); } } } @@ -1583,6 +1593,7 @@ void GenShapedWBExcitation_fx( } n1 = sub( sub( 14, n1 ), Q_bwe_exc ); pow1 = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1636,9 +1647,11 @@ void GenShapedWBExcitation_fx( #else exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ #endif + move16(); } n2 = 30 - n2 - ( Q_bwe_exc + 6 ); pow22 = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1669,6 +1682,7 @@ void GenShapedWBExcitation_fx( #else exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ #endif + move16(); } } ELSE @@ -1676,6 +1690,7 @@ void GenShapedWBExcitation_fx( sc = sub( add( n2, Q_bwe_exc ), 14 ); /* Q_bwe_exc+n2-14*/ k = 0; + move16(); FOR( i = 0; i < 4; i++ ) { test(); @@ -1721,6 +1736,7 @@ void GenShapedWBExcitation_fx( L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */ #endif + move16(); k++; } } @@ -1943,10 +1959,14 @@ void GenShapedSHBExcitation_fx( Word16 excTmp2[L_FRAME16k]; Word16 *White_exc16k; Word16 excNoisyEnv[L_FRAME16k]; - Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + move16(); Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ + move16(); + move16(); Word16 varEnvShape; Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ + move16(); Word16 exc16kWhtnd[L_FRAME16k]; Word32 L_tmp; @@ -2027,6 +2047,7 @@ void GenShapedSHBExcitation_fx( FOR( i = 0; i < 80; i++ ) { exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); + move16(); /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ } temp2 = add( temp2, 80 ); @@ -2231,6 +2252,7 @@ void GenShapedSHBExcitation_fx( if ( L_tmp == 0 ) { Q_temp = 31; + move16(); } /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ /* White_exc16k in Q6 */ @@ -2355,10 +2377,13 @@ void GenShapedSHBExcitation_fx( Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); tmp = voiceFacEst[0]; + move16(); tmp2 = MAX_16; + move16(); if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { tmp2 = 26214 /*0.8f Q15*/; + move16(); } } } @@ -2383,9 +2408,11 @@ void GenShapedSHBExcitation_fx( /* *vf_ind is an integer scale by 0.125f*/ tmp = shl( *vf_ind, ( 15 - 3 ) ); tmp2 = MAX_16; + move16(); if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { tmp2 = 26214 /*0.8f Q15*/; + move16(); } } } @@ -2420,8 +2447,9 @@ void GenShapedSHBExcitation_fx( White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + move16(); *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); - + move16(); deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ @@ -2479,9 +2507,10 @@ void GenShapedSHBExcitation_fx( L_tmp = L_mult( White_exc16k[k], scale ); /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); + move16(); /* exc16kWhtnd: Q_bwe_exc */ } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); /* i/o: exc16kWhtnd (Q_bwe_exc) */ /* i/o: tbe_premph (Q_bwe_exc) */ } @@ -2507,9 +2536,11 @@ void GenShapedSHBExcitation_fx( IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) { exp = 0; + move16(); tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ exp = 0; + move16(); tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ @@ -2532,6 +2563,7 @@ void GenShapedSHBExcitation_fx( vf_tmp = mult_r( voice_factors[i], vf_tmp ); exp = 0; + move16(); tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ @@ -2565,6 +2597,7 @@ void GenShapedSHBExcitation_fx( /* estimate the pre-emph factor */ tempQ15 = sub( MAX_16, voice_factors[i] ); exp = 0; + move16(); temp = Sqrt16( tempQ15, &exp ); temp = shl( temp, exp - 1 ); @@ -2572,7 +2605,7 @@ void GenShapedSHBExcitation_fx( temp = div_s( temp, temp2 ); /* Q15 */ temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); + PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); /* exc16kWhtnd: Q_bwe_exc; tbe_premph: Q_bwe_exc*/ } @@ -2757,8 +2790,11 @@ void GenShapedSHBExcitation_ivas_fx( Word16 excTmp2[L_FRAME16k]; Word16 *White_exc16k; Word16 excNoisyEnv[L_FRAME16k]; - Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + Word16 csfilt_num2[1] = { 6554 }; /*0.2 in Q15 */ + move16(); Word16 neg_csfilt_den2[2] = { -32767, 26214 }; /* {1.0f, -0.8f} */ + move16(); + move16(); Word16 varEnvShape; Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ Word16 exc16kWhtnd[L_FRAME16k]; @@ -2766,6 +2802,7 @@ void GenShapedSHBExcitation_ivas_fx( Word32 L_tmp; Word16 vf_tmp; Word16 tmp, exp, tmp2 = 0; + move16(); Word16 voiceFacEst[NB_SUBFR16k]; Word16 zero_mem[LPC_SHB_ORDER]; Word32 syn_shb_ener_sf[4]; @@ -2792,6 +2829,7 @@ void GenShapedSHBExcitation_ivas_fx( Word16 c0_part[NUM_SHB_SUBGAINS], c1_part[NUM_SHB_SUBGAINS], c2_part[NUM_SHB_SUBGAINS], c3_part[NUM_SHB_SUBGAINS], c4_part[NUM_SHB_SUBGAINS], c5_part[NUM_SHB_SUBGAINS]; mix_factor = 0; + move16(); #endif set16_fx( zero_mem, 0, LPC_SHB_ORDER ); set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); @@ -2840,6 +2878,7 @@ void GenShapedSHBExcitation_ivas_fx( FOR( i = 0; i < 80; i++ ) { exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); + move16(); /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ } temp2 = add( temp2, 80 ); @@ -2956,13 +2995,18 @@ void GenShapedSHBExcitation_ivas_fx( { // varEnvShape = 0.995f; varEnvShape = 32604; - // csfilt_num2[0] = 1.0f - varEnvShape; + move16(); csfilt_num2[0] = 32768 - varEnvShape; + // csfilt_num2[0] = sub( 32767, varEnvShape ); + move16(); neg_csfilt_den2[1] = varEnvShape; + move16(); } White_exc16k = exc16k; - Word16 Q_excTmp2 = getScaleFactor16( excTmp2, L_FRAME16k ) + *Q_bwe_exc; + move16(); + Word16 Q_excTmp2 = add( getScaleFactor16( excTmp2, L_FRAME16k ), *Q_bwe_exc ); + test(); /* Track the low band envelope */ IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) { @@ -2970,25 +3014,32 @@ void GenShapedSHBExcitation_ivas_fx( { mem_csfilt_left = 0; mem_csfilt_right = 0; + move16(); + move16(); FOR( k = 0; k < L_FRAME16k; k++ ) { // excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k]; excNoisyEnvLeft[k] = add( mem_csfilt_left, mult_r( csfilt_num2[0], shl( excTmp2[k], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + move16(); // mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k]; mem_csfilt_left = mult_r( neg_csfilt_den2[1], excNoisyEnvLeft[k] ); // Q_excTmp2 // excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1]; excNoisyEnvRight[L_FRAME16k - k - 1] = add( mem_csfilt_right, mult_r( csfilt_num2[0], shl( excTmp2[L_FRAME16k - k - 1], sub( Q_excTmp2, *Q_bwe_exc ) ) ) ); // Q_excTmp2 + move16(); // mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1]; mem_csfilt_right = mult_r( neg_csfilt_den2[1], excNoisyEnvRight[L_FRAME16k - k - 1] ); // Q_excTmp2 } alpha = 0; + move16(); // step = 1.0f / L_FRAME16k; step = 102; // Q15 + move16(); FOR( k = 0; k < L_FRAME16k; k++ ) { // excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k]; - excNoisyEnv[k] = add( mult_r( alpha, excNoisyEnvLeft[k] ), mult_r( ( 32767 - alpha ), excNoisyEnvRight[k] ) ); // Q_excTmp2 + excNoisyEnv[k] = add( mult_r( alpha, excNoisyEnvLeft[k] ), mult_r( sub( 32767, alpha ), excNoisyEnvRight[k] ) ); // Q_excTmp2 + move16(); alpha = add( alpha, step ); } } @@ -3011,20 +3062,25 @@ void GenShapedSHBExcitation_ivas_fx( move32(); } #if 1 // def ADD_IVAS_TBE_CODE - IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { /* generate gaussian (white) excitation */ FOR( k = 0; k < L_FRAME16k; k++ ) { White_exc16k[k] = own_random( &bwe_seed[0] ); + move16(); } /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT; + move32(); + move32(); pow22 = POW_EXC16k_WHTND_FX; Q_pow22 = -6; + move16(); // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); - Word16 pow1_exp = Q31 - Q_pow1; + Word16 pow1_exp = sub( Q31, Q_pow1 ); Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); temp_pow = L_shl( Mpy_32_32( temp_pow, pow22_inv ), pow1_exp ); /*Word16 out_exp; @@ -3032,16 +3088,20 @@ void GenShapedSHBExcitation_ivas_fx( temp_pow1 = L_shl(temp_pow1, out_exp);*/ // v_multc_fixed_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); L_tmp = 0; + move32(); FOR( k = 0; k < L_FRAME16k; k++ ) { White_exc16k_32[k] = L_mult( White_exc16k[k], round_fx( temp_pow ) ); + move32(); White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], *Q_bwe_exc - NOISE_QADJ ) ); // Q_bwe_exc - NOISE_QADJ + move16(); L_tmp = max( L_tmp, L_abs( White_exc16k_32[k] ) ); } Q_temp = norm_l( L_tmp ); IF( L_tmp == 0 ) { Q_temp = 31; + move16(); } } ELSE @@ -3049,6 +3109,7 @@ void GenShapedSHBExcitation_ivas_fx( { /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; + move16(); create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); @@ -3073,6 +3134,7 @@ void GenShapedSHBExcitation_ivas_fx( IF( L_tmp == 0 ) { Q_temp = 31; + move16(); } /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ /* White_exc16k in Q6 */ @@ -3225,22 +3287,28 @@ void GenShapedSHBExcitation_ivas_fx( ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); tmp = voiceFacEst[0]; tmp2 = MAX_16; + move16(); + move16(); if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { tmp2 = 26214 /*0.8f Q15*/; + move16(); } } } ELSE /* decoder side */ { + test(); #if 1 // def ADD_IVAS_TBE_CODE - IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { IF( *vf_ind == 0 ) { // mix_factor = 0.0f; mix_factor = 0; + move16(); flag_plosive = 1; + move16(); } ELSE { @@ -3254,9 +3322,11 @@ void GenShapedSHBExcitation_ivas_fx( /* *vf_ind is an integer scale by 0.125f*/ tmp = shl( *vf_ind, ( 15 - 3 ) ); tmp2 = MAX_16; + move16(); IF( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { tmp2 = 26214 /*0.8f Q15*/; + move16(); } } } @@ -3277,7 +3347,7 @@ void GenShapedSHBExcitation_ivas_fx( } } #if 1 // def ADD_IVAS_TBE_CODE - IF( element_mode >= IVAS_CPE_DFT && nlExc16k != NULL ) + IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL ) { /* save buffers for IC-BWE */ // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); @@ -3292,6 +3362,7 @@ void GenShapedSHBExcitation_ivas_fx( FOR( k = 0; k < L_FRAME16k; k++ ) { mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); + move16(); } } #endif @@ -3302,13 +3373,15 @@ void GenShapedSHBExcitation_ivas_fx( White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + move16(); *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); - + move16(); deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ #if 1 // def ADD_IVAS_TBE_CODE - IF( extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75 ) + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) { IF( !flag_plosive ) /* use only LB excitation in case of plosives */ { @@ -3322,17 +3395,20 @@ void GenShapedSHBExcitation_ivas_fx( old_scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 // new_scale = 1.0f; new_scale = 32767; + move16(); // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); step_scale = mult_r( sub( new_scale, old_scale ), 205 ); scale = old_scale; - + move16(); /* interpolate between the old and the new value of the mixing factor */ old_fact = *prev_mix_factor; + move16(); new_fact = mix_factor; + move16(); // step = (new_fact - old_fact) / (L_FRAME16k / 2); step = mult_r( sub( new_fact, old_fact ), 205 ); fact = old_fact; - + move16(); /* mixing of LB and gaussian excitation in the first half of the frame */ FOR( k = 0; k < L_FRAME16k / 2; k++ ) { @@ -3341,6 +3417,7 @@ void GenShapedSHBExcitation_ivas_fx( L_tmp = L_add( L_shl( L_mult( fact, mult_r( White_exc16k[k], scale ) ), NOISE_QADJ ), L_mult( sub( 32767, fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc exc16kWhtnd[k] = round_fx( L_tmp ); + move16(); fact = add_sat( fact, step ); scale = add_sat( scale, step_scale ); } @@ -3353,10 +3430,11 @@ void GenShapedSHBExcitation_ivas_fx( L_tmp = L_add( L_shl( L_mult( new_fact, White_exc16k[k] ), NOISE_QADJ ), mult_r( sub( 32767, new_fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc exc16kWhtnd[k] = round_fx( L_tmp ); + move16(); } } // preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); } ELSE #endif @@ -3379,9 +3457,10 @@ void GenShapedSHBExcitation_ivas_fx( L_tmp = L_mult( White_exc16k[k], scale ); /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); + move16(); /* exc16kWhtnd: Q_bwe_exc */ } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); /* i/o: exc16kWhtnd (Q_bwe_exc) */ /* i/o: tbe_premph (Q_bwe_exc) */ } @@ -3393,6 +3472,8 @@ void GenShapedSHBExcitation_ivas_fx( /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ nbSubFr = NB_SUBFR16k; lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + move16(); + move16(); IF( LT_32( bitrate, ACELP_24k40 ) ) { nbSubFr = NB_SUBFR; @@ -3401,15 +3482,18 @@ void GenShapedSHBExcitation_ivas_fx( move16(); } k = 0; + move16(); FOR( i = 0; i < nbSubFr; i++ ) { test(); IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) { exp = 0; + move16(); tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ exp = 0; + move16(); tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ @@ -3432,6 +3516,7 @@ void GenShapedSHBExcitation_ivas_fx( vf_tmp = mult_r( voice_factors[i], vf_tmp ); exp = 0; + move16(); tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ @@ -3465,6 +3550,7 @@ void GenShapedSHBExcitation_ivas_fx( /* estimate the pre-emph factor */ tempQ15 = sub( MAX_16, voice_factors[i] ); exp = 0; + move16(); temp = Sqrt16( tempQ15, &exp ); temp = shl( temp, exp - 1 ); @@ -3472,7 +3558,7 @@ void GenShapedSHBExcitation_ivas_fx( temp = div_s( temp, temp2 ); /* Q15 */ temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); + PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); /* exc16kWhtnd: Q_bwe_exc; tbe_premph: Q_bwe_exc*/ } @@ -3534,6 +3620,7 @@ void GenShapedSHBExcitation_ivas_fx( { L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); } } /* i: L_tmp2 in (Q31-exp) */ @@ -3756,6 +3843,7 @@ void ScaleShapedSHB_fx( move16(); sum_gain = 0; + move16(); FOR( k = 0; k < length / 2; k++ ) { sum_gain = mult_r( subwin[2 * k + 2], subgain[0] ); /* Q15 */ @@ -3843,7 +3931,10 @@ void ScaleShapedSHB_fx( Q_gFr_norm = norm_l( frame_gain ); if ( frame_gain == 0 ) + { Q_gFr_norm = 31; + move16(); + } Q_gFr_norm = sub( Q_gFr_norm, 1 ); /* give some headroom */ gain_frame_Q16 = round_fx( L_shl( frame_gain, Q_gFr_norm ) ); /* Q = 18 + Q_gFr_norm - 16 @@ -3861,14 +3952,16 @@ void ScaleShapedSHB_fx( } *Qx = *Q_bwe_exc; - + move16(); /* rescale the overlap memory */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { temp2 = 1; + move16(); if ( overlap[i] < 0 ) { temp2 = -1; + move16(); } temp1 = abs_s( overlap[i] ); temp1 = shl( temp1, ( *Q_bwe_exc - prev_Q_bwe_syn2 ) ); @@ -3883,12 +3976,14 @@ void ScaleShapedSHB_fx( synSHB[i] = mac_r( L_tmp2, overlap[i], MAX_16 ); move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ synSHB[i + l_shb_lahead] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ + move16(); } FOR( ; i < l_frame; i++ ) { L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16 ); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ synSHB[i] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ + move16(); } l_frame_tmp = add( l_frame, l_shb_lahead ); @@ -4060,6 +4155,7 @@ void ScaleShapedWB_fx( { shift = sub( 13, Q_bwe_exc ); /* earlier = (10 - Q_bwe_exc) but we changed GainFrame Q21 to Q18 */ *Qx = 0; + move16(); } ELSE IF( EQ_16( L_frame, L_FRAME ) ) /* 12.8k core */ { @@ -4075,6 +4171,7 @@ void ScaleShapedWB_fx( shift = s_min( min_shift, max_shift2 ); *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + move16(); } ELSE /* 16k core */ { @@ -4083,17 +4180,21 @@ void ScaleShapedWB_fx( /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 3 */ min_shift = 3 - ( Q_bwe_exc + 3 - 16 ); + move16(); max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + move16(); max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min( min_shift, max_shift2 ); *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + move16(); } /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */ FOR( i = 0; i < l_shb_lahead; i++ ) { overlap[i] = shl( overlap[i], ( *Qx - prev_Qx ) ); + move16(); } FOR( i = 0; i < l_shb_lahead; i++ ) @@ -4102,6 +4203,7 @@ void ScaleShapedWB_fx( L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ #ifdef BASOP_NOGLOB synSHB[i] = round_fx_sat( L_shl_sat( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ + move16(); synSHB[i] = add_sat( synSHB[i], overlap[i] ); move16(); /* Qx */ synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ @@ -4121,6 +4223,7 @@ void ScaleShapedWB_fx( #else synSHB[i] = round_fx( L_shl( L_tmp, shift ) ); /* Qx; */ #endif + move16(); } l_frame_tmp = add( l_frame, l_shb_lahead ); @@ -4132,6 +4235,7 @@ void ScaleShapedWB_fx( #else overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ #endif + move16(); } return; @@ -4392,6 +4496,7 @@ void non_linearity_fx( Word16 length_half; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -4931,6 +5036,7 @@ void create_random_vector_fx( j = s_and( j, 0xff ); k = s_and( k, 0xff ); output[i] = round_fx( L_add( L_mult( scale1, gaus_dico_swb_fx[j] ), L_mult( scale2, gaus_dico_swb_fx[k] ) ) ); /*Q5 */ + move16(); j++; k++; } @@ -4972,19 +5078,29 @@ void interp_code_5over2_fx( Word16 i, kk, kkp1, i_len2; Word32 Ltemp; Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; - + move16(); + move16(); + move16(); + move16(); + move16(); interp_code_fx[0] = inp_code_fx[0]; move16(); /* Qx */ Ltemp = L_mult( inp_code_fx[0], factor_i_fx[3] ); /* Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[3] ); /* Q(16+x) */ interp_code_fx[1] = round_fx( Ltemp ); /*Qx */ - + move16(); Ltemp = L_mult( inp_code_fx[0], factor_i_fx[4] ); /*Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[4] ); /*Q(16+x) */ interp_code_fx[2] = round_fx( Ltemp ); /* Qx */ - + move16(); kk = 1; move16(); kkp1 = 2; @@ -5000,35 +5116,35 @@ void interp_code_5over2_fx( Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] ); /*Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[0] ); /*Q(16+x) */ interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ - + move16(); Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[1] ); /*Q(16+x) */ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ - + move16(); Ltemp = L_mult( inp_code_fx[kkp1], factor_i_fx[2] ); /*Q(16+x) */ interp_code_fx[i + 2] = round_fx( Ltemp ); /*Qx */ - + move16(); kk++; kkp1++; Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[3] ); /*Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[3] ); /*Q(16+x) */ interp_code_fx[i + 3] = round_fx( Ltemp ); /*Qx */ - + move16(); Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[4] ); /*Q(16+x) */ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[4] ); /*Q(16+x) */ interp_code_fx[i + 4] = round_fx( Ltemp ); /*Qx */ - + move16(); kk++; kkp1++; } Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] ); /*Q(16+x) */ interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ - + move16(); Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ - + move16(); return; } @@ -5134,6 +5250,11 @@ void elliptic_bpf_48k_generic_fx( memory2_fx[1][i] = L_shl_sat( memory_fx2[1][i], sub( add( *Q_input_fx, 11 ), memory_fx_Q[1] ) ); memory2_fx[2][i] = L_shl_sat( memory_fx2[2][i], sub( add( *Q_input_fx, 6 ), memory_fx_Q[2] ) ); memory2_fx[3][i] = L_shl_sat( memory_fx2[3][i], sub( add( *Q_input_fx, 1 ), memory_fx_Q[3] ) ); + move32(); + move32(); + move32(); + move32(); + move32(); #else memory_fx[0][i] = shl( memory_fx0[0][i], sub( *Q_input_fx, memory_fx_Q[0] ) ); memory2_fx[1][i] = L_shl( memory_fx2[1][i], sub( add( *Q_input_fx, 11 ), memory_fx_Q[1] ) ); @@ -5247,7 +5368,11 @@ void elliptic_bpf_48k_generic_fx( memory_fx2[0][1] = input_fx[sub( L_FRAME48k, 3 )]; memory_fx2[0][2] = input_fx[sub( L_FRAME48k, 2 )]; memory_fx2[0][3] = input_fx[sub( L_FRAME48k, 1 )]; - + move32(); + move32(); + move32(); + move32(); + move32(); L_tmpX = L_shr( Mult_32_16( memory2_fx[1][0], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ L_tmpX = L_add( L_shr( Mult_32_16( memory2_fx[1][1], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ L_tmpX = L_add( L_shr( Mult_32_16( memory2_fx[1][2], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ @@ -5364,7 +5489,11 @@ void elliptic_bpf_48k_generic_fx( memory_fx2[1][1] = L_tmp[sub( L_FRAME48k, 3 )]; memory_fx2[1][2] = L_tmp[sub( L_FRAME48k, 2 )]; memory_fx2[1][3] = L_tmp[sub( L_FRAME48k, 1 )]; - + move32(); + move32(); + move32(); + move32(); + move32(); FOR( j = 0; j < 4; j++ ) { #ifdef BASOP_NOGLOB @@ -5374,6 +5503,9 @@ void elliptic_bpf_48k_generic_fx( memory2_fx_2[j] = L_shl( memory_fx2[2][j], sub( add( add( *Q_input_fx, 6 ), Q_temp ), memory_fx_Q[2] ) ); memory2_fx_3[j] = L_shl( memory_fx2[3][j], sub( add( add( *Q_input_fx, 1 ), Q_temp ), memory_fx_Q[3] ) ); #endif + move32(); + move32(); + move32(); } #ifdef BASOP_NOGLOB L_tmpX = L_shr( Mult_32_16( memory2_fx_2[0], full_band_bpf_fx[2][4] ), 3 ); /* *Q_input_fx+6 +Q_temp +13 -15 -3 */ @@ -5516,19 +5648,32 @@ void elliptic_bpf_48k_generic_fx( memory_fx2[3][1] = L_output[sub( L_FRAME48k, 3 )]; memory_fx2[3][2] = L_output[sub( L_FRAME48k, 2 )]; memory_fx2[3][3] = L_output[sub( L_FRAME48k, 1 )]; - + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); memory_fx_Q[0] = *Q_input_fx; memory_fx_Q[1] = add( *Q_input_fx, 11 ); memory_fx_Q[2] = add( add( *Q_input_fx, 6 ), Q_temp ); memory_fx_Q[3] = add( add( *Q_input_fx, 1 ), Q_temp ); - + move16(); + move16(); + move16(); + move16(); Q_temp2 = norm_l( L_tmpMax ); Scale_sig32( L_output, 960, Q_temp2 ); FOR( i = 0; i < 960; i++ ) { output_fx[i] = extract_h( L_output[i] ); + move16(); } *Q_input_fx = sub( add( add( *Q_input_fx, Q_temp ), Q_temp2 ), 15 ); + move16(); /* BASOP_NOGLOB */ return; } @@ -5642,6 +5787,7 @@ void synthesise_fb_high_band_fx( { #ifdef BASOP_NOGLOB output[i] = negate( extract_h( L_shl_sat( L_negate( L_tmp ), tmp3 ) ) ); /*Qout*/ + move16(); #else output[i] = negate( extract_h( L_shl( L_negate( L_tmp ), tmp3 ) ) ); /*Qout*/ #endif @@ -5650,6 +5796,7 @@ void synthesise_fb_high_band_fx( { #ifdef BASOP_NOGLOB output[i] = extract_h( L_shl_sat( L_tmp, tmp3 ) ); /*Qout*/ + move16(); #else output[i] = extract_h( L_shl( L_tmp, tmp3 ) ); /*Qout*/ #endif @@ -5687,6 +5834,7 @@ void Estimate_mix_factors_fx( Word32 L_tmp1, L_tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Copy( shb_res, shb_res_local, L_FRAME16k ); @@ -5699,6 +5847,7 @@ void Estimate_mix_factors_fx( if ( pow3 == 0 ) { pow3 = 1; + move32(); } /* temp_p1_p2 = (float)sqrt(pow1/pow2); */ @@ -5710,21 +5859,23 @@ void Estimate_mix_factors_fx( sc1 = Q_bwe_exc - ( Q_frac - exp1 ); sc2 = Q_bwe_exc - ( Q_shb - exp2 ); - + move16(); + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( temp_p1_p2, WN_exc_local[i] ); /* (Q_frac - exp1) +16 */ WN_exc_local[i] = round_fx( L_tmp1 ); - + move16(); L_tmp2 = Mult_32_16( temp_p1_p3, shb_res_local[i] ); /* (Q_shb - exp2) +16 */ shb_res_local[i] = round_fx( L_tmp2 ); - + move16(); /* temp_numer1[i] = sub(shb_res_local[i], WN_exc_local[i]); */ #ifdef BASOP_NOGLOB temp_numer1[i] = round_fx_sat( L_sub_sat( L_shl_sat( L_tmp2, sc2 ), L_shl_sat( L_tmp1, sc1 ) ) ); #else temp_numer1[i] = round_fx( L_sub( L_shl( L_tmp2, sc2 ), L_shl( L_tmp1, sc1 ) ) ); #endif + move16(); /* (Q_bwe_exc) */ /* temp_numer2[i] = sub(exc16kWhtnd[i], WN_exc_local[i]); */ @@ -5796,6 +5947,7 @@ void Estimate_mix_factors_fx( ELSE { tmp = 0; + move16(); } vf_modified[0] = s_min( s_max( tmp, 3277 /* 0.1f in Q15*/ ), 32440 /* 0.99f in Q15 */ ); @@ -5929,6 +6081,7 @@ void prep_tbe_exc_fx( Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; Word16 tmp_code_preInt_fx[L_SUBFR]; Word16 gain_code16 = 0; + move16(); Word16 tmp /*, tmp1, tmp2*/; /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ Word16 pitch; @@ -5938,9 +6091,11 @@ void prep_tbe_exc_fx( Word16 tempQ15; #ifndef ADD_IVAS_TBE_CODE Word16 L_subfr = L_SUBFR; + move16(); #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; @@ -5950,7 +6105,7 @@ void prep_tbe_exc_fx( tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); - + move16(); tmp = 32767; move16(); @@ -5967,6 +6122,7 @@ void prep_tbe_exc_fx( tmp = MAX_16; move16(); *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); + move16(); } *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); @@ -6007,6 +6163,7 @@ void prep_tbe_exc_fx( L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ #endif /* BASOP_NOGLOB */ + move16(); } } ELSE @@ -6165,6 +6322,7 @@ void prep_tbe_exc_ivas_fx( tmp = MAX_16; move16(); *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); + move16(); } *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); @@ -6200,6 +6358,7 @@ void prep_tbe_exc_ivas_fx( L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ #endif /* BASOP_NOGLOB */ + move16(); } } ELSE @@ -6213,8 +6372,8 @@ void prep_tbe_exc_ivas_fx( Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, 4 ) /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ #else /* BASOP_NOGLOB */ @@ -6223,6 +6382,7 @@ void prep_tbe_exc_ivas_fx( tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ #endif /* BASOP_NOGLOB */ + move16(); } } ELSE @@ -6232,22 +6392,23 @@ void prep_tbe_exc_ivas_fx( /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ #else Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( Ltemp1 ); /* Q_exc */ #endif + move16(); } } interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ - FOR( i = 0; i < L_subfr * 2; i++ ) + FOR( i = 0; i < shl( L_subfr, 1 ); i++ ) { - L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2] ); /*Q14+Q_exc+1 */ + L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + shl( i_subfr_fx, 1 )] ); /*Q14+Q_exc+1 */ #ifdef BASOP_NOGLOB tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ + bwe_exc_fx[i + shl( i_subfr_fx, 1 )] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ move16(); #else /* BASOP_NOGLOB */ tmp = round_fx( L_shl( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ ) ); /* tmp in Q_exc */ diff --git a/lib_com/syn_12k8_fx.c b/lib_com/syn_12k8_fx.c index f990b0bc9618a3cebb7848d2c388d177d30e720d..86d4c6ef76bbc06a53d7f2bee16af0a546b985ea 100644 --- a/lib_com/syn_12k8_fx.c +++ b/lib_com/syn_12k8_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*===========================================================================*/ diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 5b7fcc4c3a1e6f3d43b487228a71392626efb6dd..e3a3024ba5cdfb351995551dfd5b5baf2e3a3d5f 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stl.h" static Word32 syn_kern_2( Word32 L_tmp, const Word16 a[], const Word16 y[] ) @@ -150,6 +149,7 @@ void syn_filt_s_lc_fx( L_tmp = L_shl( L_tmp, q ); *y++ = round_fx( L_tmp ); #endif + move16(); } FOR( ; i < lg; i++ ) @@ -162,6 +162,7 @@ void syn_filt_s_lc_fx( L_tmp = L_shl( L_tmp, q ); *y++ = round_fx( L_tmp ); #endif + move16(); } } @@ -213,6 +214,7 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W Word32 ( *syn_kern )( Word32 L_tmp, const Word16 a[], const Word16 y[] ) = NULL; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif if ( EQ_16( m, 6 ) ) @@ -257,6 +259,7 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W L_tmp = L_shl( L_tmp, q ); *y++ = round_fx( L_tmp ); #endif + move16(); /* Filtering from Input + Mix of Memory & Output Signal Past */ FOR( i = 1; i < m; i++ ) @@ -287,6 +290,7 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W L_tmp = L_shl( L_tmp, q ); *y++ = round_fx( L_tmp ); #endif + move16(); } /* Filtering from Input + Output Signal Past */ @@ -300,6 +304,7 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W L_tmp = L_shl( L_tmp, q ); *y++ = round_fx( L_tmp ); #endif + move16(); } /*-----------------------------------------------------------------------* @@ -378,6 +383,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] } L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = L_tmp; + move32(); } /* Filtering from Input + Output Signal Past */ @@ -386,6 +392,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, y ); L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = L_tmp; + move32(); } /*-----------------------------------------------------------------------* @@ -452,12 +459,12 @@ void ivas_synth_mem_updt2_fx( } ELSE { - en1_e = 30 - 2 * Q; - en2_e = 30 - 2 * Q; + en1_e = sub( 30, shl( Q, 1 ) ); + en2_e = sub( 30, shl( Q, 1 ) ); tmp1 = Sqrt32( en1, &en1_e ); tmp2 = Sqrt32( en2, &en2_e ); tmp = BASOP_Util_Divide3232_Scale( tmp1, tmp2, &tmp_e ); - loc_rat_e = en1_e - en2_e + tmp_e; + loc_rat_e = add( sub( en1_e, en2_e ), tmp_e ); loc_rat = shl_sat( tmp, loc_rat_e ); // Q15 } @@ -466,6 +473,7 @@ void ivas_synth_mem_updt2_fx( { // mem_syn_r[L_SYN_MEM - M + i] *= loc_rat; mem_syn_r[L_SYN_MEM - M + i] = mult_r( mem_syn_r[L_SYN_MEM - M + i], loc_rat ); + move16(); } } } diff --git a/lib_com/tcq_position_arith.c b/lib_com/tcq_position_arith.c index 4c9764face91a612527b5411a78e8a49f0b0fd1b..4368c569feb246a830b28400a4a4a19ede102dae 100644 --- a/lib_com/tcq_position_arith.c +++ b/lib_com/tcq_position_arith.c @@ -61,9 +61,10 @@ static void set16_fx( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = a; + move16(); } return; @@ -76,9 +77,10 @@ static void set32_fx( ) { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = a; + move16(); } return; @@ -97,15 +99,15 @@ Word32 ar_div_ivas( num = L_abs( num ); denum = L_abs( denum ); - if ( L_sub( num, denum ) < 0 || denum == 0 ) + IF( L_sub( num, denum ) < 0 || denum == 0 ) { return 0; } - else if ( L_sub( num, denum ) == 0 ) + ELSE IF( L_sub( num, denum ) == 0 ) { return 1; } - else + ELSE { exp1 = norm_l( num ); exp2 = norm_l( denum ); @@ -113,16 +115,17 @@ Word32 ar_div_ivas( denum = L_shl( denum, exp ); exp = add( exp, 1 ); varout = 0; - for ( i = 0; i < exp; i++ ) + move32(); + FOR( i = 0; i < exp; i++ ) { num = L_sub( num, denum ); varout = L_shl( varout, 1 ); - if ( num >= 0 ) + IF( num >= 0 ) { num = L_shl( num, 1 ); varout = L_add( varout, 1 ); } - else + ELSE { num = L_add( num, denum ); num = L_shl( num, 1 ); @@ -149,30 +152,35 @@ void srt_vec_ind_fx_ivas( Word32 valMem; /*initialize */ - for ( pos = 0; pos < length; pos++ ) + FOR( pos = 0; pos < length; pos++ ) { I[pos] = pos; + move16(); } - for ( pos = 0; pos < length; pos++ ) + FOR( pos = 0; pos < length; pos++ ) { srt[pos] = linear[pos]; + move32(); } /* now iterate */ - for ( pos = 0; pos < ( length - 1 ); pos++ ) + FOR( pos = 0; pos < sub( length, 1 ); pos++ ) { - for ( npos = ( pos + 1 ); npos < length; npos++ ) + FOR( npos = add( pos, 1 ); npos < length; npos++ ) { if ( L_sub( srt[npos], srt[pos] ) < 0 ) { idxMem = I[pos]; I[pos] = I[npos]; I[npos] = idxMem; - + move16(); + move16(); valMem = srt[pos]; srt[pos] = srt[npos]; srt[npos] = valMem; + move32(); + move32(); } } } @@ -189,14 +197,15 @@ static Word32 GetBitsFromPulses_fx( Word32 frac_fx32; Word32 logCoeff_fx; Word16 exp = 0; + move16(); Word32 mantissa_fx = 0; - - if ( m == 0 ) + move32(); + IF( m == 0 ) { return 0; } - for ( i = 0; i < min( m, n ); i++ ) + FOR( i = 0; i < min( m, n ); i++ ) { logCoeff_fx = L_add( L_shl( i + 1, 16 ), L_sub( table_logcum_fx[n + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[n - i] ) ) ); logCoeff_fx = L_add( logCoeff_fx, L_sub( table_logcum_fx[m], L_add( table_logcum_fx[i + 1], table_logcum_fx[m - i] ) ) ); /*Q16 */ @@ -220,22 +229,23 @@ static Word32 GetBitsFromPulses_fx( exp1 = norm_l( pow_getbitsfrompulses_fx[temp_fx1] ); exp2 = norm_l( frac_fx32 ); frac_fx32 = Mult_32_32( L_shl( pow_getbitsfrompulses_fx[temp_fx1], exp1 ), L_shl( frac_fx32, exp2 ) ); /*21 + exp1 + 30 + exp2 - 31 */ - frac_fx32 = L_shr( frac_fx32, exp1 + exp2 ) + 1; /*20 */ + frac_fx32 = L_add( L_shr( frac_fx32, add( exp1, exp2 ) ), 1 ); /*20 */ - if ( sub( exp, integer_fx ) < 0 ) + IF( sub( exp, integer_fx ) < 0 ) { mantissa_fx = L_shr( mantissa_fx, sub( integer_fx, exp ) ); mantissa_fx = L_add( mantissa_fx, frac_fx32 ); exp = integer_fx; + move16(); } - else + ELSE { mantissa_fx = L_add( mantissa_fx, L_shr( frac_fx32, sub( exp, integer_fx ) ) ); } if ( L_sub( mantissa_fx, 0x200000 ) >= 0 ) { - exp++; + exp = add( exp, 1 ); mantissa_fx = L_shr( mantissa_fx, 1 ); } @@ -246,14 +256,14 @@ static Word32 GetBitsFromPulses_fx( temp32 = L_shl( L_sub( mantissa_fx, L_deposit_h( temp_fx1 ) ), 15 ); /*31 */ exp1 = sub( norm_l( temp32 ), 1 ); temp32 = ar_div_ivas( L_shl( temp32, exp1 ), temp_fx1 ); /*31 + exp1 */ - temp32 = L_shr( temp32, exp1 + 1 ); /*30 */ + temp32 = L_shr( temp32, add( exp1, 1 ) ); /*30 */ frac_fx32 = L_sub( 0x40000000, L_shr( temp32, 1 ) ); /*30 */ frac_fx32 = Mult_32_32( frac_fx32, temp32 ); /*29 */ frac_fx32 = L_shr( frac_fx32, 13 ); /*16 */ exp1 = norm_l( temp_fx1 ); - temp_fx1 = Log2_norm_lc( L_shl( temp_fx1, exp1 ) ); /*15 */ - frac_fx32 = frac_fx32 + Mult_32_32( frac_fx32, 950680361 ); /* frac_fx32 *= 1/ln(2) */ + temp_fx1 = Log2_norm_lc( L_shl( temp_fx1, exp1 ) ); /*15 */ + frac_fx32 = L_add( frac_fx32, Mult_32_32( frac_fx32, 950680361 ) ); /* frac_fx32 *= 1/ln(2) */ return L_add( L_deposit_h( exp ), L_add( L_shl( temp_fx1, 1 ), frac_fx32 ) ); } @@ -273,138 +283,159 @@ void decode_position_ari_fx_ivas( Word32 cp, scp, fxone, fxp1; Word16 stpos = 0, pos, ovrflag, temppos, storepos; - + move16(); fxone = 32768; fxp1 = 512 * 32768; + move32(); + move32(); temppos = 0; storepos = 0; ovrflag = 0; - + move16(); + move16(); + move16(); set16_fx( mode_num_nz, 0, TCQ_MAX_BAND_SIZE ); set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { position[i] = 0; + move32(); } - if ( L_sub( npulses, 1 ) > 0 ) + IF( L_sub( npulses, 1 ) > 0 ) { btcq_fx = GetBitsFromPulses_fx( npulses, size ); - for ( i = 0; i < L_min( npulses, size ); i++ ) + FOR( i = 0; i < L_min( npulses, size ); i++ ) { /*calculate the probability of #nz */ pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[npulses - i] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ - if ( L_sub( pnzp_fx, 0 ) > 0 ) + IF( L_sub( pnzp_fx, 0 ) > 0 ) { integer = extract_h( pnzp_fx ); frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ prob[i] = extract_h( L_shl( Pow2( integer, frac ), 16 ) ); /*0 */ + move16(); if ( prob[i] == 0 ) { prob[i] = 1; + move16(); } } - else + ELSE { prob[i] = 1; + move16(); } } ar_make_model( prob, mode_num_nz, min( npulses, size ) ); *nz = add( 1, (Word16) ar_decode( pardec, mode_num_nz ) ); /*get #nz */ nzp = *nz; - - if ( nzp == 1 ) + move16(); + move16(); + IF( EQ_16( nzp, 1 ) ) { Word16 tmp; mode_num_nz[0] = MAX_AR_FREQ; - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { - tmp = div_l( L_deposit_h( size - i - 1 ), size ); + tmp = div_l( L_deposit_h( sub( sub( size, i ), 1 ) ), size ); mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( tmp ), 1 ) ); } position[ar_decode( pardec, mode_num_nz )] = 1; + move32(); } - else + ELSE { Word16 tmp; mode_num_nz[0] = MAX_AR_FREQ; - - for ( ; nzp > 0; nzp-- ) + move16(); + FOR( ; nzp > 0; nzp-- ) { scp = fxp1; + move32(); temppos = 0; storepos = 0; - - for ( i = stpos; i < size; i++ ) + move16(); + move16(); + FOR( i = stpos; i < size; i++ ) { ovrflag = 0; - - if ( nzp == ( size - i ) ) + move16(); + IF( EQ_16( nzp, sub( size, i ) ) ) { cp = 0; + move32(); } - else + ELSE { tmp = div_l( L_deposit_h( nzp ), ( size - i ) ); cp = L_sub( fxone, tmp ); } scp = Mult_32_16( scp, extract_l( cp ) ); - mode_num_nz[i + 1 - storepos - stpos] = round_fx( L_shl( scp, 6 ) ); + mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = round_fx( L_shl( scp, 6 ) ); - if ( ( mode_num_nz[i + 1 - storepos - stpos] == 0 && scp > 0 ) || mode_num_nz[i - storepos - stpos] == mode_num_nz[i + 1 - storepos - stpos] ) + IF( ( mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] == 0 && scp > 0 ) || EQ_16( mode_num_nz[sub( sub( i, storepos ), stpos )], mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] ) ) { ovrflag = 1; + move16(); temppos = (Word16) ar_decode( pardec, mode_num_nz ); - storepos += temppos; + storepos = add( storepos, temppos ); scp = fxp1; - - if ( temppos == i - stpos ) /* esc transmitted */ + move32(); + IF( EQ_16( temppos, sub( i, stpos ) ) ) /* esc transmitted */ { - i--; + i = sub( i, 1 ); } - else + ELSE { - break; + BREAK; } } } - if ( !ovrflag ) + IF( !ovrflag ) { pos = (Word16) ar_decode( pardec, mode_num_nz ) + storepos; } - else + ELSE { pos = storepos; + move16(); } position[stpos + pos] = 1; - stpos += pos + 1; + move32(); + stpos = add( stpos, add( pos, 1 ) ); } } } - else if ( L_sub( npulses, 1 ) == 0 ) + ELSE IF( L_sub( npulses, 1 ) == 0 ) { Word16 tmp; *nz = npulses; nzp = *nz; + move16(); + move16(); mode_num_nz[0] = MAX_AR_FREQ; - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { - tmp = div_l( L_deposit_h( size - i - 1 ), size ); + tmp = div_l( L_deposit_h( sub( sub( size, i ), 1 ) ), size ); mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( tmp ), 1 ) ); + move16(); } position[ar_decode( pardec, mode_num_nz )] = 1; + move32(); } - else + ELSE { *nz = 0; + move16(); } return; @@ -421,31 +452,36 @@ void decode_magnitude_usq_fx_ivas( { Word16 i, magnp, magnzp; Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; - + move16(); Word16 storemagn, ovrflag, pos, tempmagn = 0, mmodel[MAX_PULSES + 2]; + move16(); Word32 cp, scp, fxone, fxp1; fxone = 32768; + move32(); fxp1 = 512 * 32768; + move32(); ovrflag = 0; - + move16(); set16_fx( magns, 1, TCQ_MAX_BAND_SIZE ); - if ( sub( nzpos, npulses ) == 0 ) + IF( sub( nzpos, npulses ) == 0 ) { - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { out[i] = positions[i]; + move32(); } return; } - else if ( sub( nzpos, 1 ) == 0 ) + ELSE IF( sub( nzpos, 1 ) == 0 ) { - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { if ( positions[i] != 0 ) { out[i] = npulses; + move32(); return; } } @@ -455,106 +491,119 @@ void decode_magnitude_usq_fx_ivas( magnp = sub( npulses, 1 ); magncout = 0; - + move16(); set32_fx( out, 0, size ); set16_fx( mmodel, 0, MAX_PULSES + 2 ); mmodel[0] = MAX_AR_FREQ; + move16(); magncout = 0; - for ( pos = 0; pos < size; pos++ ) + move16(); + FOR( pos = 0; pos < size; pos++ ) { scp = fxp1; - if ( positions[pos] != 0 ) + move32(); + IF( positions[pos] != 0 ) { storemagn = 0; - - for ( i = 0; i < magnp; i++ ) + move16(); + FOR( i = 0; i < magnp; i++ ) { ovrflag = 0; - - if ( magnzp == ( magnp - i ) ) + move16(); + IF( EQ_16( magnzp, sub( magnp, i ) ) ) { cp = 0; + move32(); } - else + ELSE { Word16 tmp; tmp = div_l( L_deposit_h( magnzp ), magnp - i ); cp = L_sub( fxone, tmp ); } - if ( cp == fxone ) + if ( EQ_32( cp, fxone ) ) { break; } scp = Mult_32_16( scp, extract_l( cp ) ); - mmodel[i + 1 - storemagn] = round_fx( L_shl( scp, 6 ) ); - - if ( ( mmodel[i + 1 - storemagn] == 0 && scp > 0 ) || mmodel[i - storemagn] == mmodel[i + 1 - storemagn] ) + mmodel[sub( add( i, 1 ), storemagn )] = round_fx( L_shl( scp, 6 ) ); + move16(); + IF( ( mmodel[sub( add( i, 1 ), storemagn )] == 0 && scp > 0 ) || EQ_16( mmodel[sub( i, storemagn )], mmodel[sub( add( i, 1 ), storemagn )] ) ) { - mmodel[i + 1 - storemagn] = 0; + mmodel[sub( add( i, 1 ), storemagn )] = 0; + move16(); /* read data */ tempmagn = (Word16) ar_decode( pardec, mmodel ); - storemagn += tempmagn; + storemagn = add( storemagn, tempmagn ); - if ( tempmagn < i ) + IF( LT_16( tempmagn, i ) ) { /* just magnitude */ ovrflag = 1; - break; + move16(); + BREAK; } - else + ELSE { /* esc code */ scp = fxp1; - i--; + move32(); + i = sub( i, 1 ); } } } - if ( ovrflag ) + IF( ovrflag ) { - out[magncout] = storemagn + 1; + out[magncout] = L_deposit_l( add( storemagn, 1 ) ); + move32(); } - else + ELSE { - out[magncout] = ar_decode( pardec, mmodel ) + storemagn + 1; + out[magncout] = L_add( ar_decode( pardec, mmodel ), L_deposit_l( add( storemagn, 1 ) ) ); + move32(); } - magnp -= (Word16) out[magncout]; - magnzp--; - magncout++; + magnp = sub( magnp, (Word16) out[magncout] ); + magnzp = sub( magnzp, 1 ); + magncout = add( magncout, 1 ); - if ( magnzp == 0 ) /* last magnitude generation */ + IF( magnzp == 0 ) /* last magnitude generation */ { - for ( pos = pos + 1; pos < size; pos++ ) + FOR( pos = add( pos, 1 ); pos < size; pos++ ) { - if ( positions[pos] != 0 ) + IF( positions[pos] != 0 ) { - out[magncout] = magnp + 1; + out[magncout] = L_deposit_l( add( magnp, 1 ) ); + move32(); return; } - else + ELSE { out[magncout] = 0; - magncout++; + move32(); + magncout = add( magncout, 1 ); } } } - else if ( magnzp == magnp ) /* rest magnitudes generation */ + ELSE IF( EQ_16( magnzp, magnp ) ) /* rest magnitudes generation */ { - for ( pos = pos + 1; pos < size; pos++ ) + FOR( pos = add( pos, 1 ); pos < size; pos++ ) { out[magncout] = positions[pos]; - magncout++; + move32(); + magncout = add( magncout, 1 ); } return; } } - else + ELSE { out[magncout] = 0; - magncout++; + move32(); + magncout = add( magncout, 1 ); } } @@ -571,11 +620,12 @@ static Word16 quantize_fx_ivas( qval4_fx = shr( abs_s( add( val, 512 ) ), 12 ); retval_fx = add( shl( qval4_fx, 2 ), DDP_fx[D] ); /* 2nd zero check */ - if ( D == 0 ) + IF( D == 0 ) { if ( sub( abs_s( sub( shl( abs_s( retval_fx ), 10 ), abs_s( val ) ) ), abs_s( val ) ) > 0 ) { retval_fx = 0; + move16(); } } @@ -600,57 +650,67 @@ void decode_mangitude_tcq_fx_ivas( Word16 leftp = npulses; /*pulsesnum; */ Word16 leftnz = nzpos; /*nzpos; */ Word16 magn_mode[3] = { MAX_AR_FREQ, 0, 0 }; - + move16(); + move16(); + move16(); bits_fx = 0; + move32(); tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - ( nzpos - 1 )] ) ); - if ( sub( nzpos, npulses ) == 0 ) + IF( sub( nzpos, npulses ) == 0 ) { - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { out[i] = positions[i]; + move32(); } return; } - else if ( sub( nzpos, 1 ) == 0 ) + ELSE IF( sub( nzpos, 1 ) == 0 ) { - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { - if ( positions[i] != 0 ) + IF( positions[i] != 0 ) { out[i] = npulses; + move32(); return; } } } st = 0; - for ( i = 0; i < size && leftnz > 1; i++ ) + move16(); + FOR( i = 0; i < size && leftnz > 1; i++ ) { out[i] = positions[i]; - if ( positions[i] != 0 ) + move32(); + IF( positions[i] != 0 ) { /*generate the trellis path */ symbol = 0; - for ( j = 0; j < leftp; j++ ) + move16(); + FOR( j = 0; j < leftp; j++ ) { num = sub( leftnz, 1 ); denum = sub( leftp, add( j, 1 ) ); - if ( sub( num, denum ) >= 0 ) + IF( sub( num, denum ) >= 0 ) { prob1_fx = MAX_16; prob0_fx = 0; + move16(); + move16(); } - else + ELSE { exp1 = sub( norm_s( num ), 1 ); exp2 = norm_s( denum ); prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; + exp = add( 15, sub( exp1, exp2 ) ); prob1_fx = shl( prob1_fx, sub( 15, exp ) ); prob0_fx = sub( MAX_16, prob1_fx ); } - if ( L_sub( sub( leftp, j ), leftnz ) == 0 ) + IF( L_sub( sub( leftp, j ), leftnz ) == 0 ) { symbol = add( j, 1 ); break; @@ -674,8 +734,8 @@ void decode_mangitude_tcq_fx_ivas( /*magn_mode[1] = (int16_t)(prob1 * MAX_AR_FREQ); */ magn_mode[1] = mult( prob1_fx, MAX_AR_FREQ ); - - if ( ar_decode( pardec, magn_mode ) ) + move16(); + IF( ar_decode( pardec, magn_mode ) ) { exp1 = norm_s( prob1_fx ); tmp32 = L_deposit_h( shl( prob1_fx, exp1 ) ); /*exp1 + 15 + 16 */ @@ -683,9 +743,9 @@ void decode_mangitude_tcq_fx_ivas( bits_fx = L_sub( bits_fx, L_sub( tmp16, L_shl( add( exp1, 1 ), 15 ) ) ); /*15 */ symbol = add( j, 1 ); - break; + BREAK; } - else + ELSE { exp1 = norm_s( prob0_fx ); tmp32 = L_deposit_h( shl( prob0_fx, exp1 ) ); /*exp1 + 15 + 16 */ @@ -694,32 +754,36 @@ void decode_mangitude_tcq_fx_ivas( } } out[i] = symbol; + move32(); /*leftp -= symbol; */ leftp = sub( leftp, symbol ); - leftnz--; + leftnz = sub( leftnz, 1 ); } quantum1_fx = quantize_fx_ivas( (Word16) out[i], ddec[st][0] ); quantum2_fx = quantize_fx_ivas( (Word16) out[i], ddec[st][1] ); /*generate the next state */ - if ( sub( quantum1_fx, (Word16) out[i] ) == 0 ) + IF( sub( quantum1_fx, (Word16) out[i] ) == 0 ) { st = nextstate[st][0]; } - else + ELSE { st = nextstate[st][1]; } + move16(); } /*generate the magnitudes */ - for ( ; i < size; i++ ) + FOR( ; i < size; i++ ) { out[i] = 0; + move32(); if ( positions[i] != 0 ) { out[i] = add( sub( leftp, leftnz ), 1 ); + move32(); } } @@ -727,6 +791,7 @@ void decode_mangitude_tcq_fx_ivas( { /*update the surplus */ *surplus_fx = L_add( *surplus_fx, L_sub( tcq_bits_fx, L_shl( bits_fx, 1 ) ) ); + move32(); } return; @@ -740,18 +805,18 @@ Word16 GetScale_fx_ivas( { Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum, tmp; Word32 t, a, b, ab, estbits_fx = 0; - + move32(); magicnum = 24773; /*Q17: 0.188992013101951f; */ - + move16(); t = L_shr( L_mult( magicnum, blen ), 2 ); exp = norm_l( t ); - a = L_shl( 14 - exp, 15 ) + Log2_norm_lc( L_shl( t, exp ) ); + a = L_add( L_shl( L_deposit_l( sub( 14, exp ) ), 15 ), L_deposit_l( Log2_norm_lc( L_shl( t, exp ) ) ) ); exp1 = sub( norm_l( bits_fx ), 1 ); - exp2 = norm_s( blen - 1 ); + exp2 = norm_s( sub( blen, 1 ) ); - tmp = div_l( L_shl( bits_fx, exp1 ), shl( blen - 1, exp2 ) ); - b = L_shr( L_deposit_l( tmp ), exp1 - exp2 ); + tmp = div_l( L_shl( bits_fx, exp1 ), shl( sub( blen, 1 ), exp2 ) ); + b = L_shr( L_deposit_l( tmp ), sub( exp1, exp2 ) ); ab = L_add( a, b ); @@ -759,18 +824,19 @@ Word16 GetScale_fx_ivas( pulses = min( p_est, MAX_PULSES ); - for ( ; pulses >= 0; pulses-- ) + FOR( ; pulses >= 0; pulses-- ) { estbits_fx = GetBitsFromPulses_fx( pulses, blen ); - if ( L_sub( bits_fx, estbits_fx ) >= 0 ) + IF( L_sub( bits_fx, estbits_fx ) >= 0 ) { - break; + BREAK; } } if ( surplus_fx != NULL ) { *surplus_fx = L_add( *surplus_fx, L_sub( bits_fx, estbits_fx ) ); + move32(); } return pulses; @@ -784,11 +850,20 @@ void decode_signs_fx_ivas( { Word16 i; - for ( i = 0; i < size; i++ ) + FOR( i = 0; i < size; i++ ) { if ( out[i] != 0 ) { - out[i] = ( ar_decode( pardec, uniform_model ) > 0 ) ? out[i] : -out[i]; + IF( ar_decode( pardec, uniform_model ) > 0 ) + { + out[i] = out[i]; + } + ELSE + { + out[i] = L_negate( out[i] ); + } + + move32(); } } @@ -1144,16 +1219,17 @@ Word32 encode_magnitude_usq_fx_ivas( static void transmission_bits( PARCODEC arInst, - int16_t bit ) + Word16 bit ) { bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits++; + arInst->num_bits = L_add( arInst->num_bits, 1 ); bit = !bit; - - for ( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow-- ) + move16(); + FOR( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow-- ) { bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits++; + arInst->num_bits = L_add( arInst->num_bits, 1 ); + move32(); } return; @@ -1162,16 +1238,20 @@ static void transmission_bits( void ar_encoder_start( PARCODEC arInst, TCQ_PBITSTREAM bsInst, - int16_t max_bits ) + Word16 max_bits ) { arInst->bsInst = bsInst; arInst->low = 0; + move32(); arInst->high = AR_TOP; + move32(); arInst->bits_to_follow = 0; - + move16(); arInst->num_bits = 0; + move32(); arInst->max_bits = max_bits; + move32(); return; } @@ -1179,47 +1259,47 @@ void ar_encoder_start( static void ar_encode( PARCODEC arInst, - const int16_t *model, - int32_t symbol ) + const Word16 *model, + Word32 symbol ) { - uint32_t range, high, low; + UWord32 range, high, low; high = arInst->high; low = arInst->low; - symbol++; + symbol = L_add( symbol, 1 ); range = high - low + 1; high = low + ( range * model[symbol - 1] ) / model[0] - 1; low = low + ( range * model[symbol] ) / model[0]; - for ( ;; ) + FOR( ;; ) { - if ( high < AR_HALF ) + IF( high < AR_HALF ) { transmission_bits( arInst, 0 ); } - else + ELSE { - if ( low >= AR_HALF ) + IF( low >= AR_HALF ) { transmission_bits( arInst, 1 ); low -= AR_HALF; high -= AR_HALF; } - else + ELSE { - if ( low >= AR_FIRST && high < AR_THIRD ) + IF( low >= AR_FIRST && high < AR_THIRD ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); low -= AR_FIRST; high -= AR_FIRST; } - else + ELSE { - break; + BREAK; } } } @@ -1229,20 +1309,21 @@ static void ar_encode( } arInst->high = high; + move32(); arInst->low = low; - + move32(); return; } static void ar_encode_uniform( PARCODEC arInst, - uint16_t data, - const int16_t bits ) + UWord16 data, + const Word16 bits ) { - int16_t i; + Word16 i; - for ( i = 0; i < bits; i++ ) + FOR( i = 0; i < bits; i++ ) { ar_encode( arInst, uniform_model, data & 0x1 ); data >>= 1; @@ -1255,7 +1336,8 @@ static void ar_encode_uniform( void ar_encoder_done( PARCODEC arInst ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); + move16(); transmission_bits( arInst, arInst->low >= AR_FIRST ); return; @@ -1266,35 +1348,43 @@ void ar_decoder_start( PARCODEC arInst, TCQ_PBITSTREAM bsInst ) { - int16_t i; + Word16 i; arInst->bsInst = bsInst; - + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); arInst->low = 0; arInst->high = AR_TOP; arInst->value = 0; - - for ( i = 0; i < AR_BITS; i++ ) + move32(); + move32(); + move32(); + FOR( i = 0; i < AR_BITS; i++ ) { - arInst->value = ( arInst->value << 1 ) + bitstream_load_bit( arInst->bsInst ); + arInst->value = L_add( L_shl( arInst->value, 1 ), bitstream_load_bit( arInst->bsInst ) ); + move32(); } return; } -static int32_t ar_decode( +static Word32 ar_decode( PARCODEC arInst, - const int16_t *model ) + const Word16 *model ) { - uint32_t range; - int16_t cum; - int16_t symbol; + UWord32 range; + Word16 cum; + Word16 symbol; - range = (uint32_t) ( arInst->high - arInst->low ) + 1; - cum = (int16_t) ( ( ( (uint32_t) ( arInst->value - arInst->low ) + 1 ) * model[0] - 1 ) / range ); + range = (UWord32) L_add( L_sub( arInst->high, arInst->low ), 1 ); + cum = (Word16) ( ( ( (UWord32) L_sub( arInst->value, arInst->low ) + 1 ) * model[0] - 1 ) / range ); - for ( symbol = 1; model[symbol] > cum; symbol++ ) + FOR( symbol = 1; model[symbol] > cum; symbol++ ) { ; } @@ -1302,36 +1392,45 @@ static int32_t ar_decode( arInst->high = arInst->low + ( range * model[symbol - 1] ) / model[0] - 1; arInst->low = arInst->low + ( range * model[symbol] ) / model[0]; - for ( ;; ) + FOR( ;; ) { - if ( arInst->high >= AR_HALF ) + IF( GE_32( arInst->high, AR_HALF ) ) { - if ( arInst->low >= AR_HALF ) + IF( GE_32( arInst->low, AR_HALF ) ) { - arInst->value -= AR_HALF; - arInst->low -= AR_HALF; - arInst->high -= AR_HALF; + arInst->value = L_sub( arInst->value, AR_HALF ); + move32(); + arInst->low = L_sub( arInst->low, AR_HALF ); + move32(); + arInst->high = L_sub( arInst->high, AR_HALF ); + move32(); } - else + ELSE { - if ( arInst->low >= AR_FIRST && arInst->high < AR_THIRD ) + IF( GE_32( arInst->low, AR_FIRST ) && LT_32( arInst->high, AR_THIRD ) ) { - arInst->value -= AR_FIRST; - arInst->low -= AR_FIRST; - arInst->high -= AR_FIRST; + arInst->value = L_sub( arInst->value, AR_FIRST ); + move32(); + arInst->low = L_sub( arInst->low, AR_FIRST ); + move32(); + arInst->high = L_sub( arInst->high, AR_FIRST ); + move32(); } - else + ELSE { - break; + BREAK; } } } - arInst->low <<= 1; - arInst->high = ( arInst->high << 1 ) + 1; - arInst->value = ( arInst->value << 1 ) + bitstream_load_bit( arInst->bsInst ); + arInst->low = L_shl( arInst->low, 1 ); + move32(); + arInst->high = L_add( L_shl( arInst->high, 1 ), 1 ); + move32(); + arInst->value = L_add( L_shl( arInst->value, 1 ), bitstream_load_bit( arInst->bsInst ) ); + move32(); } - return ( symbol - 1 ); + return ( sub( symbol, 1 ) ); } void ar_decoder_done( @@ -1343,17 +1442,17 @@ void ar_decoder_done( } -static int32_t ar_make_model( - const int16_t *freq, - int16_t *model, - const int16_t len ) +static Word32 ar_make_model( + const Word16 *freq, + Word16 *model, + const Word16 len ) { - int16_t dist; - uint32_t sum = 0; - uint32_t cum = 0; - int16_t i; + Word16 dist; + UWord32 sum = 0; + UWord32 cum = 0; + Word16 i; - for ( i = 0; i < len; i++ ) + FOR( i = 0; i < len; i++ ) { sum += freq[i]; } @@ -1363,58 +1462,62 @@ static int32_t ar_make_model( return 0; } - for ( i = len;; i-- ) + FOR( i = len;; i-- ) { - model[i] = (int16_t) ( ( cum * MAX_AR_FREQ ) / sum ); - + model[i] = (Word16) ( ( cum * MAX_AR_FREQ ) / sum ); + move16(); if ( !i ) { - break; + BREAK; } cum += freq[i - 1]; } - for ( i = 0; i < len - 1; i++ ) + FOR( i = 0; i < sub( len, 1 ); i++ ) { - dist = model[i] - model[i + 1]; + dist = sub( model[i], model[i + 1] ); if ( dist <= 0 ) { - model[i + 1] += dist - 1; + model[i + 1] = add( model[i + 1], sub( dist, 1 ) ); + move16(); } } - for ( i = len; i; i-- ) + FOR( i = len; i; i-- ) { - dist = model[i - 1] - model[i]; + dist = sub( model[i - 1], model[i] ); if ( dist <= 0 ) { - model[i - 1] -= dist - 1; + model[i - 1] = sub( model[i - 1], sub( dist, 1 ) ); + move16(); } } - return ( model[0] > model[1] ); + return ( GT_16( model[0], model[1] ) ); } static void bitstream_save_bit( TCQ_PBITSTREAM pBS, - const int16_t bit ) + const Word16 bit ) { - uint8_t cur; + UWord8 cur; cur = pBS->buf[pBS->numByte]; - cur = (uint8_t) ( cur | ( bit << pBS->curPos-- ) ); + cur = (UWord8) ( cur | shl( bit, pBS->curPos-- ) ); pBS->buf[pBS->numByte] = cur; - pBS->numbits++; + pBS->numbits = L_add( pBS->numbits, 1 ); if ( pBS->curPos < 0 ) { pBS->curPos = 7; - pBS->numByte++; + move16(); + pBS->numByte = L_add( pBS->numByte, 1 ); + move32(); } return; @@ -1424,22 +1527,25 @@ static void bitstream_save_bit( static uint32_t bitstream_load_bit( TCQ_PBITSTREAM pBS ) { - uint32_t bit; + UWord32 bit; Word16 *curPos; /* safety check in case of bit errors */ - if ( pBS->numByte >= pBS->maxBytes ) + if ( GE_32( pBS->numByte, pBS->maxBytes ) ) { return 0; } curPos = &pBS->curPos; + move16(); bit = ( ( pBS->buf[pBS->numByte] >> ( *curPos )-- ) & 0x00000001 ); if ( *curPos < 0 ) { - pBS->numByte++; + pBS->numByte = L_add( pBS->numByte, 1 ); + move32(); *curPos = 7; + move16(); } return bit; @@ -1448,18 +1554,20 @@ static uint32_t bitstream_load_bit( static void bitstream_rollback( TCQ_PBITSTREAM pBS, - int16_t numBits ) + Word16 numBits ) { - while ( numBits > 0 ) + WHILE( numBits > 0 ) { - pBS->curPos++; - pBS->numbits--; - if ( pBS->curPos == 8 ) + pBS->curPos = add( pBS->curPos, 1 ); + pBS->numbits = L_sub( pBS->numbits, 1 ); + IF( EQ_16( pBS->curPos, 8 ) ) { pBS->curPos = 0; - pBS->numByte--; + move16(); + pBS->numByte = L_sub( pBS->numByte, 1 ); + move32(); } - numBits--; + numBits = sub( numBits, 1 ); } return; @@ -1930,10 +2038,10 @@ float GetISCScale( void InitLSBTCQ( - int16_t *bcount ) + Word16 *bcount ) { *bcount = 0; - + move16(); return; } @@ -2068,12 +2176,12 @@ void TCQLSBdec( void SaveTCQdata( PARCODEC arInst, - int16_t *dpath, - int16_t bcount ) + Word16 *dpath, + Word16 bcount ) { - int16_t i; + Word16 i; - for ( i = 0; i < bcount; i++ ) + FOR( i = 0; i < bcount; i++ ) { ar_encode_uniform( arInst, dpath[i], 1 ); } @@ -2083,14 +2191,15 @@ void SaveTCQdata( void LoadTCQdata( PARCODEC arInst, - int16_t *dpath, - int16_t bcount ) + Word16 *dpath, + Word16 bcount ) { - int16_t i; + Word16 i; - for ( i = 0; i < bcount; i++ ) + FOR( i = 0; i < bcount; i++ ) { - dpath[i] = (int16_t) ar_decode( arInst, uniform_model ); + dpath[i] = (Word16) ar_decode( arInst, uniform_model ); + move16(); } return; diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 12ed381964251f0fe0335fb4345bd869f74d746f..8c4b9a582515ebb6628bc49c7eb0208eddd1abf8 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -7,8 +7,7 @@ #include "stl.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" Word32 ar_div( Word32 num, @@ -78,15 +77,17 @@ static void bitstream_save_bit( cur = (UWord8) ( cur | L_shl( bit, pBS->curPos ) ); move16(); pBS->curPos = sub( pBS->curPos, 1 ); + move16(); pBS->buf[pBS->numByte] = cur; move16(); pBS->numbits = L_add( pBS->numbits, 1 ); - + move32(); IF( pBS->curPos < 0 ) { pBS->curPos = 7; move16(); pBS->numByte = L_add( pBS->numByte, 1 ); + move32(); } return; @@ -105,15 +106,13 @@ static UWord32 bitstream_load_bit( } curPos = &pBS->curPos; - move16(); - bit = ( ( pBS->buf[pBS->numByte] >> ( *curPos )-- ) & 0x00000001 ); - move16(); - move16(); - move16(); + bit = UL_and( UL_lshr( pBS->buf[pBS->numByte], ( *curPos ) ), 0x00000001 ); + *curPos = sub( *curPos, 1 ); IF( *curPos < 0 ) { pBS->numByte = L_add( pBS->numByte, 1 ); + move32(); *curPos = 7; move16(); } @@ -131,11 +130,13 @@ static void bitstream_rollback( pBS->curPos++; move16(); pBS->numbits = L_sub( pBS->numbits, 1 ); + move32(); IF( EQ_16( pBS->curPos, 8 ) ) { pBS->curPos = 0; move16(); pBS->numByte = L_sub( pBS->numByte, 1 ); + move32(); } } @@ -147,6 +148,7 @@ static void transmission_bits( { bitstream_save_bit( arInst->bsInst, bit ); arInst->num_bits = L_add( arInst->num_bits, 1 ); + move32(); bit = !bit; move32(); @@ -154,6 +156,7 @@ static void transmission_bits( { bitstream_save_bit( arInst->bsInst, bit ); arInst->num_bits = L_add( arInst->num_bits, 1 ); + move32(); } return; @@ -166,7 +169,9 @@ static Word32 ar_make_model_fx( { Word16 dist; Word32 sum = 0; + move32(); Word32 cum = 0; + move32(); Word16 i, tmp; FOR( i = 0; i < len; i++ ) @@ -183,7 +188,7 @@ static Word32 ar_make_model_fx( { /*model[i] = (short)( ( cum * MAX_AR_FREQ ) / sum ); */ model[i] = extract_l( ar_div( cum * MAX_AR_FREQ, sum ) ); - + move16(); if ( i ) cum = L_add( cum, freq[i - 1] ); } @@ -223,12 +228,14 @@ void ar_encoder_start_fx( move32(); arInst->low = L_deposit_l( 0 ); + move32(); arInst->high = AR_TOP; move32(); arInst->bits_to_follow = 0; move16(); arInst->num_bits = L_deposit_l( 0 ); + move32(); arInst->max_bits = max_bits; move32(); } @@ -246,8 +253,8 @@ static void ar_encode_fx( symbol = L_add( symbol, 1 ); range = L_add( L_sub( high, low ), 1 ); - high = L_sub( L_add( low, ar_div( range * model[symbol - 1], model[0] ) ), 1 ); - low = L_add( low, ar_div( range * model[symbol], model[0] ) ); + high = L_sub( L_add( low, ar_div( imult3216( range, model[symbol - 1] ), model[0] ) ), 1 ); + low = L_add( low, ar_div( imult3216( range, model[symbol] ), model[0] ) ); FOR( ;; ) { @@ -330,13 +337,15 @@ void ar_decoder_start_fx( move32(); arInst->low = L_deposit_l( 0 ); + move32(); arInst->high = AR_TOP; move32(); arInst->value = L_deposit_l( 0 ); - + move32(); FOR( i = 0; i < AR_BITS; i++ ) { arInst->value = L_add( L_shl( arInst->value, 1 ), bitstream_load_bit( arInst->bsInst ) ); + move32(); } return; @@ -356,7 +365,7 @@ static Word16 ar_decode_fx( range = L_add( L_sub( high, low ), 1 ); /*cum = (short)( ( ( (unsigned int)( arInst->value - arInst->low ) + 1 ) * model[0] - 1 ) / range ); */ - cum = extract_l( ar_div( L_sub( L_add( L_sub( value, low ), 1 ) * model[0], 1 ), range ) ); + cum = extract_l( ar_div( L_sub( imult3216( L_add( L_sub( value, low ), 1 ), model[0] ), 1 ), range ) ); symbol = 1; move16(); @@ -365,8 +374,8 @@ static Word16 ar_decode_fx( symbol = add( symbol, 1 ); } - high = L_sub( L_add( low, ar_div( range * model[symbol - 1], model[0] ) ), 1 ); - low = L_add( low, ar_div( range * model[symbol], model[0] ) ); + high = L_sub( L_add( low, ar_div( imult3216( range, model[symbol - 1] ), model[0] ) ), 1 ); + low = L_add( low, ar_div( imult3216( range, model[symbol] ), model[0] ) ); FOR( i = 0; i < 0x7FFF; i++ ) { @@ -396,7 +405,7 @@ static Word16 ar_decode_fx( arInst->value = value; move32(); - return ( symbol - 1 ); + return ( sub( symbol, 1 ) ); } void ar_decoder_done_fx( @@ -472,7 +481,7 @@ static Word32 GetBitsFromPulses_fx( exp1 = norm_l( pow_getbitsfrompulses_fx[temp_fx1] ); exp2 = norm_l( frac_fx32 ); frac_fx32 = Mult_32_32( L_shl( pow_getbitsfrompulses_fx[temp_fx1], exp1 ), L_shl( frac_fx32, exp2 ) ); /*21 + exp1 + 30 + exp2 - 31 */ - frac_fx32 = L_shr( frac_fx32, exp1 + exp2 ) + 1; /*20 */ + frac_fx32 = L_add( L_shr( frac_fx32, add( exp1, exp2 ) ), 1 ); /*20 */ IF( LT_16( exp, integer_fx ) ) { @@ -488,8 +497,7 @@ static Word32 GetBitsFromPulses_fx( } IF( GE_32( mantissa_fx, 0x200000 ) ) { - exp++; - move16(); + exp = add( exp, 1 ); mantissa_fx = L_shr( mantissa_fx, 1 ); } @@ -528,7 +536,7 @@ static void TCQnew_fx( { Word16 i, st, dminpos, position; Word16 pulsesnum, nzpos = 0; - + move16(); Word32 metric_fx[STATES][TCQ_MAX_BAND_SIZE]; Word16 path_fx[STATES][TCQ_MAX_BAND_SIZE]; Word16 quant_fx[STATES][TCQ_MAX_BAND_SIZE]; @@ -570,7 +578,7 @@ static void TCQnew_fx( exp = norm_l( scale_fx ); tmp32 = L_shl( scale_fx, exp ); tmp32 = Mult_32_16( v_fx[i], extract_h( tmp32 ) ); /*12 + 20 + exp - 16 - 15 + Qscale */ - exp1 = 26 - ( exp - 19 + Qscale ); + exp1 = sub( 26, add( sub( exp, 19 ), Qscale ) ); exp2 = norm_l( tmp32 ); IF( GE_16( exp2, exp1 ) ) { @@ -659,7 +667,7 @@ static void TCQnew_fx( move16(); if ( v_fx[i - 1] <= 0 ) { - vout_fx[i - 1] = -quant_fx[position][i]; + vout_fx[i - 1] = negate( quant_fx[position][i] ); move16(); } position = path_fx[position][i]; @@ -720,10 +728,13 @@ Word32 GetISCScale_fx( Word16 SafeExp; Word32 magnbits_fx = 0, tcqmagnbits_fx /*, surplus_fx, bits_fx*/; + move32(); Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; Word32 dmin_fx, scale_fx32; Word32 actualt_fx; Word32 pt_fx, sxy_fx = 0, sy2_fx = 0; + move32(); + move32(); Word16 pn_fx, g_fx, scale_fx; Word16 tmp16, exp, exp1, exp2, Q_temp, hi, lo; Word32 m_fx, tmp32; @@ -733,8 +744,15 @@ Word32 GetISCScale_fx( Word16 Qscale; Word16 Qsxy = 4; - exp = 0; /* to avoid compilation warnings */ + move32(); + move32(); + move32(); + move16(); + + exp = 0; /* to avoid compilation warnings */ + move16(); Qscale = 0; /* to avoid compilation warnings */ + move16(); set32_fx( dist_fx, 0, size ); set16_fx( exp_dist, 31, size ); @@ -794,15 +812,16 @@ Word32 GetISCScale_fx( exp2 = norm_l( m_fx ); scale_fx = div_s( shl( pulsesnum, exp1 ), extract_h( L_shl( m_fx, exp2 ) ) ); /*15 + exp1 - (exp2 + 12 - 16) */ - exp = 15 + exp1 - ( exp2 + 12 - 16 ) + 2; + exp = add( sub( add( 15, exp1 ), sub( add( exp2, 12 ), 16 ) ), 2 ); move16(); t_fx = 0; move16(); FOR( i = 0; i < size; i++ ) { - tmp32 = Mult_32_16( aquants_fx[i], scale_fx ); /*12 + exp - 15 */ - tmp32 = L_shl( tmp32, sub( 16, 12 + exp - 15 ) ); /*16 */ + tmp32 = Mult_32_16( aquants_fx[i], scale_fx ); /*12 + exp - 15 */ + tmp32 = L_shl( tmp32, sub( 16, add( 12 - 15, exp ) ) ); /*16 */ magn_fx[i] = extract_h( L_add( 32768, tmp32 ) ); + move16(); t_fx = add( t_fx, magn_fx[i] ); } } @@ -837,8 +856,8 @@ Word32 GetISCScale_fx( { FOR( i = 0; i < size; i++ ) { - sxy_fx = L_add( sxy_fx, L_shl( Mult_32_16( aquants_fx[i], magn_fx[i] ), Qsxy + 3 ) ); /* 12+0-15 +9 -> 6 */ - sy2_fx = L_add( sy2_fx, L_mult0( magn_fx[i], magn_fx[i] ) ); /*0 */ + sxy_fx = L_add( sxy_fx, L_shl( Mult_32_16( aquants_fx[i], magn_fx[i] ), add( Qsxy, 3 ) ) ); /* 12+0-15 +9 -> 6 */ + sy2_fx = L_add( sy2_fx, L_mult0( magn_fx[i], magn_fx[i] ) ); /*0 */ } Q_temp = 32; move16(); @@ -876,20 +895,21 @@ Word32 GetISCScale_fx( { tmp16 = shl( tmp16, exp2 ); } - g_fx = div_s( extract_h( tmp32 ), tmp16 ); /*15 + 12 + exp1 - 16 - exp2; */ - exp = 15 + 12 + exp1 - 16 - exp2 - 2; + g_fx = div_s( extract_h( tmp32 ), tmp16 ); /*15 + 12 + exp1 - 16 - exp2; */ + exp = add( 15 + 12 - 16 - 2, sub( exp1, exp2 ) ); /*exp = 15 + 12 + exp1 - 16 - exp2 - 2*/ move16(); } IF( g_fx == 0 ) { dist_fx[i] = L_deposit_l( 0 ); + move32(); } ELSE { IF( direction > 0 ) { - tmp32 = L_add( sxy_fx, L_shr( aquants_fx[i], 12 - Qsxy ) ); /*Qsxy */ + tmp32 = L_add( sxy_fx, L_shr( aquants_fx[i], sub( 12, Qsxy ) ) ); /*Qsxy */ t32 = L_add( sy2_fx, L_add( 1, L_deposit_l( shl( magn_fx[i], 1 ) ) ) ); IF( LT_16( norm_l( t32 ), 15 ) ) @@ -906,7 +926,7 @@ Word32 GetISCScale_fx( } ELSE { - tmp32 = L_sub( sxy_fx, L_shr( aquants_fx[i], 12 - Qsxy ) ); /*Qsxy */ + tmp32 = L_sub( sxy_fx, L_shr( aquants_fx[i], sub( 12, Qsxy ) ) ); /*Qsxy */ t32 = L_add( sy2_fx, L_sub( 1, L_deposit_l( shl( magn_fx[i], 1 ) ) ) ); SafeExp = norm_l( t32 ); @@ -923,7 +943,7 @@ Word32 GetISCScale_fx( } } #ifdef BASOP_NOGLOB - tmp32 = L_shl_sat( tmp32, 1 - SafeExp ); /* *2 */ + tmp32 = L_shl_sat( tmp32, sub( 1, SafeExp ) ); /* *2 */ tmp32 = L_sub_sat( L_shl_sat( L_mult0( g_fx, tmp16 ), sub( Qsxy, exp ) ), tmp32 ); /*Qsxy */ #else tmp32 = L_shl( tmp32, 1 - SafeExp ); /* *2 */ @@ -931,7 +951,7 @@ Word32 GetISCScale_fx( #endif dist_fx[i] = Mult_32_16( tmp32, g_fx ); /*Qsxy + exp - 15 */ move32(); - exp_dist[i] = add( Qsxy - 15, exp ); + exp_dist[i] = add( sub( Qsxy, 15 ), exp ); move16(); if ( LT_16( exp_dist[i], Q_temp ) ) { @@ -1020,7 +1040,7 @@ Word32 GetISCScale_fx( exp2 = sub( norm_l( pulsesnum ), 1 ); lo = L_Extract_lc( L_shl( actualt_fx, exp1 ), &hi ); scale_fx32 = Div_32( L_shl( pulsesnum, exp2 ), hi, lo ); /*31 + exp2 - exp1 - 12 */ - Qscale = 31 + exp2 - exp1 - 12 + 2; + Qscale = add( 31 - 12 + 2, sub( exp2, exp1 ) ); /*31 + exp2 - exp1 - 12 + 2*/ move16(); } @@ -1172,8 +1192,7 @@ Word32 GetISCScale_fx( exp1 = sub( norm_s( num ), 1 ); exp2 = norm_s( denum ); prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; - move16(); + exp = add( 15, sub( exp1, exp2 ) ); prob1_fx = shl( prob1_fx, sub( 15, exp ) ); prob0_fx = sub( MAX_16, prob1_fx ); } @@ -1209,8 +1228,7 @@ Word32 GetISCScale_fx( } } - leftnz--; - move16(); + leftnz = sub( leftnz, 1 ); leftp = sub( leftp, abs_s( magn_fx[i] ) ); } @@ -1218,9 +1236,9 @@ Word32 GetISCScale_fx( } /* Update actual occurred surplus */ - tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[pulsescurr - ( nzposcurr - 1 )] ); + tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[sub( pulsescurr, sub( nzposcurr, 1 ) )] ); *surplus_fx = L_add( *surplus_fx, L_sub( tcqmagnbits_fx, L_shl( magnbits_fx, 1 ) ) ); - + move32(); *nzpout = nzposcurr; move16(); } /*magnitude coding */ @@ -1236,7 +1254,7 @@ Word32 GetISCScale_fx( exp2 = sub( norm_l( pulsesnum ), 1 ); lo = L_Extract_lc( L_shl( actualt_fx, exp1 ), &hi ); scale_fx32 = Div_32( L_shl( pulsesnum, exp2 ), hi, lo ); /*31 + exp2 - exp1 - 12 */ - Qscale = 31 + exp2 - exp1 - 12; + Qscale = add( 31 - 12, sub( exp2, exp1 ) ); /*31 + exp2 - exp1 - 12*/ move16(); } test(); @@ -1247,7 +1265,7 @@ Word32 GetISCScale_fx( FOR( i = 0; i < size; i++ ) { - if ( abs_s( magn_fx[i] ) > 1 ) + if ( GT_16( abs_s( magn_fx[i] ), 1 ) ) { flag_g1 = 1; move16(); @@ -1270,14 +1288,15 @@ Word32 GetISCScale_fx( move16(); /*sbuffer[*bcount] = scale_fx32;*/ exp = norm_s( pulsesnum ); - tmp16 = div_l( actualt_fx, shl( pulsesnum, exp - 1 ) ); + tmp16 = div_l( actualt_fx, shl( pulsesnum, sub( exp, 1 ) ) ); tmp32 = L_shl( L_deposit_l( tmp16 ), exp ); /*sbuffer[*bcount] = 1/((float)tmp32/pow(2.0, 12));*/ sbuffer[*bcount] = tmp32; /*Q12*/ move32(); /*sbuffer[*bcount] = (float)scale_fx32 / pow(2.0, Qscale);*/ - ( *bcount )++; + ( *bcount ) = add( *bcount, 1 ); + move16(); } } } @@ -1297,6 +1316,7 @@ void TCQLSB_fx( { Word16 i, st, dminpos, position; Word16 q_fx = 6554; /*Q15*/ + move16(); Word32 dmin_fx, curdist1_fx, curdist2_fx, newdist1_fx, newdist2_fx; Word16 path[STATES_LSB][TCQ_LSB_SIZE]; Word16 quant[STATES_LSB][TCQ_LSB_SIZE]; @@ -1338,9 +1358,9 @@ void TCQLSB_fx( exp2 = norm_l( s2_fx ); s1_fx16 = extract_h( L_shl( s1_fx, exp1 ) ); /*12 + exp1 - 16*/ s2_fx16 = extract_h( L_shl( s2_fx, exp2 ) ); /*12 + exp2 - 16*/ - exp1 = 12 + exp1 - 16; + exp1 = add( 12 - 16, exp1 ); move16(); - exp2 = 12 + exp2 - 16; + exp2 = add( 12 - 16, exp2 ); move16(); a1_fx = L_add( abuffer_fx[i], 0 ); @@ -1407,36 +1427,36 @@ void TCQLSB_fx( /* decision */ IF( LT_32( L_add( curdist1_fx, newdist1_fx ), L_add( curdist2_fx, newdist2_fx ) ) ) { - path[st][i / 2 + 1] = step_LSB[st][0]; + path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][0]; move16(); - metric_fx[st][i / 2 + 1] = L_add( curdist1_fx, newdist1_fx ); + metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist1_fx, newdist1_fx ); move32(); - quant[st][i / 2 + 1] = 0; + quant[st][add( shr( i, 1 ), 1 )] = 0; move16(); - dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } ELSE { - path[st][i / 2 + 1] = step_LSB[st][1]; + path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][1]; move16(); - metric_fx[st][i / 2 + 1] = L_add( curdist2_fx, newdist2_fx ); + metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist2_fx, newdist2_fx ); move32(); - quant[st][i / 2 + 1] = 1; + quant[st][add( shr( i, 1 ), 1 )] = 1; move16(); - dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } - if ( GT_32( MaxPath, metric_fx[st][i / 2 + 1] ) ) + if ( GT_32( MaxPath, metric_fx[st][add( shr( i, 1 ), 1 )] ) ) { - MaxPath = L_add( metric_fx[st][i / 2 + 1], 0 ); + MaxPath = L_add( metric_fx[st][add( shr( i, 1 ), 1 )], 0 ); } } /* Metric renormalization to prevent overflow */ FOR( st = 0; st < 4; st++ ) { - metric_fx[st][i / 2 + 1] = L_sub( metric_fx[st][i / 2 + 1], MaxPath ); + metric_fx[st][add( shr( i, 1 ), 1 )] = L_sub( metric_fx[st][add( shr( i, 1 ), 1 )], MaxPath ); move32(); } } @@ -1461,9 +1481,9 @@ void TCQLSB_fx( FOR( ; i >= 0; i -= 2 ) { - qout[i / 2] = quant[position][i / 2 + 1]; + qout[i / 2] = quant[position][add( shr( i, 1 ), 1 )]; move16(); - dpath[i / 2] = dquant[position][i / 2 + 1]; + dpath[i / 2] = dquant[position][add( shr( i, 1 ), 1 )]; move16(); IF( s_and( denc_LSB[position][qout[i / 2]], 0x1 ) ) @@ -1487,7 +1507,7 @@ void TCQLSB_fx( move16(); } - position = path[position][i / 2 + 1]; + position = path[position][add( shr( i, 1 ), 1 )]; move16(); } @@ -1495,6 +1515,7 @@ void TCQLSB_fx( FOR( i = 0; i < bcount; i++ ) { mbuffer_fx[i] = add( add( mbuffer_fx[i], shl( mbuffer_fx[i], 2 ) ), dbuffer_fx[i] ); + move16(); } return; @@ -1506,8 +1527,9 @@ void TCQLSBdec_fx( { /*float q = QTCQ;*/ Word16 q = 1; /*x5*/ + move16(); Word16 i, tmp, state = 0; - + move16(); tmp = shr( bcount, 1 ); FOR( i = 0; i < tmp; i++ ) { @@ -1519,16 +1541,18 @@ void TCQLSBdec_fx( ELSE { mbuffer[2 * i] = negate( q ); + move16(); } IF( s_and( ddec_LSB[state][dpath[i]], 0x2 ) ) { - mbuffer[2 * i + 1] = q; + mbuffer[add( shl( i, 1 ), 1 )] = q; move16(); } ELSE { - mbuffer[2 * i + 1] = negate( q ); + mbuffer[add( shl( i, 1 ), 1 )] = negate( q ); + move16(); } state = dstep_LSB[state][dpath[i]]; @@ -1544,7 +1568,8 @@ void RestoreTCQ_fx( Word16 *mbuffer ) { Word16 i, nzpos = 0, flag_g1 = 0; - + move16(); + move16(); /* calculate actual nz positions */ nzpos = 0; move16(); @@ -1576,6 +1601,7 @@ void RestoreTCQ_fx( magn[i] = mbuffer[*bcount]; move16(); *bcount = add( *bcount, 1 ); + move16(); } } } @@ -1589,7 +1615,8 @@ void RestoreTCQdec_fx( Word16 *mbuffer ) { Word16 i, nzpos = 0, flag_g1 = 0; - + move16(); + move16(); /* calculate actual nz positions */ nzpos = 0; move16(); @@ -1604,6 +1631,7 @@ void RestoreTCQdec_fx( move16(); } magn[i] = extract_l( L_mult0( magn[i], 5 ) ); + move16(); } } @@ -1624,6 +1652,7 @@ void RestoreTCQdec_fx( magn[i] = mbuffer[*bcount]; move16(); *bcount = add( *bcount, 1 ); + move16(); } } } @@ -1661,6 +1690,7 @@ void LoadTCQdata_fx( FOR( i = 0; i < bcount; i++ ) { dpath[i] = ar_decode_fx( arInst, uniform_model ); + move16(); } return; @@ -1675,12 +1705,15 @@ Word32 encode_position_ari_fx( { Word16 i, tmp; Word16 nz = 0, pulses = 0; + move16(); + move16(); Word16 prob[TCQ_MAX_BAND_SIZE]; Word16 model_num_nz[TCQ_MAX_BAND_SIZE]; Word16 *cur_quants = quants; Word16 integer, frac; Word32 /*est_bits_frame_fx, */ btcq_fx = 0, bits_fx = 0, pnzp_fx; - + move16(); + move16(); Word32 cp, scp, fxone, fxp1; Word16 pos; @@ -1704,26 +1737,26 @@ Word32 encode_position_ari_fx( btcq_fx = GetBitsFromPulses_fx( pulses, size ); /* Estimate TCQ bits */ - bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ); - bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1] ) ) ) ); - bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); + bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ); + bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ) ) ); + bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[add( pulses, sub( nz, 1 ) )] ) ) ); bits_fx = L_sub( bits_fx, nz ); *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); - + move32(); /*caculate the #nz probability */ tmp = s_min( pulses, size ); FOR( i = 0; i < tmp; i++ ) { pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), - L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[pulses - i] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), + L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( pulses, i )] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ IF( GT_32( pnzp_fx, 0 ) ) { integer = extract_h( pnzp_fx ); frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ prob[i] = extract_h( L_shl( Pow2( integer, frac ), 16 ) ); /*0 */ - + move16(); /*zero probability will incur problems in ar_make_model() */ if ( prob[i] == 0 ) { @@ -1742,7 +1775,7 @@ Word32 encode_position_ari_fx( IF( GT_16( nz, 1 ) ) { - ar_encode_fx( parenc, model_num_nz, nz - 1 ); /*encode #nz */ + ar_encode_fx( parenc, model_num_nz, sub( nz, 1 ) ); /*encode #nz */ scp = L_add( fxp1, 0 ); pos = 0; move16(); @@ -1759,11 +1792,11 @@ Word32 encode_position_ari_fx( } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h( nz ), ( size - i ) ) ); + cp = L_sub( fxone, div_l( L_deposit_h( nz ), sub( size, i ) ) ); } scp = Mult_32_16( scp, extract_l( cp ) ); model_num_nz[pos + 1] = round_fx( L_shl( scp, 6 ) ); - + move16(); test(); test(); IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || model_num_nz[pos] == model_num_nz[pos + 1] ) @@ -1806,8 +1839,8 @@ Word32 encode_position_ari_fx( move16(); FOR( i = 0; i < size; i++ ) { - model_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); - + model_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( sub( sub( size, i ), 1 ) ), size ) ), 1 ) ); + move16(); if ( cur_quants[i] != 0 ) { pos = i; @@ -1839,7 +1872,7 @@ Word32 encode_magnitude_usq_fx( /*estimate fac bits */ - bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1] ) ); + bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[add( sub( npulses, nzpos ), 1 )] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, bits_fx ); test(); @@ -1860,11 +1893,13 @@ Word32 encode_magnitude_usq_fx( tmp = sub( abs_s( magn_fx[i] ), 1 ); FOR( j = 0; j < tmp; j++ ) { - magn_position[k++] = 0; + magn_position[k] = 0; move16(); + k = add( k, 1 ); } - magn_position[k++] = 1; + magn_position[k] = 1; move16(); + k = add( k, 1 ); } } @@ -1892,7 +1927,7 @@ Word32 encode_magnitude_usq_fx( } scp = Mult_32_16( scp, extract_l( cp ) ); model_m[pos + 1] = round_fx( L_shl( scp, 6 ) ); - + move16(); test(); test(); IF( ( model_m[pos + 1] == 0 && scp > 0 ) || model_m[pos] == model_m[pos + 1] ) @@ -1903,8 +1938,7 @@ Word32 encode_magnitude_usq_fx( ar_encode_fx( parenc, model_m, pos ); pos = 0; move16(); - i--; - move16(); + i = sub( i, 1 ); scp = L_add( fxp1, 0 ); CONTINUE; } @@ -1914,17 +1948,16 @@ Word32 encode_magnitude_usq_fx( ar_encode_fx( parenc, model_m, pos ); pos = 0; move16(); - magnzp--; + magnzp = sub( magnzp, 1 ); move16(); scp = L_add( fxp1, 0 ); } ELSE { - pos++; - move16(); + pos = add( pos, 1 ); } - magnp--; + magnp = sub( magnp, 1 ); move16(); } return bits_fx; @@ -1945,6 +1978,9 @@ Word32 encode_magnitude_tcq_fx( Word16 i, j; Word32 st; Word16 magn_mode[3] = { MAX_AR_FREQ, 0, 0 }; + move16(); + move16(); + move16(); Word16 leftp = npulses; /*pulsesnum; */ Word16 leftnz = nzpos; /*nzpos; */ @@ -1952,8 +1988,9 @@ Word32 encode_magnitude_tcq_fx( move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - ( nzpos - 1 )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, tcq_bits_fx ); + move32(); test(); IF( EQ_16( nzpos, npulses ) || EQ_16( nzpos, 1 ) ) @@ -1989,7 +2026,7 @@ Word32 encode_magnitude_tcq_fx( exp1 = sub( norm_s( num ), 1 ); exp2 = norm_s( denum ); prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; + exp = add( 15, sub( exp1, exp2 ) ); move16(); prob1_fx = shl( prob1_fx, sub( 15, exp ) ); prob0_fx = sub( MAX_16, prob1_fx ); @@ -2014,6 +2051,7 @@ Word32 encode_magnitude_tcq_fx( } magn_mode[1] = mult( prob1_fx, MAX_AR_FREQ ); + move16(); IF( LT_16( j, sub( abs_s( magn_fx[i] ), 1 ) ) ) { ar_encode_fx( parenc, magn_mode, 0 ); @@ -2046,6 +2084,7 @@ Word32 encode_signs_fx( Word32 i, sign; *est_frame_bits_fx = L_add( *est_frame_bits_fx, L_deposit_h( npos ) ); + move32(); FOR( i = 0; i < size; i++ ) { IF( magn[i] != 0 ) @@ -2076,6 +2115,8 @@ void decode_position_ari_fx( Word16 integer, frac; Word32 cp, scp, fxone, fxp1; Word16 stpos = 0, pos, ovrflag = 0, temppos, storepos; + move16(); + move16(); fxone = 32768; move32(); @@ -2104,14 +2145,15 @@ void decode_position_ari_fx( /*calculate the probability of #nz */ pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), - L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[npulses - i] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), + L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( npulses, i )] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ IF( GT_32( pnzp_fx, 0 ) ) { integer = extract_h( pnzp_fx ); frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ prob[i] = extract_h( L_shl( Pow2( integer, frac ), 16 ) ); /*0 */ + move16(); if ( prob[i] == 0 ) { prob[i] = 1; @@ -2127,6 +2169,7 @@ void decode_position_ari_fx( ar_make_model_fx( prob, mode_num_nz, s_min( npulses, size ) ); *nz = add( 1, ar_decode_fx( pardec, mode_num_nz ) ); /*get #nz */ + move16(); nzp = *nz; move16(); IF( nzp == 1 ) @@ -2135,7 +2178,8 @@ void decode_position_ari_fx( move16(); FOR( i = 0; i < size; i++ ) { - mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); + mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( sub( sub( size, i ), 1 ) ), size ) ), 1 ) ); + move16(); } position[ar_decode_fx( pardec, mode_num_nz )] = 1; @@ -2159,34 +2203,32 @@ void decode_position_ari_fx( ovrflag = 0; move16(); - IF( nzp == ( size - i ) ) + IF( nzp == sub( size, i ) ) { cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h( nzp ), ( size - i ) ) ); + cp = L_sub( fxone, div_l( L_deposit_h( nzp ), sub( size, i ) ) ); } scp = Mult_32_16( scp, extract_l( cp ) ); - mode_num_nz[i + 1 - storepos - stpos] = round_fx( L_shl( scp, 6 ) ); + mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( ( mode_num_nz[i + 1 - storepos - stpos] == 0 && scp > 0 ) || mode_num_nz[i - storepos - stpos] == mode_num_nz[i + 1 - storepos - stpos] ) + IF( ( mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] == 0 && scp > 0 ) || EQ_16( mode_num_nz[sub( sub( i, storepos ), stpos )], mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] ) ) { - mode_num_nz[i + 1 - storepos - stpos] = 0; + mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = 0; move16(); ovrflag = 1; move16(); temppos = ar_decode_fx( pardec, mode_num_nz ); - move16(); - storepos += temppos; - move16(); + storepos = add( storepos, temppos ); scp = L_add( fxp1, 0 ); - IF( temppos == i - stpos ) /* esc transmitted */ + IF( temppos == sub( i, stpos ) ) /* esc transmitted */ { - i--; + i = sub( i, 1 ); move16(); } ELSE @@ -2197,7 +2239,7 @@ void decode_position_ari_fx( } IF( !ovrflag ) { - pos = ar_decode_fx( pardec, mode_num_nz ) + storepos; + pos = add( ar_decode_fx( pardec, mode_num_nz ), storepos ); move16(); } ELSE @@ -2206,10 +2248,9 @@ void decode_position_ari_fx( move16(); } - position[stpos + pos] = 1; - move16(); - stpos += pos + 1; + position[add( stpos, pos )] = 1; move16(); + stpos = add( stpos, add( pos, 1 ) ); } } } @@ -2223,7 +2264,8 @@ void decode_position_ari_fx( move16(); FOR( i = 0; i < size; i++ ) { - mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( size - i - 1 ), size ) ), 1 ) ); + mode_num_nz[i + 1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h( sub( sub( size, i ), 1 ) ), size ) ), 1 ) ); + move16(); } position[ar_decode_fx( pardec, mode_num_nz )] = 1; @@ -2247,7 +2289,10 @@ void decode_magnitude_usq_fx( { Word16 i, magnp, magnzp; Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; + move16(); Word16 storemagn, ovrflag = 0, pos, tempmagn = 0, mmodel[MAX_PULSES + 2]; + move16(); + move16(); Word32 cp, scp, fxone, fxp1; fxone = 32768; @@ -2304,13 +2349,13 @@ void decode_magnitude_usq_fx( ovrflag = 0; move16(); - IF( magnzp == ( magnp - i ) ) + IF( magnzp == sub( magnp, i ) ) { cp = L_deposit_l( 0 ); } ELSE { - cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), magnp - i ) ); + cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), sub( magnp, i ) ) ); } IF( cp == fxone ) @@ -2319,18 +2364,17 @@ void decode_magnitude_usq_fx( } scp = Mult_32_16( scp, extract_l( cp ) ); - mmodel[i + 1 - storemagn] = round_fx( L_shl( scp, 6 ) ); - + mmodel[sub( add( i, 1 ), storemagn )] = round_fx( L_shl( scp, 6 ) ); + move16(); test(); test(); - IF( ( mmodel[i + 1 - storemagn] == 0 && scp > 0 ) || mmodel[i - storemagn] == mmodel[i + 1 - storemagn] ) + IF( ( mmodel[sub( add( i, 1 ), storemagn )] == 0 && scp > 0 ) || EQ_16( mmodel[sub( i, storemagn )], mmodel[sub( add( i, 1 ), storemagn )] ) ) { - mmodel[i + 1 - storemagn] = 0; + mmodel[sub( add( i, 1 ), storemagn )] = 0; move16(); /* read data */ tempmagn = ar_decode_fx( pardec, mmodel ); - storemagn += tempmagn; - move16(); + storemagn = add( storemagn, tempmagn ); IF( tempmagn < i ) { @@ -2343,8 +2387,7 @@ void decode_magnitude_usq_fx( { /* esc code */ scp = L_add( fxp1, 0 ); - i--; - move16(); + i = sub( i, 1 ); } } } @@ -2359,12 +2402,9 @@ void decode_magnitude_usq_fx( out[magncout] = ar_decode_fx( pardec, mmodel ) + storemagn + 1; move16(); } - magnp -= out[magncout]; - move16(); - magnzp--; - move16(); - magncout++; - move16(); + magnp = sub( magnp, out[magncout] ); + magnzp = sub( magnzp, 1 ); + magncout = add( magncout, 1 ); IF( magnzp == 0 ) /* last magnitude generation */ { @@ -2372,7 +2412,7 @@ void decode_magnitude_usq_fx( { IF( positions[pos] != 0 ) { - out[magncout] = magnp + 1; + out[magncout] = add( magnp, 1 ); move16(); return; } @@ -2380,7 +2420,7 @@ void decode_magnitude_usq_fx( { out[magncout] = 0; move16(); - magncout++; + magncout = add( magncout, 1 ); move16(); } } @@ -2391,8 +2431,7 @@ void decode_magnitude_usq_fx( { out[magncout] = positions[pos]; move16(); - magncout++; - move16(); + magncout = add( magncout, 1 ); } return; } @@ -2401,8 +2440,7 @@ void decode_magnitude_usq_fx( { out[magncout] = 0; move16(); - magncout++; - move16(); + magncout = add( magncout, 1 ); } } @@ -2424,11 +2462,16 @@ void decode_mangitude_tcq_fx( Word16 i, j, symbol, st; Word16 leftp = npulses; /*pulsesnum; */ - Word16 leftnz = nzpos; /*nzpos; */ + move16(); + Word16 leftnz = nzpos; /*nzpos; */ + move16(); Word16 magn_mode[3] = { MAX_AR_FREQ, 0, 0 }; + move16(); + move16(); + move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - ( nzpos - 1 )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); IF( EQ_16( nzpos, npulses ) ) { @@ -2462,6 +2505,7 @@ void decode_mangitude_tcq_fx( } out[i] = positions[i]; + move16(); IF( positions[i] != 0 ) { /*generate the trellis path */ @@ -2483,7 +2527,7 @@ void decode_mangitude_tcq_fx( exp1 = sub( norm_s( num ), 1 ); exp2 = norm_s( denum ); prob1_fx = div_s( shl( num, exp1 ), shl( denum, exp2 ) ); /*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; + exp = add( 15, sub( exp1, exp2 ) ); prob1_fx = shl( prob1_fx, sub( 15, exp ) ); prob0_fx = sub( MAX_16, prob1_fx ); } @@ -2514,7 +2558,7 @@ void decode_mangitude_tcq_fx( /*magn_mode[1] = (short)(prob1 * MAX_AR_FREQ); */ magn_mode[1] = mult( prob1_fx, MAX_AR_FREQ ); - + move16(); IF( ar_decode_fx( pardec, magn_mode ) ) { exp1 = norm_s( prob1_fx ); @@ -2564,6 +2608,7 @@ void decode_mangitude_tcq_fx( IF( positions[i] != 0 ) { out[i] = add( sub( leftp, leftnz ), 1 ); + move16(); } } @@ -2572,6 +2617,7 @@ void decode_mangitude_tcq_fx( { /*update the surplus */ *surplus_fx = L_add( *surplus_fx, L_sub( tcq_bits_fx, L_shl( bits_fx, 1 ) ) ); + move32(); } return; @@ -2594,6 +2640,7 @@ void decode_signs_fx( if ( tmp <= 0 ) { out[i] = negate( out[i] ); + move16(); } } } @@ -2608,18 +2655,19 @@ Word16 GetScale_fx( ) { Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum; + move16(); Word32 t, a, b, ab, estbits_fx = 0; - + move32(); magicnum = 24773; move16(); /*Q17: 0.188992013101951f; */ t = L_shr( L_mult( magicnum, blen ), 2 ); exp = norm_l( t ); - a = L_shl( 14 - exp, 15 ) + Log2_norm_lc( L_shl( t, exp ) ); + a = L_add( L_shl( sub( 14, exp ), 15 ), Log2_norm_lc( L_shl( t, exp ) ) ); exp1 = sub( norm_l( bits_fx ), 1 ); - exp2 = norm_s( blen - 1 ); - b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1 ), shl( blen - 1, exp2 ) ) ), exp1 - exp2 ); + exp2 = norm_s( sub( blen, 1 ) ); + b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1 ), shl( sub( blen, 1 ), exp2 ) ) ), sub( exp1, exp2 ) ); ab = L_add( a, b ); @@ -2639,6 +2687,7 @@ Word16 GetScale_fx( IF( surplus_fx != 0 ) { *surplus_fx = L_add( *surplus_fx, L_sub( bits_fx, estbits_fx ) ); + move16(); } return pulses; diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 0c3190705a143769f8d5585133a26fe20be63fe0..fb5a8e27d5009b9392ff1c819d8f7f886014e03d 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" #include "basop_util.h" #include "rom_com.h" @@ -402,6 +401,7 @@ void predict_signal( const Word16 *x0, *win; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif x0 = &excI[-T0 - 1]; frac = negate( frac ); @@ -453,6 +453,7 @@ static void tcx_ltp_synth_filter( const Word16 *v0, *v1; const Word16 *w0, *w1; Word16 alpha, step = 0; /* initialize just to avoid compiler warning */ + move16(); Word16 i, j, k, L; IF( gain > 0 ) @@ -663,7 +664,7 @@ static void tcx_ltp_synth_filter32( L_tmp2 = Mpy_32_16_r( L_tmp2, alpha ); #ifdef BASOP_NOGLOB L_tmp2 = L_add_sat( synth[j], L_tmp2 ); - IF( zir != NULL ) + if ( zir != NULL ) { L_tmp2 = L_sub_sat( L_tmp2, zir[j] ); } @@ -726,12 +727,13 @@ static void tcx_ltp_synth_filter_10( assert( GE_16( filtIdx, 0 ) ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[sub( pitch_res, pitch_fr )]; v0 = &tcxLtpFilters[filtIdx].filt[0]; v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; L = tcxLtpFilters[filtIdx].length; curr_gain = gain; + move16(); gain_step = negate( gain ) / length; for ( j = 0; j < length; j++ ) @@ -784,7 +786,7 @@ static void tcx_ltp_synth_filter_10_fx( y0 = in; y1 = y0 - 1; - assert( GE_16( filtIdx, 0 ) ); + assert( filtIdx >= 0 ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; @@ -793,12 +795,15 @@ static void tcx_ltp_synth_filter_10_fx( L = tcxLtpFilters[filtIdx].length; curr_gain = gain; - gain_step = negate( gain ) / length; + move16(); + gain_step = idiv1616( negate( gain ), length ); // TODO for ( j = 0; j < length; j++ ) { s = 0; + move16(); s2 = 0; + move16(); for ( i = 0, k = 0; i < L; i++, k += pitch_res ) { @@ -810,7 +815,7 @@ static void tcx_ltp_synth_filter_10_fx( // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; out[j] = L_add_sat( in[j], Mpy_32_16_1( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); - + move32(); x0++; x1++; y0++; @@ -845,7 +850,7 @@ static void tcx_ltp_synth_filter_01( y0 = in; y1 = y0 - 1; - assert( GE_16( filtIdx, 0 ) ); + assert( filtIdx >= 0 ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; @@ -854,12 +859,16 @@ static void tcx_ltp_synth_filter_01( L = tcxLtpFilters[filtIdx].length; curr_gain = 0; - gain_step = gain / length; + move16(); + // gain_step = gain / length; // TODO + gain_step = idiv1616( gain, length ); // TODO for ( j = 0; j < length; j++ ) { s = 0; + move16(); s2 = 0; + move16(); for ( i = 0, k = 0; i < L; i++, k = add( k, pitch_res ) ) { @@ -871,7 +880,7 @@ static void tcx_ltp_synth_filter_01( // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; out[j] = add_sat( in[j], mult_r_sat( curr_gain, sub_sat( round_fx_sat( s ), mult_r_sat( round_fx_sat( s2 ), ALPHA ) ) ) ); - + move32(); x0++; x1++; @@ -907,7 +916,7 @@ static void tcx_ltp_synth_filter_01_fx( y0 = in; y1 = y0 - 1; - assert( GE_16( filtIdx, 0 ) ); + assert( filtIdx >= 0 ); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; @@ -916,12 +925,16 @@ static void tcx_ltp_synth_filter_01_fx( L = tcxLtpFilters[filtIdx].length; curr_gain = 0; - gain_step = gain / length; + move16(); + // gain_step = gain / length; // TODO + gain_step = idiv1616( gain, length ); // TODO for ( j = 0; j < length; j++ ) { s = 0; + move16(); s2 = 0; + move16(); for ( i = 0, k = 0; i < L; i++, k = add( k, pitch_res ) ) { @@ -933,7 +946,7 @@ static void tcx_ltp_synth_filter_01_fx( // out[j] = in[j] - curr_gain * s2 * ALPHA + curr_gain * s; out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), curr_gain ) ); - + move32(); x0++; x1++; @@ -992,7 +1005,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( y0 = in; y1 = y0 - 1; - assert( GE_16( filtIdx, 0 ) && GE_16( prev_filtIdx, 0 ) ); + assert( ( filtIdx >= 0 ) && ( prev_filtIdx >= 0 ) ); w0 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_fr]; w1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res - prev_pitch_fr]; @@ -1000,6 +1013,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; prev_L = tcxLtpFilters[prev_filtIdx].length; + move16(); p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; @@ -1007,15 +1021,20 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; L = tcxLtpFilters[filtIdx].length; + move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ gain = prev_gain; - gain_step = negate( prev_gain ) / length; + move16(); + // gain_step = negate( prev_gain ) / length; // TODO + gain_step = idiv1616( negate( prev_gain ), length ); // TODO for ( j = 0; j < length; j++ ) { s = 0; + move16(); s2 = 0; + move16(); for ( i = 0, k = 0; i < prev_L; i++, k += prev_pitch_res ) { @@ -1047,12 +1066,15 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ gain = 0; - gain_step = cur_gain / length; + move16(); + gain_step = cur_gain / length; // TODO for ( j = 0; j < length; j++ ) { s3 = 0; + move16(); s4 = 0; + move16(); for ( i = 0, k = 0; i < L; i++, k += pitch_res ) { @@ -1064,7 +1086,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch( // out[j] = *(temp_ptr + j) - gain * s4 * ALPHA + gain * s3; out[j] = add_sat( *( temp_ptr + j ), mult_r_sat( gain, sub_sat( round_fx_sat( s3 ), mult_r_sat( round_fx_sat( s4 ), ALPHA ) ) ) ); - + move32(); l0++; l1++; @@ -1120,6 +1142,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( v1 = &tcxLtpFilters[prev_filtIdx].filt[prev_pitch_res]; prev_L = tcxLtpFilters[prev_filtIdx].length; + move16(); p0 = &tcxLtpFilters[filtIdx].filt[cur_pitch_fr]; p1 = &tcxLtpFilters[filtIdx].filt[pitch_res - cur_pitch_fr]; @@ -1127,15 +1150,19 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( q1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; L = tcxLtpFilters[filtIdx].length; + move16(); /* 1. decreasing gain filter. The first filter unit with the parameters associated to the previous interval and scaling towards 0 */ gain = prev_gain; - gain_step = negate( prev_gain ) / length; + move16(); + gain_step = idiv1616( negate( prev_gain ), length ); // TODOD for ( j = 0; j < length; j++ ) { s = 0; + move16(); s2 = 0; + move16(); for ( i = 0, k = 0; i < prev_L; i++, k += prev_pitch_res ) { @@ -1147,7 +1174,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( // out[j] = in[j] - gain * s2 * ALPHA + gain * s; out[j] = L_add_sat( in[j], Mpy_32_16_r( L_sub_sat( s, Mpy_32_16_1( s2, ALPHA ) ), gain ) ); - + move32(); x0++; x1++; y0++; @@ -1167,12 +1194,15 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( /* 2. increasing gain filter. The second filter unit with the parameters associated to the current interval and scaling from 0 towards current gain */ gain = 0; - gain_step = cur_gain / length; + move16(); + gain_step = cur_gain / length; // TODO for ( j = 0; j < length; j++ ) { s3 = 0; + move16(); s4 = 0; + move16(); for ( i = 0, k = 0; i < L; i++, k += pitch_res ) { @@ -1184,7 +1214,7 @@ static void tcx_ltp_synth_filter_11_unequal_pitch_fx( // out[j] = *(temp_ptr + j) - gain * s4 * ALPHA + gain * s3; out[j] = L_add_sat( *( temp_ptr + j ), Mpy_32_16_r( L_sub_sat( s3, Mpy_32_16_1( s4, ALPHA ) ), gain ) ); - + move32(); l0++; l1++; @@ -1309,9 +1339,10 @@ void tcx_ltp_post( } filtIdx = 0; /* just to avoid comilation warnings */ + move16(); tcx_buf_len = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); SideInfoOnly = 0; - + move16(); if ( GE_32( total_brate, HQ_96k ) ) { SideInfoOnly = 1; @@ -1327,16 +1358,17 @@ void tcx_ltp_post( move16(); } - IF( EQ_16( core, ACELP_CORE ) ) + IF( core == ACELP_CORE ) { bfi = 0; + move16(); pitch_int = 0; - pitch_fr = 0; - gain = 0; - L_frame_core = st->L_frame_past; move16(); + pitch_fr = 0; move16(); + gain = 0; move16(); + L_frame_core = st->L_frame_past; move16(); } ELSE @@ -1388,6 +1420,7 @@ void tcx_ltp_post( ELSE IF( bfi == 0 ) { /* LTP and good frame */ + test(); IF( EQ_16( st->element_mode, EVS_MONO ) ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { IF( NE_16( output_frame, L_frame_core ) ) @@ -1544,29 +1577,36 @@ void tcx_ltp_post( test(); test(); test(); - //#ifdef IVAS_CODE_TCX_LTP + // #ifdef IVAS_CODE_TCX_LTP if ( st->element_mode != EVS_MONO ) { - if ( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* The filtering is deactivated, just copy input to the output */ Copy( sig_in + delay, sig_out + delay, L_transition ); } - else if ( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) + ELSE IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev != 0 ) { /* Filtering with the first filter unit */ tcx_ltp_synth_filter_10( sig_out + delay, sig_in + delay, L_transition, hTcxLtpDec->tcxltp_pitch_int_post_prev, hTcxLtpDec->tcxltp_pitch_fr_post_prev, hTcxLtpDec->tcxltp_gain_post_prev, st->pit_res_max_past, hTcxLtpDec->tcxltp_filt_idx_prev ); } - else if ( gain != 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) + ELSE IF( gain != 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { /* Filtering with the second filter unit */ tcx_ltp_synth_filter_01( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx ); } - else if ( gain == hTcxLtpDec->tcxltp_gain_post_prev && pitch_int == hTcxLtpDec->tcxltp_pitch_int_post_prev && pitch_fr == hTcxLtpDec->tcxltp_pitch_fr_post_prev && st->pit_res_max == st->pit_res_max_past && filtIdx == hTcxLtpDec->tcxltp_filt_idx_prev ) + ELSE IF( EQ_16( gain, hTcxLtpDec->tcxltp_gain_post_prev ) && EQ_16( pitch_int, hTcxLtpDec->tcxltp_pitch_int_post_prev ) && EQ_16( pitch_fr, hTcxLtpDec->tcxltp_pitch_fr_post_prev ) && EQ_16( st->pit_res_max, st->pit_res_max_past ) && EQ_16( filtIdx, hTcxLtpDec->tcxltp_filt_idx_prev ) ) { tcx_ltp_synth_filter( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, NULL, 0, filtIdx ); } - else + ELSE { /* Filtering with the first filter unit, followed by the filtering with the second filter unit */ tcx_ltp_synth_filter_11_unequal_pitch( sig_out + delay, sig_in + delay, L_transition, pitch_int, pitch_fr, gain, st->pit_res_max, filtIdx, @@ -1574,8 +1614,12 @@ void tcx_ltp_post( } } ELSE - //#endif + // #endif { + test(); + test(); + test(); + test(); IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { Copy( sig_in + delay, sig_out + delay, L_transition ); @@ -1626,6 +1670,7 @@ void tcx_ltp_post( hTcxLtpDec->tcxltp_filt_idx_prev = filtIdx; move16(); st->pit_res_max_past = st->pit_res_max; + move16(); Copy( sig_out, hTcxLtpDec->tcxltp_mem_out, output_frame ); } @@ -1653,14 +1698,16 @@ void tcx_ltp_post32( move32(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; + total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; // TDO move32(); } filtIdx = 0; /* just to avoid comilation warnings */ - tcx_buf_len = NS2SA_fx2( st->output_Fs, TCXLTP_DELAY_NS ); + move16(); + tcx_buf_len = NS2SA_FX2( st->output_Fs, TCXLTP_DELAY_NS ); + move16(); SideInfoOnly = 0; - + move16(); if ( GE_32( total_brate, HQ_96k ) ) { SideInfoOnly = 1; @@ -1745,7 +1792,7 @@ void tcx_ltp_post32( pitch_int = idiv1616U( tmp, st->pit_res_max ); pitch_fr = sub( tmp, imult1616( pitch_int, st->pit_res_max ) ); } - IF( EQ_16( st->element_mode, EVS_MONO ) ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ + IF( st->element_mode == EVS_MONO ) /* hard tunings for EVS_MONO, HQ_48k is TCX only */ { test(); test(); @@ -1893,7 +1940,7 @@ void tcx_ltp_post32( test(); test(); test(); - //#ifdef IVAS_CODE_TCX_LTP + // #ifdef IVAS_CODE_TCX_LTP if ( st->element_mode != EVS_MONO ) { if ( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) @@ -1923,7 +1970,7 @@ void tcx_ltp_post32( } } ELSE - //#endif + // #endif { IF( gain == 0 && hTcxLtpDec->tcxltp_gain_post_prev == 0 ) { diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index 76f8e414ae432665390c09b4123fbb1cde003eb8..474f8779bf69aeaaa277a085b36fa97d759cc863 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" static Word16 TCX_MDCT_GetScaleFactor( @@ -30,7 +29,7 @@ static Word16 TCX_MDCT_GetScaleFactor( *factor_e = 0; move16(); } - ELSE IF( EQ_16( L, 4 * NORM_MDCT_FACTOR ) ) + ELSE IF( EQ_16( L, shl( NORM_MDCT_FACTOR, 2 ) ) ) { factor = 16384; move16(); @@ -109,6 +108,7 @@ void TCX_MDCT( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); *y_e = add( *y_e, factor_e ); @@ -119,13 +119,13 @@ void TCX_MDCT( /* Init */ FOR( i = 0; i < m / 2; i++ ) { - y[m / 2 + r / 2 + i] = L_mult( x[l + m / 2 - 1 - i], neg_factor ); + y[add( add( shr( m, 1 ), shr( r, 1 ) ), i )] = L_mult( x[sub( sub( add( l, shr( m, 1 ) ), 1 ), i )], neg_factor ); move32(); } FOR( i = 0; i < l / 2; i++ ) { #ifdef BASOP_NOGLOB - y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], factor ), x[l - 1 - i], factor, &Overflow ); + y[add( add( add( shr( m, 1 ), shr( r, 1 ) ), shr( m, 1 ) ), i )] = L_msu_o( L_mult( x[i], factor ), x[sub( sub( l, 1 ), i )], factor, &Overflow ); #else /* BASOP_NOGLOB */ y[m / 2 + r / 2 + m / 2 + i] = L_msu( L_mult( x[i], factor ), x[l - 1 - i], factor ); #endif /* BASOP_NOGLOB */ @@ -133,13 +133,13 @@ void TCX_MDCT( } FOR( i = 0; i < m / 2; i++ ) { - y[m / 2 + r / 2 - 1 - i] = L_mult( x[l + m / 2 + i], neg_factor ); + y[sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), i )] = L_mult( x[add( add( l, shr( m, 1 ) ), i )], neg_factor ); move32(); } FOR( i = 0; i < r / 2; i++ ) { #ifdef BASOP_NOGLOB - y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_o( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor, &Overflow ); + y[sub( sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), shr( m, 1 ) ), i )] = L_mac_o( L_mult( x[add( add( l, m ), i )], neg_factor ), x[sub( sub( add( add( l, m ), r ), 1 ), i )], neg_factor, &Overflow ); #else /* BASOP_NOGLOB */ y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor ); #endif /* BASOP_NOGLOB */ @@ -147,8 +147,10 @@ void TCX_MDCT( } *y_e = sub( 15, *y_e ); + move16(); edct_fx( y, y, l / 2 + m + r / 2, y_e ); *y_e = sub( 15 - 1, *y_e ); + move16(); return; } @@ -170,6 +172,7 @@ void TCX_MDST( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); *y_e = add( *y_e, factor_e ); @@ -179,13 +182,13 @@ void TCX_MDST( /* Init */ FOR( i = 0; i < m / 2; i++ ) { - y[m / 2 + r / 2 + i] = L_mult( x[l + m / 2 - 1 - i], neg_factor ); + y[add( add( shr( m, 1 ), shr( r, 1 ) ), i )] = L_mult( x[sub( sub( add( l, shr( m, 1 ) ), 1 ), i )], neg_factor ); move32(); } FOR( i = 0; i < l / 2; i++ ) { #ifdef BASOP_NOGLOB - y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], neg_factor ), x[l - 1 - i], factor, &Overflow ); + y[add( add( add( shr( m, 1 ), shr( r, 1 ) ), shr( m, 1 ) ), i )] = L_msu_o( L_mult( x[i], neg_factor ), x[sub( sub( l, 1 ), i )], factor, &Overflow ); #else /* BASOP_NOGLOB */ y[m / 2 + r / 2 + m / 2 + i] = L_msu( L_mult( x[i], neg_factor ), x[l - 1 - i], factor ); #endif @@ -193,13 +196,13 @@ void TCX_MDST( } FOR( i = 0; i < m / 2; i++ ) { - y[m / 2 + r / 2 - 1 - i] = L_mult( x[l + m / 2 + i], neg_factor ); + y[sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), i )] = L_mult( x[add( add( l, shr( m, 1 ) ), i )], neg_factor ); move32(); } FOR( i = 0; i < r / 2; i++ ) { #ifdef BASOP_NOGLOB - y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_sat( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], factor ); + y[sub( sub( sub( add( shr( m, 1 ), shr( r, 1 ) ), 1 ), m / 2 ), i )] = L_mac_sat( L_mult( x[add( add( l, m ), i )], neg_factor ), x[sub( sub( add( add( l, m ), r ), 1 ), i )], factor ); #else y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], factor ); #endif @@ -207,7 +210,7 @@ void TCX_MDST( } *y_e = sub( 15, *y_e ); - edst_fx( y, y, l / 2 + m + r / 2, y_e ); + edst_fx( y, y, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), y_e ); *y_e = sub( 15 - 1, *y_e ); return; } @@ -233,7 +236,7 @@ void TCX_MDCT_Inverse( R2 = shr( r, 1 ); x_e = sub( 15, x_e ); - edct_fx( x, tmp_buf + L2, l / 2 + m + r / 2, &x_e ); + edct_fx( x, tmp_buf + L2, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &x_e ); x_e = sub( 15, x_e ); fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); @@ -247,19 +250,22 @@ void TCX_MDCT_Inverse( FOR( i = 0; i < R2; i++ ) { #ifdef BASOP_NOGLOB - y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT */ + y[add( add( add( l, m ), R2 ), i )] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); /* fold out right end of DCT */ #else y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT */ #endif + + move16(); } FOR( i = 0; i < L2; i++ ) { #ifdef BASOP_NOGLOB - y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT */ + y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], fac ), s ) ); /* negate, fold out left end of DCT */ #else y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT */ #endif + move16(); } FOR( i = 0; i < shr( add( L2, add( m, R2 ) ), 1 ); i++ ) @@ -267,14 +273,15 @@ void TCX_MDCT_Inverse( Word16 f; #ifdef BASOP_NOGLOB - f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT */ + f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); + y[add( L2, i )] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ #else f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT */ #endif move16(); - y[l + m + R2 - 1 - i] = f; + y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = f; + move16(); } } @@ -290,6 +297,8 @@ void TCX_MDST_Inverse_fx( Word16 i, fac, negfac, s; Word16 L2 = l, R2 = r; + move16(); + move16(); Word32 tmp_buf[N_MAX + L_MDCT_OVLP_MAX / 2]; Word16 fac_e; @@ -297,7 +306,7 @@ void TCX_MDST_Inverse_fx( R2 = shr( r, 1 ); x_e = sub( 15, x_e ); - edst_fx( x, tmp_buf + L2, l / 2 + m + r / 2, &x_e ); + edst_fx( x, tmp_buf + L2, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &x_e ); x_e = sub( 15, x_e ); fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); @@ -310,23 +319,26 @@ void TCX_MDST_Inverse_fx( FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT */ + y[add( add( add( l, m ), R2 ), i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], fac ), s ) ); /* fold out right end of DCT */ + move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT */ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], negfac ), s ) ); /* negate, fold out left end of DCT */ + move16(); } FOR( i = 0; i < shr( add( L2, add( m, R2 ) ), 1 ); i++ ) { Word16 f; - f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], fac ), s ) ); - y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT */ + y[add( L2, i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ + move16(); + y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = negate( f ); move16(); - y[l + m + R2 - 1 - i] = negate( f ); } } @@ -354,37 +366,54 @@ void TCX_MDXT_Inverse_fx( set32_fx( tmp_buf, 0, N_MAX + L_MDCT_OVLP_MAX / 2 ); - edxt_fx( x, tmp_buf + L2, L2 + m + R2, kernel_type, TRUE ); + edxt_fx( x, tmp_buf + L2, add( add( L2, m ), R2 ), kernel_type, TRUE ); fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); x_e = add( x_e, fac_e ); negfac = negate( fac ); - signLeft = ( kernel_type >= MDCT_II ? negfac : fac ); - signRight = ( kernel_type & 1 ? fac : negfac ); + IF( GE_16( kernel_type, MDCT_II ) ) + { + signLeft = negfac; + } + ELSE + { + signLeft = fac; + } + // signRight = ( kernel_type & 1 ? fac : negfac ); + IF( L_and( kernel_type, 1 ) ) + { + signRight = fac; + } + ELSE + { + signRight = negfac; + } s = x_e; move16(); FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end */ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( add( add( L2, m ), R2 ), i )], signLeft ), s ) ); /* fold out the left end */ } FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end */ + y[add( add( add( l, m ), R2 ), i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], signRight ), s ) ); /* ...and right end */ + move16(); } - FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) + FOR( i = 0; i < ( ( add( add( L2, m ), R2 ) ) >> 1 ); i++ ) { - f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[add( L2, i )], negfac ), s ) ); - y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT */ + y[add( L2, i )] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[sub( sub( add( add( l, m ), R2 ), 1 ), i )], negfac ), s ) ); /* time-reverse mid of DCT */ + move16(); + y[sub( sub( add( add( l, m ), R2 ), 1 ), i )] = f; move16(); - y[l + m + R2 - 1 - i] = f; } return; diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c index 87333ccd4119fa6b3d1a10ecf471fd93ecdc0352..65fb6a1a0217a4e94f797dfa7f7d681239fea5e9 100644 --- a/lib_com/tcx_mdct_window.c +++ b/lib_com/tcx_mdct_window.c @@ -40,8 +40,7 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" @@ -55,13 +54,13 @@ const PWord16 *getSineWindowTable( Word16 length ); void mdct_window_sine_flt( float *window, const int32_t Fs, - const int16_t n, - const int16_t window_type, - const int16_t element_mode ) + const Word16 n, + const Word16 window_type, + const Word16 element_mode ) { if ( element_mode == EVS_MONO ) { - int16_t i; + Word16 i; float c; c = EVS_PI / ( 2.0f * (float) n ); @@ -74,26 +73,26 @@ void mdct_window_sine_flt( else { const float *window_table = 0; - int16_t buf_in_size = 0; + Word16 buf_in_size = 0; switch ( window_type ) { case FULL_OVERLAP: window_table = tcx_mdct_window_48; buf_in_size = 420; - break; + BREAK; case HALF_OVERLAP: window_table = tcx_mdct_window_half_48; buf_in_size = 180; - break; + BREAK; case TRANSITION_OVERLAP: case MIN_OVERLAP: window_table = tcx_mdct_window_trans_48; buf_in_size = 60; - break; + BREAK; default: assert( 0 && "Unsupported window type" ); - break; + BREAK; } if ( Fs == 48000 ) @@ -116,56 +115,64 @@ void mdct_window_sine_IVAS_updated( const Word16 window_type, const Word16 element_mode ) { - if ( element_mode == EVS_MONO ) + IF( EQ_16( element_mode, EVS_MONO ) ) { const PWord16 *table; table = getSineWindowTable( n ); - for ( int i = 0; i < n / 2; i++ ) + FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) { window[i].v.re = table[i].v.re; + move16(); window[i].v.im = table[i].v.im; + move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") } - else + ELSE { const Word16 *window_table = 0; - int16_t buf_in_size = 0; - Word16 temp[420] = { 0 }; - switch ( window_type ) + Word16 buf_in_size = 0; + move16(); + Word16 temp[420]; + set16_fx( temp, 0, 420 ); + SWITCH( window_type ) { case FULL_OVERLAP: window_table = tcx_mdct_window_48_fx; buf_in_size = 420; - break; + move16(); + BREAK; case HALF_OVERLAP: window_table = tcx_mdct_window_half_48_fx; buf_in_size = 180; - break; + BREAK; case TRANSITION_OVERLAP: case MIN_OVERLAP: window_table = tcx_mdct_window_trans_48_fx; buf_in_size = 60; - break; + move16(); + BREAK; default: assert( 0 && "Unsupported window type" ); - break; + BREAK; } - if ( Fs == 48000 ) + IF( EQ_32( Fs, 48000 ) ) { Copy( window_table, temp, n ); } - else + ELSE { lerp( window_table, temp, n, buf_in_size ); } - for ( int i = 0; i < n / 2; i++ ) + FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) { window[i].v.re = temp[n - 1 - i]; + move16(); window[i].v.im = temp[i]; + move16(); } } } @@ -179,10 +186,12 @@ void mdct_window_sine( PWord16 *window, Word16 n ) { const PWord16 *table; table = getSineWindowTable( n ); - for ( int i = 0; i < n / 2; i++ ) + FOR( Word32 i = 0; i < shr( n, 1 ); i++ ) { window[i].v.re = table[i].v.re; + move16(); window[i].v.im = table[i].v.im; + move16(); } // PMT("getSineWindowTable needs to be updated for IVAS") } @@ -190,7 +199,7 @@ void mdct_window_sine( PWord16 *window, Word16 n ) else { const float *window_table = 0; - int16_t buf_in_size = 0; + Word16 buf_in_size = 0; switch ( window_type ) { case FULL_OVERLAP: @@ -233,9 +242,9 @@ void mdct_window_sine( PWord16 *window, Word16 n ) void mdct_window_aldo_flt( float *window1, float *window2, - const int16_t n ) + const Word16 n ) { - int16_t i, n1, n2, d; + Word16 i, n1, n2, d; const float *p1, *p2; /* set table pointers and decimation factor */ @@ -394,6 +403,7 @@ void mdct_window_aldo( p1 = window_48kHz_fx + 2; p2 = window_48kHz_fx + 1110 - 3; d = 6; + move16(); BREAK; case 512 / 2: p1 = window_256kHz; @@ -404,11 +414,13 @@ void mdct_window_aldo( p1 = window_48kHz_fx + 1; p2 = window_48kHz_fx + 1110 - 2; d = 3; + move16(); BREAK; case 1024 / 2: p1 = window_256kHz; p2 = window_256kHz + 592 - 1; d = 1; + move16(); BREAK; case 1280 / 2: p1 = window_48kHz_fx + 1; @@ -419,6 +431,7 @@ void mdct_window_aldo( p1 = window_48kHz_fx; p2 = window_48kHz_fx + 1110 - 1; d = 1; + move16(); BREAK; default: assert( 0 ); diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 74149f2bea571b767536bc948bced51dd3c12d00..60f26d30324a0e8e1b4d2c1c830c9bb72ee0c842 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "rom_basop_util.h" #include "basop_util.h" @@ -75,7 +74,6 @@ static void tcx_get_windows( *left_overlap = hTcxCfg->tcx_mdct_window_length; move16(); *left_win = hTcxCfg->tcx_aldo_window_1_trunc; - move16(); BREAK; default: assert( !"Not supported overlap" ); @@ -98,7 +96,6 @@ static void tcx_get_windows( *right_overlap = hTcxCfg->tcx_mdct_window_delay; move16(); *right_win = hTcxCfg->tcx_aldo_window_2; - move16(); BREAK; default: assert( !"Not supported overlap" ); @@ -131,10 +128,8 @@ static void tcx_get_windows( BREAK; case FULL_OVERLAP: *left_overlap = hTcxCfg->tcx_mdct_window_lengthFB; - *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; - move16(); move16(); - + *left_win = hTcxCfg->tcx_aldo_window_1_FB_trunc; BREAK; default: assert( !"Not supported overlap" ); @@ -161,7 +156,6 @@ static void tcx_get_windows( case FULL_OVERLAP: *right_overlap = hTcxCfg->tcx_mdct_window_delayFB; move16(); - move16(); *right_win = hTcxCfg->tcx_aldo_window_2_FB; BREAK; default: @@ -366,8 +360,8 @@ void tcx_windowing_synthesis_current_frame( { /*signal[i] *= (float)(i)/(float)(acelp_zir_len); signal[i] += acelp_zir[i]*(float)(acelp_zir_len-i)/(float)(acelp_zir_len);*/ - move16(); signal[i] = add( mult_r( signal[i], div_s( i, acelp_zir_len ) ), mult_r( acelp_zir[i], div_s( sub( acelp_zir_len, i ), acelp_zir_len ) ) ); + move16(); } } /* Rectangular window (past-frame is ACELP) */ @@ -706,8 +700,8 @@ void lpc2mdct( Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp, - const int16_t length, - const int16_t noInverse ) + const Word16 length, + const Word16 noInverse ) { Word32 ComplexData[2 * FDNS_NPTS]; Word16 i, j, k, sizeN, step, scale, s, tmp16; @@ -739,7 +733,9 @@ void lpc2mdct( FOR( ; i < FDNS_NPTS; i++ ) { ComplexData[2 * i] = L_deposit_l( 0 ); + move32(); ComplexData[2 * i + 1] = L_deposit_l( 0 ); + move32(); } move16(); @@ -873,14 +869,18 @@ void lpc2mdct_2( FOR( i = 0; i < lpcOrder + 1; i++ ) { RealData_fx[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + move32(); ImagData_fx[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + move32(); ptwiddle += step; } FOR( ; i < sizeN; i++ ) { RealData_fx[i] = L_deposit_l( 0 ); + move32(); ImagData_fx[i] = L_deposit_l( 0 ); + move32(); } /* half length FFT */ @@ -888,7 +888,8 @@ void lpc2mdct_2( BASOP_cfft_ivas( RealData_fx, ImagData_fx, 1, &scale ); /*Get amplitude*/ - j = FDNS_NPTS - 1; + j = sub( FDNS_NPTS, 1 ); + move16(); k = 0; move16(); @@ -1172,11 +1173,13 @@ void mdct_noiseShaping_ivas_fx( Word16 m, n, k1, k2; j = 0; + move16(); /* FDNS_NPTS = 64 */ k = shr( lg, 6 ); m = s_and( lg, 0x3F ); Word16 max_e = MIN16B; + move16(); FOR( i = 0; i < FDNS_NPTS; i++ ) { max_e = s_max( max_e, add( *x_e, gains_exp[i] ) ); @@ -1223,7 +1226,9 @@ void mdct_noiseShaping_ivas_fx( FOR( l = 0; l < k; l++ ) { x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); + move32(); x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); + move32(); i = add( i, 1 ); } j = add( j, 1 ); @@ -1236,7 +1241,9 @@ void mdct_noiseShaping_ivas_fx( FOR( l = 0; l < k; l++ ) { x_fx[i] = Mpy_32_16_1( x_fx[i], gains_fx[j] ); + move32(); x_fx[i] = L_shr( x_fx[i], sub( max_e, add( *x_e, gains_exp[j] ) ) ); + move32(); i = add( i, 1 ); } j = add( j, 1 ); @@ -1739,7 +1746,6 @@ void tcx_noise_filling( nrg = L_deposit_l( 1 ); win = 0; move16(); - move16(); FOR( ; i < lowpassLine; i++ ) { @@ -1851,7 +1857,7 @@ void tcx_noise_filling_with_shift( tmp32 = L_shr( Mpy_32_16_1( tmp32, tmp1 ), 6 ); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); + tilt_factor = round_fx_sat( BASOP_Util_InvLog2( tmp32 ) ); #else tilt_factor = round_fx( BASOP_Util_InvLog2( tmp32 ) ); #endif @@ -1882,11 +1888,11 @@ void tcx_noise_filling_with_shift( } i = add( i, 1 ); segmentOffset = i; + move16(); } nrg = L_deposit_l( 1 ); win = 0; move16(); - move16(); FOR( ; i < lowpassLine; i++ ) { @@ -1909,13 +1915,15 @@ void tcx_noise_filling_with_shift( FOR( m = segmentOffset; m < tmp2; m++ ) { Word16 nrm = 31; - + move16(); Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } Q[m] = L_shl( Q[m], nrm ); + move32(); new_Q_e[m] = sub( add( new_Q_e[m], s ), nrm ); move32(); } @@ -1928,11 +1936,13 @@ void tcx_noise_filling_with_shift( Word16 nrm = 31; Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } Q[m] = L_shl( Q[m], nrm ); + move32(); new_Q_e[m] = sub( add( new_Q_e[m], s ), nrm ); move32(); win = sub( win, 1 ); @@ -1951,16 +1961,18 @@ void tcx_noise_filling_with_shift( } Word16 nrm = 31; + move16(); Random( &seed ); Q[i] = L_mult0( mult( seed, fac_ns ), win ); + move32(); IF( Q[i] ) { nrm = norm_l( Q[i] ); } Q[i] = L_shl( Q[i], nrm ); - new_Q_e[i] = 31 - nrm; move32(); + new_Q_e[i] = sub( 31, nrm ); tmp1 = shr( seed, 4 ); nrg = L_mac0( nrg, tmp1, tmp1 ); /* sum up energy of current noise segment */ @@ -1985,24 +1997,27 @@ void tcx_noise_filling_with_shift( FOR( m = segmentOffset; m < lowpassLine; m++ ) { Word16 nrm = 31; - + move16(); /* at this point: - flt Q[m] = (Q[m] * 2^(new_Q_e[m] - 31)) / (nTransWidth*nTransWidth) - flt tmp1 = (tmp1 * 2^(s - 15)) * (nTransWidth*nTransWidth) */ Q[m] = Mpy_32_16_1( Q[m], tmp1 ); + move32(); IF( Q[m] ) { nrm = norm_l( Q[m] ); } Q[m] = L_shl( Q[m], nrm ); + move32(); new_Q_e[m] = add( new_Q_e[m], s - nrm ); move32(); } } Word16 max_e = 0; + move16(); FOR( i = 0; i < lowpassLine; i++ ) { max_e = s_max( max_e, new_Q_e[i] ); @@ -2011,6 +2026,7 @@ void tcx_noise_filling_with_shift( FOR( i = 0; i < lowpassLine; i++ ) { Q[i] = L_shr( Q[i], sub( max_e, new_Q_e[i] ) ); + move32(); } *Q_e = max_e; @@ -2028,8 +2044,8 @@ void InitTnsConfigs( STnsConfig tnsConfig[2][2], const Word16 igfStopFreq, const Word32 total_brate, - const int16_t element_mode, - const int16_t MCT_flag ) + const Word16 element_mode, + const Word16 MCT_flag ) { IF( GT_32( total_brate, ACELP_32k ) ) { @@ -2063,10 +2079,13 @@ void SetAllowTnsOnWhite( ) { tnsConfig[0][0].allowTnsOnWhite = allowTnsOnWhite; + move16(); tnsConfig[0][1].allowTnsOnWhite = allowTnsOnWhite; + move16(); tnsConfig[1][0].allowTnsOnWhite = allowTnsOnWhite; + move16(); tnsConfig[1][1].allowTnsOnWhite = allowTnsOnWhite; - + move16(); return; } #endif @@ -2216,27 +2235,31 @@ void init_TCX_config( { /* Initialize the TCX MDCT windows */ hTcxCfg->tcx_mdct_window_length = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); + move16(); hTcxCfg->tcx_mdct_window_delay = hTcxCfg->tcx_mdct_window_length; move16(); hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscale ), LD_FSCALE_DENOM ) ); - - hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + move16(); + hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */ + move16(); hTcxCfg->tcx_mdct_window_trans_length = shr( L_frame, 4 ); /* 1.25ms */ - + move16(); hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* 5ms */ - + move16(); hTcxCfg->tcx_mdct_window_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscaleFB ), LD_FSCALE_DENOM ) ); + move16(); hTcxCfg->tcx_mdct_window_delayFB = hTcxCfg->tcx_mdct_window_lengthFB; move16(); hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), fscaleFB ), LD_FSCALE_DENOM ) ); - - hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + move16(); + hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ + move16(); hTcxCfg->tcx_mdct_window_trans_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */ - + move16(); hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* 5ms */ - + move16(); mdct_window_sine( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_window_length ); mdct_window_sine( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_half_length ); mdct_window_sine( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_min_length ); diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index 5e32b842b2bad659208a06ff9b7b91e9875fa281..32c6e9fef23a75214a4490e13f24856c26f10198 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -5,8 +5,7 @@ #include #include "options.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" #include "rom_com.h" @@ -80,6 +79,7 @@ static Word32 calcVar_Fix( xx = L_deposit_l( 0 ); *x = L_deposit_l( 0 ); + move32(); FOR( i = 0; i < len; i++ ) { @@ -88,6 +88,7 @@ static Word32 calcVar_Fix( tmpX = L_shr( Mpy_32_32( L_shl( in[i], exp1 ), L_shl( in[i], exp1 ) ), r_sft ); xx = L_add( xx, tmpX ); *x = L_add( *x, in[i] ); + move32(); } ans = L_deposit_l( 0 ); @@ -213,11 +214,13 @@ static Word32 calcCorrelationCoefficient2_Fix( r_sft = sub( 8, sub( exp2, exp1 ) ); tmpCor = L_shr( tmpCor, r_sft ); ans = tmpCor; + move16(); } } ELSE { ans = 0; + move16(); } @@ -256,7 +259,6 @@ static void calcLoBufferEnc_Fx( li = TecLowBandTable[lb]; move16(); ui = sub( TecLowBandTable[lb + 1], 1 ); - move16(); assert( ( ui - li ) == 1 ); @@ -283,6 +285,7 @@ static void calcLoBufferEnc_Fx( /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + move16(); } } /*------------------------------------------------------------------- @@ -318,7 +321,6 @@ static void calcHiTempEnv_Fx( normFac = getNormReciprocalWord16( bwHigh ); scale = sub( scale, s1 ); - move16(); FOR( timeIndex = startPos; timeIndex < stopPos; timeIndex++ ) { @@ -350,6 +352,7 @@ static void calcHiTempEnv_Fx( /* 0.75257498916 = 10 * log10(2.0) / 4.0 */ hiTempEnv[timeIndex] = extract_h( L_shr( L_shl( Mpy_32_16_1( nrgLog, 24660 /*0.75257498916 Q15*/ ), 2 ), 1 ) ); + move16(); } } /*------------------------------------------------------------------- @@ -433,6 +436,7 @@ static void calcLoBufferDec_Fx( /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + move16(); } ELSE { @@ -468,6 +472,7 @@ static void calcLoTempEnv_Fx( } /* adjFac is scaled by factor 0.5 */ loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + move16(); } } /*------------------------------------------------------------------- @@ -506,6 +511,7 @@ static void calcLoTempEnv_TBE_Fx( Word16 slot; Word32 accu; Word16 delay = 1; + move16(); /* TecSC_Fx values are scaled by factor 2.0 */ FOR( slot = 0; slot < noCols; slot++ ) @@ -517,6 +523,7 @@ static void calcLoTempEnv_TBE_Fx( } /* adjFac is scaled by factor 0.5 */ loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + move16(); } } /*------------------------------------------------------------------- @@ -534,6 +541,7 @@ static void calcLoTempEnv_ns_TBE_Fx( Word16 slot; Word16 delay = 1; Word16 fac = 22938 /*1.4f * 0.5f Q15*/; + move16(); FOR( slot = 0; slot < noCols; slot++ ) { @@ -605,7 +613,9 @@ static void calcGainLinear_TBE_Fx( s2 = norm_l( tmp32 ); pGainTemp_m[slot] = extract_h( L_shl( tmp32, s2 ) ); + move16(); pGainTemp_e[slot] = sub( s, s2 ); + move16(); } } /*------------------------------------------------------------------- @@ -629,10 +639,11 @@ void calcGainTemp_TBE_Fx( Word16 loTempEnv_Fx[16]; const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; + move16(); Word16 slot; - Word16 noCols = stopPos - startPos; - Word16 bandOffset = lowSubband - BW_LO; + Word16 noCols = sub( stopPos, startPos ); + Word16 bandOffset = sub( lowSubband, BW_LO ); assert( lowSubband >= BW_LO ); @@ -643,7 +654,7 @@ void calcGainTemp_TBE_Fx( startPos, stopPos, bandOffset, - 15 - cldfb_exp ); + sub( 15, cldfb_exp ) ); IF( code > 0 ) { @@ -680,7 +691,9 @@ static void setSubfrConfig_Fix( const Word16 l_subfr ) { *n_subfr = sub( (Word16) N_TEC_TFA_SUBFR, i_offset ); + move16(); *k_offset = i_mult( i_offset, l_subfr ); + move16(); } /*------------------------------------------------------------------- * calcSum_Fx() @@ -699,7 +712,9 @@ static Word16 calcSum_Fx( Word16 sum16_e; /* Q0 */ *sum16_m = 0; + move16(); sum16_e = 0; + move16(); FOR( slot = 0; slot < len; slot++ ) { sum16_e = BASOP_Util_Add_MantExp( @@ -731,8 +746,10 @@ static Word16 calcSubfrNrg_Fx( Word16 s; Word16 sum16_e; Word16 s2 = 1; /* headroom for a summatoin of length l_subfr ( < 2^s2 = 64 ) */ + move16(); k = k_offset; + move16(); FOR( i = i_offset; i < N_TEC_TFA_SUBFR; i++ ) { Word32 nrg32; @@ -771,7 +788,9 @@ static Word16 calcSubfrNrg_Fx( } sum16_e = enr_e[i_offset]; + move16(); *sum16_m = enr_m[i_offset]; + move16(); FOR( i = i_offset + 1; i < N_TEC_TFA_SUBFR; i++ ) { @@ -868,6 +887,7 @@ static Word16 procTec_Fx( gain_ave_e = sub( gain_ave_e, 3 ); k = k_offset; + move16(); FOR( i = i_offset; i < N_TEC_TFA_SUBFR; i++ ) { IF( enr_m[i] > 0 ) @@ -943,7 +963,6 @@ static Word16 procTec_Fx( lower_limit_gain_m = min_curr_enr_m; move16(); lower_limit_gain_e = sub( min_curr_enr_e, 1 ); - move16(); } /* upper_limit_gain */ @@ -977,7 +996,9 @@ static Word16 procTec_Fx( } gain_m[i] = mult_r( gain_m[i], inv_curr_enr_m[i] ); + move16(); gain_e[i] = add( gain_e[i], inv_curr_enr_e[i] ); + move16(); s = norm_s( gain_m[i] ); gain_m[i] = shl( gain_m[i], s ); @@ -1009,8 +1030,7 @@ static Word16 procTec_Fx( s = norm_s( hb_synth_Fx[k] ); hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); move16(); - shift[k] = s - gain_e[i]; - move16(); + shift[k] = sub( s, gain_e[i] ); if ( GT_16( min_shift, shift[k] ) ) { @@ -1040,6 +1060,7 @@ static Word16 procTec_Fx( min_shift = sub( s, exp_syn ); /* exp_syn(old) - exp_syn(new) */ k = k_offset; + move16(); FOR( i = i_offset; i < N_TEC_TFA_SUBFR; i++ ) { FOR( j = 0; j < l_subfr; j++ ) @@ -1203,6 +1224,7 @@ Word16 procTecTfa_TBE_Fx( Word16 code ) { Word16 i_offset = 0; + move16(); Word16 exp_syn_frame = sub( 15, hb_synth_fx_exp ); @@ -1252,8 +1274,11 @@ void calcHiEnvLoBuff_Fix( Word16 pCldfbPow_FixScale ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; + move16(); const Word16 lowSubband = pFreqBandTable[0]; + move16(); const Word16 highSubband = pFreqBandTable[nSfb]; + move16(); Word16 bandOffsetBottom; @@ -1300,7 +1325,9 @@ void calcLoEnvCheckCorrHiLo_Fix( ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; + move16(); const Word16 lowSubband = pFreqBandTable[0]; + move16(); Word16 i; Word16 bandOffsetBottom; @@ -1317,6 +1344,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word32 EQ4, EQ5, EQ6; Word16 code = 0; /* SET TENTATIVELY */ + move16(); Word32 loVar_ns_Fix; Word32 diff_hi_lo_sum_Fix; Word32 loSum_ns_Fix; @@ -1335,6 +1363,7 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); + move32(); } hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); @@ -1355,6 +1384,7 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols; i++ ) { loTempEnv32_ns_Fix[i] = L_deposit_l( loTempEnv_ns_Fix[i] ); + move32(); } loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); @@ -1362,9 +1392,9 @@ void calcLoEnvCheckCorrHiLo_Fix( EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); - ; + EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); - ; + test(); test(); if ( EQ4 > 0 && EQ5 > 0 && EQ6 < 0 ) @@ -1393,6 +1423,7 @@ void calcLoEnvCheckCorrHiLo_Fix( move16(); maxPosHi = maxPosLo = 0; move16(); + move16(); FOR( i = 1; i < noCols; i++ ) { if ( LT_16( maxHiFix, hiTempEnv[i] ) ) @@ -1419,12 +1450,14 @@ void calcLoEnvCheckCorrHiLo_Fix( { Word16 feature_max_Fix = 0; + move16(); Word16 pos_feature_max = 0; + move16(); Word16 feature_Fix[16]; Word16 min_local_Fix, max_local_Fix; Word16 j; Word16 len_window = EXT_DELAY_HI_TEMP_ENV + 1; - + move16(); Word16 *curr_pos_Fix = hiTempEnv; move16(); @@ -1458,6 +1491,7 @@ void calcLoEnvCheckCorrHiLo_Fix( } } feature_Fix[i] = sub( max_local_Fix, min_local_Fix ); + move16(); if ( LT_16( feature_max_Fix, feature_Fix[i] ) ) { @@ -1492,6 +1526,7 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols; i++ ) { loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); + move32(); } loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); /* = = */ diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index f89bf8e07bbf57d895b42b5a30401e6c159f331f..c9130877094380f5d42b38e62014f550d116f764 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -10,8 +10,7 @@ #include "stat_com.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" /*---------------------------------------------------------------------------- @@ -90,6 +89,7 @@ void InitTnsConfiguration( const int16_t is_mct ) { Word16 iFilter = 0; + move16(); Word16 *startLineFilter; Word32 L_tmp; Word32 nSampleRate; @@ -105,7 +105,9 @@ void InitTnsConfiguration( /* Sanity checks */ assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); - if ( ( nSampleRate <= 0 ) || ( frameLength <= 0 ) || ( pTnsConfig == NULL ) ) + test(); + test(); + IF( ( nSampleRate <= 0 ) || ( frameLength <= 0 ) || ( pTnsConfig == NULL ) ) { return /*TNS_FATAL_ERROR*/; } @@ -250,8 +252,6 @@ void ApplyTnsFilter( Word16 parCoeff[TNS_MAX_FILTER_ORDER]; const STnsFilter *pFilter; - - move16(); move16(); move16(); pFilter = &pTnsData->filter[iFilter]; @@ -309,6 +309,7 @@ Word16 ITF_Detect_fx( Word16 spectrumLength; Word16 const nSubdivisions = MAX_SUBDIVISIONS; + move16(); Word16 iSubdivisions; Word16 iStartLine; Word16 iEndLine; @@ -323,6 +324,7 @@ Word16 ITF_Detect_fx( Word16 n, i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); @@ -357,7 +359,7 @@ Word16 ITF_Detect_fx( /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); #else /* BASOP_NOGLOB */ tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif @@ -435,6 +437,7 @@ Word16 ITF_Detect_fx( FOR( i = 0; i < n; i++ ) { tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); + move16(); } FOR( lag = 0; lag <= maxOrder; lag++ ) @@ -464,6 +467,7 @@ Word16 ITF_Detect_fx( ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; + move16(); } return 1; @@ -483,6 +487,7 @@ Word16 ITF_Detect_ivas_fx( Word16 spectrumLength; Word16 const nSubdivisions = MAX_SUBDIVISIONS; + move16(); Word16 iSubdivisions; Word16 iStartLine; Word16 iEndLine; @@ -497,6 +502,7 @@ Word16 ITF_Detect_ivas_fx( Word16 n, i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); @@ -605,6 +611,7 @@ Word16 ITF_Detect_ivas_fx( FOR( i = 0; i < n; i++ ) { tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); + move16(); } FOR( lag = 0; lag <= maxOrder; lag++ ) @@ -634,6 +641,7 @@ Word16 ITF_Detect_ivas_fx( ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; + move16(); } return 1; @@ -672,6 +680,8 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding { Word16 code = 0; Word16 nBits = 0; + move16(); + move16(); Word16 valueIndex; assert( ( nSize >= 0 ) && ( nSize <= 256 ) ); @@ -683,12 +693,14 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding WHILE( valueIndex == nSize ) { - code = add( shl( code, 1 ), get_next_indice( st, 1 ) ); + code = add( shl( code, 1 ), get_next_indice_fx( st, 1 ) ); nBits = add( nBits, 1 ); if ( nBits > nSize || nBits > 16 ) { st->BER_detect = 1; + move16(); *pValue = 0; + move16(); return -1; } @@ -705,12 +717,14 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding if ( valueIndex < nSize ) { *pValue = (Word16) codes[valueIndex].value; + move16(); } else { st->BER_detect = 1; + move16(); *pValue = 0; - + move16(); return -1; } @@ -723,12 +737,14 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding void const *GetTnsFilterCoeff( void const *p, const Word16 index, Word16 *pValue ) { *pValue = ( (Word16 const *) p )[index] + INDEX_SHIFT; + move16(); return NULL; } void *SetTnsFilterCoeff( void *p, const Word16 index, const Word16 value ) { ( (Word16 *) p )[index] = sub( value, INDEX_SHIFT ); + move16(); return NULL; } @@ -884,15 +900,17 @@ Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pVal void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValue ) { + move16(); *pValue = ( (STnsData const *) p )[index].nFilters; - + move16(); return ( (STnsData const *) p )[index].filter; } void *SetNumOfTnsFilters( void *p, const Word16 index, Word16 value ) { + move16(); ( (STnsData *) p )[index].nFilters = value; - + move16(); return ( (STnsData *) p )[index].filter; } @@ -951,7 +969,9 @@ void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ) { + move16(); ( (STnsData *) p )[index].nFilters = value; + move16(); return ( (STnsData *) p )[index].filter; } @@ -966,13 +986,18 @@ void ResetTnsData( STnsData *pTnsData ) pTnsData->nFilters = 0; + move16(); pTnsData->tnsOnWhitenedSpectra = 0; + move16(); FOR( iFilter = 0; iFilter < (Word16) ( sizeof( pTnsData->filter ) / sizeof( pTnsData->filter[0] ) ); iFilter++ ) { STnsFilter *const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; + move16(); pTnsFilter->predictionGain = ONE_IN_Q7; + move16(); pTnsFilter->avgSqrCoef = 0; + move16(); /* TODO: remove float _flt dependencies */ pTnsFilter->predictionGain_flt = 1.0f; pTnsFilter->avgSqrCoef_flt = 0; @@ -990,6 +1015,7 @@ void ClearTnsFilterCoefficients( { move16(); pTnsFilter->order = 0; + move16(); assert( TNS_MAX_FILTER_ORDER == 8 ); move16(); move16(); @@ -1070,12 +1096,12 @@ static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, W /* first stage: no need to calculate state[order-1] */ - x = L_sub( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); + x = Msub_32_16( x, state[order - 1], parCoeff[order - 1] ); FOR( i = order - 2; i >= 0; i-- ) { - x = L_sub( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); - state[i + 1] = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); + x = Msub_32_16( x, state[i], parCoeff[i] ); + state[i + 1] = Madd_32_16( state[i], x, parCoeff[i] ); move32(); } @@ -1194,6 +1220,7 @@ static void ITF_GetFilterParameters_fx( L_tmp = E_LPC_schur( rxx, parCoeff, epsP, maxOrder ); BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); + move16(); BASOP_SATURATE_WARNING_ON_EVS { @@ -1202,8 +1229,9 @@ static void ITF_GetFilterParameters_fx( /* Convert ParCor / reflection coefficients to LPC */ A32[0] = 134217728l /*1.0 Q27*/; - move16(); /* Q11+16 */ + move32(); /* Q11+16 */ A32[1] = L_shr( L_deposit_h( parCoeff[0] ), 4 ); /* Q11+16 */ + move32(); FOR( i = 1; i < maxOrder; i++ ) { @@ -1239,8 +1267,10 @@ static void ITF_GetFilterParameters_fx( FOR( i = 0; i < maxOrder; i++ ) { A[i] = round_fx( L_shl( A32[i], tmp ) ); /* Q11+tmp */ + move16(); } *Q_A = add( 11, tmp ); + move16(); } return; } diff --git a/lib_com/tools.c b/lib_com/tools.c index 55d866a3e336a3db7a88de40da7394ddb577b9bf..64de07a75841248a4c168b386f2c96aeff8fdbec 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -38,9 +38,8 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "wmc_auto.h" -#include "prot_fx1.h" /*------------------------------------------------------------------* * own_random() @@ -197,6 +196,22 @@ Word32 sum2_f_16_fx( return tmp; } +Word32 sum2_f_16_gb_fx( + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 gb ) +{ + int16_t i; + Word32 tmp; + + tmp = 0; + FOR( i = 0; i < lvec; i++ ) + { + tmp = L_add( tmp, L_shr( L_mult0( vec[i], vec[i] ), gb ) ); + } + + return tmp; +} #endif float sum2_f( const float *vec, /* i : input vector */ @@ -216,10 +231,41 @@ float sum2_f( } #ifdef IVAS_FLOAT_FIXED -Word32 sum2_f_32_fx( - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word16 gb ) +Word32 sum2_32_exp_fx( + const Word32 *vec, /* i : input vector, Qx */ + const Word16 lvec, /* i : length of input vector */ + Word16 *exp, /* i/o: exponent of vector */ + Word16 gb /* i : guard bits */ +) +{ + Word16 i, s; + Word64 W_tmp; + + W_tmp = 0; + Word64 var_a = 0; + move64(); + move64(); + FOR( i = 0; i < lvec; i++ ) + { + var_a = W_mult0_32_32( vec[i], vec[i] ); // 2x + W_tmp = W_add( W_tmp, W_shr( var_a, gb ) ); // 2x-gb + } + + s = W_norm( W_tmp ); + W_tmp = W_shl( W_tmp, s ); // 2x - gb + s + + //*exp = 31 - (2*(31 - *exp) - gb + s) + 32; + *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 ); + move16(); + + return W_extract_h( W_tmp ); +} + +Word32 sum2_f_32_fx( /* o : Q(2x - 31 - gb) */ + const Word32 *vec, /* i : input vector, Qx */ + const Word16 lvec, /* i : length of input vector */ + Word16 gb /* i : guard bits */ +) { Word16 i; Word32 tmp; @@ -341,29 +387,7 @@ void set_f( return; } -#ifdef IVAS_FLOAT_FIXED -/*---------------------------------------------------------------------* - * set_zero() - * - * Set a vector vec[] of dimension lvec to zero - *---------------------------------------------------------------------*/ -void set_zero_fx( - Word32 *vec, /* o : input vector */ - const Word16 lvec /* i : length of the vector */ -) -{ - Word16 i; - - FOR( i = 0; i < lvec; i++ ) - { - *vec++ = 0; - move32(); - } - - return; -} -#endif /*---------------------------------------------------------------------* * set_zero() * @@ -523,78 +547,6 @@ uint32_t mvr2s( return noClipping; } -#ifdef IVAS_FLOAT_FIXED -UWord32 mvl2s_r( - const Word32 x[], /* i : input vector */ - const Word16 q_x, - Word16 y[], /* o : output vector */ - const Word16 n /* i : vector size */ -) -{ - Word16 i; - Word32 temp; - UWord32 noClipping = 0; - move32(); - - IF( n <= 0 ) - { - /* cannot transfer vectors with size 0 */ - return 0; - } - - IF( (void *) y <= (const void *) x ) - { - FOR( i = 0; i < n; i++ ) - { - temp = L_shr( x[i], sub( q_x, 1 ) ); - temp = L_shr( L_add( temp, 1 ), 1 ); - - IF( GT_32( temp, MAX16B ) ) - { - temp = MAX16B; - move32(); - noClipping = L_add( (Word32) noClipping, 1 ); - } - ELSE IF( LT_32( temp, MIN16B ) ) - { - temp = MIN16B; - move32(); - noClipping = L_add( (Word32) noClipping, 1 ); - } - - y[i] = extract_l( temp ); - move16(); - } - } - ELSE - { - FOR( i = n - 1; i >= 0; i-- ) - { - temp = L_shr( x[i], q_x - 1 ); - temp = L_shr( L_add( temp, 1 ), 1 ); - - IF( GT_32( temp, MAX16B ) ) - { - temp = MAX16B; - move32(); - noClipping = L_add( (Word32) noClipping, 1 ); - } - ELSE IF( LT_32( temp, MIN16B ) ) - { - temp = MIN16B; - move32(); - noClipping = L_add( (Word32) noClipping, 1 ); - } - - y[i] = extract_l( temp ); - move16(); - } - } - - return noClipping; -} -#endif - void mvs2r( const int16_t x[], /* i : input vector */ float y[], /* o : output vector */ @@ -1086,29 +1038,38 @@ Word32 dotp_fixed( return suma; } -#ifdef IVAS_FLOAT_FIXED -Word32 dotp_fixed_guarded( - const Word32 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ +/*To calculate dot product of two 32 bit arrays in case of overflow*/ +Word32 dotp_fixed_o( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */ + Word16 *res_q /*stores resultant Q*/ ) { Word16 i; - Word32 suma; - Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( Mpy_32_32( x[0], y[0] ), guarded_bits ); + Word64 suma; /*resultant q= q(x)+q(y)-9-x such that q<=31*/ + + suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len ); FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( Mpy_32_32( x[i], y[i] ), guarded_bits ) ); + suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) ); } - - return suma; + *res_q = add( sub( *res_q, log_len ), 1 ); + move16(); + test(); + test(); + WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) ) + { + suma = W_shr( suma, 1 ); + *res_q = sub( *res_q, 1 ); + move16(); + } + return W_extract_l( suma ); } -#endif -/*To calculate dot product of two 32 bit arrays in case of overflow*/ -Word32 dotp_fixed_o( +Word32 dotp_fixed_32( const Word32 x[], /* i : vector x[] */ const Word32 y[], /* i : vector y[] */ const Word16 n, /* i : vector length */ @@ -1125,10 +1086,11 @@ Word32 dotp_fixed_o( { suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) ); } - *res_q = add( sub( *res_q, log_len ), 1 ); + *res_q = add( *res_q, add( sub( *res_q, log_len ), 1 ) ); move16(); test(); - WHILE( GT_64( suma, MAX_32 ) || GT_16( *res_q, 31 ) ) + test(); + WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) ) { suma = W_shr( suma, 1 ); *res_q = sub( *res_q, 1 ); @@ -1136,6 +1098,7 @@ Word32 dotp_fixed_o( } return W_extract_l( suma ); } + /*---------------------------------------------------------------------* * inv_sqrt() * @@ -1257,58 +1220,6 @@ void v_add( return; } -/*-------------------------------------------------------------------* - * v_add_fixed() - * - * Subtraction of two vectors sample by sample - *-------------------------------------------------------------------*/ - -void v_add_fixed( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ - const Word16 N, /* i : Vector length */ - const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ -) -{ - Word16 i; - - FOR( i = 0; i < N; i++ ) - { - y[i] = L_add( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) ); - move32(); - } - - return; -} - -void v_add_fixed_me( - const Word32 x1[], /* i : Input vector 1 */ - const Word16 x1_e, /* i : Exponent for input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - const Word16 x2_e, /* i : Exponent for input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ - Word16 *y_e, /* i : Exponent for output vector */ - const Word16 N, /* i : Vector length */ - const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ -) -{ - Word16 i; - Word16 x1_shift = sub( s_max( x1_e, x2_e ), x1_e ); - Word16 x2_shift = sub( s_max( x1_e, x2_e ), x2_e ); - - FOR( i = 0; i < N; i++ ) - { - y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); - move32(); - } - - *y_e = add( s_max( x1_e, x2_e ), hdrm ); - move16(); - - return; -} - /*-------------------------------------------------------------------* * v_add_w64() @@ -1389,25 +1300,6 @@ void v_sub_fixed( * * Multiplication of two vectors *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void v_mult_fixed( - const Word32 x1[], /* i : Input vector 1 */ - const Word32 x2[], /* i : Input vector 2 */ - Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 N /* i : Vector length */ -) -{ - Word16 i; - - FOR( i = 0; i < N; i++ ) - { - y[i] = Mpy_32_32( x1[i], x2[i] ); - move32(); - } - - return; -} -#endif void v_mult( const float x1[], /* i : Input vector 1 */ @@ -1839,19 +1731,22 @@ void v_sort_float( return; } +#ifdef IVAS_FLOAT_FIXED void sort( - uint16_t *x, /* i/o: Vector to be sorted */ - uint16_t len /* i/o: vector length */ + UWord16 *x, /* i/o: Vector to be sorted */ + UWord16 len /* i/o: vector length */ ) { - int16_t i; - uint16_t j, tempr; + Word16 i; + UWord16 j, tempr; - for ( i = len - 2; i >= 0; i-- ) + FOR( i = sub( len, 2 ); i >= 0; i-- ) { tempr = x[i]; - for ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + test(); + FOR( j = add( i, 1 ); ( j < len ) && ( tempr > x[j] ); j++ ) { + test(); x[j - 1] = x[j]; } x[j - 1] = tempr; @@ -1859,29 +1754,28 @@ void sort( return; } - -void sort_l( - Word32 *x, /* i/o: Vector to be sorted */ - Word16 len /* i/o: vector length */ +#else +void sort( + uint16_t *x, /* i/o: Vector to be sorted */ + uint16_t len /* i/o: vector length */ ) { - Word16 i, j; - Word32 tempr; + int16_t i; + uint16_t j, tempr; - FOR( i = len - 2; i >= 0; i-- ) + for ( i = len - 2; i >= 0; i-- ) { tempr = x[i]; - FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + for ( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { x[j - 1] = x[j]; - move32(); } x[j - 1] = tempr; - move32(); } return; } +#endif /*---------------------------------------------------------------------* * var() @@ -2262,44 +2156,6 @@ double anint( return ( x ) >= 0 ? (int32_t) ( ( x ) + 0.5 ) : (int32_t) ( (x) -0.5 ); } -/*-------------------------------------------------------------------* - * anint_fixed() - * - * Round to the nearest integer. - *-------------------------------------------------------------------*/ -Word32 anint_fixed( Word32 x, Word16 exp ) -{ - IF( EQ_32( x, 0 ) ) - { - return 0; - } - IF( GE_32( x, 0 ) ) - { - return L_add( x, L_shl( 1, exp - 1 ) ); - } - ELSE - { - return L_sub( x, L_shl( 1, exp - 1 ) ); - } -} - -/*-------------------------------------------------------------------* - * ceil_fixed() - * - * Ceil to the next multiple of (1 << exp). - *-------------------------------------------------------------------*/ -Word32 ceil_fixed( Word32 x, Word16 exp ) -{ - Word32 step; - // step = x / L_shl( 1, exp ); - step = L_shr( x, exp ); - if ( ( x % L_shl( 1, exp ) ) > 0 ) - { - step = L_add( step, 1 ); - } - return L_shl( step, exp ); -} - /*-------------------------------------------------------------------* * is_numeric_float() * diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 6d17d6a4a8ca84e77760ef2597f7d76d0d970221..19c5efcbb903118ed2141691d96cc7d8f80b2c38 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -45,8 +45,7 @@ #include "stl.h" #include #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "basop32.h" #include "wmc_auto.h" @@ -61,6 +60,8 @@ const Word16 b_hp400_fx[3] = { 3660, -7320, 3660 }; /* Q12 (/4) */ const Word16 a_hp400_fx[3] = { 16384, 29280, -14160 }; const Word16 a_hp400_ivas_fx[3] = { 4096, 7320, -3540 }; /*Q12*/ +#define WMC_TOOL_SKIP + // conversion functions: Word32 float_to_fix( float number, Word32 Q ) { @@ -239,6 +240,8 @@ void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ) *var_flt = (float) ldexp( mf, expo ); } +#undef WMC_TOOL_SKIP + int16_t norm_ul( uint32_t UL_var1 ) { int16_t var_out; @@ -573,6 +576,24 @@ void Copy32( } } } + +void set8_fx( + Word8 y[], /* i/o: Vector to set */ + const Word8 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ +) +{ + Word16 i; + + FOR( i = 0; i < N; i++ ) + { + y[i] = a; + move16(); + } + + return; +} + /*-------------------------------------------------------------------* * set16_fx() * set32_fx() @@ -2412,7 +2433,7 @@ void v_add_32( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = L_add( x1[i], x2[i] ); move32(); @@ -2430,7 +2451,7 @@ void v_shr_32( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = L_shr( x1[i], shift ); move32(); @@ -2480,7 +2501,7 @@ void v_add_16( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = add_sat( x1[i], x2[i] ); move16(); @@ -2505,7 +2526,7 @@ void v_sub_16( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = sub_sat( x1[i], x2[i] ); move16(); @@ -4076,3 +4097,276 @@ void v_mult16_fixed( return; } + +/*---------------------------------------------------------------------* + * set_zero() + * + * Set a vector vec[] of dimension lvec to zero + *---------------------------------------------------------------------*/ + +void set_zero_fx( + Word32 *vec, /* o : input vector */ + const Word16 lvec /* i : length of the vector */ +) +{ + Word16 i; + + FOR( i = 0; i < lvec; i++ ) + { + *vec++ = 0; + move32(); + } + + return; +} + +UWord32 mvl2s_r( + const Word32 x[], /* i : input vector */ + const Word16 q_x, + Word16 y[], /* o : output vector */ + const Word16 n /* i : vector size */ +) +{ + Word16 i; + Word32 temp; + UWord32 noClipping = 0; + move32(); + + IF( n <= 0 ) + { + /* cannot transfer vectors with size 0 */ + return 0; + } + + IF( (void *) y <= (const void *) x ) + { + FOR( i = 0; i < n; i++ ) + { + temp = L_shr( x[i], sub( q_x, 1 ) ); + temp = L_shr( L_add( temp, 1 ), 1 ); + + IF( GT_32( temp, MAX16B ) ) + { + temp = MAX16B; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); + } + ELSE IF( LT_32( temp, MIN16B ) ) + { + temp = MIN16B; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); + } + + y[i] = extract_l( temp ); + move16(); + } + } + ELSE + { + FOR( i = n - 1; i >= 0; i-- ) + { + temp = L_shr( x[i], sub( q_x, 1 ) ); + temp = L_shr( L_add( temp, 1 ), 1 ); + + IF( GT_32( temp, MAX16B ) ) + { + temp = MAX16B; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); + } + ELSE IF( LT_32( temp, MIN16B ) ) + { + temp = MIN16B; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); + } + + y[i] = extract_l( temp ); + move16(); + } + } + + return noClipping; +} + +#ifdef IVAS_FLOAT_FIXED +Word32 dotp_me_fx( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n, /* i : vector length */ + Word16 exp_x, + Word16 exp_y, + Word16 *exp_suma ) +{ + Word16 i; + Word32 suma; + Word32 mul; + Word16 mul_exp = add( exp_x, exp_y ); + suma = Mpy_32_32( x[0], y[0] ); + *exp_suma = mul_exp; + FOR( i = 1; i < n; i++ ) + { + mul = Mpy_32_32( x[i], y[i] ); + suma = BASOP_Util_Add_Mant32Exp( suma, *exp_suma, mul, mul_exp, exp_suma ); // exp_x+exp_A + } + + return suma; +} + +Word32 dotp_fixed_guarded( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n /* i : vector length */ +) +{ + Word16 i; + Word32 suma; + Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_32( x[0], y[0] ), guarded_bits ); + + FOR( i = 1; i < n; i++ ) + { + suma = L_add( suma, L_shr( Mpy_32_32( x[i], y[i] ), guarded_bits ) ); + } + + return suma; +} +#endif +/*-------------------------------------------------------------------* + * v_mult() + * + * Multiplication of two vectors + *-------------------------------------------------------------------*/ + + +void v_mult_fixed( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + + FOR( i = 0; i < N; i++ ) + { + y[i] = Mpy_32_32( x1[i], x2[i] ); + move32(); + } + + return; +} + +/*-------------------------------------------------------------------* + * anint_fixed() + * + * Round to the nearest integer. + *-------------------------------------------------------------------*/ +Word32 anint_fixed( Word32 x, Word16 exp ) +{ + IF( x == 0 ) + { + return 0; + } + IF( x >= 0 ) + { + return L_add( x, L_shl( 1, sub( exp, 1 ) ) ); + } + ELSE + { + return L_sub( x, L_shl( 1, sub( exp, 1 ) ) ); + } +} + +/*-------------------------------------------------------------------* + * ceil_fixed() + * + * Ceil to the next multiple of (1 << exp). + *-------------------------------------------------------------------*/ +Word32 ceil_fixed( Word32 x, Word16 exp ) +{ + Word32 step; + // step = x / L_shl( 1, exp ); + step = L_shr( x, exp ); + if ( ( x % L_shl( 1, exp ) ) > 0 ) + { + step = L_add( step, 1 ); + } + return L_shl( step, exp ); +} + +void sort_l( + Word32 *x, /* i/o: Vector to be sorted */ + Word16 len /* i/o: vector length */ +) +{ + Word16 i, j; + Word32 tempr; + + FOR( i = len - 2; i >= 0; i-- ) + { + tempr = x[i]; + FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) + { + x[j - 1] = x[j]; + move32(); + } + x[j - 1] = tempr; + move32(); + } + + return; +} + +/*-------------------------------------------------------------------* + * v_add_fixed() + * + * Subtraction of two vectors sample by sample + *-------------------------------------------------------------------*/ + +void v_add_fixed( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N, /* i : Vector length */ + const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ +) +{ + Word16 i; + + FOR( i = 0; i < N; i++ ) + { + y[i] = L_add( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) ); + move32(); + } + + return; +} + +void v_add_fixed_me( + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x1_e, /* i : Exponent for input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + const Word16 x2_e, /* i : Exponent for input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + Word16 *y_e, /* i : Exponent for output vector */ + const Word16 N, /* i : Vector length */ + const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ +) +{ + Word16 i; + Word16 x1_shift = sub( s_max( x1_e, x2_e ), x1_e ); + Word16 x2_shift = sub( s_max( x1_e, x2_e ), x2_e ); + + FOR( i = 0; i < N; i++ ) + { + y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); + move32(); + } + + *y_e = add( s_max( x1_e, x2_e ), hdrm ); + move16(); + + return; +} diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 32d94aa4941d06496d57bd69ac2f03e615bd2de9..82e2c981c7d80f4f60d45183e7a58ab5240b7fb2 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common FX constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common FX constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ /*------------------------------------------------------------------- * direct_transform() diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 70746dba9196e5e2f26a9f06a239f1c5d2856732..f79443862199a7cacad0a6d5ae65e7108b9cc579 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ #include "rom_dec.h" diff --git a/lib_com/vlpc_2st_com_fx.c b/lib_com/vlpc_2st_com_fx.c index f25e8bbf048244fbeae7fbbafd5af961fb882225..c54e5632f07a3861ef9b52211c3c6cd69ac719ce 100644 --- a/lib_com/vlpc_2st_com_fx.c +++ b/lib_com/vlpc_2st_com_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "control.h" #include "basop_util.h" diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c index 3177fea34bcfb3425f366cd7e192ad65592da3ef..99b621fa57c95f4d79abd591a675deeb03639141 100644 --- a/lib_com/weight_a_fx.c +++ b/lib_com/weight_a_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" /* Compilation switches */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include /*------------------------------------------------------------------ @@ -29,7 +28,7 @@ void weight_a_subfr_fx( orderp1 = add( order, 1 ); FOR( k = 0; k < nb_subfr; k++ ) { - weight_a_fx( &A[k * ( orderp1 )], &Aw[k * ( orderp1 )], gamma, order ); + weight_a_fx( &A[imult1616( k, ( orderp1 ) )], &Aw[imult1616( k, ( orderp1 ) )], gamma, order ); } return; @@ -78,8 +77,10 @@ void weight_a_lc_fx( FOR( i = 1; i < m; i++ ) { ap[i] = round_fx( L_shl( L_mult0( a[i], *ptr_gamma++ ), shift ) ); + move16(); } ap[m] = round_fx( L_shl( L_mult0( a[m], *ptr_gamma++ ), shift ) ); + move16(); return; } @@ -100,7 +101,9 @@ void weight_a_fx( Word32 Amax; Word16 shift; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow; + Overflow = 0; + move32(); #endif fac = gamma; @@ -124,9 +127,11 @@ void weight_a_fx( #else /* BASOP_NOGLOB */ ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); #endif + move16(); fac = mult_r( fac, gamma ); } ap[m] = round_fx( L_shl( L_mult0( a[m], fac ), shift ) ); + move16(); return; } @@ -157,13 +162,46 @@ void E_LPC_a_weight_inv( 17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */ static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878, /* Q14 */ 14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 }; /* Q13 */ + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + const Word16 *inv_gamma_tab; Word32 L_tmp; Word32 Amax; Word16 shift; - IF( inv_gamma == 16384 ) + IF( EQ_16( inv_gamma, 16384 ) ) { FOR( i = 0; i <= m; i++ ) { @@ -177,11 +215,9 @@ void E_LPC_a_weight_inv( assert( m == 16 ); inv_gamma_tab = inv_gamma_tab_12k8; - move16(); if ( EQ_16( inv_gamma, GAMMA16k_INV ) ) { inv_gamma_tab = inv_gamma_tab_16k; - move16(); } @@ -201,12 +237,14 @@ void E_LPC_a_weight_inv( { L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); ap[i] = round_fx( L_shl( L_tmp, shift ) ); + move16(); } shift = add( shift, 1 ); FOR( i = 9; i < 17; i++ ) { L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); ap[i] = round_fx( L_shl( L_tmp, shift ) ); + move16(); } diff --git a/lib_com/weight_fx.c b/lib_com/weight_fx.c index 5b5005fafd94af10259b225ef5e0ae8867a74612..6c123cbf2f14822ffe53631b3646ab11f26edea0 100644 --- a/lib_com/weight_fx.c +++ b/lib_com/weight_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*--------------------------------------------------------------------------* * sfm2mqb_fx() diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 602487f7199b893963bad38e35e33e98ca29348d..675ba31aabb71d87c9831e78022abe79f313617a 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "log2.h" @@ -160,8 +159,11 @@ void DTFS_sub_fx( move16(); } tmp->lag_fx = s_max( X1.lag_fx, X2.lag_fx ); + move16(); tmp->nH_fx = s_max( X1.nH_fx, X2.nH_fx ); + move16(); tmp->nH_4kHz_fx = s_max( X1.nH_4kHz_fx, X2.nH_4kHz_fx ); + move16(); tmp->upper_cut_off_freq_of_interest_fx = X1.upper_cut_off_freq_of_interest_fx; move16(); tmp->upper_cut_off_freq_fx = X1.upper_cut_off_freq_fx; @@ -180,7 +182,6 @@ static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_ Word16 dbuf_fx[256 + 1]; M_2 = s_min( shr( X_fx->lag_fx, 1 ), X_fx->nH_fx ); - move16(); N_2 = shr( N_fx, 1 ); s = negate( X_fx->Q ); @@ -193,7 +194,7 @@ static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_ { dbuf_fx[2 * i] = shl_r( X_fx->a_fx[i], s ); move16(); - dbuf_fx[2 * i + 1] = shl_r( X_fx->b_fx[i], s ); + dbuf_fx[add( 2 * i, 1 )] = shl_r( X_fx->b_fx[i], s ); move16(); } @@ -201,7 +202,7 @@ static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx, Word16 *out_fx, Word16 N_ { dbuf_fx[2 * i] = 0; move16(); - dbuf_fx[2 * i + 1] = 0; + dbuf_fx[add( 2 * i, 1 )] = 0; move16(); } @@ -265,6 +266,7 @@ static Word16 DTFS_alignment_weight_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif diff_fx = 0; /* to avoid compilation warnings */ @@ -278,6 +280,7 @@ static Word16 DTFS_alignment_weight_fx( FOR( k = 0; k < M + 1; k++ ) { tmplpc_fx[k] = mult_r( LPC1[k], pwf_fx[k] ); /* Q12 */ + move16(); } DTFS_zeroFilter_fx( &X1, tmplpc_fx, M + 1, S_fx, C_fx ); @@ -287,6 +290,7 @@ static Word16 DTFS_alignment_weight_fx( FOR( k = 0; k < M + 1; k++ ) { tmplpc_fx[k] = mult_r( LPC2[k], pwf_fx[k] ); /* Q12 */ + move16(); } DTFS_zeroFilter_fx( &X2, tmplpc_fx, M + 1, S_fx, C_fx ); @@ -295,7 +299,7 @@ static Word16 DTFS_alignment_weight_fx( move16(); fshift_fx = Eshift; move16(); - Adiff_fx = (Word16) s_max( 768, mult_r( 4915, shl( X2.lag_fx, 7 ) ) ); /* Q7, 768=6*128, 4915 = 0.15*32768 */ + Adiff_fx = s_max( 768, mult_r( 4915, shl( X2.lag_fx, 7 ) ) ); /* Q7, 768=6*128, 4915 = 0.15*32768 */ if ( LT_16( X2.lag_fx, 60 ) ) { @@ -311,7 +315,7 @@ static Word16 DTFS_alignment_weight_fx( HalfLag = s_min( shr( X2.lag_fx, 1 ), X2.nH_4kHz_fx ); exp = norm_s( X2.lag_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), X2.lag_fx ); - L_tmp = L_shl( tmp, exp + 6 ); + L_tmp = L_shl( tmp, add( exp, 6 ) ); inv_lag = round_fx( L_tmp ); FOR( k = 0; k <= HalfLag; k++ ) @@ -323,6 +327,8 @@ static Word16 DTFS_alignment_weight_fx( ab1[k] = round_fx( L_mac0( L_mult0( X1.a_fx[k], X2.a_fx[k] ), X1.b_fx[k], X2.b_fx[k] ) ); /* Q(-15) */ ab2[k] = round_fx( L_msu0( L_mult0( X1.a_fx[k], X2.b_fx[k] ), X1.b_fx[k], X2.a_fx[k] ) ); /* Q(-15) */ #endif + move16(); + move16(); } start = sub( Eshift, Adiff_fx ); @@ -345,11 +351,13 @@ static Word16 DTFS_alignment_weight_fx( { #ifdef BASOP_NOGLOB corr_fx = L_mac0_o( corr_fx, ab1[k], cos_table[s_and( temp, 511 )], &Overflow ); - corr_fx = L_mac0_o( corr_fx, ab2[k], cos_table[s_and( ( temp + 128 ), 511 )], &Overflow ); + corr_fx = L_mac0_o( corr_fx, ab2[k], cos_table[s_and( add( temp, 128 ), 511 )], &Overflow ); #else corr_fx = L_mac0( corr_fx, ab1[k], cos_table[s_and( temp, 511 )] ); - corr_fx = L_mac0( corr_fx, ab2[k], cos_table[s_and( ( temp + 128 ), 511 )] ); + corr_fx = L_mac0( corr_fx, ab2[k], cos_table[s_and( add( temp, 128 ), 511 )] ); #endif + move32(); + move32(); temp = add( temp, temp1 ); } temp = sub( 8192, mult_r( 20972, abs_s( sub( n_fx, Eshift ) ) ) ); /* Q13, 20972 = Q21 of 0.01. */ @@ -384,7 +392,7 @@ static Word16 DTFS_alignment_weight_fx( #endif } - if ( diff_corr > 0 ) + IF( diff_corr > 0 ) { fshift_fx = n_fx; move16(); @@ -434,6 +442,7 @@ Word16 DTFS_alignment_full_fx( Word16 Eshift, Adiff_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Calculating the expected alignment shift */ @@ -570,7 +579,9 @@ void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_ temp = X_fx->a_fx[k]; L_temp = L_shr( L_temp2, 5 ); /* Q2 */ X_fx->a_fx[k] = round_fx( L_msu( L_mult( temp, C_fx[L_temp % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[L_temp % ( 4 * Lag )] ) ); /* X.Q */ + move16(); X_fx->b_fx[k] = round_fx( L_mac( L_mult( X_fx->b_fx[k], C_fx[L_temp % ( 4 * Lag )] ), temp, S_fx[L_temp % ( 4 * Lag )] ) ); + move16(); L_temp2 = L_add( L_temp2, ph ); } } @@ -582,7 +593,9 @@ void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_ temp = X_fx->a_fx[k]; L_temp = L_shr( L_negate( L_temp2 ), 5 ); /* Q2 */ X_fx->a_fx[k] = round_fx( L_mac( L_mult( temp, C_fx[L_temp % ( 4 * Lag )] ), X_fx->b_fx[k], S_fx[L_temp % ( 4 * Lag )] ) ); /* X.Q */ + move16(); X_fx->b_fx[k] = round_fx( L_msu( L_mult( X_fx->b_fx[k], C_fx[L_temp % ( 4 * Lag )] ), temp, S_fx[L_temp % ( 4 * Lag )] ) ); + move16(); L_temp2 = L_add( L_temp2, ph ); } } @@ -623,6 +636,7 @@ void Q2phaseShift_fx( Word32 temp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif temp2 = L_deposit_l( 0 ); @@ -643,6 +657,8 @@ void Q2phaseShift_fx( X_fx->b_fx[k] = round_fx( L_mac( L_mult( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )] ), temp, S_fx[temp2 % ( 4 * Lag )] ) ); temp2 = L_add( temp2, (Word32) ph ); #endif + move16(); + move16(); } } @@ -661,6 +677,8 @@ void Q2phaseShift_fx( X_fx->b_fx[k] = round_fx( L_msu( L_mult( X_fx->b_fx[k], C_fx[temp2 % ( 4 * Lag )] ), temp, S_fx[temp2 % ( 4 * Lag )] ) ); temp2 = add( (Word16) temp2, negate( ph ) ); #endif + move16(); + move16(); } } } @@ -712,10 +730,12 @@ void DTFS_zeroPadd_fx( /* recompute nH for new lag */ diff_fx = find_rem( 12800, X_fx->lag_fx, &rem_fx ); X_fx->nH_fx = find_rem( X_fx->upper_cut_off_freq_fx, diff_fx, &rem_fx ); + move16(); if ( GE_16( sub( X_fx->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, X_fx->nH_fx ), 1 ) ), diff_fx ) ) { X_fx->nH_fx = add( X_fx->nH_fx, 1 ); + move16(); } } /*===================================================================*/ @@ -762,6 +782,7 @@ void DTFS_to_fs_fx( Word32 L_tmp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif IF( !FR_flag ) @@ -869,19 +890,23 @@ void DTFS_to_fs_fx( sum = add( sum, temp ); } La[k] = L_shr( L_a, 6 ); /* Q8 of a[k]*2.0 */ + move32(); Lb[k] = L_shr( L_b, 6 ); /* Q8 of b[k]*2.0 */ + move32(); L_temp = L_abs( La[k] ); if ( GT_32( L_temp, Labmax ) ) { Labmax = L_temp; + move32(); } L_temp = L_abs( Lb[k] ); if ( GT_32( L_temp, Labmax ) ) { Labmax = L_temp; + move32(); } } @@ -942,16 +967,20 @@ void DTFS_to_fs_fx( { #ifdef BASOP_NOGLOB X_fx->a_fx[k] = round_fx_o( L_shl_o( La[k], temp, &Overflow ), &Overflow ); /* Q(8+temp-16)=Q(temp-8) */ + move16(); X_fx->a_fx[k] = mult_ro( X_fx->a_fx[k], inv_lag, &Overflow ); move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ X_fx->b_fx[k] = round_fx_o( L_shl_o( Lb[k], temp, &Overflow ), &Overflow ); /* Q(8+temp-16)=Q(temp-8) */ + move16(); X_fx->b_fx[k] = mult_ro( X_fx->b_fx[k], inv_lag, &Overflow ); move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ #else X_fx->a_fx[k] = round_fx( L_shl( La[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ + move16(); X_fx->a_fx[k] = mult_r( X_fx->a_fx[k], inv_lag ); move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ X_fx->b_fx[k] = round_fx( L_shl( Lb[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ + move16(); X_fx->b_fx[k] = mult_r( X_fx->b_fx[k], inv_lag ); move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ #endif @@ -967,12 +996,14 @@ void DTFS_to_fs_fx( X_fx->a_fx[k] = round_fx( L_shl( La[k], temp ) ); /* Q(8+temp-16)=Q(temp-8) */ X_fx->a_fx[k] = mult_r( X_fx->a_fx[k], inv_lag ); #endif + move16(); move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*1.0/N */ X_fx->b_fx[k] = 0; move16(); } X_fx->Q = sub( temp, 4 ); + move16(); tmp = s_min( shr( X_fx->lag_fx, 1 ), sub( MAXLAG_WI, 1 ) ); FOR( k = add( nH_band, 1 ); k <= tmp; k++ ) @@ -1028,11 +1059,12 @@ static void DTFS_transform_fx( Word32 Lw_fx, temp32_fx; Word16 x2_256_fx[256], x1_256_fx[256]; Word16 k, m, l1; - Word32 x_r_fx[256] = { 0 }; + Word32 x_r_fx[256]; Word32 tmptmp3_40_fx; Word16 temp_w; Word16 N1; Word16 nrg_flag = 0; + move16(); Word32 L_tmp; Word16 tmp, tmp1, tmp2, frac, exp1, exp2; Word16 expa, expb, fraca, fracb, scale; @@ -1044,6 +1076,8 @@ static void DTFS_transform_fx( DTFS_STRUCTURE *tmp3_dtfs_fx; error = IVAS_ERR_OK; + move16(); + set32_fx( x_r_fx, 0, 256 ); IF( ( error = DTFS_new_fx( &tmp1_dtfs_fx ) ) != IVAS_ERR_OK ) { @@ -1062,7 +1096,7 @@ static void DTFS_transform_fx( DTFS_copy_fx( tmp2_dtfs_fx, X2_fx ); tmp2 = 0; /* to avoid compilation warnings */ - + move16(); DTFS_fast_fs_inv_fx( tmp1_dtfs_fx, x1_256_fx, 256, 8 ); DTFS_fast_fs_inv_fx( tmp2_dtfs_fx, x2_256_fx, 256, 8 ); @@ -1082,7 +1116,7 @@ static void DTFS_transform_fx( { tmp2 = negate( tmp1 ); } - tmp = div_s( shl( 1, ( 14 - exp2 ) ), tmp2 ); /* 29-exp2 */ + tmp = div_s( shl( 1, sub( 14, exp2 ) ), tmp2 ); /* 29-exp2 */ L_tmp = L_shl( tmp, 16 ); if ( tmp1 < 0 ) @@ -1169,11 +1203,12 @@ static void DTFS_transform_fx( w_fx = div_s( fracb, fraca ); exp1 = sub( expb, expa ); - w_fx = shl( w_fx, exp1 - 1 ); /*Q14*/ + w_fx = shl( w_fx, sub( exp1, 1 ) ); /*Q14*/ } ELSE { w_fx = 0; + move16(); } Lw_fx = L_deposit_h( w_fx ); @@ -1189,6 +1224,7 @@ static void DTFS_transform_fx( Lw_fx = L_add( Lw_fx, inv_fx ); /* (i+1)*inv */ /* mapping phase to 8x256 length signal */ temp32_fx = phase_fx[i]; /* Q(27-11)=Q16 due to multiplication by pow(2.0,11) */ + move32(); j = rint_new_fx( temp32_fx ); j = s_and( j, 0x07ff ); @@ -1201,15 +1237,16 @@ static void DTFS_transform_fx( FOR( j = 0; j < 12; j++ ) { - m = ( 1000 * LL + l1 - OSLENGTH / 2 + j ) % LL; /* use circular addressing */ + m = L_add( 1000 * LL - OSLENGTH / 2, add( l1, j ) ) % LL; /* use circular addressing */ x_r_fx[m] = L_mac( L_mult( x1_256_fx[m], temp_w ), x2_256_fx[m], w_fx ); + move32(); } tmptmp3_40_fx = L_deposit_l( 0 ); FOR( j = 0; j < 12; j++ ) { - m = ( 1000 * LL + l1 - OSLENGTH / 2 + j ) % LL; /* use circular addressing */ + m = L_add( 1000 * LL - OSLENGTH / 2, add( l1, j ) ) % LL; /* use circular addressing */ tmptmp3_40_fx = L_add( tmptmp3_40_fx, Mult_32_16( x_r_fx[m], sinc_fx[k][j] ) ); } #ifdef BASOP_NOGLOB @@ -1217,12 +1254,13 @@ static void DTFS_transform_fx( #else out_fx[i] = round_fx( L_shl( tmptmp3_40_fx, 2 ) ); #endif + move16(); } - count_free( tmp1_dtfs_fx ); - count_free( tmp2_dtfs_fx ); - count_free( tmp3_dtfs_fx ); + free( tmp1_dtfs_fx ); + free( tmp2_dtfs_fx ); + free( tmp3_dtfs_fx ); return; } /*===================================================================*/ @@ -1264,6 +1302,7 @@ void DTFS_zeroFilter_fx( Word16 Qmin, Qab[MAXLAG_WI], na, nb; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Qmin = 32767; move16(); @@ -1282,11 +1321,11 @@ void DTFS_zeroFilter_fx( FOR( n = 0; n < N; n++ ) { #ifdef BASOP_NOGLOB - sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ + sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[i_mult( 4, temp2 ) % i_mult( 4, X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); #else - sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ - sum2_fx = L_mac( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); + sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[i_mult( 4, temp2 ) % i_mult( 4, X_fx->lag_fx )] ); /* Q(12+15+1) */ + sum2_fx = L_mac( sum2_fx, LPC[n], S_fx[i_mult( 4, temp2 ) % i_mult( 4, X_fx->lag_fx )] ); #endif temp2 = add( temp2, temp ); } @@ -1336,8 +1375,11 @@ void DTFS_zeroFilter_fx( X_fx->a_fx[k] = round_fx( (Word32) L_shl( L_temp1, nb ) ); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ X_fx->b_fx[k] = round_fx( (Word32) L_shl( L_temp2, nb ) ); /* Q(Q+nb-3) */ #endif + move32(); + move32(); Qab[k] = sub( nb, 3 ); + move16(); if ( LT_16( Qab[k], Qmin ) ) { @@ -1455,9 +1497,12 @@ void DTFS_poleFilter_fx_9( } nb = sub( nb, 1 ); /* leave one more sign bit */ X_fx->a_fx[k] = round_fx( (Word32) L_shl( sum1_fx, nb ) ); /* Q(-3+n2+Q+exp+nb ) */ + move16(); X_fx->b_fx[k] = round_fx( (Word32) L_shl( sum2_fx, nb ) ); + move16(); Qab[k] = add( sub( nb, 3 ), n2_temp1 ); + move16(); if ( LT_16( Qab[k], Qmin ) ) { @@ -1466,7 +1511,7 @@ void DTFS_poleFilter_fx_9( } } /* bring to the same Q */ - move16(); + FOR( k = 0; k <= HalfLag; k++ ) { X_fx->a_fx[k] = shl( X_fx->a_fx[k], sub( Qmin, Qab[k] ) ); @@ -1476,6 +1521,7 @@ void DTFS_poleFilter_fx_9( } X_fx->Q = add( X_fx->Q, Qmin ); + move16(); return; } /*===================================================================*/ @@ -1539,20 +1585,21 @@ void DTFS_adjustLag_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), X_DTFS_FX->lag_fx ); /* 29 - exp */ L_tmp = L_mult0( 12800, tmp ); temp32_fx = L_shl( L_tmp, sub( exp, 23 ) ); - diff_fx = (Word16) L_shl( L_tmp, sub( exp, 29 ) ); + diff_fx = extract_l( L_shl( L_tmp, sub( exp, 29 ) ) ); exp = norm_s( diff_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), diff_fx ); /* 29 - exp */ L_tmp = L_mult0( X_DTFS_FX->upper_cut_off_freq_fx, tmp ); - X_DTFS_FX->nH_fx = (Word16) L_shl( L_tmp, sub( exp, 29 ) ); + X_DTFS_FX->nH_fx = extract_l( L_shl( L_tmp, sub( exp, 29 ) ) ); + move16(); L_tmp = L_mult0( 4000, tmp ); tempnH_fx = L_shl( L_tmp, sub( exp, 23 ) ); X_DTFS_FX->nH_4kHz_fx = extract_l( L_shl( L_tmp, sub( exp, 29 ) ) ); + move16(); - - if ( GE_16( sub( X_DTFS_FX->upper_cut_off_freq_fx, shr( (Word16) L_mult( diff_fx, X_DTFS_FX->nH_fx ), 1 ) ), diff_fx ) ) + if ( GE_16( sub( X_DTFS_FX->upper_cut_off_freq_fx, shr( extract_l( L_mult( diff_fx, X_DTFS_FX->nH_fx ) ), 1 ) ), diff_fx ) ) { X_DTFS_FX->nH_fx = add( X_DTFS_FX->nH_fx, 1 ); move16(); @@ -1595,9 +1642,11 @@ Word32 DTFS_getEngy_fx( { Word16 k, HalfLag_fx; Word32 en_fx = 0; + move32(); Word16 temp_a_fx, temp_b_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif HalfLag_fx = shr( sub( X_fx->lag_fx, 1 ), 1 ); HalfLag_fx = s_min( HalfLag_fx, X_fx->nH_fx ); @@ -1619,6 +1668,7 @@ Word32 DTFS_getEngy_fx( en_fx = L_shr( en_fx, 1 ); temp_a_fx = X_fx->a_fx[0]; + move16(); #ifdef BASOP_NOGLOB en_fx = L_mac0_o( en_fx, temp_a_fx, temp_a_fx, &Overflow ); #else @@ -1668,8 +1718,10 @@ Word32 DTFS_getEngy_P2A_fx( { Word16 k, HalfLag_fx; Word32 en_fx = 0; + move32(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif HalfLag_fx = shr( sub( X_fx->lag_fx, 1 ), 1 ); HalfLag_fx = s_min( HalfLag_fx, X_fx->nH_fx ); @@ -1740,7 +1792,7 @@ static Word32 DTFS_setEngy_fx( en1_fx = DTFS_getEngy_fx( X_DTFS_FX ); move16(); - if ( en1_fx == 0 ) + IF( en1_fx == 0 ) { return 0; } @@ -1748,6 +1800,7 @@ static Word32 DTFS_setEngy_fx( IF( en2_fx == 0 ) { factor_fx = 0; + move32(); } ELSE { @@ -1780,9 +1833,11 @@ static Word32 DTFS_setEngy_fx( { L_temp_fx = Mult_32_16( factor_fx, X_DTFS_FX->a_fx[k] ); /* Q(temp+X1.Q-15) */ X_DTFS_FX->a_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + move16(); L_temp_fx = Mult_32_16( factor_fx, X_DTFS_FX->b_fx[k] ); /* Q(temp+X1.Q-15) */ X_DTFS_FX->b_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ + move16(); } @@ -1830,6 +1885,7 @@ void DTFS_car2pol_fx( Word16 exp, tmp, frac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif HalfLag_fx = s_min( shr( sub( X_fx->lag_fx, 1 ), 1 ), X_fx->nH_fx ); FOR( k = 1; k <= HalfLag_fx; k++ ) @@ -1853,6 +1909,7 @@ void DTFS_car2pol_fx( Ltemp_fx = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ X_fx->a_fx[k] = extract_h( L_shl( Ltemp_fx, sub( add( X_fx->Q, exp ), 15 ) ) ); /* Q */ + move16(); } ELSE { @@ -1880,6 +1937,7 @@ void DTFS_car2pol_fx( Ltemp_fx = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ X_fx->a_fx[k] = extract_h( L_shl( Ltemp_fx, sub( add( X_fx->Q, exp ), 15 ) ) ); /* Q */ + move16(); } ELSE { @@ -1943,9 +2001,12 @@ Word32 DTFS_setEngyHarm_fx( Word16 exp, tmp, expa, expb, fraca, fracb, scale; Word32 L_tmp; Word32 Lacc_max = 0; + move32(); Word16 expp = 0; + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -2058,15 +2119,18 @@ Word32 DTFS_setEngyHarm_fx( #else X_fx->a_fx[k] = round_fx( L_temp_fx ); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ #endif + move16(); } if ( GE_32( Lacc_max, 2147483647 ) ) { *Qa_fx = sub( sub( X_fx->Q, add( 1, s_min( 2, expp ) ) ), exp ); + move16(); } else { *Qa_fx = sub( sub( X_fx->Q, 1 ), exp ); + move16(); } return en1_fx; /* Q(2*X1.Q) */ @@ -2120,20 +2184,23 @@ static void cubicPhase_fx( Word16 dbgshft; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif num_flag = 0; + move16(); den_flag = 0; + move16(); N = sub( N, L2 ); exp = norm_s( L1 ); tmp = div_s( shl( 1, sub( 14, exp ) ), L1 ); - L_tmp = L_shl( tmp, exp + 6 ); + L_tmp = L_shl( tmp, add( exp, 6 ) ); f1 = round_fx( L_tmp ); exp = norm_s( L2 ); tmp = div_s( shl( 1, sub( 14, exp ) ), L2 ); - L_tmp = L_shl( tmp, exp + 6 ); + L_tmp = L_shl( tmp, add( exp, 6 ) ); Ltemp4 = inverse_table[L2]; f2 = round_fx( L_tmp ); @@ -2173,7 +2240,7 @@ static void cubicPhase_fx( Ltemp2 = L_shl( Mult_32_16( Ltemp2, N ), 1 ); /* IF(N%2) */ - if ( s_and( N, 1 ) == 1 ) + if ( EQ_16( s_and( N, 1 ), 1 ) ) { Ltemp2 = L_add( Ltemp2, 1 ); } @@ -2326,7 +2393,7 @@ static void cubicPhase_fx( tmp = negate( tmp ); } - Lacc = L_shl( tmp, exp + 27 ); + Lacc = L_shl( tmp, add( exp, 27 ) ); Lacc = L_add( Lacc, 0x08000 ); c1 = extract_h( Lacc ); /* c1 in Q27 */ @@ -2384,7 +2451,7 @@ static void cubicPhase_fx( N2 = L_shl( L_mult0( n, n ), 14 ); Ltemp3 = L_shl( Mult_32_16( N2, n ), 1 ); - if ( s_and( N, 1 ) == 1 ) + if ( EQ_16( s_and( N, 1 ), 1 ) ) { Ltemp3 = L_add( Ltemp3, 1 ); } @@ -2453,6 +2520,7 @@ void DTFS_to_erb_fx( Word16 expa, expb, fraca, fracb, scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif const Word16 *erb_fx = NULL; num_erb_fx = NUM_ERB_NB; @@ -2556,6 +2624,7 @@ void DTFS_to_erb_fx( out_fx[i] = round_fx( L_tmp ); #endif + move16(); } } return; @@ -2599,6 +2668,7 @@ void erb_slot_fx( Word16 fraca, fracb, expa, expb, scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif const Word16 *erb_fx = NULL; /*move16(); */ @@ -2610,14 +2680,12 @@ void erb_slot_fx( upper_cut_off_freq_fx = 4000; move16(); erb_fx = &( erb_NB_fx[0] ); - move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { upper_cut_off_freq_fx = 6400; move16(); erb_fx = &( erb_WB_fx[0] ); - move16(); } exp = norm_s( lag_fx ); @@ -2688,6 +2756,7 @@ void erb_slot_fx( #else mfreq_fx[j] = round_fx( L_shl( mf_fx[j], 11 ) ); /* Q15 */ #endif + move16(); IF( GT_16( out_fx[j], 1 ) ) { expb = norm_l( mf_fx[j] ); @@ -2771,6 +2840,7 @@ void DTFS_erb_inv_fx( Word16 exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) @@ -2809,7 +2879,7 @@ void DTFS_erb_inv_fx( exp = norm_s( X_fx->lag_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), X_fx->lag_fx ); /* 29-exp */ - diff_fx = shl( tmp, exp - 10 ); /* Q19 */ + diff_fx = shl( tmp, sub( exp, 10 ) ); /* Q19 */ min_q = EVS_SW_MAX; move16(); @@ -2861,7 +2931,9 @@ void DTFS_erb_inv_fx( #else X_fx->a_fx[i] = round_fx( L_shl( Ltemp_fx, d2h ) ); /* Q(28-n+d2h) */ #endif + move16(); q[i] = add( sub( 28, n ), d2h ); + move16(); min_q = s_min( min_q, q[i] ); BREAK; @@ -2876,6 +2948,7 @@ void DTFS_erb_inv_fx( } X_fx->Q = min_q; + move16(); return; } @@ -2987,8 +3060,10 @@ void erb_add_fx( move16(); } ELSE + { curr_erb_fx[i] = 0; - move16(); + move16(); + } } tmp_fx = add( shl( index_fx[1], 3 ), index_fx[1] ); /* tmp=9*index[1] */ @@ -3002,19 +3077,23 @@ void erb_add_fx( IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { curr_erb_fx[i] = add( AmpCB2_NB_fx[sub( add( tmp_fx, i ), 11 )], t_prev_erb_fx[i] ); /* Q13+Q13=Q13 */ + move16(); curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { curr_erb_fx[i] = add( AmpCB2_WB_fx[sub( add( tmp2_fx, i ), 11 )], t_prev_erb_fx[i] ); /* Q13 */ + move16(); curr_erb_fx[i] = s_max( 0, curr_erb_fx[i] ); move16(); } } ELSE + { curr_erb_fx[i] = 0; - move16(); + move16(); + } } return; } @@ -3075,17 +3154,24 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W tmp = round_fx( L_shl( Lacc, exp ) ); exp = sub( sub( 30, exp ), 23 ); IF( tmp ) - tmp = div_s( 16384, tmp ); /* 15+exp1 */ + { + tmp = div_s( 16384, tmp ); /* 15+exp1 */ + } ELSE + { tmp = 0; + move16(); + } Ltemp = L_deposit_h( tmp ); tmp = round_fx( Ltemp ); /* tmp in Q(22-n) */ Ltemp1 = Mult_32_16( Ltemp1, tmp ); /* Q(30-n) */ n = sub( 8, exp ); w[0] = round_fx( L_shl( Ltemp1, n ) ); /* w[0] in Q15 */ + move16(); Ltemp2 = Mult_32_16( Ltemp2, tmp ); w[1] = round_fx( L_shl( Ltemp2, n ) ); /* w[1] in Q15 */ + move16(); logLag = log10_fx( X_fx->lag_fx ); /* logLag=10*log10(lag), Q23 */ Ltemp3 = L_shl( L_mult( shl( X_fx->Q, 1 ), 24660 ), 9 ); /* Ltemp3=2Q*10log10(2), Q23 */ @@ -3096,20 +3182,28 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W Ltemp = L_add( L_sub( Ltemp, Ltemp3 ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ target[0] = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ + move16(); /* Process high band */ Ltemp = DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh, X_fx ); Ltemp = log10_fx( Ltemp ); Ltemp = L_add( L_sub( Ltemp, Ltemp3 ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ target[1] = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ + move16(); /* Need to unify the Q factors of both bands */ X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ - n = sub( Ql, Qh ); /* compare band Q factors */ + move16(); + n = sub( Ql, Qh ); /* compare band Q factors */ IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); - ELSE IF( n > 0 ) rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + { + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + } + ELSE IF( n > 0 ) + { + rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + } } /*==========================================================================*/ @@ -3152,6 +3246,8 @@ ivas_error WIsyn_fx( { Word16 i; UWord16 I = 1, flag = 0; + move16(); + move16(); /* Word16 *phase_fx = (Word16*)malloc(sizeof(Word16) * (2*N)); new operator used size 2*N */ Word32 phase_fx[WI_FX_phase_fx]; Word16 alignment_fx; @@ -3166,6 +3262,7 @@ ivas_error WIsyn_fx( ivas_error error; error = IVAS_ERR_OK; + move16(); IF( ( error = DTFS_new_fx( &CURRCW_DTFS_FX ) ) != IVAS_ERR_OK ) { @@ -3217,7 +3314,9 @@ ivas_error WIsyn_fx( IF( temp < 0 ) - temp = add( temp, shl( CURRCW_DTFS_FX->lag_fx, 7 ) ); /* Q7 */ + { + temp = add( temp, shl( CURRCW_DTFS_FX->lag_fx, 7 ) ); /* Q7 */ + } find_rem( temp, shl( CURRCW_DTFS_FX->lag_fx, 7 ), &tmp_fx ); /* Q7 */ IF( FR_flag == 0 ) @@ -3241,7 +3340,7 @@ ivas_error WIsyn_fx( tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); exp = norm_s( tmp ); tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ - L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + L_tmp = L_shl( L_mult( temp, tmp ), add( exp, 1 ) ); tmp_fx = round_fx( L_tmp ); } ELSE IF( alignment_fx < 0 ) @@ -3250,7 +3349,7 @@ ivas_error WIsyn_fx( tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); exp = norm_s( tmp ); tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ - L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + L_tmp = L_shl( L_mult( temp, tmp ), add( exp, 1 ) ); tmp_fx = negate( round_fx( L_tmp ) ); } ELSE @@ -3260,7 +3359,7 @@ ivas_error WIsyn_fx( tmp = shl( CURRCW_DTFS_FX->lag_fx, 7 ); exp = norm_s( tmp ); tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* 22-exp */ - L_tmp = L_shl( L_mult( temp, tmp ), exp + 1 ); + L_tmp = L_shl( L_mult( temp, tmp ), add( exp, 1 ) ); tmp_fx = round_fx( L_tmp ); } @@ -3301,9 +3400,10 @@ ivas_error WIsyn_fx( { /* empty loop */ } - L_temp = L_temp & 0x7fff; + L_temp = L_and( L_temp, 0x7fff ); move16(); /* fraction part */ *ph_offset_fx = extract_l( L_temp ); + move16(); /* free(phase_fx) ; */ free( CURRCW_DTFS_FX ); @@ -3342,12 +3442,18 @@ Word16 ppp_extract_pitch_period_fx( { Word16 i, j, k; Word16 spike = 0, range; + move16(); Word16 max = 0; + move16(); const Word16 *ptr = in + L_FRAME - l; Word32 en1 = 0, Lacc, L_tmp; + move32(); Word16 spike_near_edge = 0, scale; + move16(); Word16 pos_max, neg_max; Word16 spike_pos = 0, spike_neg = 0; + move16(); + move16(); Word16 x, tmp, expa, fraca, expb, fracb, scale1, exp; pos_max = -0x8000L; @@ -3362,7 +3468,7 @@ Word16 ppp_extract_pitch_period_fx( { x = abs_s( ptr[i] ); - if ( GT_16( x, max ) ) + IF( GT_16( x, max ) ) { max = x; move16(); @@ -3383,9 +3489,10 @@ Word16 ppp_extract_pitch_period_fx( /* search for neg spike around the pos spike */ FOR( j = spike - 10; j < spike + 10; j++ ) { - k = ( j + l ) % l; + k = add( j, l ) % l; + move16(); - if ( LT_16( ptr[k], neg_max ) ) + IF( LT_16( ptr[k], neg_max ) ) { neg_max = ptr[k]; move16(); @@ -3401,9 +3508,10 @@ Word16 ppp_extract_pitch_period_fx( /* search for pos spike around the neg spike */ FOR( j = spike - 10; j < spike + 10; j++ ) { - k = ( j + l ) % l; + k = add( j, l ) % l; + move16(); - if ( GT_16( ptr[k], pos_max ) ) + IF( GT_16( ptr[k], pos_max ) ) { pos_max = ptr[k]; move16(); @@ -3414,7 +3522,7 @@ Word16 ppp_extract_pitch_period_fx( } test(); - IF( ( LE_16( ( l - 1 - s_max( spike_pos, spike_neg ) ), 2 ) ) || ( LE_16( s_min( spike_pos, spike_neg ), 2 ) ) ) + IF( ( LE_16( sub( sub( l, 1 ), s_max( spike_pos, spike_neg ) ), 2 ) ) || ( LE_16( s_min( spike_pos, spike_neg ), 2 ) ) ) { *out_of_bound = 1; move16(); @@ -3425,10 +3533,14 @@ Word16 ppp_extract_pitch_period_fx( tmp = (Word16) ( L_max( L_mult( CUTFREE_REL_RANGE_Q2, l ), CUTFREE_ABS_RANGE_Q3 ) ); /* Q3 */ IF( tmp > 0 ) - tmp = add( tmp, 4 ); /* Q3 */ + { + tmp = add( tmp, 4 ); /* Q3 */ + } ELSE + { tmp = sub( tmp, 4 ); /* Q3 */ - range = shr( tmp, 3 ); /* Q0 */ + } + range = shr( tmp, 3 ); /* Q0 */ test(); IF( ( LT_16( spike, range ) ) || ( GE_16( add( spike, range ), l ) ) ) @@ -3566,6 +3678,8 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W { Word32 L_sum; Word32 maxPosEn_fx = 0, maxNegEn_fx = 0, L_temp; + move32(); + move32(); Word16 i; Word16 time_fx[256]; Word16 expa, expb, fraca, fracb, scale; @@ -3573,6 +3687,7 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_sum = DTFS_getEngy_P2A_fx( &X_fx ); /* 2Q */ DTFS_fast_fs_inv_fx( &X_fx, time_fx, 256, 8 ); @@ -3589,6 +3704,7 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W if ( GT_32( L_temp, maxPosEn_fx ) ) { maxPosEn_fx = L_temp; /* Q(1) */ + move32(); } } ELSE @@ -3596,6 +3712,7 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W if ( GT_32( L_temp, maxNegEn_fx ) ) { maxNegEn_fx = L_temp; /* Q(1) */ + move32(); } } } @@ -3604,15 +3721,17 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W IF( L_sum == 0 ) { *pos_fx = *neg_fx = 0; - move16(); - move16(); + move32(); + move32(); } ELSE { IF( maxPosEn_fx == 0 ) { *pos_fx = 0; + move32(); *Qpos = 31; + move16(); } ELSE { @@ -3647,13 +3766,17 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ *pos_fx = L_tmp; + move32(); *Qpos = sub( 31, exp ); + move16(); } IF( maxNegEn_fx == 0 ) { *neg_fx = 0; + move32(); *Qneg = 31; + move16(); } ELSE { @@ -3664,7 +3787,7 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W #else fraca = extract_h( L_shl( maxNegEn_fx, expa ) ); #endif - expa = 30 - expa - 1; + expa = sub( Q29, expa ); // 30 - expa - 1; expb = norm_l( L_sum ); @@ -3673,7 +3796,7 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W #else fracb = round_fx( L_shl( L_sum, expb ) ); #endif - expb = 30 - expb - ( 2 * X_fx.Q ); + expb = sub( 30, add( expb, shl( X_fx.Q, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); @@ -3689,7 +3812,9 @@ void DTFS_peaktoaverage_fx( DTFS_STRUCTURE X_fx, Word32 *pos_fx, Word16 *Qpos, W L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ *neg_fx = L_tmp; - *Qneg = 31 - exp; + move32(); + *Qneg = sub( Q31, exp ); + move16(); } } } @@ -3777,19 +3902,19 @@ void GetSinCosTab_fx( Word16 L, Word16 *sinTab, Word16 *cosTab ) w = extract_h( Lw ); /* w in Q9 */ dl = extract_l( Lw ); /* dl has 16 bits left-over */ w = s_and( w, 511 ); - move16(); - move16(); /* t1=cos_table[w%512]; */ t1 = cos_table[w]; + move16(); /* t2=cos_table[add(w,1)%512]; */ dt = cos_diff_table[w]; + move16(); /*t2=cos_table[s_and(add(w,1),511)]; */ /*dt = sub(t2,t1); */ /* Q15 */ IF( dl < 0 ) { L_tmp = L_add( 65536, dl ); - Ltemp = ( L_tmp * dt ); + Ltemp = imult3216( L_tmp, dt ); } ELSE { @@ -3809,13 +3934,14 @@ void GetSinCosTab_fx( Word16 L, Word16 *sinTab, Word16 *cosTab ) move16(); /* t2=cos_table[add(w,1)%512]; */ dt = cos_diff_table[w]; + move16(); /*t2=cos_table[s_and(add(w,1),511)];move16(); */ /*dt = sub(t2,t1); */ /* dt=t2-t1, Q15 */ IF( dl < 0 ) { L_tmp = L_add( 65536, dl ); - Ltemp = ( L_tmp * dt ); + Ltemp = imult3216( L_tmp, dt ); } ELSE { @@ -3844,11 +3970,8 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 Word16 n_2, K; Word16 ii_table[8]; - - move16(); - move16(); - K = 0; + move16(); FOR( k = 256; k > 0; k -= size ) { @@ -3856,45 +3979,47 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 } n_2 = shr( size, 1 ); FOR( i = 1; i <= stage; i++ ) - ii_table[i - 1] = shr( size, i ); + { + ii_table[i - 1] = shr( size, i ); + } /* Rearrange the input array in bit reversed order */ j = 0; move16(); FOR( i = 0; i < size - 2; i = i + 2 ) { - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); IF( GT_16( j, i ) ) { ftmp_fx = *( farray_ptr_fx + i ); *( farray_ptr_fx + i ) = *( farray_ptr_fx + j ); *( farray_ptr_fx + j ) = (Word16) ftmp_fx; + move32(); + move16(); + move16(); - ftmp_fx = *( farray_ptr_fx + i + 1 ); - *( farray_ptr_fx + i + 1 ) = *( farray_ptr_fx + j + 1 ); - *( farray_ptr_fx + j + 1 ) = (Word16) ftmp_fx; + ftmp_fx = *( farray_ptr_fx + add( i, 1 ) ); + *( farray_ptr_fx + add( i, 1 ) ) = *( farray_ptr_fx + add( j, 1 ) ); + *( farray_ptr_fx + add( j, 1 ) ) = (Word16) ftmp_fx; + move32(); + move16(); + move16(); } k = n_2; move16(); - WHILE( j >= k ) + WHILE( GE_16( j, k ) ) { j = sub( j, k ); k = shr( k, 1 ); } - j += k; + j = add( j, k ); } /* The FFT part */ - IF( isign == 1 ) + IF( EQ_16( isign, 1 ) ) { FOR( i = 0; i < stage; i++ ) /* i is stage counter */ { @@ -3907,21 +4032,21 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 FOR( j = 0; j < jj; j = j + 2 ) /* j is sample counter */ { - ji = j * ii; /* ji is phase table index */ + ji = i_mult( j, ii ); /* ji is phase table index */ FOR( k = j; k < size; k = k + kk ) /* k is butterfly top */ { kj = add( k, jj ); /* kj is butterfly bottom */ - temp_sand = s_and( ( ji * K + 384 ), 511 ); + temp_sand = s_and( ( add( i_mult( ji, K ), 384 ) ), 511 ); /* Butterfly computations */ /* ftmp_real_fx = L_sub(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_msu( L_mult( *( farray_ptr_fx + kj ), cos_table[ji * K] ), - *( farray_ptr_fx + kj + 1 ), cos_table[temp_sand] ); + ftmp_real_fx = L_msu( L_mult( *( farray_ptr_fx + kj ), cos_table[i_mult( ji, K )] ), + *( farray_ptr_fx + add( kj, 1 ) ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_add(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_mac( L_mult( *( farray_ptr_fx + kj + 1 ), cos_table[ji * K] ), + ftmp_imag_fx = L_mac( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[i_mult( ji, K )] ), *( farray_ptr_fx + kj ), cos_table[temp_sand] ); tmp1 = round_fx( ftmp_real_fx ); @@ -3931,16 +4056,16 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 *( farray_ptr_fx + kj ) = shr( tmp, 1 ); move16(); - tmp = sub( *( farray_ptr_fx + k + 1 ), tmp2 ); - *( farray_ptr_fx + kj + 1 ) = shr( tmp, 1 ); + tmp = sub( *( farray_ptr_fx + add( k, 1 ) ), tmp2 ); + *( farray_ptr_fx + add( kj, 1 ) ) = shr( tmp, 1 ); move16(); tmp = add( *( farray_ptr_fx + k ), tmp1 ); *( farray_ptr_fx + k ) = shr( tmp, 1 ); move16(); - tmp = add( *( farray_ptr_fx + k + 1 ), tmp2 ); - *( farray_ptr_fx + k + 1 ) = shr( tmp, 1 ); + tmp = add( *( farray_ptr_fx + add( k, 1 ) ), tmp2 ); + *( farray_ptr_fx + add( k, 1 ) ) = shr( tmp, 1 ); move16(); } } @@ -3958,21 +4083,21 @@ static void c_fft_wi_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word1 FOR( j = 0; j < jj; j = j + 2 ) /* j is sample counter */ { - ji = j * ii; /* ji is phase table index */ + ji = i_mult( j, ii ); /* ji is phase table index */ FOR( k = j; k < size; k = k + kk ) /* k is butterfly top */ { kj = add( k, jj ); /* kj is butterfly bottom */ - temp_sand = s_and( ( ji * K + 384 ), 511 ); + temp_sand = s_and( ( add( i_mult( ji, K ), 384 ) ), 511 ); /* Butterfly computations */ /* ftmp_real_fx = L_add(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_mac( L_mult( *( farray_ptr_fx + kj ), cos_table[ji * K] ), + ftmp_real_fx = L_mac( L_mult( *( farray_ptr_fx + kj ), cos_table[i_mult( ji, K )] ), *( farray_ptr_fx + kj + 1 ), cos_table[temp_sand] ); /* ftmp_imag_fx = L_sub(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_msu( L_mult( *( farray_ptr_fx + kj + 1 ), cos_table[ji * K] ), + ftmp_imag_fx = L_msu( L_mult( *( farray_ptr_fx + add( kj, 1 ) ), cos_table[i_mult( ji, K )] ), *( farray_ptr_fx + kj ), cos_table[temp_sand] ); tmp1 = round_fx( ftmp_real_fx ); @@ -4024,7 +4149,7 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign } /* The FFT part */ - IF( isign == 1 ) + IF( EQ_16( isign, 1 ) ) { /* Perform the complex FFT */ c_fft_wi_fx( farray_ptr_fx, size, stage, isign ); @@ -4033,10 +4158,12 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign ftmp1_real_fx = *farray_ptr_fx; ftmp2_real_fx = *( farray_ptr_fx + 1 ); *farray_ptr_fx = add( ftmp1_real_fx, ftmp2_real_fx ); + move16(); *( farray_ptr_fx + 1 ) = sub( ftmp1_real_fx, ftmp2_real_fx ); + move16(); /* Now, handle the remaining positive frequencies */ - j = size - 2; + j = sub( size, 2 ); FOR( i = 2; i <= n_2; i = i + 2 ) { ftmp1_real_fx = add( *( farray_ptr_fx + i ), *( farray_ptr_fx + j ) ); @@ -4046,24 +4173,28 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign Lftmp1_real_fx = L_deposit_h( ftmp1_real_fx ); Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); - temp_sand = s_and( ( i * K + 384 ), 511 ); + temp_sand = s_and( add( i_mult( i, K ), 384 ), 511 ); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i_mult( i, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_add(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_imag_fx, cos_table[i * K] ), ftmp2_real_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_imag_fx, cos_table[i_mult( i, K )] ), ftmp2_real_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[j * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i_mult( j, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_add(L_negate(L_mult(ftmp2_imag_fx, cos_table[j*K])), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[temp_sand] ), ftmp2_imag_fx, cos_table[j * K] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[temp_sand] ), ftmp2_imag_fx, cos_table[i_mult( j, K )] ); Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); - j = size - i; + move16(); + j = sub( size, i ); } } ELSE @@ -4093,23 +4224,27 @@ void r_fft_4_fx( Word16 *farray_ptr_fx, Word16 size, Word16 stage, Word16 isign Lftmp1_real_fx = L_deposit_h( ftmp1_real_fx ); Lftmp1_imag_fx = L_deposit_h( ftmp1_imag_fx ); - temp_sand = s_and( ( i * K + 384 ), 511 ); + temp_sand = s_and( ( add( i_mult( i, K ), 384 ) ), 511 ); /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_mac( L_mult( ftmp2_real_fx, cos_table[i_mult( i, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_sub(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_imag_fx, cos_table[i * K] ), ftmp2_real_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_imag_fx, cos_table[i_mult( i, K )] ), ftmp2_real_fx, cos_table[temp_sand] ); *( farray_ptr_fx + i + 1 ) = round_fx( L_shr( L_add( Lftmp1_imag_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[j * K] ), ftmp2_imag_fx, cos_table[temp_sand] ); + Ltmp1_fx = L_msu( L_mult( ftmp2_real_fx, cos_table[i_mult( j, K )] ), ftmp2_imag_fx, cos_table[temp_sand] ); *( farray_ptr_fx + j ) = round_fx( L_shr( L_add( Lftmp1_real_fx, Ltmp1_fx ), 1 ) ); + move16(); /* Ltmp1_fx = L_negate(L_add(L_mult(ftmp2_imag_fx, cos_table[j*K]), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512]))); */ - Ltmp1_fx = L_negate( L_mac( L_mult( ftmp2_imag_fx, cos_table[j * K] ), ftmp2_real_fx, cos_table[temp_sand] ) ); + Ltmp1_fx = L_negate( L_mac( L_mult( ftmp2_imag_fx, cos_table[i_mult( j, K )] ), ftmp2_real_fx, cos_table[temp_sand] ) ); Ltmp2_fx = L_sub( Ltmp1_fx, Lftmp1_imag_fx ); *( farray_ptr_fx + j + 1 ) = round_fx( L_shr( Ltmp2_fx, 1 ) ); + move16(); } /* Perform the complex IFFT */ @@ -4162,13 +4297,15 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE Word16 exp, tmp, exp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - move16(); retX_fx->lag_fx = X1_fx->lag_fx; + move16(); retX_fx->Q = sub( X2_fx.Q, 1 ); /* equivalent to 2x MIN_FX(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx) */ - HalfLag = s_min( shr( X1_fx->lag_fx, 1 ), X1_fx->nH_fx ); move16(); + HalfLag = s_min( shr( X1_fx->lag_fx, 1 ), X1_fx->nH_fx ); + FOR( k = 1; k <= HalfLag; k++ ) { #ifdef BASOP_NOGLOB @@ -4184,11 +4321,15 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE exp1 = sub( sub( 30, exp ), 2 * X1_fx->Q + 1 ); IF( tmp ) - tmp = div_s( 16384, tmp ); /* 15+exp1 */ + { + tmp = div_s( 16384, tmp ); /* 15+exp1 */ + } ELSE + { tmp = 0; + } tmp = shr( tmp, 1 ); - q = 15 + exp1 + 16 - 1; + q = sub( add( add( 15, exp1 ), 16 ), 1 ); IF( tmp ) { @@ -4199,10 +4340,15 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE Ltemp_fx = Isqrt_lc( L_tmp, &exp ); /* Q(31-exp) */ } ELSE + { Ltemp_fx = 0; + move32(); + } - if ( s_and( q, 1 ) ) + IF( s_and( q, 1 ) ) + { Ltemp_fx = Mult_32_16( Ltemp_fx, 23170 ); /* 23170 is 1/sqrt(2) in Q15 */ + } q = shr( q, 1 ); /* Ltemp_fx in Q(q+16) */ @@ -4213,21 +4359,25 @@ void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE Ltemp_fx = L_add_o( L_shr( Ltemp_fx, 15 ), L_mult_o( X1_fx->b_fx[k], d1h, &Overflow ), &Overflow ); /* sin(w) in Q(q+16+Q-15) */ sn = round_fx_o( L_shl_o( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ), &Overflow ), &Overflow ); /* Q15 */ retX_fx->b_fx[k] = mult_ro( X2_fx.a_fx[k], sn, &Overflow ); /* X2_fx.Q */ + move16(); Ltemp_fx = L_mult0( X1_fx->a_fx[k], d1l ); Ltemp_fx = L_add_o( L_shr( Ltemp_fx, 15 ), L_mult_o( X1_fx->a_fx[k], d1h, &Overflow ), &Overflow ); /* cos(w) in Q(q+Q+1) */ cn = round_fx_o( L_shl_o( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ), &Overflow ), &Overflow ); /* Q15 */ retX_fx->a_fx[k] = mult_ro( X2_fx.a_fx[k], cn, &Overflow ); /* X2_fx.Q */ + move16(); #else Ltemp_fx = L_mult0( X1_fx->b_fx[k], d1l ); Ltemp_fx = L_add( L_shr( Ltemp_fx, 15 ), L_mult( X1_fx->b_fx[k], d1h ) ); /* sin(w) in Q(q+16+Q-15) */ sn = round_fx( L_shl( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ) ) ); /* Q15 */ retX_fx->b_fx[k] = mult_r( X2_fx.a_fx[k], sn ); /* X2_fx.Q */ + move16(); Ltemp_fx = L_mult0( X1_fx->a_fx[k], d1l ); Ltemp_fx = L_add( L_shr( Ltemp_fx, 15 ), L_mult( X1_fx->a_fx[k], d1h ) ); /* cos(w) in Q(q+Q+1) */ cn = round_fx( L_shl( Ltemp_fx, sub( 30, add( q, X1_fx->Q ) ) ) ); /* Q15 */ retX_fx->a_fx[k] = mult_r( X2_fx.a_fx[k], cn ); /* X2_fx.Q */ + move16(); #endif } k = sub( k, 1 ); @@ -4283,6 +4433,7 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif en = L_deposit_l( 0 ); @@ -4321,7 +4472,7 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, #ifdef BASOP_NOGLOB Lacc = L_mac_o( Lacc, curr_lpc[i], cos_tab[n % M_fx], &Overflow ); /* Q28 */ #else - Lacc = L_mac( Lacc, curr_lpc[i], cos_tab[n % M_fx] ); /* Q28 */ + Lacc = L_mac( Lacc, curr_lpc[i], cos_tab[n % M_fx] ); /* Q28 */ #endif n = add( n, k4 ); /* n=4*i*k */ } @@ -4336,7 +4487,7 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, #ifdef BASOP_NOGLOB Lacc = L_msu_o( Lacc, curr_lpc[i], sin_tab[n % M_fx], &Overflow ); /* Q28 */ #else - Lacc = L_msu( Lacc, curr_lpc[i], sin_tab[n % M_fx] ); /* Q28 */ + Lacc = L_msu( Lacc, curr_lpc[i], sin_tab[n % M_fx] ); /* Q28 */ #endif n = add( n, k4 ); /* n=4*i*k */ } @@ -4345,7 +4496,7 @@ Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband, #ifdef BASOP_NOGLOB Lacc = L_add_o( Mult_32_32( Re, Re ), Mult_32_32( Im, Im ), &Overflow ); /* Lacc=Re^2+Im^2 in Q23 */ #else - Lacc = L_add( Mult_32_32( Re, Re ), Mult_32_32( Im, Im ) ); /* Lacc=Re^2+Im^2 in Q23 */ + Lacc = L_add( Mult_32_32( Re, Re ), Mult_32_32( Im, Im ) ); /* Lacc=Re^2+Im^2 in Q23 */ #endif Ltemp = L_mult0( X_fx->a_fx[k], X_fx->a_fx[k] ); /* 2*a[k]^2 in 2Q */ /* Ltemp=(Word32)L_sat32_40(divide_dp(Ltemp,Lacc,-19,1)); : Ltemp in Q(2Q-13) */ @@ -4428,6 +4579,7 @@ void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_ Word16 exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Qmin = 32767; move16(); @@ -4443,8 +4595,8 @@ void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_ FOR( n = 0; n < N; n++ ) { #ifdef BASOP_NOGLOB - sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ - sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )], &Overflow ); /* Q(12+15+1) */ + sum1_fx = L_mac_o( sum1_fx, LPC[n], C_fx[shl( temp2, 2 ) % shl( X_fx->lag_fx, 2 )], &Overflow ); /* Q(12+15+1) */ + sum2_fx = L_mac_o( sum2_fx, LPC[n], S_fx[shl( temp2, 2 ) % shl( X_fx->lag_fx, 2 )], &Overflow ); /* Q(12+15+1) */ #else sum1_fx = L_mac( sum1_fx, LPC[n], C_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ sum2_fx = L_mac( sum2_fx, LPC[n], S_fx[( 4 * temp2 ) % ( 4 * X_fx->lag_fx )] ); /* Q(12+15+1) */ @@ -4520,7 +4672,9 @@ void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_ } nb = sub( nb, 1 ); /* leave one more sign bit */ X_fx->a_fx[k] = round_fx( L_shl( sum1_fx, nb ) ); /* Q(Q-temp1+22+nb-16)=Q(Q-temp1+nb+2) */ + move16(); X_fx->b_fx[k] = round_fx( L_shl( sum2_fx, nb ) ); /* Q(Q-temp1+nb+2) */ + move16(); Qab[k] = add( sub( add( nb, 2 ), temp1 ), X_fx->Q ); @@ -4540,6 +4694,7 @@ void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_ } X_fx->Q = Qmin; + move16(); } /*===================================================================*/ /* FUNCTION : poleFilter_setup_fx() */ @@ -4574,6 +4729,7 @@ void poleFilter_setup_fx( const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word Word16 exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif HalfLag = s_min( shr( X_fx.lag_fx, 1 ), X_fx.nH_fx ); @@ -4618,7 +4774,11 @@ void poleFilter_setup_fx( const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word } n2 = sub( n2, 1 ); temp1 = pf_temp1[k] = round_fx( (Word32) L_shl( sum1_fx, n2 ) ); /* Q(12+15+1+n2-16)=Q(12+n2) */ + move16(); + move16(); temp2 = pf_temp2[k] = round_fx( (Word32) L_shl( sum2_fx, n2 ) ); /* Q(12+n2) */ + move16(); + move16(); /* Calculate the circular convolution */ sum = L_mac( L_mult( temp1, temp1 ), temp2, temp2 ); /* Q(12+n2+12+n2+1)=Q(25+2*n2) */ @@ -4677,7 +4837,7 @@ Word32 DTFS_getEngy_band_wb_fx( DTFS_STRUCTURE X_fx, Word16 lband, Word16 hband { freq_fx = L_mult( k, 12800 ); - if ( GE_32( freq_fx, L_lband ) ) + IF( GE_32( freq_fx, L_lband ) ) { BREAK; } @@ -4687,7 +4847,7 @@ Word32 DTFS_getEngy_band_wb_fx( DTFS_STRUCTURE X_fx, Word16 lband, Word16 hband FOR( k = 1; k <= HalfLag; k++ ) { freq_fx = L_mult( k, 12800 ); - if ( GE_32( freq_fx, L_hband ) ) + IF( GE_32( freq_fx, L_hband ) ) { BREAK; } @@ -4702,14 +4862,14 @@ Word32 DTFS_getEngy_band_wb_fx( DTFS_STRUCTURE X_fx, Word16 lband, Word16 hband } en_fx = L_shr( en_fx, 1 ); /* 2*X1.Q+1 */ - if ( lband == 0 ) + IF( lband == 0 ) { en_fx = L_mac0( en_fx, X_fx.a_fx[0], X_fx.a_fx[0] ); /* 2*X1.Q+1 */ } /* IF ((X_fx.lag_fx%2 == 0) && (hband == X_fx.upper_cut_off_freq_fx)) */ test(); - IF( ( s_and( X_fx.lag_fx, 1 ) == 0 ) && ( hband == X_fx.upper_cut_off_freq_fx ) ) + IF( ( s_and( X_fx.lag_fx, 1 ) == 0 ) && EQ_16( hband, X_fx.upper_cut_off_freq_fx ) ) { en_fx = L_mac0( en_fx, X_fx.a_fx[k], X_fx.a_fx[k] ); en_fx = L_mac0( en_fx, X_fx.b_fx[k], X_fx.b_fx[k] ); diff --git a/lib_com/window_fx.c b/lib_com/window_fx.c index d848b2dd38998370f39b718fafb097111395bfd0..97443e3b594aadfa39b35e1efaf58a0cdfd67e73 100644 --- a/lib_com/window_fx.c +++ b/lib_com/window_fx.c @@ -7,7 +7,6 @@ #include "options.h" #include #include "basop_util.h" -#include "prot_fx1.h" #define PI_HALF_0Q15 51472 /* ~=round(pi/2*2^15) */ #define PI2_15Q16 0x0006487F /* ~=round(2*PI*2^16) */ @@ -19,7 +18,7 @@ #define P92_0Q15 30147 /* ~=round(0.92*2^15) */ #include "options.h" #include "rom_basop_util.h" -#include "prot_fx2.h" +#include "prot_fx.h" void ham_cos_window( @@ -32,16 +31,17 @@ void ham_cos_window( Word32 cte, cc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif assert( n1 >= 102 ); /* if n1 is too low -> overflow in div_l */ /* cte = PI2/(Float32)(2*n1 - 1); */ BASOP_SATURATE_WARNING_OFF_EVS - move16(); cte = L_deposit_l( div_l( PI2_10Q21, sub( shl( n1, 1 ), 1 ) ) ); /*0Q15*/ BASOP_SATURATE_WARNING_ON_EVS cc = 0; + move32(); FOR( i = 0; i < n1; i++ ) { /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */ @@ -61,7 +61,7 @@ void ham_cos_window( /* cte = PI2/(Float32)(4*n2 - 1); */ cte = L_deposit_l( div_l( PI2_11Q20, sub( shl( n2, 2 ), 1 ) ) ); /*0Q15*/ cc = 0; - move16(); + move32(); add( n1, n2 ); BASOP_SATURATE_WARNING_OFF_EVS @@ -96,9 +96,10 @@ void ham_cos_window_ivas( // cte_fx = div_s(1, sub(shl(n1, 1), 1)); cc_fx = 0; move16(); - for ( i = 0; i < n1; i++ ) + FOR( i = 0; i < n1; i++ ) { *fh++ = sub( 17694, mult( getCosWord16R2( cc_fx ), 15073 ) ); + move16(); cc_fx = div_s( add( i, 1 ), sub( shl( n1, 1 ), 1 ) ); // add(cc_fx, cte_fx); } @@ -109,8 +110,8 @@ void ham_cos_window_ivas( for ( i = 0; i < n2; i++ ) { *fh++ = getCosWord16R2( cc_fx ); + move16(); cc_fx = div_s( add( i, 1 ), sub( shl( n1, 2 ), 1 ) ); - ; } return; diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 32ae48d50392969cfbf442082bfadc76cf8cc985..40c31f8fd9d7d4eeee81b0e24a634b2e8cd0cbf8 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Function prototypes */ #include "stl.h" void sinq_fx( @@ -32,7 +31,7 @@ void sinq_fx( #ifdef BASOP_NOGLOB tmp1 = add_sat( shl_sat( tmp, 1 ), phi ); /*Q15 */ #else - tmp1 = add( shl( tmp, 1 ), phi ); /*Q15 */ + tmp1 = add( shl( tmp, 1 ), phi ); /*Q15 */ #endif L_tmp = L_mult( tmp1, tmp1 ); /*Q31 */ L_tmp = Mult_32_16( L_tmp, tmp1 ); /*Q31 */ @@ -67,9 +66,10 @@ void sinq_fx( tmp_old = L_shl_sat( L_tmp, 1 ); /*Q31 */ x[i] = round_fx_sat( tmp_old ); /*Q15 */ #else - tmp_old = L_shl( L_tmp, 1 ); /*Q31 */ - x[i] = round_fx( tmp_old ); /*Q15 */ + tmp_old = L_shl( L_tmp, 1 ); /*Q31 */ + x[i] = round_fx( tmp_old ); /*Q15 */ #endif + move16(); } return; @@ -130,6 +130,7 @@ void window_ola_fx( move32(); } *Q_sig = add( *Q_sig, temp ); + move16(); /* rescaling for overlapp add */ @@ -137,14 +138,17 @@ void window_ola_fx( { Copy_Scale_sig( OldauOut, OldauOut, L, sub( *Q_sig, add( *Q_old, 15 ) ) ); *Q_old = sub( *Q_sig, 15 ); + move16(); } ELSE IF( LT_16( add( *Q_old, 15 ), *Q_sig ) ) { Scale_sig32( ImdctOut, L, sub( add( *Q_old, 15 ), *Q_sig ) ); *Q_sig = add( *Q_old, 15 ); + move16(); } *Q_sig = *Q_old; /*fixing output to new Q_old */ + move16(); decimate = 1; @@ -285,6 +289,7 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i++ ) { *p1++ = round_fx( L_shl( *pa++, 1 ) ); + move16(); } /*p1=paout+shr(L,1);*/ @@ -293,6 +298,7 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i++ ) { *p1++ = round_fx( L_negate( L_shl( *pa--, 1 ) ) ); + move16(); } @@ -323,11 +329,10 @@ void window_ola_fx( { #ifdef BASOP_NOGLOB *p1 = add_sat( mult( *p1, *p2 ), shl_sat( mult( *p4, *p3 ), 5 ) ); /*auOut[i]*SS2[i]+ OldauOut[i+n]*(SS2[L-n-i-1])/(wret2[i]+0.01f);;*/ - move16(); #else - *p1 = add( mult( *p1, *p2 ), shl( mult( *p4, *p3 ), 5 ) ); /*auOut[i]*SS2[i]+ OldauOut[i+n]*(SS2[L-n-i-1])/(wret2[i]+0.01f);;*/ - move16(); + *p1 = add( mult( *p1, *p2 ), shl( mult( *p4, *p3 ), 5 ) ); /*auOut[i]*SS2[i]+ OldauOut[i+n]*(SS2[L-n-i-1])/(wret2[i]+0.01f);;*/ #endif + move16(); p1++; p2++; p3++; @@ -362,6 +367,7 @@ void window_ola_fx( p3 -= decimate; *p1++ = round_fx( L_add( L_shl( Mult_32_16( *pa++, *p5-- ), 1 ), L_deposit_h( *p4++ ) ) ); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ #endif + move16(); /* paout[i] = ImdctOut[L/2 + i] * win_right[(2*L_FRAME16k-(n16+(i-n)/2))*decimate-1-decay-windecay48]+OldauOut[i]; paout[i+1] = ImdctOut[L/2 + i +1] * win_int_right[2*L_FRAME16k-(n16+(i-n)/2)-1-windecay16]+OldauOut[i+1];*/ } @@ -380,6 +386,7 @@ void window_ola_fx( *p1++ = round_fx( L_sub( L_deposit_h( *p4++ ), L_shl( Mult_32_16( *pa--, *p5-- ), 1 ) ) ); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ *p1++ = round_fx( L_sub( L_deposit_h( *p4++ ), L_shl( Mult_32_16( *pa--, *p3 ), 1 ) ) ); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ #endif + move16(); p3 -= decimate; /* paout[L/2 + i ] = -ImdctOut[L - 1 - i] * win_int_right[(3*L_FRAME16k/2-1-i/2)-windecay16]+OldauOut[i+L/2]; paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)] * win_right[(3*L_FRAME16k/2-1-i/2)*decimate+decay-windecay48]+OldauOut[i+L/2+1]; */ @@ -387,7 +394,9 @@ void window_ola_fx( FOR( i = 0; i < n; i += 2 ) { *p1++ = round_fx_sat( L_sub_sat( L_deposit_h( *p4++ ), L_shl( *pa--, 1 ) ) ); + move16(); *p1++ = round_fx_sat( L_sub_sat( L_deposit_h( *p4++ ), L_shl( *pa--, 1 ) ) ); + move16(); /* paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)]+OldauOut[i+L/2+1] ; paout[L/2 + i ] = -ImdctOut[L - 1 - i]+OldauOut[i+L/2]; */ } @@ -402,7 +411,9 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i += 2 ) { *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa++, *p2-- ), 1 ) ) ); + move16(); *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa++, *p3 ), 1 ) ) ); + move16(); p3 -= decimate; /* OldauOut[L/2 + i] = -ImdctOut[i] * win_int_left[(L_FRAME16k/2-i/2-1)]; OldauOut[L/2 + i +1] = -ImdctOut[i+1] * win_left[(L_FRAME16k/2-i/2-1)*decimate+decay]*/ @@ -417,7 +428,9 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i += 2 ) { *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa--, *p2 ), 1 ) ) ); + move16(); *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa--, *p3-- ), 1 ) ) ); + move16(); p2 -= decimate; /* OldauOut[ i] = -ImdctOut[L/2 - 1 - i] *win_left[(L_FRAME16k-i/2)*decimate-decay-1]; OldauOut[ i +1] = -ImdctOut[L/2 - 1 - (i +1)] * win_int_left[L_FRAME16k-(i/2)-1];; */ @@ -441,6 +454,7 @@ void window_ola_fx( #else *p1++ = round_fx( L_add( L_shl( Mult_32_16( *pa++, *p3 ), 1 ), L_deposit_h( *p4++ ) ) ); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ #endif + move16(); p3 -= decimate; /*paout[i] = ImdctOut[L/2 + i] * win_right[(2*L-i)*decimate-1-decay-windecay48]+OldauOut[i];*/ } @@ -456,12 +470,14 @@ void window_ola_fx( #else *p1++ = round_fx( L_sub( L_deposit_h( *p4++ ), L_shl( Mult_32_16( *pa--, *p3 ), 1 ) ) ); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ #endif + move16(); p3 -= decimate; /* paout[L/2 + i] = -ImdctOut[L - 1 - i] * win_right[(3*L/2-1-i)*decimate+decay-windecay48]+OldauOut[i+L/2]; */ } FOR( i = 0; i < n; i++ ) { *p1++ = round_fx_sat( L_sub_sat( L_deposit_h( *p4++ ), L_shl( *pa--, 1 ) ) ); + move16(); /* paout[L/2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i+L/2]; */ } } @@ -475,6 +491,7 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i++ ) { *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa++, *p2 ), 1 ) ) ); + move16(); p2 -= decimate; /*OldauOut[L/2 + i] = -ImdctOut[i] * win_left[(L/2-i-1)*decimate+decay]; */ } @@ -486,6 +503,7 @@ void window_ola_fx( FOR( i = 0; i < temp_len; i++ ) { *p1++ = round_fx( L_negate( L_shl( Mult_32_16( *pa--, *p2 ), 1 ) ) ); + move16(); p2 -= decimate; /* OldauOut[ i] = -ImdctOut[L/2 - 1 - i] * win_left[(L-i)*decimate-decay-1]; */ } @@ -498,7 +516,9 @@ void window_ola_fx( FOR( i = 0; i < n; i++ ) { *p1 = round_fx( L_negate( L_shl( *pa--, 1 ) ) ); + move16(); *p2++ = *p1++; + move16(); } return; @@ -532,35 +552,51 @@ void window_ola_ext_fx( n = shr( mult( shl( L, Q5 ), N_ZERO_BY_FS ), Q5 ); n16 = N16_CORE_SW; + move16(); windecay48 = WINDECAY48; + move16(); windecay16 = WINDECAY16; + move16(); decimate = 1; + move16(); decay = 0; + move16(); tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L ); + test(); IF( EQ_16( L, L_FRAME32k ) || EQ_16( L, L_FRAME16k ) ) { decimate = 3; + move16(); decay = 1; + move16(); } ELSE IF( EQ_16( L, L_FRAME8k ) ) { decimate = 6; + move16(); decay = 2; + move16(); } ELSE IF( EQ_16( L, 512 ) ) { windecay48 = WINDECAY48_256; + move16(); decimate = 1; + move16(); decay = 0; + move16(); } ELSE IF( EQ_16( L, 256 ) ) { windecay48 = WINDECAY48_256; + move16(); decimate = 2; + move16(); decay = 0; + move16(); } paout = auOut - n; @@ -569,71 +605,88 @@ void window_ola_ext_fx( { FOR( i = n; i < shr( L, 1 ); i += 2 ) { - paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i], sign_right ), win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] ), OldauOut[i] ); - paout[i + 1] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i + 1], sign_right ), win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] ), OldauOut[i + 1] ); + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( shr( L, 1 ), i )], sign_right ), win_right[sub( sub( sub( i_mult( ( sub( 2 * L_FRAME16k, add( n16, shr( sub( i, n ), 1 ) ) ) ), decimate ), 1 ), decay ), windecay48 )] ), OldauOut[i] ); + move32(); + paout[i + 1] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( add( shr( L, 1 ), i ), 1 )], sign_right ), win_int_right[sub( sub( sub( 2 * L_FRAME16k, add( n16, shr( sub( i, n ), 1 ) ) ), 1 ), windecay16 )] ), OldauOut[i + 1] ); + move32(); } FOR( i = 0; i < shr( L, 1 ) - n; i += 2 ) { - paout[shr( L, 1 ) + i + 1] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - ( i + 1 )] ), win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] ), OldauOut[i + shr( L, 1 ) + 1] ); - paout[shr( L, 1 ) + i] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - i] ), win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] ), OldauOut[i + shr( L, 1 )] ); + paout[add( add( shr( L, 1 ), i ), 1 )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( sub( L, 1 ), add( i, 1 ) )] ), win_right[sub( add( i_mult( ( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ) ), decimate ), decay ), windecay48 )] ), OldauOut[add( add( i, shr( L, 1 ) ), 1 )] ); + move32(); + paout[add( shr( L, 1 ), i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( sub( L, 1 ), i )] ), win_int_right[sub( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ), windecay16 )] ), OldauOut[add( i, shr( L, 1 ) )] ); + move32(); } FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i += 2 ) { - paout[shr( L, 1 ) + i + 1] = L_add_sat( L_negate( ImdstOut[L - 1 - ( i + 1 )] ), OldauOut[i + shr( L, 1 ) + 1] ); - paout[shr( L, 1 ) + i] = L_add_sat( L_negate( ImdstOut[L - 1 - i] ), OldauOut[i + shr( L, 1 )] ); + paout[add( add( shr( L, 1 ), i ), 1 )] = L_add_sat( L_negate( ImdstOut[sub( sub( L, 1 ), add( i, 1 ) )] ), OldauOut[add( add( i, shr( L, 1 ) ), 1 )] ); + move32(); + paout[add( shr( L, 1 ), i )] = L_add_sat( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), OldauOut[add( i, shr( L, 1 ) )] ); + move32(); } FOR( i = 0; i < shr( L, 1 ); i += 2 ) { - OldauOut[shr( L, 1 ) + i + 1] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i + 1], sign_left ), win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay] ); - OldauOut[shr( L, 1 ) + i] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )] ); + OldauOut[add( add( shr( L, 1 ), i ), 1 )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i + 1], sign_left ), win_left[add( i_mult( sub( L_FRAME16k / 2 - 1, shr( i, 1 ) ), decimate ), decay )] ); + move32(); + OldauOut[add( shr( L, 1 ), i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_int_left[sub( L_FRAME16k / 2 - 1, shr( i, 1 ) )] ); + move32(); } FOR( i = n; i < shr( L, 1 ); i += 2 ) { - OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ), win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1] ); - OldauOut[i + 1] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - ( i + 1 )] ), win_int_left[L_FRAME16k - i / 2 - 1] ); + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[sub( sub( shr( L, 1 ), 1 ), i )] ), win_left[sub( sub( i_mult( sub( L_FRAME16k, shr( i, 1 ) ), decimate ), decay ), 1 )] ); + move32(); + OldauOut[i + 1] = Mpy_32_16_1( L_negate( ImdstOut[sub( sub( shr( L, 1 ), 1 ), add( i, 1 ) )] ), win_int_left[sub( L_FRAME16k - 1, shr( i, 1 ) )] ); + move32(); } } ELSE { FOR( i = n; i < shr( L, 1 ); i++ ) { - paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i], sign_right ), win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] ), OldauOut[i] ); + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[add( shr( L, 1 ), i )], sign_right ), win_right[sub( sub( sub( i_mult( ( sub( shl( L, 1 ), i ) ), decimate ), 1 ), decay ), windecay48 )] ), OldauOut[i] ); + move32(); } FOR( i = 0; i < shr( L, 1 ) - n; i++ ) { - paout[shr( L, 1 ) + i] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - i] ), win_right[( 3 * shr( L, 1 ) - 1 - i ) * decimate + decay - windecay48] ), OldauOut[i + shr( L, 1 )] ); + paout[add( shr( L, 1 ), i )] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), win_right[sub( add( i_mult( ( sub( sub( i_mult( 3, shr( L, 1 ) ), 1 ), i ) ), decimate ), decay ), windecay48 )] ), OldauOut[add( i, shr( L, 1 ) )] ); + move32(); } FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i++ ) { - paout[shr( L, 1 ) + i] = L_add_sat( L_negate( ImdstOut[L - 1 - i] ), OldauOut[i + shr( L, 1 )] ); + paout[add( shr( L, 1 ), i )] = L_add_sat( L_negate( ImdstOut[sub( L, add( 1, i ) )] ), OldauOut[add( i, shr( L, 1 ) )] ); + move32(); } FOR( i = 0; i < shr( L, 1 ); i++ ) { - OldauOut[shr( L, 1 ) + i] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_left[( shr( L, 1 ) - i - 1 ) * decimate + decay] ); + OldauOut[add( shr( L, 1 ), i )] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_left[add( i_mult( ( sub( shr( L, 1 ), add( i, 1 ) ) ), decimate ), decay )] ); + move32(); } FOR( i = n; i < shr( L, 1 ); i++ ) { - OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ), win_left[( L - i ) * decimate - decay - 1] ); + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[sub( shr( L, 1 ), add( 1, i ) )] ), win_left[sub( sub( i_mult( sub( L, i ), decimate ), decay ), 1 )] ); + move32(); } } FOR( i = 0; i < n; i++ ) { - OldauOut[i] = L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ); + OldauOut[i] = L_negate( ImdstOut[sub( shr( L, 1 ), add( 1, i ) )] ); + move32(); } FOR( i = 0; i < n; i++ ) { - paout[L + i] = OldauOut[i]; + paout[add( L, i )] = OldauOut[i]; + move32(); } return; @@ -665,6 +718,8 @@ void core_switching_OLA_fx( const Word16 *pt4, *pt5; Word16 tmp, tmp2, temp_len; Word16 decimate = 0, delta = 0; /* initialize just to avoid compiler warnings */ + move16(); + move16(); const Word16 *on_win, *on_win_int; Word16 a, b, divisor, buf_offset; Word32 L_tmp; diff --git a/lib_com/wtda.c b/lib_com/wtda.c index 053e892f1b985850165859e0a949f9f201768a24..eed61a240778fb7867926794b02c2501ffbff432 100644 --- a/lib_com/wtda.c +++ b/lib_com/wtda.c @@ -42,8 +42,8 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*--------------------------------------------------------------------------* * mvr2r_inv() @@ -374,127 +374,153 @@ void wtda_fx32( tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L ); decimate = 1; /* L_FRAME 48k */ + move16(); decay = 0; + move16(); windecay48 = (Word16) WINDECAY48; // (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48 + move16(); IF( EQ_16( L, L_FRAME32k ) || EQ_16( L, L_FRAME16k ) ) { decimate = 3; + move16(); decay = 1; + move16(); } ELSE IF( EQ_16( L, L_FRAME8k ) ) { decimate = 6; + move16(); decay = 2; + move16(); } - switch ( L ) // (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS) + SWITCH( L ) // (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS) { case L_FRAME16k: n = 90; - break; + move16(); + BREAK; case L_FRAME32k: n = 180; - break; + move16(); + BREAK; case L_FRAME48k: n = 270; - break; + move16(); + BREAK; default: n = (Word16) ( ( L * N_ZERO_MDCT_NS ) / FRAME_SIZE_NS ); - break; + move16(); + BREAK; } windecay16 = (Word16) WINDECAY16; // (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; /* algorithmic delay reduction */ i = 0; + move16(); - if ( old_wtda == NULL ) + IF( old_wtda == NULL ) { allsig_r = new_audio + n; allsig_l = new_audio + n - L; } - else + ELSE { allsig_r = new_audio + n; allsig_l = old_wtda + n; } - if ( EQ_16( L, L_FRAME32k ) ) + IF( EQ_16( L, L_FRAME32k ) ) { - for ( i = 0; i < L / 2 - n; i += 2 ) + FOR( i = 0; i < sub( L / 2, n ); i += 2 ) { - idx1 = L / 2 - i - 1; - idx2 = 3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16; - idx3 = L / 2 + i; - idx4 = 3 * L_FRAME16k / 2 + i / 2 - windecay16; + idx1 = sub( sub( shr( L, 1 ), i ), 1 ); + idx2 = sub( sub( 3 * L_FRAME16k / 2 - 1, shr( i, 1 ) ), windecay16 ); + idx3 = add( shr( L, 1 ), i ); + idx4 = sub( add( 3 * L_FRAME16k / 2, shr( i, 1 ) ), windecay16 ); wtda_audio[i] = L_sub_sat( Mpy_32_16_1( -allsig_r[idx1], win_int_right[idx2] ), Mpy_32_16_1( allsig_r[idx3], win_int_right[idx4] ) ); + move32(); - idx1 = L / 2 - ( i + 1 ) - 1; - idx2 = ( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48; - idx3 = L / 2 + i + 1; - idx4 = ( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48; + idx1 = sub( sub( shr( L, 1 ), add( i, 1 ) ), 1 ); + idx2 = sub( add( i_mult( ( sub( sub( 3 * L_FRAME16k / 2, shr( i, 1 ) ), 1 ) ), decimate ), decay ), windecay48 ); + idx3 = add( add( shr( L, 1 ), i ), 1 ); + idx4 = sub( sub( sub( i_mult( ( add( 3 * L_FRAME16k / 2 + 1, shr( i, 1 ) ) ), decimate ), decay ), 1 ), windecay48 ); wtda_audio[i + 1] = L_sub_sat( Mpy_32_16_1( -allsig_r[idx1], win_right[idx2] ), Mpy_32_16_1( allsig_r[idx3], win_right[idx4] ) ); + move32(); } - for ( i = L / 2 - n; i < L / 2; i += 2 ) + FOR( i = L / 2 - n; i < L / 2; i += 2 ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1]; - wtda_audio[i + 1] = -allsig_r[L / 2 - ( i + 1 ) - 1]; + wtda_audio[i] = L_negate( allsig_r[sub( sub( shr( L, 1 ), i ), 1 )] ); + move32(); + wtda_audio[i + 1] = L_negate( allsig_r[sub( sub( shr( L, 1 ), add( i, 1 ) ), 1 )] ); + move32(); } - for ( i = 0; i < n; i += 2 ) + FOR( i = 0; i < n; i += 2 ) { - wtda_audio[i + L / 2] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), new_audio[n - i - 1] ); - wtda_audio[i + L / 2 + 1] = L_sub_sat( Mpy_32_16_1( allsig_l[i + 1], win_int_left[i / 2] ), new_audio[n - ( i + 1 ) - 1] ); + wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[add( i_mult( shr( i, 1 ), decimate ), decay )] ), new_audio[sub( sub( n, i ), 1 )] ); + move32(); + wtda_audio[add( add( i, shr( L, 1 ) ), 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[i + 1], win_int_left[i / 2] ), new_audio[sub( sub( n, add( i, 1 ) ), 1 )] ); + move32(); } - for ( i = n; i < L / 2; i += 2 ) + FOR( i = n; i < L / 2; i += 2 ) { idx1 = i; - idx2 = ( i / 2 ) * decimate + decay; - idx3 = L - i - 1; - idx4 = ( L / 2 - i / 2 ) * decimate - 1 - decay; - wtda_audio[i + L / 2] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); - - idx1 = i + 1; - idx2 = i / 2; - idx3 = L - ( i + 1 ) - 1; - idx4 = L / 2 - i / 2 - 1; - wtda_audio[i + L / 2 + 1] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_int_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_int_left[idx4] ) ); + move16(); + idx2 = add( i_mult( shr( i, 1 ), decimate ), decay ); + idx3 = sub( sub( L, i ), 1 ); + idx4 = sub( sub( i_mult( sub( shr( L, 1 ), shr( i, 1 ) ), decimate ), 1 ), decay ); + wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); + move32(); + + idx1 = add( i, 1 ); + idx2 = shr( i, 1 ); + idx3 = sub( sub( L, add( i, 1 ) ), 1 ); + idx4 = sub( sub( shr( L, 1 ), shr( i, 1 ) ), 1 ); + wtda_audio[add( add( i, shr( L, 1 ) ), 1 )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_int_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_int_left[idx4] ) ); + move32(); } } - else + ELSE { - for ( i = 0; i < L / 2 - n; i++ ) + FOR( i = 0; i < L / 2 - n; i++ ) { - idx1 = L / 2 - i - 1; - idx2 = 3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48; - idx3 = L / 2 + i; - idx4 = 3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48; + idx1 = sub( sub( shr( L, 1 ), i ), 1 ); + idx2 = sub( add( sub( i_mult( i_mult( 3, shr( L, 1 ) ), decimate ), i_mult( add( i, 1 ), decimate ) ), decay ), windecay48 ); + idx3 = add( shr( L, 1 ), i ); + idx4 = sub( sub( add( sub( i_mult( i_mult( 3, shr( L, 1 ) ), decimate ), 1 ), i_mult( add( i, 1 ), decimate ) ), decay ), windecay48 ); wtda_audio[i] = L_sub_sat( Mpy_32_16_1( -allsig_r[idx1], win_right[idx2] ), Mpy_32_16_1( allsig_r[idx3], win_right[idx4] ) ); + move32(); } - for ( i = L / 2 - n; i < L / 2; i++ ) + FOR( i = L / 2 - n; i < L / 2; i++ ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1]; + wtda_audio[i] = L_negate( allsig_r[sub( sub( shr( L, 1 ), i ), 1 )] ); + move32(); } - for ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { - wtda_audio[i + L / 2] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[i * decimate + decay] ), new_audio[n - i - 1] ); + wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[i], win_left[add( i_mult( i, decimate ), decay )] ), new_audio[sub( sub( n, i ), 1 )] ); + move32(); } - for ( i = n; i < L / 2; i++ ) + FOR( i = n; i < L / 2; i++ ) { idx1 = i; - idx2 = i * decimate + decay; - idx3 = L - i - 1; - idx4 = L * decimate - i * decimate - 1 - decay; - wtda_audio[i + L / 2] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); + move16(); + idx2 = add( i_mult( i, decimate ), decay ); + idx3 = sub( sub( L, i ), 1 ); + idx4 = sub( sub( sub( i_mult( L, decimate ), i_mult( i, decimate ) ), 1 ), decay ); + wtda_audio[add( i, shr( L, 1 ) )] = L_sub_sat( Mpy_32_16_1( allsig_l[idx1], win_left[idx2] ), Mpy_32_16_1( allsig_l[idx3], win_left[idx4] ) ); + move32(); } } - if ( old_wtda != NULL ) + IF( old_wtda != NULL ) { Copy32( new_audio, old_wtda, L ); } diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index dcc9b8229106403b6b422d325bf896b652faef6b..b20771f8cec8d7bb6f612290256471ea1d07161e 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* required by wmc_tool */ -#include "prot_fx2.h" /* required by wmc_tool */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* required by wmc_tool */ #include "stat_com.h" /*--------------------------------------------------------------------------* * mvr2r_inv() @@ -284,7 +283,7 @@ void wtda_fx( } - IF( L == L_FRAME32k ) + IF( EQ_16( L, L_FRAME32k ) ) { /* decimate = 3 */ @@ -403,8 +402,9 @@ void wtda_fx( } *Q = add( *Q, 15 ); /* output Q */ + move16(); - if ( old_wtda != NULL ) + IF( old_wtda != NULL ) { Copy( new_audio, old_wtda, L ); diff --git a/lib_debug/debug.c b/lib_debug/debug.c index 5e65379903e77a3b064c33bebd23f1c683122859..f1cfa928ab136ad2fb2817655dae23025cf79eed 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -919,6 +919,7 @@ int16_t dbgwrite_wav( return 0; } +#endif int16_t dbgwrite_txt( @@ -974,5 +975,4 @@ int16_t dbgwrite_txt( return 0; } -#endif #endif /* DEBUGGING */ diff --git a/lib_debug/debug.h b/lib_debug/debug.h index 0d3e920ca4f7f870cd12ecb306f0b4534da12436..e88def922b0992a0ba765942089cb59a8d4a76c6 100644 --- a/lib_debug/debug.h +++ b/lib_debug/debug.h @@ -105,12 +105,14 @@ int16_t dbgwrite_wav( const char *const filename, int32_t fs, int16_t num_chs ); +#endif + int16_t dbgwrite_txt( const float *buffer, /* i : Write buffer */ const int16_t count, /* i : Number of elements */ const char *const filename, const char *const msg_opt ); -#endif + void dbgwrite_mat_repeat( float *buffer, /* i : write buffer */ int16_t nRow, /* i : matrix size (rows) */ diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index eafa02a2ea3c3d259927b7c8e00d207bcbedccd1..e37fecf2ebdec6b1fead6dccf0df4e8ff5bc321c 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #ifndef _MSC_VER @@ -28,25 +29,32 @@ #include "options.h" #include "wmc_auto.h" +#include "typedef.h" +#include "count.h" + #define WMC_TOOL_SKIP /* Skip the instrumentation of this file, if invoked by accident */ -#ifdef WMOPS_FLT +#ifdef WMOPS /*-------------------------------------------------------------------* * Complexity counting tool *--------------------------------------------------------------------*/ -#define MAX_RECORDS 1024 -#define MAX_CHAR 64 -#define MAX_STACK 64 -#define DOUBLE_MAX 0x80000000 +#define MAX_FUNCTION_NAME_LENGTH 200 /* Maximum length of the function name */ +#define MAX_PARAMS_LENGTH 200 /* Maximum length of the function parameter string */ +#define MAX_NUM_RECORDS 300 /* Initial maximum number of records -> might be increased during runtime, if needed */ +#define MAX_NUM_RECORDS_REALLOC_STEP 50 /* When re-allocating the list of records, increase the number of records by this number */ +#define MAX_CALL_TREE_DEPTH 100 /* maximum depth of the function call tree */ +#define DOUBLE_MAX 0x80000000 +#define FAC ( FRAMES_PER_SECOND / 1e6 ) -struct wmops_record +typedef struct { - char label[MAX_CHAR]; + char label[MAX_FUNCTION_NAME_LENGTH]; long call_number; long update_cnt; - int call_tree[MAX_RECORDS]; + int call_tree[MAX_CALL_TREE_DEPTH]; + long LastWOper; double start_selfcnt; double current_selfcnt; double max_selfcnt; @@ -63,16 +71,14 @@ struct wmops_record double wc_selfcnt; int32_t wc_call_number; #endif -}; +} wmops_record; -double ops_cnt; -double prom_cnt; +double ops_cnt_wmc; +double prom_cnt_wmc; double inst_cnt[NUM_INST]; -static struct wmops_record wmops[MAX_RECORDS]; -static int stack[MAX_STACK]; -static int sptr; -static int num_records; +static wmops_record* wmops = NULL; +static int num_wmops_records, max_num_wmops_records; static int current_record; static long update_cnt; static double start_cnt; @@ -80,20 +86,59 @@ static double max_cnt; static double min_cnt; static double inst_cnt_wc[NUM_INST]; static long fnum_cnt_wc; - +static int *wmops_caller_stack = NULL, wmops_caller_stack_index, max_wmops_caller_stack_index = 0; static int *heap_allocation_call_tree = NULL, heap_allocation_call_tree_size = 0, heap_allocation_call_tree_max_size = 0; void reset_wmops( void ) { int i, j; + //unsigned int *ptr; + + num_wmops_records = 0; + max_num_wmops_records = MAX_NUM_RECORDS; + current_record = -1; + update_cnt = 0; + + max_cnt = 0.0; + min_cnt = DOUBLE_MAX; + start_cnt = 0.0; + ops_cnt_wmc = 0.0; + + /* allocate the list of wmops records */ + if ( wmops == NULL ) + { + wmops = (wmops_record *) malloc( max_num_wmops_records * sizeof( wmops_record ) ); + } + + if ( wmops == NULL ) + { + fprintf( stderr, "Error: Unable to Allocate List of WMOPS Records!" ); + exit( -1 ); + } + + /* allocate the BASOP WMOPS counter */ + //if ( multiCounter == NULL ) + //{ + // multiCounter = (BASIC_OP *) malloc( max_num_wmops_records * sizeof( BASIC_OP ) ); + //} + + //if ( multiCounter == NULL ) + //{ + // fprintf( stderr, "Error: Unable to Allocate the BASOP WMOPS counter!" ); + // exit( -1 ); + //} + + BASOP_init - for ( i = 0; i < MAX_RECORDS; i++ ) + /* initilize the list of WMOPS records */ + /* initilize the BASOP WMOPS counters */ + for ( i = 0; i < max_num_wmops_records; i++ ) { strcpy( &wmops[i].label[0], "\0" ); wmops[i].call_number = 0; wmops[i].update_cnt = 0; - for ( j = 0; j < MAX_RECORDS; j++ ) + for ( j = 0; j < MAX_CALL_TREE_DEPTH; j++ ) { wmops[i].call_tree[j] = -1; } @@ -111,96 +156,175 @@ void reset_wmops( void ) wmops[i].wc_cnt = 0.0; wmops[i].wc_selfcnt = 0.0; wmops[i].current_call_number = 0; + wmops[i].wc_call_number = -1; #endif + + /* clear all BASOP operation counters */ + //ptr = (unsigned int *) &multiCounter[i]; + //for ( j = 0; j < (int) ( sizeof( BASIC_OP ) / sizeof( unsigned int ) ); j++ ) + //{ + // *ptr++ = 0; + //} + wmops[i].LastWOper = 0; } - for ( i = 0; i < MAX_STACK; i++ ) + /* allocate the list of wmops callers to track the sequence of function calls */ + wmops_caller_stack_index = 0; + max_wmops_caller_stack_index = MAX_NUM_RECORDS; + if ( wmops_caller_stack == NULL ) { - stack[i] = -1; + wmops_caller_stack = malloc( max_wmops_caller_stack_index * sizeof( int ) ); } - sptr = 0; - num_records = 0; - current_record = -1; - update_cnt = 0; - max_cnt = 0.0; - min_cnt = DOUBLE_MAX; - start_cnt = 0.0; - ops_cnt = 0.0; -} + if ( wmops_caller_stack == NULL ) + { + fprintf( stderr, "Error: Unable to Allocate List of WMOPS Callers!" ); + exit( -1 ); + } + for ( i = 0; i < max_wmops_caller_stack_index; i++ ) + { + wmops_caller_stack[i] = -1; + } + + /* initialize auxiliary BASOP WMOPS variables */ + //call_occurred = 1; + //funcId_where_last_call_to_else_occurred = INT_MAX; + + return; +} -void push_wmops( const char *label ) +void push_wmops_fct( const char *label, ... ) { int new_flag; - int i, j; + int i, j, index_record; + //unsigned int *ptr; + va_list arg; + char func_name[MAX_FUNCTION_NAME_LENGTH] = ""; + + /* concatenate all function name labels into a single string */ + va_start( arg, label ); + while ( label ) + { + strcat( func_name, label ); + label = va_arg( arg, const char * ); + } + va_end( arg ); - /* Check if new function record label */ + /* Check, if this is a new function label */ new_flag = 1; - for ( i = 0; i < num_records; i++ ) + for ( i = 0; i < num_wmops_records; i++ ) { - if ( strcmp( wmops[i].label, label ) == 0 ) + if ( strcmp( wmops[i].label, func_name ) == 0 ) { new_flag = 0; break; } } + index_record = i; - /* Configure new record */ + /* Create a new record in the list */ if ( new_flag ) { - if ( num_records >= MAX_RECORDS ) + if ( num_wmops_records >= max_num_wmops_records ) { - fprintf( stdout, "push_wmops(): exceeded MAX_RECORDS count.\n\n" ); - exit( -1 ); + /* There is no room for a new WMOPS record -> reallocate the list */ + max_num_wmops_records += MAX_NUM_RECORDS_REALLOC_STEP; + wmops = realloc( wmops, max_num_wmops_records * sizeof( wmops_record ) ); + //multiCounter = realloc( multiCounter, max_num_wmops_records * sizeof( BASIC_OP ) ); + + /* initilize newly created WMOPS records */ + for ( i = num_wmops_records; i < max_num_wmops_records; i++ ) + { + strcpy( &wmops[i].label[0], "\0" ); + wmops[i].call_number = 0; + wmops[i].update_cnt = 0; + for ( j = 0; j < MAX_CALL_TREE_DEPTH; j++ ) + { + wmops[i].call_tree[j] = -1; + } + wmops[i].start_selfcnt = 0.0; + wmops[i].current_selfcnt = 0.0; + wmops[i].max_selfcnt = 0.0; + wmops[i].min_selfcnt = DOUBLE_MAX; + wmops[i].tot_selfcnt = 0.0; + wmops[i].start_cnt = 0.0; + wmops[i].current_cnt = 0.0; + wmops[i].max_cnt = 0.0; + wmops[i].min_cnt = DOUBLE_MAX; + wmops[i].tot_cnt = 0.0; +#ifdef WMOPS_WC_FRAME_ANALYSIS + wmops[i].wc_cnt = 0.0; + wmops[i].wc_selfcnt = 0.0; + wmops[i].current_call_number = 0; + wmops[i].wc_call_number = -1; +#endif + + /* initialize BASOP WMOPS counters */ + //ptr = (unsigned int *) &multiCounter[i]; + //for ( j = 0; j < (int) ( sizeof( BASIC_OP ) / sizeof( unsigned int ) ); j++ ) + //{ + // *ptr++ = 0; + //} + wmops[i].LastWOper = 0; + } } - strcpy( wmops[i].label, label ); - num_records++; + + strcpy( wmops[index_record].label, func_name ); + + num_wmops_records++; } - /* Push current context onto stack */ + /* Push the current context info to the new record */ if ( current_record >= 0 ) { - if ( sptr >= MAX_STACK ) + if ( wmops_caller_stack_index >= max_wmops_caller_stack_index ) { - fprintf( stdout, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n" ); - exit( -1 ); + /* There is no room for a new record -> reallocate the list */ + max_wmops_caller_stack_index += MAX_NUM_RECORDS_REALLOC_STEP; + wmops_caller_stack = realloc( wmops_caller_stack, max_wmops_caller_stack_index * sizeof( int ) ); } - stack[sptr++] = current_record; + wmops_caller_stack[wmops_caller_stack_index++] = current_record; /* accumulate op counts */ - wmops[current_record].current_selfcnt += ops_cnt - wmops[current_record].start_selfcnt; + wmops[current_record].current_selfcnt += ops_cnt_wmc - wmops[current_record].start_selfcnt; /* update call tree */ - for ( j = 0; j < MAX_RECORDS; j++ ) + for ( j = 0; j < MAX_CALL_TREE_DEPTH; j++ ) { - if ( wmops[i].call_tree[j] == current_record ) + if ( wmops[index_record].call_tree[j] == current_record ) { break; } - else if ( wmops[i].call_tree[j] == -1 ) + else if ( wmops[index_record].call_tree[j] == -1 ) { - wmops[i].call_tree[j] = current_record; + wmops[index_record].call_tree[j] = current_record; break; } } } - /* init current record */ - current_record = i; - wmops[current_record].start_selfcnt = ops_cnt; - wmops[current_record].start_cnt = ops_cnt; - wmops[current_record].call_number++; + /* update the current context info */ + current_record = index_record; + wmops[index_record].start_selfcnt = ops_cnt_wmc; + wmops[index_record].start_cnt = ops_cnt_wmc; + wmops[index_record].call_number++; #ifdef WMOPS_WC_FRAME_ANALYSIS - wmops[current_record].current_call_number++; + wmops[index_record].current_call_number++; #endif + /* set the ID of BASOP functions counters */ + //Set_BASOP_WMOPS_counter( index_record ); + + BASOP_push_wmops( func_name ); + return; } void pop_wmops( void ) { + //long tot; /* Check for underflow */ if ( current_record < 0 ) @@ -209,21 +333,30 @@ void pop_wmops( void ) exit( -1 ); } + /* add the BASOP complexity to the counter */ + //tot = DeltaWeightedOperation(); + //ops_cnt_wmc += tot; + /* update count of current record */ - wmops[current_record].current_selfcnt += ops_cnt - wmops[current_record].start_selfcnt; - wmops[current_record].current_cnt += ops_cnt - wmops[current_record].start_cnt; + wmops[current_record].current_selfcnt += ops_cnt_wmc - wmops[current_record].start_selfcnt; + wmops[current_record].current_cnt += ops_cnt_wmc - wmops[current_record].start_cnt; /* Get back previous context from stack */ - if ( sptr > 0 ) + if ( wmops_caller_stack_index > 0 ) { - current_record = stack[--sptr]; - wmops[current_record].start_selfcnt = ops_cnt; + current_record = wmops_caller_stack[--wmops_caller_stack_index]; + wmops[current_record].start_selfcnt = ops_cnt_wmc; + + /* set the ID of the previous BASOP counter */ + //Set_BASOP_WMOPS_counter( current_record ); } else { current_record = -1; } + BASOP_pop_wmops(); + return; } @@ -238,9 +371,9 @@ void update_wmops( void ) float tmpF; #endif - if ( sptr != 0 ) + if ( wmops_caller_stack_index != 0 ) { - fprintf( stdout, "update_wmops(): Stack must be empty!\n" ); + fprintf( stdout, "update_wmops(): WMOPS caller stack corrupted - check that all push_wmops() are matched with pop_wmops()!\n" ); exit( -1 ); } @@ -265,7 +398,7 @@ void update_wmops( void ) #ifdef WMOPS_WC_FRAME_ANALYSIS if ( ops_cnt - start_cnt > max_cnt ) { - for ( i = 0; i < num_records; i++ ) + for ( i = 0; i < num_wmops_records; i++ ) { wmops[i].wc_cnt = wmops[i].current_cnt; wmops[i].wc_selfcnt = wmops[i].current_selfcnt; @@ -274,7 +407,7 @@ void update_wmops( void ) } #endif - for ( i = 0; i < num_records; i++ ) + for ( i = 0; i < num_wmops_records; i++ ) { wmops[i].tot_selfcnt += wmops[i].current_selfcnt; wmops[i].tot_cnt += wmops[i].current_cnt; @@ -301,6 +434,7 @@ void update_wmops( void ) wmops[i].max_cnt = wmops[i].current_cnt; } + if ( wmops[i].current_cnt < wmops[i].min_cnt ) { wmops[i].min_cnt = wmops[i].current_cnt; @@ -313,9 +447,13 @@ void update_wmops( void ) #ifdef WMOPS_WC_FRAME_ANALYSIS wmops[i].current_call_number = 0; #endif + + /* update the WC of all BASOP counters */ + //Set_BASOP_WMOPS_counter( i ); + //Reset_BASOP_WMOPS_counter(); } - current_cnt = ops_cnt - start_cnt; + current_cnt = ops_cnt_wmc - start_cnt; if ( current_cnt > max_cnt ) { max_cnt = current_cnt; @@ -338,169 +476,196 @@ void update_wmops( void ) inst_cnt[i] = 0.0; } - start_cnt = ops_cnt; + start_cnt = ops_cnt_wmc; /* increment frame counter */ update_cnt++; + BASOP_frame_update(); + return; } - void print_wmops( void ) { - int i; - - char *sfmts = "%20s %8s %8s %7s %7s\n"; - char *dfmts = "%20s %8.2f %8.3f %7.3f %7.3f\n"; - char *sfmt = "%20s %8s %8s %7s %7s %7s %7s %7s\n"; - char *dfmt = "%20s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - -#ifdef WMOPS_WC_FRAME_ANALYSIS - int j, label_len, max_label_len; - char *sfmtt = "%20s %4s %15s\n"; - char *dfmtt = "%20s %4d "; -#endif - - fprintf( stdout, "\n\n --- Complexity analysis [WMOPS] --- \n\n" ); - - fprintf( stdout, "%54s %23s\n", "|------ SELF ------|", "|--- CUMULATIVE ---|" ); - fprintf( stdout, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg " ); - fprintf( stdout, sfmt, "---------------", "------", "------", "------", "------", "------", "------", "------" ); - - for ( i = 0; i < num_records; i++ ) - { - fprintf( stdout, dfmt, wmops[i].label, update_cnt == 0 ? 0 : (float) wmops[i].call_number / update_cnt, - wmops[i].min_selfcnt == DOUBLE_MAX ? 0 : FAC * wmops[i].min_selfcnt, - FAC * wmops[i].max_selfcnt, - wmops[i].update_cnt == 0 ? 0 : FAC * wmops[i].tot_selfcnt / wmops[i].update_cnt, - wmops[i].min_cnt == DOUBLE_MAX ? 0 : FAC * wmops[i].min_cnt, - FAC * wmops[i].max_cnt, - wmops[i].update_cnt == 0 ? 0 : FAC * wmops[i].tot_cnt / wmops[i].update_cnt ); - } - - fprintf( stdout, sfmts, "---------------", "------", "------", "------", "------" ); - fprintf( stdout, dfmts, "total", (float) update_cnt, update_cnt == 0 ? 0 : FAC * min_cnt, FAC * max_cnt, update_cnt == 0 ? 0 : FAC * ops_cnt / update_cnt ); - fprintf( stdout, "\n" ); - -#ifdef WMOPS_WC_FRAME_ANALYSIS - /* calculate maximum label length for compact prinout */ - max_label_len = 0; - for ( i = 0; i < num_records; i++ ) - { - label_len = strlen( wmops[i].label ); - if ( label_len > max_label_len ) - { - max_label_len = label_len; - } - } - max_label_len += 4; - - fprintf( stdout, "\nComplexity analysis for the worst-case frame %ld:\n", fnum_cnt_wc ); - fprintf( stdout, "%*s %8s %10s %12s\n", max_label_len, " routine", " calls", " SELF", " CUMULATIVE" ); - fprintf( stdout, "%*s %8s %10s %10s\n", max_label_len, "---------------", "------", "------", "----------" ); + //int i, label_len, max_label_len; - for ( i = 0; i < num_records; i++ ) - { - fprintf( stdout, "%*s %8d %10.3f %12.3f\n", max_label_len, wmops[i].label, wmops[i].wc_call_number, FAC * wmops[i].wc_selfcnt, FAC * wmops[i].wc_cnt ); - } - - fprintf( stdout, "\nCall Tree:\n\n" ); - fprintf( stdout, sfmtt, " function", "num", "called by: " ); - fprintf( stdout, sfmtt, "---------------", "---", "--------------" ); - - for ( i = 0; i < num_records; i++ ) - { - fprintf( stdout, dfmtt, wmops[i].label, i ); - for ( j = 0; wmops[i].call_tree[j] != -1; j++ ) - { - if ( j != 0 ) - { - fprintf( stdout, ", " ); - } - fprintf( stdout, "%d", wmops[i].call_tree[j] ); - } - fprintf( stdout, "\n" ); - } + //char *sfmts = "%*s %8s %8s %7s %7s\n"; + //char *dfmts = "%*s %8.2f %8.3f %7.3f %7.3f\n"; + //char *sfmt = "%*s %8s %8s %7s %7s %7s %7s %7s\n"; + //char *dfmt = "%*s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - fprintf( stdout, sfmtt, "---------------", "---", "--------------" ); - fprintf( stdout, "\n\n" ); + WMOPS_output_all_std( 0 ); + WMOPS_destroy(); + return; - fprintf( stdout, "\nInstruction type analysis for the worst-case frame %ld:\n\n", fnum_cnt_wc ); /* added -- JPA */ - for ( i = 0; i < NUM_INST; i++ ) - { - switch ( (enum instructions) i ) - { - case _ADD: - fprintf( stdout, "\tAdds: %12.1f\n", inst_cnt_wc[i] ); - break; - case _ABS: - fprintf( stdout, "\tAbsolutes: %12.1f\n", inst_cnt_wc[i] ); - break; - case _MULT: - fprintf( stdout, "\tMultiplies: %12.1f\n", inst_cnt_wc[i] ); - break; - case _MAC: - fprintf( stdout, "\tMACs: %12.1f\n", inst_cnt_wc[i] ); - break; - case _MOVE: - fprintf( stdout, "\tMoves: %12.1f\n", inst_cnt_wc[i] ); - break; - case _STORE: - fprintf( stdout, "\tStores: %12.1f\n", inst_cnt_wc[i] ); - break; - case _LOGIC: - fprintf( stdout, "\tLogicals: %12.1f\n", inst_cnt_wc[i] ); - break; - case _SHIFT: - fprintf( stdout, "\tShifts: %12.1f\n", inst_cnt_wc[i] ); - break; - case _BRANCH: - fprintf( stdout, "\tBranches: %12.1f\n", inst_cnt_wc[i] ); - break; - case _DIV: - fprintf( stdout, "\tDivisions: %12.1f\n", inst_cnt_wc[i] ); - break; - case _SQRT: - fprintf( stdout, "\tSquare Root: %12.1f\n", inst_cnt_wc[i] ); - break; - case _TRANS: - fprintf( stdout, "\tTrans: %12.1f\n", inst_cnt_wc[i] ); - break; - case _FUNC: - fprintf( stdout, "\tFunc Call: %12.1f\n", inst_cnt_wc[i] ); - break; - case _LOOP: - fprintf( stdout, "\tLoop Init: %12.1f\n", inst_cnt_wc[i] ); - break; - case _INDIRECT: - fprintf( stdout, "\tIndirect Addr: %12.1f\n", inst_cnt_wc[i] ); - break; - case _PTR_INIT: - fprintf( stdout, "\tPointer Init: %12.1f\n", inst_cnt_wc[i] ); - break; - case _TEST: - fprintf( stdout, "\tExtra condit.: %12.1f\n", inst_cnt_wc[i] ); - break; - case _POWER: - fprintf( stdout, "\tExponential: %12.1f\n", inst_cnt_wc[i] ); - break; - case _LOG: - fprintf( stdout, "\tLogarithm: %12.1f\n", inst_cnt_wc[i] ); - break; - case _MISC: - fprintf( stdout, "\tAll other op.: %12.1f\n", inst_cnt_wc[i] ); - break; - default: - fprintf( stdout, "\tERROR: Invalid instruction type: %d\n\n", i ); - } - } -#endif +//#ifdef WMOPS_WC_FRAME_ANALYSIS +// int j; +// char *sfmtt = "%20s %4s %15s\n"; +// char *dfmtt = "%20s %4d "; +//#endif + +// /* calculate maximum label length for compact prinout */ +// max_label_len = 0; +// for ( i = 0; i < num_wmops_records; i++ ) +// { +// label_len = strlen( wmops[i].label ); +// if ( label_len > max_label_len ) +// { +// max_label_len = label_len; +// } +// } +// max_label_len += 4; +// +// fprintf( stdout, "\n\n --- Complexity analysis [WMOPS] --- \n\n" ); +// +// fprintf( stdout, "%*s %33s %23s\n", max_label_len, "", "|------ SELF ------|", "|--- CUMULATIVE ---|" ); +// fprintf( stdout, sfmt, max_label_len, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg " ); +// fprintf( stdout, sfmt, max_label_len, "---------------", "------", "------", "------", "------", "------", "------", "------" ); +// +// for ( i = 0; i < num_wmops_records; i++ ) +// { +// fprintf( stdout, dfmt, max_label_len, wmops[i].label, update_cnt == 0 ? 0 : (float) wmops[i].call_number / update_cnt, +// wmops[i].min_selfcnt == DOUBLE_MAX ? 0 : FAC * wmops[i].min_selfcnt, +// FAC * wmops[i].max_selfcnt, +// wmops[i].update_cnt == 0 ? 0 : FAC * wmops[i].tot_selfcnt / wmops[i].update_cnt, +// wmops[i].min_cnt == DOUBLE_MAX ? 0 : FAC * wmops[i].min_cnt, +// FAC * wmops[i].max_cnt, +// wmops[i].update_cnt == 0 ? 0 : FAC * wmops[i].tot_cnt / wmops[i].update_cnt ); +// } +// +// fprintf( stdout, sfmts, max_label_len, "---------------", "------", "------", "------", "------" ); +// fprintf( stdout, dfmts, max_label_len, "total", (float) update_cnt, update_cnt == 0 ? 0 : FAC * min_cnt, FAC * max_cnt, update_cnt == 0 ? 0 : FAC * ops_cnt_wmc / update_cnt ); +// fprintf( stdout, "\n" ); +// +//#ifdef WMOPS_WC_FRAME_ANALYSIS +// fprintf( stdout, "\nComplexity analysis for the worst-case frame %ld:\n\n", fnum_cnt_wc ); +// fprintf( stdout, "%*s %8s %10s %12s\n", max_label_len, " routine", " calls", " SELF", " CUMULATIVE" ); +// fprintf( stdout, "%*s %8s %10s %10s\n", max_label_len, "---------------", "------", "------", "----------" ); +// +// for ( i = 0; i < num_wmops_records; i++ ) +// { +// if ( wmops[i].wc_call_number > 0 ) +// { +// fprintf( stdout, "%*s %8d %10.3f %12.3f\n", max_label_len, wmops[i].label, wmops[i].wc_call_number, FAC * wmops[i].wc_selfcnt, FAC * wmops[i].wc_cnt ); +// } +// } +// +// fprintf( stdout, "\nCall tree for the worst-case frame %ld:\n\n", fnum_cnt_wc ); +// fprintf( stdout, sfmtt, " function", "num", "called by " ); +// fprintf( stdout, sfmtt, "---------------", "---", "--------------" ); +// +// for ( i = 0; i < num_wmops_records; i++ ) +// { +// if ( wmops[i].wc_call_number > 0 ) +// { +// fprintf( stdout, dfmtt, wmops[i].label, i ); +// for ( j = 0; wmops[i].call_tree[j] != -1 && j < MAX_CALL_TREE_DEPTH; j++ ) +// { +// if ( j != 0 ) +// { +// fprintf( stdout, ", " ); +// } +// fprintf( stdout, "%d", wmops[i].call_tree[j] ); +// } +// fprintf( stdout, "\n" ); +// } +// } +// +// fprintf( stdout, "\n\n" ); +// +// fprintf( stdout, "\nInstruction type analysis for the worst-case frame %ld:\n\n", fnum_cnt_wc ); +// for ( i = 0; i < NUM_INST; i++ ) +// { +// switch ( (enum instructions) i ) +// { +// case _ADD: +// fprintf( stdout, "\tAdds: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _ABS: +// fprintf( stdout, "\tAbsolutes: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _MULT: +// fprintf( stdout, "\tMultiplies: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _MAC: +// fprintf( stdout, "\tMACs: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _MOVE: +// fprintf( stdout, "\tMoves: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _STORE: +// fprintf( stdout, "\tStores: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _LOGIC: +// fprintf( stdout, "\tLogicals: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _SHIFT: +// fprintf( stdout, "\tShifts: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _BRANCH: +// fprintf( stdout, "\tBranches: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _DIV: +// fprintf( stdout, "\tDivisions: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _SQRT: +// fprintf( stdout, "\tSquare Root: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _TRANS: +// fprintf( stdout, "\tTrans: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _FUNC: +// fprintf( stdout, "\tFunc Call: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _LOOP: +// fprintf( stdout, "\tLoop Init: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _INDIRECT: +// fprintf( stdout, "\tIndirect Addr: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _PTR_INIT: +// fprintf( stdout, "\tPointer Init: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _TEST: +// fprintf( stdout, "\tExtra condit.: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _POWER: +// fprintf( stdout, "\tExponential: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _LOG: +// fprintf( stdout, "\tLogarithm: %12.1f\n", inst_cnt_wc[i] ); +// break; +// case _MISC: +// fprintf( stdout, "\tAll other op.: %12.1f\n", inst_cnt_wc[i] ); +// break; +// default: +// fprintf( stdout, "\tERROR: Invalid instruction type: %d\n\n", i ); +// } +// } +//#endif +// +// /* De-allocate the list of wmops record */ +// if ( wmops != NULL ) +// { +// free( wmops ); +// } +// +// /* De-allocate the list of wmops caller functions */ +// if ( wmops_caller_stack != NULL ) +// { +// free( wmops_caller_stack ); +// } +// +// /* De-allocate the BASOP WMOPS counter */ +// //if ( multiCounter != NULL ) +// //{ +// // free( multiCounter ); +// //} return; } - /*-------------------------------------------------------------------* * Memory counting tool measuring RAM usage (stack and heap) * @@ -523,11 +688,6 @@ void print_wmops( void ) * #define WMC_TOOL_SKIP ... #undef WMC_TOOL_SKIP macro pair around the malloc(), calloc() and free(). *--------------------------------------------------------------------*/ -#define MAX_RECORDABLE_CALLS 100 -#define MAX_FUNCTION_NAME_LENGTH 35 /* Maximum length that the function string will be truncated to */ -#define MAX_PARAMS_LENGTH 50 /* Maximum length that the parameter string will be truncated to */ -#define MAX_NUM_RECORDS 300 /* Initial maximum number of memory records -> mightb be increased during runtime, if needed */ -#define MAX_NUM_RECORDS_REALLOC_STEP 50 /* When re-allocating the list of memory records, increase the number of records by this number */ /* This is the value (in bytes) towards which the block size is rounded. For example, a block of 123 bytes, when using a 32 bits system, will end up taking 124 bytes since the last unused byte cannot be used for another block. */ @@ -558,7 +718,14 @@ typedef struct int16_t *stack_ptr; } caller_info; -caller_info stack_callers[2][MAX_RECORDABLE_CALLS]; +static caller_info *stack_callers[2] = { NULL, NULL }; + +static int16_t *ptr_base_stack = 0; /* Pointer to the bottom of stack (base pointer). Stack grows up. */ +static int16_t *ptr_current_stack = 0; /* Pointer to the current stack pointer */ +static int16_t *ptr_max_stack = 0; /* Pointer to the maximum stack pointer (the farest point from the bottom of stack) */ +static int32_t wc_stack_frame = 0; /* Frame corresponding to the worst-case stack usage */ +static int current_calls = 0, max_num_calls = MAX_NUM_RECORDS; +static char location_max_stack[256] = "undefined"; typedef struct { @@ -579,18 +746,12 @@ typedef struct allocator_record *allocation_list = NULL; -static int16_t *ptr_base_stack = 0; /* Pointer to the bottom of stack (base pointer). Stack grows up. */ -static int16_t *ptr_current_stack = 0; /* Pointer to the current stack pointer */ -static int16_t *ptr_max_stack = 0; /* Pointer to the maximum stack pointer (the farest point from the bottom of stack) */ -static int32_t wc_stack_frame = 0; /* Frame corresponding to the worst-case stack usage */ -static int32_t wc_ram_size, wc_ram_frame; -static int32_t current_heap_size; -static int current_calls = 0; -static char location_max_stack[256] = "undefined"; static int Num_Records, Max_Num_Records; static size_t Stat_Cnt_Size = USE_BYTES; -static const char *Count_Unit[] = { "bytes", "words", "words" }; +static const char *Count_Unit[] = { "bytes", "words", "words", "words" }; +static int32_t wc_ram_size, wc_ram_frame; +static int32_t current_heap_size; static int *list_wc_intra_frame_heap, n_items_wc_intra_frame_heap, max_items_wc_intra_frame_heap, size_wc_intra_frame_heap, location_wc_intra_frame_heap; static int *list_current_inter_frame_heap, n_items_current_inter_frame_heap, max_items_current_inter_frame_heap, size_current_inter_frame_heap; static int *list_wc_inter_frame_heap, n_items_wc_inter_frame_heap, max_items_wc_inter_frame_heap, size_wc_inter_frame_heap, location_wc_inter_frame_heap; @@ -611,11 +772,28 @@ void reset_mem( Counting_Size cnt_size ) int16_t something; size_t tmp_size; + /* initialize list of stack records */ + if ( stack_callers[0] == NULL ) + { + stack_callers[0] = malloc( MAX_NUM_RECORDS * sizeof( caller_info ) ); + stack_callers[1] = malloc( MAX_NUM_RECORDS * sizeof( caller_info ) ); + } + + if ( stack_callers[0] == NULL || stack_callers[1] == NULL ) + { + fprintf( stderr, "Error: Unable to Allocate List of Stack Records!" ); + exit( -1 ); + } + + current_calls = 0; + max_num_calls = MAX_NUM_RECORDS; + /* initialize stack pointers */ ptr_base_stack = &something; ptr_max_stack = ptr_base_stack; ptr_current_stack = ptr_base_stack; + /* initialize the unit of memory block size */ Stat_Cnt_Size = cnt_size; /* Check, if sizeof(int32_t) is 4 bytes */ @@ -741,11 +919,12 @@ int push_stack( const char *filename, const char *fctname ) (void) *filename; /* to avoid compilation warning */ - /* Is there room to save the caller's information? */ - if ( current_calls >= MAX_RECORDABLE_CALLS ) - { /* No */ - fprintf( stderr, "No more room to store call stack info. Please increase MAX_RECORDABLE_CALLS" ); - exit( -1 ); + if ( current_calls >= max_num_calls ) + { + /* There is no room for a new record -> reallocate the list */ + max_num_calls += MAX_NUM_RECORDS_REALLOC_STEP; + stack_callers[0] = realloc( stack_callers[0], max_num_calls * sizeof( caller_info ) ); + stack_callers[1] = realloc( stack_callers[1], max_num_calls * sizeof( caller_info ) ); } /* Valid Function Name? */ @@ -762,7 +941,7 @@ int push_stack( const char *filename, const char *fctname ) /* Save the Stack Pointer */ stack_callers[0][current_calls].stack_ptr = ptr_current_stack; - /* Increase Stack Calling Tree Level */ + /* Increase the Number of Calls in the List */ current_calls++; /* Is this the First Time or the Worst Case? */ @@ -771,22 +950,24 @@ int push_stack( const char *filename, const char *fctname ) /* Save Info about it */ ptr_max_stack = ptr_current_stack; - wc_stack_frame = update_cnt; /* current frame number is stored in the variable update_cnt and updated in the function update_wmops() */ + /* save the worst-case frame number */ + /* current frame number is stored in the variable update_cnt and updated in the function update_wmops() */ + wc_stack_frame = update_cnt; strncpy( location_max_stack, fctname, sizeof( location_max_stack ) - 1 ); location_max_stack[sizeof( location_max_stack ) - 1] = '\0'; /* Save Call Tree */ memmove( stack_callers[1], stack_callers[0], sizeof( caller_info ) * current_calls ); - /* Terminate the List (Unless Full) */ - if ( current_calls < MAX_RECORDABLE_CALLS ) + /* Terminate the List with 0 (for printing purposes) */ + if ( current_calls < max_num_calls ) { stack_callers[1][current_calls].function_name[0] = 0; } } /* Check, if This is the New Worst-Case RAM (stack + heap) */ - current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); + current_stack_size = ( int32_t )( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); if ( current_stack_size < 0 ) { @@ -815,13 +996,13 @@ int pop_stack( const char *filename, const char *fctname ) (void) *filename; /* to avoid compilation warning */ - /* Decrease Stack Calling */ + /* Decrease the Number of Records */ current_calls--; /* Get Pointer to Caller Information */ caller_info_ptr = &stack_callers[0][current_calls]; - /* Check, if Names Match */ + /* Check, if the Function Names Match */ if ( strncmp( caller_info_ptr->function_name, fctname, MAX_FUNCTION_NAME_LENGTH ) != 0 ) { fprintf( stderr, "Invalid usage of pop_stack()" ); @@ -860,7 +1041,7 @@ static void print_stack_call_tree( void ) fprintf( stdout, "\nList of functions when maximum stack size is reached:\n\n" ); caller_info_ptr = &stack_callers[1][0]; - for ( call_level = 0; call_level < MAX_RECORDABLE_CALLS; call_level++ ) + for ( call_level = 0; call_level < max_num_calls; call_level++ ) { /* Done? */ if ( caller_info_ptr->function_name[0] == 0 ) @@ -979,7 +1160,7 @@ void *mem_alloc( #ifdef MEM_COUNT_DETAILS /* Export heap memory allocation record to the .csv file */ - fprintf( fid_csv_filename, "A,%d,%s,%d,%d\n", update_cnt, ptr_record->name, ptr_record->lineno, ptr_record->block_size ); + fprintf( fid_csv_filename, "A,%ld,%s,%d,%d\n", update_cnt, ptr_record->name, ptr_record->lineno, ptr_record->block_size ); #endif if ( ptr_record->frame_allocated != -1 ) @@ -994,7 +1175,7 @@ void *mem_alloc( current_heap_size += ptr_record->block_size; /* Check, if this is the new Worst-Case RAM (stack + heap) */ - current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); + current_stack_size = ( int32_t )( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) ); if ( current_stack_size + current_heap_size > wc_ram_size ) { wc_ram_size = current_stack_size + current_heap_size; @@ -1059,7 +1240,7 @@ static void *mem_alloc_block( size_t size, const char *size_str ) /* Fill Memory Block with Magic Value or 0 */ fill_value = MAGIC_VALUE_USED; - if ( IS_CALLOC( size_str ) ) + if ( size_str[0] == 'c' ) { fill_value = 0x00000000; } @@ -1277,8 +1458,8 @@ allocator_record *get_mem_record( unsigned long *hash, const char *func_name, in /*-------------------------------------------------------------------* * mem_free() * - * This function de-allocatesd the memory block and frees the mphysical memory with free(). - * It also updates actual and average usage of the memory block. + * This function de-allocates memory blocks and frees physical memory with free(). + * It also updates the actual and average usage of memory blocks. * * Note: The record is not removed from the list and may be reused later on in mem_alloc()! *--------------------------------------------------------------------*/ @@ -1319,7 +1500,7 @@ void mem_free( const char *func_name, int func_lineno, void *ptr ) #ifdef MEM_COUNT_DETAILS /* Export heap memory de-allocation record to the .csv file */ - fprintf( fid_csv_filename, "D,%d,%s,%d,%d\n", update_cnt, ptr_record->name, ptr_record->lineno, ptr_record->block_size ); + fprintf( fid_csv_filename, "D,%ld,%s,%d,%d\n", update_cnt, ptr_record->name, ptr_record->lineno, ptr_record->block_size ); #endif /* De-Allocate Memory Block */ @@ -1579,7 +1760,7 @@ static void mem_count_summary( void ) allocator_record *ptr_record, *ptr; /* Prepare format string */ - sprintf( format_str, "%%-%ds %%5s %%6s %%-%ds %%20s %%6s ", MAX_FUNCTION_NAME_LENGTH, MAX_PARAMS_LENGTH ); + sprintf( format_str, "%%-%d.%ds %%5.5s %%6.6s %%-%d.%ds %%20.20s %%6.6s ", 50, 50, 50, 50 ); if ( n_items_wc_intra_frame_heap > 0 ) { @@ -1780,7 +1961,16 @@ void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] ) for ( i = 0; i < nElem; i++ ) { - fprintf( stdout, "Program ROM size (%s): %d instruction words\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].PROM_size ); + if ( Stat_Cnt_Size > 0 ) + { + /* words */ + fprintf( stdout, "Program ROM size (%s): %d words\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].PROM_size ); + } + else + { + /* bytes (here, we assume that each instruction takes PROM_INST_SIZE bits of the PROM memory) */ + fprintf( stdout, "Program ROM size (%s): %d bytes\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].PROM_size * ( PROM_INST_SIZE / 8 ) ); + } } for ( i = 0; i < nElem; i++ ) @@ -1871,9 +2061,15 @@ void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] ) if ( Stat_Cnt_Size > 0 ) { - fprintf( stdout, "\nNote: 1 word = %d bits\n", 8 << Stat_Cnt_Size ); - fprintf( stdout, "This is an optimistic estimate of memory consumption assuming that each variable type is stored with sizeof(type) bits\n" ); + /* words */ + fprintf( stdout, "\nNote: The Program ROM size is calculated under the assumption that 1 instruction word is stored with %d bits\n", 8 << Stat_Cnt_Size ); } + else + { + /* bytes */ + fprintf( stdout, "\nNote: The Program ROM size is calculated under the assumption that 1 instruction word is stored with %d bits\n", PROM_INST_SIZE ); + } + fprintf( stdout, "Note: The Data ROM size is calculated using the sizeof(type) built-in function\n" ); if ( n_items_wc_intra_frame_heap > 0 ) { @@ -1886,6 +2082,17 @@ void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] ) free( allocation_list ); } + /* De-allocate list of stack records */ + if ( stack_callers[0] != NULL ) + { + free( stack_callers[0] ); + } + + if ( stack_callers[1] != NULL ) + { + free( stack_callers[1] ); + } + /* De-allocate heap allocation call tree */ if ( heap_allocation_call_tree != NULL ) { @@ -1920,7 +2127,7 @@ void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] ) #endif /* WMOPS */ -#ifndef WMOPS_FLT + +#ifndef WMOPS int cntr_push_pop = 0; /* global counter for checking balanced push_wmops()/pop_wmops() pairs when WMOPS is not activated */ -double ops_cnt; #endif diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 7d07a84a0e9383331f20e5181a548fca927d798f..5f5d6d9753f98612762f47dca560f63c7b22ddd6 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -23,21 +23,17 @@ #include /* stdio is needed for fprintf() */ #endif +#include "options.h" /* To Prevent "warning: '$' in identifier or number" message under GCC */ #ifdef __GNUC__ #pragma GCC system_header #endif -/* Real-time relationships */ #define FRAMES_PER_SECOND 50.0 -#define MILLION_CYCLES 1e6 -#define WMOPS_BOOST_FAC ( 1.0f ) /* scaling factor for equalizing the difference between automatic and manual instrumentation */ -#define FAC ( FRAMES_PER_SECOND / MILLION_CYCLES * WMOPS_BOOST_FAC ) -#define NUM_INST 20 /* Total number of instruction types (in enum below) */ +#define PROM_INST_SIZE 32 /* number of bits of each program instruction when stored in the PROM memory (applied only when the user selects reporting in bytes) */ - -#ifdef WMOPS_FLT +#ifdef WMOPS enum instructions { _ADD, @@ -59,7 +55,8 @@ enum instructions _TEST, _POWER, _LOG, - _MISC + _MISC, + NUM_INST }; #define _ADD_C 1 @@ -107,14 +104,14 @@ enum instructions #define ADD( x ) \ { \ { \ - ops_cnt += ( _ADD_C * ( x ) ); \ + ops_cnt_wmc += ( _ADD_C * ( x ) ); \ inst_cnt[_ADD] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _ADD_P * ( x ) ); \ + prom_cnt_wmc += ( _ADD_P * ( x ) ); \ } \ } \ } \ @@ -122,14 +119,14 @@ enum instructions #define ABS( x ) \ { \ { \ - ops_cnt += ( _ABS_C * ( x ) ); \ + ops_cnt_wmc += ( _ABS_C * ( x ) ); \ inst_cnt[_ABS] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _ABS_P * ( x ) ); \ + prom_cnt_wmc += ( _ABS_P * ( x ) ); \ } \ } \ } \ @@ -137,14 +134,14 @@ enum instructions #define MULT( x ) \ { \ { \ - ops_cnt += ( _MULT_C * ( x ) ); \ + ops_cnt_wmc += ( _MULT_C * ( x ) ); \ inst_cnt[_MULT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MULT_P * ( x ) ); \ + prom_cnt_wmc += ( _MULT_P * ( x ) ); \ } \ } \ } \ @@ -152,14 +149,14 @@ enum instructions #define MAC( x ) \ { \ { \ - ops_cnt += ( _MAC_C * ( x ) ); \ + ops_cnt_wmc += ( _MAC_C * ( x ) ); \ inst_cnt[_MAC] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MAC_P * ( x ) ); \ + prom_cnt_wmc += ( _MAC_P * ( x ) ); \ } \ } \ } \ @@ -167,14 +164,14 @@ enum instructions #define MOVE( x ) \ { \ { \ - ops_cnt += ( _MOVE_C * ( x ) ); \ + ops_cnt_wmc += ( _MOVE_C * ( x ) ); \ inst_cnt[_MOVE] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MOVE_P * ( x ) ); \ + prom_cnt_wmc += ( _MOVE_P * ( x ) ); \ } \ } \ } \ @@ -182,14 +179,14 @@ enum instructions #define STORE( x ) \ { \ { \ - ops_cnt += ( _STORE_C * ( x ) ); \ + ops_cnt_wmc += ( _STORE_C * ( x ) ); \ inst_cnt[_STORE] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _STORE_P * ( x ) ); \ + prom_cnt_wmc += ( _STORE_P * ( x ) ); \ } \ } \ } \ @@ -197,14 +194,14 @@ enum instructions #define LOGIC( x ) \ { \ { \ - ops_cnt += ( _LOGIC_C * ( x ) ); \ + ops_cnt_wmc += ( _LOGIC_C * ( x ) ); \ inst_cnt[_LOGIC] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _LOGIC_P * ( x ) ); \ + prom_cnt_wmc += ( _LOGIC_P * ( x ) ); \ } \ } \ } \ @@ -212,14 +209,14 @@ enum instructions #define SHIFT( x ) \ { \ { \ - ops_cnt += ( _SHIFT_C * ( x ) ); \ + ops_cnt_wmc += ( _SHIFT_C * ( x ) ); \ inst_cnt[_SHIFT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _SHIFT_P * ( x ) ); \ + prom_cnt_wmc += ( _SHIFT_P * ( x ) ); \ } \ } \ } \ @@ -227,14 +224,14 @@ enum instructions #define BRANCH( x ) \ { \ { \ - ops_cnt += ( _BRANCH_C * ( x ) ); \ + ops_cnt_wmc += ( _BRANCH_C * ( x ) ); \ inst_cnt[_BRANCH] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _BRANCH_P * ( x ) ); \ + prom_cnt_wmc += ( _BRANCH_P * ( x ) ); \ } \ } \ } \ @@ -242,14 +239,14 @@ enum instructions #define DIV( x ) \ { \ { \ - ops_cnt += ( _DIV_C * ( x ) ); \ + ops_cnt_wmc += ( _DIV_C * ( x ) ); \ inst_cnt[_DIV] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _DIV_P * ( x ) ); \ + prom_cnt_wmc += ( _DIV_P * ( x ) ); \ } \ } \ } \ @@ -257,14 +254,14 @@ enum instructions #define SQRT( x ) \ { \ { \ - ops_cnt += ( _SQRT_C * ( x ) ); \ + ops_cnt_wmc += ( _SQRT_C * ( x ) ); \ inst_cnt[_SQRT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _SQRT_P * ( x ) ); \ + prom_cnt_wmc += ( _SQRT_P * ( x ) ); \ } \ } \ } \ @@ -272,14 +269,14 @@ enum instructions #define TRANS( x ) \ { \ { \ - ops_cnt += ( _TRANS_C * ( x ) ); \ + ops_cnt_wmc += ( _TRANS_C * ( x ) ); \ inst_cnt[_TRANS] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _TRANS_P * ( x ) ); \ + prom_cnt_wmc += ( _TRANS_P * ( x ) ); \ } \ } \ } \ @@ -287,14 +284,14 @@ enum instructions #define LOOP( x ) \ { \ { \ - ops_cnt += ( _LOOP_C * ( x ) ); \ + ops_cnt_wmc += ( _LOOP_C * ( x ) ); \ inst_cnt[_LOOP] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _LOOP_P * ( x ) ); \ + prom_cnt_wmc += ( _LOOP_P * ( x ) ); \ } \ } \ } \ @@ -302,14 +299,14 @@ enum instructions #define INDIRECT( x ) \ { \ { \ - ops_cnt += ( _INDIRECT_C * ( x ) ); \ + ops_cnt_wmc += ( _INDIRECT_C * ( x ) ); \ inst_cnt[_INDIRECT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _INDIRECT_P * ( x ) ); \ + prom_cnt_wmc += ( _INDIRECT_P * ( x ) ); \ } \ } \ } \ @@ -317,14 +314,14 @@ enum instructions #define PTR_INIT( x ) \ { \ { \ - ops_cnt += ( _PTR_INIT_C * ( x ) ); \ + ops_cnt_wmc += ( _PTR_INIT_C * ( x ) ); \ inst_cnt[_PTR_INIT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _PTR_INIT_P * ( x ) ); \ + prom_cnt_wmc += ( _PTR_INIT_P * ( x ) ); \ } \ } \ } \ @@ -332,14 +329,14 @@ enum instructions #define TEST( x ) \ { \ { \ - ops_cnt += ( _TEST_C * ( x ) ); \ + ops_cnt_wmc += ( _TEST_C * ( x ) ); \ inst_cnt[_TEST] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _TEST_P * ( x ) ); \ + prom_cnt_wmc += ( _TEST_P * ( x ) ); \ } \ } \ } \ @@ -347,14 +344,14 @@ enum instructions #define POWER( x ) \ { \ { \ - ops_cnt += ( _POWER_C * ( x ) ); \ + ops_cnt_wmc += ( _POWER_C * ( x ) ); \ inst_cnt[_POWER] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _POWER_P * ( x ) ); \ + prom_cnt_wmc += ( _POWER_P * ( x ) ); \ } \ } \ } \ @@ -362,14 +359,14 @@ enum instructions #define LOG( x ) \ { \ { \ - ops_cnt += ( _LOG_C * ( x ) ); \ + ops_cnt_wmc += ( _LOG_C * ( x ) ); \ inst_cnt[_LOG] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _LOG_P * ( x ) ); \ + prom_cnt_wmc += ( _LOG_P * ( x ) ); \ } \ } \ } \ @@ -377,14 +374,14 @@ enum instructions #define MISC( x ) \ { \ { \ - ops_cnt += ( _MISC_C * ( x ) ); \ + ops_cnt_wmc += ( _MISC_C * ( x ) ); \ inst_cnt[_MISC] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MISC_P * ( x ) ); \ + prom_cnt_wmc += ( _MISC_P * ( x ) ); \ } \ } \ } \ @@ -393,7 +390,7 @@ enum instructions #define FUNC( x ) \ { \ { \ - ops_cnt += ( _FUNC_C + _MOVE_C * ( x ) ); \ + ops_cnt_wmc += ( _FUNC_C + _MOVE_C * ( x ) ); \ inst_cnt[_FUNC]++; \ inst_cnt[_MOVE] += ( x ); \ { \ @@ -401,7 +398,7 @@ enum instructions if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _FUNC_P + _MOVE_P * ( x ) ); \ + prom_cnt_wmc += ( _FUNC_P + _MOVE_P * ( x ) ); \ } \ } \ } \ @@ -410,14 +407,14 @@ enum instructions #define DADD( x ) \ { \ { \ - ops_cnt += ( 2 * _ADD_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _ADD_C * ( x ) ); \ inst_cnt[_ADD] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _ADD_P * ( x ) ); \ + prom_cnt_wmc += ( _ADD_P * ( x ) ); \ } \ } \ } \ @@ -425,14 +422,14 @@ enum instructions #define DMULT( x ) \ { \ { \ - ops_cnt += ( 2 * _MULT_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _MULT_C * ( x ) ); \ inst_cnt[_MULT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MULT_P * ( x ) ); \ + prom_cnt_wmc += ( _MULT_P * ( x ) ); \ } \ } \ } \ @@ -440,14 +437,14 @@ enum instructions #define DMAC( x ) \ { \ { \ - ops_cnt += ( 2 * _MAC_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _MAC_C * ( x ) ); \ inst_cnt[_MAC] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MAC_P * ( x ) ); \ + prom_cnt_wmc += ( _MAC_P * ( x ) ); \ } \ } \ } \ @@ -455,14 +452,14 @@ enum instructions #define DMOVE( x ) \ { \ { \ - ops_cnt += ( 2 * _MOVE_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _MOVE_C * ( x ) ); \ inst_cnt[_MOVE] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _MOVE_P * ( x ) ); \ + prom_cnt_wmc += ( _MOVE_P * ( x ) ); \ } \ } \ } \ @@ -470,14 +467,14 @@ enum instructions #define DSTORE( x ) \ { \ { \ - ops_cnt += ( 2 * _STORE_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _STORE_C * ( x ) ); \ inst_cnt[_STORE] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _STORE_P * ( x ) ); \ + prom_cnt_wmc += ( _STORE_P * ( x ) ); \ } \ } \ } \ @@ -485,14 +482,14 @@ enum instructions #define DLOGIC( x ) \ { \ { \ - ops_cnt += ( 2 * _LOGIC_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _LOGIC_C * ( x ) ); \ inst_cnt[_LOGIC] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _LOGIC_P * ( x ) ); \ + prom_cnt_wmc += ( _LOGIC_P * ( x ) ); \ } \ } \ } \ @@ -500,14 +497,14 @@ enum instructions #define DSHIFT( x ) \ { \ { \ - ops_cnt += ( 2 * _SHIFT_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _SHIFT_C * ( x ) ); \ inst_cnt[_SHIFT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _SHIFT_P * ( x ) ); \ + prom_cnt_wmc += ( _SHIFT_P * ( x ) ); \ } \ } \ } \ @@ -515,14 +512,14 @@ enum instructions #define DDIV( x ) \ { \ { \ - ops_cnt += ( 2 * _DIV_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _DIV_C * ( x ) ); \ inst_cnt[_DIV] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _DIV_P * ( x ) ); \ + prom_cnt_wmc += ( _DIV_P * ( x ) ); \ } \ } \ } \ @@ -530,14 +527,14 @@ enum instructions #define DSQRT( x ) \ { \ { \ - ops_cnt += ( 2 * _SQRT_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _SQRT_C * ( x ) ); \ inst_cnt[_SQRT] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _SQRT_P * ( x ) ); \ + prom_cnt_wmc += ( _SQRT_P * ( x ) ); \ } \ } \ } \ @@ -545,42 +542,40 @@ enum instructions #define DTRANS( x ) \ { \ { \ - ops_cnt += ( 2 * _TRANS_C * ( x ) ); \ + ops_cnt_wmc += ( 2 * _TRANS_C * ( x ) ); \ inst_cnt[_TRANS] += ( x ); \ { \ static int pcnt; \ if ( !pcnt ) \ { \ pcnt = 1; \ - prom_cnt += ( _TRANS_P * ( x ) ); \ + prom_cnt_wmc += ( _TRANS_P * ( x ) ); \ } \ } \ } \ } -extern double ops_cnt; -extern double prom_cnt; +extern double ops_cnt_wmc; +extern double prom_cnt_wmc; extern double inst_cnt[NUM_INST]; -extern int ops_cnt_activ; -void reset_wmops( void ); -void push_wmops( const char *label ); +#define push_wmops( ... ) push_wmops_fct( __VA_ARGS__, NULL ) +void push_wmops_fct( const char *label, ... ); void pop_wmops( void ); +void reset_wmops( void ); +void print_wmops( void ); void update_wmops( void ); void update_mem( void ); -void print_wmops( void ); -#else /* WMOPS_FL counting disabled */ -#if 0 /* -> defined in count.h instead */ -#include -#define reset_wmops() +#else + extern int cntr_push_pop; #define push_wmops( x ) ( cntr_push_pop++ ) #define pop_wmops() ( cntr_push_pop-- ) -#define update_wmops() ( assert( cntr_push_pop == 0 ) ) -#define update_mem() +#define reset_wmops() #define print_wmops() -#endif +#define update_wmops() ( assert( cntr_push_pop == 0 ) ) +#define update_mem() #define ADD( x ) #define ABS( x ) @@ -620,11 +615,11 @@ extern int cntr_push_pop; #ifndef mac #define mac( a, b, c ) ( ( a ) + ( b ) * ( c ) ) #endif -#ifndef mac +#ifndef msu #define msu( a, b, c ) ( ( a ) - ( b ) * ( c ) ) #endif -#ifndef WMOPS_FLT +#ifndef WMOPS /* DESACTIVATE the Counting Mechanism */ #define OP_COUNT_( op, n ) @@ -639,8 +634,8 @@ extern int cntr_push_pop; #else -/* '*ops_cnt_ptr' is Used to Avoid: "warning: operation on 'ops_cnt' may be undefined" with Cygwin gcc Compiler */ -static double *ops_cnt_ptr = &ops_cnt; +/* '*ops_cnt_ptr' is Used to Avoid: "warning: operation on 'ops_cnt_wmc' may be undefined" with Cygwin gcc Compiler */ +static double *ops_cnt_ptr = &ops_cnt_wmc; #define OP_COUNT_( op, x ) ( *ops_cnt_ptr += ( op##_C * ( x ) ), inst_cnt[op] += ( x ) ) /******************************************************************/ @@ -671,84 +666,99 @@ static int wmc_flag_ = 0; #endif /* Define all Macros without '{' & '}' (None of these should be called externally!) */ -#define ABS_( x ) OP_COUNT_( _ABS, ( x ) / WMOPS_BOOST_FAC ) -#define ADD_( x ) OP_COUNT_( _ADD, ( x ) / WMOPS_BOOST_FAC ) -#define MULT_( x ) OP_COUNT_( _MULT, ( x ) / WMOPS_BOOST_FAC ) -#define MAC_( x ) OP_COUNT_( _MAC, ( x ) / WMOPS_BOOST_FAC ) -#define MOVE_( x ) OP_COUNT_( _MOVE, ( x ) / WMOPS_BOOST_FAC ) -#define STORE_( x ) OP_COUNT_( _STORE, ( x ) / WMOPS_BOOST_FAC ) -#define LOGIC_( x ) OP_COUNT_( _LOGIC, ( x ) / WMOPS_BOOST_FAC ) -#define SHIFT_( x ) OP_COUNT_( _SHIFT, ( x ) / WMOPS_BOOST_FAC ) -#define BRANCH_( x ) OP_COUNT_( _BRANCH, ( x ) / WMOPS_BOOST_FAC ) -#define DIV_( x ) OP_COUNT_( _DIV, ( x ) / WMOPS_BOOST_FAC ) -#define SQRT_( x ) OP_COUNT_( _SQRT, ( x ) / WMOPS_BOOST_FAC ) -#define TRANS_( x ) OP_COUNT_( _TRANS, ( x ) / WMOPS_BOOST_FAC ) +#define ABS_( x ) OP_COUNT_( _ABS, ( x ) ) +#define ADD_( x ) OP_COUNT_( _ADD, ( x ) ) +#define MULT_( x ) OP_COUNT_( _MULT, ( x ) ) +#define MAC_( x ) OP_COUNT_( _MAC, ( x ) ) +#define MOVE_( x ) OP_COUNT_( _MOVE, ( x ) ) +#define STORE_( x ) OP_COUNT_( _STORE, ( x ) ) +#define LOGIC_( x ) OP_COUNT_( _LOGIC, ( x ) ) +#define SHIFT_( x ) OP_COUNT_( _SHIFT, ( x ) ) +#define BRANCH_( x ) OP_COUNT_( _BRANCH, ( x ) ) +#define DIV_( x ) OP_COUNT_( _DIV, ( x ) ) +#define SQRT_( x ) OP_COUNT_( _SQRT, ( x ) ) +#define TRANS_( x ) OP_COUNT_( _TRANS, ( x ) ) #define POWER_( x ) TRANS_( x ) #define LOG_( x ) TRANS_( x ) -#define LOOP_( x ) OP_COUNT_( _LOOP, ( x ) / WMOPS_BOOST_FAC ) -#define INDIRECT_( x ) OP_COUNT_( _INDIRECT, ( x ) / WMOPS_BOOST_FAC ) -#define PTR_INIT_( x ) OP_COUNT_( _PTR_INIT, ( x ) / WMOPS_BOOST_FAC ) -#define FUNC_( x ) ( OP_COUNT_( _MOVE, ( x ) / WMOPS_BOOST_FAC ), OP_COUNT_( _FUNC, 1 ) ) +#define LOOP_( x ) OP_COUNT_( _LOOP, ( x ) ) +#define INDIRECT_( x ) OP_COUNT_( _INDIRECT, ( x ) ) +#define PTR_INIT_( x ) OP_COUNT_( _PTR_INIT, ( x ) ) +#define FUNC_( x ) ( OP_COUNT_( _MOVE, ( x ) ), OP_COUNT_( _FUNC, 1 ) ) #define MISC_( x ) ABS_( x ) /* Math Operations */ -#define abs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), abs ) -#define fabs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), fabs ) -#define labs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), labs ) -#define floor_ OP_COUNT_WRAPPER1_( MISC_( 1 ), floor ) -#define sqrt_ OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrt ) -#define pow_ OP_COUNT_WRAPPER1_( POWER_( 1 ), pow ) -#define exp_ OP_COUNT_WRAPPER1_( POWER_( 1 ), exp ) -#define log_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log ) -#define log10_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log10 ) -#define cos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cos ) -#define sin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sin ) -#define tan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tan ) -#define acos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), acos ) -#define asin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), asin ) -#define atan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan ) -#define atan2_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan2 ) -#define cosh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cosh ) -#define sinh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinh ) -#define tanh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanh ) -#define fmod_ OP_COUNT_WRAPPER1_( DIV_( 1 ), fmod ) -/* these macros use any local macros already defined */ -/* min/max and their Variants */ -#define min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), min( ( a ), ( b ) ) ) -#define max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), max( ( a ), ( b ) ) ) -#define MIN_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MIN( ( a ), ( b ) ) ) -#define MAX_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MAX( ( a ), ( b ) ) ) -#define Min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Min( ( a ), ( b ) ) ) -#define Max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Max( ( a ), ( b ) ) ) -/* Square and its Variants */ -#define sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), sqr( ( x ) ) ) -#define Sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Sqr( ( x ) ) ) -#define SQR_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQR( ( x ) ) ) -#define square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), square( ( x ) ) ) -#define Square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Square( ( x ) ) ) -#define SQUARE_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQUARE( ( x ) ) ) -/* Sign and its Variants */ -#define sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), sign( ( x ) ) ) -#define Sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), Sign( ( x ) ) ) -#define SIGN_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), SIGN( ( x ) ) ) -/* Square Root and its Variants */ -#define sqrtf_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrtf( ( x ) ) ) -/* Invert Square Root and its Variants */ -#define inv_sqrt_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), inv_sqrt( ( x ) ) ) -/* Others */ +#define abs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), abs ) +#define fabs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), fabs ) +#define fabsf_ OP_COUNT_WRAPPER1_( ABS_( 1 ), fabsf ) +#define labs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), labs ) +#define floor_ OP_COUNT_WRAPPER1_( MISC_( 1 ), floor ) +#define floorf_ OP_COUNT_WRAPPER1_( MISC_( 1 ), floorf ) +#define sqrt_ OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrt ) +#define sqrtf_ OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrtf ) +#define pow_ OP_COUNT_WRAPPER1_( POWER_( 1 ), pow ) +#define powf_ OP_COUNT_WRAPPER1_( POWER_( 1 ), powf ) +#define exp_ OP_COUNT_WRAPPER1_( POWER_( 1 ), exp ) +#define expf_ OP_COUNT_WRAPPER1_( POWER_( 1 ), expf ) +#define log_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log ) +#define logf_ OP_COUNT_WRAPPER1_( LOG_( 1 ), logf ) +#define log10_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log10 ) +#define log10f_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log10f ) +#define cos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cos ) +#define cosf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cosf ) +#define sin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sin ) +#define sinf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinf ) +#define tan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tan ) +#define tanf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanf ) +#define acos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), acos ) +#define acosf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), acosf ) +#define asin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), asin ) +#define asinf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), asinf ) +#define atan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan ) +#define atanf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atanf ) +#define atan2_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan2 ) +#define atan2f_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan2f ) +#define cosh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cosh ) +#define coshf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), coshf ) +#define sinh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinh ) +#define sinhf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinhf ) +#define tanh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanh ) +#define tanhf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanhf ) +#define fmod_ OP_COUNT_WRAPPER1_( DIV_( 1 ), fmod ) +#define fmodf_ OP_COUNT_WRAPPER1_( DIV_( 1 ), fmodf ) +#define frexp_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexp ) +#define frexpf_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexpf ) + +/* the macros below are instrumented versions of user-defined macros that might be used in the source code + representing some well-known and recognized mathematical operations (that are not defined in math.h) + Note: the 'wmc_flag_=wmc_flag_' is used to avoid warning: left-hand operand of comma expression has no effect with gcc */ + +#define min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), min( ( a ), ( b ) ) ) +#define max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), max( ( a ), ( b ) ) ) +#define MIN_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MIN( ( a ), ( b ) ) ) +#define MAX_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MAX( ( a ), ( b ) ) ) +#define Min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Min( ( a ), ( b ) ) ) +#define Max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Max( ( a ), ( b ) ) ) +#define sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), sqr( ( x ) ) ) +#define Sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Sqr( ( x ) ) ) +#define SQR_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQR( ( x ) ) ) +#define square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), square( ( x ) ) ) +#define Square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Square( ( x ) ) ) +#define SQUARE_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQUARE( ( x ) ) ) +#define sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), sign( ( x ) ) ) +#define Sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), Sign( ( x ) ) ) +#define SIGN_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), SIGN( ( x ) ) ) +#define inv_sqrt_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), inv_sqrt( ( x ) ) ) +#define inv_sqrtf_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), inv_sqrtf( ( x ) ) ) #define log_base_2_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log_base_2( ( x ) ) ) +#define log2_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2( ( x ) ) ) +#define log2f_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2f( ( x ) ) ) #define log2_f_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2_f( ( x ) ) ) -/* The 'wmc_flag_=wmc_flag_' is Used to Avoid: "warning: left-hand operand of comma expression has no effect" - with Cygwin gcc Compiler */ -#define _round_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, _round( ( x ) ) ) -#define round_f_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, round_f( ( x ) ) ) -#define _squant_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, _squant( ( x ) ) ) -/* Set Min/Max */ +#define _round_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, _round( ( x ) ) ) +#define round_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, round( ( x ) ) ) +#define round_f_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, round_f( ( x ) ) ) +#define roundf_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, roundf( ( x ) ) ) #define set_min_( a, b ) OP_COUNT_WRAPPER3_( ( ADD_( 1 ), BRANCH_( 1 ), MOVE_( 1 ) ), set_min( ( a ), ( b ) ) ) #define set_max_( a, b ) OP_COUNT_WRAPPER3_( ( ADD_( 1 ), BRANCH_( 1 ), MOVE_( 1 ) ), set_max( ( a ), ( b ) ) ) -/* mac & msu (Instrumented Versions) */ -#define mac_( a, b, c ) OP_COUNT_WRAPPER1_( MAC_( 1 ), mac( a, b, c ) ) -#define msu_( a, b, c ) OP_COUNT_WRAPPER1_( MAC_( 1 ), msu( a, b, c ) ) /* Functions */ #define func_( name, x ) OP_COUNT_WRAPPER1_( FUNC_( x ), name ) @@ -797,7 +807,7 @@ static int wmc_flag_ = 0; switch #define cost_( n ) OP_COUNT_WRAPPER2_( wmc_flag_ ? ( ADD_( n ), BRANCH_( n ), wmc_flag_ = 0 ) : 0 ); -#ifdef WMOPS_FLT +#ifdef WMOPS #define ACC 2 #define MUL 1 @@ -969,7 +979,7 @@ typedef struct ROM_Size_Lookup_Table * ROM_Size_Lookup_Table Const_Data_PROM_Table[] = * { * {"../lib_enc/rom_enc.c", 0, NULL}, - * {"../lib_com/*.c", 0, NULL}, + * {"../lib_com/[star].c", 0, NULL}, * {"", -1, NULL} * }; * #endif @@ -998,7 +1008,7 @@ typedef enum #endif -#ifdef WMOPS_FLT +#ifdef WMOPS void *mem_alloc( const char *func_name, int func_lineno, size_t size, char *alloc_str ); void mem_free( const char *func_name, int func_lineno, void *ptr ); diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index 01298f6ddb2f3eb99d434673f8fc6b3af43f862e..92dddd54fa1de4e115fddb27348f923624e3fe52 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -9,8 +9,7 @@ #include "rom_dec.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c index f87cc884f1525119815b33eb104d93e246bc0204..5dd3351aace8647f9f7e9a86153354ef4d89727d 100644 --- a/lib_dec/FEC_HQ_core.c +++ b/lib_dec/FEC_HQ_core.c @@ -43,8 +43,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #endif #ifndef IVAS_FLOAT_FIXED diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 2a375498e27a83f7a4cf0b78a49c630e67401caa..49dab93588a863200675b1a0fcf3522397273592 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" @@ -1016,1099 +1015,1101 @@ void HQ_FEC_Mem_update_fx( move16(); hHQ_core->old_is_transient[0] = is_transient; move16(); - - return; +#ifdef ADD_IVAS_HQ_CODE_FEC } +#endif + return; +} #endif #ifdef IVAS_FLOAT_FIXED - static Word16 find_best_delay_fx( - Word16 * mu_o_fx, - Word16 * in_fx, - Word16 mind1, - Word16 maxd1, - Word16 lin, - Word16 delta, - Word16 * false_flag ) - { - Word16 i, d1, k; - Word16 d1m = 0; - - Word16 tmp, exp1, exp2; - Word32 L_tmp1, L_tmp2; - - Word32 min_sq_cross_fx, min_corr_fx; - Word32 accA_fx, accB_fx; - Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; +static Word16 find_best_delay_fx( + Word16 *mu_o_fx, + Word16 *in_fx, + Word16 mind1, + Word16 maxd1, + Word16 lin, + Word16 delta, + Word16 *false_flag ) +{ + Word16 i, d1, k; + Word16 d1m = 0; + + Word16 tmp, exp1, exp2; + Word32 L_tmp1, L_tmp2; + + Word32 min_sq_cross_fx, min_corr_fx; + Word32 accA_fx, accB_fx; + Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); + Flag Overflow = 0; + move32(); #endif - move16(); // d1m + move16(); // d1m - d1 = mind1; - move16(); - FOR( k = 0; k < idiv1616( sub( maxd1, mind1 ), delta ); k++ ) + d1 = mind1; + move16(); + FOR( k = 0; k < idiv1616( sub( maxd1, mind1 ), delta ); k++ ) + { + accA_fx = L_deposit_l( 0 ); + accB_fx = L_deposit_l( 0 ); + FOR( i = 0; i < lin; i += delta ) { - accA_fx = L_deposit_l( 0 ); - accB_fx = L_deposit_l( 0 ); - FOR( i = 0; i < lin; i += delta ) - { #ifdef BASOP_NOGLOB - accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], mu_o_fx[add( d1, i )] ), 2 ) ); - accB_fx = L_add_sat( accB_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], in_fx[i] ), 2 ) ); + accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], mu_o_fx[add( d1, i )] ), 2 ) ); + accB_fx = L_add_sat( accB_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], in_fx[i] ), 2 ) ); #else accA_fx = L_add( accA_fx, L_shr( L_mult( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); accB_fx = L_add( accB_fx, L_shr( L_mult( mu_o_fx[d1 + i], in_fx[i] ), 2 ) ); #endif - } - - Rxy_fx[k] = accB_fx; - move32(); - Ryy_fx[k] = accA_fx; - move32(); - - d1 = add( d1, delta ); } - /* Obtain the best delay values */ - min_sq_cross_fx = 0x80000000; + Rxy_fx[k] = accB_fx; + move32(); + Ryy_fx[k] = accA_fx; move32(); - min_corr_fx = L_deposit_l( 0 ); - exp2 = 0; - move16(); - FOR( d1 = 0; d1 < ( maxd1 - mind1 ) / delta; d1++ ) - { - IF( GT_32( L_abs( Rxy_fx[d1] ), L_abs( Ryy_fx[d1] ) ) ) - exp1 = norm_l( Rxy_fx[d1] ); - ELSE - exp1 = norm_l( Ryy_fx[d1] ); - L_tmp1 = Mult_32_32( L_shl( Rxy_fx[d1], exp1 ), L_shl( min_corr_fx, exp2 ) ); - L_tmp2 = Mult_32_32( L_shl( Ryy_fx[d1], exp1 ), L_shl( min_sq_cross_fx, exp2 ) ); - IF( GE_32( L_tmp1, L_tmp2 ) ) - { - d1m = d1; - move16(); - min_corr_fx = L_add( Ryy_fx[d1], 0 ); /*12 + 12 - 31 */ - min_sq_cross_fx = L_add( Rxy_fx[d1], 0 ); /*12 + 12 - 31 */ - exp2 = exp1; - move16(); - } - } + d1 = add( d1, delta ); + } - test(); - IF( ( min_sq_cross_fx <= 0 ) || ( min_corr_fx <= 0 ) ) - { - tmp = 0; - move16(); /* If cross correlation is negative, the division per the energy will always be negative --> tmp will be < 8192, no need to do the division per say */ - } + /* Obtain the best delay values */ + min_sq_cross_fx = 0x80000000; + move32(); + min_corr_fx = L_deposit_l( 0 ); + exp2 = 0; + move16(); + FOR( d1 = 0; d1 < ( maxd1 - mind1 ) / delta; d1++ ) + { + IF( GT_32( L_abs( Rxy_fx[d1] ), L_abs( Ryy_fx[d1] ) ) ) + exp1 = norm_l( Rxy_fx[d1] ); ELSE - { - /*d1m *= delta; */ - d1m = extract_l( L_mult0( d1m, delta ) ); - - exp1 = sub( norm_l( min_sq_cross_fx ), 1 ); - exp2 = norm_l( min_corr_fx ); - L_tmp1 = L_shl( min_sq_cross_fx, exp1 ); - L_tmp2 = L_shl( min_corr_fx, exp2 ); - tmp = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*15 + exp1 - exp2 */ -#ifdef BASOP_NOGLOB - tmp = shl_o( tmp, sub( exp2, add( exp1, 1 ) ), &Overflow ); /*14 */ -#else - tmp = shl( tmp, sub( exp2, add( exp1, 1 ) ) ); /*14 */ -#endif - } + exp1 = norm_l( Ryy_fx[d1] ); - *false_flag = 0; - move16(); - test(); - if ( LT_16( tmp, 8192 ) || GT_16( tmp, 24576 ) ) + L_tmp1 = Mult_32_32( L_shl( Rxy_fx[d1], exp1 ), L_shl( min_corr_fx, exp2 ) ); + L_tmp2 = Mult_32_32( L_shl( Ryy_fx[d1], exp1 ), L_shl( min_sq_cross_fx, exp2 ) ); + IF( GE_32( L_tmp1, L_tmp2 ) ) { - *false_flag = 1; + d1m = d1; + move16(); + min_corr_fx = L_add( Ryy_fx[d1], 0 ); /*12 + 12 - 31 */ + min_sq_cross_fx = L_add( Rxy_fx[d1], 0 ); /*12 + 12 - 31 */ + exp2 = exp1; move16(); } + } - return d1m; + test(); + IF( ( min_sq_cross_fx <= 0 ) || ( min_corr_fx <= 0 ) ) + { + tmp = 0; + move16(); /* If cross correlation is negative, the division per the energy will always be negative --> tmp will be < 8192, no need to do the division per say */ + } + ELSE + { + /*d1m *= delta; */ + d1m = extract_l( L_mult0( d1m, delta ) ); + + exp1 = sub( norm_l( min_sq_cross_fx ), 1 ); + exp2 = norm_l( min_corr_fx ); + L_tmp1 = L_shl( min_sq_cross_fx, exp1 ); + L_tmp2 = L_shl( min_corr_fx, exp2 ); + tmp = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*15 + exp1 - exp2 */ +#ifdef BASOP_NOGLOB + tmp = shl_o( tmp, sub( exp2, add( exp1, 1 ) ), &Overflow ); /*14 */ +#else + tmp = shl( tmp, sub( exp2, add( exp1, 1 ) ) ); /*14 */ +#endif } - static Word16 Search_Max_Corr_fx( - Word16 * mu_o_fx, /* i : *old_auOut_2fr, */ - Word16 old_Min_ind, /* i : *old_auOut_2fr, */ - const Word16 L /* i : L/2 */ - ) + *false_flag = 0; + move16(); + test(); + if ( LT_16( tmp, 8192 ) || GT_16( tmp, 24576 ) ) { - Word16 pos; - Word16 pos2, delta2; - Word16 lin, delta; - Word16 mind1, maxd1; - Word16 false_flag; - Word16 min_d1, max_d1; - Word16 tmp1, tmp2; - Word16 *in_fx; + *false_flag = 1; + move16(); + } - IF( old_Min_ind == 0 ) - { - /*lin = 8*L/20; */ /* Basic size of the block for phase matching */ - lin = mult_r( L, 13107 ); /* Basic size of the block for phase matching */ - /*min_dist = -1e35f; */ - mind1 = 0; - move16(); /* min value of delay d1 to search for */ - /*maxd1 = 12*L/20; */ /* max value of delay d1 to search for */ - maxd1 = mult_r( L, 19661 ); /* max value of delay d1 to search for */ - - /*in = mu_o + 2*L -lin; */ - in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); - move16(); + return d1m; +} - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); +static Word16 Search_Max_Corr_fx( + Word16 *mu_o_fx, /* i : *old_auOut_2fr, */ + Word16 old_Min_ind, /* i : *old_auOut_2fr, */ + const Word16 L /* i : L/2 */ +) +{ + Word16 pos; + Word16 pos2, delta2; + Word16 lin, delta; + Word16 mind1, maxd1; + Word16 false_flag; + Word16 min_d1, max_d1; + Word16 tmp1, tmp2; + Word16 *in_fx; + + IF( old_Min_ind == 0 ) + { + /*lin = 8*L/20; */ /* Basic size of the block for phase matching */ + lin = mult_r( L, 13107 ); /* Basic size of the block for phase matching */ + /*min_dist = -1e35f; */ + mind1 = 0; + move16(); /* min value of delay d1 to search for */ + /*maxd1 = 12*L/20; */ /* max value of delay d1 to search for */ + maxd1 = mult_r( L, 19661 ); /* max value of delay d1 to search for */ + + /*in = mu_o + 2*L -lin; */ + in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); + move16(); - pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); + /* generate correlation */ + delta = 2; + move16(); + delta2 = 1; + move16(); - IF( false_flag ) - { - return 0; - } + pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); - tmp1 = add( mind1, sub( add( pos, 1 ), delta ) ); - tmp2 = add( mind1, add( pos, delta ) ); - min_d1 = s_max( mind1, tmp1 ); - max_d1 = s_min( maxd1, tmp2 ); - pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); - IF( GT_16( mind1, tmp1 ) ) - { - pos = pos2; - move16(); - } - ELSE - { - pos = add( pos, add( sub( pos2, delta ), 1 ) ); - } + IF( false_flag ) + { + return 0; + } - pos = add( pos, add( lin, mind1 ) ); + tmp1 = add( mind1, sub( add( pos, 1 ), delta ) ); + tmp2 = add( mind1, add( pos, delta ) ); + min_d1 = s_max( mind1, tmp1 ); + max_d1 = s_min( maxd1, tmp2 ); + pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); + IF( GT_16( mind1, tmp1 ) ) + { + pos = pos2; + move16(); } ELSE { - lin = mult_r( L, 9830 ); - mind1 = mult_r( L, 14746 ); /* min value of delay d1 to search for */ - maxd1 = mult_r( L, 22938 ); /* max value of delay d1 to search for */ - in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); - move16(); - - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); - - pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); - - IF( false_flag ) - { - return 0; - } - - tmp1 = add( mind1, add( sub( pos, delta ), 1 ) ); - tmp2 = add( mind1, add( pos, delta ) ); - min_d1 = s_max( mind1, tmp1 ); - max_d1 = s_min( maxd1, tmp2 ); - pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); - - IF( GT_16( mind1, tmp1 ) ) - { - pos = pos2; - move16(); - } - ELSE - { - pos = add( pos, add( sub( pos2, delta ), 1 ) ); - } - pos = add( pos, add( lin, mind1 ) ); + pos = add( pos, add( sub( pos2, delta ), 1 ) ); } - return pos; + pos = add( pos, add( lin, mind1 ) ); } - - static Word16 FEC_phase_matching_fx( - HQ_NBFEC_HANDLE st_fx, /* i : Decoder State */ - Word32 * ImdctOut_fx, /* i : input */ - Word16 * auOut_fx, /* o : output audio */ - Word16 * OldauOut_fx, - Word16 OldauOut_pha_fx[2][N_LEAD_NB] ) + ELSE { - Word16 i; - Word16 pos, remain; - Word16 ol_size; - Word16 L_overlap, L; - Word16 ImdctOutWin_fx[2 * L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 OldauOut2_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - Word16 exp1, exp2, tmp; - Word32 pow1_fx, pow22_fx; - Word16 SmoothingWin_NB3_fx[24]; - - L = L_FRAME8k; + lin = mult_r( L, 9830 ); + mind1 = mult_r( L, 14746 ); /* min value of delay d1 to search for */ + maxd1 = mult_r( L, 22938 ); /* max value of delay d1 to search for */ + in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); move16(); - ol_size = idiv1616( shl( L, 1 ), 20 ); + + /* generate correlation */ + delta = 2; move16(); - L_overlap = idiv1616( imult1616( 3, L ), 20 ); + delta2 = 1; move16(); - FOR( i = 0; i < L_overlap; i++ ) - { - SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[imult1616( i, 3 )]; - move16(); - } + pos = find_best_delay_fx( mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag ); - FOR( i = 0; i < add( L, 25 ); i++ ) + IF( false_flag ) { - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); + return 0; } - set16_fx( ImdctOutWin_fx, 0, shl( L, 1 ) ); - pos = Search_Max_Corr_fx( st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind, L ); + tmp1 = add( mind1, add( sub( pos, delta ), 1 ) ); + tmp2 = add( mind1, add( pos, delta ) ); + min_d1 = s_max( mind1, tmp1 ); + max_d1 = s_min( maxd1, tmp2 ); + pos2 = find_best_delay_fx( mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag ); - IF( pos == 0 ) + IF( GT_16( mind1, tmp1 ) ) { - return 1; - } - - /* Repetition */ - remain = sub( add( L, N_Z_L_NB ), sub( shl( L, 1 ), pos ) ); - Copy( &st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], sub( shl( L, 1 ), pos ) ); - - /* OldauOut without windowing */ - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + pos = pos2; move16(); } - FOR( i = 0; i < shr( L, 1 ); i++ ) + ELSE { - OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[i] ), 6 ) ); - move16(); + pos = add( pos, add( sub( pos2, delta ), 1 ) ); } + pos = add( pos, add( lin, mind1 ) ); + } - Copy( OldauOutnoWin_fx, &ImdctOutWin_fx[add( N_ZERO_NB, sub( shl( L, 1 ), pos ) )], remain ); + return pos; +} - pow1_fx = L_deposit_l( 0 ); - pow22_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L; i++ ) - { - pow1_fx = L_add( pow1_fx, shr( abs_s( st_fx->old_auOut_2fr_fx[add( L, i )] ), 1 ) ); - pow22_fx = L_add( pow22_fx, shr( abs_s( ImdctOutWin_fx[N_ZERO_NB + i] ), 1 ) ); - } - IF( pow22_fx != 0 ) +static Word16 FEC_phase_matching_fx( + HQ_NBFEC_HANDLE st_fx, /* i : Decoder State */ + Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word16 *OldauOut_fx, + Word16 OldauOut_pha_fx[2][N_LEAD_NB] ) +{ + Word16 i; + Word16 pos, remain; + Word16 ol_size; + Word16 L_overlap, L; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 OldauOutnoWin_fx[L_FRAME8k]; + Word16 OldauOut2_fx[L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; + Word16 exp1, exp2, tmp; + Word32 pow1_fx, pow22_fx; + Word16 SmoothingWin_NB3_fx[24]; + + L = L_FRAME8k; + move16(); + ol_size = idiv1616( shl( L, 1 ), 20 ); + move16(); + L_overlap = idiv1616( imult1616( 3, L ), 20 ); + move16(); + + FOR( i = 0; i < L_overlap; i++ ) + { + SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[imult1616( i, 3 )]; + move16(); + } + + FOR( i = 0; i < add( L, 25 ); i++ ) + { + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; + move16(); + } + set16_fx( ImdctOutWin_fx, 0, shl( L, 1 ) ); + + pos = Search_Max_Corr_fx( st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind, L ); + + IF( pos == 0 ) + { + return 1; + } + + /* Repetition */ + remain = sub( add( L, N_Z_L_NB ), sub( shl( L, 1 ), pos ) ); + Copy( &st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], sub( shl( L, 1 ), pos ) ); + + /* OldauOut without windowing */ + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) + { + OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + } + FOR( i = 0; i < shr( L, 1 ); i++ ) + { + OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[i] ), 6 ) ); + move16(); + } + + Copy( OldauOutnoWin_fx, &ImdctOutWin_fx[add( N_ZERO_NB, sub( shl( L, 1 ), pos ) )], remain ); + + pow1_fx = L_deposit_l( 0 ); + pow22_fx = L_deposit_l( 0 ); + FOR( i = 0; i < L; i++ ) + { + pow1_fx = L_add( pow1_fx, shr( abs_s( st_fx->old_auOut_2fr_fx[add( L, i )] ), 1 ) ); + pow22_fx = L_add( pow22_fx, shr( abs_s( ImdctOutWin_fx[N_ZERO_NB + i] ), 1 ) ); + } + IF( pow22_fx != 0 ) + { + exp1 = sub( norm_l( pow1_fx ), 1 ); + exp2 = norm_l( pow22_fx ); + tmp = div_s( extract_h( L_shl( pow1_fx, exp1 ) ), extract_h( L_shl( pow22_fx, exp2 ) ) ); /*15 + exp1 - exp2*/ + tmp = shl( tmp, sub( sub( exp2, exp1 ), 1 ) ); /*14*/ + FOR( i = N_ZERO_NB; i < shl( L, 1 ); i++ ) { - exp1 = sub( norm_l( pow1_fx ), 1 ); - exp2 = norm_l( pow22_fx ); - tmp = div_s( extract_h( L_shl( pow1_fx, exp1 ) ), extract_h( L_shl( pow22_fx, exp2 ) ) ); /*15 + exp1 - exp2*/ - tmp = shl( tmp, sub( sub( exp2, exp1 ), 1 ) ); /*14*/ - FOR( i = N_ZERO_NB; i < shl( L, 1 ); i++ ) - { #ifdef BASOP_NOGLOB - ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); + ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); #else ImdctOutWin_fx[i] = shl( mult( ImdctOutWin_fx[i], tmp ), 1 ); #endif - move16(); - } - } - Smoothing_vector_NB_fx( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size ); - - FOR( i = 0; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ - ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = mult( ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )], win_NB_fx[sub( sub( shr( L, 1 ), i ), 1 )] ); move16(); } + } + Smoothing_vector_NB_fx( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size ); - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ - ImdctOutWin_fx[add( L, i )] = mult( ImdctOutWin_fx[add( L, i )], win_NB_fx[sub( sub( L, 1 ), i )] ); - move16(); - } + FOR( i = 0; i < shr( L, 1 ); i++ ) + { + /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = mult( ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )], win_NB_fx[sub( sub( shr( L, 1 ), i ), 1 )] ); + move16(); + } - Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); - Copy( &ImdctOutWin_fx[add( ol_size, N_ZERO_NB )], &auOut_fx[ol_size], sub( N_Z_L_NB, ol_size ) ); - Copy( &ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB ); - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) + { + /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ + ImdctOutWin_fx[add( L, i )] = mult( ImdctOutWin_fx[add( L, i )], win_NB_fx[sub( sub( L, 1 ), i )] ); + move16(); + } - FOR( i = 0; i < shr( L, 1 ); i++ ) - { - OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); - move16(); - OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); - move16(); - } + Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); + Copy( &ImdctOutWin_fx[add( ol_size, N_ZERO_NB )], &auOut_fx[ol_size], sub( N_Z_L_NB, ol_size ) ); + Copy( &ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB ); + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); + FOR( i = 0; i < shr( L, 1 ); i++ ) + { + OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + move16(); + } - FOR( i = L_overlap; i < N_LEAD_NB; i++ ) - { - OldauOut_pha_fx[1][i] = OldauOut2_fx[i + N_ZERO_NB]; - move32(); - } + Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); - return 0; + FOR( i = L_overlap; i < N_LEAD_NB; i++ ) + { + OldauOut_pha_fx[1][i] = OldauOut2_fx[i + N_ZERO_NB]; + move32(); } - static void FEC_phase_matching_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 mean_en_high_fx /*Q5 */ - ) - { - Word16 i; - Word16 L_overlap, L; - Word16 oldout_pha_idx; - Word16 *OldOut_pha_fx; - Word16 ImdctOutWin_fx[2 * L_FRAME48k]; - Word16 win_NB_fx[L_FRAME8k + 25]; + return 0; +} - L = L_FRAME8k; - move16(); - FOR( i = 0; i < L + 25; i++ ) - { - /* win_NB[i] = window_48kHz[i*6+3]; */ - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); - } +static void FEC_phase_matching_nextgood_fx( + const Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word16 *OldauOut_fx, /* i/o: audio from previous frame */ + Word16 OldauOut_pha_fx[2][N_LEAD_NB], + Word16 mean_en_high_fx /*Q5 */ +) +{ + Word16 i; + Word16 L_overlap, L; + Word16 oldout_pha_idx; + Word16 *OldOut_pha_fx; + Word16 ImdctOutWin_fx[2 * L_FRAME48k]; + Word16 win_NB_fx[L_FRAME8k + 25]; - test(); - IF( ( GT_16( mean_en_high_fx, 64 ) ) || ( LT_16( mean_en_high_fx, 16 ) ) ) - { - oldout_pha_idx = 1; - move16(); - } - ELSE - { - oldout_pha_idx = 0; - move16(); - } + L = L_FRAME8k; + move16(); + FOR( i = 0; i < L + 25; i++ ) + { + /* win_NB[i] = window_48kHz[i*6+3]; */ + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; + move16(); + } - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - L_overlap = N_LEAD_NB; + test(); + IF( ( GT_16( mean_en_high_fx, 64 ) ) || ( LT_16( mean_en_high_fx, 16 ) ) ) + { + oldout_pha_idx = 1; move16(); - OldOut_pha_fx = OldauOut_pha_fx[oldout_pha_idx]; - FOR( i = 0; i < N_LEAD_NB; i++ ) - { - /* OldOut_pha[i] *= SmoothingWin_NB875[L_overlap-i-1]; */ - OldOut_pha_fx[i] = mult( OldOut_pha_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); - move16(); - } + } + ELSE + { + oldout_pha_idx = 0; + move16(); + } - IF( EQ_16( oldout_pha_idx, 1 ) ) - { - /* Use phase matching and overlapping with the Oldauout*/ - /* Windowing */ - /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, NULL, 0);*/ - /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB); */ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); - } - ELSE - { - /* Only use phase matching */ - /* Windowing */ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); - } - /* common_overlapping(auOut, ImdctOutWin, OldOut_pha, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0, L);*/ - common_overlapping_fx( auOut_fx, ImdctOutWin_fx, OldOut_pha_fx, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0 ); - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + /* Overlapping with next good frame : Overlapping to remove the discontinuity */ + L_overlap = N_LEAD_NB; + move16(); + OldOut_pha_fx = OldauOut_pha_fx[oldout_pha_idx]; + FOR( i = 0; i < N_LEAD_NB; i++ ) + { + /* OldOut_pha[i] *= SmoothingWin_NB875[L_overlap-i-1]; */ + OldOut_pha_fx[i] = mult( OldOut_pha_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); + move16(); + } - return; + IF( EQ_16( oldout_pha_idx, 1 ) ) + { + /* Use phase matching and overlapping with the Oldauout*/ + /* Windowing */ + /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, NULL, 0);*/ + /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB); */ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + } + ELSE + { + /* Only use phase matching */ + /* Windowing */ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); } + /* common_overlapping(auOut, ImdctOutWin, OldOut_pha, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0, L);*/ + common_overlapping_fx( auOut_fx, ImdctOutWin_fx, OldOut_pha_fx, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0 ); + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + + return; +} #endif #ifdef IVAS_FLOAT_FIXED - static void FEC_phase_matching_burst_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 *prev_oldauOut_fx /* i : OldauOut from previous frame */ - ) - { - Word16 i; - Word16 L_overlap; - Word16 L; - Word16 OldauOut2_fx[L_FRAME8k]; - Word16 ImdctOutWin_fx[2 * L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - Word16 SmoothingWin_NB3_fx[24]; +static void FEC_phase_matching_burst_fx( + const Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word16 *OldauOut_fx, /* i/o: audio from previous frame */ + Word16 OldauOut_pha_fx[2][N_LEAD_NB], + Word16 *prev_oldauOut_fx /* i : OldauOut from previous frame */ +) +{ + Word16 i; + Word16 L_overlap; + Word16 L; + Word16 OldauOut2_fx[L_FRAME8k]; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; + Word16 SmoothingWin_NB3_fx[24]; + + L = L_FRAME8k; + move16(); + L_overlap = idiv1616( imult1616( 3, L ), 20 ); + move16(); - L = L_FRAME8k; + FOR( i = 0; i < L_overlap; i++ ) + { + SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[i * 3]; move16(); - L_overlap = idiv1616( imult1616( 3, L ), 20 ); + } + + FOR( i = 0; i < add( L, 25 ); i++ ) + { + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); + } - FOR( i = 0; i < L_overlap; i++ ) - { - SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[i * 3]; - move16(); - } + /* Windowing */ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); - FOR( i = 0; i < add( L, 25 ); i++ ) - { - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); - } + /* Repetition with old frame to reserve energy */ + /*common_overlapping(auOut, ImdctOutWin, prev_oldauOut, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0, L);*/ + common_overlapping_fx( auOut_fx, ImdctOutWin_fx, prev_oldauOut_fx, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0 ); - /* Windowing */ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + /* data transition from OldauOut to auOut using smoothing win*/ + Smoothing_vector_NB_fx( OldauOut_pha_fx[0], auOut_fx, SmoothingWin_NB875_fx, auOut_fx, N_LEAD_NB ); + + /* Update the OldauOut array for next overlapping */ + Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); - /* Repetition with old frame to reserve energy */ - /*common_overlapping(auOut, ImdctOutWin, prev_oldauOut, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0, L);*/ - common_overlapping_fx( auOut_fx, ImdctOutWin_fx, prev_oldauOut_fx, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0 ); + FOR( i = 0; i < shr( L, 1 ); i++ ) + { + /* OldauOut2[i] = -ImdctOut[L/2 - 1 - i];*/ + /* OldauOut2[L/2+i] = -ImdctOut[i];*/ + OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + move16(); + } - /* data transition from OldauOut to auOut using smoothing win*/ - Smoothing_vector_NB_fx( OldauOut_pha_fx[0], auOut_fx, SmoothingWin_NB875_fx, auOut_fx, N_LEAD_NB ); + Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); - /* Update the OldauOut array for next overlapping */ - Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); + FOR( i = L_overlap; i < N_LEAD_NB; i++ ) + { + /* OldauOut_pha[1][i] = OldauOut2[i+N_ZERO_NB]; */ + OldauOut_pha_fx[1][i] = OldauOut2_fx[i + N_ZERO_NB]; + move16(); + } - FOR( i = 0; i < shr( L, 1 ); i++ ) - { - /* OldauOut2[i] = -ImdctOut[L/2 - 1 - i];*/ - /* OldauOut2[L/2+i] = -ImdctOut[i];*/ - OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); - move16(); - OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); - move16(); - } + return; +} - Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); +static void Repetition_smoothing_nextgood_fx( + const Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word32 *OldImdctOut_fx, /* i : input */ + Word16 *OldauOut_fx, /* i/o: audio from previous frame */ + Word16 cur_data_use_flag, /* i : current imdct data use flag */ + Word16 overlap_time ) +{ + Word16 i; + Word16 L_overlap; + Word16 ol_size; + Word16 L; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; - FOR( i = L_overlap; i < N_LEAD_NB; i++ ) - { - /* OldauOut_pha[1][i] = OldauOut2[i+N_ZERO_NB]; */ - OldauOut_pha_fx[1][i] = OldauOut2_fx[i + N_ZERO_NB]; - move16(); - } + L = L_FRAME8k; + move16(); - return; + FOR( i = 0; i < L_FRAME8k + 25; i++ ) + { + /*win_NB[i] = window_48kHz[i*6+3];*/ + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; + move16(); } - static void Repetition_smoothing_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 cur_data_use_flag, /* i : current imdct data use flag */ - Word16 overlap_time ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - Word16 i; - Word16 L_overlap; - Word16 ol_size; - Word16 L; - Word16 ImdctOutWin_fx[2 * L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - - L = L_FRAME8k; + /*OldauOut[i-N_ZERO_NB] = -OldImdctOut[L/2 - 1 - i];*/ + OldauOut_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); /* Q6 -> Q0 */ + move16(); + } + FOR( i = 0; i < shr( L, 2 ); i++ ) + { + /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ + OldauOut_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); /* Q6 -> Q0 */ move16(); + } - FOR( i = 0; i < L_FRAME8k + 25; i++ ) - { - /*win_NB[i] = window_48kHz[i*6+3];*/ - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); - } + /* Overlapping with next good frame : Overlapping to remove the discontinuity */ + IF( cur_data_use_flag ) + { + ol_size = N_LEAD_NB; + move16(); FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - /*OldauOut[i-N_ZERO_NB] = -OldImdctOut[L/2 - 1 - i];*/ - OldauOut_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); /* Q6 -> Q0 */ + /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ + ImdctOutWin_fx[add( i, L )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); move16(); } - FOR( i = 0; i < shr( L, 2 ); i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { - /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ - OldauOut_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); /* Q6 -> Q0 */ + ImdctOutWin_fx[add( i, shr( imult1616( 3, L ), 1 ) )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); move16(); } - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - IF( cur_data_use_flag ) - { - ol_size = N_LEAD_NB; - move16(); - - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ - ImdctOutWin_fx[add( i, L )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); - move16(); - } - FOR( i = 0; i < shr( L, 1 ); i++ ) - { - ImdctOutWin_fx[add( i, shr( imult1616( 3, L ), 1 ) )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); - move16(); - } - - /*a = (float)(1./(float)(ol_size)); y = ax */ - Smoothing_vector_scaledown_NB_fx( OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size ); + /*a = (float)(1./(float)(ol_size)); y = ax */ + Smoothing_vector_scaledown_NB_fx( OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size ); - /* Scale down the overlapped signal */ - Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[ol_size], 23170, sub( N_Z_L_NB, ol_size ) ); - } + /* Scale down the overlapped signal */ + Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[ol_size], 23170, sub( N_Z_L_NB, ol_size ) ); + } - L_overlap = overlap_time; + L_overlap = overlap_time; + move16(); + FOR( i = 0; i < L_overlap; i++ ) + { + /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ + OldauOut_fx[i] = mult( OldauOut_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); move16(); - FOR( i = 0; i < L_overlap; i++ ) - { - /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ - OldauOut_fx[i] = mult( OldauOut_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); - move16(); - } - FOR( i = L_overlap; i < L; i++ ) - { - OldauOut_fx[i] = 0; - move16(); - } + } + FOR( i = L_overlap; i < L; i++ ) + { + OldauOut_fx[i] = 0; + move16(); + } - /* Windowing */ - /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1);*/ - /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB);*/ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + /* Windowing */ + /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1);*/ + /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB);*/ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); - /*v_add(&ImdctOutWin[N_ZERO_NB], OldauOut, auOut, L);*/ - /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ - FOR( i = 0; i < L; i++ ) - { + /*v_add(&ImdctOutWin[N_ZERO_NB], OldauOut, auOut, L);*/ + /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ + FOR( i = 0; i < L; i++ ) + { #ifdef BASOP_NOGLOB - auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); + auOut_fx[i] = add_sat( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); #else auOut_fx[i] = add( ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i] ); #endif - move16(); - } - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + move16(); + } + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + + return; +} + +static Word16 Repetition_smoothing_fx( + const Word32 *ImdctOut_fx, /* i : input */ + Word16 *auOut_fx, /* o : output audio */ + Word32 *OldImdctOut_fx, /* i : input */ + Word16 *OldauOut_fx, /* i/o: audio from previous frame */ + const Word16 L, /* i : length */ + Word16 *prev_oldauOut_fx, /* i : OldauOut from previous frame */ + Word16 overlap_time /* i : overlap time */ +) +{ + Word16 i; + Word32 pow1_fx; + Word32 pow22_fx; + Word16 ImdctOutWin_fx[2 * L_FRAME8k]; + Word16 OldauOutnoWin_fx[L_FRAME8k]; + Word16 win_NB_fx[L_FRAME8k + 25]; - return; + FOR( i = 0; i < L_FRAME8k + 25; i++ ) + { + /*win_NB[i] = window_48kHz[i*6+3];*/ + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; + move16(); } - static Word16 Repetition_smoothing_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - Word16 *prev_oldauOut_fx, /* i : OldauOut from previous frame */ - Word16 overlap_time /* i : overlap time */ - ) + /* Windowing */ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + + /* Repetition with old frame to reserve energy */ + common_overlapping_fx( auOut_fx, ImdctOutWin_fx, prev_oldauOut_fx, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0 ); + + /* OldauOut without windowing */ + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) + { + OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + } + FOR( i = 0; i < shr( L, 1 ); i++ ) { - Word16 i; - Word32 pow1_fx; - Word32 pow22_fx; - Word16 ImdctOutWin_fx[2 * L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; + OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); + move16(); + } - FOR( i = 0; i < L_FRAME8k + 25; i++ ) - { - /*win_NB[i] = window_48kHz[i*6+3];*/ - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); - } + /* data transition from OldauOut to auOut using smoothing win*/ + Smoothing_vector_NB_fx( OldauOutnoWin_fx, auOut_fx, SmoothingWin_NB875_fx, auOut_fx, overlap_time ); - /* Windowing */ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + pow1_fx = L_deposit_l( 0 ); + pow22_fx = L_deposit_l( 0 ); + FOR( i = 0; i < idiv1616( imult1616( 4, L ), 20 ); i++ ) + { + pow1_fx = L_add( pow1_fx, Mult_32_32( L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ), L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ) ) ); + pow22_fx = L_add( pow22_fx, Mult_32_32( L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ), L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ) ) ); + } - /* Repetition with old frame to reserve energy */ - common_overlapping_fx( auOut_fx, ImdctOutWin_fx, prev_oldauOut_fx, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0 ); - /* OldauOut without windowing */ - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); - move16(); - } - FOR( i = 0; i < shr( L, 1 ); i++ ) - { - OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); - move16(); - } + IF( GT_32( pow22_fx, L_add( pow1_fx, L_shl( pow1_fx, 1 ) ) ) ) + { + return 1; + } - /* data transition from OldauOut to auOut using smoothing win*/ - Smoothing_vector_NB_fx( OldauOutnoWin_fx, auOut_fx, SmoothingWin_NB875_fx, auOut_fx, overlap_time ); + /* Update the OldauOut array for next overlapping */ + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); - pow1_fx = L_deposit_l( 0 ); - pow22_fx = L_deposit_l( 0 ); - FOR( i = 0; i < idiv1616( imult1616( 4, L ), 20 ); i++ ) - { - pow1_fx = L_add( pow1_fx, Mult_32_32( L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ), L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ) ) ); - pow22_fx = L_add( pow22_fx, Mult_32_32( L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ), L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ) ) ); - } + return 0; +} +static void common_overlapping_fx( + Word16 *auOut_fx, /* i : Input */ + Word16 *ImdctOutWin_fx, /* o : Output */ + Word16 *OldauOut_fx, /* i : Window */ + Word16 end1, /* i : Decay */ + Word16 offset1, + Word16 start2, + Word16 end2, + Word16 offset_i2, + Word16 offset2 ) +{ + Word16 i; - IF( GT_32( pow22_fx, L_add( pow1_fx, L_shl( pow1_fx, 1 ) ) ) ) - { - return 1; - } + /* Common Overlapping */ + FOR( i = 0; i < end1; i++ ) + { + /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ +#ifdef BASOP_NOGLOB + auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[add( i, offset1 )] ); +#else + auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); +#endif + move16(); + } + FOR( i = start2; i < end2; i++ ) + { + /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ + auOut_fx[add( i, offset2 )] = ImdctOutWin_fx[add( i, offset_i2 )]; + move16(); + } + + return; +} - /* Update the OldauOut array for next overlapping */ - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); - return 0; +static void Smoothing_vector_NB_fx( + const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ + const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ + const Word16 SmoothingWin_fx[], /* i : Smoothing window */ + Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 ol_size /* i : Overlap size */ +) +{ + Word16 i; + Word16 weight_fx; + + FOR( i = 0; i < ol_size; i++ ) + { + weight_fx = SmoothingWin_fx[i]; + move16(); + auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), mult( ImdctOutWin_fx[i], weight_fx ) ); + move16(); } - static void common_overlapping_fx( - Word16 * auOut_fx, /* i : Input */ - Word16 * ImdctOutWin_fx, /* o : Output */ - Word16 * OldauOut_fx, /* i : Window */ - Word16 end1, /* i : Decay */ - Word16 offset1, - Word16 start2, - Word16 end2, - Word16 offset_i2, - Word16 offset2 ) + return; +} + + +static void Windowing_1st_NB_fx( + Word16 *ImdctOutWin_fx, /* o : Output */ + const Word32 *ImdctOut_fx, /* i : Input */ + const Word16 *win_fx, /* i : Window */ + const Word16 *smoothingWin_fx, /* i : Smoothing Window */ + Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ +) +{ + Word16 i; + Word16 L; + + L = L_FRAME8k; + move16(); + IF( smoothing_flag == 0 ) { - Word16 i; - - /* Common Overlapping */ - FOR( i = 0; i < end1; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ -#ifdef BASOP_NOGLOB - auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[add( i, offset1 )] ); -#else - auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); -#endif + /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], win_fx[sub( sub( sub( shl( L, 1 ), 1 ), i ), N_LEAD_O_NB )] ), 6 ) ); move16(); } - FOR( i = start2; i < end2; i++ ) + + FOR( i = 0; i < N_ZERO_O_NB; i++ ) { - /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ - auOut_fx[add( i, offset2 )] = ImdctOutWin_fx[add( i, offset_i2 )]; + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), win_fx[sub( ( sub( sub( shr( imult1616( 3, L ), 1 ), 1 ), i ) ), N_LEAD_O_NB )] ), 6 ) ); + move16(); + ImdctOutWin_fx[add( idiv1616( imult1616( 3, L ), 2 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); move16(); } - - return; } - - - static void Smoothing_vector_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ - ) + ELSE { - Word16 i; - Word16 weight_fx; + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) + { + /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], smoothingWin_fx[sub( i, N_ZERO_NB )] ), 6 ) ); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + move16(); + } - FOR( i = 0; i < ol_size; i++ ) + FOR( i = 0; i < N_ZERO_O_NB; i++ ) { - weight_fx = SmoothingWin_fx[i]; + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), smoothingWin_fx[add( i, N_ZERO_O_NB )] ), 6 ) ); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ move16(); - auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), mult( ImdctOutWin_fx[i], weight_fx ) ); + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); move16(); } - - return; } + return; +} +static void Windowing_2nd_NB_fx( + Word16 *ImdctOutWin_fx, /* o : Output */ + const Word32 *ImdctOut_fx, /* i : Input */ + const Word16 *win_fx /* i : Window */ +) +{ + Word16 i; + Word16 L; - static void Windowing_1st_NB_fx( - Word16 * ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx, /* i : Window */ - const Word16 *smoothingWin_fx, /* i : Smoothing Window */ - Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ - ) + L = L_FRAME8k; + move16(); + FOR( i = N_ZERO_O_NB; i < shr( L, 1 ); i++ ) { - Word16 i; - Word16 L; - - L = L_FRAME8k; + /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ + /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), 6 ) ); + move16(); + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); move16(); - IF( smoothing_flag == 0 ) - { - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], win_fx[sub( sub( sub( shl( L, 1 ), 1 ), i ), N_LEAD_O_NB )] ), 6 ) ); - move16(); - } - - FOR( i = 0; i < N_ZERO_O_NB; i++ ) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), win_fx[sub( ( sub( sub( shr( imult1616( 3, L ), 1 ), 1 ), i ) ), N_LEAD_O_NB )] ), 6 ) ); - move16(); - ImdctOutWin_fx[add( idiv1616( imult1616( 3, L ), 2 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); - move16(); - } - } - ELSE - { - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], smoothingWin_fx[sub( i, N_ZERO_NB )] ), 6 ) ); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - move16(); - } - - FOR( i = 0; i < N_ZERO_O_NB; i++ ) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), smoothingWin_fx[add( i, N_ZERO_O_NB )] ), 6 ) ); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - move16(); - ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); - move16(); - } - } - - return; } - static void Windowing_2nd_NB_fx( - Word16 * ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx /* i : Window */ - ) + + FOR( i = 0; i < N_ZERO_NB; i++ ) { - Word16 i; - Word16 L; + /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ + ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + } - L = L_FRAME8k; + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) + { + /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ + ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), win_fx[sub( sub( L, 1 ), i )] ), 6 ) ); move16(); - FOR( i = N_ZERO_O_NB; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ - ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), 6 ) ); - move16(); - ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); - move16(); - } + } - FOR( i = 0; i < N_ZERO_NB; i++ ) - { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ - ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); - move16(); - } + return; +} - FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) - { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ - ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), win_fx[sub( sub( L, 1 ), i )] ), 6 ) ); - move16(); - } +static void Smoothing_vector_scaledown_NB_fx( + const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ + const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ + const Word16 SmoothingWin_fx[], /* i : Smoothing window */ + Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 ol_size /* i : Overlap size */ + +) +{ + Word16 i; + Word16 weight_fx; - return; + FOR( i = 0; i < ol_size; i++ ) + { + weight_fx = SmoothingWin_fx[i]; + move16(); + auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), + mult( ImdctOutWin_fx[i], mult_r( 23170, weight_fx ) ) ); + move16(); } - static void Smoothing_vector_scaledown_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ + return; +} - ) - { - Word16 i; - Word16 weight_fx; - FOR( i = 0; i < ol_size; i++ ) - { - weight_fx = SmoothingWin_fx[i]; - move16(); - auOut_fx[i] = add( mult( OldauOutnoWin_fx[i], sub( 32767, weight_fx ) ), - mult( ImdctOutWin_fx[i], mult_r( 23170, weight_fx ) ) ); - move16(); - } +static void Scaledown_fx( + Word16 x[], /* i : Input vector */ + Word16 y[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word16 scale_v, /*Q15 */ + const Word16 N /* i : Overlap size */ +) +{ + Word16 i; - return; + FOR( i = 0; i < N; i++ ) + { + y[i] = mult( x[i], scale_v ); + move16(); } + return; +} + +void time_domain_FEC_HQ_fx( + Decoder_State *st_fx, /* i : Decoder State */ + Word32 *wtda_audio_fx, /* i : input */ + Word16 *out_fx, /* o : output audio */ + Word16 mean_en_high_fx, /* i : transient flag */ + const Word16 output_frame, + Word16 *Q_synth ) +{ + HQ_NBFEC_HANDLE hHQ_nbfec; + HQ_DEC_HANDLE hHQ_core; + hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; - static void Scaledown_fx( - Word16 x[], /* i : Input vector */ - Word16 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 scale_v, /*Q15 */ - const Word16 N /* i : Overlap size */ - ) + IF( hHQ_core->Q_old_wtda != 0 ) { - Word16 i; + Scale_sig( hHQ_core->old_out_fx, output_frame, negate( hHQ_core->Q_old_wtda ) ); + hHQ_core->Q_old_wtda = 0; + move16(); + } - FOR( i = 0; i < N; i++ ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_flag, 1 ) ) && ( hHQ_nbfec->phase_mat_next == 0 ) ) + { + IF( FEC_phase_matching_fx( hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx ) ) { - y[i] = mult( x[i], scale_v ); + /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); + hHQ_nbfec->phase_mat_next = 0; move16(); } - - return; - } - - void time_domain_FEC_HQ_fx( - Decoder_State * st_fx, /* i : Decoder State */ - Word32 * wtda_audio_fx, /* i : input */ - Word16 * out_fx, /* o : output audio */ - Word16 mean_en_high_fx, /* i : transient flag */ - const Word16 output_frame, - Word16 *Q_synth ) - { - HQ_NBFEC_HANDLE hHQ_nbfec; - HQ_DEC_HANDLE hHQ_core; - hHQ_nbfec = st_fx->hHQ_nbfec; - hHQ_core = st_fx->hHQ_core; - - IF( hHQ_core->Q_old_wtda != 0 ) + ELSE { - Scale_sig( hHQ_core->old_out_fx, output_frame, negate( hHQ_core->Q_old_wtda ) ); - hHQ_core->Q_old_wtda = 0; + hHQ_nbfec->phase_mat_next = 1; + move16(); + *Q_synth = 0; move16(); } + } + ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( st_fx->bfi == 0 ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) + { + FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx ); + hHQ_nbfec->phase_mat_next = 0; + move16(); + *Q_synth = 0; + move16(); + } + ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( EQ_16( st_fx->bfi, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) + { + FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx ); + hHQ_nbfec->phase_mat_next = 1; + move16(); + *Q_synth = 0; + move16(); + } + ELSE + { + /*n4 = (short)(N_LEAD_MDCT*(float)(output_frame/20));*/ test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_flag, 1 ) ) && ( hHQ_nbfec->phase_mat_next == 0 ) ) + IF( st_fx->bfi == 0 && EQ_16( st_fx->prev_bfi, 1 ) ) { - IF( FEC_phase_matching_fx( hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx ) ) + test(); + IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) /* Q11 */ { - /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); - hHQ_nbfec->phase_mat_next = 0; + Word16 tmp; + + tmp = 0; + move16(); + if ( GT_16( st_fx->old_bfi_cnt, 1 ) ) + { + tmp = 1; + move16(); + } + Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB ); + *Q_synth = 0; move16(); } - ELSE + ELSE IF( GT_16( st_fx->old_bfi_cnt, 1 ) ) { - hHQ_nbfec->phase_mat_next = 1; - move16(); + Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, N_LEAD_NB ); *Q_synth = 0; move16(); } + ELSE + { + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + } } - ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( st_fx->bfi == 0 ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) - { - FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx ); - - hHQ_nbfec->phase_mat_next = 0; - move16(); - *Q_synth = 0; - move16(); - } - ELSE IF( ( EQ_16( st_fx->prev_bfi, 1 ) ) && ( EQ_16( st_fx->bfi, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 1 ) ) ) - { - FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx ); - hHQ_nbfec->phase_mat_next = 1; - move16(); - *Q_synth = 0; - move16(); - } - ELSE + ELSE /* if(st->bfi == 1) */ { - /*n4 = (short)(N_LEAD_MDCT*(float)(output_frame/20));*/ test(); - IF( st_fx->bfi == 0 && EQ_16( st_fx->prev_bfi, 1 ) ) + IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) { - test(); - IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) /* Q11 */ + /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ + IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB ) ) { - Word16 tmp; - - tmp = 0; - move16(); - if ( GT_16( st_fx->old_bfi_cnt, 1 ) ) - { - tmp = 1; - move16(); - } - Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB ); - *Q_synth = 0; - move16(); + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); } - ELSE IF( GT_16( st_fx->old_bfi_cnt, 1 ) ) + ELSE { - Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, N_LEAD_NB ); *Q_synth = 0; move16(); } - ELSE - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - } } - ELSE /* if(st->bfi == 1) */ + ELSE { - test(); - IF( ( EQ_16( hHQ_nbfec->stat_mode_out, 1 ) ) || ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_50P_fx ) ) ) - { - /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ - IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB ) ) - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - } - ELSE - { - *Q_synth = 0; - move16(); - } - } - ELSE - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - } + /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ + window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); } - hHQ_nbfec->phase_mat_next = 0; - move16(); } - - return; + hHQ_nbfec->phase_mat_next = 0; + move16(); } - static void Next_good_after_burst_erasures_fx( - const Word32 *ImdctOut_fx, - Word16 *auOut_fx, - Word16 *OldauOut_fx, - const Word16 ol_size ) - { - Word16 i, L; - Word16 ImdctOutWin_fx[2 * L_FRAME48k]; - Word16 win_NB_fx[L_FRAME8k + 25]; + return; +} + +static void Next_good_after_burst_erasures_fx( + const Word32 *ImdctOut_fx, + Word16 *auOut_fx, + Word16 *OldauOut_fx, + const Word16 ol_size ) +{ + Word16 i, L; + Word16 ImdctOutWin_fx[2 * L_FRAME48k]; + Word16 win_NB_fx[L_FRAME8k + 25]; - L = L_FRAME8k; + L = L_FRAME8k; + move16(); + FOR( i = 0; i < add( L, 25 ); i++ ) + { + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); - FOR( i = 0; i < add( L, 25 ); i++ ) - { - win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; - move16(); - } + } - /* Windowing */ - Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); - Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); + /* Windowing */ + Windowing_1st_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0 ); + Windowing_2nd_NB_fx( ImdctOutWin_fx, ImdctOut_fx, win_NB_fx ); - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - Smoothing_vector_scaledown_NB_fx( &OldauOut_fx[N_ZERO_NB], &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, &OldauOut_fx[N_ZERO_NB], ol_size ); + /* Overlapping with next good frame : Overlapping to remove the discontinuity */ + Smoothing_vector_scaledown_NB_fx( &OldauOut_fx[N_ZERO_NB], &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, &OldauOut_fx[N_ZERO_NB], ol_size ); - /* Scale down the overlapped signal */ - Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[add( ol_size, N_ZERO_NB )], 23170, sub( N_Z_L_NB, ol_size ) ); + /* Scale down the overlapped signal */ + Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[add( ol_size, N_ZERO_NB )], 23170, sub( N_Z_L_NB, ol_size ) ); - /* Common Overlapping */ - common_overlapping_fx( auOut_fx, ImdctOutWin_fx, OldauOut_fx, N_Z_L_NB, N_ZERO_NB, 0, N_ZERO_NB, L, N_Z_L_NB ); - Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); + /* Common Overlapping */ + common_overlapping_fx( auOut_fx, ImdctOutWin_fx, OldauOut_fx, N_Z_L_NB, N_ZERO_NB, 0, N_ZERO_NB, L, N_Z_L_NB ); + Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - return; - } + return; +} #endif #ifdef ADD_IVAS_HQ_CODE_FEC - /*-------------------------------------------------------------------------- - * save_synthesis_hq_fec() - * - * Save synthesis for HQ FEC - *-------------------------------------------------------------------------*/ - - void save_synthesis_hq_fec( - Decoder_State * st, /* i/o: decoder state structure */ - const float *output, /* i : decoded synthesis */ - const int16_t output_frame, /* i : decoded synthesis */ - CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ - ) - { - int16_t post_hq_delay; - - switch ( st->element_mode ) - { - case EVS_MONO: - post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS ); - break; - case IVAS_SCE: +/*-------------------------------------------------------------------------- + * save_synthesis_hq_fec() + * + * Save synthesis for HQ FEC + *-------------------------------------------------------------------------*/ + +void save_synthesis_hq_fec( + Decoder_State *st, /* i/o: decoder state structure */ + const float *output, /* i : decoded synthesis */ + const int16_t output_frame, /* i : decoded synthesis */ + CPE_DEC_HANDLE hCPE /* i : CPE decoder structure */ +) +{ + int16_t post_hq_delay; + + switch ( st->element_mode ) + { + case EVS_MONO: + post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS ); + break; + case IVAS_SCE: + post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + break; + case IVAS_CPE_DFT: + if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + { post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - break; - case IVAS_CPE_DFT: - if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) - { - post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - } - else - { - post_hq_delay = 0; - } - break; - default: + } + else + { post_hq_delay = 0; - break; - } + } + break; + default: + post_hq_delay = 0; + break; + } - if ( ( st->codec_mode == MODE1 && st->hTcxDec != NULL ) && ( ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) ) || st->core == HQ_CORE ) ) + if ( ( st->codec_mode == MODE1 && st->hTcxDec != NULL ) && ( ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) ) || st->core == HQ_CORE ) ) + { + mvr2r( st->hTcxDec->synth_history + output_frame, st->hTcxDec->synth_history, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); + mvr2r( output, st->hTcxDec->old_synthFB + output_frame - post_hq_delay, output_frame ); + + if ( st->element_mode == EVS_MONO ) { - mvr2r( st->hTcxDec->synth_history + output_frame, st->hTcxDec->synth_history, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); - mvr2r( output, st->hTcxDec->old_synthFB + output_frame - post_hq_delay, output_frame ); + /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill + this buffer are not available for all cases, the impact on the output is limited */ + set_f( st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, 0.f, post_hq_delay ); + if ( output_frame >= L_FRAME16k ) + { + mvr2r( st->prev_synth_buffer, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + } + else + { + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + } - if ( st->element_mode == EVS_MONO ) + if ( st->core != ACELP_CORE ) { - /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill - this buffer are not available for all cases, the impact on the output is limited */ - set_f( st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, 0.f, post_hq_delay ); if ( output_frame >= L_FRAME16k ) { - mvr2r( st->prev_synth_buffer, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - } - else - { + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } - - if ( st->core != ACELP_CORE ) + else { - if ( output_frame >= L_FRAME16k ) - { - mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - } - else - { - mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - } + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } } - else + } + else + { + if ( st->core != ACELP_CORE ) { - if ( st->core != ACELP_CORE ) - { - mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, post_hq_delay ); - mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - } + mvr2r( st->delay_buf_out, st->hTcxDec->old_synthFB + 2 * output_frame - post_hq_delay, post_hq_delay ); + mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } } - - return; } + + return; +} #endif diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 7d75f0029e5deca8e1b070c487aa12ade6225207..d31fa5a7f0320a88bcfcb7eefada2db4d5f4f9a8 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "rom_dec.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" @@ -3280,7 +3279,7 @@ static void rec_wtda_fx( p_ecu++; } - timesh = NS2SA_fx2( fs, 10000000L - PH_ECU_ALDO_OLP2_NS ); + timesh = NS2SA_FX2( fs, 10000000L - PH_ECU_ALDO_OLP2_NS ); move16(); set16_fx( rec_buf, 0, output_frame ); diff --git a/lib_dec/FEC_adapt_codebook_fx.c b/lib_dec/FEC_adapt_codebook_fx.c index 63c5559c055275cea9a579ceae4c14e6e716b477..d6aec88404e2ecee34b8437376f9d46bb259e021 100644 --- a/lib_dec/FEC_adapt_codebook_fx.c +++ b/lib_dec/FEC_adapt_codebook_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_dec.h" /* Decoder static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_dec.h" /* Decoder static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*---------------------------------------------------------------------* @@ -119,7 +118,7 @@ Word16 FEC_SinOnset_fx( exp2 = add( sub( exp2, 15 ), Q_exc ); /* from Q15 to Q_exc */ /* Find if rescaling needed */ - tmp = extract_h( L_mult( H_low[2], gain ) ); + tmp = extract_h( L_mult( h_low_fx[2], gain ) ); exp_gain = norm_s( tmp ); tmp = sub( exp_gain, exp2 ); /* difference */ @@ -132,7 +131,7 @@ Word16 FEC_SinOnset_fx( /* Generate the scaled pulse */ FOR( i = 0; i < MODE1_L_FIR_FER; i++ ) { - L_tmp = L_mult( gain, H_low[i] ); /* Q_exc*Q15 -> Q_exc */ + L_tmp = L_mult( gain, h_low_fx[i] ); /* Q_exc*Q15 -> Q_exc */ H_low_s[i] = round_fx( L_shl( L_tmp, exp2 ) ); move16(); } diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 9591807b7559a4f48a47878fe845663dc16d00b8..0c668df55ed762c801f29b4473adc0b24dde0e97 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /*-------------------------------------------------------------------* diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index a029f1dfd771fb32e053bcceef31cdf482391749..7353f8f83b03b8a852ab8800343b0a060b26ec17 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -3,12 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Common static table prototypes */ -#include "rom_dec.h" /* Decoder static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Common static table prototypes */ +#include "rom_dec.h" /* Decoder static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index 21efc90e7cc38a906e3bb821e2441909ea3c7243..d79d90c8512625ce85c5a9e3e8664736befcb40e 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 1305f1373009e57add9801f6b852ac504bf96b79..d12c4b30ac591fc9af7de282ee0ebbe9cfbf5a53 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 9a8da8454af1eedae4e9333ef1368cb17bd50c69..8448695c1fc517838e124cb175bcefee213d3d2e 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c index da0fa66ded2c4a6c6ce84869c37902b3e797fc30..cffd1a42ef6fb427af4589c3b51f1edd827a6ed6 100644 --- a/lib_dec/LD_music_post_filter.c +++ b/lib_dec/LD_music_post_filter.c @@ -40,6 +40,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx.h" #include "wmc_auto.h" /*-------------------------------------------------------------------* @@ -746,7 +747,7 @@ void music_postfilt_init_flt( set_f( hMusicPF->dct_post_old_exc, 0, DCT_L_POST - OFFSET2 ); #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word16( hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2 ); + set16_fx( hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2 ); #endif #ifndef IVAS_FLOAT_FIXED @@ -764,7 +765,7 @@ void music_postfilt_init_flt( hMusicPF->LDm_thres[3] = TH_3_MIN; #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word16( hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT ); + set16_fx( hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT ); hMusicPF->LDm_thres_fx[0] = TH_0_MIN_FX << 1; hMusicPF->LDm_thres_fx[1] = TH_1_MIN_FX << 1; hMusicPF->LDm_thres_fx[2] = TH_2_MIN_FX << 1; diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 454e59ddd3d4d1c9e089575bad50bb03dd558381..02f6293176830b9018a5289d75d72703444ea0aa 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index c3224a0998d1adb968a05a4bf0b4a5c22ef40f15..6ef4f65da364e4cd6b7a4f479fb62d64efcb53af 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -7,16 +7,12 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "cnst.h" #include "rom_basop_util.h" #include "rom_com.h" #include "basop_util.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#endif /*---------------------------------------------------------------------* diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index c0267b47f93660e6582e0dafb32b07ec19550508..75c61452a904df7c8794776453d04d659c2c253d 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -42,8 +42,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -233,7 +232,11 @@ ivas_error acelp_core_dec( st->hGSCDec->Last_frame_ener = (float) MAX_32; } +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if ( st->hFdCngDec != NULL && ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) ) +#else if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) ) +#endif { set_zero( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, FFTLEN ); set_zero( hStereoCng->olapBufferSynth22, FFTLEN ); diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index c3cf9be3b05ec2c1dd87855be901d29e1bff9399..024e8f1e2d30c2322c6b71a4166e58b8c3fbec97 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -4,10 +4,9 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" #include "ivas_cnst.h" /* Common constants */ #include "cnst.h" /* Common constants */ @@ -265,7 +264,11 @@ ivas_error acelp_core_dec_fx( move32(); } #ifdef IVAS_CODE +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if ( st->hFdCngDec != NULL && ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) ) +#else if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) ) +#endif { set_zero( st->hFdCngDec->hFdCngCom->olapBufferSynth2, FFTLEN ); set_zero( hStereoCng->olapBufferSynth22, FFTLEN ); @@ -985,7 +988,7 @@ ivas_error acelp_core_dec_fx( Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; /* SC-VBR - PPP frames */ - IF( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1008,7 +1011,7 @@ ivas_error acelp_core_dec_fx( } ELSE { - IF( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ), IVAS_ERR_OK ) ) { return error; } @@ -1534,8 +1537,10 @@ ivas_error acelp_core_dec_fx( } } } +#endif } +#ifdef IVAS_CODE if ( !st->cna_dirac_flag ) { if ( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && !( st->last_coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || st->last_core == AMR_WB_CORE ) ) @@ -1557,20 +1562,21 @@ ivas_error acelp_core_dec_fx( } } #else - IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) - { - generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); - } - ELSE IF( st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) + IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) + { + generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + ELSE IF( st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) + { + FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { - FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) - { - syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); - move16(); - } + syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); + move16(); } } +#endif +#ifndef IVAS_CODE IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && st_fx->last_flag_cna == 1 && ( ( st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) || st_fx->last_core == AMR_WB_CORE ) ) { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) @@ -1587,6 +1593,7 @@ ivas_error acelp_core_dec_fx( } #endif } + /*----------------------------------------------------------------* * Resample to the output sampling rate (8/16/32/48 kHz) * Bass post-filter @@ -1667,7 +1674,7 @@ ivas_error acelp_core_dec_fx( /* set NB mask for upsampling */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); } - ELSE if ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) + ELSE IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 422d9c5c6d37379a524cd0a387941bd32b90bf29..9d715d30b75f7e75b6784e37fca9b79acd0a5323 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -40,8 +40,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -141,7 +140,7 @@ ivas_error acelp_core_dec_ivas_fx( #endif Word16 bpf_error_signal_16fx[L_FRAME16k]; #ifdef MSAN_FIX - set_s( bpf_error_signal_16fx, 0, L_FRAME16k ); + set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k ); #endif Word16 tmp; @@ -177,16 +176,24 @@ ivas_error acelp_core_dec_ivas_fx( FdCng_decodeSID_ivas_fx( st ); rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); } +#ifdef IVAS_ENH32_CADENCE_CHANGES + FOR( i = 0; i < NPART; i++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), + STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); + move32(); + } +#else FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); move32(); } - +#endif ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); - IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; @@ -210,8 +217,8 @@ ivas_error acelp_core_dec_ivas_fx( Copy( lsp_new_fx, st->lsp_old_fx, M ); } - set_s( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ - set_s( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ pop_wmops(); @@ -239,7 +246,7 @@ ivas_error acelp_core_dec_ivas_fx( LSF_Q_prediction = -1; move16(); - set_s( syn_tmp_fx, 0, L_SUBFR ); + set16_fx( syn_tmp_fx, 0, L_SUBFR ); psyn_fx = syn_tmp_fx + L_SUBFR; syn1_tmp_fx[0] = 0; move16(); @@ -253,7 +260,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) + test(); + test(); + IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st->bpf_off = 1; @@ -273,6 +282,7 @@ ivas_error acelp_core_dec_ivas_fx( } } + test(); IF( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ @@ -282,10 +292,15 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || EQ_32( st->last_core_brate, FRAME_NO_DATA ) ) ) +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + test(); + IF( st->hFdCngDec != NULL && ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) ) +#else + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) ) +#endif { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); - set_s( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); } st->clas_dec = st->last_good; @@ -305,7 +320,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - set_s( old_exc2_fx, 0, L_EXC_MEM ); + set16_fx( old_exc2_fx, 0, L_EXC_MEM ); } exc2_fx = old_exc2_fx + L_EXC_MEM; @@ -327,7 +342,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); st->relax_prev_lsf_interp = 0; move16(); - set_s( gain_buf_fx, 0, NB_SUBFR16k ); + set16_fx( gain_buf_fx, 0, NB_SUBFR16k ); IF( EQ_16( st->L_frame, L_FRAME ) ) { @@ -353,7 +368,7 @@ ivas_error acelp_core_dec_ivas_fx( } test(); /* reset post-filter in case of switching */ - IF( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) + if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) { st->hPFstat->reset = 1; move16(); @@ -363,7 +378,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - IF( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) + if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -387,7 +402,7 @@ ivas_error acelp_core_dec_ivas_fx( tdm_low_rate_mode = 0; move16(); test(); - IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) + if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); @@ -402,7 +417,7 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------*/ test(); test(); - IF( NE_16( st->last_L_frame, st->L_frame ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) + IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { Word16 dec; @@ -435,12 +450,12 @@ ivas_error acelp_core_dec_ivas_fx( { Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } - set_s( st->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ dec = DEC; move16(); - IF( NE_16( st->element_mode, EVS_MONO ) ) + if ( st->element_mode != EVS_MONO ) { dec = DEC_IVAS; move16(); @@ -486,23 +501,25 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - move16(); Word16 exp = 0; + move16(); IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { tmpF_fx = 16384; + move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { tmpF_fx = 20480; + move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ { tmpF_fx = 20480; // Q14 + move16(); exp = 1; move16(); } - move16(); FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); @@ -525,50 +542,56 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->L_frame, L_FRAME ) ) { - move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 13107; + move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 16384; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { tmpF_fx = 26214; + move16(); } st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); + move16(); st->bfi_pitch_frame = L_FRAME; move16(); } ELSE { - move16(); Word16 exp = 0; + move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { tmpF_fx = 16384; + move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { tmpF_fx = 20480; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { tmpF_fx = 20480; // Q14 + move16(); exp = 1; move16(); } - move16(); st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); + move16(); st->bfi_pitch_frame = L_FRAME16k; move16(); } } test(); test(); - IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) + if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) { st->rate_switching_reset = 1; move16(); @@ -599,13 +622,14 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->idchan, 0 ) && !( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + IF( GT_16( st->element_mode, EVS_MONO ) && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { test(); test(); - IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + if ( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { - st->GSC_IVAS_mode = get_next_indice( st, 2 ); + st->GSC_IVAS_mode = get_next_indice_fx( st, 2 ); + move16(); } } @@ -613,10 +637,10 @@ ivas_error acelp_core_dec_ivas_fx( * Decoding of inactive CNG frames *----------------------------------------------------------------*/ test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) + IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) @@ -632,7 +656,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - IF( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) + if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) { local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ move16(); @@ -641,10 +665,11 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - + test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; + move16(); FdCng_decodeSID_ivas_fx( st ); rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); @@ -656,23 +681,36 @@ ivas_error acelp_core_dec_ivas_fx( { assert( nchan_out == 1 ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + FOR( i = 0; i < NPART; i++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), + STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); + move32(); + } +#else FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); move32(); } +#endif Word16 new_sidNoiseEstExp = 31 - Q4; - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); + move16(); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; + move16(); Word16 new_cngNoiseLevelExp = 31 - Q4; + move16(); Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; + move16(); ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; @@ -684,7 +722,8 @@ ivas_error acelp_core_dec_ivas_fx( { Word32 noise_lvl_highest_fx; - noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1]; + noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[sub( sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ), 1 )]; + move32(); FOR( Word16 b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; @@ -692,7 +731,7 @@ ivas_error acelp_core_dec_ivas_fx( } } - generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); + generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); @@ -820,7 +859,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( st->hTdCngDec != NULL && ( EQ_32( st->last_core_brate, FRAME_NO_DATA ) || EQ_32( st->last_core_brate, SID_2k40 ) ) ) + IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { Copy( st->lspCNG_fx, st->lsp_old_fx, M ); lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); @@ -833,10 +872,10 @@ ivas_error acelp_core_dec_ivas_fx( IF( !st->use_acelp_preq ) { st->mem_preemp_preQ_fx = 0; - st->last_nq_preQ = 0; - st->last_code_preq = 0; move16(); + st->last_nq_preQ = 0; move16(); + st->last_code_preq = 0; move16(); } st->use_acelp_preq = 0; @@ -861,7 +900,7 @@ ivas_error acelp_core_dec_ivas_fx( { Word16 beta_index; - beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); + beta_index = get_next_indice_fx( st, TDM_IC_LSF_PRED_BITS ); tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index ); } ELSE @@ -878,12 +917,10 @@ ivas_error acelp_core_dec_ivas_fx( } pt_interp_2_fx = interpol_frac_fx; - move16(); test(); - IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) + if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) { pt_interp_2_fx = interpol_frac2_fx; - move16(); } IF( EQ_16( st->active_cnt, 1 ) ) @@ -896,1096 +933,1038 @@ ivas_error acelp_core_dec_ivas_fx( int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 ); /* Check LSF stability (distance between old LSFs and current LSFs) */ st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); + move16(); } #ifndef MSAN_FIX for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) - { #else FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif - { - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; - move16(); - } - test(); - IF( EQ_16( st->last_core, HQ_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) - { - /* Prepare ACB memory from last HQ frame */ - old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; - tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = old_exc_s_fx[st->L_frame - 1]; - preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); - Copy( old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); - Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); + { + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); + Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + move16(); + } + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; + tmpF_fx = *old_exc_s_fx; + st->mem_deemph_fx = old_exc_s_fx[sub( st->L_frame, 1 )]; + move16(); + PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); + Copy( old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M ); + Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 ); #ifdef FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR - Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); + Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); #endif + } + test(); + IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); } - test(); - IF( NE_16( st->last_core, ACELP_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) + ELSE { - /* Prepare ACB memory of old_bwe_exc */ - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); - } - ELSE - { - lerp( old_exc_fx, old_bwe_exc_fx, shl( L_EXC_MEM_DEC, 1 ), L_EXC_MEM_DEC ); - } + lerp( old_exc_fx, old_bwe_exc_fx, shl( L_EXC_MEM_DEC, 1 ), L_EXC_MEM_DEC ); } + } - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * FEC - first good frame after lost frame(s) (possibility to correct the ACB) + *-----------------------------------------------------------------*/ - IF( st->acelp_cfg.FEC_mode > 0 ) + IF( st->acelp_cfg.FEC_mode > 0 ) + { + last_pulse_pos = 0; + move16(); + /* decode the last glottal pulse position */ + T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); + test(); + test(); + IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) { - last_pulse_pos = 0; - move16(); - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); test(); test(); - IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->clas_dec, SIN_ONSET ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->prev_bfi, 1 ) ) - { - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); - } - ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) - { - do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); - } + FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); + } + ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) + { + do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); } } + } - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) - { - int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } + /*------------------------------------------------------------* + * In case of first frame after an erasure and transition from voiced to unvoiced or inactive + * redo the LPC interpolation + *------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) + { + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + } - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ + /*---------------------------------------------------------------* + * Decoding of the scaled predicted innovation energy + *---------------------------------------------------------------*/ - IF( GT_16( nb_bits, 0 ) ) + IF( nb_bits > 0 ) + { + indice = get_next_indice_fx( st, nb_bits ); + Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); + } + + /*------------------------------------------------------------* + * Decode excitation according to coding type + *------------------------------------------------------------*/ + test(); + test(); + IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + IF( LE_16( st->coder_type, UNVOICED ) ) { - indice = get_next_indice( st, nb_bits ); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); + tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - test(); - test(); - IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + ELSE /* GENERIC */ { - IF( LE_16( st->coder_type, UNVOICED ) ) + decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + + if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - ELSE /* GENERIC */ - { - decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } - } - ELSE IF( st->nelp_mode_dec ) - { - /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - /* SC-VBR - NELP frames */ - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) + } + ELSE IF( st->nelp_mode_dec ) + { + /* SC-VBR - NELP frames */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); + /* SC-VBR - NELP frames */ + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) + { + /* UNVOICED frames */ + decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + ELSE IF( st->ppp_mode_dec ) + { + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); + /* SC-VBR - PPP frames */ + IF( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) { - /* UNVOICED frames */ - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + return error; } - ELSE IF( st->ppp_mode_dec ) - { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - /* SC-VBR - PPP frames */ - IF( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) + { + decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); + } + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx +#if 1 // def ADD_LRTD + , + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx +#endif + ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + ELSE + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) { - decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); + return error; } - ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + + if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx -#if 1 // def ADD_LRTD - , - tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx -#endif - ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) - { - return error; - } + } - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + + /* save and delay synthesis to be used by SWB BWE */ + IF( st->hBWE_FD != NULL ) + { + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + /*-----------------------------------------------------------------* + * Apply energy matching when switching to inactive frames + *-----------------------------------------------------------------*/ - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } + Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ + /*------------------------------------------------------------* + * Decode information and modify the excitation signal of stationary unvoiced frames + *------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + { + stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + } - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + /*------------------------------------------------------------* + * Save filter memory in case the synthesis is redone after scaling + * Synthesis at 12k8 Hz sampling rate + *------------------------------------------------------------*/ - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - test(); + /* update past excitation signals for LD music post-filter */ + IF( st->hMusicPF != NULL ) + { + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + } + + test(); + test(); + test(); + IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) + { + Word16 last_coder_type = st->last_coder_type; + move16(); test(); test(); test(); - IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) { - stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + last_coder_type = AUDIO; + move16(); } - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ + Word16 qdct = 0; + move16(); + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) + /* LD music post-filter */ + LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + + /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, + &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, + &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); + } + ELSE + { + /* Core synthesis at 12.8kHz or 16kHz */ + i = 1; + move16(); + if ( st->coder_type == INACTIVE ) { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, sub( sub( DCT_L_POST, L_FRAME ), OFFSET2 ) ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub( DCT_L_POST, OFFSET2 ) ); + i = 0; + move16(); } + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); test(); test(); - test(); - - IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { - Word16 last_coder_type = st->last_coder_type; + k = 1; move16(); - test(); - test(); - test(); - IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) - { - last_coder_type = AUDIO; - move16(); - } + } - Word16 qdct = 0; - move16(); - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - /* LD music post-filter */ - LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, - &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, - &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); - } - ELSE + IF( st->hMusicPF != NULL ) { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - if ( EQ_16( st->coder_type, INACTIVE ) ) - { - i = 0; - move16(); - } - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + FOR( i = 0; i < DCT_L_POST; i++ ) { - k = 1; + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } + } + } - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); + /*------------------------------------------------------------* + * FEC - Estimate the classification information + *------------------------------------------------------------*/ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, + psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, + NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, + st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, + 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); + /*------------------------------------------------------------* + * FEC - Estimate pitch + *------------------------------------------------------------*/ - IF( st->hMusicPF != NULL ) - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - } - } - } - - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, - psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx, - st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, - 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ - - FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, - &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - move16(); - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - test(); - test(); - test(); - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - } - } - - } /* End of GOOD FRAME */ + FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, + &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ - ELSE - { - /* SC-VBR */ - if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) - { - st->nelp_mode_dec = 1; - move16(); - } + move16(); + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + test(); test(); test(); test(); - /* long burst frame erasures */ - IF( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - st->last_good = VOICED_TRANSITION; - move16(); + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); } + } - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); + } /* End of GOOD FRAME */ + + /*----------------------------------------------------------------* + * BAD frame + *----------------------------------------------------------------*/ - FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); + ELSE + { + /* SC-VBR */ + if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) + { + st->nelp_mode_dec = 1; + move16(); + } + test(); + test(); + /* long burst frame erasures */ + if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) + { + st->last_good = VOICED_TRANSITION; + move16(); + } + + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); + + FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); #ifndef MSAN_FIX - for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) - { + for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) #else FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) - { #endif - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; - move16(); - } - IF( EQ_16( st->nelp_mode_dec, 1 ) ) - { - /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); - st->Q_exc = 0; - move16(); - - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - FEC_pitch_fx = pitch_buf_fx[3]; - move16(); - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE - { - /* calculation of excitation signal */ - FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); + { + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); + Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + move16(); + } + IF( EQ_16( st->nelp_mode_dec, 1 ) ) + { + /* SC-VBR */ + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + st->Q_exc = 0; + move16(); - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, - &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + FEC_pitch_fx = pitch_buf_fx[3]; + move16(); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); + } + ELSE + { + /* calculation of excitation signal */ + FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, + &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); - /* SC-VBR */ - st->prev_gain_pit_dec_fx = st->lp_gainp_fx; - move16(); - } + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + /* SC-VBR */ + st->prev_gain_pit_dec_fx = st->lp_gainp_fx; + move16(); + } - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); - /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + /* save and delay synthesis to be used by SWB BWE */ + IF( st->hBWE_FD != NULL ) + { + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) - { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + /* Apply energy matching when switching to inactive frames */ + Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_shl( 1228, ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; i < MAX_LT; i++ ) - { - st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; - move16(); - } - } + /* update past excitation signals for LD music post-filter */ + IF( st->hMusicPF != NULL ) + { + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + /* Update music post processing values */ + /* Filter energies update */ + FOR( i = 0; i < DCT_L_POST; i++ ) { - k = 1; + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_shl( 1228, ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } - - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); - test(); - IF( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + /* Update circular buffer, keep last energy difference unchanged */ + FOR( i = 1; i < MAX_LT; i++ ) { - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; + move16(); } - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + } - /* update buffer for classifier */ - IF( st->hWIDec != NULL ) - { - Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); - Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); - } - st->prev_Q_exc_fr = st->Q_exc; - st->prev_Q_syn_fr = st->Q_syn; - move16(); + /* synthesis at 12k8 Hz sampling rate */ + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ + Word16 k = 0; + move16(); + test(); + test(); + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + { + k = 1; move16(); - Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + } - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - test(); - IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + } + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - } + /* update buffer for classifier */ + IF( st->hWIDec != NULL ) + { + Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); + Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); + } + st->prev_Q_exc_fr = st->Q_exc; + move16(); + st->prev_Q_syn_fr = st->Q_syn; + move16(); + Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); - IF( NE_16( st->nelp_mode_dec, 1 ) ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, - &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, - &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); - } + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); } - IF( st->hBWE_TD != NULL ) + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + + IF( NE_16( st->nelp_mode_dec, 1 ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } + /* modify the excitation signal of stationary unvoiced frames */ + stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, + &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, + &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); } + } - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - test(); - IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + IF( st->hBWE_TD != NULL ) + { + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); - IF( EQ_16( st->bwidth, NB ) ) - { - st->hPFstat->on = 1; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); - } - ELSE - { - st->hPFstat->on = 0; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); - } + Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } + } - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); - unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); - Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); - IF( st->hTcxDec != NULL ) + /*--------------------------------------------------------* + * Apply NB postfilter in case of 8kHz output + *--------------------------------------------------------*/ + test(); + IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + { + Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); + IF( EQ_16( st->bwidth, NB ) ) { - Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ + st->hPFstat->on = 1; + move16(); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); } - Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || GT_16( st->element_mode, EVS_MONO ) ) && LE_32( st->core_brate, ACELP_32k ) ) + ELSE { - st->hPFstat->on = 1; + st->hPFstat->on = 0; move16(); - /*----ftf conversions---*/ - Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); + } + } + ELSE + { + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); + move16(); + } - set16_fx( st->hPFstat->mem_zero, 0, M ); + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ - formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); - } - ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) - { - IF( st->hPFstat->on ) - { + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + Copy( psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); + unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); + Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); + IF( st->hTcxDec != NULL ) + { + Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ + } + Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ - Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); - Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); + /*------------------------------------------------------------------* + * Formant post-filter + *-----------------------------------------------------------------*/ - Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); - blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); - } - st->hPFstat->on = 0; - move16(); + test(); + test(); + test(); + test(); + IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) ) + { + st->hPFstat->on = 1; + move16(); + /*----ftf conversions---*/ + Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); + + set16_fx( st->hPFstat->mem_zero, 0, M ); + + formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); + } + ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) + { + IF( st->hPFstat->on ) + { + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); + Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); + + Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); + Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); + blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); } + st->hPFstat->on = 0; + move16(); + } - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ + /*----------------------------------------------------------------* + * Comfort noise addition + *----------------------------------------------------------------*/ + test(); + test(); + IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + test(); test(); test(); - IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) { + /*VAD only for non inactive frame*/ + st->VAD = st->VAD && st->coder_type != INACTIVE; + test(); test(); test(); test(); test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) + IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) ) { - /*VAD only for non inactive frame*/ - st->VAD = st->VAD && NE_16( st->coder_type, INACTIVE ); - test(); - test(); - test(); - test(); - IF( EQ_16( st->idchan, 0 ) && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) ) - { - /*Noisy speech detector*/ - noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); + /*Noisy speech detector*/ + noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( NE_16( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) - { - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); - move16(); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + move16(); + IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + { + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + move16(); } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ); + move32(); + } + + if ( st->idchan == 0 ) + { + st->lp_noise = st->hFdCngDec->lp_noise; + move32(); + } + test(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) + { + /*Noise estimate*/ - if ( st->idchan == 0 ) + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, Q27 ) ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + move16(); + + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, Q27 ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, Q27 ) ); + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 + move16(); + /*==========================================================*/ + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + /*==========================================================*/ + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) { - st->lp_noise = st->hFdCngDec->lp_noise; - move32(); + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); } - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { - /*Noise estimate*/ - - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27 ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27 ); - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 - /*==========================================================*/ - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - /*==========================================================*/ - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) - { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - } + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); } + } - IF( !st->cna_dirac_flag ) + IF( !st->cna_dirac_flag ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { test(); - test(); - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + IF( hStereoCng->flag_cna_fade ) { - IF( hStereoCng->flag_cna_fade ) - { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 0; - } - ELSE - { - IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) - { - /* Clear memory for secondary channel CNA */ - set_s( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); - } - - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); - } + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 0; + move16(); } - ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE { - IF( st->idchan == 0 ) + IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { - IF( NE_16( st->element_mode, last_element_mode ) ) - { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); + /* Clear memory for secondary channel CNA */ + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); } + + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } } - ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + IF( st->idchan == 0 ) { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 1; - move16(); - } - ELSE - { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + IF( NE_16( st->element_mode, last_element_mode ) ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); - move16(); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } + generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 /*, 0, 0, st->element_mode, hStereoCng, nchan_out*/ ); } } - ELSE + } + ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) + { + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { - if ( hStereoCng != NULL ) - { - hStereoCng->flag_cna_fade = 1; - hStereoCng->enableSecCNA = 0; - move16(); - move16(); - } + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 1; + move16(); } - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + ELSE { - /*Noise estimate*/ - IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) ) ) + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) { - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->partNoiseShape_exp < 0 ) - { - Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); - st->hFdCngDec->partNoiseShape_exp = 0; - } - IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) - { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - } + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } } - } - - IF( !st->cna_dirac_flag ) - { - IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) + ELSE { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + if ( hStereoCng != NULL ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + hStereoCng->flag_cna_fade = 1; + move16(); + hStereoCng->enableSecCNA = 0; move16(); } } - IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - IF( st->idchan == 0 ) - { - set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - IF( hStereoCng != NULL && ( st->idchan == 0 ) ) + test(); + test(); + test(); + /*Noise estimate*/ + IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) { - set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); + ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); + } + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) + { + Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); + st->hFdCngDec->partNoiseShape_exp = 0; + move16(); + } + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); + } } } } } - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - /* check if the CLDFB works on the right sample rate */ - IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) + IF( !st->cna_dirac_flag ) { - resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - - IF( st->ini_frame > 0 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + { + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + move16(); + } } - } - /* analyze pitch coherence for bass post-filter */ - - Word32 pitch_buf_fx_q20[12]; - - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); - Word16 lim = shr( st->L_frame, 6 ); - FOR( Word16 lp = 0; lp < lim; lp++ ) - { - pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); - move32(); - } - bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); - - - IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) - { test(); - IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) + test(); + test(); + IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) + IF( st->idchan == 0 ) { - retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } - ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) + IF( hStereoCng != NULL && ( st->idchan == 0 ) ) { - retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); } } + } + } + + /*----------------------------------------------------------------* + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ + + /* check if the CLDFB works on the right sample rate */ + IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) + { + resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, - st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + IF( st->ini_frame > 0 ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); } + } + + /* analyze pitch coherence for bass post-filter */ - Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; - set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); - syn_32_fx = syn_tmp_32_fx + L_SUBFR; + Word32 pitch_buf_fx_q20[12]; + + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); + Word16 lim = shr( st->L_frame, 6 ); + FOR( Word16 lp = 0; lp < lim; lp++ ) + { + pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); + move32(); + } + bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); + + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) + { test(); - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) + IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) { - /* analysis of the synthesis at internal sampling rate */ - Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + } + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - pRealSave_fx[i] = realBufferSave_fx[i]; - pImagSave_fx[i] = imagBufferSave_fx[i]; + retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); } + } + + bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, + st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + } + + Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; + set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); + syn_32_fx = syn_tmp_32_fx + L_SUBFR; + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) + { + /* analysis of the synthesis at internal sampling rate */ + Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + pRealSave_fx[i] = realBufferSave_fx[i]; + pImagSave_fx[i] = imagBufferSave_fx[i]; + } #ifndef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - IF( st->p_bpf_noise_buf_32 ) - { + IF( st->p_bpf_noise_buf_32 ) + { #ifdef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } #ifdef MSAN_FIX - FOR( i = 0; i < st->L_frame; i++ ) + FOR( i = 0; i < st->L_frame; i++ ) #else for ( i = 0; i < L_FRAME16k; i++ ) #endif - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 - move32(); - } + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 + move32(); + } - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; - move16(); - cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - /* analysis and add the BPF error signal */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + /* analysis and add the BPF error signal */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - q_bpf_error_signal = Q6; - move16(); + q_bpf_error_signal = Q6; + move16(); #ifdef MSAN_FIX - Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 #else Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 #endif - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - move16(); - tmp = -1; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = -1; + move16(); + if ( st->bpf_off ) + { + tmp = 0; move16(); - IF( st->bpf_off ) - { - tmp = 0; - move16(); - } + } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + /* set output mask for upsampling */ + IF( EQ_16( st->bwidth, NB ) ) + { + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); - /* set output mask for upsampling */ - IF( EQ_16( st->bwidth, NB ) ) - { - /* set NB mask for upsampling */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); - } - ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) - { - /* in case of BW switching, re-init to default */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - } - test(); - IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - /*WB/SWB-FD_CNG*/ - IF( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LE_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) - { - Word16 tmpBufferScale = 0; - move16(); - generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); - - /* Fixed to float */ - FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) - { - Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - } - - IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); - } - ELSE - { - st->cldfbSyn->bandsToZero = 0; - move16(); - } - } - } - - IF( save_hb_synth_fx16 != NULL ) - { - /* save and then zero-out lowband */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; - move16(); - move16(); - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } - } - Word32 max_val = max( max_real, max_imag ); - Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; - Q_real = Q_imag; - move16(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); - } - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); - - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBufferSave_fx[i][j] = realBuffer_fx[i][j]; - imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; - move32(); - move32(); - IF( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots ) - { - realBuffer_fx[i][j] = 0; - imagBuffer_fx[i][j] = 0; - move32(); - move32(); - } - } - } - - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - - Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 - Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - /* restore lowband */ - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBuffer_fx[i][j] = realBufferSave_fx[i][j]; - imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; - move32(); - move32(); - } - } - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - } - ELSE + } + ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); + } + test(); + IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + test(); + test(); + /*WB/SWB-FD_CNG*/ + IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) { - /* synthesis of the combined signal */ - Word16 Q_real = 0, Q_imag = 0; - Word32 max_real = 0, max_imag = 0; + Word16 tmpBufferScale = 0; move16(); - move16(); - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); + + /* Fixed to float */ + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } + Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 + Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 } - Word32 max_val = max( max_real, max_imag ); - Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; - Q_real = Q_imag; - move16(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + + IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); + move16(); + } + ELSE + { + st->cldfbSyn->bandsToZero = 0; + move16(); } - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) - st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); -#ifndef MSAN_FIX - Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); -#endif - - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); -#ifdef MSAN_FIX - scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); -#else - Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); -#endif - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); } - - /* save synthesis - needed in case of core switching */ - Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 } - ELSE - { - Word16 nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ - - /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ -#ifndef MSAN_FIX - for ( i = 0; i < L_FRAME16k; i++ ) -#else - FOR( i = 0; i < st->L_frame; i++ ) -#endif - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); - move32(); - } - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; + IF( save_hb_synth_fx16 != NULL ) + { + /* save and then zero-out lowband */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; move16(); - cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); - - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - - // Get Q-factor - q_bpf_error_signal = Q6; move16(); - Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + move32(); + move32(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + Word32 max_val = L_max( max_real, max_imag ); + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; + Q_real = Q_imag; move16(); - tmp = 0; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); + } + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); - if ( !st->bpf_off ) + Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); + + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - tmp = nSamples; - move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBufferSave_fx[i][j] = realBuffer_fx[i][j]; + imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; + move32(); + move32(); + IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) ) + { + realBuffer_fx[i][j] = 0; + imagBuffer_fx[i][j] = 0; + move32(); + move32(); + } + } } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; - /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + /* restore lowband */ + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBuffer_fx[i][j] = realBufferSave_fx[i][j]; + imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + move32(); + move32(); + } + } + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); + move16(); + cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); + Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + } + ELSE + { + /* synthesis of the combined signal */ Word16 Q_real = 0, Q_imag = 0; Word32 max_real = 0, max_imag = 0; move16(); @@ -1996,11 +1975,11 @@ ivas_error acelp_core_dec_ivas_fx( { FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); } } - Word32 max_val = max( max_real, max_imag ); + Word32 max_val = L_max( max_real, max_imag ); Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; Q_real = Q_imag; move16(); @@ -2010,192 +1989,293 @@ ivas_error acelp_core_dec_ivas_fx( scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); } scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) + st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); + move16(); #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); - + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); + scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); #else - Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; move16(); - IF( st->p_bpf_noise_buf_32 ) - { - Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); - } - - set_l( synth_fx, 0, output_frame ); } - /* Copy output signal */ + /* save synthesis - needed in case of core switching */ + Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 + } + ELSE + { + Word16 nSamples = NS2SA( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + + /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX - Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); + for ( i = 0; i < L_FRAME16k; i++ ) #else - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); + FOR( i = 0; i < st->L_frame; i++ ) #endif - IF( GT_16( st->element_mode, EVS_MONO ) ) { - Copy( psyn_fx, output_fx, st->L_frame ); + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); + move32(); + } + + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); + + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + + // Get Q-factor + q_bpf_error_signal = Q6; + move16(); + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = 0; + move16(); + if ( !st->bpf_off ) + { + tmp = nSamples; + move16(); } + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + - st->Q_syn2 = 0; + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; move16(); - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz - *-----------------------------------------------------------------*/ - IF( st->hBWE_zero != NULL ) + /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + Word16 Q_real = 0, Q_imag = 0; + Word32 max_real = 0, max_imag = 0; + move16(); + move16(); + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } + } + Word32 max_val = L_max( max_real, max_imag ); + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; + Q_real = Q_imag; + move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + } + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) +#ifndef MSAN_FIX + Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); +#endif + + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); + +#ifdef MSAN_FIX + Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); +#else + Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); +#endif + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + st->cldfbSyn->Q_cldfb_state = Q10; + move16(); + IF( st->p_bpf_noise_buf_32 ) + { + Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + } + + set32_fx( synth_fx, 0, output_frame ); + } + + /* Copy output signal */ +#ifndef MSAN_FIX + Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); +#else + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); +#endif + IF( st->element_mode > EVS_MONO ) + { + Copy( psyn_fx, output_fx, st->L_frame ); + } + + st->Q_syn2 = 0; + move16(); + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-7kHz + *-----------------------------------------------------------------*/ + IF( st->hBWE_zero != NULL ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) + { #ifndef FIX_774_ENERGY_BURST - Word16 tmp_exp = 0; - move16(); + Word16 tmp_exp = 0; + move16(); #endif #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif #ifdef FIX_774_ENERGY_BURST - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, - psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, - st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); + hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); #else hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); #endif #ifdef MSAN_FIX - Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); #else Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); #endif #ifndef FIX_774_ENERGY_BURST - IF( st->hBWE_FD != NULL ) - { - st->hBWE_FD->memExp1 = tmp_exp; - move16(); - } - ELSE - { - Scale_sig( st->hBWE_zero->mem_hf_fx, sub( L_FIR, 1 ), -tmp_exp ); - } -#endif + IF( st->hBWE_FD != NULL ) + { + st->hBWE_FD->memExp1 = tmp_exp; + move16(); } ELSE { - hf_synth_reset_fx( st->hBWE_zero ); + Scale_sig( st->hBWE_zero->mem_hf_fx, sub( L_FIR, 1 ), -tmp_exp ); + } +#endif + } + ELSE + { + hf_synth_reset_fx( st->hBWE_zero ); #ifdef MSAN_FIX - set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); + set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); #endif - } } + } - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Populate parameters for SWB TBE + *-----------------------------------------------------------------*/ - IF( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - set_s( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - test(); - test(); - test(); - test(); - test(); - IF( !st->ppp_mode_dec && ( EQ_16( st->idchan, 0 ) || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); - } - test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - } + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + } + test(); + test(); + test(); + test(); + test(); + IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); } - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); test(); - IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) + if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - /* update CNG parameters in active frames */ - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, - st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, - st->hFdCngDec->hFdCngCom->CngBandwidth ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); + } + } + /*----------------------------------------------------------------------* + * Updates + *----------------------------------------------------------------------*/ + + updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); + test(); + test(); + IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) + { + /* update CNG parameters in active frames */ + cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, + st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, + st->hFdCngDec->hFdCngCom->CngBandwidth ); - /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + move16(); + if ( NE_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; move16(); - if ( NE_16( st->L_frame, L_FRAME ) ) - { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; - move16(); - } } + } + { + IF( save_hb_synth_fx16 ) { - IF( save_hb_synth_fx16 ) - { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); - } + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); + } #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif - if ( st->hFdCngDec ) - { - st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; - move16(); - } + if ( st->hFdCngDec ) + { + st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; + move16(); } - - pop_wmops(); - return error; } + pop_wmops(); + return error; +} - static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff ) - { - Scale_sig32( hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff ); - } + +static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff ) +{ + Scale_sig32( hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff ); +} #endif diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 76b8b8ed23a1cfca50c008502fd99089ae63321e..6062659416cd1230efab6461e4506f9da3c4022d 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -3,12 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "prot.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes @@ -249,9 +248,9 @@ ivas_error acelp_core_switch_dec_fx( IF( !( ( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) { /* Decoding of BWE */ - d1m = (Word16) get_next_indice( st_fx, AUDIODELAYBITS ); + d1m = (Word16) get_next_indice_fx( st_fx, AUDIODELAYBITS ); move16(); - ind1 = (Word16) get_next_indice( st_fx, NOOFGAINBITS1 ); + ind1 = (Word16) get_next_indice_fx( st_fx, NOOFGAINBITS1 ); move16(); gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr( DELTAOFFIRSTGAIN_FX, 3 ) ); /*Q13*/ decode_bwe = 1; @@ -317,10 +316,10 @@ ivas_error acelp_core_switch_dec_fx( move16(); } - i = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ); + i = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ); move16(); Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); - set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2( st_fx->output_Fs, 10000000L ) - i ); + set16_fx( hb_synth_tmp + i, 0, NS2SA_FX2( st_fx->output_Fs, 10000000L ) - i ); fir_fx( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, shr( output_frame, 1 ), fdelay, 1, 0 ); set16_fx( tmp_synth_bwe, 0, SWITCH_MAX_GAP ); @@ -849,9 +848,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 ); Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); - /* output to Q0 */ - Copy_Scale_sig32_16( syn32, synth_out, L_FRAME16k, -5 ); - // Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 895af08609696bfc74683c1b503a75dbc68dc0d8..29b2e5a265eb496118a239e4552a41477825b33a 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -43,7 +43,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif #ifndef IVAS_FLOAT_FIXED diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index e1ffd2adf57b5ac0245601ea39f5807f5214d433..132322c061d529d101f9cf96e888c6eab3039816 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -6,8 +6,7 @@ #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -194,7 +193,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->reset = 1; move16(); } - IF( GT_16( st_fx->bfi, 0 ) ) + IF( st_fx->bfi > 0 ) { st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); move16(); @@ -226,7 +225,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( ( st_fx->last_core != 0 ) ) ) + if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -244,7 +243,6 @@ ivas_error amr_wb_dec_fx( /* in case of switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); - IF( st_fx->hPFstat->on ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -353,7 +351,7 @@ ivas_error amr_wb_dec_fx( } /*End of _DIFF_FLOAT_FIX_*/ test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->ini_frame, 0 ) ) + if ( EQ_16( st_fx->last_bwidth, NB ) && st_fx->ini_frame != 0 ) { st_fx->rate_switching_reset = 1; move16(); @@ -385,16 +383,9 @@ ivas_error amr_wb_dec_fx( class_para_fx = 0; move16(); - // has been moved to updt_dec_common_fx() - // if( st_fx->first_CNG == 0 ) - //{ - // st_fx->first_CNG = 1; - // move16(); - //} - delta_mem_scale = 3; move16(); - test(); + if ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; @@ -432,6 +423,7 @@ ivas_error amr_wb_dec_fx( frame_energy_fx( L_FRAME, pitch_temp, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ + move16(); } /* update old synthesis for classification */ Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); @@ -510,6 +502,7 @@ ivas_error amr_wb_dec_fx( /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ L_tmp = Mult_32_16( st_fx->lp_ener_fx, 22938 ); st_fx->lp_ener_fx = L_add( L_tmp, Mult_32_16( L_tmp1, 9830 ) ); /*Q6 + Q6*/ + move32(); FOR( i = 0; i < M; i++ ) { L_tmp = L_mult( 3277, lsp_new_fx[i] ); @@ -539,7 +532,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - IF( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) + if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) { tmp16 = 1; move16(); @@ -582,7 +575,7 @@ ivas_error amr_wb_dec_fx( tmp_coder_type = AUDIO; move16(); test(); - IF( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) + if ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -784,11 +777,11 @@ ivas_error amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( ( GE_16( st_fx->psf_lp_noise_fx, ( 15 << 8 ) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( ( GE_16( st_fx->psf_lp_noise_fx, ( 15 * ONE_IN_Q8 ) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { /*VAD only for non inactive frame*/ test(); - IF( EQ_16( st_fx->VAD, 1 ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( EQ_16( st_fx->VAD, 1 ) && st_fx->coder_type != INACTIVE ) { st_fx->VAD = 1; move16(); @@ -811,7 +804,7 @@ ivas_error amr_wb_dec_fx( noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( NE_16( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) + IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); @@ -838,7 +831,6 @@ ivas_error amr_wb_dec_fx( generate_masking_noise_update_seed_fx( st_fx->hFdCngDec->hFdCngCom ); } - IF( !flag_cna ) { test(); @@ -869,7 +861,7 @@ ivas_error amr_wb_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); - if ( st_fx->ini_frame > 0 ) + IF( st_fx->ini_frame > 0 ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); move16(); @@ -902,6 +894,7 @@ ivas_error amr_wb_dec_fx( { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + move16(); } cldfb_synth_set_bandsToZero( st_fx, realBuffer, imagBuffer, CLDFB_NO_COL_MAX, scaleFactor ); /* CLDFB synthesis of the combined signal */ @@ -968,7 +961,7 @@ ivas_error amr_wb_dec_fx( test(); test(); test(); - test(); + if ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; @@ -1021,7 +1014,7 @@ ivas_error amr_wb_dec_fx( } } - delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( st_fx->Q_syn2, hHQ_core->Q_old_postdec ) ); hHQ_core->Q_old_postdec = st_fx->Q_syn2; move16(); @@ -1037,8 +1030,8 @@ ivas_error amr_wb_dec_fx( i = 15; move16(); - tmps = NS2SA_fx2( st_fx->output_Fs, 6000000L ); - nz = NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, 6000000L ); + nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); step = Inv16( tmps, &i ); step = shl( step, i ); alpha = 0; @@ -1070,7 +1063,7 @@ ivas_error amr_wb_dec_fx( /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); delay_signal( synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); } @@ -1081,7 +1074,7 @@ ivas_error amr_wb_dec_fx( move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); move16(); } @@ -1093,14 +1086,15 @@ ivas_error amr_wb_dec_fx( /* HP filter */ Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); st_fx->Qprev_synth_buffer_fx = st_fx->Q_syn2; + move16(); hp20( synth_out_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /* save synthesis for core switching */ - Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); + Copy_Scale_sig( synth_out_fx + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); { /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ - Word16 delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + Word16 delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); move16(); Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); diff --git a/lib_dec/ari_dec.c b/lib_dec/ari_dec.c index 334e2419594e315e200da434ad9fd96059d08044..e92565f6b4da9e63e1d973be243588f824b0e57f 100644 --- a/lib_dec/ari_dec.c +++ b/lib_dec/ari_dec.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "stat_com.h" #include "basop_util.h" #include "wmc_auto.h" @@ -128,6 +129,7 @@ Word16 ari_start_decoding_14bits_prm_ivas_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------- * ari_decode_14bits_s17_ext_ivas() * @@ -458,6 +460,7 @@ void ari_decode_14bits_bit_ext_ivas( return; } +#endif /*------------------------------------------------------------------------ * Function: ari_decode_14bits_pow_ivas() diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 78d7b799ce1814277729d1619bd2be5130ac69fb..385a50d41830af911c122a4f8ef3f89f03d20b7b 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------- * Ari decode 14 bits routines @@ -31,7 +30,7 @@ void ari_start_decoding_14bits_fx( { Word32 val; - val = L_and( L_deposit_l( get_next_indice( st, cbitsnew ) ), 0xffffL ); + val = L_and( L_deposit_l( get_next_indice_fx( st, cbitsnew ) ), 0xffffL ); s->low = L_deposit_l( 0 ); move32(); @@ -306,7 +305,7 @@ static Word16 ari_decode_14bits_ext_fx( high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); high = L_shl( high, 1 ); value = L_msu( value, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); - value = L_mac0( L_shl( value, 1 ), 1, get_next_indice_1( st ) ); + value = L_mac0( L_shl( value, 1 ), 1, get_next_indice_1_fx( st ) ); } s->low = low; diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index fc45166c11ef11a1272a29ac59d1c4dcc29364e8..fbd863d6fc2d4592f125665a97613d1890bb9053 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -43,7 +43,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * DecodeIndex() diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index 0bffd69633fe573a9bfaabcdff73bd84eb7b7a65..1d23d827d4d34cec79faa7706e2cca1f9699f447 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -43,8 +43,7 @@ #include "basop_util.h" #include "basop_proto_func.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------* * tcx_arith_decode() @@ -245,7 +244,7 @@ void tcx_arith_decode_envelope( gamma_uw = 1.0f / st->gamma_float; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_ivas( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP if ( use_hm ) @@ -278,7 +277,7 @@ void tcx_arith_decode_envelope( } envelope = (Word16 *) env; - tcx_arith_scale_envelope_flt( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); + tcx_arith_scale_envelope_ivas( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); *arith_bits = tcx_arith_decode( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum ); @@ -362,7 +361,7 @@ void tcx_arith_decode_envelope_ivas_fx( move16(); #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + tcx_arith_render_envelope_ivas( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #undef WMC_TOOL_SKIP IF( use_hm != 0 ) diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index ddd4ac4782aeeab90815a458478ef8c376662a62..61bb24b663c8ef8b2e7c0740b4b687290926c4e9 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /* Returns: number of bits consumed */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index d4351b1a541d81e562b443c7620f8ebb94704573..fa865d0ed56308f7e99f6100d3cd648d82af4537 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -4,12 +4,11 @@ #include -#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 */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local prototypes @@ -141,7 +140,7 @@ void AVQ_demuxdec_fx( BREAK; } } - WHILE( get_next_indice_1( st ) ); + WHILE( get_next_indice_1_fx( st ) ); if ( EQ_16( add( add( shl( nq[k], 2 ), nq[k] ), 4 ), bits ) ) /* check the overflow */ { @@ -249,7 +248,7 @@ void AVQ_demuxdec_fx( BREAK; } } - WHILE( get_next_indice_1( st ) ); + WHILE( get_next_indice_1_fx( st ) ); unusedbitsFlag = 0; move16(); @@ -450,13 +449,13 @@ static void read_cv_fx( } ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ { - *I = get_next_indice( st, shl( nq, 2 ) ); + *I = get_next_indice_fx( st, shl( nq, 2 ) ); move32(); bits = sub( bits, shl( nq, 2 ) ); } ELSE IF( ( s_and( nq, 1 ) == 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 16 ); + *I = get_next_indice_fx( st, 16 ); move32(); bits = sub( bits, 16 ); order_v = (Word16) sub( shr( nq, 1 ), 2 ); @@ -464,21 +463,21 @@ static void read_cv_fx( FOR( j = 0; j < 8; j++ ) { - kv[j] = get_next_indice( st, order_v ); + kv[j] = get_next_indice_fx( st, order_v ); move16(); } bits = sub( bits, ( shl( order_v, 3 ) ) ); } ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 12 ); + *I = get_next_indice_fx( st, 12 ); move32(); bits = sub( bits, 12 ); order_v = (Word16) sub( shr( nq, 1 ), 1 ); FOR( j = 0; j < 8; j++ ) { - kv[j] = get_next_indice( st, order_v ); + kv[j] = get_next_indice_fx( st, order_v ); move32(); } bits = sub( bits, shl( order_v, 3 ) ); diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 13c822522a7f4d82c0e9ff392e167f696ce5ab5b..5572077146782ef9b9b02586907b12fdcd04a752 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -38,8 +38,7 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "cnst.h" #include "stat_dec.h" @@ -48,7 +47,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*---------------------------------------------------------------------* * Local constants @@ -572,6 +571,20 @@ void addBassPostFilter_ivas_fx( cldfbAnalysis_ivas_fx( harm_timeIn_fx, tmp_R_fx, tmp_I_fx, samplesToProcess, cldfb ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + /* now do the subtraction */ + FOR( i = 0; i < nColToProcess; i++ ) + { + /* loop over low frequency bands */ + FOR( b = 0; b < maxBand; b++ ) + { + rAnalysis_fx[i][b] = Msub_32_32( rAnalysis_fx[i][b], tmp_R_fx[i][b], weights_fx[b] ); // Qx - 6 + move32(); + iAnalysis_fx[i][b] = Msub_32_32( iAnalysis_fx[i][b], tmp_I_fx[i][b], weights_fx[b] ); // Qx - 6 + move32(); + } + } +#else /* now do the subtraction */ FOR( i = 0; i < nColToProcess; i++ ) { @@ -584,6 +597,7 @@ void addBassPostFilter_ivas_fx( move32(); } } +#endif return; } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index d3984a7e477c078c1cf7ab0cc329afd52455e601..3620495a89021918f149668011f652e7f828e026 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -4,12 +4,11 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_dec.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_dec.h" /* Static table prototypes */ #include "basop_util.h" /*---------------------------------------------------------------------* diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c index cb202f38b0bfbf68b4e37dbfc060551dfc9ce49e..83854f3aed83cd0b758347800f8cb9d2ffbe4b98 100644 --- a/lib_dec/cng_dec.c +++ b/lib_dec/cng_dec.c @@ -39,7 +39,6 @@ #include #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" #include "rom_com.h" #include "wmc_auto.h" diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index ab41059c5352f6d6462113dab6949167dea89e4c..fdb708f46c35fdcf77d18d49542c16751a0ae7e6 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" /*Temporary location to be move in prot* when merge is done*/ @@ -173,7 +172,7 @@ void CNG_dec_fx( } /* decode the energy index */ - L_enr_index = get_next_indice( st_fx, num_bits ); + L_enr_index = get_next_indice_fx( st_fx, num_bits ); IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -227,13 +226,13 @@ void CNG_dec_fx( IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - burst_ho_cnt = get_next_indice( st_fx, 3 ); /* 3bit */ + burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ - *sid_bw = get_next_indice( st_fx, 1 ); + *sid_bw = get_next_indice_fx( st_fx, 1 ); move16(); IF( *sid_bw == 0 ) { - env_idx[0] = get_next_indice( st_fx, 6 ); + env_idx[0] = get_next_indice_fx( st_fx, 6 ); move16(); /* get quantized res_env_details */ @@ -863,7 +862,7 @@ static void shb_CNG_decod_fx( test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { - idx_ener_fx = get_next_indice( st_fx, 4 ); + idx_ener_fx = get_next_indice_fx( st_fx, 4 ); if ( !idx_ener_fx ) { @@ -1151,7 +1150,7 @@ static void shb_CNG_decod_ivas_fx( { IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { - idx_ener = get_next_indice( st, 4 ); + idx_ener = get_next_indice_fx( st, 4 ); IF( EQ_16( idx_ener, 0 ) ) { @@ -1512,7 +1511,7 @@ void td_cng_dec_init_ivas_fx( move16(); hTdCngDec->Enew_fx = 0; move32(); - mvs2s( st->lsp_old_fx, st->lspCNG_fx, M ); // Q(15) + Copy( st->lsp_old_fx, st->lspCNG_fx, M ); // Q(15) hTdCngDec->last_allow_cn_step = 0; move16(); hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11) diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index d8c00803e354bee1203f80f1c33751fa38228da4..2ae22c470d57756f157b5c5d56346953ea860f51 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -41,7 +41,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------* * open_decoder_LPD() * diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 684b21fb2271a8426e56d81e7dba23e0de9b6607..bcee307664768221f77306e7761ef9a954bb0b91 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -7,9 +7,8 @@ #include #include #include "options.h" -#include "prot_fx1.h" #include "prot.h" //Can be removed later -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" #include "cnst.h" /* for MIN_CNG_LEV */ @@ -451,9 +450,9 @@ void open_decoder_LPD_fx( W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ - nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ); move16(); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ move16(); Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); @@ -481,7 +480,7 @@ void open_decoder_LPD_fx( lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); - nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); + nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); move16(); Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; @@ -1171,9 +1170,9 @@ void acelp_plc_mdct_transition_fx( W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ - nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ); move16(); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); move16(); /*CLDFB delay*/ Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); diff --git a/lib_dec/core_dec_reconf.c b/lib_dec/core_dec_reconf.c index 13aa708dc4a76c26a3fbcdf0cd7f358ca3b36178..2599303f315b8e5562b5c9759096cbbfa1e67466 100644 --- a/lib_dec/core_dec_reconf.c +++ b/lib_dec/core_dec_reconf.c @@ -40,7 +40,7 @@ #include "rom_com.h" #include "rom_dec.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * reconfig_decoder_LPD_ivas() diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index c347fbe8df726bfab3721c805b7706c755853a53..13ddbe6f23606e918cc97fb9194f1ddf86c9930e 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 6aaad23ef40e7fd098f9a8c1a0c0b34eba56d021..835b930979f92a40ba5b5da56854fe5a7c981c80 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" // Temporarily added diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 7e7bfbd6c5bdca8b817f8b010584d70e548dc9c9..43431ba309c92bce579a28ec6e655b7fd55592ae 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -40,8 +40,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "wmc_auto.h" diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 4f8854d7c540e86310c66fa7fec1b595eeda032f..a0e74feb6197e4de132a2888af4ff893a57c52af 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" @@ -543,11 +542,11 @@ ivas_error core_switching_pre_dec_fx( /* reset old HB synthesis buffer */ IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { - st_fx->old_bwe_delay = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } ELSE { - st_fx->old_bwe_delay = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); @@ -640,7 +639,7 @@ ivas_error core_switching_pre_dec_fx( move16(); } - delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) { diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 1507c284e17fd7f66622d8184ca817d33fb91da0..63eff5413795ce52a79bc6208eaf96deb046e82f 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -4,8 +4,7 @@ #include #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "stl.h" #include "rom_com.h" diff --git a/lib_dec/dec2t32_fx.c b/lib_dec/dec2t32_fx.c index e62814cc65f6fa7da9dcd60bf55b999986de4b70..d6f82276591399289ac9aef73346b8db944ab917 100644 --- a/lib_dec/dec2t32_fx.c +++ b/lib_dec/dec2t32_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*==========================================================================*/ @@ -42,7 +41,7 @@ void dec_acelp_2t32_fx( Word16 index, i0, i1; - index = (Word16) get_next_indice( st_fx, 12 ); + index = (Word16) get_next_indice_fx( st_fx, 12 ); move16(); set16_fx( code, 0, L_SUBFR ); @@ -107,12 +106,12 @@ void dec_acelp_1t64_fx( *-----------------------------------------------------------------*/ IF( EQ_16( L_subfr, L_SUBFR ) ) { - pos = (Word16) get_next_indice( st_fx, 7 ); + pos = (Word16) get_next_indice_fx( st_fx, 7 ); move16(); } ELSE /* L_subfr == 2*L_SUBFR */ { - pos = (Word16) get_next_indice( st_fx, 8 ); + pos = (Word16) get_next_indice_fx( st_fx, 8 ); move16(); } diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 10e9b5b13a0918b7c12ab8f75bfa3039c45eace8..dd126cc2d2b069124cb0995f05dc1bd0f12e71a1 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "assert.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "assert.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local functions @@ -113,12 +112,12 @@ void dec_acelp_4t64_fx( bitcnt = s_and( nbbits, 15 ); FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); move16(); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); move16(); } @@ -136,7 +135,7 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - L_index = get_next_indice( st_fx, 5 ); + L_index = get_next_indice_fx( st_fx, 5 ); dec_1p_N1_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 1, k, code ); } @@ -145,7 +144,7 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - L_index = get_next_indice( st_fx, 9 ); + L_index = get_next_indice_fx( st_fx, 9 ); dec_2p_2N1_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 2, k, code ); } @@ -154,14 +153,14 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T - 2; k++ ) { - L_index = get_next_indice( st_fx, 13 ); + L_index = get_next_indice_fx( st_fx, 13 ); dec_3p_3N1_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 3, k, code ); } FOR( k = 2; k < NB_TRACK_FCB_4T; k++ ) { - L_index = get_next_indice( st_fx, 9 ); + L_index = get_next_indice_fx( st_fx, 9 ); dec_2p_2N1_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 2, k, code ); } @@ -170,7 +169,7 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - L_index = get_next_indice( st_fx, 13 ); + L_index = get_next_indice_fx( st_fx, 13 ); dec_3p_3N1_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 3, k, code ); } @@ -179,12 +178,12 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - ind1[k] = get_next_indice( st_fx, 2 ); + ind1[k] = get_next_indice_fx( st_fx, 2 ); move32(); } FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - index2 = get_next_indice( st_fx, 14 ); + index2 = get_next_indice_fx( st_fx, 14 ); L_index = L_add( L_shl( ind1[k], 14 ), index2 ); dec_4p_4N_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 4, k, code ); @@ -194,24 +193,24 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T - 2; k++ ) { - ind1[k] = get_next_indice( st_fx, 10 ); + ind1[k] = get_next_indice_fx( st_fx, 10 ); move32(); } FOR( k = 2; k < NB_TRACK_FCB_4T; k++ ) { - ind1[k] = get_next_indice( st_fx, 2 ); + ind1[k] = get_next_indice_fx( st_fx, 2 ); move32(); } FOR( k = 0; k < NB_TRACK_FCB_4T - 2; k++ ) { - index2 = get_next_indice( st_fx, 10 ); + index2 = get_next_indice_fx( st_fx, 10 ); L_index = L_add( L_shl( ind1[k], 10 ), index2 ); dec_5p_5N_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 5, k, code ); } FOR( k = 2; k < NB_TRACK_FCB_4T; k++ ) { - index2 = get_next_indice( st_fx, 14 ); + index2 = get_next_indice_fx( st_fx, 14 ); L_index = L_add( L_shl( ind1[k], 14 ), index2 ); dec_4p_4N_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 4, k, code ); @@ -221,12 +220,12 @@ void dec_acelp_4t64_fx( { FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - ind1[k] = get_next_indice( st_fx, 11 ); + ind1[k] = get_next_indice_fx( st_fx, 11 ); move16(); } FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { - index2 = get_next_indice( st_fx, 11 ); + index2 = get_next_indice_fx( st_fx, 11 ); L_index = L_add( L_shl( ind1[k], 11 ), index2 ); dec_6p_6N2_fx( L_index, 4, 0, pos ); add_pulses_fx( pos, 6, k, code ); diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index 746e18e38bae66c088e3d10069d0821390bf81d7..e45e44b471c4835c7c2ac3f3ea6e92c8c032efeb 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -44,7 +44,7 @@ #include "basop_proto_func.h" #include "stat_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 11afd0184baebf196ddbaa1a6ca8ec74306e5d4c..c870b04a03b7973ab10ad57106a8d3891f6d1091 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -6,8 +6,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" #ifdef IVAS_FLOAT_FIXED @@ -895,9 +894,9 @@ void decoder_LPD_fx( /* Update */ Copy( synth_buf + L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len ); - Copy( hTcxDec->old_synthFB_fx + L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( hTcxDec->old_synthFB_fx + L_frameTCX - NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); Copy( synth_bufFB + L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); - Copy_Scale_sig( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( st->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( st->hHQ_core->Q_old_wtda ) ); Copy( &xspnew_uw[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); Copy( &xsfnew_uw[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 8764b1d2a139c04a8fbba1a2a15d8a1de7bade44..7c3de901a83a4eacd7d7b6d651bbba86ee3a4308 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -8,8 +8,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "stl.h" #include "rom_com.h" diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index b560f7beae8300edbcfb724f8f1a361fa8db28ea..b05086d9fc61e0d4c4b36f77b5c023ca97500028 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -7,8 +7,7 @@ #include #include "options.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "rom_basop_util.h" #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 93eb4605f15c77fd86f593bc1688f205ec902e4e..ad7117763bc403b7c06164a2ec87687ed92e5c78 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -8,8 +8,7 @@ #include "options.h" #include "rom_com.h" #include "stat_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED static void decode_frame_type_fx( Decoder_State *st diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index 9682b152b87ab07c0971313aa315129ce5f9b257..03ae965aabbbe968eff0187734c4b68253de0e5a 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 1fd514e1ccfe28bd1dbbc1eb47182b366915395e..b8d17a1e3938937c3c0ab77da7b78feaf47b2a37 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED @@ -487,8 +486,8 @@ ivas_error decod_gen_voic_fx( interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + shl( i_subfr_fx, 1 ), L_SUBFR ); } - count_free( PREVP ); - count_free( CURRP ); + free( PREVP ); + free( CURRP ); } } @@ -619,7 +618,7 @@ ivas_error decod_gen_voic_ivas_fx( test(); IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) ) { - harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 ); + harm_flag_acelp = (Word16) get_next_indice_fx( st_fx, 1 ); } /*------------------------------------------------------------------* @@ -708,7 +707,7 @@ ivas_error decod_gen_voic_ivas_fx( } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation @@ -986,8 +985,8 @@ ivas_error decod_gen_voic_ivas_fx( interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR ); } - count_free( PREVP ); - count_free( CURRP ); + free( PREVP ); + free( CURRP ); } } diff --git a/lib_dec/dec_higher_acelp.c b/lib_dec/dec_higher_acelp.c index 304884e714e1f54d084e74f97bbbfe7fbdfc1227..d3d0876fda3cd9a5ef71c2fb13566273494b87b8 100644 --- a/lib_dec/dec_higher_acelp.c +++ b/lib_dec/dec_higher_acelp.c @@ -42,8 +42,8 @@ #include "rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-----------------------------------------------------------------* * transf_cdbk_dec() diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 0bc9665d804906bacd705e9f9ef1f94e1afa90a3..042a69b3abefdda66e966b73870bff26c296bca0 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -4,10 +4,9 @@ #include #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 */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #define IVAS_CODE #define IVAS_CODE_AVQ @@ -65,7 +64,7 @@ void transf_cdbk_dec_fx( * Dequantize prequantizer excitation gain *--------------------------------------------------------------*/ - index = (Word16) get_next_indice( st_fx, G_AVQ_BITS ); + index = (Word16) get_next_indice_fx( st_fx, G_AVQ_BITS ); IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { @@ -219,7 +218,7 @@ void transf_cdbk_dec_fx( st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); move16(); #endif - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); + PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); /*--------------------------------------------------------------* * Compute normalized prequantizer excitation gain for FEC * diff --git a/lib_dec/dec_nelp_fx.c b/lib_dec/dec_nelp_fx.c index 9732ce9f1a5c88d5606fc7a85bab5a3e3cbce770..7083919c455c76ab46d32ad1489d3669eb8d42c8 100644 --- a/lib_dec/dec_nelp_fx.c +++ b/lib_dec/dec_nelp_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*======================================================================*/ /* FUNCTION : decod_nelp_fx() */ diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index aba8af9b22b2e1004f6187a95059512864ddd2da..fc06c6649dc80ded08dd0d17bca545295d17d490 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*==========================================================================*/ @@ -679,7 +678,7 @@ void dec_pit_exc_ivas_fx( gain_code_fx = L_deposit_l( 0 ); st_fx->tilt_code_fx = 0; move16(); - pit_idx_fx = (Word16) get_next_indice( st_fx, nbits ); + pit_idx_fx = (Word16) get_next_indice_fx( st_fx, nbits ); move16(); gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); @@ -864,7 +863,7 @@ void dec_pit_exc_ivas_fx( move16(); pt_gain++; - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); } } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 2552a15ec37180c6986db410547cd13b75fbd45c..7826cabc4c51120e5b984efb58ad72b3acf19d50 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_dec.h" #include "rom_com.h" @@ -1071,7 +1070,7 @@ static void search_del_fx( move32(); ptr_L_den0 = L_den0; ptr_L_den1 = L_den1; - ptr_h = Tab_hup_s; + ptr_h = tab_hup_s_fx; temp = sub( lambda, LH_UP_S - 1 ); ptr_sig_past0 = ptr_sig_in - temp; @@ -1421,7 +1420,7 @@ static void compute_ltp_l_fx( temp = sub( phase, 1 ); temp = shl( temp, L2_LH2_L ); - ptr_h = Tab_hup_l + temp; /* Tab_hup_l + LH2_L * (phase-1) */ + ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ temp = sub( LH_UP_L, ltpdel ); ptr2 = s_in + temp; diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index cd4d6462f6be21a92c0ecdb8806199ef5b5b7777..d37efa4c7d80b2ca92d6f92813f7b6185644999e 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -4,9 +4,8 @@ #include #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED /*===================================================================*/ /* FUNCTION : void decod_ppp_fx () */ diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index c10b3f587295bcf8e77e5885aa93cc0a5c3d6e4d..b6a2b7d82af34b2cebb9486865b511d699f3264c 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -41,7 +41,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * getTCXMode_ivas() diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index f238f3e3a5136bc1c12fef6dd9acd44db1c54e9a..feef8f2be017b8da3317805e1d7ff309753523e4 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -9,8 +9,7 @@ #include #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -645,9 +644,9 @@ void dec_prm_fx( /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ IF( st->tcxonly ) { - st->core = add( get_next_indice( st, 1 ), 1 ); + st->core = add( get_next_indice_fx( st, 1 ), 1 ); move16(); - ind = get_next_indice( st, 2 ); + ind = get_next_indice_fx( st, 2 ); st->clas_dec = ONSET; move16(); if ( ind == 0 ) @@ -682,7 +681,7 @@ void dec_prm_fx( /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; move16(); - st->hTcxCfg->coder_type = get_next_indice( st, 2 ); + st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); move16(); *coder_type = st->hTcxCfg->coder_type; move16(); @@ -691,9 +690,9 @@ void dec_prm_fx( { IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) { - IF( get_next_indice_1( st ) != 0 ) /* TCX */ + IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ { - tmp = get_next_indice( st, 3 ); + tmp = get_next_indice_fx( st, 3 ); assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" ); st->core = TCX_20_CORE; move16(); @@ -706,7 +705,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice( st, 2 ); + *coder_type = get_next_indice_fx( st, 2 ); move16(); } } @@ -716,7 +715,7 @@ void dec_prm_fx( { IF( !( st->use_partial_copy ) ) { - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); IF( tmp == 0 ) { st->core = ACELP_CORE; @@ -735,7 +734,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice( st, 3 ); + *coder_type = get_next_indice_fx( st, 3 ); move16(); IF( GE_16( *coder_type, ACELP_MODE_MAX ) ) { @@ -789,7 +788,7 @@ void dec_prm_fx( test(); IF( ( NE_16( st->core, ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { - st->last_core_from_bs = get_next_indice( st, 1 ); + st->last_core_from_bs = get_next_indice_fx( st, 1 ); move16(); /* @@ -867,9 +866,9 @@ void dec_prm_fx( tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - if ( get_next_indice( st, 1 ) ) + if ( get_next_indice_fx( st, 1 ) ) { - tmp = add( 2, get_next_indice( st, 1 ) ); + tmp = add( 2, get_next_indice_fx( st, 1 ) ); } st->hTcxCfg->tcx_curr_overlap_mode = tmp; move16(); @@ -895,14 +894,14 @@ void dec_prm_fx( search_range = 8; move16(); - st->flagGuidedAcelp = get_next_indice( st, 1 ); + st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); move16(); pitchDiff = 0; move16(); IF( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice( st, bits_per_subfr ); + pitchDiff = get_next_indice_fx( st, bits_per_subfr ); move16(); st->guidedT0 = sub( pitchDiff, search_range ); move16(); @@ -926,7 +925,7 @@ void dec_prm_fx( st->dec_glr_idx = -1; if ( EQ_16( st->core, ACELP_CORE ) ) { - st->dec_glr_idx = get_next_indice( st, G_LPC_RECOVERY_BITS ); + st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); move16(); } } @@ -1007,19 +1006,19 @@ void dec_prm_fx( { param_lpc[0] = 0; move16(); - param_lpc[1] = get_next_indice( st, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ move16(); - param_lpc[2] = get_next_indice( st, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ move16(); - param_lpc[3] = get_next_indice( st, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ - param_lpc[0] = get_next_indice( st, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ move16(); - param_lpc[1] = get_next_indice( st, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ move16(); } } @@ -1057,7 +1056,7 @@ void dec_prm_fx( st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); if ( n != 0 ) { - st->bpf_gain_param = get_next_indice( st, n ); + st->bpf_gain_param = get_next_indice_fx( st, n ); move16(); } @@ -1066,7 +1065,7 @@ void dec_prm_fx( move16(); if ( n != 0 ) { - prm[j] = get_next_indice( st, n ); + prm[j] = get_next_indice_fx( st, n ); j = add( j, 1 ); move16(); } @@ -1080,7 +1079,7 @@ void dec_prm_fx( IF( n != 0 ) { - prm[j] = get_next_indice( st, n ); + prm[j] = get_next_indice_fx( st, n ); j = add( j, 1 ); move16(); } @@ -1088,7 +1087,7 @@ void dec_prm_fx( /* Adaptive codebook filtering (1 bit) */ IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j] = get_next_indice( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); j = add( j, 1 ); move16(); } @@ -1113,13 +1112,13 @@ void dec_prm_fx( FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j] = get_next_indice( st, 16 ); + prm[j] = get_next_indice_fx( st, 16 ); j = add( j, 1 ); move16(); } if ( bitcnt ) { - prm[j] = get_next_indice( st, bitcnt ); + prm[j] = get_next_indice_fx( st, bitcnt ); move16(); } @@ -1130,7 +1129,7 @@ void dec_prm_fx( n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; move16(); - prm[j] = get_next_indice( st, n ); + prm[j] = get_next_indice_fx( st, n ); j = add( j, 1 ); move16(); } /*end of subfr loop*/ @@ -1155,25 +1154,25 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* NELP gain indices */ - st->rf_indx_nelp_iG1 = get_next_indice( st, 5 ); - st->rf_indx_nelp_iG2[0] = get_next_indice( st, 6 ); + st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); + st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); move16(); - st->rf_indx_nelp_iG2[1] = get_next_indice( st, 6 ); + st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); move16(); /* NELP filter selection index */ - st->rf_indx_nelp_fid = get_next_indice( st, 2 ); + st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); move16(); /* tbe gainFr */ - st->rf_indx_tbeGainFr = get_next_indice( st, 5 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); move16(); } ELSE { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j] = get_next_indice( st, 3 ); + prm[j] = get_next_indice_fx( st, 3 ); move16(); j = add( j, 1 ); @@ -1190,7 +1189,7 @@ void dec_prm_fx( move16(); IF( n != 0 ) { - prm[j] = get_next_indice( st, n ); + prm[j] = get_next_indice_fx( st, n ); j = add( j, 1 ); move16(); } @@ -1203,7 +1202,7 @@ void dec_prm_fx( { /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ - prm[j] = get_next_indice( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); move16(); j = add( j, 8 ); } @@ -1214,13 +1213,13 @@ void dec_prm_fx( { n = ACELP_GAINS_BITS[gains_mode]; move16(); - prm[j] = get_next_indice( st, n ); + prm[j] = get_next_indice_fx( st, n ); j = add( j, 1 ); move16(); } } - st->rf_indx_tbeGainFr = get_next_indice( st, 2 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); move16(); } } @@ -1236,17 +1235,17 @@ void dec_prm_fx( if ( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); j = add( j, 1 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); j = add( j, 1 ); move16(); @@ -1256,14 +1255,14 @@ void dec_prm_fx( IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) { - prm[j] = get_next_indice( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); move16(); - prm[j + 2] = get_next_indice( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); move16(); } @@ -1343,7 +1342,7 @@ void dec_prm_fx( test(); IF( st->hTcxCfg->ctx_hm && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { - prm[j] = get_next_indice( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); move16(); nbits_tcx = sub( nbits_tcx, 1 ); @@ -1405,7 +1404,7 @@ void dec_prm_fx( prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1( st ); + prms[ix] = get_next_indice_1_fx( st ); move16(); } set16_fx( prms + nbits_tcx, 1, 32 ); @@ -1431,7 +1430,7 @@ void dec_prm_fx( IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && EQ_16( st->use_partial_copy, 1 ) ) { /* classification */ - ind = get_next_indice( st, 2 ); + ind = get_next_indice_fx( st, 2 ); st->clas_dec = ONSET; move16(); @@ -1462,7 +1461,7 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { /* TCX Gain = 7 bits */ - hTcxDec->old_gaintcx_bfi = get_next_indice( st, 7 ); + hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); move16(); } ELSE @@ -1475,7 +1474,7 @@ void dec_prm_fx( { prm_ltp[0] = 1; move16(); /* LTP active*/ - prm_ltp[1] = get_next_indice( st, 9 ); + prm_ltp[1] = get_next_indice_fx( st, 9 ); prm_ltp[2] = 3; move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ @@ -1538,16 +1537,16 @@ void dec_prm_fx( test(); if ( st->enablePlcWaveadjust && k ) { - st->tonality_flag = get_next_indice( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); j = add( j, 1 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); j = add( j, 1 ); move16(); @@ -1556,15 +1555,15 @@ void dec_prm_fx( test(); IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) ) { - prm[j] = get_next_indice( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); move16(); - prm[j + 2] = get_next_indice( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); move16(); tcxltp_prm_0 = prm[j]; diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 921e84976d7eaaeb324e6af7cbe9189d821f861b..11af1d430e9a4dc40bc252b7ffa8ce48f0c45df7 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -37,7 +37,7 @@ #include #include "prot.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include #include "options.h" #include @@ -45,12 +45,10 @@ #include "cnst.h" #include "wmc_auto.h" #include "ivas_rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "ivas_prot_fx.h" -#ifndef IVAS_FLOAT_FIXED_UNIT_TESTING +//#ifndef IVAS_FLOAT_FIXED_UNIT_TESTING #include "debug.h" -#endif // !IVAS_FLOAT_FIXED_UNIT_TESTING +//#endif #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* @@ -1568,9 +1566,10 @@ void decoder_tcx_tns_fx( STnsData *tnsData, const Word16 bfi, /* i : Bad frame indicator */ const Word16 frame_cnt, /* i : frame counter in the super frame */ - const Word16 whitenedDomain ) + const Word16 whitenedDomain, + Word16 *length ) { - Word16 index, isTCX5, L; + Word16 index, isTCX5, L, tmp; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ @@ -1580,9 +1579,14 @@ void decoder_tcx_tns_fx( move16(); L = L_frameTCX; move16(); + tmp = L; + move16(); + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) ) { + test(); + test(); IF( NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) { /* fix sub-window overlap */ @@ -1590,12 +1594,24 @@ void decoder_tcx_tns_fx( move16(); } + test(); + test(); + test(); IF( ( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); + tmp = L; + move16(); } + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && @@ -1613,11 +1629,16 @@ void decoder_tcx_tns_fx( *-----------------------------------------------------------*/ + test(); + test(); + test(); IF( NE_16( hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) && EQ_16( tnsData->tnsOnWhitenedSpectra, whitenedDomain ) ) { /* Apply TNS to get the reconstructed signal */ SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) ); + test(); + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) ) { tcx5TnsGrouping_fx( shr( L, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx ); @@ -1625,11 +1646,16 @@ void decoder_tcx_tns_fx( ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x_fx, 0 ); + test(); + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( isTCX5, 0 ) ) { + test(); IF( EQ_16( st->element_mode, EVS_MONO ) || LT_16( L_spec, L_frameTCX ) ) /* todo: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ { tcx5TnsUngrouping_fx( shr( L_frameTCX, 1 ), shr( hTcxCfg->tnsConfig[0][0].iFilterBorders[0], 1 ), x_fx, DEC ); + tmp = L_frameTCX; + move16(); } ELSE { @@ -1637,12 +1663,17 @@ void decoder_tcx_tns_fx( } } } + test(); IF( NE_16( whitenedDomain, 0 ) && NE_16( isTCX5, 0 ) ) { tcx5SpectrumInterleaving_fx( shr( L, 1 ), x_fx ); } /* restore index */ + test(); + test(); + test(); + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) { /* restore sub-window overlap */ @@ -1650,6 +1681,12 @@ void decoder_tcx_tns_fx( move16(); } + if ( length != NULL ) + { + *length = tmp; + move16(); + } + return; } #endif @@ -2024,17 +2061,17 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { set32_fx( x_tmp_fx, 0, L_FRAME_PLUS ); - mvl2l( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); - mvl2l( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); + Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); } ELSE IF( EQ_16( st->element_mode, EVS_MONO ) ) { - mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); } ELSE { - mvl2l( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); - mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); } IF( NE_16( st->igf, 0 ) ) @@ -2062,7 +2099,7 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || NE_16( sba_dirac_stereo_flag, 0 ) ) { - mvl2l( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -2124,7 +2161,7 @@ void decoder_tcx_imdct_fx( /* Update old_syn_overl */ IF( EQ_16( hTcxCfg->last_aldo, 0 ) ) { - mvs2s( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); + Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); FOR( Word16 ind = 0; ind < overlapFB; ind++ ) { hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, L_frameTCX )], sub( q_x, q_win ) ); @@ -2132,7 +2169,7 @@ void decoder_tcx_imdct_fx( } /* Output */ - mvs2s( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); + Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB ) )], sub( q_x, q_win ) ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f521839cdbd05572fe831b473a662225729a0905..870299242a97fd0c27dcb1ded0d2512785505399 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -5,8 +5,7 @@ #include #include #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "stl.h" #include "options.h" @@ -2016,7 +2015,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T { tmp32 = L_add( st->output_Fs, 0 ); } - nz = NS2SA_fx2( tmp32, N_ZERO_MDCT_NS ); + nz = NS2SA_FX2( tmp32, N_ZERO_MDCT_NS ); tmp_offset = 0; move16(); @@ -2886,7 +2885,7 @@ void IMDCT_ivas_fx( v_add_16( win_fx, xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), imult1616( w, L_win ) ), xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), imult1616( w, L_win ) ), L_ola ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_ola, xn_buf_fx + add( tcx_offset, add( shr( L_ola, 1 ), imult1616( w, L_win ) ) ), L_win ); + Copy( win_fx + L_ola, xn_buf_fx + add( tcx_offset, add( shr( L_ola, 1 ), imult1616( w, L_win ) ) ), L_win ); } /* To assure that no garbage values are passed to overlap */ @@ -2926,7 +2925,7 @@ void IMDCT_ivas_fx( set16_fx( xn_buf_fx, 0, shr( overlap, 1 ) ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); + Copy( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ IF( s_and( kernel_type, 1 ) ) @@ -2947,7 +2946,7 @@ void IMDCT_ivas_fx( v_add_16( win_fx, xn_buf_fx + add( shr( overlap, 1 ), sub( L_win, shr( L_ola, 1 ) ) ), xn_buf_fx + sub( add( shr( overlap, 1 ), L_win ), shr( L_ola, 1 ) ), L_ola ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_ola, xn_buf_fx + add( add( shr( overlap, 1 ), L_win ), shr( L_ola, 1 ) ), L_win ); + Copy( win_fx + L_ola, xn_buf_fx + add( add( shr( overlap, 1 ), L_win ), shr( L_ola, 1 ) ), L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ IF( GE_16( kernel_type, MDCT_II ) ) @@ -3120,7 +3119,7 @@ void IMDCT_ivas_fx( Word16 q_r, q_buf; /* get the first 5 ms of non-aliased TCX syntesis */ - mvs2s( xn_buf_fx + add( shr( overlap, 1 ), shl( acelp_mem_len, 1 ) ), &buf_fx[0], analysis_len ); + Copy( xn_buf_fx + add( shr( overlap, 1 ), shl( acelp_mem_len, 1 ) ), &buf_fx[0], analysis_len ); q_buf = q_win; move16(); @@ -3225,7 +3224,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = add( xn_buf_fx[i], old_syn_overl_fx[i] ); + xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); move16(); } } @@ -3246,7 +3245,7 @@ void IMDCT_ivas_fx( IF( ( aldo == 0 ) && ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && ( frame_cnt > 0 ) ) || NE_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) { /* Compute windowed synthesis in case of switching to ALDO windows in next frame */ - mvs2s( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); + Copy( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); set16_fx( old_out_fx + add( nz, overlap ), 0, nz ); tcx_windowing_synthesis_past_frame( old_out_fx + nz, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_curr_overlap_mode ); @@ -3293,14 +3292,14 @@ void IMDCT_ivas_fx( FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); move16(); move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); move16(); move16(); } @@ -3726,7 +3725,7 @@ void decoder_tcx_ivas_fx( x_e = sub( x_e, shift ); move16(); - decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0 ); + decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0, NULL ); Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index 85497cc849dd6070f132d72c3083c513d719b0b4..4d8767e475e737c6a2eb2e4fd98c2667483d9683 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -2,11 +2,18 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED + +#ifdef FIX_810_PREVENT_UNECESSARY_SAT_IN_TC +#define Q3_4 ( 4 << Q3 ) +#define Q3_17 ( 17 << Q3 ) +#define Q16_8 ( 8 << Q16 ) +#define Q16_30 ( 30 << Q16 ) +#endif + /*======================================================================*/ /* FUNCTION : decod_tran_fx() */ /*----------------------------------------------------------------------*/ @@ -160,15 +167,17 @@ void decod_tran_fx( } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { + lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); move16(); } ELSE { + lp_gain_updt_ivas_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); move16(); } @@ -176,10 +185,29 @@ void decod_tran_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - +#ifdef FIX_810_PREVENT_UNECESSARY_SAT_IN_TC + test(); + test(); + test(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( add( i_subfr, L_SUBFR ), tc_subfr_fx ) && LT_16( i_subfr, tc_subfr_fx ) && GT_16( st_fx->Q_subfr[0], 4 ) ) ) + { + test(); + test(); + test(); + IF( GE_16( st_fx->Q_subfr[0], 7 ) && LE_32( st_fx->lp_gainc_fx, Q3_4 ) && LE_32( norm_gain_code_fx, Q16_8 ) ) + { + st_fx->Q_subfr[0] = s_min( st_fx->Q_subfr[0], 4 ); + move16(); + } + ELSE IF( LE_32( st_fx->lp_gainc_fx, Q3_17 ) && LE_32( L_sub( gain_code_fx, norm_gain_code_fx ), Q16_30 ) ) + { + st_fx->Q_subfr[0] = s_min( 4, sub( st_fx->Q_subfr[0], 2 ) ); + move16(); + } + } +#endif IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[shr( imult1616( i_subfr, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index cbdb9407ff4dff93ea3f26a5a9b1280e23ac42c0..ceb4d26507435ec099a533980f7278d4dc2ab8b3 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED static void gain_dec_gacelp_uv_fx( Word16 index, /* i : Quantization index vector Q0 */ @@ -196,7 +195,7 @@ void decod_unvoiced_ivas_fx( { tmp_idx_1 = idiv1616( i_subfr_fx, L_SUBFR ); } - Word16 index = get_next_indice( st_fx, st_fx->acelp_cfg.gains_mode[tmp_idx_1] ); + Word16 index = get_next_indice_fx( st_fx, st_fx->acelp_cfg.gains_mode[tmp_idx_1] ); // gain_dec_gacelp_uv(index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &(st->past_gpit_float), &norm_gain_code, &gain_inov); gain_dec_gacelp_uv_fx( index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &( st_fx->past_gpit ), &norm_gain_code_fx, &gain_inov_fx ); @@ -205,7 +204,7 @@ void decod_unvoiced_ivas_fx( /* update LP filtered gains for the case of frame erasures */ // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME); - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); /*-------------------------------------------------------* * - Find the total excitation. * @@ -364,7 +363,11 @@ static void gain_dec_gacelp_uv_fx( *past_gcode = L_shl( L_tmp1, sub( exp_L_tmp1, 15 ) ); /* Q16 */ move32(); +#ifdef BASOP_NOGLOB + *gain_code = L_shl_sat( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#else *gain_code = L_shl( Mpy_32_16_1( *past_gcode, *gain_inov ), 3 ); +#endif move32(); diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 8c9a12b69c14b8dc511450251fb3a5951bd2adcf..fc727fa3b475903fa26f4960bd371d7506ca9d69 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stat_dec.h" #include "rom_com.h" #include "stl.h" @@ -70,14 +69,14 @@ void decision_matrix_dec_fx( IF( NE_32( st->total_brate, FRAME_NO_DATA ) ) { - st->cng_type = get_next_indice( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); IF( EQ_16( st->cng_type, LP_CNG ) ) { st->L_frame = L_FRAME; move16(); - tmp16 = get_next_indice( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); IF( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; @@ -86,9 +85,9 @@ void decision_matrix_dec_fx( } ELSE { - st->bwidth = get_next_indice( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); - tmp16 = get_next_indice( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); move16(); st->L_frame = L_FRAME16k; @@ -143,9 +142,9 @@ void decision_matrix_dec_fx( st->vbr_hw_BWE_disable_dec = 1; move16(); - get_next_indice( st, 1 ); + get_next_indice_fx( st, 1 ); - ppp_nelp_mode = get_next_indice( st, 2 ); + ppp_nelp_mode = get_next_indice_fx( st, 2 ); /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ IF( ppp_nelp_mode == 0 ) @@ -202,7 +201,7 @@ void decision_matrix_dec_fx( ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) { /* read the ACELP/HQ core selection bit */ - temp_core = get_next_indice( st, 1 ); + temp_core = get_next_indice_fx( st, 1 ); st->core = HQ_CORE; move16(); @@ -243,7 +242,7 @@ void decision_matrix_dec_fx( nBits = extract_l( acelp_sig_tbl[start_idx] ); start_idx = add( start_idx, 1 ); - start_idx = add( start_idx, get_next_indice( st, nBits ) ); + start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { ind = 0; @@ -422,7 +421,7 @@ void decision_matrix_dec_fx( ELSE IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, ACELP_9k60 ) && LE_32( st->total_brate, ACELP_16k40 ) ) { /* read the WB TBE/BWE selection bit */ - tmp16 = get_next_indice( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); IF( EQ_16( tmp16, 1 ) ) { st->extl = WB_BWE; @@ -457,7 +456,7 @@ void decision_matrix_dec_fx( /* read the SWB TBE/BWE selection bit */ ELSE { - tmp16 = get_next_indice( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); IF( tmp16 ) { st->extl = SWB_BWE; @@ -520,7 +519,7 @@ void decision_matrix_dec_fx( } /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice( st, 1 ); + *core_switching_flag = get_next_indice_fx( st, 1 ); IF( EQ_16( *core_switching_flag, 1 ) ) { @@ -530,7 +529,7 @@ void decision_matrix_dec_fx( /* read ACELP L_frame info */ st->last_L_frame = L_FRAME16k; move16(); - tmp16 = get_next_indice( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); IF( tmp16 == 0 ) { st->last_L_frame = L_FRAME; @@ -544,7 +543,7 @@ void decision_matrix_dec_fx( /* read/set band-width (needed for different I/O sampling rate support) */ IF( GT_32( st->total_brate, ACELP_16k40 ) ) { - tmp16 = get_next_indice( st, 2 ); + tmp16 = get_next_indice_fx( st, 2 ); IF( tmp16 == 0 ) { diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 07f20ce6a3c00742ba4f434a879eefa7dd0c5359..1cb91e22f84a98734ccc9e1ab180c378bee6faab 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED /* Constants */ diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index 742f76dd3ea3438763f1a96dc0a31eeb336c83c9..f42d7d45708c5ea53faeedc570f7d10bac02fb0a 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -8,8 +8,7 @@ #include #include "options.h" #include "basop_util.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED /* Constants */ #define M 16 diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index ca23584a1b1098c75bd9a05a7af29bab79f97d68..3a8a3de62bc5e9a0cb93a9569798e54f1035b696 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -8,8 +8,7 @@ #include #include "options.h" #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index c3cf2f0ab1b2548d0987c13735d11606db323ad4..1998a3f8fd22ca59bb2423b389da9eb3dddfeb9f 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -6,8 +6,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED @@ -1944,6 +1943,7 @@ void con_tcx_ivas_fx( new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); + new_Q = s_min( new_Q, norm_s( tmp_deemph ) ); tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index ed78d88429c32c52dc3f04be491cf32ef849460a..652041e6717b2572ef49833799c2ba03ccb0c3ac 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index f4535152f3647126423204922d08166cf95fa9f1..48f811e71d26c990432a3e27605e4d9582d6d445 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -8,8 +8,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop32.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index ee0c52b8ea09c1d2a3a991d8033d80bc23e03949..93ccaed26d8be53dd3e2740f13cd14c6fcfe8c5a 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 96c3b57928b31659d1f135f695bc94e022e15328..d5498c622a1f4988018a0e8ae59ef80b3abd4338 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -42,8 +42,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif #ifndef IVAS_FLOAT_FIXED diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index e258c68e9af358a69e3dadfd9f231b199ec720f8..ba94c988a1b4fef895855f96612d021830f7e542 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED @@ -533,7 +532,7 @@ ivas_error evs_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx ); Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); @@ -571,7 +570,7 @@ ivas_error evs_dec_fx( move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, @@ -603,7 +602,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } ELSE { @@ -611,12 +610,12 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } ELSE { /* TBE on top of ACELP@16kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } } @@ -767,7 +766,7 @@ ivas_error evs_dec_fx( move16(); /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ - delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); @@ -1176,11 +1175,11 @@ ivas_error evs_dec_fx( /*CLDFB output always in timeIn_e*/ /* MODE1 MDCT to ACELP 2 transition */ - delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); hHQ_core->Q_old_postdec = 0; move16(); - delay_tdbwe = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); IF( GE_16( output_frame, L_FRAME16k ) ) { Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); @@ -1196,8 +1195,8 @@ ivas_error evs_dec_fx( i = 15; move16(); - tmps = NS2SA_fx2( st_fx->output_Fs, 3000000L ); - nz = NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); + nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); step = Inv16( tmps, &i ); step = shl( step, i ); alpha = 0; @@ -1309,13 +1308,13 @@ ivas_error evs_dec_fx( IF( EQ_32( st_fx->output_Fs, 8000 ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); } ELSE { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); } - delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); test(); test(); @@ -1405,7 +1404,7 @@ ivas_error evs_dec_fx( Scale_sig( output_sp, output_frame, timeIn_e ); - tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, + tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ) + tmps, output_sp, hTcxDec->FBTCXdelayBuf ); Copy( output_sp, synth_fx, output_frame ); @@ -1416,11 +1415,11 @@ ivas_error evs_dec_fx( * Save synthesis for HQ FEC *----------------------------------------------------------------*/ // PMT("The code below could be move to save_synthesis_hq_fec") - post_hq_delay = NS2SA_fx2( st_fx->output_Fs, POST_HQ_DELAY_NS ); + post_hq_delay = NS2SA_FX2( st_fx->output_Fs, POST_HQ_DELAY_NS ); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); + Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( output_frame, post_hq_delay ), output_frame, negate( Qpostd ) ); /* output_sp not initialized yet */ /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ @@ -1428,20 +1427,20 @@ ivas_error evs_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); + Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); } IF( NE_16( st_fx->core, ACELP_CORE ) ) { IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } ELSE { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } } } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 3eca9decd3edb7964f38d82d011511f635f80948..e5a7bb6669b7e1ae51972aba6c9b21cd0f065a20 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -45,8 +45,7 @@ #include "ivas_prot.h" #include "ivas_rom_dec.h" #include "ivas_rom_com_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" @@ -552,12 +551,7 @@ void configureFdCngDec_ivas_fx( hsCom->startBand = 2; move16(); hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); -#ifndef IVAS_FLOAT_FIXED - /* remove floating point dependency */ - initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); -#else // IVAS_FLOAT_FIXED initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); -#endif // IVAS_FLOAT_FIXED IF( EQ_16( hsCom->stopFFTbin, 160 ) ) { @@ -578,9 +572,6 @@ void configureFdCngDec_ivas_fx( FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); -#ifndef IVAS_FLOAT_FIXED - hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; // TODO remove floating point dependency -#endif move16(); hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; move16(); @@ -594,12 +585,7 @@ void configureFdCngDec_ivas_fx( move16(); } -#ifdef IVAS_FLOAT_FIXED initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); -#else // IVAS_FLOAT_FIXED - /* remove floating point dependency */ - initPartitions_flt( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping_float, hFdCngDec->psize_inv_shaping_float, stopBandFR ); -#endif // IVAS_FLOAT_FIXED hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); @@ -1338,7 +1324,7 @@ void FdCng_decodeSID_ivas_fx( Decoder_State *st /* i/o: decoder state structure */ ) { - int16_t N; + Word16 N; Word32 *sidNoiseEst; Word32 gain; Word16 i, index; @@ -1370,6 +1356,7 @@ void FdCng_decodeSID_ivas_fx( sidNoiseEst = hFdCngCom->sidNoiseEst; N = hFdCngCom->npart; + move16(); gain = 0; move32(); hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); @@ -1993,6 +1980,7 @@ void generate_masking_noise_ivas_fx( Word32 *ptr_r_fx; Word32 *ptr_i_fx; Word16 startBand = hFdCngCom->startBand; + move16(); Word16 *seed = &( hFdCngCom->seed ); Word32 scale_fx = 0x40000000; // 1.0 in Q30 move32(); @@ -2004,6 +1992,7 @@ void generate_masking_noise_ivas_fx( } scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, shift ); + move16(); /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ *exp_out = Q15; @@ -2054,7 +2043,7 @@ void generate_masking_noise_ivas_fx( /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ - IF( EQ_16( startBand, 0 ) ) + IF( startBand == 0 ) { rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15 ptr_r_fx = fftBuffer_fx + 2; @@ -2104,13 +2093,14 @@ void generate_masking_noise_ivas_fx( /* Perform STFT synthesis */ IF( secondary ) { - SynthesisSTFT_fx( fftBuffer_fx, *exp_out, maskingNoise_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); + SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); } ELSE { - SynthesisSTFT_fx( fftBuffer_fx, *exp_out, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); + SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); } *exp_out = sub( *exp_out, Q9 ); + move16(); /* Add some comfort noise on top of decoded signal */ IF( return_noise ) @@ -2390,10 +2380,10 @@ void generate_stereo_masking_noise_fx( Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - const int16_t fadeOut, /* i : only fade out of previous state */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 fadeOut, /* i : only fade out of previous state */ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels */ ) { HANDLE_FD_CNG_COM hFdCngCom; @@ -2403,7 +2393,7 @@ void generate_stereo_masking_noise_fx( Word32 N1_fx[L_FRAME16k]; Word32 N2_fx[L_FRAME16k]; Word16 N1_fx_exp, N2_fx_exp; - int16_t i; + Word16 i; IF( st->idchan == 0 ) { @@ -2556,6 +2546,7 @@ void generate_stereo_masking_noise_fx( move16(); } hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); + move16(); } return; @@ -2708,6 +2699,7 @@ void generate_masking_noise_lb_dirac_fx( n_samples_out = i_mult( shr( hFdCngCom->frameSize, 4 ), nCldfbTs ); n_samples_start = 0; Word16 exp_out = Q15; + move16(); /*LB CLDFB - CNA from STFT*/ IF( cna_flag ) { @@ -2799,7 +2791,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 = sub( 31, 15 ); + hFdCngCom->fftBuffer_exp = 31 - 15; n_samples_out = sub( n_samples_out, hFdCngCom->frameSize ); n_samples_start = add( n_samples_start, hFdCngCom->frameSize ); } @@ -3417,7 +3409,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( exp_diff = sub( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp ); FOR( p = 0; p < N; p++ ) { - IF( GT_16( exp_diff, 0 ) ) + IF( exp_diff > 0 ) { sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], add( exp_diff, 1 ) ) ); move32(); @@ -3428,7 +3420,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( move32(); } } - IF( LT_16( exp_diff, 0 ) ) + IF( exp_diff < 0 ) { sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) ); } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 4c0e5b1d71a3c5383b5413555f2dce1845e0699c..54c251e2123eca4d588309433868ddacb0e2dac4 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -9,8 +9,7 @@ #include "options.h" #include "rom_com.h" #include "stat_dec.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop_util.h" #include "rom_basop_util.h" @@ -52,7 +51,7 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error = IVAS_ERR_OK; /* Allocate memory */ - hs = (HANDLE_FD_CNG_DEC) count_malloc( sizeof( FD_CNG_DEC ) ); + hs = (HANDLE_FD_CNG_DEC) malloc( sizeof( FD_CNG_DEC ) ); IF( hs == NULL ) { @@ -545,7 +544,7 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) IF( hsDec != NULL ) { deleteFdCngCom( &( hsDec->hFdCngCom ) ); - count_free( hsDec ); + free( hsDec ); *hFdCngDec = NULL; } } @@ -1905,7 +1904,7 @@ Word16 ApplyFdCng_ivas_fx( IF( EQ_16( st->codec_mode, MODE2 ) ) { /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); + generate_comfort_noise_dec_ivas_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } BREAK; @@ -2680,8 +2679,11 @@ void perform_noise_estimation_dec_ivas_fx( { temp = L_shr( temp, sub( hFdCngDec->msPeriodog_ST_exp, hFdCngDec->hFdCngCom->periodog_exp ) ); } - +#ifdef IVAS_ENH32_CADENCE_CHANGES + hFdCngDec->msPeriodog_ST_fx[p] = Madd_32_16( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ); +#else hFdCngDec->msPeriodog_ST_fx[p] = L_add( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), Mpy_32_16_1( temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ) ); +#endif move32(); } } @@ -2762,7 +2764,11 @@ void perform_noise_estimation_dec_ivas_fx( temp = msPeriodog[p]; move32(); temp = L_shr( temp, sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( shl_sat( 1, sub( 15, e ) ), alpha ) ), temp, alpha ); +#else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], sub( shl_sat( 1, sub( 15, e ) ), alpha ) ), Mpy_32_16_1( temp, alpha ) ); +#endif move32(); } } @@ -2833,7 +2839,11 @@ void perform_noise_estimation_dec_ivas_fx( L_tmp = L_shr( msPeriodog[p], sub( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 4 ) ); IF( LT_32( L_tmp, msNoiseEst[p] ) ) { +#ifdef IVAS_ENH32_CADENCE_CHANGES + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); +#else msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); +#endif move32(); temp_q_msNoiseEst[p] = sub( add( hFdCngDec->msNoiseEst_exp, scale ), 15 ); move16(); @@ -2853,10 +2863,14 @@ void perform_noise_estimation_dec_ivas_fx( /* energy significantly decreases in one of the larger partitions during active frames -> downward update */ FOR( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { - L_tmp = L_shr( hFdCngDec->msPeriodog_ST_fx[p], sub( sub( 31, hFdCngDec->msPeriodog_ST_exp ), 4 ) ); - IF( LT_32( hFdCngDec->msPeriodog_ST_fx[p], msNoiseEst[p] ) ) + L_tmp = L_shr( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); + IF( LT_32( L_tmp, msNoiseEst[p] ) ) { - msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, (Word16) L_sub( ONE_IN_Q15, CNA_ACT_DN_FACT_Q15 ) ) ); +#ifdef IVAS_ENH32_CADENCE_CHANGES + msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); +#else + msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ) ); +#endif move32(); } } @@ -2907,8 +2921,27 @@ void perform_noise_estimation_dec_ivas_fx( } /* IIR smoothing */ - *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); + test(); + IF( *ptr_per != 0 && alpha != 0 ) + { + *ptr_per = Mpy_32_16_1( ( *ptr_per ), alpha ); + move32(); + IF( *ptr_per == 0 ) + { + *ptr_per = 1; + move32(); + } + } + ELSE + { + *ptr_per = 0; + move32(); + } +#ifdef IVAS_ENH32_CADENCE_CHANGES + *ptr_per = Madd_32_16( ( *ptr_per ), temp, sub( MAX_16, alpha ) ); +#else *ptr_per = L_add( ( *ptr_per ), Mpy_32_16_1( temp, sub( MAX_16, alpha ) ) ); +#endif ptr_per++; } @@ -3145,10 +3178,10 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* Read bitstream */ FOR( i = 0; i < stages_37bits; i++ ) { - indices[i] = get_next_indice( corest, bits_37bits[i] ); + indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); move16(); } - index = get_next_indice( corest, 7 ); + index = get_next_indice_fx( corest, 7 ); /* MSVQ decoder */ #ifdef IVAS_FLOAT_FIXED @@ -3788,6 +3821,549 @@ void generate_comfort_noise_dec_fx( } } +void generate_comfort_noise_dec_ivas_fx( + Word32 **bufferReal, /* o : Real part of input bands */ + Word32 **bufferImag, /* o : Imaginary part of input bands */ + Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *Q_new, + Word16 gen_exc, + const Word16 nchan_out /* i : number of output channels */ +) +{ + Word16 i, j, s; + Word32 *ptr_r, *ptr_i; + HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; + HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; + Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; + Word16 cngNoiseLevel_exp = hFdCngCom->cngNoiseLevelExp; + + Word32 *ptr_level = cngNoiseLevel; + Word16 *seed = &( hFdCngCom->seed ); + Word16 *seed2; + Word16 c1, c2; + Word32 tmp1, tmp2; + Word16 scaleCldfb; + Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word16 fftBuffer_exp = hFdCngCom->fftBuffer_exp; + Word16 fftBuffer_temp_exp[FFTLEN]; + Word16 *timeDomainOutput = hFdCngCom->timeDomainBuffer; + Word16 temp; + Word32 sqrtNoiseLevel; + Word16 sqrtNoiseLevel_exp; + Word16 idx = 0; + move16(); + Word16 preemph_fac; + Word16 old_syn_pe_tmp[16]; + Word16 tcx_transition = 0; + TCX_DEC_HANDLE hTcxDec; + move16(); + + hTcxDec = st->hTcxDec; + + scaleCldfb = mult( hFdCngCom->invScalingFactor, CLDFB_SCALING ); + + temp = 0; + move16(); + c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); + c1 = shl( c1, temp ); + temp = 0; + move16(); + c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); + c2 = shl( c2, temp ); + + temp = getScaleFactor32( fftBuffer, FFTLEN ); + scale_sig32( fftBuffer, FFTLEN, temp ); + fftBuffer_exp = sub( fftBuffer_exp, temp ); + hFdCngCom->fftBuffer_exp = fftBuffer_exp; + move16(); + set16_fx( fftBuffer_temp_exp, fftBuffer_exp, FFTLEN ); + fftBuffer_exp = 0; + move16(); + + seed2 = &( hFdCngCom->seed2 ); + if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->idchan, 1 ) ) + { + seed2 = &( hFdCngCom->seed3 ); + } + + /* Generate Gaussian random noise in real and imaginary parts of the FFT bins + Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ + + IF( hFdCngCom->startBand == 0 ) + { + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) + { + rand_gauss_fx( &tmp1, seed, Q15 ); + rand_gauss_fx( &tmp2, seed2, Q15 ); + fftBuffer[0] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + move32(); + fftBuffer_temp_exp[0] = Q16 + Q15; + } + ELSE + { + rand_gauss_fx( &fftBuffer[0], seed, Q15 ); + fftBuffer_temp_exp[0] = Q16; + move16(); + } + sqrtNoiseLevel_exp = cngNoiseLevel_exp; + move16(); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); + fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqrtNoiseLevel ); + move32(); + fftBuffer_temp_exp[0] = add( sqrtNoiseLevel_exp, fftBuffer_temp_exp[0] ); + move16(); + ptr_level++; + ptr_r = fftBuffer + 2; + idx = 2; + } + ELSE + { + fftBuffer[0] = 0; + move16(); + set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); + ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); + idx = shl( hFdCngCom->startBand, 1 ); + } + + ptr_i = ptr_r + 1; + FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) + { + /* Real part in FFT bins */ + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) + { + rand_gauss_fx( &tmp1, seed, Q15 ); + rand_gauss_fx( &tmp2, seed2, Q15 ); + *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + move32(); + fftBuffer_temp_exp[idx] = Q16; + move16(); + } + ELSE + { + rand_gauss_fx( ptr_r, seed, Q15 ); + fftBuffer_temp_exp[idx] = Q16; + move16(); + } + + sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); + ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); + move32(); + fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); + move16(); + idx = add( idx, 1 ); + ptr_r += 2; + + /* Imaginary part in FFT bins */ + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) + { + rand_gauss_fx( &tmp1, seed, Q15 ); + rand_gauss_fx( &tmp2, seed2, Q15 ); + *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + move32(); + fftBuffer_temp_exp[idx] = Q16; + move16(); + } + ELSE + { + rand_gauss_fx( ptr_i, seed, Q15 ); + fftBuffer_temp_exp[idx] = Q16; + move16(); + } + sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); + sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); + ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); + move32(); + fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); + move16(); + idx = add( idx, 1 ); + ptr_i += 2; + } + + /* Remaining FFT bins are set to zero */ + set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); + set16_fx( fftBuffer_temp_exp + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); + + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0; + move32(); + + fftBuffer_exp = MAX_16; + move16(); + FOR( i = 0; i < FFTLEN; i++ ) + { + if ( fftBuffer[i] != 0 ) + { + fftBuffer_exp = s_min( fftBuffer_exp, add( sub( 31, fftBuffer_temp_exp[i] ), norm_l( fftBuffer[i] ) ) ); + } + } + if ( EQ_16( fftBuffer_exp, MAX_16 ) ) + { + fftBuffer_exp = 0; + move16(); + } + fftBuffer_exp = sub( 31, fftBuffer_exp ); + FOR( i = 0; i < FFTLEN; i++ ) + { + fftBuffer[i] = L_shr( fftBuffer[i], sub( fftBuffer_exp, fftBuffer_temp_exp[i] ) ); + move32(); + } + + /* If previous frame is active, reset the overlap-add buffer */ + tcx_transition = 0; + move16(); + IF( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) + { + set16_fx( hFdCngCom->olapBufferSynth, 0, hFdCngCom->fftlen ); + test(); + test(); + if ( ( st->last_core_bfi > ACELP_CORE && EQ_16( st->codec_mode, MODE2 ) ) || EQ_16( st->codec_mode, MODE1 ) ) + { + tcx_transition = 1; + move16(); + } + } + + /* Perform STFT synthesis */ + SynthesisSTFT( fftBuffer, fftBuffer_exp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, + tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); + scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); + + { + Word32 Lener, att; + Word16 exp; + /* update CNG excitation energy for LP_CNG */ + + /* calculate the residual signal energy */ + /*enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;*/ + Lener = Dot_productSq16HQ( 1, hFdCngCom->exc_cng, st->L_frame, &exp ); + exp = add( sub( shl( sub( 15, *Q_new ), 1 ), 8 ), exp ); /*8 = log2(256)*/ + + /* convert log2 of residual signal energy */ + /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ + Lener = BASOP_Util_Log2( Lener ); + Lener = L_add( Lener, L_shl( L_deposit_l( exp ), WORD32_BITS - 1 - LD_DATA_SCALE ) ); /*Q25*/ + if ( EQ_16( st->L_frame, L_FRAME16k ) ) + { + Lener = L_sub( Lener, 10802114l /*0.3219280949f Q25*/ ); /*log2(320) = 8.3219280949f*/ + } + /* decrease the energy in case of WB input */ + IF( st->bwidth != NB ) + { + IF( EQ_16( st->bwidth, WB ) ) + { + IF( st->CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = L_shl( L_deposit_l( ENR_ATT_fx[st->CNG_mode] ), 17 ); + } + ELSE + { + /* Use least attenuation for higher bitrates */ + att = L_shl( L_deposit_l( ENR_ATT_fx[4] ), 17 ); + } + } + ELSE + { + att = 384 << 17; + move16(); /*1.5 Q8<<17=Q25*/ + } + Lener = L_sub( Lener, att ); + } + /*st->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ + Lener = BASOP_util_Pow2( Lener, 6, &exp ); + Lener = Mult_32_16( Lener, 6554 /*0.2f Q15*/ ); + exp = sub( 25, exp ); + Lener = L_shr( Lener, exp ); /*Q6*/ + st->lp_ener_fx = L_add( Mult_32_16( st->lp_ener_fx, 26214 /*0.8f Q15*/ ), Lener ); /*Q6*/ + } + + /* Generate Gaussian random noise in real and imaginary parts of the CLDFB bands + Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each band */ + + test(); + IF( bufferReal != NULL && ( LT_16( hFdCngCom->numCoreBands, hFdCngCom->regularStopBand ) ) ) + { + Word16 bufferReal_exp[CLDFB_NO_COL_MAX]; + Word16 bufferImag_exp[CLDFB_NO_COL_MAX]; + *bufferScale = 0; + move16(); + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) + { + sqrtNoiseLevel_exp = add( CLDFBinvScalingFactor_EXP, sub( cngNoiseLevel_exp, 1 ) ); + sqrtNoiseLevel = Sqrt32( Mpy_32_16_1( *ptr_level, scaleCldfb ), &sqrtNoiseLevel_exp ); + + FOR( i = 0; i < hFdCngCom->numSlots; i++ ) + { + /* Real part in CLDFB band */ + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) + { + rand_gauss_fx( &tmp1, seed, Q15 ); + rand_gauss_fx( &tmp2, seed2, Q15 ); + bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + move32(); + bufferReal_exp[j] = Q16; + move16(); + } + ELSE + { + rand_gauss_fx( &bufferReal[i][j], seed, Q15 ); + move32(); + bufferReal_exp[j] = Q16; + move16(); + } + + bufferReal[i][j] = Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ); + move32(); + bufferReal_exp[j] = add( bufferReal_exp[j], sqrtNoiseLevel_exp ); + move16(); + + /* Imaginary part in CLDFB band */ + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) + { + rand_gauss_fx( &tmp1, seed, Q15 ); + rand_gauss_fx( &tmp2, seed2, Q15 ); + bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); + move32(); + bufferImag_exp[j] = Q16; + move16(); + } + ELSE + { + rand_gauss_fx( &bufferImag[i][j], seed, Q15 ); + bufferImag_exp[j] = Q16; + move16(); + } + bufferImag[i][j] = Mpy_32_32( bufferImag[i][j], sqrtNoiseLevel ); + bufferImag_exp[j] = add( bufferImag_exp[j], sqrtNoiseLevel_exp ); + move16(); + + move32(); + } + ptr_level++; + } + + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) + { + *bufferScale = s_max( *bufferScale, bufferReal_exp[j] ); + move16(); + *bufferScale = s_max( *bufferScale, bufferImag_exp[j] ); + move16(); + } + + FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) + { + FOR( i = 0; i < hFdCngCom->numSlots; i++ ) + { + bufferImag[i][j] = L_shr( bufferImag[i][j], sub( *bufferScale, bufferImag_exp[j] ) ); + move32(); + bufferReal[i][j] = L_shr( bufferReal[i][j], sub( *bufferScale, bufferReal_exp[j] ) ); + move32(); + } + } + } + + test(); + IF( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) && EQ_16( st->codec_mode, MODE2 ) ) + { + Word32 old_exc_ener, gain, noise32; + Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; + Word16 old_exc_ener_exp, gain_exp; + Word16 normFacE, normShiftE, normShiftEM1; + Word16 normFacG, normShiftG, normShiftGM1; + Word16 noiseExp, *old_exc, *old_Aq, *old_syn_pe; + Word16 noise[640], normShiftP2; + Word16 Q_exc, Q_syn; + + + assert( hFdCngCom->frameSize <= 640 ); + + seed_loc = hFdCngCom->seed; + move16(); + N = hFdCngCom->frameSize; + move16(); + N2 = shr( hFdCngCom->frameSize, 1 ); + + IF( st->last_core_bfi > ACELP_CORE ) + { + Word16 left_overlap_mode; + left_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode; + move16(); + if ( EQ_16( left_overlap_mode, ALDO_WINDOW ) ) + { + left_overlap_mode = FULL_OVERLAP; + move16(); + } + tcx_windowing_synthesis_current_frame( timeDomainOutput, st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, + st->hTcxCfg->tcx_mdct_window_min_length, 0, left_overlap_mode, NULL, NULL, NULL, NULL, NULL, shr( N, 1 ), shr( sub( abs_s( st->hTcxCfg->tcx_offset ), st->hTcxCfg->tcx_offset ), 1 ), 1, 0, 0 ); + + IF( st->hTcxCfg->last_aldo != 0 ) + { + FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) + { + timeDomainOutput[i] = add( timeDomainOutput[i], shr_r( st->hHQ_core->old_out_LB_fx[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )], st->hHQ_core->Q_old_wtda_LB ) ); + move16(); + } + } + ELSE + { + tcx_windowing_synthesis_past_frame( hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, + st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->hTcxCfg->tcx_last_overlap_mode ); + + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) + { + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + move16(); + } + } + } + ELSE + { + + /* + - the scaling of the LPCs (e.g. old_Aq) is always Q12 (encoder or decoder) + + - the scaling of the deemphasized signals (e.g. old_syn) is always Q0 (encoder or decoder) + + - the scaling of the excitation signals in the encoder (e.g. old_exc) is Q_new + - the scaling of the preemphasized signals in the encoder (e.g. old_syn_pe) is Q_new-1 + + - the scaling of the excitation signals in the decoder (e.g. old_exc) is Q_exc (or stdec->Q_exc) + - the scaling of the preemphasized signals in the decoder (e.g. old_syn_pe) is Q_syn (or stdec->Q_syn) + */ + + lpcorder = M; + move16(); + old_Aq = st->old_Aq_12_8_fx; + old_exc = st->old_exc_fx + sub( L_EXC_MEM_DEC, N2 ); + old_syn_pe = st->mem_syn2_fx; + old_syn = st->syn[lpcorder]; + move16(); + preemph_fac = st->preemph_fac; + move16(); + Q_exc = st->Q_exc; + move16(); + Q_syn = st->Q_syn; + move16(); + + /* shift to be in the range of values supported by getNormReciprocalWord16() */ + N8 = shr( N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); + + assert( N2 == ( N8 << CNG_NORM_RECIPROCAL_RANGE_SHIFT ) ); + + normFacE = getNormReciprocalWord16( N8 ); + normShiftE = BASOP_util_norm_s_bands2shift( N8 ); + normShiftEM1 = sub( normShiftE, 1 ); + normShiftP2 = add( normShiftE, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); + + old_exc_ener = L_shr( L_mult( old_exc[0], old_exc[0] ), normShiftP2 ); + FOR( i = 1; i < N2; i++ ) + { + old_exc_ener = L_add( old_exc_ener, L_shr( L_mult( old_exc[i], old_exc[i] ), normShiftP2 ) ); + } + old_exc_ener = L_shl( Mpy_32_16_1( old_exc_ener, shl( normFacE, normShiftEM1 ) ), 1 ); + + old_exc_ener_exp = 0; + move16(); + old_exc_ener = Sqrt32( old_exc_ener, &old_exc_ener_exp ); + old_exc_ener_exp = add( old_exc_ener_exp, ( sub( 15, Q_exc ) ) ); + + /* shift to be in the range of values supported by getNormReciprocalWord16() */ + N4 = shr( N, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); + + assert( N == ( N4 << CNG_NORM_RECIPROCAL_RANGE_SHIFT ) ); + + normFacG = getNormReciprocalWord16( N4 ); + normShiftG = BASOP_util_norm_s_bands2shift( N4 ); + normShiftGM1 = sub( normShiftG, 1 ); + normShiftP2 = add( normShiftG, CNG_NORM_RECIPROCAL_RANGE_SHIFT ); + + gain = L_deposit_l( 0 ); + FOR( i = 0; i < N; i++ ) + { + noise32 = rand_gauss( &seed_loc ); + noise[i] = extract_h( noise32 ); + move16(); + gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); + } + gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); + + gain_exp = 2 * CNG_RAND_GAUSS_SHIFT; + move16(); + gain = ISqrt32( gain, &gain_exp ); + + gain = Mpy_32_32( old_exc_ener, gain ); + gain16 = extract_h( gain ); + + gain_exp = add( old_exc_ener_exp, gain_exp ); + noiseExp = add( CNG_RAND_GAUSS_SHIFT, gain_exp ); + + s = sub( 15 - NOISE_HEADROOM, noiseExp ); + FOR( i = 0; i < N; i++ ) + { +#ifdef BASOP_NOGLOB + noise[i] = shr_sat( mult( noise[i], gain16 ), s ); +#else + noise[i] = shr( mult( noise[i], gain16 ), s ); +#endif + move16(); + } + + assert( lpcorder <= 16 ); + + s = sub( 15 - NOISE_HEADROOM, ( sub( 15, Q_syn ) ) ); + FOR( i = 0; i < lpcorder; i++ ) + { +#ifdef BASOP_NOGLOB + old_syn_pe_tmp[i] = shr_sat( old_syn_pe[i], s ); +#else + old_syn_pe_tmp[i] = shr( old_syn_pe[i], s ); +#endif + move16(); + } + + E_UTIL_synthesis( + 0, /* i : scaling to apply for a[0] Q0 */ + old_Aq, /* i : LP filter coefficients Q12 */ + noise, /* i : input signal Qx */ + noise, /* o : output signal Qx-s */ + N, /* i : size of filtering Q0 */ + old_syn_pe_tmp, /* i/o: memory associated with this filtering. Q0 */ + 0, /* i : 0=no update, 1=update of memory. Q0 */ + lpcorder /* i : order of LP filter Q0 */ + ); + + tmp = old_syn; + move16(); + + E_UTIL_deemph2( + NOISE_HEADROOM, + noise, /* I/O: signal Qx */ + preemph_fac, /* I: deemphasis factor Qx */ + N, /* I: vector size */ + &tmp /* I/O: memory (signal[-1]) Qx */ + ); + + FOR( i = 0; i < N4; i++ ) + { + tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); + timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); + move16(); + tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); + timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); + move16(); + } + } + } + return; +} void generate_comfort_noise_dec_hf_fx( Word32 **bufferReal, /* o : matrix to real part of input bands */ @@ -3922,7 +4498,7 @@ void generate_comfort_noise_dec_hf_ivas_fx( move16(); } - randGaussExp = CNG_RAND_GAUSS_SHIFT; + randGaussExp = add( CNG_RAND_GAUSS_SHIFT, 1 ); move16(); /* @@ -3946,16 +4522,16 @@ void generate_comfort_noise_dec_hf_ivas_fx( IF( cng_coh_flag ) { - tmp1 = rand_gauss( seed ); - tmp2 = rand_gauss( seed2 ); + rand_gauss_fx( &tmp1, seed, Q28 ); + rand_gauss_fx( &tmp2, seed2, Q28 ); bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); move32(); bufferReal[i][j] = L_shl( Mpy_32_32( bufferReal[i][j], sqrtNoiseLevel ), s ); move32(); - tmp1 = rand_gauss( seed ); - tmp2 = rand_gauss( seed2 ); + rand_gauss_fx( &tmp1, seed, Q28 ); + rand_gauss_fx( &tmp2, seed2, Q28 ); bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); move32(); @@ -3965,11 +4541,11 @@ void generate_comfort_noise_dec_hf_ivas_fx( ELSE { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferReal[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); move32(); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl( Mpy_32_32( rand_gauss( seed ), sqrtNoiseLevel ), s ); + bufferImag[i][j] = L_shl( Mpy_32_32( L_shr( rand_gauss( seed ), 1 ), sqrtNoiseLevel ), s ); move32(); } } diff --git a/lib_dec/gain_dec.c b/lib_dec/gain_dec.c index 64ea85de20abba3152d48eef2fec0fc144b27782..c0aea3813c356a4e81a6ecd9b5427bbb944e65bf 100644 --- a/lib_dec/gain_dec.c +++ b/lib_dec/gain_dec.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Es_pred_dec() * @@ -694,3 +695,4 @@ float gain_dec_gaus( return gain; } +#endif diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index ff97e81cd27b30ccc264436802328cd240f7d5f6..d9639bbcc716a624e62b32ec011a9ffc4dc278d0 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*===========================================================================*/ @@ -163,7 +162,7 @@ void gain_dec_tc_fx( *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); @@ -303,7 +302,7 @@ void gain_dec_tc_ivas_fx( *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); IF( GT_16( nBits, 3 ) ) @@ -401,7 +400,7 @@ void gain_dec_mless_fx( ( EQ_16( tc_subfr_fx, 4 * L_SUBFR ) && EQ_16( i_subfr_fx, 4 * L_SUBFR ) && EQ_16( L_frame_fx, L_FRAME16k ) ) ) { /* decode pitch gain */ - index = (Word16) get_next_indice( st_fx, shr( nBits, 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( nBits, 1 ) ); /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ tmp_fx = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /*Q15*/ @@ -455,7 +454,7 @@ void gain_dec_mless_fx( /* decode normalized codebook gain */ /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ - index = (Word16) get_next_indice( st_fx, shr( add( nBits, 1 ), 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ gain_code16 = gain_dequant_fx( index, G_CODE_MIN_TC192_Q15, G_CODE_MAX_TC192_Q0, shr( add( nBits, 1 ), 1 ), &expg ); @@ -506,7 +505,7 @@ void gain_dec_mless_fx( nBits = sub( nBits, 1 ); } - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *gain_pit_fx = qua_table_fx[index * 2]; move16(); @@ -723,7 +722,7 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *gain_pit_fx = cdbk_fx[index * 2]; move16(); @@ -796,7 +795,7 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *gain_pit_fx = cdbk_fx[index * 2]; move16(); @@ -873,7 +872,7 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *gain_pit_fx = cdbk_fx[shl( index, 1 )]; move16(); @@ -960,7 +959,7 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); *gain_pit_fx = cdbk_fx[shl( index, 1 )]; move16(); @@ -1109,6 +1108,147 @@ void lp_gain_updt_fx( return; } +/*====================================================================== */ +/* FUNCTION : lp_gain_updt_ivas_fx() */ +/*-----------------------------------------------------------------------*/ +/* PURPOSE : Update of LP pitch and code gains (FEC) */ +/* */ +/*-----------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) i_subfr : subframe number Q0 */ +/* _ (Word16) gain_pit : Decoded gain pitch Q14 */ +/* _ (Word32) norm_gain_code : Normalised gain code Q16 */ +/* _ (Word16) L_frame : length of the frame Q0 */ +/*-----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16 *) T0 : close loop integer pitch */ +/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ +/* _ (Word16 ) pitch : pitch value Q6 */ +/*-----------------------------------------------------------------------*/ +/* INPUT OUTPUT ARGUMENTS */ +/* _ (Word16 *) lp_gainp : LP-filtered pitch gain(FEC) Q14 */ +/* _ (Word16 *) lp_gainc : LP-filtered code gain (FEC) Q3 */ +/*-----------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*=======================================================================*/ + + +void lp_gain_updt_ivas_fx( + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ +) +{ + Word16 tmp; + +#ifdef BASOP_NOGLOB + tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ +#else + tmp = extract_h( L_shl( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ +#endif + /* To handle extremely low values */ + test(); + if ( norm_gain_code != 0 && tmp == 0 ) + { + tmp = 1; + move16(); + } + + IF( EQ_16( L_frame, L_FRAME ) ) + { + IF( EQ_16( i_subfr, 0 ) ) + { + *lp_gainp = mult( 3277, gain_pit ); + move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 3277, tmp ); + move16(); /* (15+3)-15 -> Q3*/ + } + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (0.2 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 9830, gain_pit ) ); + move16(); /*Q14 (0.3 in Q15 = 9830)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 9830, tmp ); + move16(); /*Q3*/ + } + ELSE /* i_subfr == 3*L_SUBFR */ + { + *lp_gainp = add( *lp_gainp, mult( 13107, gain_pit ) ); + move16(); /*Q14 (0.4 in Q15 = 13107)*/ +#ifdef BASOP_NOGLOB + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 13107, tmp ); +#else + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 13107, tmp ); +#endif + move16(); /*Q3*/ + } + } + ELSE + { + IF( i_subfr == 0 ) + { + *lp_gainp = mult( 2185, gain_pit ); + move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 2185, tmp ); + move16(); /* (15+3)-15 -> Q3*/ + } + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 4369, gain_pit ) ); + move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 4369, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 8738, gain_pit ) ); + move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 8738, tmp ); + move16(); /*Q3*/ + } + ELSE /* i_subfr == 4*L_SUBFR */ + { + *lp_gainp = add( *lp_gainp, mult( 10923, gain_pit ) ); + move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ +#ifdef BASOP_NOGLOB + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 10923, tmp ); +#else + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 10923, tmp ); +#endif + move16(); /*Q3*/ + } + } + + /* To handle extremely low values */ + test(); + if ( tmp != 0 && *lp_gainc == 0 ) + { + *lp_gainc = 1; + move16(); + } + + return; +} + /*-------------------------------------------------* * Gain_dec_gaus_vbr * @@ -1210,7 +1350,7 @@ void gain_dec_SQ_fx( * decode pitch gain *-----------------------------------------------------------------*/ - index = (Word16) get_next_indice( st_fx, shr( nBits, 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( nBits, 1 ) ); /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1); set quantization step */ tmp16 = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /* Q15*/ @@ -1260,7 +1400,7 @@ void gain_dec_SQ_fx( * decode normalized codebook gain *-----------------------------------------------------------------*/ - index = (Word16) get_next_indice( st_fx, shr( add( nBits, 1 ), 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); tmp16 = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, shr( add( nBits, 1 ), 1 ), &expg ); @@ -1376,7 +1516,7 @@ void gain_dec_amr_wb_fx( * Decode pitch gain *-----------------------------------------------------------------*/ - index = (Word16) get_next_indice( st_fx, nbits ); + index = (Word16) get_next_indice_fx( st_fx, nbits ); index2 = shl( index, 1 ); *gain_pit = t_qua_gain[index2]; move16(); diff --git a/lib_dec/gaus_dec.c b/lib_dec/gaus_dec.c index e5d7adc32798bb6c4e8a4afa87caa6b14e1af1c6..b7a89bec99f8ed94f03d2c395d29b2675e0b0191 100644 --- a/lib_dec/gaus_dec.c +++ b/lib_dec/gaus_dec.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -263,3 +264,4 @@ void gaus_L2_dec_flt( return; } +#endif diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index dc999e3f0276eb4b9d30ac77fd3f9e68beb9a4bf..7b70d7281d7727278eaf889b793dd831bad203ce 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*---------------------------------------------------------------------* * Local function prototypes @@ -71,7 +70,7 @@ void gaus_dec_fx( nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; move16(); - idx = (Word16) get_next_indice( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* safety check in case of bit errors */ test(); @@ -87,7 +86,14 @@ void gaus_dec_fx( move32(); /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + IF( st_fx->element_mode == EVS_MONO ) + { + lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + } + ELSE + { + lp_gain_updt_ivas_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + } /*------------------------------------------------------------------------------------------* * Updates @@ -159,8 +165,8 @@ void gaus_dec2v_fx( step = shr( 0x80, nb_bits ); - idx = (Word16) get_next_indice( st_fx, add( shl( nb_bits, 1 ), 1 ) ); - index_delta = (Word16) get_next_indice( st_fx, 3 ); + idx = (Word16) get_next_indice_fx( st_fx, add( shl( nb_bits, 1 ), 1 ) ); + index_delta = (Word16) get_next_indice_fx( st_fx, 3 ); dec_2pos_fx( idx, &ind1, &ind2, &sign1, &sign2, nb_bits ); diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index 4ad733294b40f95c2d6449e7e7fcf1c068c0420c..5864c697cc2caae3420577ab2bcdaee58a45d50a 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index bd5f9b7f84fb74e7f634bd8e02e3643cb036b081..4fa3ee0aeb163a5fa403e9e7c35f947a15c3a964 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #ifdef IVAS_FLOAT_FIXED /*=========================================================================*/ @@ -72,7 +71,7 @@ void decod_audio_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* decode GSC SWB speech flag */ test(); @@ -83,7 +82,7 @@ void decod_audio_fx( ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); } @@ -144,12 +143,12 @@ void decod_audio_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); move16(); } @@ -180,7 +179,7 @@ void decod_audio_fx( nbits = 2; } #endif - nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); if ( s_and( nb_frame_flg, 0x1 ) == 0 ) { @@ -237,7 +236,7 @@ void decod_audio_fx( } ELSE { - pit_band_idx = (Word16) get_next_indice( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); } if ( pit_band_idx != 0 ) @@ -294,7 +293,7 @@ void decod_audio_fx( move16(); } - indice = get_next_indice( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -577,7 +576,7 @@ void decod_audio_ivas_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* decode GSC SWB speech flag */ test(); @@ -594,7 +593,7 @@ void decod_audio_ivas_fx( ( st_fx->element_mode > EVS_MONO && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); } @@ -660,12 +659,12 @@ void decod_audio_ivas_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); move16(); } @@ -702,7 +701,7 @@ void decod_audio_ivas_fx( move16(); } #endif - nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); test(); IF( s_and( nb_frame_flg, 0x1 ) == 0 ) @@ -763,7 +762,7 @@ void decod_audio_ivas_fx( } ELSE { - pit_band_idx = (Word16) get_next_indice( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); } IF( pit_band_idx != 0 ) @@ -827,7 +826,7 @@ void decod_audio_ivas_fx( move16(); } - indice = get_next_indice( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 4894ee0e86d7fd53aba25d7cd2260a97f3749a10..28aeeceb42f25d6fbc53baf6a13cc96e080fa37a 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_dec.h" /*--------------------------------------------------------------------------*/ @@ -33,12 +32,12 @@ void hdecnrm_fx( k = (Word16) 0; move16(); - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { j = (Word16) 1; move16(); } - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { k = (Word16) 1; move16(); @@ -46,14 +45,14 @@ void hdecnrm_fx( n = add( shl( j, 1 ), k ); j = shl( j, 2 ); temp = sub( add( 16, n ), j ); - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( add( 12, n ), j ); - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { j = (Word16) 0; move16(); - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { j = 1; move16(); @@ -63,12 +62,12 @@ void hdecnrm_fx( { temp = add( temp, 12 ); } - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { temp = n; move16(); - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( 4, n ); } @@ -111,7 +110,7 @@ Word16 decode_huff_context_fx( tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); *rbits = add( *rbits, tmp_l ); move16(); - hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice( st_fx, tmp_l ) ) ); + hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); } return negate( hufftab[hufftab_idx] ); } @@ -190,7 +189,7 @@ void hdecnrm_resize_fx( FOR( j = 0; j < 11; j++ ) { - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { k = add( k, 1 ); move16(); @@ -217,7 +216,7 @@ void hdecnrm_resize_fx( move16(); } ELSE{ - IF( get_next_indice_1( st_fx ) != 0 ){ + IF( get_next_indice_1_fx( st_fx ) != 0 ){ temp = add( 16, k ); } ELSE @@ -267,7 +266,7 @@ void huff_dec_fx( last_bits = sub( buffer_len, j ); val = lshl( val, last_bits ); val = s_and( val, sub( lshl( 1, buffer_len ), 1 ) ); - val = s_or( val, get_next_indice( st_fx, last_bits ) ); + val = s_or( val, get_next_indice_fx( st_fx, last_bits ) ); /* Find codeword length */ j = sub( num_lengths, 1 ); @@ -313,13 +312,13 @@ void hdecnrm_tran_fx( move16(); k = 0; move16(); - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { j = 1; move16(); } - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { k = 1; move16(); @@ -339,17 +338,17 @@ void hdecnrm_tran_fx( temp = sub( add( 15, l ), n ); } ELSE{ - IF( get_next_indice_1( st_fx ) != 0 ){ + IF( get_next_indice_1_fx( st_fx ) != 0 ){ temp = sub( add( 15, n ), l ); } ELSE { temp = sub( add( 15, l ), n ); - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { FOR( k = 0; k < 3; ) { - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { k = add( k, 1 ); } @@ -375,10 +374,10 @@ void hdecnrm_tran_fx( ELSE { temp = add( temp, 2 ); - IF( get_next_indice_1( st_fx ) != 0 ) + IF( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( temp, 1 ); - if ( get_next_indice_1( st_fx ) != 0 ) + if ( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( temp, 1 ); } diff --git a/lib_dec/hf_synth.c b/lib_dec/hf_synth.c index 38aaab11ffe715db0edd2c8805e101619e797728..b2589a9bc600874872e006f9bb64e9a4cc5fe309 100644 --- a/lib_dec/hf_synth.c +++ b/lib_dec/hf_synth.c @@ -42,8 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "basop32.h" #endif diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index a40ae1a3045c7f5deb2223dffdb2676875a9a639..cee42b0ca04ff1a1117570370a21b384a6eefc1d 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #include "basop32.h" #include "prot.h" diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index 3a2d3f511590da1ab414f1e8d745c735cb96a8fb..ace2e535ceeb365b5bac2e1f9a761456c0ef9ed9 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -2,9 +2,8 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -39,7 +38,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); move16(); bits = 2; move16(); @@ -53,7 +52,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); move16(); bits = 1; move16(); diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dacd23a76b6e7260b16ad05d0f6e5db86d485ee2..dfc19c542dae9ad137e032b0afd4ae1a6cd7ed1f 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index fb0f5f02471dbb37fe336e69a09bdd48115ffd5c..bde72c4a35cb7a62306ae1f50574d49e22d1d5d8 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "prot.h" #include "ivas_prot_fx.h" @@ -197,7 +196,7 @@ void hq_core_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); @@ -713,7 +712,7 @@ void ivas_hq_core_dec_fx( test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); num_bits = sub( num_bits, 1 ); } ELSE @@ -782,7 +781,7 @@ void ivas_hq_core_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); @@ -925,7 +924,7 @@ void ivas_hq_core_dec_fx( move16(); L_spec = hTcxDec->L_frameTCX; move16(); - st_fx->fscale = sr2fscale( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 0226c32f3d65f6538e2d87b2954c4e2b9a804e45..db710413e4034b92011371f94257ec8b64a22ffc 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------* @@ -35,13 +34,13 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); } ELSE { - LCmode = (Word16) get_next_indice( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); } test(); @@ -131,7 +130,7 @@ Word16 decode_envelope_indices_fx( /* o : Number of b pDifidx = &difidx[startNormPlus1]; FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); move16(); } hcode_l = numnrmibits; diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index d42acd11bde6ea877da0fbd31892f66f2eadb654..a4c5ebf13cf9457ed55d6a94d4da784b06e0e9b1 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -2,10 +2,9 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -225,7 +224,7 @@ void ivas_hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); } /*------------------------------------------------------------------* diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index a454af97a75ac6ebe558732edffe0c895853dbaa..f6bedf43ba4906ebb8f50ab9d9b46aa23d3560d3 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" #include "rom_dec.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /*--------------------------------------------------------------------------* @@ -75,7 +74,7 @@ static void spt_shorten_domain_set_dec_fx( move16(); IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice( st_fx, 1 ); + spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); *bit_budget = sub( *bit_budget, 1 ); IF( EQ_16( spt_shorten_flag[j], 1 ) ) { @@ -202,7 +201,7 @@ void hq_lr_dec_fx( test(); IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - hqswb_clas_fx = get_next_indice( st_fx, 2 ); + hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); num_bits = sub( num_bits, 2 ); *is_transient_fx = 0; @@ -216,7 +215,7 @@ void hq_lr_dec_fx( ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice( st_fx, 1 ); + *is_transient_fx = get_next_indice_fx( st_fx, 1 ); num_bits = sub( num_bits, 1 ); } @@ -390,7 +389,7 @@ void hq_lr_dec_fx( j = 0; FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); move16(); } lowband = 6; @@ -604,7 +603,7 @@ void hq_lr_dec_fx( FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); move16(); } FOR( i = 0; i < bands_fx; i++ ) @@ -1017,7 +1016,7 @@ static Word16 small_symbol_dec_fx( /* o : bits /* Decoding LSB bit packing */ FOR( i = 0; i < bands; ++i ) { - LSB = get_next_indice( st_fx, BITS_DE_LSB ); + LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); move16(); } @@ -1049,7 +1048,7 @@ static Word16 decode_huff_8s_fx( WHILE( *hufftab > 0 ) { *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); - bit = get_next_indice( st_fx, s_and( *hufftab, 0xf ) ); + bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); move16(); hufftab += add( shr( *hufftab, 4 ), bit ); } @@ -1071,21 +1070,21 @@ static Word16 large_symbol_dec_fx( /* o : bits cntbits = BITS_DE_8SMODE; move16(); - ns2mode = get_next_indice( st_fx, BITS_DE_8SMODE ); + ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice( st_fx, BITS_DE_8SMODE_N0 ); - ns2mode1 = get_next_indice( st_fx, BITS_DE_8SMODE_N1 ); + ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); + ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice( st_fx, BITS_DE_8SPOS ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[pos_outlyer] = sub( get_next_indice( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); move16(); cntbits = add( cntbits, BITS_ABS_ENG ); } @@ -1117,12 +1116,12 @@ static Word16 large_symbol_dec_fx( /* o : bits { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice( st_fx, BITS_DE_8SPOS ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[0] = sub( get_next_indice( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); move16(); cntbits = add( cntbits, BITS_ABS_ENG ); - qbidx[pos_outlyer] = sub( get_next_indice( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); move16(); cntbits = add( cntbits, BITS_ABS_ENG ); } @@ -1130,7 +1129,7 @@ static Word16 large_symbol_dec_fx( /* o : bits { pos_outlyer = 0; move16(); - qbidx[0] = sub( get_next_indice( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); move16(); cntbits = add( cntbits, BITS_ABS_ENG ); } @@ -1156,7 +1155,7 @@ static Word16 large_symbol_dec_fx( /* o : bits } ELSE { - basic_shift = get_next_indice( st_fx, BITS_MAX_DEPTH ); + basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); cntbits = add( cntbits, BITS_MAX_DEPTH ); FOR( i = 0; i < bands; ++i ) @@ -1172,7 +1171,7 @@ static Word16 large_symbol_dec_fx( /* o : bits FOR( i = 0; i < bands; ++i ) { - LSB[0] = get_next_indice( st_fx, basic_shift ); + LSB[0] = get_next_indice_fx( st_fx, basic_shift ); move16(); qbidx[i] = add( qbidx[i], LSB[0] ); move16(); @@ -1213,7 +1212,7 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ - deng_cmode = get_next_indice( st_fx, BITS_DE_CMODE ); + deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); IF( deng_cmode == 0 ) { @@ -1292,7 +1291,7 @@ static Word16 p2a_threshold_dequant_fx( move16(); FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) { - p2a_flags[k] = get_next_indice( st_fx, 1 ); + p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); move16(); j = add( j, 1 ); } @@ -1362,7 +1361,7 @@ static void mdct_spectrum_fine_gain_dec_fx( FOR( k = sub( bands, Ngq ); k < bands; k++ ) { - imin_fx = get_next_indice( st_fx, gqbits ); + imin_fx = get_next_indice_fx( st_fx, gqbits ); /*gamma = gain_table[imin]; */ gamma_fx = gain_table_fx[imin_fx]; diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index c6d72f5d8370a2dbc070f5f9186e347e148c4163..451b7e29b4efbef64de34d96fa653d7b4af8dc7e 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -44,7 +44,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index cdcdfab1fdf57e279687f11d55683d01b3339bee..7f1545e8d9ca9a71f55954ddcf619403a11154c1 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -11,8 +11,7 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" #include "stat_dec.h" #include "basop_util.h" @@ -283,9 +282,12 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in IF( TCXNoise[sb] ) { Word16 nrm = norm_l( in[sb] ); - in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp - in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e - in[sb] = L_shr( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original + in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp + move32(); + in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e + move32(); + /* To handle corner cases */ + in[sb] = L_shr_sat( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original move32(); } } @@ -389,7 +391,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, Word16 tmp; - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); IF( tmp == 0 ) { @@ -399,7 +401,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, return; } - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); @@ -417,7 +419,7 @@ static void IGF_decode_temp_flattening_trigger( Decoder_State *st, IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { - hInstance->flatteningTrigger = get_next_indice( st, 1 ); + hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); } /**********************************************************************/ /* @@ -3080,7 +3082,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in IF( isIndepFrame == 0 ) { - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); } IF( tmp == 1 ) @@ -3102,7 +3104,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } ELSE { - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); } IF( EQ_16( tmp, 1 ) ) @@ -3165,7 +3167,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins IF( isIndepFrame == 0 ) { - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); } IF( EQ_16( tmp, 1 ) ) @@ -3179,7 +3181,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) @@ -3233,7 +3235,7 @@ void IGFDecReadLevel( /**< ou hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; move16(); - IGFAllZero = get_next_indice( st, 1 ); + IGFAllZero = get_next_indice_fx( st, 1 ); IF( IGFAllZero == 0 ) { @@ -4018,6 +4020,9 @@ void IGFDecSetMode_ivas_fx( hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; + hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; + hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; return; } /**********************************************************************/ /* @@ -4095,7 +4100,7 @@ void IGFDecReplicateTCX10State_fx( ) { Copy( &hIGFDec->flag_sparseBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->flag_sparseBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); - mvs2s( &hIGFDec->infoTCXNoise_evs[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoise_evs[0], ( IGF_START_MX ) / 2 ); + Copy( &hIGFDec->infoTCXNoise_evs[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoise_evs[0], ( IGF_START_MX ) / 2 ); /* TODO: remove float dependency */ // mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index b9af11db158cb9d6c6b54ac4ac8f25b90962933e..221b9b7a4981e17944331cf6875eafc25a4bd080 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -8,8 +8,7 @@ #include #include "options.h" #include "stl.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stat_dec.h" #include "basop_util.h" diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 3a56b99e54f42c4d30e836e57b91e706890c602e..908738df38be464283726ae416d55ca9a586924e 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -40,12 +40,9 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index ba95b6933bb73c2db66eaaaee5f4ae21f4104ac6..bed5c11bb8b4f6d2901b06cf656b184b61575a0b 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -3,8 +3,7 @@ ====================================================================================*/ #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ #include "stl.h" /* required for wmc_tool */ @@ -132,7 +131,7 @@ ivas_error init_decoder_fx( test(); IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) count_malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } @@ -151,7 +150,7 @@ ivas_error init_decoder_fx( test(); IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) count_malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); } @@ -171,7 +170,7 @@ ivas_error init_decoder_fx( IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) count_malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); } @@ -211,7 +210,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) count_malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } @@ -229,7 +228,7 @@ ivas_error init_decoder_fx( test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); } @@ -250,7 +249,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) count_malloc( sizeof( PFSTAT ) ) ) == NULL ) + IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); } @@ -338,7 +337,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); } @@ -356,7 +355,7 @@ ivas_error init_decoder_fx( test(); IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) count_malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } @@ -433,7 +432,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || ( st_fx->element_mode == EVS_MONO ) ) ) { - IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) count_malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } @@ -444,7 +443,7 @@ ivas_error init_decoder_fx( IF( st_fx->element_mode == EVS_MONO ) { /* HQ NB FEC initialization */ - IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) count_malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); } @@ -482,7 +481,7 @@ ivas_error init_decoder_fx( /* TCX-LTP */ IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } @@ -496,7 +495,7 @@ ivas_error init_decoder_fx( // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) count_malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); } @@ -513,7 +512,7 @@ ivas_error init_decoder_fx( /* TCX config. data structure */ IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } @@ -529,8 +528,8 @@ ivas_error init_decoder_fx( st_fx->tilt_wb_fx = 0; move16(); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, DELAY_BWE_TOTAL_NS ) ); + set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); st_fx->old_bwe_delay = -1; /*Q0*/ move16(); @@ -541,7 +540,7 @@ ivas_error init_decoder_fx( test(); IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) count_malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -628,7 +627,7 @@ ivas_error init_decoder_fx( test(); IF( st_fx->Opt_AMR_WB || st_fx->element_mode == EVS_MONO ) { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) count_malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } @@ -650,7 +649,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) count_malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); } @@ -677,7 +676,7 @@ ivas_error init_decoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) count_malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); } @@ -736,7 +735,7 @@ ivas_error init_decoder_fx( IF( st_fx->element_mode == EVS_MONO ) { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) count_malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } @@ -1092,10 +1091,10 @@ ivas_error init_decoder_ivas_fx( st_fx->last_voice_factor_fx = 0; move16(); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); st_fx->Qprev_synth_buffer_fx = 15; move16(); - set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); st_fx->old_bfi_cnt = 0; move16(); @@ -1115,7 +1114,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) count_malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } @@ -1134,7 +1133,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); } @@ -1154,7 +1153,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) count_malloc( sizeof( PFSTAT ) ) ) == NULL ) + IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); } @@ -1198,7 +1197,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); } @@ -1232,7 +1231,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( idchan == 0 && ( EQ_16( st_fx->element_mode, EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) count_malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } @@ -1326,7 +1325,7 @@ ivas_error init_decoder_ivas_fx( st_fx->old_bwe_delay = -1; /*Q0*/ move16(); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2( 48000, DELAY_BWE_TOTAL_NS ) ); + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); /*-----------------------------------------------------------------* * SWB BWE parameters @@ -1379,7 +1378,7 @@ ivas_error init_decoder_ivas_fx( IF( ( st_fx->element_mode == EVS_MONO ) ) { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) count_malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); } @@ -1397,7 +1396,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) count_malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } @@ -1533,7 +1532,7 @@ ivas_error init_decoder_ivas_fx( IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) count_malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } @@ -1572,7 +1571,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } @@ -1593,8 +1592,8 @@ ivas_error init_decoder_ivas_fx( set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); } ELSE { @@ -1605,7 +1604,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } diff --git a/lib_dec/inov_dec.c b/lib_dec/inov_dec.c index ad5df5d4abeb3af4c0e97ea076c7895c633c2a7d..03831b28c66bf4eb251d370c71328bafb4d3a8a3 100644 --- a/lib_dec/inov_dec.c +++ b/lib_dec/inov_dec.c @@ -38,7 +38,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 24c82e20ae7ad543f189a81c92c62b648bae2ca5..49461af4dcd044297b109f2f08e2470f3d3ab0f0 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED /*======================================================================*/ /* FUNCTION : inov_decode_fx() */ @@ -122,12 +121,12 @@ void inov_decode_fx( // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); move16(); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; @@ -312,11 +311,11 @@ void inov_decode_ivas_fx( // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); diff --git a/lib_dec/ivas_agc_dec.c b/lib_dec/ivas_agc_dec.c index 83a2147632fb5d79ff12e48b1103bc960402bad2..6296e6c12925bcc0f37788adca8cc4465c116013 100644 --- a/lib_dec/ivas_agc_dec.c +++ b/lib_dec/ivas_agc_dec.c @@ -31,13 +31,13 @@ *******************************************************************************************************/ #include +#include +#include #include "options.h" +#include "wmc_auto.h" #ifndef IVAS_FLOAT_FIXED #include "prot.h" #include "ivas_prot.h" -#include -#include -#include "wmc_auto.h" /*-----------------------------------------------------------------------------------------* diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c index 2bf3ad9ca4c121a92fcf8237d012f7bdd187bc24..bd01d2f04d08f102b7ad32bbebbb52d9c8e41e07 100644 --- a/lib_dec/ivas_agc_dec_fx.c +++ b/lib_dec/ivas_agc_dec_fx.c @@ -35,7 +35,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include @@ -108,7 +108,7 @@ ivas_error ivas_spar_agc_dec_open_fx( } output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - delay = NS2SA_fx2( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); + delay = NS2SA_FX2( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); move16(); IF( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( output_frame - delay ) ) ) == NULL ) diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 0f92acf2d646b5745ec95ebf22170e1dc2bffd0e..109c076dd95d2a7157c17716748c05d5946c1c26 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -44,8 +44,7 @@ #include "ivas_rom_binauralRenderer.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com_fx.h" #include "debug.h" #endif @@ -1421,8 +1420,8 @@ static ivas_error ivas_binaural_hrtf_open_fx( } } } - mvl2l( fastconvReverberationTimes_fx, HrtfFastConv->fastconvReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX ); - mvl2l( fastconvReverberationEneCorrections_fx, HrtfFastConv->fastconvReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( fastconvReverberationTimes_fx, HrtfFastConv->fastconvReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( fastconvReverberationEneCorrections_fx, HrtfFastConv->fastconvReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX ); *hHrtfFastConv = HrtfFastConv; } @@ -1693,14 +1692,14 @@ static void ivas_binaural_obtain_DMX_fx( { FOR( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) { - set_l( realDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); - set_l( imagDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( realDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX ); } } FOR( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) { - set_l( P_in_fx, 0, hBinRenderer->conv_band ); + set32_fx( P_in_fx, 0, hBinRenderer->conv_band ); FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { @@ -1777,10 +1776,10 @@ static void ivas_binaural_obtain_DMX_fx( outImagLeftPtr_fx = imagDMX[0][k]; outRealRightPtr_fx = realDMX[1][k]; outImagRightPtr_fx = imagDMX[1][k]; - set_l( outRealLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); - set_l( outImagLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); - set_l( outRealRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); - set_l( outImagRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( outRealLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( outImagLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( outRealRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( outImagRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX ); FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 4ee545e4923c21dc398826f47350f8350a45520e..5ed51a26c6429c6b38ef68fe8b66e622682d8ea1 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1,2299 +1,2354 @@ -/****************************************************************************************************** - - (C) 2022-2024 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 -#include -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "ivas_prot.h" -#include "ivas_prot_fx.h" -#include "ivas_rom_com.h" -#include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" -#include "ivas_prot_fx.h" -#endif - -/*-------------------------------------------------------------------* - * ivas_core_dec() - * - * Principal IVAS core decoder routine, where number of core channels is 1 or 2 - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_core_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const Word16 n_channels, /* i : number of channels to be decoded */ - Word32 *output_32_fx[], /* o : output synthesis signal */ - Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -) -{ - Word16 i, n, output_frame; - Decoder_State **sts, *st; - STEREO_ICBWE_DEC_HANDLE hStereoICBWE; - STEREO_TD_DEC_DATA_HANDLE hStereoTD; - Word16 sharpFlag[CPE_CHANNELS]; - Word16 tmp_buffer_fx[L_FRAME48k]; - set_s( tmp_buffer_fx, 0, L_FRAME48k ); - Word16 tmp16, tmp16_2, j; - tmp16 = 0; - move16(); - Word16 Q_white_exc; - Q_white_exc = 0; - move16(); - - Word16 tmps, incr; - Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - - Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; - Word16 core_switching_flag[CPE_CHANNELS]; - - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; - Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; - - Word16 unbits[CPE_CHANNELS]; - Word16 sid_bw[CPE_CHANNELS]; - FRAME_MODE frameMode[CPE_CHANNELS]; - Word16 tdm_LRTD_flag; - Word32 element_brate, output_Fs; - Word32 last_element_brate; - Word16 use_cldfb_for_dft; - Word32 *p_output_mem_fx; - Word16 flag_sec_CNA; - Word16 read_sid_info; - Word16 last_element_mode; - Word16 nchan_out; - Word32 *save_hb_synth_32_fx; - ivas_error error; - Word32 L_tmp; - Word16 Q_synth; - Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - - Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; - - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); - set16_fx( output_16_fx[i], 0, L_FRAME48k ); - } - - Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; - Word32 conceal_eof_gain32; - -#ifdef BASOP_NOGLOB - Flag Overflow; -#endif - - error = IVAS_ERR_OK; - move32(); - push_wmops( "ivas_core_dec" ); - - /*------------------------------------------------------------------* - * General initialization - *-----------------------------------------------------------------*/ - - use_cldfb_for_dft = 0; - move16(); - tdm_LRTD_flag = -1; - move16(); - read_sid_info = 1; /* read SID by default */ - move16(); - - IF( hSCE != NULL ) - { - sts = hSCE->hCoreCoder; - hStereoICBWE = NULL; - element_brate = hSCE->element_brate; - move32(); - last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ - move32(); - last_element_mode = IVAS_SCE; - move16(); - hStereoTD = NULL; - p_output_mem_fx = NULL; - nchan_out = 1; - move16(); - test(); - IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) - { - if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) - { - read_sid_info = 0; - move16(); - } - } - } - ELSE - { - sts = hCPE->hCoreCoder; - element_brate = hCPE->element_brate; - move32(); - last_element_brate = hCPE->last_element_brate; - move32(); - last_element_mode = hCPE->last_element_mode; - move16(); - hStereoICBWE = hCPE->hStereoICBWE; - hStereoTD = hCPE->hStereoTD; - p_output_mem_fx = hCPE->output_mem_fx[1]; - - nchan_out = hCPE->nchan_out; - move16(); - - if ( hCPE->hStereoTD != NULL ) - { - tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; - move16(); - } - - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) - { - test(); - IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) - { - use_cldfb_for_dft = 1; - move16(); - } - ELSE - { - use_cldfb_for_dft = 0; - move16(); - } - } - } - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbAna->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - } - } - - output_Fs = sts[0]->output_Fs; - move32(); - output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*------------------------------------------------------------------* - * Initialization per core-decoder channel - *-----------------------------------------------------------------*/ - - frameMode[n] = FRAMEMODE_NORMAL; - move32(); - st->rate_switching_reset = 0; - move16(); - st->mdct_sw = MODE1; - move16(); - sid_bw[n] = -1; - move16(); - core_switching_flag[n] = 0; - move16(); - sharpFlag[n] = 0; - move16(); - unbits[n] = 0; - move16(); - st->GSC_IVAS_mode = 0; - move16(); - st->element_brate = element_brate; - move32(); - st->use_partial_copy = 0; - move16(); - st->rf_flag = 0; - move16(); - st->rf_frame_type = RF_NO_DATA; - move16(); - - IF( EQ_16( st->bfi, 1 ) ) - { - frameMode[n] = FRAMEMODE_MISSING; - move32(); - st->coder_type = st->last_coder_type; - move16(); - } - ELSE - { - test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ - { - st->coder_type = INACTIVE; - move16(); - } - st->extl = -1; - move16(); - st->flagGuidedAcelp = 0; - move16(); - } - - test(); - test(); - test(); - test(); - IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) - { - conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); - - FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) - { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 - } - - FOR( i = 0; i < st->L_frame; i++ ) - { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 - } - } - - set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); - set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); - set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); - /*------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_16( st->bfi, 1 ) ) - { - ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); - - synchonize_channels_mdct_sid_fx( sts, n ); - - IF( NE_16( st->bfi, 1 ) ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ - { - st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); - st->fscale_old = st->fscale; - move16(); - st->fscale = sr2fscale( st->sr_core ); - } - ELSE - { - frameMode[n] = FRAMEMODE_MISSING; - move32(); - } - } - ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) - { - st->core = TCX_20_CORE; - move16(); - } - } /* n_channels loop */ - - /* MDCT stereo -> DFT stereo switching */ - test(); - test(); - IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) - { - Word16 ovl, fade_len; - IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) - { - Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); - L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); - } - IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) - { - ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ - L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); - - fade_len = mult( sts[0]->L_frame, 12288 ); /* STEREO_MDCT2DFT_FADE_LEN_48k/L_FRAME16k = 3/8 = 12288 (Q15)*/ - L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); - } - } - - test(); - IF( hCPE != NULL && hCPE->hStereoCng != NULL ) - { - hCPE->hStereoCng->flag_cna_fade = 0; - move16(); - } - - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) - { - save_hb_synth_32_fx = hSCE->save_hb_synth_fx; - } - ELSE - { - save_hb_synth_32_fx = NULL; - } - - /*------------------------------------------------------------------* - * Decode SID for MDCT-Stereo DTX mode - *-----------------------------------------------------------------*/ - - test(); - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) - { - IF( sts[0]->cng_sba_flag ) - { - FdCngDecodeDiracMDCTStereoSID_fx( hCPE ); - } - ELSE - { - FdCngDecodeMDCTStereoSID_fx( hCPE ); - } - } - - /*------------------------------------------------------------------* - * Sanity check in combined format coding - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) - { - ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); - } - - /*------------------------------------------------------------------* - * Core Decoding - *-----------------------------------------------------------------*/ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*------------------------------------------------------------------* - * Initialization - *-----------------------------------------------------------------*/ - - IF( EQ_16( st->bfi, 1 ) ) - { - st->nbLostCmpt = add( st->nbLostCmpt, 1 ); - } - ELSE - { - IF( EQ_16( st->prev_bfi, 1 ) ) - { - st->prev_nbLostCmpt = st->nbLostCmpt; - move16(); - } - ELSE - { - st->prev_nbLostCmpt = 0; - move16(); - } - - st->nbLostCmpt = 0; - move16(); - } - st->enablePlcWaveadjust = 0; - move16(); - - IF( EQ_16( n, 1 ) ) - { - sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); - } - - /*---------------------------------------------------------------------* - * Detect bandwidth switching - *---------------------------------------------------------------------*/ - - bandwidth_switching_detect_ivas_fx( st ); - - /*---------------------------------------------------------------------* - * Preprocessing (preparing) for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - Word16 Q_olapBufferSynth, Q_olapBufferSynth2; - - Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ - Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ - move16(); - move16(); - - Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); - - IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - flag_sec_CNA = -1; - move16(); - IF( hCPE != NULL ) - { - flag_sec_CNA = sts[1]->flag_cna; - move16(); - } - - /*---------------------------------------------------------------------* - * ACELP core decoding - * TCX core decoding - * HQ core decoding - *---------------------------------------------------------------------*/ - - IF( EQ_16( st->core, ACELP_CORE ) ) - { - /* ACELP core decoder */ - Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; - set_s( output_16_fx[n], 0, L_FRAME48k ); - Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; - IF( save_hb_synth_32_fx ) - { - save_hb_synth_16_fx = save_hb_synth_fx_arr; - } - ELSE - { - save_hb_synth_16_fx = NULL; - } - - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbBPF ) - { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbBPF->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbSyn ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); - } - - IF( st->hFdCngDec != NULL ) - { - Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); - st->hFdCngDec->msNoiseEst_exp = 27; - move16(); - - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); - } - - IF( hCPE == NULL ) - { - IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); - Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ - st->cldfbAna->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbBPF ) - { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbBPF->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSyn ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSyn->Q_cldfb_state = Q11; - move16(); - } - st->prev_Q_syn = st->Q_syn; - move16(); - - if ( save_hb_synth_32_fx ) - { - Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); - hSCE->q_save_hb_synth_fx = Q11; - move16(); - } - - Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); - } - - Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); - - test(); - test(); - test(); - IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - Word16 Qsyn_temp; - STEREO_CNG_DEC_HANDLE hStereoCng; - IVAS_FORMAT ivas_format; - - Qsyn_temp = st->Q_syn; - move16(); - st->Q_syn = 0; - move16(); - st->prev_Q_syn = st->Q_syn; - move16(); - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - st->mem_error = st->hBPF->pst_mem_deemp_err_fx; - move32(); - - /* TCX decoder */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); - Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); - st->hFdCngDec->msNoiseEst_exp = 27; - move16(); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); - - IF( hCPE == NULL ) - { - hStereoCng = NULL; - } - ELSE - { - hStereoCng = hCPE->hStereoCng; - } - IF( st_ivas == NULL ) - { - ivas_format = 0; - move32(); - } - ELSE - { - ivas_format = st_ivas->ivas_format; - move32(); - } - stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); - st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; - move16(); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); - - IF( st->hTcxDec ) - { - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; - move16(); - } - st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); - } - - IF( EQ_16( st->core, HQ_CORE ) ) - { - /* HQ core decoder */ - Word16 Q_output; - - Q_output = 0; - move16(); - Q_synth = 0; - move16(); - - ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); -#else - Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); -#endif - Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); - } - - /*---------------------------------------------------------------------* - * TD stereo updates - *---------------------------------------------------------------------*/ - - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) - { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); - - td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, - tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc -#ifndef FIX_798_WRONG_CPY_OF_PITCH - , - Q6 -#endif - ); - - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); - } - - } /* n_channels loop */ - - - /*---------------------------------------------------------------------* - * MDCT stereo: joint TCX Core Decoding - *---------------------------------------------------------------------*/ - - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) - { - /* active-frame decoding */ - IF( GT_32( sts[0]->core_brate, SID_2k40 ) ) - { - IF( hMCT ) - { - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSynHB->Q_cldfb_state = Q11; - move16(); - } - } - - pop_wmops(); - return error; - } - ELSE - { - Word16 e_sig; - Word16 ch; - - e_sig = 17; - move16(); - sts = hCPE->hCoreCoder; - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - - st->last_gain_syn_deemph = 0; - move16(); - IF( st->hHQ_core ) - { - st->hHQ_core->Q_fer_samples = 0; - move16(); - } -#ifdef FIX_778_STEREO_BRATE_SWITCHING - st->Q_syn = 0; - move16(); -#endif - st->prev_Q_syn = st->Q_syn; - move16(); - - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); - - IF( st->hTcxDec ) - { - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - } - IF( st->hTcxDec ) - { - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - } - } - - stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); - - FOR( ch = 0; ch < 2; ch++ ) - { - st = hCPE->hCoreCoder[ch]; - st->hHQ_core->Q_old_wtda_LB = st->Q_syn; - move16(); - st->hHQ_core->Q_old_wtda = st->Q_syn; - move16(); - } - -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); - Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); -#else - Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); - Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); -#endif - } - } - /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ - ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) - { - sts[0] = hCPE->hCoreCoder[0]; - sts[1] = hCPE->hCoreCoder[1]; - - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) - { - sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); - sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); - } - updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) - { - sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); - sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); - } - } - test(); - IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) - { - /* On first good frame after frameloss undo the whitening of the bg noise shape */ - FOR( n = 0; n < n_channels; ++n ) - { - IF( NE_16( sts[n]->last_core_bfi, ACELP_CORE ) ) - { - Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; - move16(); - - TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); - } - } - } - } - - /*---------------------------------------------------------------------* - * Stereo CNG updates - *---------------------------------------------------------------------*/ - - test(); - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) - { - /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ - Word16 Q_c_PS_LT, Q_output; - Word32 c_PS_LT_fx; - - Q_c_PS_LT = 31; - move16(); - Q_output = 11; - move16(); - c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); - Q_c_PS_LT = Q31; - move16(); - - stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); - - hCPE->hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); - } - - /*---------------------------------------------------------------------* - * Postprocessing, BWEs and updates - *---------------------------------------------------------------------*/ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*---------------------------------------------------------------------* - * TD-BWE for ACELP to TCX transitions - *---------------------------------------------------------------------*/ - - /*core_switching_post_dec*/ - Q_synth = 0; - move16(); - if ( st->hHQ_core != NULL ) - { - st->hHQ_core->Q_old_postdec = 0; - move16(); - } - - /*------------------fix-to-fix-end-----------------------*/ - - Word16 output_mem_16_fx[L_FRAME48k]; - Word16 *p_output_mem_16; - - IF( p_output_mem_fx != NULL ) - { - p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); - } - ELSE - { - p_output_mem_16 = NULL; - set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); - } - - Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); - - IF( st->hHQ_core != NULL ) - { - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); - st->hHQ_core->Q_old_wtda = 0; - move16(); - } - - /*size of synth is choosen as delay comp to start with*/ - /*-------------------cldfb-start-------------------------*/ - - IF( st->cldfbSyn != NULL ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); - st->cldfbSyn->Q_cldfb_state = Q4; - move16(); - } - - Word16 q_audio, old_syn_fx; - old_syn_fx = Q11; - move16(); - q_audio = Q12; - move16(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) - { - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) - { - GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); - } - ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) - { - GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); - } - - /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); - } - - /* Memories Re-Scaling */ - IF( st->hBWE_TD != NULL ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); - } - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/MDCT core switching - *---------------------------------------------------------------------*/ - - /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) - { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); - } - - IVAS_FORMAT ivas_format; - IF( st_ivas != NULL ) - { - ivas_format = st_ivas->ivas_format; - move32(); - } - ELSE - { - ivas_format = UNDEFINED_FORMAT; - move32(); - } - IF( hCPE != NULL ) - { - last_element_mode = hCPE->last_element_mode; - move16(); - } - ELSE - { - last_element_mode = IVAS_SCE; - move16(); - } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) - { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); - } - - /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ - test(); - test(); - test(); - test(); - test(); - IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) - { - Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); - } - /*---------------------------------------------------------------------* - * Pre-processing for bandwidth switching - *---------------------------------------------------------------------*/ - - ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); - - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); - Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); - - - /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ - - IF( st->cldfbSyn != NULL ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); - st->cldfbSyn->Q_cldfb_state = Q11; - move16(); - } - -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); -#else - Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); -#endif - - /*------------------reset-code-start---------------------*/ - - test(); - test(); - IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) - { - test(); - IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) - { - st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; - move16(); - } - st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; - move16(); - st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; - move16(); - } - - /*---------------------------------------------------------------------* - * WB TBE decoding - * WB BWE decoding - *---------------------------------------------------------------------*/ - - Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; - Word16 Q_syn_hb; - - Q_input = 0; - move16(); - Q_hb_synth_fx = 0; - move16(); - Q_synth_fx = 0; - move16(); - - FD_BWE_DEC_HANDLE hBWE_FD; - hBWE_FD = st->hBWE_FD; - - Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, negate( Q11 ) ); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( Q11 ) ); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->extl, WB_TBE ) ) - { - /* WB TBE decoder */ - - ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) - { - /* do nothing */ - } - ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) - { - /* WB BWE decoder */ - Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); - } - - /* Memories Re-Scaling */ - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); - Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); - - IF( hBWE_FD != NULL ) - { - Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); - } - IF( st->hBWE_TD != NULL ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); - } - - /*---------------------------------------------------------------------* - * SWB(FB) TBE decoding - * SWB(FB) BWE decoding - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) - { - /* SWB TBE decoder */ - Q_white_exc = 0; - move16(); - - ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); - - IF( GT_16( Q_white_exc, 31 ) ) - { - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); - Q_white_exc = 31; - move16(); - } - - /* FB TBE decoder */ - IF( EQ_16( st->extl, FB_TBE ) ) - { - fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); - } - } - ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && EQ_16( st->core, ACELP_CORE ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) - { - /* SWB BWE decoder */ - Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); - - Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); - - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); - } - - /*---------------------------------------------------------------------* - * FEC - recovery after lost HQ core (smoothing of the BWE component) - *---------------------------------------------------------------------*/ - - test(); - test(); - IF( st->prev_bfi && EQ_16( st->last_core, HQ_CORE ) && NE_16( st->extl, -1 ) ) - { - /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ - tmp16 = shr( 410, shr( output_frame, 8 ) ); /* Q15 */ - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - tmp16 = 68; - move16(); - } - /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr( output_frame, 1 ); - tmp16_2 = 0; - move16(); - FOR( i = 0; i < j; i++ ) - { - hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], tmp16_2 ); /* Q11 */ - move32(); -#ifdef BASOP_NOGLOB - tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); /* Q15 */ -#else - tmp16_2 = add( tmp16_2, tmp16 ); -#endif - } - } - - /*---------------------------------------------------------------------* - * SWB CNG - *---------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) - { - /* SHB CNG decoder */ - Word16 synth_fxl[960]; /* Q-2 */ - Word16 q; - - q = 2; - move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); -#ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); -#else - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); -#endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); - - swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); - - IF( EQ_32( 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( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); - } - - /*-------------------------------------------------------------------* - * Inter-channel BWE decoding - *-------------------------------------------------------------------*/ - test(); - IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - Word16 q; - q = 11; - move16(); - - IF( hCPE->hStereoDft != NULL ) - { - hCPE->hStereoDft->td_gain_fx[0] = 1; - move32(); - } - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); - stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); -#ifdef MSAN_FIX - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) - { - Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); - Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); - } -#else - Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); - Scale_sig32( hb_synth_32_fx[1], L_FRAME48k, sub( Q11, q ) ); -#endif - } - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - /*----------------------------------------------------------------* - * BFI waveform adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) - { - tmps = NS2SA_fx2( output_Fs, DELAY_CLDFB_NS ); - - waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, - &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, - st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); - - st->hPlcInfo->Pitch = 0; - move16(); - } - } - - /*----------------------------------------------------------------* - * Transition and synchronization of BWE components - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( st->bws_cnt > 0 && EQ_16( st->core, ACELP_CORE ) ) ) - { - /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); - } - ELSE - { - test(); - IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) - { - /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); - } - ELSE - { - /* TBE on top of ACELP@16kHz */ - tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); - } - } - - /* Smooth transitions when switching between different technologies */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && EQ_16( st->last_core, ACELP_CORE ) ) && - ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) - { - /* switching between BWE and TBE technologies */ - incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < tmps; i++ ) - { - hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); - move16(); - tmp16 = add( tmp16, incr ); - } - - set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); - } - ELSE IF( LT_16( tmps, st->old_bwe_delay ) ) - { - /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - - incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < tmps; i++ ) - { - tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); - move16(); - tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); - move16(); - tmp16 = add( tmp16, incr ); - } - Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); - } - ELSE IF( GT_16( tmps, st->old_bwe_delay ) ) - { - /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); - move16(); - tmp16 = add( tmp16, incr ); - } - FOR( ; i < tmps; i++ ) - { - tmp_buffer_fx[i] = 0; - move16(); - } - tmp16 = 0; - move16(); - FOR( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); - move16(); - tmp16 = add( tmp16, incr ); - } - - Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); - } - - test(); - test(); - test(); - IF( ( NE_16( st->element_mode, IVAS_CPE_TD ) && !use_cldfb_for_dft ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) - { - /* Delay hb_synth */ - Word32 hb_prev_synth_buffer_fx_32[111]; - - Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); - delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); - } - ELSE - { - Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); - } - - st->old_bwe_delay = tmps; - - /* SWB CNG/DTX - calculate SHB energy */ - test(); - test(); - test(); - IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && EQ_16( st->core, ACELP_CORE ) && st->hTdCngDec != NULL ) - { - Word16 exp; - Word32 fra; - SWITCH( output_frame ) - { - case L_FRAME8k: - tmp16 = 205; - move16(); - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - move16(); - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - move16(); - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - move16(); - BREAK; /*Q15*/ - } - - L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - - Word16 exp2; - exp = 20; - move16(); - Word32 L_tmp2 = sum2_32_fx( hb_synth_32_fx[n], output_frame, &exp ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 20, L_tmp2, exp, &exp ); - L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); - exp2 = norm_l( L_tmp ); - exp = sub( exp, exp2 ); - fra = BASOP_Util_Log2( L_shl_sat( L_tmp, exp2 ) ); - exp2 = norm_l( exp ); - L_tmp = L_shl( exp, exp2 ); - exp = sub( Q31, exp2 ); - L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); - // exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); - L_tmp = Mpy_32_16_1( L_tmp, 24660 ); - exp = add( exp, 2 ); - st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, exp - 7 ) ); /*Q8*/ - st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, exp - 20 ); /*Q11*/ - } - } - - test(); - IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ - break; - } - - /*----------------------------------------------------------------* - * Post-processing - * - TCX-LTP Postfilter (except DFT stereo) - * - core switching in DFT stereo - * - updates for potential TD->DFT stereo switching - *----------------------------------------------------------------*/ - if ( hCPE != NULL ) - { - FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) - { - if ( hCPE->hCoreCoder[ch_ind] != NULL ) - { - if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) - { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); - } - } - } - } - if ( hSCE != NULL ) - { - if ( hSCE->hCoreCoder[0] != NULL ) - { - if ( hSCE->hCoreCoder[0]->hHQ_core != NULL ) - { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); - } - } - } - - Word16 exp_max; - Word32 output_fx_loc[L_FRAME48k]; - - exp_max = 0; - move16(); - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - test(); - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) - { - ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); - } - - /* update OLA buffers - needed for switching to DFT stereo */ - IF( !sba_dirac_stereo_flag ) - { - IF( hCPE != NULL ) - { - stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); - } - } - } - ELSE /* IVAS_CPE_DFT */ - { - Word16 q; - q = 11; - move16(); - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) - { - stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); - } - Word16 q_DFT[2] = { 3, 3 }; - - stereo_dft_dec_core_switching_fx( hCPE, output_32_fx[0], synth_32_fx[0], hb_synth_32_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); - - hCPE->hStereoDft->q_dft = s_min( q_DFT[0], q_DFT[1] ); - - IF( DFT_fx != NULL ) - { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); - } - - test(); - IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) - { - /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ - stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); - } - } - - Copy32( synth_32_fx[n], output_32_fx[n], output_frame ); - - /*--------------------------------------------------------* - * Common updates - *--------------------------------------------------------*/ - - /*Scale Memories*/ - - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) - { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); - st->q_prev_synth_buffer_fx = 0; - move16(); - - exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); - exp_ouput = add( exp_ouput, Q11 ); - exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); - exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); - exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); -#ifndef FIX_740_HQ_CORE_OVA - exp_synth_history += st->hTcxDec->q_synth_history_fx; -#endif - exp_max = s_min( exp_synth_history, exp_ouput ); - exp_max = s_min( exp_max, exp_prev_synth_buffer ); - exp_max = s_min( exp_max, exp_old_out ); - exp_max = s_min( exp_max, exp_delay_buf_out ); - - Copy32( output_32_fx[n], output_fx_loc, output_frame ); - - Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); - Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); - Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); - Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); - - st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); - } - /* Save synthesis for HQ FEC */ - save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); - - /* Updates */ - - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); - - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); - - } /* n_channels loop */ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSynHB->Q_cldfb_state = Q11; - move16(); - } - } - - pop_wmops(); - return error; -} -#else -ivas_error ivas_core_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const int16_t n_channels, /* i : number of channels to be decoded */ - float *output[], /* o : output synthesis signal */ - float hb_synth[][L_FRAME48k], /* o : output HB synthesis signal */ - float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -) -{ - int16_t i, n, output_frame; - Decoder_State **sts, *st; - STEREO_ICBWE_DEC_HANDLE hStereoICBWE; - STEREO_TD_DEC_DATA_HANDLE hStereoTD; - int16_t sharpFlag[CPE_CHANNELS]; - float synth[CPE_CHANNELS][L_FRAME48k]; - float tmp_buffer[L_FRAME48k]; - int16_t tmps, incr; - float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; - int16_t core_switching_flag[CPE_CHANNELS]; - float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; - float tmp; - float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; - int16_t unbits[CPE_CHANNELS]; - int16_t sid_bw[CPE_CHANNELS]; - FRAME_MODE frameMode[CPE_CHANNELS]; - float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; - int16_t tdm_LRTD_flag; - int32_t element_brate, output_Fs; - int32_t last_element_brate; - int16_t use_cldfb_for_dft; - float *p_output_mem; - int16_t flag_sec_CNA; - int16_t read_sid_info; - int16_t last_element_mode; - int16_t nchan_out; - float *save_hb_synth; - ivas_error error; - - error = IVAS_ERR_OK; - push_wmops( "ivas_core_dec" ); - - /*------------------------------------------------------------------* - * General initialization - *-----------------------------------------------------------------*/ - - use_cldfb_for_dft = 0; - tdm_LRTD_flag = -1; - read_sid_info = 1; /* read SID by default */ - - if ( hSCE != NULL ) - { - sts = hSCE->hCoreCoder; - hStereoICBWE = NULL; - element_brate = hSCE->element_brate; - last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ - last_element_mode = IVAS_SCE; - hStereoTD = NULL; - p_output_mem = NULL; - nchan_out = 1; - if ( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) - { - if ( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) - { - read_sid_info = 0; - } - } - } - else - { - sts = hCPE->hCoreCoder; - element_brate = hCPE->element_brate; - last_element_brate = hCPE->last_element_brate; - last_element_mode = hCPE->last_element_mode; - hStereoICBWE = hCPE->hStereoICBWE; - hStereoTD = hCPE->hStereoTD; - p_output_mem = hCPE->output_mem[1]; - nchan_out = hCPE->nchan_out; - - if ( hCPE->hStereoTD != NULL ) - { - tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; - } - - if ( sts[0]->element_mode == IVAS_CPE_DFT ) - { - use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; - } - } - - output_Fs = sts[0]->output_Fs; - output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); - - for ( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*------------------------------------------------------------------* - * Initialization per core-decoder channel - *-----------------------------------------------------------------*/ - - frameMode[n] = FRAMEMODE_NORMAL; - st->rate_switching_reset = 0; - - st->mdct_sw = MODE1; - - sid_bw[n] = -1; - core_switching_flag[n] = 0; - sharpFlag[n] = 0; - unbits[n] = 0; - st->GSC_IVAS_mode = 0; - st->element_brate = element_brate; - - st->use_partial_copy = 0; - st->rf_flag = 0; - st->rf_frame_type = RF_NO_DATA; - - if ( st->bfi == 1 ) - { - frameMode[n] = FRAMEMODE_MISSING; - st->coder_type = st->last_coder_type; - } - else - { - if ( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ - { - st->coder_type = INACTIVE; - } - st->extl = -1; - st->flagGuidedAcelp = 0; - } - - if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) - { - v_multc( st->hHQ_core->old_out, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX ); - v_multc( st->hHQ_core->old_outLB, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_outLB, st->L_frame ); - } - - set_f( voice_factors[n], 0.f, NB_SUBFR16k ); - set_f( hb_synth[n], 0.0f, L_FRAME48k ); - - /*------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *-----------------------------------------------------------------*/ - - if ( st->bfi != 1 ) - { - ivas_decision_matrix_dec( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); - - synchonize_channels_mdct_sid( sts, n ); - - if ( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ - { - st->sr_core = st->L_frame * FRAMES_PER_SEC; - st->fscale_old = st->fscale; - st->fscale = sr2fscale( st->sr_core ); - } - else - { - frameMode[n] = FRAMEMODE_MISSING; - } - } - else if ( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) - { - st->core = TCX_20_CORE; - } - } /* n_channels loop */ - - /* MDCT stereo -> DFT stereo switching */ - if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) - { - int16_t ovl, fade_len; - if ( sts[0]->L_frame != sts[0]->last_L_frame ) - { - lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); - } - if ( sts[0]->L_frame != L_FRAME16k ) - { - ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); - lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); - - fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); - lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); - } - } - - if ( hCPE != NULL && hCPE->hStereoCng != NULL ) - { - hCPE->hStereoCng->flag_cna_fade = 0; - } - - if ( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) - { - save_hb_synth = hSCE->save_hb_synth; - } - else - { - save_hb_synth = NULL; - } - - /*------------------------------------------------------------------* - * Decode SID for MDCT-Stereo DTX mode - *-----------------------------------------------------------------*/ - - if ( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) - { - if ( sts[0]->cng_sba_flag ) - { - FdCngDecodeDiracMDCTStereoSID( hCPE ); - } - else - { - FdCngDecodeMDCTStereoSID( hCPE ); - } - } - - /*------------------------------------------------------------------* - * Sanity check in combined format coding - *-----------------------------------------------------------------*/ - - if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) - { - ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); - } - - /*------------------------------------------------------------------* - * Core Decoding - *-----------------------------------------------------------------*/ - - for ( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*------------------------------------------------------------------* - * Initialization - *-----------------------------------------------------------------*/ - - if ( st->bfi == 1 ) - { - st->nbLostCmpt++; - } - else - { - if ( st->prev_bfi == 1 ) - { - st->prev_nbLostCmpt = st->nbLostCmpt; - } - else - { - st->prev_nbLostCmpt = 0; - } - - st->nbLostCmpt = 0; - } - st->enablePlcWaveadjust = 0; - - if ( n == 1 ) - { - sts[1]->BER_detect |= sts[0]->BER_detect; - } - - /*---------------------------------------------------------------------* - * Detect bandwidth switching - *---------------------------------------------------------------------*/ - - bandwidth_switching_detect( st ); - - /*---------------------------------------------------------------------* - * Preprocessing (preparing) for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - - if ( ( error = core_switching_pre_dec( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate ) ) != IVAS_ERR_OK ) - { - return error; - } - - flag_sec_CNA = -1; - if ( hCPE != NULL ) - { - flag_sec_CNA = sts[1]->flag_cna; - } - - /*---------------------------------------------------------------------* - * ACELP core decoding - * TCX core decoding - * HQ core decoding - *---------------------------------------------------------------------*/ - - if ( st->core == ACELP_CORE ) - { - /* ACELP core decoder */ - if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) - { - /* TCX decoder */ - stereo_tcx_core_dec( st, frameMode[n], output[n], synth[n], pitch_buf[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); - } - - if ( st->core == HQ_CORE ) - { - /* HQ core decoder */ - hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); - } - - /*---------------------------------------------------------------------* - * TD stereo updates - *---------------------------------------------------------------------*/ - - if ( st->element_mode == IVAS_CPE_TD && n == 0 ) - { - td_stereo_param_updt( st->lsp_old, st->lsf_old, st->old_pitch_buf + st->nb_subfr, tdm_lspQ_PCh, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); - } - - } /* n_channels loop */ - - /*---------------------------------------------------------------------* - * MDCT stereo: joint TCX Core Decoding - *---------------------------------------------------------------------*/ - - if ( sts[0]->element_mode == IVAS_CPE_MDCT ) - { - /* active-frame decoding */ - if ( sts[0]->core_brate > SID_2k40 ) - { - if ( hMCT ) - { - pop_wmops(); - - return error; - } - else - { - stereo_mdct_core_dec( st_ivas, hCPE, output, synth ); - } - } - /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ - else if ( hCPE->nchan_out == 1 ) - { - updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth ); - } - - if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) - { - /* On first good frame after frameloss undo the whitening of the bg noise shape */ - for ( n = 0; n < n_channels; ++n ) - { - if ( sts[n]->last_core_bfi != ACELP_CORE ) - { - TonalMdctConceal_whiten_noise_shape_ivas( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); - } - } - } - } - - /*---------------------------------------------------------------------* - * Stereo CNG updates - *---------------------------------------------------------------------*/ - - if ( sts[0]->element_mode == IVAS_CPE_TD && hCPE->hStereoCng != NULL ) - { - stereo_cng_compute_PScorr( output, &hCPE->hStereoCng->c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); - } - - /*---------------------------------------------------------------------* - * Postprocessing, BWEs and updates - *---------------------------------------------------------------------*/ - - for ( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*---------------------------------------------------------------------* - * TD-BWE for ACELP to TCX transitions - *---------------------------------------------------------------------*/ - - if ( st->last_core == ACELP_CORE && ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->hBWE_TD != NULL ) - { - if ( ( st->bwidth == SWB || st->bwidth == FB ) && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) ) - { - GenTransition( st->hBWE_TD, hb_synth[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); - } - else if ( st->bwidth == WB && st->last_extl == WB_TBE ) - { - GenTransition_WB( st->hBWE_TD, hb_synth[n], output_Fs ); - } - } - - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/MDCT core switching - *---------------------------------------------------------------------*/ - - /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ - if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT && !( st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) ) - { - mvr2r( synth[n], hSCE->save_synth, output_frame ); - } - - if ( ( error = core_switching_post_dec( st, synth[n], output[n], p_output_mem, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ - if ( sba_dirac_stereo_flag && hSCE && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) - { - mvr2r( synth[n], hSCE->save_synth, output_frame ); - } - - /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ - if ( n == 0 && st->element_mode == IVAS_CPE_MDCT && st->last_core == ACELP_CORE && st->core != ACELP_CORE && ( nchan_out == 1 || ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_DFT ) ) ) - { - mvr2r( sts[0]->previoussynth, sts[1]->previoussynth, st->hTcxDec->L_frameTCX ); - } - - /*---------------------------------------------------------------------* - * Pre-processing for bandwidth switching - *---------------------------------------------------------------------*/ - - bw_switching_pre_proc( st, old_syn_12k8_16k[n], last_element_brate, nchan_out ); - - /*---------------------------------------------------------------------* - * WB TBE decoding - * WB BWE decoding - *---------------------------------------------------------------------*/ - - if ( st->extl == WB_TBE ) - { - /* WB TBE decoder */ - wb_tbe_dec( st, bwe_exc_extended[n], voice_factors[n], hb_synth[n] ); - } - else if ( st->element_mode == IVAS_CPE_TD && n == 1 && !tdm_LRTD_flag && st->extl != -1 && st->bws_cnt == 0 && st->extl_brate == 0 ) - { - /* do nothing */ - } - else if ( st->extl == WB_BWE && st->bws_cnt == 0 ) - { - /* WB BWE decoder */ - wb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame, voice_factors[n], pitch_buf[n] ); - } - - /*---------------------------------------------------------------------* - * SWB(FB) TBE decoding - * SWB(FB) BWE decoding - *---------------------------------------------------------------------*/ - - if ( st->extl == SWB_TBE || st->extl == FB_TBE || ( st->coder_type != AUDIO && st->coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE && !st->con_tcx && output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0 ) ) - { - /* SWB TBE decoder */ - swb_tbe_dec( st, hStereoICBWE, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], tmp_buffer /*fb_exc*/, hb_synth[n], pitch_buf[n] ); - - /* FB TBE decoder */ - if ( st->extl == FB_TBE ) - { - fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); - } - } - else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) - { - /* SWB BWE decoder */ - swb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame ); - } - - /*---------------------------------------------------------------------* - * FEC - recovery after lost HQ core (smoothing of the BWE component) - *---------------------------------------------------------------------*/ - - if ( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 ) - { - tmp = FRAC_BWE_SMOOTH / output_frame; - - for ( i = 0; i < output_frame / FRAC_BWE_SMOOTH; i++ ) - { - hb_synth[n][i] *= ( i * tmp ); - } - } - - /*---------------------------------------------------------------------* - * SWB CNG - *---------------------------------------------------------------------*/ - - if ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) - { - /* SHB CNG decoder */ - swb_CNG_dec( st, synth[n], hb_synth[n], sid_bw[n] ); - } - - /*-------------------------------------------------------------------* - * Inter-channel BWE decoding - *-------------------------------------------------------------------*/ - - if ( n == 0 && st->element_mode >= IVAS_CPE_DFT ) - { - stereo_icBWE_dec( hCPE, hb_synth[0], hb_synth[1], tmp_buffer /*fb_synth_ref*/, voice_factors[0], output_frame ); - } - - if ( st->element_mode == EVS_MONO ) - { - /*----------------------------------------------------------------* - * BFI waveform adjustment - *----------------------------------------------------------------*/ - - if ( st->core == ACELP_CORE && !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 ) - { - tmps = NS2SA( output_Fs, DELAY_CLDFB_NS ); - - waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut_float, synth[n] + tmps, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); - - st->hPlcInfo->Pitch = 0; - } - } - - /*----------------------------------------------------------------* - * Transition and synchronization of BWE components - *----------------------------------------------------------------*/ - - if ( ( st->extl != -1 && ( st->extl != IGF_BWE || st->last_core == ACELP_CORE ) ) || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) - { - /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - if ( st->L_frame == L_FRAME ) - { - /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); - } - else - { - if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) - { - /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); - } - else - { - /* TBE on top of ACELP@16kHz */ - tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); - } - } - - /* Smooth transitions when switching between different technologies */ - if ( !( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->last_core == ACELP_CORE ) && - ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) && ( st->element_mode != IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) ) - { - /* switching between BWE and TBE technologies */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); - for ( i = 0; i < tmps; i++ ) - { - hb_synth[n][i] *= sin_table256[i * incr]; - } - - set_f( st->hb_prev_synth_buffer, 0.0f, tmps ); - } - else if ( tmps < st->old_bwe_delay ) - { - /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); - for ( i = 0; i < tmps; i++ ) - { - tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + - st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; - } - - mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); - } - else if ( tmps > st->old_bwe_delay ) - { - /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); - for ( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; - } - - for ( ; i < tmps; i++ ) - { - tmp_buffer[i] = 0.0f; - } - - for ( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; - } - - mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); - } - - if ( ( st->element_mode != IVAS_CPE_TD && !use_cldfb_for_dft ) || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) - { - /* Delay hb_synth */ - delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); - } - else - { - mvr2r( hb_synth[n] + output_frame - tmps, st->hb_prev_synth_buffer, tmps ); - } - - st->old_bwe_delay = tmps; - if ( st->hBWE_TD != NULL ) - { - mvr2r( hb_synth[n], st->hBWE_TD->old_hb_synth, output_frame ); - } - - /* SWB CNG/DTX - calculate SHB energy */ - if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG && st->core == ACELP_CORE && st->hTdCngDec != NULL ) - { - st->hTdCngDec->last_shb_ener = sum2_f( hb_synth[n], output_frame ) + 0.001f; - st->hTdCngDec->last_shb_ener /= (float) output_frame; - st->hTdCngDec->last_shb_ener = 10 * log10f( st->hTdCngDec->last_shb_ener ); - } - } - - if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT ) - { - /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ - break; - } - - /*----------------------------------------------------------------* - * Post-processing - * - TCX-LTP Postfilter (except DFT stereo) - * - core switching in DFT stereo - * - updates for potential TD->DFT stereo switching - *----------------------------------------------------------------*/ - - if ( st->element_mode != IVAS_CPE_DFT ) - { - if ( st->element_mode != IVAS_CPE_MDCT || sba_dirac_stereo_flag ) - { - ivas_post_proc( hSCE, hCPE, n, synth[n], NULL, output_frame, sba_dirac_stereo_flag ); - } - - /* update OLA buffers - needed for switching to DFT stereo */ - if ( !sba_dirac_stereo_flag ) - { - stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); - } - } - else /* IVAS_CPE_DFT */ - { - if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) - { - stereo_mdct2dft_update( hCPE, output[0], synth[0] ); - } - - stereo_dft_dec_core_switching( hCPE, output[0], synth[0], hb_synth[0], DFT, output_frame, use_cldfb_for_dft, 0 ); - - if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) - { - /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ - stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); - } - } - - mvr2r( synth[n], output[n], output_frame ); - - /*--------------------------------------------------------* - * Common updates - *--------------------------------------------------------*/ - - /* Save synthesis for HQ FEC */ - save_synthesis_hq_fec( st, output[n], output_frame, hCPE ); - - /* Updates */ - updt_dec_common( st, NORMAL_HQ_CORE, -1, output[n] ); - - } /* n_channels loop */ - - - pop_wmops(); - return error; -} -#endif +/****************************************************************************************************** + + (C) 2022-2024 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 +#include +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include "ivas_rom_com.h" +#include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#endif + +/*-------------------------------------------------------------------* + * ivas_core_dec() + * + * Principal IVAS core decoder routine, where number of core channels is 1 or 2 + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_core_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const Word16 n_channels, /* i : number of channels to be decoded */ + Word32 *output_32_fx[], /* o : output synthesis signal */ + Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +) +{ + Word16 i, n, output_frame; + Decoder_State **sts, *st; + STEREO_ICBWE_DEC_HANDLE hStereoICBWE; + STEREO_TD_DEC_DATA_HANDLE hStereoTD; + Word16 sharpFlag[CPE_CHANNELS]; + Word16 tmp_buffer_fx[L_FRAME48k]; + set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); + Word16 tmp16, tmp16_2, j; + tmp16 = 0; + move16(); + Word16 Q_white_exc; + Q_white_exc = 0; + move16(); + + Word16 tmps, incr; + Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + + Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 core_switching_flag[CPE_CHANNELS]; + + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; + + Word16 unbits[CPE_CHANNELS]; + Word16 sid_bw[CPE_CHANNELS]; + FRAME_MODE frameMode[CPE_CHANNELS]; + Word16 tdm_LRTD_flag; + Word32 element_brate, output_Fs; + Word32 last_element_brate; + Word16 use_cldfb_for_dft; + Word32 *p_output_mem_fx; + Word16 flag_sec_CNA; + Word16 read_sid_info; + Word16 last_element_mode; + Word16 nchan_out; + Word32 *save_hb_synth_32_fx; + ivas_error error; + Word32 L_tmp; + Word16 Q_synth; + Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + + Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); + set16_fx( output_16_fx[i], 0, L_FRAME48k ); + } + + Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; + Word32 conceal_eof_gain32; + +#ifdef BASOP_NOGLOB + Flag Overflow; +#endif + + error = IVAS_ERR_OK; + move32(); + push_wmops( "ivas_core_dec" ); + + /*------------------------------------------------------------------* + * General initialization + *-----------------------------------------------------------------*/ + + use_cldfb_for_dft = 0; + move16(); + tdm_LRTD_flag = -1; + move16(); + read_sid_info = 1; /* read SID by default */ + move16(); + + IF( hSCE != NULL ) + { + sts = hSCE->hCoreCoder; + hStereoICBWE = NULL; + element_brate = hSCE->element_brate; + move32(); + last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + move32(); + last_element_mode = IVAS_SCE; + move16(); + hStereoTD = NULL; + p_output_mem_fx = NULL; + nchan_out = 1; + move16(); + test(); + IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) + { + read_sid_info = 0; + move16(); + } + } + } + ELSE + { + sts = hCPE->hCoreCoder; + element_brate = hCPE->element_brate; + move32(); + last_element_brate = hCPE->last_element_brate; + move32(); + last_element_mode = hCPE->last_element_mode; + move16(); + hStereoICBWE = hCPE->hStereoICBWE; + hStereoTD = hCPE->hStereoTD; + p_output_mem_fx = hCPE->output_mem_fx[1]; + + nchan_out = hCPE->nchan_out; + move16(); + + if ( hCPE->hStereoTD != NULL ) + { + tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + move16(); + } + + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + { + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + use_cldfb_for_dft = 1; + move16(); + } + ELSE + { + use_cldfb_for_dft = 0; + move16(); + } + } + } + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbAna->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + } + } + + output_Fs = sts[0]->output_Fs; + move32(); + output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization per core-decoder channel + *-----------------------------------------------------------------*/ + + frameMode[n] = FRAMEMODE_NORMAL; + move32(); + st->rate_switching_reset = 0; + move16(); + st->mdct_sw = MODE1; + move16(); + sid_bw[n] = -1; + move16(); + core_switching_flag[n] = 0; + move16(); + sharpFlag[n] = 0; + move16(); + unbits[n] = 0; + move16(); + st->GSC_IVAS_mode = 0; + move16(); + st->element_brate = element_brate; + move32(); + st->use_partial_copy = 0; + move16(); + st->rf_flag = 0; + move16(); + st->rf_frame_type = RF_NO_DATA; + move16(); + + IF( EQ_16( st->bfi, 1 ) ) + { + frameMode[n] = FRAMEMODE_MISSING; + move32(); + st->coder_type = st->last_coder_type; + move16(); + } + ELSE + { + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + { + st->coder_type = INACTIVE; + move16(); + } + st->extl = -1; + move16(); + st->flagGuidedAcelp = 0; + move16(); + } + + test(); + test(); + test(); + test(); + test(); +#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID + IF( !st->bfi && st->prev_bfi && GT_32( st->total_brate, SID_2k40 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) +#else + IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) +#endif + { + conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); + + FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) + { + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 + move16(); + } + + FOR( i = 0; i < st->L_frame; i++ ) + { + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 + move16(); + } + } + + set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); + set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); + set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); + /*------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( NE_16( st->bfi, 1 ) ) + { + ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); + + synchonize_channels_mdct_sid_fx( sts, n ); + + IF( NE_16( st->bfi, 1 ) ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + { + st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); + move32(); + st->fscale_old = st->fscale; + move16(); + st->fscale = sr2fscale_fx( st->sr_core ); + move16(); + } + ELSE + { + frameMode[n] = FRAMEMODE_MISSING; + move32(); + } + } + ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) + { + st->core = TCX_20_CORE; + move16(); + } + } /* n_channels loop */ + + /* MDCT stereo -> DFT stereo switching */ + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + { + Word16 ovl, fade_len; + IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) + { + Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); + L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); + } + IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) + { + ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ + L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); + + fade_len = mult( sts[0]->L_frame, 12288 ); /* STEREO_MDCT2DFT_FADE_LEN_48k/L_FRAME16k = 3/8 = 12288 (Q15)*/ + L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + } + } + + test(); + IF( hCPE != NULL && hCPE->hStereoCng != NULL ) + { + hCPE->hStereoCng->flag_cna_fade = 0; + move16(); + } + + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) + { + save_hb_synth_32_fx = hSCE->save_hb_synth_fx; + } + ELSE + { + save_hb_synth_32_fx = NULL; + } + + /*------------------------------------------------------------------* + * Decode SID for MDCT-Stereo DTX mode + *-----------------------------------------------------------------*/ + + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) + { + IF( sts[0]->cng_sba_flag ) + { + FdCngDecodeDiracMDCTStereoSID_fx( hCPE ); + } + ELSE + { + FdCngDecodeMDCTStereoSID_fx( hCPE ); + } + } + + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); + } + + /*------------------------------------------------------------------* + * Core Decoding + *-----------------------------------------------------------------*/ + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + IF( EQ_16( st->bfi, 1 ) ) + { + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); + move16(); + } + ELSE + { + IF( EQ_16( st->prev_bfi, 1 ) ) + { + st->prev_nbLostCmpt = st->nbLostCmpt; + move16(); + } + ELSE + { + st->prev_nbLostCmpt = 0; + move16(); + } + + st->nbLostCmpt = 0; + move16(); + } + st->enablePlcWaveadjust = 0; + move16(); + + IF( EQ_16( n, 1 ) ) + { + sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); + move16(); + } + + /*---------------------------------------------------------------------* + * Detect bandwidth switching + *---------------------------------------------------------------------*/ + + bandwidth_switching_detect_ivas_fx( st ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + Word16 Q_olapBufferSynth, Q_olapBufferSynth2; + + Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ + Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ + move16(); + move16(); + + Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); + + IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + flag_sec_CNA = -1; + move16(); + IF( hCPE != NULL ) + { + flag_sec_CNA = sts[1]->flag_cna; + move16(); + } + + /*---------------------------------------------------------------------* + * ACELP core decoding + * TCX core decoding + * HQ core decoding + *---------------------------------------------------------------------*/ + + IF( EQ_16( st->core, ACELP_CORE ) ) + { + /* ACELP core decoder */ + Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; + set16_fx( output_16_fx[n], 0, L_FRAME48k ); + Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; + IF( save_hb_synth_32_fx ) + { + save_hb_synth_16_fx = save_hb_synth_fx_arr; + } + ELSE + { + save_hb_synth_16_fx = NULL; + } + + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbBPF ) + { + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbSyn ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbSyn->Q_cldfb_state = Q10; + move16(); + } + + IF( st->hFdCngDec != NULL ) + { + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); + st->hFdCngDec->msNoiseEst_exp = 27; + move16(); + + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); + } + + IF( hCPE == NULL ) + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ + st->cldfbAna->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbBPF ) + { + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbBPF->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSyn ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSyn->Q_cldfb_state = Q11; + move16(); + } + st->prev_Q_syn = st->Q_syn; + move16(); + + if ( save_hb_synth_32_fx ) + { + Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); + hSCE->q_save_hb_synth_fx = Q11; + move16(); + } + + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); + } + + Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); + + test(); + test(); + test(); + IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + Word16 Qsyn_temp; + STEREO_CNG_DEC_HANDLE hStereoCng; + IVAS_FORMAT ivas_format; + + Qsyn_temp = st->Q_syn; + move16(); + st->Q_syn = 0; + move16(); + st->prev_Q_syn = st->Q_syn; + move16(); + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + st->mem_error = st->hBPF->pst_mem_deemp_err_fx; + move32(); + + /* TCX decoder */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); + st->hFdCngDec->msNoiseEst_exp = 27; + move16(); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); + + IF( hCPE == NULL ) + { + hStereoCng = NULL; + } + ELSE + { + hStereoCng = hCPE->hStereoCng; + } + IF( st_ivas == NULL ) + { + ivas_format = 0; + move32(); + } + ELSE + { + ivas_format = st_ivas->ivas_format; + move32(); + } + stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); + st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; + move16(); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); + + IF( st->hTcxDec ) + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; + move16(); + } + st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); + move16(); + } + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* HQ core decoder */ + Word16 Q_output; + + Q_output = 0; + move16(); + Q_synth = 0; + move16(); + + ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); + + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); +#else + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); +#endif + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); + } + + /*---------------------------------------------------------------------* + * TD stereo updates + *---------------------------------------------------------------------*/ + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) + { + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); + + td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, + tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Q6 +#endif + ); + + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); + } + + } /* n_channels loop */ + + + /*---------------------------------------------------------------------* + * MDCT stereo: joint TCX Core Decoding + *---------------------------------------------------------------------*/ + + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) + { + /* active-frame decoding */ + IF( GT_32( sts[0]->core_brate, SID_2k40 ) ) + { + IF( hMCT ) + { + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); + } + } + + pop_wmops(); + return error; + } + ELSE + { + Word16 e_sig; + Word16 ch; + + e_sig = 17; + move16(); + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = sts[ch]; + + st->last_gain_syn_deemph = 0; + move16(); + IF( st->hHQ_core ) + { + st->hHQ_core->Q_fer_samples = 0; + move16(); + } +#ifdef FIX_778_STEREO_BRATE_SWITCHING + st->Q_syn = 0; + move16(); +#endif + st->prev_Q_syn = st->Q_syn; + move16(); + + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); + + IF( st->hTcxDec ) + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + } + IF( st->hTcxDec ) + { + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + } + } + + stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); + + FOR( ch = 0; ch < 2; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hHQ_core->Q_old_wtda_LB = st->Q_syn; + move16(); + st->hHQ_core->Q_old_wtda = st->Q_syn; + move16(); + } + +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); +#else + Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); +#endif + } + } + /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ + ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) + { + sts[0] = hCPE->hCoreCoder[0]; + sts[1] = hCPE->hCoreCoder[1]; + + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + { + sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); + move16(); + sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); + move16(); + } + updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); + + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + { + sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); + move16(); + sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); + move16(); + } + } + + test(); + test(); +#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES + /* On first good active frame after frameloss undo the whitening of the bg noise shape */ + IF( GT_32( sts[0]->core_brate, SID_2k40 ) && sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) +#else + IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) + /* On first good frame after frameloss undo the whitening of the bg noise shape */ +#endif + { + FOR( n = 0; n < n_channels; ++n ) + { + IF( NE_16( sts[n]->last_core_bfi, ACELP_CORE ) ) + { + Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; + move16(); + + TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); + } + } + } + } + + /*---------------------------------------------------------------------* + * Stereo CNG updates + *---------------------------------------------------------------------*/ + + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) + { + /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ + Word16 Q_c_PS_LT, Q_output; + Word32 c_PS_LT_fx; + + Q_c_PS_LT = 31; + move16(); + Q_output = 11; + move16(); + c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); + Q_c_PS_LT = Q31; + move16(); + + stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); + + hCPE->hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); + } + + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and updates + *---------------------------------------------------------------------*/ + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * TD-BWE for ACELP to TCX transitions + *---------------------------------------------------------------------*/ + + /*core_switching_post_dec*/ + Q_synth = 0; + move16(); + if ( st->hHQ_core != NULL ) + { + st->hHQ_core->Q_old_postdec = 0; + move16(); + } + + /*------------------fix-to-fix-end-----------------------*/ + + Word16 output_mem_16_fx[L_FRAME48k]; + Word16 *p_output_mem_16; + + IF( p_output_mem_fx != NULL ) + { + p_output_mem_16 = output_mem_16_fx; + Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); + } + ELSE + { + p_output_mem_16 = NULL; + set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); + } + + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); + + IF( st->hHQ_core != NULL ) + { + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); + st->hHQ_core->Q_old_wtda = 0; + move16(); + } + + /*size of synth is choosen as delay comp to start with*/ + /*-------------------cldfb-start-------------------------*/ + + IF( st->cldfbSyn != NULL ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); + st->cldfbSyn->Q_cldfb_state = Q4; + move16(); + } + + Word16 q_audio, old_syn_fx; + old_syn_fx = Q11; + move16(); + q_audio = Q12; + move16(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) + { + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) + { + GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); + } + ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) + { + GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); + } + + /* Memories Scaling */ + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); + } + + /* Memories Re-Scaling */ + IF( st->hBWE_TD != NULL ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); + } + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/MDCT core switching + *---------------------------------------------------------------------*/ + + /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) + { + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + } + + IVAS_FORMAT ivas_format; + IF( st_ivas != NULL ) + { + ivas_format = st_ivas->ivas_format; + move32(); + } + ELSE + { + ivas_format = UNDEFINED_FORMAT; + move32(); + } + IF( hCPE != NULL ) + { + last_element_mode = hCPE->last_element_mode; + move16(); + } + ELSE + { + last_element_mode = IVAS_SCE; + move16(); + } + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) + { + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + } + + /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) + { + Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); + } + /*---------------------------------------------------------------------* + * Pre-processing for bandwidth switching + *---------------------------------------------------------------------*/ + + ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); + + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); + + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + IF( st->cldfbSyn != NULL ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); + st->cldfbSyn->Q_cldfb_state = Q11; + move16(); + } + +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); +#else + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); +#endif + + /*------------------reset-code-start---------------------*/ + + test(); + test(); + IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) + { + test(); + if ( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) + { + st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + move16(); + } + st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + move16(); + st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + move16(); + } + + /*---------------------------------------------------------------------* + * WB TBE decoding + * WB BWE decoding + *---------------------------------------------------------------------*/ + + Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; + Word16 Q_syn_hb; + + Q_input = 0; + move16(); + Q_hb_synth_fx = 0; + move16(); + Q_synth_fx = 0; + move16(); + + FD_BWE_DEC_HANDLE hBWE_FD; + hBWE_FD = st->hBWE_FD; + + Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, negate( Q11 ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( Q11 ) ); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, WB_TBE ) ) + { + /* WB TBE decoder */ + + ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) + { + /* do nothing */ + } + ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) + { + /* WB BWE decoder */ + Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); + } + + /* Memories Re-Scaling */ + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); + + IF( hBWE_FD != NULL ) + { + Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); + } + IF( st->hBWE_TD != NULL ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE decoding + * SWB(FB) BWE decoding + *---------------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) + { + /* SWB TBE decoder */ + Q_white_exc = 0; + move16(); + + ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); + + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + + IF( GT_16( Q_white_exc, 31 ) ) + { + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); + Q_white_exc = 31; + move16(); + } + + /* FB TBE decoder */ + IF( EQ_16( st->extl, FB_TBE ) ) + { + fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); + } + } + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) + { + /* SWB BWE decoder */ + Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); + + Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); + + Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); + } + + /*---------------------------------------------------------------------* + * FEC - recovery after lost HQ core (smoothing of the BWE component) + *---------------------------------------------------------------------*/ + + test(); + test(); + IF( st->prev_bfi && EQ_16( st->last_core, HQ_CORE ) && NE_16( st->extl, -1 ) ) + { + /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ + tmp16 = shr( 410, shr( output_frame, 8 ) ); /* Q15 */ + IF( EQ_16( output_frame, L_FRAME48k ) ) + { + tmp16 = 68; + move16(); + } + /*output_frame/FRAC_BWE_SMOOTH*/ + j = shr( output_frame, 1 ); + tmp16_2 = 0; + move16(); + FOR( i = 0; i < j; i++ ) + { + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], tmp16_2 ); /* Q11 */ + move32(); +#ifdef BASOP_NOGLOB + tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); /* Q15 */ +#else + tmp16_2 = add( tmp16_2, tmp16 ); +#endif + } + } + + /*---------------------------------------------------------------------* + * SWB CNG + *---------------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) + { + /* SHB CNG decoder */ + Word16 synth_fxl[960]; /* Q-2 */ + Word16 q; + + q = 2; + move16(); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); +#ifdef MSAN_FIX + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); +#else + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); +#endif + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); + + swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); + + 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 ) ); + } + +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); +#endif + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); + } + + /*-------------------------------------------------------------------* + * Inter-channel BWE decoding + *-------------------------------------------------------------------*/ + test(); + IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + Word16 q; + q = 11; + move16(); + + IF( hCPE->hStereoDft != NULL ) + { + hCPE->hStereoDft->td_gain_fx[0] = 1; + move32(); + } + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); + stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); +#ifdef MSAN_FIX + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) + { + Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); + } +#else + Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[1], L_FRAME48k, sub( Q11, q ) ); +#endif + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + /*----------------------------------------------------------------* + * BFI waveform adjustment + *----------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) + { + tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + + waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, + &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, + st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); + + st->hPlcInfo->Pitch = 0; + move16(); + } + } + + /*----------------------------------------------------------------* + * Transition and synchronization of BWE components + *----------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || st->last_core == ACELP_CORE ) ) || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) + { + /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + /* TBE on top of ACELP@12.8kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + ELSE + { + test(); + IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) + { + /* HR SWB BWE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + } + ELSE + { + /* TBE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + } + + /* Smooth transitions when switching between different technologies */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->last_core == ACELP_CORE ) && + ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && s_xor( st->core, st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) + { + /* switching between BWE and TBE technologies */ + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < tmps; i++ ) + { + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); + move16(); + tmp16 = add( tmp16, incr ); + } + + set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); + } + ELSE IF( LT_16( tmps, st->old_bwe_delay ) ) + { + /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ + + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < tmps; i++ ) + { + +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); + move16(); + tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); + move16(); +#else + tmp_buffer_fx[i] = round_fx_sat( L_mac_sat( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + move16(); +#endif + + tmp16 = add( tmp16, incr ); + } + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); + } + ELSE IF( GT_16( tmps, st->old_bwe_delay ) ) + { + /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); + move16(); + tmp16 = add( tmp16, incr ); + } + FOR( ; i < tmps; i++ ) + { + tmp_buffer_fx[i] = 0; + move16(); + } + tmp16 = 0; + move16(); + FOR( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + move16(); + tmp16 = add( tmp16, incr ); + } + + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); + } + + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_TD ) && !use_cldfb_for_dft ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) + { + /* Delay hb_synth */ + Word32 hb_prev_synth_buffer_fx_32[111]; + + Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); + delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); + } + ELSE + { + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); + } + + st->old_bwe_delay = tmps; + + /* SWB CNG/DTX - calculate SHB energy */ + test(); + test(); + test(); + IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && st->core == ACELP_CORE && st->hTdCngDec != NULL ) + { + Word16 exp; + Word32 fra; + SWITCH( output_frame ) + { + case L_FRAME8k: + tmp16 = 205; + move16(); + BREAK; /*Q15*/ + case L_FRAME16k: + tmp16 = 102; + move16(); + BREAK; /*Q15*/ + case L_FRAME32k: + tmp16 = 51; + move16(); + BREAK; /*Q15*/ + case L_FRAME48k: + tmp16 = 34; + move16(); + BREAK; /*Q15*/ + } + + L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ + + Word16 exp2; + exp = 20; + move16(); + Word32 L_tmp2 = sum2_32_fx( hb_synth_32_fx[n], output_frame, &exp ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 20, L_tmp2, exp, &exp ); + L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); + exp2 = norm_l( L_tmp ); + exp = sub( exp, exp2 ); + fra = BASOP_Util_Log2( L_shl_sat( L_tmp, exp2 ) ); + exp2 = norm_l( exp ); + L_tmp = L_shl( exp, exp2 ); + exp = sub( Q31, exp2 ); + L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); + // exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); + L_tmp = Mpy_32_16_1( L_tmp, 24660 ); + exp = add( exp, 2 ); + st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 7 ) ) ); /*Q8*/ + move16(); + st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, sub( exp, 20 ) ); /*Q11*/ + move32(); + } + } + + test(); + IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ + break; + } + + /*----------------------------------------------------------------* + * Post-processing + * - TCX-LTP Postfilter (except DFT stereo) + * - core switching in DFT stereo + * - updates for potential TD->DFT stereo switching + *----------------------------------------------------------------*/ + IF( hCPE != NULL ) + { + FOR( Word32 ch_ind = 0; ch_ind < n_channels; ch_ind++ ) + { + IF( hCPE->hCoreCoder[ch_ind] != NULL ) + { + IF( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) + { + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); + } + } + } + } + IF( hSCE != NULL ) + { + IF( hSCE->hCoreCoder[0] != NULL ) + { + IF( hSCE->hCoreCoder[0]->hHQ_core != NULL ) + { + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); + } + } + } + + Word16 exp_max; + Word32 output_fx_loc[L_FRAME48k]; + + exp_max = 0; + move16(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + test(); + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) + { + ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); + } + + /* update OLA buffers - needed for switching to DFT stereo */ + IF( !sba_dirac_stereo_flag ) + { + IF( hCPE != NULL ) + { + stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); + } + } + } + ELSE /* IVAS_CPE_DFT */ + { + Word16 q; + q = 11; + move16(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) + { + stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); + } + Word16 q_DFT[2] = { 3, 3 }; + move16(); + move16(); + + stereo_dft_dec_core_switching_fx( hCPE, output_32_fx[0], synth_32_fx[0], hb_synth_32_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); + + hCPE->hStereoDft->q_dft = s_min( q_DFT[0], q_DFT[1] ); + move16(); + + IF( DFT_fx != NULL ) + { + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); + } + + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ + stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); + } + } + + Copy32( synth_32_fx[n], output_32_fx[n], output_frame ); + + /*--------------------------------------------------------* + * Common updates + *--------------------------------------------------------*/ + + /*Scale Memories*/ + + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) + { + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); + st->q_prev_synth_buffer_fx = 0; + move16(); + + exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); + exp_ouput = add( exp_ouput, Q11 ); + exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); + exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); + exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); +#ifndef FIX_740_HQ_CORE_OVA + exp_synth_history += st->hTcxDec->q_synth_history_fx; +#endif + exp_max = s_min( exp_synth_history, exp_ouput ); + exp_max = s_min( exp_max, exp_prev_synth_buffer ); + exp_max = s_min( exp_max, exp_old_out ); + exp_max = s_min( exp_max, exp_delay_buf_out ); + + Copy32( output_32_fx[n], output_fx_loc, output_frame ); + + Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); + Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); + Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); + + st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); + } + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); + + /* Updates */ + + ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); + + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); + + } /* n_channels loop */ + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); + } + } + + pop_wmops(); + return error; +} +#else +ivas_error ivas_core_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const int16_t n_channels, /* i : number of channels to be decoded */ + float *output[], /* o : output synthesis signal */ + float hb_synth[][L_FRAME48k], /* o : output HB synthesis signal */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +) +{ + int16_t i, n, output_frame; + Decoder_State **sts, *st; + STEREO_ICBWE_DEC_HANDLE hStereoICBWE; + STEREO_TD_DEC_DATA_HANDLE hStereoTD; + int16_t sharpFlag[CPE_CHANNELS]; + float synth[CPE_CHANNELS][L_FRAME48k]; + float tmp_buffer[L_FRAME48k]; + int16_t tmps, incr; + float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; + int16_t core_switching_flag[CPE_CHANNELS]; + float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; + float tmp; + float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; + int16_t unbits[CPE_CHANNELS]; + int16_t sid_bw[CPE_CHANNELS]; + FRAME_MODE frameMode[CPE_CHANNELS]; + float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; + int16_t tdm_LRTD_flag; + int32_t element_brate, output_Fs; + int32_t last_element_brate; + int16_t use_cldfb_for_dft; + float *p_output_mem; + int16_t flag_sec_CNA; + int16_t read_sid_info; + int16_t last_element_mode; + int16_t nchan_out; + float *save_hb_synth; + ivas_error error; + + error = IVAS_ERR_OK; + push_wmops( "ivas_core_dec" ); + + /*------------------------------------------------------------------* + * General initialization + *-----------------------------------------------------------------*/ + + use_cldfb_for_dft = 0; + tdm_LRTD_flag = -1; + read_sid_info = 1; /* read SID by default */ + + if ( hSCE != NULL ) + { + sts = hSCE->hCoreCoder; + hStereoICBWE = NULL; + element_brate = hSCE->element_brate; + last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + last_element_mode = IVAS_SCE; + hStereoTD = NULL; + p_output_mem = NULL; + nchan_out = 1; + if ( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + { + if ( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + { + read_sid_info = 0; + } + } + } + else + { + sts = hCPE->hCoreCoder; + element_brate = hCPE->element_brate; + last_element_brate = hCPE->last_element_brate; + last_element_mode = hCPE->last_element_mode; + hStereoICBWE = hCPE->hStereoICBWE; + hStereoTD = hCPE->hStereoTD; + p_output_mem = hCPE->output_mem[1]; + nchan_out = hCPE->nchan_out; + + if ( hCPE->hStereoTD != NULL ) + { + tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + } + + if ( sts[0]->element_mode == IVAS_CPE_DFT ) + { + use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; + } + } + + output_Fs = sts[0]->output_Fs; + output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization per core-decoder channel + *-----------------------------------------------------------------*/ + + frameMode[n] = FRAMEMODE_NORMAL; + st->rate_switching_reset = 0; + + st->mdct_sw = MODE1; + + sid_bw[n] = -1; + core_switching_flag[n] = 0; + sharpFlag[n] = 0; + unbits[n] = 0; + st->GSC_IVAS_mode = 0; + st->element_brate = element_brate; + + st->use_partial_copy = 0; + st->rf_flag = 0; + st->rf_frame_type = RF_NO_DATA; + + if ( st->bfi == 1 ) + { + frameMode[n] = FRAMEMODE_MISSING; + st->coder_type = st->last_coder_type; + } + else + { + if ( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + { + st->coder_type = INACTIVE; + } + st->extl = -1; + st->flagGuidedAcelp = 0; + } + +#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID + if ( !st->bfi && st->prev_bfi && st->total_brate > SID_2k40 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) +#else + if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) +#endif + { + v_multc( st->hHQ_core->old_out, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX ); + v_multc( st->hHQ_core->old_outLB, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_outLB, st->L_frame ); + } + + set_f( voice_factors[n], 0.f, NB_SUBFR16k ); + set_f( hb_synth[n], 0.0f, L_FRAME48k ); + + /*------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ + + if ( st->bfi != 1 ) + { + ivas_decision_matrix_dec( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); + + synchonize_channels_mdct_sid( sts, n ); + + if ( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + { + st->sr_core = st->L_frame * FRAMES_PER_SEC; + st->fscale_old = st->fscale; + st->fscale = sr2fscale( st->sr_core ); + } + else + { + frameMode[n] = FRAMEMODE_MISSING; + } + } + else if ( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) + { + st->core = TCX_20_CORE; + } + } /* n_channels loop */ + + /* MDCT stereo -> DFT stereo switching */ + if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + { + int16_t ovl, fade_len; + if ( sts[0]->L_frame != sts[0]->last_L_frame ) + { + lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); + } + if ( sts[0]->L_frame != L_FRAME16k ) + { + ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); + + fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + } + } + + if ( hCPE != NULL && hCPE->hStereoCng != NULL ) + { + hCPE->hStereoCng->flag_cna_fade = 0; + } + + if ( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) + { + save_hb_synth = hSCE->save_hb_synth; + } + else + { + save_hb_synth = NULL; + } + + /*------------------------------------------------------------------* + * Decode SID for MDCT-Stereo DTX mode + *-----------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + { + if ( sts[0]->cng_sba_flag ) + { + FdCngDecodeDiracMDCTStereoSID( hCPE ); + } + else + { + FdCngDecodeMDCTStereoSID( hCPE ); + } + } + + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); + } + + /*------------------------------------------------------------------* + * Core Decoding + *-----------------------------------------------------------------*/ + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + if ( st->bfi == 1 ) + { + st->nbLostCmpt++; + } + else + { + if ( st->prev_bfi == 1 ) + { + st->prev_nbLostCmpt = st->nbLostCmpt; + } + else + { + st->prev_nbLostCmpt = 0; + } + + st->nbLostCmpt = 0; + } + st->enablePlcWaveadjust = 0; + + if ( n == 1 ) + { + sts[1]->BER_detect |= sts[0]->BER_detect; + } + + /*---------------------------------------------------------------------* + * Detect bandwidth switching + *---------------------------------------------------------------------*/ + + bandwidth_switching_detect( st ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + if ( ( error = core_switching_pre_dec( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + + flag_sec_CNA = -1; + if ( hCPE != NULL ) + { + flag_sec_CNA = sts[1]->flag_cna; + } + + /*---------------------------------------------------------------------* + * ACELP core decoding + * TCX core decoding + * HQ core decoding + *---------------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE ) + { + /* ACELP core decoder */ + if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) + { + /* TCX decoder */ + stereo_tcx_core_dec( st, frameMode[n], output[n], synth[n], pitch_buf[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); + } + + if ( st->core == HQ_CORE ) + { + /* HQ core decoder */ + hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); + } + + /*---------------------------------------------------------------------* + * TD stereo updates + *---------------------------------------------------------------------*/ + + if ( st->element_mode == IVAS_CPE_TD && n == 0 ) + { + td_stereo_param_updt( st->lsp_old, st->lsf_old, st->old_pitch_buf + st->nb_subfr, tdm_lspQ_PCh, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); + } + + } /* n_channels loop */ + + /*---------------------------------------------------------------------* + * MDCT stereo: joint TCX Core Decoding + *---------------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_MDCT ) + { + /* active-frame decoding */ + if ( sts[0]->core_brate > SID_2k40 ) + { + if ( hMCT ) + { + pop_wmops(); + + return error; + } + else + { + stereo_mdct_core_dec( st_ivas, hCPE, output, synth ); + } + } + /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ + else if ( hCPE->nchan_out == 1 ) + { + updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth ); + } + +#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES + + /* On first good active frame after frameloss undo the whitening of the bg noise shape */ + if ( sts[0]->core_brate > SID_2k40 && sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) +#else + if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) + /* On first good frame after frameloss undo the whitening of the bg noise shape */ +#endif + { + for ( n = 0; n < n_channels; ++n ) + { + if ( sts[n]->last_core_bfi != ACELP_CORE ) + { + TonalMdctConceal_whiten_noise_shape_ivas( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); + } + } + } + } + + /*---------------------------------------------------------------------* + * Stereo CNG updates + *---------------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_TD && hCPE->hStereoCng != NULL ) + { + stereo_cng_compute_PScorr( output, &hCPE->hStereoCng->c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); + } + + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and updates + *---------------------------------------------------------------------*/ + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * TD-BWE for ACELP to TCX transitions + *---------------------------------------------------------------------*/ + + if ( st->last_core == ACELP_CORE && ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->hBWE_TD != NULL ) + { + if ( ( st->bwidth == SWB || st->bwidth == FB ) && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) ) + { + GenTransition( st->hBWE_TD, hb_synth[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); + } + else if ( st->bwidth == WB && st->last_extl == WB_TBE ) + { + GenTransition_WB( st->hBWE_TD, hb_synth[n], output_Fs ); + } + } + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/MDCT core switching + *---------------------------------------------------------------------*/ + + /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ + if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT && !( st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) ) + { + mvr2r( synth[n], hSCE->save_synth, output_frame ); + } + + if ( ( error = core_switching_post_dec( st, synth[n], output[n], p_output_mem, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ + if ( sba_dirac_stereo_flag && hSCE && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) + { + mvr2r( synth[n], hSCE->save_synth, output_frame ); + } + + /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ + if ( n == 0 && st->element_mode == IVAS_CPE_MDCT && st->last_core == ACELP_CORE && st->core != ACELP_CORE && ( nchan_out == 1 || ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_DFT ) ) ) + { + mvr2r( sts[0]->previoussynth, sts[1]->previoussynth, st->hTcxDec->L_frameTCX ); + } + + /*---------------------------------------------------------------------* + * Pre-processing for bandwidth switching + *---------------------------------------------------------------------*/ + + bw_switching_pre_proc( st, old_syn_12k8_16k[n], last_element_brate, nchan_out ); + + /*---------------------------------------------------------------------* + * WB TBE decoding + * WB BWE decoding + *---------------------------------------------------------------------*/ + + if ( st->extl == WB_TBE ) + { + /* WB TBE decoder */ + wb_tbe_dec( st, bwe_exc_extended[n], voice_factors[n], hb_synth[n] ); + } + else if ( st->element_mode == IVAS_CPE_TD && n == 1 && !tdm_LRTD_flag && st->extl != -1 && st->bws_cnt == 0 && st->extl_brate == 0 ) + { + /* do nothing */ + } + else if ( st->extl == WB_BWE && st->bws_cnt == 0 ) + { + /* WB BWE decoder */ + wb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame, voice_factors[n], pitch_buf[n] ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE decoding + * SWB(FB) BWE decoding + *---------------------------------------------------------------------*/ + + if ( st->extl == SWB_TBE || st->extl == FB_TBE || ( st->coder_type != AUDIO && st->coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE && !st->con_tcx && output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0 ) ) + { + /* SWB TBE decoder */ + swb_tbe_dec( st, hStereoICBWE, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], tmp_buffer /*fb_exc*/, hb_synth[n], pitch_buf[n] ); + + /* FB TBE decoder */ + if ( st->extl == FB_TBE ) + { + fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); + } + } + else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) + { + /* SWB BWE decoder */ + swb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame ); + } + + /*---------------------------------------------------------------------* + * FEC - recovery after lost HQ core (smoothing of the BWE component) + *---------------------------------------------------------------------*/ + + if ( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 ) + { + tmp = FRAC_BWE_SMOOTH / output_frame; + + for ( i = 0; i < output_frame / FRAC_BWE_SMOOTH; i++ ) + { + hb_synth[n][i] *= ( i * tmp ); + } + } + + /*---------------------------------------------------------------------* + * SWB CNG + *---------------------------------------------------------------------*/ + + if ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) + { + /* SHB CNG decoder */ + swb_CNG_dec( st, synth[n], hb_synth[n], sid_bw[n] ); + } + + /*-------------------------------------------------------------------* + * Inter-channel BWE decoding + *-------------------------------------------------------------------*/ + + if ( n == 0 && st->element_mode >= IVAS_CPE_DFT ) + { + stereo_icBWE_dec( hCPE, hb_synth[0], hb_synth[1], tmp_buffer /*fb_synth_ref*/, voice_factors[0], output_frame ); + } + + if ( st->element_mode == EVS_MONO ) + { + /*----------------------------------------------------------------* + * BFI waveform adjustment + *----------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE && !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 ) + { + tmps = NS2SA( output_Fs, DELAY_CLDFB_NS ); + + waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut_float, synth[n] + tmps, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); + + st->hPlcInfo->Pitch = 0; + } + } + + /*----------------------------------------------------------------* + * Transition and synchronization of BWE components + *----------------------------------------------------------------*/ + + if ( ( st->extl != -1 && ( st->extl != IGF_BWE || st->last_core == ACELP_CORE ) ) || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) + { + /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ + if ( st->L_frame == L_FRAME ) + { + /* TBE on top of ACELP@12.8kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + else + { + if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + { + /* HR SWB BWE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + } + else + { + /* TBE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + } + + /* Smooth transitions when switching between different technologies */ + if ( !( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->last_core == ACELP_CORE ) && + ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) && ( st->element_mode != IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) ) + { + /* switching between BWE and TBE technologies */ + incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + for ( i = 0; i < tmps; i++ ) + { + hb_synth[n][i] *= sin_table256[i * incr]; + } + + set_f( st->hb_prev_synth_buffer, 0.0f, tmps ); + } + else if ( tmps < st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ + incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + for ( i = 0; i < tmps; i++ ) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + + st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + else if ( tmps > st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ + incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); + for ( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; + } + + for ( ; i < tmps; i++ ) + { + tmp_buffer[i] = 0.0f; + } + + for ( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + + if ( ( st->element_mode != IVAS_CPE_TD && !use_cldfb_for_dft ) || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) + { + /* Delay hb_synth */ + delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); + } + else + { + mvr2r( hb_synth[n] + output_frame - tmps, st->hb_prev_synth_buffer, tmps ); + } + + st->old_bwe_delay = tmps; + if ( st->hBWE_TD != NULL ) + { + mvr2r( hb_synth[n], st->hBWE_TD->old_hb_synth, output_frame ); + } + + /* SWB CNG/DTX - calculate SHB energy */ + if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG && st->core == ACELP_CORE && st->hTdCngDec != NULL ) + { + st->hTdCngDec->last_shb_ener = sum2_f( hb_synth[n], output_frame ) + 0.001f; + st->hTdCngDec->last_shb_ener /= (float) output_frame; + st->hTdCngDec->last_shb_ener = 10 * log10f( st->hTdCngDec->last_shb_ener ); + } + } + + if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT ) + { + /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ + break; + } + + /*----------------------------------------------------------------* + * Post-processing + * - TCX-LTP Postfilter (except DFT stereo) + * - core switching in DFT stereo + * - updates for potential TD->DFT stereo switching + *----------------------------------------------------------------*/ + + if ( st->element_mode != IVAS_CPE_DFT ) + { + if ( st->element_mode != IVAS_CPE_MDCT || sba_dirac_stereo_flag ) + { + ivas_post_proc( hSCE, hCPE, n, synth[n], NULL, output_frame, sba_dirac_stereo_flag ); + } + + /* update OLA buffers - needed for switching to DFT stereo */ + if ( !sba_dirac_stereo_flag ) + { + stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + } + } + else /* IVAS_CPE_DFT */ + { + if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) + { + stereo_mdct2dft_update( hCPE, output[0], synth[0] ); + } + + stereo_dft_dec_core_switching( hCPE, output[0], synth[0], hb_synth[0], DFT, output_frame, use_cldfb_for_dft, 0 ); + + if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + { + /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ + stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + } + } + + mvr2r( synth[n], output[n], output_frame ); + + /*--------------------------------------------------------* + * Common updates + *--------------------------------------------------------*/ + + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec( st, output[n], output_frame, hCPE ); + + /* Updates */ + updt_dec_common( st, NORMAL_HQ_CORE, -1, output[n] ); + + } /* n_channels loop */ + + + pop_wmops(); + return error; +} +#endif diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index ccb39cadf82506a8dc582450739dc44dadeb7c58..1ab53f387da149f684e6bddfbb513c066d77b17e 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -35,8 +35,7 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #endif // IVAS_FLOAT_FIXED #include "prot.h" #include @@ -978,7 +977,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { - deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[1] ) ); + deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[1] ) ); numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ @@ -996,7 +995,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { - deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } ELSE IF( LT_16( numCldfbAnalyses_old, numCldfbAnalyses ) ) @@ -1016,7 +1015,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { - deleteCldfb_ivas( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); } } ELSE IF( LT_16( numCldfbSyntheses_old, numCldfbSyntheses ) ) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 4faab3eb7afb2021d00e358d8f3fcfe0aaf80e87..f0e4bfeceee5d2622d72aad2f5a6a3f2dcd5f41e 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -38,7 +38,7 @@ #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #include diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index e0ac57446c165ddca7789cb16608827411dd9057..f33bb4fc7b8cb4fc922746076873bce5e6412d5e 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -40,14 +40,11 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #include -/* NOTE: Temporary macro for computation happening in floating point. This macro and code active under this is to be removed once the intermediate conversions to float are not required */ -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*--------------------------------------------------------------------------* * Local function prototypes @@ -65,12 +62,15 @@ static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, C *--------------------------------------------------------------------------*/ ivas_error ivas_cpe_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - Word32 *output[CPE_CHANNELS], /* o : output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - Word16 *q_output /* i/o : Q of output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 *output[CPE_CHANNELS], /* o : output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + , + Word16 *q_output /* i/o : Q of output synthesis signal */ +#endif ) { Word16 i, n, n_channels; @@ -141,7 +141,7 @@ ivas_error ivas_cpe_dec_fx( } q_old_out_LB = Q11; move16(); - FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) + FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { @@ -564,7 +564,7 @@ ivas_error ivas_cpe_dec_fx( { IF( !st_ivas->bfi ) { - tdm_configure_dec( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); + tdm_configure_dec_fx( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo ); @@ -586,7 +586,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { - IF( NE_32( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_dec_fx( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -611,7 +611,7 @@ ivas_error ivas_cpe_dec_fx( set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); /* core decoder */ - IF( NE_32( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -645,7 +645,7 @@ ivas_error ivas_cpe_dec_fx( IF( NE_16( shift, 31 ) ) { - shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q13 ); /* Q13 for guard bits */ + shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q15 ); /* Q15 for guard bits */ IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) { @@ -761,7 +761,7 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < hCPE->nchan_out; n++ ) { Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->output_mem_fx[n], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; move16(); } @@ -776,7 +776,7 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < hCPE->nchan_out; n++ ) { Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->output_mem_fx[n], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[n] = Q11; move16(); } @@ -851,7 +851,11 @@ ivas_error ivas_cpe_dec_fx( * IC-BWE: output LB and HB mix in ACELP mode *----------------------------------------------------------------*/ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL stereo_icBWE_decproc_fx( hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame, *q_output ); +#else + stereo_icBWE_decproc_fx( hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame ); +#endif smooth_dft2td_transition_fx( hCPE, output, output_frame ); @@ -1004,8 +1008,8 @@ ivas_error create_cpe_dec( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); - set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) ); + set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); + set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) ); } hCPE->q_prev_synth_fx = 0; move16(); @@ -1026,11 +1030,11 @@ ivas_error create_cpe_dec( IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) && EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) ) || st_ivas->sba_dirac_stereo_flag ) { - IF( ( hCPE->input_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) + IF( ( hCPE->input_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } - set32_fx( hCPE->input_mem_fx[i], 0, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->input_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); IF( ( hCPE->input_mem_LB_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL ) { @@ -1047,20 +1051,20 @@ ivas_error create_cpe_dec( set32_fx( hCPE->input_mem_BPF_fx[0], 0, STEREO_DFT32MS_OVL_16k ); } - IF( ( hCPE->output_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) + IF( ( hCPE->output_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } - set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); hCPE->q_output_mem_fx[i] = Q11; move16(); IF( LT_16( i, hCPE->nchan_out ) ) { - IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) + IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } - set32_fx( hCPE->prev_synth_chs_fx[i], 0, NS2SA_fx2( output_Fs, FRAME_SIZE_NS ) ); + set32_fx( hCPE->prev_synth_chs_fx[i], 0, NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) ); } ELSE { @@ -1222,8 +1226,8 @@ ivas_error create_cpe_dec( move16(); hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; move32(); - set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); - set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); + set16_fx( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); + set16_fx( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; move16(); hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; @@ -1322,14 +1326,12 @@ void destroy_cpe_dec( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef IVAS_FLOAT_FIXED free( hCPE->input_mem_LB_fx[n] ); hCPE->input_mem_LB_fx[n] = NULL; free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; free( hCPE->output_mem_fx[n] ); hCPE->output_mem_fx[n] = NULL; -#endif IF( hCPE->prev_synth_chs_fx[n] != NULL ) { @@ -1337,10 +1339,8 @@ void destroy_cpe_dec( hCPE->prev_synth_chs_fx[n] = NULL; } } -#ifdef IVAS_FLOAT_FIXED free( hCPE->input_mem_BPF_fx[0] ); hCPE->input_mem_BPF_fx[0] = NULL; -#endif } IF( hCPE->hStereoCng != NULL ) diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index c6623f9e511d4b414f468b4c3e7fd0f7b8033a8a..111678e82e6e93f962bdb249ac56cd43c2df15b0 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -39,6 +39,9 @@ #include "ivas_cnst.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-----------------------------------------------------------------* * ivas_decision_matrix_dec() @@ -527,14 +530,14 @@ void ivas_decision_matrix_dec_fx( { IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - st->cng_type = get_next_indice( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); IF( EQ_16( st->cng_type, FD_CNG ) ) { - st->bwidth = get_next_indice( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); } } - IF( get_next_indice( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -549,7 +552,7 @@ void ivas_decision_matrix_dec_fx( { /* read channel coherence */ Word16 index; - index = get_next_indice( st, 4 ); + index = get_next_indice_fx( st, 4 ); st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; move16(); @@ -557,7 +560,7 @@ void ivas_decision_matrix_dec_fx( // st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); /* read flag for no side noise shape */ - st->hFdCngDec->hFdCngCom->no_side_flag = get_next_indice( st, 1 ); + st->hFdCngDec->hFdCngCom->no_side_flag = get_next_indice_fx( st, 1 ); } test(); @@ -615,7 +618,7 @@ void ivas_decision_matrix_dec_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) { /* ACELP/transform core selection bit */ - IF( get_next_indice( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { st->core = HQ_CORE; move16(); @@ -673,7 +676,7 @@ void ivas_decision_matrix_dec_fx( { IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) { - st->coder_type = get_next_indice( st, 3 ); + st->coder_type = get_next_indice_fx( st, 3 ); *sharpFlag = 0; move16(); @@ -689,10 +692,10 @@ void ivas_decision_matrix_dec_fx( ELSE { /* get coder_type info */ - st->coder_type = get_next_indice( st, 3 ); + st->coder_type = get_next_indice_fx( st, 3 ); /* get sharpening flag */ - *sharpFlag = get_next_indice( st, 1 ); + *sharpFlag = get_next_indice_fx( st, 1 ); } } } @@ -731,7 +734,7 @@ void ivas_decision_matrix_dec_fx( ELSE IF( EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, MIN_BRATE_WB_BWE ) && !st->flag_ACELP16k ) { /* read the WB TBE/BWE selection bit */ - IF( get_next_indice( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { st->extl = WB_BWE; move16(); @@ -769,7 +772,7 @@ void ivas_decision_matrix_dec_fx( IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) ) { /* read the SWB TBE/BWE selection bit */ - tmp = get_next_indice( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); IF( tmp ) { @@ -893,7 +896,7 @@ void ivas_decision_matrix_dec_fx( test(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( st->core, HQ_CORE ) ) { - IF( get_next_indice( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { st->core = TCX_20_CORE; move16(); @@ -924,7 +927,7 @@ void ivas_decision_matrix_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice( st, 1 ); + *core_switching_flag = get_next_indice_fx( st, 1 ); } ELSE { diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ae75fcf2f8f3742fb83ff8a74cc246e896e208e2..ab66ecf6437f84de9ffc54f5084b781fdd207e18 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -36,8 +36,6 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_cnst.h" @@ -46,8 +44,7 @@ #include "ivas_rom_rend.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "ivas_rom_com_fx.h" #include "ivas_prot_fx.h" #endif @@ -3256,12 +3253,12 @@ void ivas_dirac_dec_set_md_map( { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; move16(); - mvs2s( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); + Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); } /* set mapping according to dirac_read_idx */ - set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); test(); test(); @@ -3301,7 +3298,7 @@ void ivas_dirac_dec_set_md_map( hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; } - set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); + set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); } return; @@ -3772,8 +3769,8 @@ void ivas_dirac_dec_render_sf_fx( } q_cldfb = Q11; move16(); - set_s( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); - set_s( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); + set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); + set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX ); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) @@ -4594,7 +4591,7 @@ void ivas_dirac_dec_render_sf_fx( test(); IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_params->max_band_decorr, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); @@ -4606,11 +4603,11 @@ void ivas_dirac_dec_render_sf_fx( test(); IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); h_dirac_output_synthesis_state->direct_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); @@ -4804,7 +4801,7 @@ void ivas_dirac_dec_render_sf_fx( } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, ( size_ho / hDirACRend->num_outputs_dir ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { @@ -4812,7 +4809,7 @@ void ivas_dirac_dec_render_sf_fx( } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_params.max_band_decorr, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) ) { @@ -4887,7 +4884,7 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { @@ -4895,7 +4892,7 @@ void ivas_dirac_dec_render_sf_fx( } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); } IF( NE_16( q_diffuseness_vector, Q31 ) ) { diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index c11dda7ccb99db4414f70fc1982705e6e8030985..10660be2da70d3f5c6291bb9fc9bc4cb8b4c20ad 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -49,8 +49,7 @@ #include "wmc_auto.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index 9c769bf5719c8fe70e6d208cd6423d123b3f92eb..b2c140e651c0407d5d46610dbcaa86a1398b9907 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -38,6 +38,7 @@ #include "ivas_rom_com.h" #include #include "wmc_auto.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif @@ -73,7 +74,7 @@ static void ivas_arith_decode_array( { IF( pArith->dyn_model_bits > 0 ) { - model_idx = get_next_indice( st0, pArith->dyn_model_bits ); + model_idx = get_next_indice_fx( st0, pArith->dyn_model_bits ); IF( model_idx > 0 ) { @@ -212,7 +213,7 @@ ivas_error ivas_huffman_decode( { Word16 code, num_bits_read, ind, bit; - code = get_next_indice( st0, huff_cfg->min_len ); + code = get_next_indice_fx( st0, huff_cfg->min_len ); num_bits_read = huff_cfg->min_len; move16(); @@ -220,7 +221,7 @@ ivas_error ivas_huffman_decode( WHILE( GT_16( ind, huff_cfg->sym_len ) ) { - bit = get_next_indice( st0, 1 ); + bit = get_next_indice_fx( st0, 1 ); num_bits_read = add( num_bits_read, 1 ); code = s_or( shl( code, 1 ), bit ); ind = ivas_huffman_code_bits_present( huff_cfg->codebook, code, num_bits_read, huff_cfg->sym_len ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index bb9894dfdffc263988e530d5c3d56adc4bc2c213..f17a8ccb7780fcb4ae2015cbfac763ece0774b8d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -42,8 +42,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED @@ -204,6 +203,9 @@ ivas_error ivas_dec_setup( { IF( EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) { + test(); + test(); + test(); IF( ( st_ivas->ini_active_frame == 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->nchan_out = 1; @@ -277,7 +279,7 @@ ivas_error ivas_dec_setup( num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); /* read Ambisonic (SBA) order */ - IF( LT_32( ivas_total_brate, IVAS_256k ) ) + if ( LT_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->sba_order = 3; move16(); @@ -326,7 +328,7 @@ ivas_error ivas_dec_setup( move16(); FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) { - IF( st_ivas->bit_stream[num_bits_read + k] ) + IF( st_ivas->bit_stream[add( num_bits_read, k )] ) { idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); } @@ -390,8 +392,7 @@ ivas_error ivas_dec_setup( st_ivas->nchan_transport = 1; move16(); BREAK; - case SID_MASA_2TC: - move16(); + case SID_MASA_2TC:; // empyt statement for declaration Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); IF( EQ_16( st_ivas->bit_stream[L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS )], 1 ) ) @@ -481,7 +482,7 @@ ivas_error ivas_dec_setup( k = sub( k, 1 ); test(); - if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + if ( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); } @@ -519,7 +520,7 @@ ivas_error ivas_dec_setup( * and number of transport channels *-------------------------------------------------------------------*/ - IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) + IF( st_ivas->ini_frame == 0 && st_ivas->ivas_format != UNDEFINED_FORMAT ) { IF( NE_32( ( error = doSanityChecks_IVAS( st_ivas ) ), IVAS_ERR_OK ) ) { @@ -990,7 +991,7 @@ static ivas_error ivas_read_format( /* read IVAS format */ k = 0; move16(); - IF( st_ivas->bit_stream[*num_bits_read] ) + if ( st_ivas->bit_stream[*num_bits_read] ) { k = 1; move16(); @@ -998,7 +999,7 @@ static ivas_error ivas_read_format( k = shl( k, 1 ); ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); move16(); - IF( st_ivas->bit_stream[*num_bits_read] ) + if ( st_ivas->bit_stream[*num_bits_read] ) { k = add( k, 1 ); } @@ -1059,7 +1060,7 @@ static ivas_error ivas_read_format( move16(); st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[add( add( ( *num_bits_read ), 1 ), SBA_PLANAR_BITS )], 1 ) ); move16(); - IF( st_ivas->sba_order == 0 ) + if ( st_ivas->sba_order == 0 ) { st_ivas->ivas_format = SBA_ISM_FORMAT; move32(); @@ -1124,7 +1125,7 @@ static ivas_error ivas_read_format( move32(); Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( st_ivas->bit_stream[res_dec - 1] == 1 ) + IF( EQ_32( st_ivas->bit_stream[res_dec - 1], 1 ) ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); @@ -1142,7 +1143,7 @@ static ivas_error ivas_read_format( IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF( st_ivas->sba_analysis_order == 0 ) + if ( st_ivas->sba_analysis_order == 0 ) { st_ivas->sba_analysis_order = SBA_FOA_ORDER; move16(); @@ -1342,7 +1343,6 @@ Word16 getNumChanSynthesis( n = add( st_ivas->nSCE, imult1616( CPE_CHANNELS, st_ivas->nCPE ) ); test(); test(); - test(); IF( st_ivas->sba_dirac_stereo_flag ) { n = CPE_CHANNELS; @@ -1497,7 +1497,7 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->Opt_LsCustom ) { - IF( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ) == IVAS_ERR_OK ) + IF( EQ_32( ( error = ivas_ls_custom_open_fx( &( st_ivas->hLsSetupCustom ) ) ), IVAS_ERR_OK ) ) { #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED set_zero( ( st_ivas->hLsSetupCustom )->ls_azimuth, MAX_OUTPUT_CHANNELS ); @@ -1606,7 +1606,7 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ - IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { IF( NE_32( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) ) { @@ -1865,7 +1865,7 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ) == IVAS_ERR_OK ) + IF( EQ_16( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ), IVAS_ERR_OK ) ) { st_ivas->hOutSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; move32(); @@ -2020,6 +2020,7 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3; + move16(); } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { @@ -2043,7 +2044,7 @@ ivas_error ivas_init_decoder_fx( } #ifdef MSAN_FIX set_f( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 0.f, CLDFB_NO_COL_MAX ); - set_s( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX ); + set16_fx( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX ); #endif test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup ) @@ -2093,7 +2094,7 @@ ivas_error ivas_init_decoder_fx( { st_ivas->hSpar->enc_param_start_band = 0; move16(); - set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; move16(); } @@ -2177,7 +2178,6 @@ ivas_error ivas_init_decoder_fx( test(); test(); test(); - test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) @@ -2280,11 +2280,12 @@ ivas_error ivas_init_decoder_fx( Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; move16(); - set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + set8_fx( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; move16(); } @@ -2385,8 +2386,7 @@ ivas_error ivas_init_decoder_fx( test(); WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k++; - move16(); + k = add( k, 1 ); } test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) @@ -2619,7 +2619,7 @@ ivas_error ivas_init_decoder_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); move16(); test(); - IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) + IF( st_ivas->renderer_type != RENDERER_DISABLE && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) { IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { @@ -2702,7 +2702,7 @@ ivas_error ivas_init_decoder_fx( } /* set CNA/CNG flags */ - IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; move16(); @@ -2750,8 +2750,6 @@ ivas_error ivas_init_decoder_fx( test(); test(); test(); - test(); - test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) @@ -2991,7 +2989,7 @@ ivas_error ivas_init_decoder_fx( FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF( Src_p->SrcSpatial_p != NULL ) + if ( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; move16(); @@ -3044,7 +3042,7 @@ ivas_error ivas_init_decoder_fx( FOR( i = 0; i < numCldfbAnalyses; i++ ) { - IF( NE_32( ( error = openCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -3056,7 +3054,7 @@ ivas_error ivas_init_decoder_fx( FOR( i = 0; i < numCldfbSyntheses; i++ ) { - IF( NE_32( ( error = openCldfb_ivas( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -3070,7 +3068,7 @@ ivas_error ivas_init_decoder_fx( test(); test(); test(); - IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 ) + IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !st_ivas->sba_dirac_stereo_flag && NE_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) { #ifdef IVAS_FLOAT_FIXED #if 1 @@ -4793,7 +4791,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbAnaDec[i] != NULL ) { - deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } @@ -4801,7 +4799,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbSynDec[i] != NULL ) { - deleteCldfb_ivas( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); } } @@ -4862,7 +4860,7 @@ void ivas_destroy_dec_fx( } /* SPAR handle */ - ivas_spar_dec_close( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); + ivas_spar_dec_close_fx( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); /* HOA decoder matrix */ IF( st_ivas->hoa_dec_mtx != NULL ) @@ -5279,7 +5277,6 @@ void ivas_init_dec_get_num_cldfb_instances( } } - test(); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { test(); @@ -5791,7 +5788,6 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_Headrotation ) { - test(); test(); test(); IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) @@ -5802,7 +5798,6 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - test(); test(); test(); IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) @@ -5822,7 +5817,7 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_aeid_on ) { - IF( output_config != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( NE_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { return IVAS_ERROR( IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED, "Wrong set-up: Acoustic environment is not supported in this output configuration." ); } @@ -5833,6 +5828,7 @@ static ivas_error doSanityChecks_IVAS( test(); IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 5a62afa9e8fc96123b51f112835a69cc694ffbdb..1615a177618c63639672abf70f1b1e111a514f29 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -39,8 +39,9 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif + #define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*-------------------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index d891ccfca096e34bf057139b00a8e8fb4fa22439..7a14947649abfb8232e30f4215723c0ef850f471 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -39,7 +39,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 2c2e61b706c47d04bfd75267703a698c86ed39dc..e28a1214aef41047542358984d574657b9bec2ac 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -38,8 +38,7 @@ #include "ivas_rom_com.h" #include "ivas_rom_com_fx.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_stat_enc.h" #include #include "wmc_auto.h" diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 5aad9690891f0cf79279c00a0935fbc8d1747c98..e50db18afcf419dc5743bafcf1763229782f20f2 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -41,8 +41,7 @@ #include "ivas_rom_dec.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" @@ -1050,8 +1049,8 @@ ivas_error ivas_param_ism_dec_open_fx( /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ hSpatParamRendCom->slot_size = extract_l( L_shr( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ), 4 ) ); move16(); - set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; hSpatParamRendCom->subframes_rendered = 0; move16(); @@ -2592,11 +2591,20 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( } ELSE { - /*handling denominator equals to zero*/ - gain_fx = 1; - move16(); - tmp_e1 = -32767; - move16(); + IF( ene_tc_fx == 0 ) /*handling numerator equals to zero*/ + { + gain_fx = 0; + move16(); + tmp_e1 = 31; + move16(); + } + ELSE + { /*handling denominator equals to zero*/ + gain_fx = 1; + move16(); + tmp_e1 = -32767; + move16(); + } } tmp_e1 = add( tmp_e1, sub( ene_tc_e, ene_sum_e ) ); /* tmp_e1 + (ene_tc_e - ene_sum_e)*/ gain_fx = Sqrt16( gain_fx, &tmp_e1 ); diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 11fd356f45bf05d2bd6c20793b86f5652a1dedf3..8f3576ff31021891c5e98566be8352cfed51ca9a 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -34,8 +34,7 @@ #include "options.h" #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_prot_rend.h" @@ -414,7 +413,7 @@ void ivas_ism_render_sf_fx( { FOR( i = 0; i < num_objects; i++ ) { - mvl2l( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); + Copy32( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); p_tc_fx[i] = tc_local_fx[i]; } } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 85963d37179ce3936ae6831a66ec1c2ad73d20bf..3e8ff12c1af4083849430ad67092e42904385b0d 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -43,15 +43,14 @@ #include #include "wmc_auto.h" #include "ivas_prot_fx.h" -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING #include "debug.h" -#endif // DUMPS_ENABLED -#include "prot_fx1.h" -#include "prot_fx2.h" +#endif +#include "prot_fx.h" + #define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fixed_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) -#include "debug.h" /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ @@ -176,7 +175,11 @@ ivas_error ivas_jbm_dec_tc_fx( set32_fx( &p_output_fx[0][0], 0, L_FRAME48k ); set32_fx( &p_output_fx[1][0], 0, L_FRAME48k ); +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -339,7 +342,11 @@ ivas_error ivas_jbm_dec_tc_fx( set32_fx( &p_output_fx[0][0], 0, L_FRAME48k ); set32_fx( &p_output_fx[1][0], 0, L_FRAME48k ); +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -472,7 +479,7 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; } #ifdef MSAN_FIX @@ -551,7 +558,7 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; } } @@ -720,7 +727,11 @@ ivas_error ivas_jbm_dec_tc_fx( } /* decode MASA channels */ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -780,7 +791,7 @@ ivas_error ivas_jbm_dec_tc_fx( { Word16 nchan_ism, sba_ch_idx; - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); nchan_ism = st_ivas->nchan_ism; IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { @@ -824,7 +835,11 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -916,12 +931,12 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -933,7 +948,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif @@ -960,7 +975,7 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; } } @@ -1143,7 +1158,11 @@ ivas_error ivas_jbm_dec_tc_fx( { Word16 q_output = 11; +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1203,7 +1222,11 @@ ivas_error ivas_jbm_dec_tc_fx( /* Decode the transport audio signals */ Word16 q_output = 11; +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1253,7 +1276,11 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) +#else + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1321,12 +1348,12 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -1337,7 +1364,7 @@ ivas_error ivas_jbm_dec_tc_fx( } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif // MSAN_FIX @@ -1366,7 +1393,7 @@ ivas_error ivas_jbm_dec_tc_fx( move16(); FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -3132,7 +3159,7 @@ ivas_error ivas_jbm_dec_render_fx( Word16 nchan_out_cov; Word16 nchan_out_cldfb = 0; - set_s( channel_active_fx, 0, MAX_CICP_CHANNELS ); + set16_fx( channel_active_fx, 0, MAX_CICP_CHANNELS ); Word16 nchan_transport_tmp = st_ivas->nchan_transport; output_Fs = st_ivas->hDecoderConfig->output_Fs; Word16 nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; @@ -3142,7 +3169,7 @@ ivas_error ivas_jbm_dec_render_fx( { nchan_out_cldfb = BINAURAL_CHANNELS; move16(); - set_s( channel_active_fx, 1, BINAURAL_CHANNELS ); + set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS ); nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); } ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) @@ -3156,7 +3183,7 @@ ivas_error ivas_jbm_dec_render_fx( nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); nchan_out_cldfb = nchan_out_cov; move16(); - set_s( channel_active_fx, 1, nchan_out_cov ); + set16_fx( channel_active_fx, 1, nchan_out_cov ); } ELSE { @@ -3164,7 +3191,7 @@ ivas_error ivas_jbm_dec_render_fx( move16(); nchan_out_cldfb = nchan_out_transport; move16(); - set_s( channel_active_fx, 1, nchan_out_cov ); + set16_fx( channel_active_fx, 1, nchan_out_cov ); } // ftf for ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx // ftf changes @@ -3226,11 +3253,11 @@ ivas_error ivas_jbm_dec_render_fx( { IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { - mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); + Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; move16(); } - mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); + Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; move16(); } @@ -4477,8 +4504,8 @@ void ivas_jbm_dec_get_adapted_subframes( *nb_subframes = add( *nb_subframes, ( nCldfbSlotsLocal + PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ) / PARAM_MC_MAX_NSLOTS_IN_SUBFRAME ); nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; - set_s( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes ); + set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes ); IF( GT_16( nSlotsInFirstSubframe, 0 ) ) { @@ -4576,7 +4603,7 @@ void ivas_jbm_dec_get_md_map( } ELSE { - set_s( map, offset, map_idx + 1 ); + set16_fx( map, offset, map_idx + 1 ); } return; @@ -5852,7 +5879,7 @@ static void ivas_jbm_dec_tc_buffer_playout_fx( FOR( ch_idx = 0; ch_idx < st_ivas->hTcBuffer->nchan_transport_jbm; ch_idx++ ) { - mvl2l( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered ); + Copy32( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered ); } st_ivas->hTcBuffer->subframes_rendered = last_sf; @@ -5969,8 +5996,8 @@ void ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16( tmp, ( 15 - ( s2 - s1 ) ) ) ); nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe; - set_s( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes ); + set16_fx( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes ); IF( nSlotsInFirstSubframe > 0 ) { diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index a6368a72785bc9df6154fc5ef6297b4839e487e8..df9bf4748a126f76726be0875c65d9fd96e1d4a6 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -31,13 +31,14 @@ *******************************************************************************************************/ #include +#include #include "options.h" +#include "wmc_auto.h" + #ifndef IVAS_FLOAT_FIXED #include "prot.h" #include "ivas_prot.h" #include "ivas_rom_com.h" -#include "math.h" -#include "wmc_auto.h" /*------------------------------------------------------------------------------------------* diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c index f615bbd1ea4f1b8c5e8b8c3d52dfae635b6dc4b4..0b38566e1a8a697d32cd54b8e65981d9298a2353 100644 --- a/lib_dec/ivas_lfe_dec_fx.c +++ b/lib_dec/ivas_lfe_dec_fx.c @@ -34,8 +34,7 @@ #include "options.h" #ifdef IVAS_FLOAT_FIXED #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" @@ -471,7 +470,7 @@ ivas_error ivas_create_lfe_dec_fx( move16(); hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, low_pass_delay_dec_out ); move16(); - hLFE->lfe_prior_buf_len = NS2SA_fx2( output_Fs, IVAS_LFE_FADE_NS ); + hLFE->lfe_prior_buf_len = NS2SA_FX2( output_Fs, IVAS_LFE_FADE_NS ); move16(); hLFE->bfi_count = 0; diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 003392ca908cbf93caa1abe97ff2e79e61f4d52b..6a65839b8cfcaa72b7c3eec8e7e5de5376025641 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -33,8 +33,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include @@ -964,8 +963,9 @@ void ivas_lfe_tdplc_fx( Copy_Scale_sig_32_16( prevsynth_fx, prevsynth_16_fx, LFE_PLC_BUFLEN, -16 ); // Q5 = Q21 - Q16 Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, 0 ); // Q5 - modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0 ); - modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); + modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); /*samples are generated with 48k sampling rate and then converted to required sampling rate by simple decimation as signal is already bandlimited*/ diff --git a/lib_dec/ivas_ls_custom_dec.c b/lib_dec/ivas_ls_custom_dec.c index 86414d84aa5a00f78af2850cba6cc9e7b208c1e8..6c0b738a7d7b31e5488bbd291426cf41c9e81357 100644 --- a/lib_dec/ivas_ls_custom_dec.c +++ b/lib_dec/ivas_ls_custom_dec.c @@ -36,7 +36,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" +#include "prot_fx.h" #endif @@ -91,7 +91,7 @@ ivas_error ivas_ls_custom_open_fx( ( *hLsSetupCustom )->num_lfe = -1; move16(); - set_s( ( *hLsSetupCustom )->lfe_idx, -1, MAX_OUTPUT_CHANNELS ); + set16_fx( ( *hLsSetupCustom )->lfe_idx, -1, MAX_OUTPUT_CHANNELS ); ( *hLsSetupCustom )->separate_ch_found = -1; move16(); diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 9dff654ad4a07533fe3a8cf8f0f419f2d65373ce..78aa9867bd6e2a2ce5200ce43373c70c391be0cc 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -39,12 +39,9 @@ #include "ivas_rom_com.h" #include "ivas_stat_dec.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "ivas_prot_fx.h" #include "ivas_rom_com_fx.h" diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4887ffa129dc46b1b7ac49c67f3eaa7af8158990..c57261bbf57ad5e2186ae3fdb08beba2418a6187 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -46,8 +46,7 @@ #include "wmc_auto.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif @@ -3305,93 +3304,7 @@ void ivas_param_mc_dec_digest_tc( } if ( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) { -#ifdef IVAS_FLOAT_FIXED - Word32( *cx_fx )[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 cx_e; - Word32( *cx_imag_fx )[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 cx_imag_e; - Word16 cldfb_slots; - - cx_fx = malloc( sizeof( Word32[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS] ) ); - cx_imag_fx = malloc( sizeof( Word32[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS] ) ); - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - set32_fx( cx_fx[lp], 0, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - set32_fx( cx_imag_fx[lp], 0, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - } - - cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; - if ( st_ivas->hDecoderConfig->Opt_tsm ) - { - cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; - } - - f2me_buf( hParamMC->Cldfb_RealBuffer_tc, hParamMC->Cldfb_RealBuffer_tc_fx, &hParamMC->Cldfb_RealBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * hParamMC->num_freq_bands ); - f2me_buf( hParamMC->Cldfb_ImagBuffer_tc, hParamMC->Cldfb_ImagBuffer_tc_fx, &hParamMC->Cldfb_ImagBuffer_tc_e, cldfb_slots * st_ivas->nchan_transport * hParamMC->num_freq_bands ); - - Word16 max_e = 0; - cx_e; - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx[lp][lp2], &cx_fx[lp][lp2], &cx_e ); - max_e = s_max( cx_e, max_e ); - } - } - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx[lp][lp2], &cx_fx[lp][lp2], &cx_e ); - cx_fx[lp][lp2] = L_shr( cx_fx[lp][lp2], max_e - cx_e ); - } - } - cx_e = max_e; - - max_e = 0; - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx_imag[lp][lp2], &cx_imag_fx[lp][lp2], &cx_imag_e ); - max_e = s_max( cx_imag_e, max_e ); - } - } - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - for ( int lp2 = 0; lp2 < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; lp2++ ) - { - f2me( cx_imag[lp][lp2], &cx_imag_fx[lp][lp2], &cx_imag_e ); - cx_imag_fx[lp][lp2] = L_shr( cx_imag_fx[lp][lp2], max_e - cx_imag_e ); - } - } - cx_imag_e = max_e; - - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], - hParamMC->Cldfb_RealBuffer_tc_e, - &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], - hParamMC->Cldfb_ImagBuffer_tc_e, - cx_fx, - &cx_e, - cx_imag_fx, - &cx_imag_e, - hParamMC, - nchan_transport ); - - for ( int lp = 0; lp < PARAM_MC_MAX_PARAMETER_BANDS; lp++ ) - { - me2f_buf( cx_fx[lp], cx_e, cx[lp], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - me2f_buf( cx_imag_fx[lp], cx_imag_e, cx_imag[lp], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - } - free( cx_fx ); - free( cx_imag_fx ); -#else ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], cx, cx_imag, hParamMC, nchan_transport ); -#endif } } diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 9b35fb7c9265eac624fb4bc1ad3bfd828f990fb5..6921066aa007d69b33456ebadedb8abd83950abc 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -35,10 +35,8 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif #include "ivas_prot.h" @@ -354,11 +352,11 @@ ivas_error ivas_mc_paramupmix_dec_open( FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ ) { - IF( ( hMCParamUpmix->pcm_delay_fx[i] = (Word32 *) malloc( NS2SA_fx2( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMCParamUpmix->pcm_delay_fx[i] = (Word32 *) malloc( NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) ); } - set32_fx( hMCParamUpmix->pcm_delay_fx[i], 0, NS2SA_fx2( output_Fs, IVAS_FB_DEC_DELAY_NS ) ); + set32_fx( hMCParamUpmix->pcm_delay_fx[i], 0, NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) ); } /* Head or external rotation */ @@ -687,7 +685,7 @@ static void ps_pred_process_sf( res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); - qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); + qmf_side_im_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); ismp = add( ismp, 1 ); } diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index 7bd948ad61cab35a479d5e6fee8bb08eb28ac0b7..cc014dd76ebd112cfa75b0eb5c741ffe1e460f99 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -43,8 +43,7 @@ #include "ivas_stat_dec.h" #include "ivas_stat_com.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index d83e28576745ebc078c32d1a3f3dde2ce1092ce3..f750f3c9929057907b7f326a7bbc456ddfabf980 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -37,16 +37,15 @@ #include "cnst.h" #include "ivas_cnst.h" #include "rom_com.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*-----------------------------------------------------------------------* @@ -364,8 +363,11 @@ ivas_error ivas_mct_dec_fx( set32_fx( &output_fx[0][0], 0, L_FRAME48k ); set32_fx( &output_fx[1][0], 0, L_FRAME48k ); - +#ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ), IVAS_ERR_OK ) ) +#else + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0 ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -582,6 +584,7 @@ ivas_error ivas_mct_dec_fx( IF( hCPE->hCoreCoder[n]->Q_syn != 0 ) { Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); + Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_LB_fx, L_FRAME32k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); } IF( hCPE->hCoreCoder[n]->hBPF ) { @@ -592,10 +595,10 @@ ivas_error ivas_mct_dec_fx( { // Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); } - IF( hCPE->hCoreCoder[n]->hHQ_core ) - { - Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); - } + // IF( hCPE->hCoreCoder[n]->hHQ_core ) + //{ + // Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); + // } } @@ -654,7 +657,7 @@ ivas_error ivas_mct_dec_fx( /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; - mvl2l( output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_fx_, L_FRAME48k ); + Copy32( output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_fx_, L_FRAME48k ); Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); sts[n]->q_prev_synth_buffer_fx = 0; diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index 83c66b62e8284cda2b9309aadfaa25ec397a8f8a..29685d898c85cf9c9c892823571a64189ed0b5af 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -39,8 +39,7 @@ #include #include "stat_enc.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" /*----------------------------------------------------------* diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 72c1985d84ebafc165da12028d11da237b3fe4a3..ee7864a13e7153acab4a33a18ac4f573d2ab6967 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -45,11 +45,9 @@ #include "ivas_stat_com.h" #include #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#endif /*-----------------------------------------------------------------* @@ -150,6 +148,7 @@ void mdct_read_IGF_bits( } #endif + /*-----------------------------------------------------------------* * Function dec_prm_tcx_sidebits() * @@ -208,7 +207,7 @@ static void dec_prm_tcx_sidebits_fx( IF( ( ( st->last_core == ACELP_CORE ) && ( st->last_total_brate == FRAME_NO_DATA ) ) || st->prev_bfi ) { /* needed for cases where first TCX frame after a certain transition (e.g. inactive SID/zero frame -> active or stereo switching) is lost */ - st->last_core_from_bs = get_next_indice( st0, 1 ); + st->last_core_from_bs = get_next_indice_fx( st0, 1 ); move16(); /* ACELP -> TCX_10 transitions are forbidden */ @@ -221,7 +220,7 @@ static void dec_prm_tcx_sidebits_fx( } ELSE { - st->last_core = get_next_indice( st0, 1 ); + st->last_core = get_next_indice_fx( st0, 1 ); move16(); st->last_core_from_bs = st->last_core; move16(); @@ -234,16 +233,16 @@ static void dec_prm_tcx_sidebits_fx( move16(); IF( st->last_core_from_bs != ACELP_CORE ) { - st->hTcxDec->kernel_type[0] = get_next_indice( st0, 2 ); + st->hTcxDec->kernel_type[0] = get_next_indice_fx( st0, 2 ); } ELSE { - st->hTcxDec->kernel_type[0] = get_next_indice( st0, 1 ); + st->hTcxDec->kernel_type[0] = get_next_indice_fx( st0, 1 ); } move16(); IF( EQ_16( st->core, TCX_10_CORE ) ) { - st->hTcxDec->kernel_type[1] = add( shl( s_and( st->hTcxDec->kernel_type[0], 1 ), 1 ), get_next_indice( st0, 1 ) ); + st->hTcxDec->kernel_type[1] = add( shl( s_and( st->hTcxDec->kernel_type[0], 1 ), 1 ), get_next_indice_fx( st0, 1 ) ); move16(); } IF( EQ_16( st->core, TCX_20_CORE ) ) @@ -296,8 +295,7 @@ static void dec_prm_tcx_sidebits_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED +#else static void dec_prm_tcx_sidebits( int16_t param[], /* o : decoded parameters */ Decoder_State *st, /* i/o: decoder memory state */ @@ -398,11 +396,13 @@ static void dec_prm_tcx_sidebits( } #endif + /*-----------------------------------------------------------------* * Function dec_prm_tcx_spec() * * decode TCX core parameters *-----------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void dec_prm_tcx_spec_fx( Decoder_State *st, /* i/o: decoder memory state */ @@ -482,8 +482,7 @@ static void dec_prm_tcx_spec_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED +#else static void dec_prm_tcx_spec( Decoder_State *st, /* i/o: decoder memory state */ int16_t param[], /* o : decoded parameters */ @@ -545,6 +544,7 @@ static void dec_prm_tcx_spec( } #endif + /*-----------------------------------------------------------------* * Function ivas_mdct_dec_side_bits_frame_channel() * @@ -604,7 +604,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( st = sts[ch]; IF( MCT_flag ) { - tmp = get_next_indice( st0, 1 ); + tmp = get_next_indice_fx( st0, 1 ); IF( tmp ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; @@ -688,7 +688,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( FOR( Word16 n = 0; n < nSubframes; ++n ) { - param_lpc[0][n] = get_next_indice( st0, 1 ); + param_lpc[0][n] = get_next_indice_fx( st0, 1 ); move16(); } @@ -697,7 +697,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( { IF( EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ) { - param_lpc[0][n + ( SNS_STEREO_MODE_OFFSET_INDICES / 2 )] = get_next_indice( st0, 1 ); + param_lpc[0][n + ( SNS_STEREO_MODE_OFFSET_INDICES / 2 )] = get_next_indice_fx( st0, 1 ); move16(); } } @@ -784,14 +784,14 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( IF( ( ch == 0 ) || skipped_first_channel ) { /* read SNS stereo mode */ - param_lpc[0][0] = shl( (Word16) get_next_indice( st0, 1 ), 1 ); + param_lpc[0][0] = shl( (Word16) get_next_indice_fx( st0, 1 ), 1 ); /* read low br mode flag (if it is possible to be non-zero) */ test(); test(); IF( EQ_32( sts[0]->element_brate, IVAS_48k ) && !( EQ_16( sts[0]->core, TCX_20 ) && EQ_16( sts[1]->core, TCX_20 ) ) ) { - sns_low_br_mode = get_next_indice( st0, 1 ); + sns_low_br_mode = get_next_indice_fx( st0, 1 ); } } @@ -815,8 +815,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( return; } -#endif -#ifndef IVAS_FLOAT_FIXED +#else void ivas_mdct_dec_side_bits_frame_channel( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW], /* o : lpc_parameters */ @@ -848,16 +847,7 @@ void ivas_mdct_dec_side_bits_frame_channel( if ( MCT_flag ) { /* Initialization or re-configuration of Stereo TCX */ -#ifdef IVAS_FLOAT_FIXED - /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_init_dec_fx( sts[ch], 1, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); -#else stereo_tcx_init_dec( sts[ch], 1, hCPE->last_element_mode ); -#endif // IVAS_FLOAT_FIXED } sts[ch]->enablePlcWaveadjust = 0; } @@ -1018,11 +1008,13 @@ void ivas_mdct_dec_side_bits_frame_channel( } #endif + /*-----------------------------------------------------------------* * ivas_mdct_core_invQ() * * Inverse processing steps up to inverse quantization *-----------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_mdct_core_invQ_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ @@ -2131,7 +2123,7 @@ void ivas_mdct_core_reconstruct_fx( /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { - con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); + con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); } ELSE { @@ -2288,13 +2280,13 @@ void ivas_mdct_core_reconstruct_fx( #endif -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * ivas_mdct_core_tns_ns() * * reconstruct time signal *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_mdct_core_tns_ns( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t fUseTns[CPE_CHANNELS][NB_DIV], /* i : two entries for each channel in TCX10 */ @@ -2352,55 +2344,11 @@ void ivas_mdct_core_tns_ns( if ( !bfi ) { -#ifdef IVAS_FLOAT_FIXED - Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[SNS_NPTS]; - FOR( int c = 0; c < SNS_NPTS; c++ ) - { - Aq_fx[c] = (Word32) ( Aq[ch][k * M + c] * ONE_IN_Q16 ); - } - - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx, DEC ); - - FOR( int c = 0; c < FDNS_NPTS; c++ ) - { - sns_int_scf[c] = ( (float) sns_int_scf_fx[c] / ONE_IN_Q16 ); - } -#else sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#endif // IVAS_FLOAT_FIXED if ( MCT_flag && st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[N_MAX]; - Word16 x_e, scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; - f2me_buf( x[ch][k], x_fx, &x_e, L_frameTCX[ch] ); - /*for ( int j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) - { - f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); - }*/ - Word16 q_shift; - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - q_shift = norm_l( sns_int_scf_fx[ind] ); - scf_fx[ind] = extract_h( L_shl( sns_int_scf_fx[ind], q_shift ) ); - scf_e[ind] = 15 - q_shift; - } - /*float maxim = 0; - FOR(Word16 ind = 0; ind < L_frameTCX[ch]; ind++) { - maxim = fmaxf(maxim, fabsf(x[ch][k][ind])); - } - if (maxim >= 1) q_x = norm_l((Word32)maxim); - FOR(Word16 ind = 0; ind < L_frameTCX[ch]; ind++) { - x_fx[ind] = (Word32)(x[ch][k][ind] * (1 << q_x)); - } - x_e = 31 - q_x;*/ - - TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); -#else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); -#endif } } else @@ -2409,6 +2357,7 @@ void ivas_mdct_core_tns_ns( { if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float < 0.99f ) // if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float != 1.f ) + { float *scf_last, *scf_bg; float fade_in, fade_out; @@ -2434,66 +2383,9 @@ void ivas_mdct_core_tns_ns( } } -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx_[1200]; - Word16 q = 26; - float maximum = 0; - FOR( Word16 ind = 0; ind < st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0]; ind++ ) - maximum = fmaxf( maximum, fabsf( x[ch][k][ind] ) ); - if ( maximum >= 1.f ) - q = norm_l( (Word32) maximum ) - 5; - FOR( Word16 ind = 0; ind < s_max( s_max( L_frameTCX[ch], L_spec[ch] ), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0] ); ind++ ) - x_fx_[ind] = (Word32) ( x[ch][k][ind] * ( 1 << q ) ); - decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx_, fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); - FOR( Word16 ind = 0; ind < s_max( s_max( L_frameTCX[ch], L_spec[ch] ), st->hTcxCfg->pCurrentTnsConfig->iFilterBorders[0] ); ind++ ) - x[ch][k][ind] = (float) ( x_fx_[ind] ) / (float) ( 1 << q ); -#else decoder_tcx_tns( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); -#endif - -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx[L_FRAME48k], sns_int_scf_fx[FDNS_NPTS]; - Word16 q_x = 31, q_sns_int_scf = 31; - FOR( Word16 c = 0; c < L_FRAME16k; c++ ) - { - if ( abs( (Word32) x[ch][k][c] ) != 0 ) - q_x = s_min( q_x, norm_l( (Word32) x[ch][k][c] ) ); - } - FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) - { - if ( abs( (Word32) sns_int_scf[c] ) != 0 ) - q_sns_int_scf = s_min( q_sns_int_scf, norm_l( (Word32) sns_int_scf[c] ) ); - } - q_x -= 1; - q_sns_int_scf -= 1; - FOR( Word16 c = 0; c < st->hTcxCfg->psychParamsCurrent->nBins; c++ ) - { - x_fx[c] = (Word32) ( x[ch][k][c] * ( 1 << q_x ) ); - } - FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) - { - sns_int_scf_fx[c] = (Word32) ( sns_int_scf[c] * ( 1 << q_sns_int_scf ) ); - } - sns_shape_spectrum_fx( x_fx, &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins ); - - IF( q_x + 1 < 31 ) - { - FOR( Word16 c = 0; c < st->hTcxCfg->psychParamsCurrent->nBins; c++ ) - { - x[ch][k][c] = ( (float) x_fx[c] / ( 1 << ( q_x + 1 ) ) ); - } - } - ELSE - { - FOR( Word16 c = 0; c < st->hTcxCfg->psychParamsCurrent->nBins; c++ ) - { - x[ch][k][c] = ( (float) x_fx[c] / ONE_IN_Q31 ); - } - } -#else sns_shape_spectrum( x[ch][k], st->hTcxCfg->psychParamsCurrent, &sns_int_scf[0], st->hTcxCfg->psychParamsCurrent->nBins ); -#endif // IVAS_FLOAT_FIXED v_multc( x[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf[FDNS_NPTS - 1], x[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins ); decoder_tcx_tns( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0 ); @@ -2512,8 +2404,7 @@ void ivas_mdct_core_tns_ns( return; } -#endif -#ifdef IVAS_FLOAT_FIXED +#else /* Has a missing dependency: TonalMDCTConceal_Apply. Currently not used anywhere and untested.*/ void ivas_mdct_core_tns_ns_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -2537,7 +2428,7 @@ void ivas_mdct_core_tns_ns_fx( Word16 left_rect[CPE_CHANNELS]; Word16 L_spec[CPE_CHANNELS]; Word32 sns_int_scf_fx[FDNS_NPTS]; - Word16 exp; + Word16 exp, length; /* Initializations */ sts = hCPE->hCoreCoder; @@ -2638,7 +2529,7 @@ void ivas_mdct_core_tns_ns_fx( FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_add( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), Mpy_32_16_1( L_shl( scf_bg[i], 1 ), fade_in ) ); + sns_int_scf_fx[i] = Madd_32_16( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), L_shl( scf_bg[i], 1 ), fade_in ); move32(); } } @@ -2656,16 +2547,28 @@ void ivas_mdct_core_tns_ns_fx( } Word16 norm_x; q_x = sub( q_x, 5 ); - Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); - decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); - norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); - Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); + length = L_frameTCX[ch]; + move16(); + test(); + test(); + test(); + test(); + test(); + if ( EQ_16( L_frame[ch], shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && ( ( NE_16( st->hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns[ch][k], 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec[ch], L_frameTCX[ch] ) ) ) + { + length = L_spec[ch]; + move16(); + } + Scale_sig32( &x_fx[ch][k][0], length, -5 ); + decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1, &length ); + norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); + Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); x_e[ch][k] = sub( 31, q_x ); move16(); Word16 q_sns_int_scf; - Word16 q_2, length; + Word16 q_2; q_sns_int_scf = add( 16 - 1, getScaleFactor32( sns_int_scf_fx, FDNS_NPTS ) ); // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) @@ -2700,10 +2603,22 @@ void ivas_mdct_core_tns_ns_fx( move16(); q_x = sub( q_x, 5 ); - Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); - decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0 ); - norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); - Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); + length = L_frameTCX[ch]; + move16(); + test(); + test(); + test(); + test(); + test(); + if ( EQ_16( L_frame[ch], shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && ( ( NE_16( st->hTcxCfg->fIsTNSAllowed, 0 ) && NE_16( fUseTns[ch][k], 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec[ch], L_frameTCX[ch] ) ) ) + { + length = L_spec[ch]; + move16(); + } + Scale_sig32( &x_fx[ch][k][0], length, -5 ); + decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0, &length ); + norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); + Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); x_e[ch][k] = sub( 31, q_x ); move16(); diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 892298f1c8c9164f55a6a0cfd1ab241faccff4e5..fabd897f50f26fb2238b9deecbc18ad7d80e39ae 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -35,8 +35,7 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 51cf795b303fa6f2ffc22221f33c24c7be52f648..d6f965c8fc206980724099fb5392bc21c76983b9 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -40,8 +40,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index f376e8d7e1e6e27f4ac2b0b2937efe19a2cb1474..bc136eb1a8586a8be89073c19a800161ba8355da 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -40,7 +40,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "math.h" // temporary (for fabs) #endif diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index 47d3ee5ecc40b43dcf532124695eb249b1b6ce39..4c8c8103eee490879f406e82e30ca9cecc86464d 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -40,9 +40,8 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 60f3f81580c673743f0dc80c52e491de03e3a666..2764b640b3a9af0f5a8132585ac15530026567cc 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -41,8 +41,7 @@ #include "ivas_rom_rend.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -1691,11 +1690,13 @@ void ivas_ls_setup_conversion_process_mdct( } #endif + /*------------------------------------------------------------------------- * ivas_ls_setup_conversion_process_mdct_param_mc() * * Equalization in MDCT Domain *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_ls_setup_conversion_process_mdct_param_mc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -2076,7 +2077,6 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( return; } #else - void ivas_ls_setup_conversion_process_mdct_param_mc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *x[][NB_DIV] /* i/o: output synthesis signal */ @@ -2238,49 +2238,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } } -#ifdef IVAS_FLOAT_FIXED - Word32 real_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS]; - Word32 imag_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * PARAM_MC_BAND_TO_MDCT_BAND_RATIO * MAX_TRANSPORT_CHANNELS]; - Word32 real_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 imag_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word16 real_exp, imag_exp, input_exp, output_exp; - Word16 shift = find_guarded_bits_fx( num_bands + 1 ); - - f2me_buf( real_in_buffer, real_in_buffer_fx, &real_exp, num_bands * nchan_transport ); - f2me_buf( imag_in_buffer, imag_in_buffer_fx, &imag_exp, num_bands * nchan_transport ); - - IF( real_exp > imag_exp ) - { - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], real_exp - imag_exp ); - } - input_exp = real_exp; - } - ELSE - { - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], imag_exp - real_exp ); - } - input_exp = imag_exp; - } - - FOR( i = 0; i < num_bands * nchan_transport; ++i ) - { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], shift ); - } - - input_exp += shift; - - cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_transport, real_buffer_fx, imag_buffer_fx, input_exp, &output_exp ); - - me2f_buf( real_buffer_fx, output_exp, real_buffer, nchan_transport * nchan_transport ); - me2f_buf( imag_buffer_fx, output_exp, imag_buffer, nchan_transport * nchan_transport ); -#else cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_transport, real_buffer, imag_buffer ); -#endif v_add( cx[bandIdx], real_buffer, cx[bandIdx], nchan_transport * nchan_transport ); @@ -2446,6 +2404,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } #endif + /*------------------------------------------------------------------------- * ivas_ls_setup_conversion_process_param_mc() * diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 40052469b6fd0d01719718c35de10cfc0c8f8fb7..7dd2e334c09251ae4c900102458e07e262057dd4 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -38,7 +38,7 @@ #include #include "ivas_cnst.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "math.h" /*-----------------------------------------------------------------------* diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index 694bc53201e4d7faee0fa1d3ddf552b1f9e94375..ed7cc13c4d7b7677f1345f3afd42810f9b797f38 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -36,8 +36,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" @@ -199,7 +198,7 @@ void ivas_post_proc_fx( ELSE { /* set delay */ - delay_comp = NS2SA_fx2( output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); move16(); test(); @@ -213,12 +212,12 @@ void ivas_post_proc_fx( } ELSE IF( sba_dirac_stereo_flag && EQ_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { - Word16 numZeros = (Word16) ( NS2SA_fx2( output_Fs, N_ZERO_MDCT_NS ) ); + Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); move16(); Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); } - tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_fx2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32 ); + tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32 ); } } } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 7332f26f16b6c4f76311d2960c8b87d0d122c3aa..2d20ed6898bfb2381675c8d88ac47e22b75929e9 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -41,8 +41,7 @@ #include "wmc_auto.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" @@ -1709,16 +1708,20 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); + move32(); + } + } #else FOR( b = 0; b < MASA_MAXIMUM_CODING_SUBBANDS; b++ ) { FOR( m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES; m++ ) { -#endif // MSAN_FIX hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); move32(); } } +#endif // MSAN_FIX IF( EQ_32( hQMetaData->no_directions, 2 ) ) { #ifdef MSAN_FIX @@ -1726,16 +1729,20 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); + move32(); + } + } #else FOR( b = 0; b < MASA_MAXIMUM_CODING_SUBBANDS; b++ ) { FOR( m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES; m++ ) { -#endif // MSAN_FIX hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); move32(); } } +#endif // MSAN_FIX } /* Store status information for renderer use */ hQMetaData->ec_flag = 0; @@ -7366,7 +7373,7 @@ static Word16 read_coherence_data_fx( nbits = add( nbits, no_bits_vec ); - set_s( (Word16 *) spr_coh_temp_index, 0, MASA_MAXIMUM_CODING_SUBBANDS ); + set16_fx( (Word16 *) spr_coh_temp_index, 0, MASA_MAXIMUM_CODING_SUBBANDS ); decode_combined_index_fx( dct0_index, no_cv_vec, spr_coh_temp_index, coding_subbands ); @@ -8314,7 +8321,7 @@ static Word16 read_surround_coherence_hr_fx( { /* fixed rate */ UWord16 sur_coh_temp_index[MASA_MAXIMUM_CODING_SUBBANDS]; - set_s( (Word16 *) sur_coh_temp_index, 0, MASA_MAXIMUM_CODING_SUBBANDS ); + set16_fx( (Word16 *) sur_coh_temp_index, 0, MASA_MAXIMUM_CODING_SUBBANDS ); decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, sur_coh_temp_index, MASA_MAX_NO_CV_SUR_COH ); diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 395a0654c11085c226771b4546c7b66e17f0841b..2f93698054b1c23577f1f2cd640707e03ec80883 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -220,22 +220,28 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( UWord32 reversed_low; low = rc_st_dec->rc_low; + move32(); range = rc_st_dec->rc_range; + move32(); // Not converted , to be rechecked(Value of range exceeds Word32) - range >>= tot_shift; + range = UL_lshr( range, tot_shift ); /* the cumulative value is val = low / range */ /* the condition val >= level is equivalent with low >= range * level */ /* in case of bitstream errors it is possible that val >= (1 << tot_shift) */ - IF( low >= ( range << tot_shift ) ) + /*basop comment : unsigned integers are getting compared hence basops are not used*/ + IF( low >= UL_lshl( range, tot_shift ) ) { rc_st_dec->bit_error_detected = 1; + move16(); /* for valid bitstreams, always low < range, therefore setting low = range */ /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; + move32(); rc_st_dec->rc_low = rc_st_dec->rc_range; + move32(); /* the current value and all the following values are very likely incorrect */ return 0; /* return the minimum valid value for the output */ @@ -243,13 +249,15 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* do a binary search to find the symbol read */ sym_begin = 0; + move16(); sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} */ + move16(); /* ceil(log2(x)) = 1 + floor(log2(x - 1)), for any x >= 2 */ /* floor(log2(y)) = 31 - norm_ul_float(y) = 30 - norm_l(y), for any 1 <= y <= 2 ^ 31 - 1 */ - ceil_log2_alphabet_size = sub( 31, norm_l( alphabet_size - 1 ) ); + ceil_log2_alphabet_size = sub( 31, norm_l( UL_subNsD( alphabet_size, 1 ) ) ); /* completely equivalent with 32 - norm_ul_float(alphabet_size - 1), but norm_l is faster */ - reversed_low = ( range << tot_shift ) - low; + reversed_low = UL_subNsD( UL_lshl( range, tot_shift ), low ); /* at most ceil_log2_alphabet_size steps are needed so that sym_end - sym_begin == 1 */ FOR( step = 0; step < ceil_log2_alphabet_size; step++ ) @@ -259,10 +267,12 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( IF( range * L_sub( L_shl( 1, tot_shift ), cum_freq_table[sym_middle] ) >= reversed_low ) { sym_begin = sym_middle; + move16(); } ELSE { sym_end = sym_middle; + move16(); } } @@ -270,6 +280,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* low was not modified */ rc_st_dec->rc_range = range; + move32(); rc_uni_dec_update_fx( rc_st_dec, cum_freq_table[sym_begin], sym_freq_table[sym_begin] ); @@ -314,18 +325,19 @@ static void rc_uni_dec_update_fx( ) { // Not adding basop because the value of rc_st_dec->rc_range exceeds Word32 - rc_st_dec->rc_low -= cum_freq * rc_st_dec->rc_range; + rc_st_dec->rc_low = UL_subNsD( rc_st_dec->rc_low, cum_freq * rc_st_dec->rc_range ); rc_st_dec->rc_range *= sym_freq; + move16(); /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ IF( rc_st_dec->rc_range < 0x01000000 ) { - rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); - rc_st_dec->rc_range <<= 8; + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); IF( rc_st_dec->rc_range < 0x01000000 ) { - rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); - rc_st_dec->rc_range <<= 8; + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); } } @@ -338,6 +350,65 @@ static void rc_uni_dec_update_fx( *-------------------------------------------------------------------*/ /*! r: Read bit */ +#ifdef IVAS_FLOAT_FIXED +UWord16 rc_uni_dec_read_bit( + RangeUniDecState *rc_st_dec /* i/o: RC State handle */ +) +{ + UWord32 val; + UWord32 low; /* local copy (1 to 5 uses) */ + UWord32 range; /* local copy (3 to 6 uses) */ + + low = rc_st_dec->rc_low; + move32(); + range = rc_st_dec->rc_range; + move32(); + + range = UL_lshr( range, 1 ); + + /* in case of bitstream errors it is possible that rc_low >= (rc_range << 1) */ + val = 0; + move32(); + /*basop comment : comparision of unsigned integers hence basops are not used*/ + IF( low >= range ) + { + val = UL_addNsD( val, 1 ); + low = UL_subNsD( low, range ); + + /* rc_range was already subtracted once from rc_low */ + IF( low >= range ) + { + rc_st_dec->bit_error_detected = 1; + move16(); + + /* for valid bitstreams, always low < range, therefore setting low = range */ + /* will always reach the bitstream error condition branch on the next call */ + rc_st_dec->rc_range = 0xFFFFFFFF; + move32(); + rc_st_dec->rc_low = rc_st_dec->rc_range; + move32(); + + /* the current value and all the following values are very likely incorrect */ + return 0; /* return the minimum valid value for the output */ + } + } + + /* rc_range was shifted right by 1, so at most one renormalization is needed */ + /*basop comment : comparision of unsigned integers hence basops are not used*/ + IF( range < 0x01000000 ) + { + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read( rc_st_dec ) ); + range = UL_lshl( range, 8 ); + } + + rc_st_dec->rc_low = low; + move32(); + rc_st_dec->rc_range = range; + move32(); + + return (UWord16) val; +} +#else uint16_t rc_uni_dec_read_bit( RangeUniDecState *rc_st_dec /* i/o: RC State handle */ ) @@ -385,6 +456,7 @@ uint16_t rc_uni_dec_read_bit( return (uint16_t) val; } +#endif /*-------------------------------------------------------------------* @@ -394,6 +466,80 @@ uint16_t rc_uni_dec_read_bit( *-------------------------------------------------------------------*/ /*! r: Read bit */ +#ifdef IVAS_FLOAT_FIXED +UWord16 rc_uni_dec_read_bit_prob_fast( + RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ + const Word16 freq0, /* i : Frequency for symbol 0 */ + const UWord16 tot_shift /* i : Total frequency as a power of 2 */ +) +{ + UWord32 val; + UWord32 low; /* local copy (2 to 7 uses) */ + UWord32 range; /* local copy (5 to 9 uses) */ + + low = rc_st_dec->rc_low; + move32(); + range = rc_st_dec->rc_range; + move32(); + + range = UL_lshr( range, tot_shift ); + + /* in case of bitstream errors it is possible that low >= (1 << tot_shift) * range */ + /*basop comment : unsigned integers are getting compared hence basops are not used*/ + IF( low >= UL_lshl( range, tot_shift ) ) /* equivalent condition */ + { + rc_st_dec->bit_error_detected = 1; + move16(); + + /* for valid bitstreams, always low < range, therefore setting low = range */ + /* will always reach the bitstream error condition branch on the next call */ + rc_st_dec->rc_range = 0xFFFFFFFF; + move32(); + rc_st_dec->rc_low = rc_st_dec->rc_range; + move32(); + + /* the current value and all the following values are very likely incorrect */ + return 0; /* return the minimum valid value for the output */ + } + + val = 0; + move32(); + /*basop comment : unsigned comparision and multiplication of unsigned and signed hence basops are not used*/ + IF( low >= range * freq0 ) + { + val = UL_addNsD( val, 1 ); + + low = UL_subNsD( low, range * freq0 ); + /*basop comment : multiplication of two unsigned integers and result is stored in unsigned hence basops are not used*/ + range *= UL_subNsD( UL_lshl( 1, tot_shift ), freq0 ); /* freq1 = (1 << tot_shift) - freq0 */ + } + ELSE + { + /* basop comment : multiplication of two unsigned integers and result is stored in unsigned integer hence basops are not used*/ + range *= freq0; + } + + /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ + /*basop comment : comparision of unsigned integers hence basops are not used*/ + IF( range < 0x01000000 ) + { + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read( rc_st_dec ) ); + range = UL_lshl( range, 8 ); + IF( range < 0x01000000 ) + { + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read( rc_st_dec ) ); + range = UL_lshl( range, 8 ); + } + } + + rc_st_dec->rc_low = low; + move32(); + rc_st_dec->rc_range = range; + move32(); + + return (UWord16) val; +} +#else uint16_t rc_uni_dec_read_bit_prob_fast( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ const int16_t freq0, /* i : Frequency for symbol 0 */ @@ -453,6 +599,7 @@ uint16_t rc_uni_dec_read_bit_prob_fast( return (uint16_t) val; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 8933057bdcd71312466b8a650d63c8d3fee24693..6ed2b922a9720e59835195716440a94c1d967db5 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -43,7 +43,7 @@ #include #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * ivas_sba_set_cna_cng_flag() * @@ -883,7 +883,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered; move16(); - mvs2s( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } ELSE IF( st_ivas->hSpatParamRendCom != NULL ) { @@ -895,7 +895,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; move16(); - mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } @@ -926,7 +926,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) { - ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); + ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ), IVAS_ERR_OK ) ) { @@ -959,7 +959,11 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_pca_dec_init_fx( hSpar->hPCA ); } +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#else ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif } ELSE { @@ -1321,13 +1325,13 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) { - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; move16(); st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; move16(); } - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes; move16(); st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; @@ -1566,12 +1570,10 @@ void ivas_sba_dec_digest_tc( { #ifndef IVAS_FLOAT_FIXED ivas_td_decorr_process( st_ivas->hDiracDecBin->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr ); -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING for ( i = 0; i < st_ivas->hDiracDecBin->hTdDecorr->num_apd_outputs; i++ ) { -#ifdef DUMPS_ENABLED dbgwrite_txt( decorr_signal[i], nSamplesToDecorr, "fixed.txt", NULL ); -#endif } #endif #else @@ -1601,7 +1603,7 @@ void ivas_sba_dec_digest_tc( { decorr_signal[i][j] = ( decorr_signal_fx[i][j] ) / (float) ( 1 << q_format ); } -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING dbgwrite_txt( decorr_signal[i], nSamplesToDecorr, "fixed.txt", NULL ); #endif } @@ -1801,7 +1803,7 @@ ivas_error ivas_sba_dec_render_fx( output_f_local_fx[ch] = output_fx[ch]; } - slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 2ad1c081be820629d4cf4f70e67a010578aaf974..1088e44c0ed320a3df6a8532e3f6d322ac4dec23 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -34,8 +34,7 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" @@ -720,7 +719,7 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( } ELSE { - set_val_Word32( hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, 0, output_frame ); + set32_fx( hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, 0, output_frame ); #ifdef MSAN_FIX hStereoDft->hb_nrg_subr_fx[0] = 0; move32(); @@ -1245,16 +1244,16 @@ void ivas_sba_dirac_stereo_dec_fx( move16(); #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); #else - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); #else - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); @@ -1318,7 +1317,7 @@ void ivas_sba_dirac_stereo_dec_fx( IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) { - set_val_Word32( hStereoDft->res_pred_gain_fx, MAX_32, 3 * STEREO_DFT_BAND_MAX ); + set32_fx( hStereoDft->res_pred_gain_fx, MAX_32, 3 * STEREO_DFT_BAND_MAX ); } /* DFT Stereo upmix */ @@ -1378,20 +1377,20 @@ void ivas_sba_dirac_stereo_dec_fx( /* reset the other channels to 0 (they are not used since here) */ FOR( Word16 ch = CPE_CHANNELS; ch < st_ivas->nchan_transport; ch++ ) { - set_val_Word32( output[ch], 0, output_frame ); + set32_fx( output[ch], 0, output_frame ); } #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); #else - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); #else - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX hSCE->q_prev_hb_synth_fx = Q11; move16(); diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index e925bd3e6e582f27be15571d709ba299a16b06b9..0ef56c856ea4389e20bdb7dd15167bd77efa766d 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -41,12 +41,11 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED -#ifdef DUMPS_ENABLED +#include "prot_fx.h" +#endif +#ifdef DEBUGGING #include "debug.h" -#endif // DUMPS_ENABLED - +#endif /*-------------------------------------------------------------------------* * ivas_sba2MC_cldfb() @@ -145,8 +144,8 @@ void ivas_sba2mc_cldfb_fixed( FOR( n = 0; n < nb_channels_out; n++ ) { - set_l( realOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); - set_l( imagOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); + set32_fx( realOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); + set32_fx( imagOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); FOR( m = 0; m < nb_channels_in; m++ ) { @@ -655,6 +654,17 @@ void ivas_ism2sba_sf_fx( move32(); prev_gain_fx = hIsmRendererData->prev_gains_fx[i][j]; move32(); +#ifdef IVAS_ENH32_CADENCE_CHANGES + FOR( k = 0; k < n_samples_to_render; k++ ) + { + g1_fx = sub( 32767, *g2_fx ); + *( out_fx ) = Madd_32_32( *( out_fx ), Madd_32_16( Mult_32_16( gain_fx, ( *( g2_fx ) ) ), prev_gain_fx, g1_fx ), ( *( tc_fx ) ) ); /*Q_buffer_in + 29 - 31*/ + move32(); + g2_fx++; + tc_fx++; + out_fx++; + } +#else FOR( k = 0; k < n_samples_to_render; k++ ) { g1_fx = sub( 32767, *g2_fx ); @@ -664,6 +674,7 @@ void ivas_ism2sba_sf_fx( tc_fx++; out_fx++; } +#endif } } FOR( j = 0; j < sba_num_chans; j++ ) @@ -861,7 +872,7 @@ void ivas_sba_mix_matrix_determiner_fx( const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ - const Word16 Q_output /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ ) { Word16 i, ch; @@ -899,16 +910,17 @@ void ivas_sba_mix_matrix_determiner_fx( nchan_out = nchan_transport; move16(); ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED + Q_p_output = sub( Q_p_output, 3 ); +#ifdef DEBUGGING + dbgwrite_txt( (const float *) ( output_fx[0] ), output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); +#endif /* Convert numeric range back */ FOR( ch = 0; ch < nchan_out; ch++ ) { FOR( i = 0; i < output_frame; i++ ) { - output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 18, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /*Q-0*/ + output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 15, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /* Q0 */ } } diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 7c30d30328c77caebe7c29333fbffaa7935ccb1d..8c2ee04ba43e3e3ce1b7f2faace2505513451799 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -37,8 +37,7 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 78ce1a71ab3f75504ae36c46a077ba6c724a0d5b..9d33f6dd74e679906d8c58e87b2a47e873a85a2e 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -38,8 +38,7 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" @@ -147,13 +146,13 @@ ivas_error ivas_sce_dec_fx( ( LT_32( hSCE->element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) { /* WB and SWB are supported */ - st->bwidth = add( get_next_indice( st, 1 ), WB ); + st->bwidth = add( get_next_indice_fx( st, 1 ), WB ); move16(); } ELSE { /* WB, SWB and FB are supported */ - st->bwidth = get_next_indice( st, NBITS_BWIDTH ); + st->bwidth = get_next_indice_fx( st, NBITS_BWIDTH ); move16(); } } @@ -298,7 +297,7 @@ ivas_error ivas_sce_dec_fx( set32_fx( output[0], 0, L_FRAME48k ); - IF( NE_32( ( error = ivas_core_dec( st_ivas, hSCE, NULL, NULL, 1, output, outputHB, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_dec_fx( st_ivas, hSCE, NULL, NULL, 1, output, outputHB, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -321,13 +320,13 @@ ivas_error ivas_sce_dec_fx( * LB synthesis synchronization between IVAS formats *----------------------------------------------------------------*/ - delay_signal_fx( output[0], output_frame, st->prev_synth_buffer32_fx, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + delay_signal_fx( output[0], output_frame, st->prev_synth_buffer32_fx, NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); /*----------------------------------------------------------------* * HB synthesis synchronization between IVAS formats *----------------------------------------------------------------*/ - delay_signal_fx( outputHB[0], output_frame, hSCE->prev_hb_synth_fx, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); + delay_signal_fx( outputHB[0], output_frame, hSCE->prev_hb_synth_fx, NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); /*----------------------------------------------------------------* * output LB and HB mix @@ -391,7 +390,7 @@ ivas_error create_sce_dec( hSCE->element_brate = element_brate; move32(); - set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); + set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index f240029b3e17df8949b83c1379a700dee9283459..ff96b6c0611fd85938f3069d9f47b21a1d8f9c2c 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -40,8 +40,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index f18e474e4faa9b20c7e2c05e0bea0f9ea04f49b3..7186d031a0c96af22b7d67fb857cef7304861ee1 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -31,10 +31,11 @@ *******************************************************************************************************/ #include +#include +#include #include "options.h" #include "ivas_stat_dec.h" #include "prot.h" -#include "prot_fx2.h" #include "string.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" @@ -42,18 +43,14 @@ #include "ivas_rom_dec.h" #include "ivas_stat_com.h" #include "stat_com.h" -#include -#include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED -#ifdef DUMPS_ENABLED +#endif +#ifdef DEBUGGING #include "debug.h" -#endif // DUMPS_ENABLED - +#endif /*-------------------------------------------------------------------* * Local function prototypes @@ -66,13 +63,13 @@ static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 #endif -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_spar_dec_open() * * Allocate and initialize SPAR decoder handle and sub-handles *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_dec_open( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ @@ -280,222 +277,250 @@ ivas_error ivas_spar_dec_open( #else ivas_error ivas_spar_dec_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { SPAR_DEC_HANDLE hSpar; ivas_error error; - int16_t sba_order_internal, num_channels_internal; + Word16 sba_order_internal, num_channels_internal; IVAS_FB_CFG *fb_cfg; - int16_t i, j, b, active_w_mixing; - int32_t output_Fs; - int16_t num_decor_chs, map_idx; + Word16 i, j, b, active_w_mixing; + Word32 output_Fs; + Word16 num_decor_chs, map_idx; error = IVAS_ERR_OK; + move32(); sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + move16(); num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); hSpar = st_ivas->hSpar; - if ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { /* SPAR decoder handle */ - if ( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) + IF( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); } } output_Fs = st_ivas->hDecoderConfig->output_Fs; - if ( num_channels_internal > ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) + move32(); + IF( GT_16( num_channels_internal, ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) ) { num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; + move16(); } - else + ELSE { - num_decor_chs = num_channels_internal - 1; + num_decor_chs = sub( num_channels_internal, 1 ); } /* TD decorr. */ - if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_256k && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) ) ) + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) || ( GE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_256k ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) ) ) { hSpar->hTdDecorr = NULL; } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_td_decorr_dec_open_fx( &hSpar->hTdDecorr, output_Fs, num_decor_chs + 1, 1 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_decor_chs + 1, 1 ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_td_decorr_dec_open_fx( &hSpar->hTdDecorr, output_Fs, add( num_decor_chs, 1 ), 1 ) ), IVAS_ERR_OK ) ) { return error; } } /* MD handle */ - if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal, st_ivas->sid_format, st_ivas->last_active_ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal, st_ivas->sid_format, st_ivas->last_active_ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } hSpar->hMdDec->td_decorr_flag = 1; + move16(); if ( hSpar->hTdDecorr ) { hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; + move16(); } /* set FB config. */ active_w_mixing = -1; - if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs, 0 ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs, 0 ) ), IVAS_ERR_OK ) ) { return error; } fb_cfg->pcm_offset = NS2SA( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + move16(); fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + move16(); /* FB mixer handle */ -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_FB_mixer_open_fx( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_FB_mixer_open_fx( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ), IVAS_ERR_OK ) ) { return error; } -#else - if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif /* 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 + IF( NE_32( ( error = ivas_spar_agc_dec_open_fx( &hSpar->hAgcDec, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } /* PCA handle */ hSpar->hPCA = NULL; - if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) + test(); + IF( EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( sba_order_internal, 1 ) ) { - if ( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); } - // ivas_pca_dec_init( hSpar->hPCA ); -#ifdef IVAS_FLOAT_FIXED ivas_pca_dec_init_fx( hSpar->hPCA ); -#endif } /* mixer_mat intitialization */ - for ( i = 0; i < num_channels_internal; i++ ) + FOR( i = 0; i < num_channels_internal; i++ ) { - for ( j = 0; j < num_channels_internal; j++ ) + FOR( j = 0; j < num_channels_internal; j++ ) { - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { hSpar->hMdDec->mixer_mat_fx[i][j][b] = 0; - for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + move32(); + FOR( Word16 i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) { hSpar->hMdDec->mixer_mat_prev_fx[i_ts][i][j][b] = 0; + move32(); } } } } hSpar->i_subframe = 0; + move16(); hSpar->AGC_flag = 0; + move16(); /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#else ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif - switch ( sba_order_internal ) + SWITCH( sba_order_internal ) { case 1: st_ivas->transport_config = IVAS_AUDIO_CONFIG_FOA; - break; + move32(); + BREAK; case 2: st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA2; - break; + move32(); + BREAK; case 3: st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA3; - break; + move32(); + BREAK; } ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); - set_s( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + set16_fx( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + move16(); hSpar->subframes_rendered = 0; + move16(); hSpar->slots_rendered = 0; + move16(); hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); /* init render timeslot mapping */ - set_s( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ ) + set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + FOR( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ ) { hSpar->render_to_md_map[map_idx] = map_idx; + move16(); } /* allocate transport channels*/ - if ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { - int16_t nchan_to_allocate; - int16_t nchan_tc; + Word16 nchan_to_allocate; + Word16 nchan_tc; TC_BUFFER_MODE buffer_mode; - int16_t granularity; + Word16 granularity; buffer_mode = TC_BUFFER_MODE_RENDERER; + move32(); nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); nchan_to_allocate = num_channels_internal; + move16(); - if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + if ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - nchan_to_allocate += st_ivas->nchan_ism; + nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); } granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + move16(); - if ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) ) + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) { - if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + test(); + IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - nchan_tc = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; + nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); nchan_to_allocate = nchan_tc; + move16(); } - else + ELSE { buffer_mode = TC_BUFFER_MODE_BUFFER; + move32(); nchan_tc = st_ivas->hDecoderConfig->nchan_out; + move16(); nchan_to_allocate = nchan_tc; + move16(); } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { nchan_to_allocate = 2 * BINAURAL_CHANNELS; + move16(); } - if ( st_ivas->ivas_format == SBA_ISM_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */ - granularity = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); + Word32 quo, rem; + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &quo, &rem, 0 ); + granularity = extract_l( quo ); + move16(); } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -507,12 +532,14 @@ ivas_error ivas_spar_dec_open_fx( } #endif + /*------------------------------------------------------------------------- * ivas_spar_dec_close() * * Deallocate SPAR handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_close( SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ const int32_t output_Fs, /* i : output sampling rate */ @@ -531,18 +558,10 @@ void ivas_spar_dec_close( ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr ); /* FB mixer handle */ -#ifdef IVAS_FLOAT_FIXED - ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); -#else ivas_FB_mixer_close( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); -#endif /* 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 ) @@ -559,6 +578,47 @@ void ivas_spar_dec_close( return; } +#else +void ivas_spar_dec_close_fx( + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +) +{ + test(); + IF( hSpar == NULL || *hSpar == NULL ) + { + return; + } + + /* MD handle */ + ivas_spar_md_dec_close( &( *hSpar )->hMdDec ); + + /* TD decorrelator handle */ + ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr ); + + /* FB mixer handle */ + ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); + + /* AGC */ + ivas_spar_agc_dec_close_fx( &( *hSpar )->hAgcDec ); + + /* PCA */ + IF( ( *hSpar )->hPCA != NULL ) + { + free( ( *hSpar )->hPCA ); + ( *hSpar )->hPCA = NULL; + } + + IF( !spar_reconfig_flag ) + { + free( ( *hSpar ) ); + ( *hSpar ) = NULL; + } + + return; +} +#endif /*-------------------------------------------------------------------* @@ -579,20 +639,31 @@ ivas_error ivas_spar_dec_fx( Word16 next_bit_pos_orig, last_bit_pos; UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; ivas_error error; + Word32 quo, rem; push_wmops( "ivas_spar_decode" ); error = IVAS_ERR_OK; + move32(); hDecoderConfig = st_ivas->hDecoderConfig; - st0 = GT_16( st_ivas->nSCE, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + st0 = NULL; + IF( st_ivas->nSCE > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } + bit_stream_orig = st0->bit_stream; - move16(); next_bit_pos_orig = st0->next_bit_pos; move16(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - last_bit_pos = sub( extract_l( L_sub( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ), 1 ) ), nb_bits_read[1] ); + iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); } ELSE { @@ -610,15 +681,17 @@ ivas_error ivas_spar_dec_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - last_bit_pos = sub( extract_l( L_sub( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ), 1 ) ), nb_bits_read[1] ); + iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); } ELSE { - last_bit_pos = extract_l( L_sub( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ), 1 ) ); + iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + last_bit_pos = extract_l( L_sub( quo, 1 ) ); } test(); - IF( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) + if ( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); } @@ -629,16 +702,16 @@ ivas_error ivas_spar_dec_fx( /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; + bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; move16(); } st0->bit_stream = bstr_meta; - move16(); st0->next_bit_pos = 0; move16(); st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); + move16(); - IF( !st0->bfi ) + if ( !st0->bfi ) { st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ move32(); @@ -648,22 +721,27 @@ ivas_error ivas_spar_dec_fx( * Decode SPAR metadata *---------------------------------------------------------------------*/ - IF( ( error = ivas_spar_dec_MD_fx( st_ivas, st0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_dec_MD_fx( st_ivas, st0 ) ), IVAS_ERR_OK ) ) { return error; } - *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig; + *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); + move16(); st0->bit_stream = bit_stream_orig; st0->next_bit_pos = next_bit_pos_orig; + move16(); - IF( !st0->bfi && hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 ) + test(); + IF( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { Word16 zero_pad_bits; - *nb_bits_read += SID_FORMAT_NBITS; - zero_pad_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - *nb_bits_read; + *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); + move16(); + zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); assert( zero_pad_bits <= 1 ); - *nb_bits_read += zero_pad_bits; + *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); + move16(); } pop_wmops(); @@ -792,13 +870,15 @@ static Word16 ivas_get_spar_table_idx_from_coded_idx( test(); IF( EQ_32( ivas_spar_br_table_consts[i].ivas_total_brate, ivas_total_brate ) && EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) { - ind1[j++] = i; + ind1[j] = i; move16(); + j = add( j, 1 ); } } assert( j > 0 ); - *bitlen = ivas_get_bits_to_encode( j - 1 ); + *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); + move16(); ind2 = get_next_indice_fx( st0, *bitlen ); @@ -856,6 +936,7 @@ static Word16 ivas_parse_spar_header( Word16 bitlen, bwidth; *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); + move16(); bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; move16(); @@ -879,6 +960,7 @@ static int16_t ivas_parse_spar_header( } #endif + #ifdef IVAS_FLOAT_FIXED static Word16 get_random_number_fx( Word16 *seed ) @@ -895,6 +977,7 @@ static float get_random_number( } #endif // IVAS_FLOAT_FIXED + #ifdef IVAS_FLOAT_FIXED static Word32 matrix_det_fx( const Word32 a00, @@ -904,9 +987,7 @@ static Word32 matrix_det_fx( { return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); } -#endif - -#ifndef IVAS_FLOAT_FIXED +#else static float matrix_det( const float a00, const float a01, @@ -917,6 +998,7 @@ static float matrix_det( } #endif + #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_fx( Word32 in[3][3], @@ -938,6 +1020,7 @@ static void matrix_inverse_fx( out[0][0] = L_shl( tmp_32, shift ); move32(); *out_q = add( shift, sub( Q15, tmp_e ) ); + move16(); return; } @@ -960,6 +1043,7 @@ static void matrix_inverse_fx( move32(); *out_q = add( Q27, sub( q_fac, 31 ) ); + move16(); return; } @@ -992,12 +1076,11 @@ static void matrix_inverse_fx( move32(); *out_q = add( Q23, sub( q_fac, 31 ) ); + move16(); return; } -#endif - -#ifndef IVAS_FLOAT_FIXED +#else static void matrix_inverse( float in[3][3], float out[3][3], @@ -1051,6 +1134,7 @@ static void matrix_inverse( * * *---------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_spar_get_cldfb_gains_fx( SPAR_DEC_HANDLE hSpar, @@ -1077,38 +1161,49 @@ void ivas_spar_get_cldfb_gains_fx( Word16 seed, split_band, slot_row, slot_col, slot, tmp_idx; pt_len = cldfbAnaDec0->p_filter_length; + move16(); num_cldfb_bands = cldfbAnaDec0->no_channels; + move16(); - stride = NS2SA_fx2( output_Fs_fx, DELAY_CLDFB_NS ); - encfb_delay = NS2SA_fx2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); - decfb_delay = NS2SA_fx2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); + stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS ); + encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); + decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay ); cf_len = sub( cf_end, cf_start ); weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx; - cf_cldfb_start = shr( (Word16) ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ), 6 ); + cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 ); cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 ); num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) ); seed = RANDOM_INITSEED; + move16(); split_band = SPAR_DIRAC_SPLIT_START_BAND; + move16(); pp_ts_im_fx[0] = ts_im_fx; pp_ts_re_fx[0] = ts_re_fx; set32_fx( tgt_fx, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX ); cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx ); cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); - Word16 Q_cf_start_s = norm_s( cf_start_s_fx ) - 1; + Word16 Q_cf_start_s = sub( norm_s( cf_start_s_fx ), 1 ); Word16 Q_cf_len_s = norm_s( cf_len_s_fx ); - Word16 Q_weights = 15 + Q_cf_start_s - Q_cf_len_s; + Word16 Q_weights = add( 15, sub( Q_cf_start_s, Q_cf_len_s ) ); FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); + move16(); weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); + move16(); } hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; + move16(); hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; + move16(); + test(); + test(); + test(); IF( GT_16( num_cf_slots, 3 ) || GT_16( pt_len, 10 * CLDFB_NO_CHANNELS_MAX ) || GT_16( stride, CLDFB_NO_CHANNELS_MAX ) || EQ_16( split_band, IVAS_MAX_NUM_BANDS ) ) { return; @@ -1121,34 +1216,44 @@ void ivas_spar_get_cldfb_gains_fx( // floatToFixed_arrL( (float *)hSpar->hFbMixer->pFilterbank_cross_fade, pFilterbank_cross_fade_fx, Q31, cf_len ); FOR( sample = 0; sample < cf_len; sample++ ) { - tgt_fx[tmp_idx++] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); + tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); + move32(); + tmp_idx = add( tmp_idx, 1 ); /* increasing window function */ } FOR( ; tmp_idx < num_samples; tmp_idx++ ) { /* fill up with ones*/ tgt_fx[tmp_idx] = MAX_32; + move32(); } FOR( sample = 0; sample < num_samples; sample++ ) { /* initialize trasnform matrix with zeros*/ T_fx[sample][0] = T_fx[sample][1] = T_fx[sample][2] = 0; + move32(); + move32(); + move32(); } - FOR( sample = 0; sample < pt_len - stride; sample++ ) + FOR( sample = 0; sample < sub( pt_len, stride ); sample++ ) { /* fill internal CLDFB analysis time buffer with data*/ Word16 x_fx = get_random_number_fx( &seed ); cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); + move32(); } Word16 q_cldfb = 27; + move16(); cldfbAnaDec0->Q_cldfb_state = q_cldfb; + move16(); FOR( slot = 0; slot < num_cf_slots; slot++ ) { FOR( sample = 0; sample < stride; sample++ ) { Word16 x_fx = get_random_number_fx( &seed ); ts_inout_fx[sample] = L_shl( x_fx, 12 ); /*Q-27*/ + move32(); } cldfbAnalysis_ts_fx_fixed_q( ts_inout_fx, ts_re_fx, ts_im_fx, num_cldfb_bands, cldfbAnaDec0, &q_cldfb ); @@ -1157,19 +1262,23 @@ void ivas_spar_get_cldfb_gains_fx( FOR( sample = 0; sample < stride; sample++ ) { - T_fx[slot * stride + sample][slot] = ts_inout_fx[sample]; + T_fx[add( imult1616( slot, stride ), sample )][slot] = ts_inout_fx[sample]; + move32(); } tmp_idx = sub( pt_len, 1 ); FOR( sample = stride; sample < pt_len; sample++ ) { - T_fx[add( imult1616( slot, stride ), sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx--]; + T_fx[add( imult1616( slot, stride ), sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; + move32(); + tmp_idx = sub( tmp_idx, 1 ); } } /* target is synthesis output times the cross-fade window*/ FOR( sample = 0; sample < num_samples; sample++ ) { - tgt_fx[sample] = L_shl( Mult_32_32( tgt_fx[sample], L_add( T_fx[sample][0], L_add( T_fx[sample][1], T_fx[sample][2] ) ) ), 10 ); /*Q31*/ + tgt_fx[sample] = L_shl( Mpy_32_32( tgt_fx[sample], L_add( T_fx[sample][0], L_add( T_fx[sample][1], T_fx[sample][2] ) ) ), 10 ); /*Q31*/ + move32(); } /* compute matrices */ FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) @@ -1177,37 +1286,48 @@ void ivas_spar_get_cldfb_gains_fx( FOR( slot_col = slot_row; slot_col < num_cf_slots; slot_col++ ) { Tt_T_fx[slot_row][slot_col] = 0; + move32(); FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_T_fx[slot_row][slot_col] = L_add( Tt_T_fx[slot_row][slot_col], Mult_32_32( L_shl( T_fx[sample][slot_row], 8 ), L_shl( T_fx[sample][slot_col], 8 ) ) ); /*Q58-Q31*/ + Tt_T_fx[slot_row][slot_col] = L_add( Tt_T_fx[slot_row][slot_col], Mpy_32_32( L_shl( T_fx[sample][slot_row], 8 ), L_shl( T_fx[sample][slot_col], 8 ) ) ); /*Q58-Q31*/ + move32(); } } } Tt_T_fx[1][0] = Tt_T_fx[0][1]; + move32(); Tt_T_fx[2][0] = Tt_T_fx[0][2]; + move32(); Tt_T_fx[2][1] = Tt_T_fx[1][2]; + move32(); FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { Tt_tgt_fx[slot_row] = 0; + move32(); FOR( sample = 0; sample < num_samples; sample++ ) { - Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mult_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); + Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); + move32(); } } Word16 output_q = 27; + move16(); matrix_inverse_fx( Tt_T_fx, Tt_T_inv_fx, num_cf_slots, &output_q ); /* compute the optimal coefficients */ FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ ) { Word32 tmp = 0; + move32(); FOR( slot_col = 0; slot_col < num_cf_slots; slot_col++ ) { - tmp = L_add( tmp, Mult_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); + tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); } - weights_fx[add( cf_cldfb_start, slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, ( output_q - 10 ) ) ), 0 ), output_q - 10 - Q_weights ) ); /*Q_weights*/ + weights_fx[add( cf_cldfb_start, slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/ + move16(); } hSpar->hFbMixer->cldfb_cross_fade_q = Q_weights; + move16(); cldfb_reset_memory_fx( cldfbSynDec0 ); cldfb_reset_memory_fx( cldfbAnaDec0 ); @@ -1465,7 +1585,7 @@ static ivas_error ivas_spar_dec_MD_fx( move16(); test(); - IF( GT_32( ivas_total_brate, FRAME_NO_DATA ) && !bfi ) + IF( ( ivas_total_brate > FRAME_NO_DATA ) && !bfi ) { IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { @@ -1479,19 +1599,20 @@ static ivas_error ivas_spar_dec_MD_fx( ELSE { hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); + move16(); } IF( NE_16( hSpar->hMdDec->table_idx, table_idx ) ) { hSpar->hMdDec->table_idx = table_idx; move16(); - IF( hSpar->hTdDecorr ) + if ( hSpar->hTdDecorr ) { hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; move16(); } - IF( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -1524,6 +1645,7 @@ static ivas_error ivas_spar_dec_MD_fx( IF( EQ_16( hSpar->hMdDec->spar_md_cfg.nchan_transport, 1 ) ) { hSpar->AGC_flag = get_next_indice_fx( st0, 1 ); + move16(); } ivas_agc_read_bits_fx( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag ); @@ -1536,7 +1658,7 @@ static ivas_error ivas_spar_dec_MD_fx( test(); test(); test(); - IF( EQ_16( st0->m_old_frame_type, ZERO_FRAME ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && EQ_16( st0->prev_bfi, 0 ) && EQ_16( hSpar->hMdDec->spar_md_cfg.nchan_transport, 1 ) ) + IF( EQ_16( st0->m_old_frame_type, ZERO_FRAME ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && ( st0->prev_bfi == 0 ) && EQ_16( hSpar->hMdDec->spar_md_cfg.nchan_transport, 1 ) ) { ivas_spar_setup_md_smoothing_fx( hSpar->hMdDec, num_bands_out, num_md_sub_frames ); } @@ -1552,7 +1674,7 @@ static ivas_error ivas_spar_dec_MD_fx( ivas_spar_smooth_md_dtx_fx( hSpar->hMdDec, num_bands_out, num_md_sub_frames ); } - set_s( hSpar->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( hSpar->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); } pop_wmops(); @@ -1678,87 +1800,109 @@ static ivas_error ivas_spar_dec_MD( * * *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 ivas_spar_get_cldfb_slot_gain_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t time_slot_idx, - int16_t *time_slot_idx0, - int16_t *time_slot_idx1, + const Word16 time_slot_idx, + Word16 *time_slot_idx0, + Word16 *time_slot_idx1, Word16 *weight_lowfreq_fx ) { Word16 weight_fx; Word32 encfb_delay_fx, decfb_delay_fx; Word32 xfade_start_ns_fx; - int16_t xfade_delay_subframes; - int16_t i_hist; - int16_t split_band; + Word16 xfade_delay_subframes; + Word16 i_hist; + Word16 split_band; *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; + move16(); encfb_delay_fx = IVAS_FB_ENC_DELAY_NS; + move32(); decfb_delay_fx = IVAS_FB_DEC_DELAY_NS; + move32(); Word32 one_by_outfs = 0; // q15 - switch ( hDecoderConfig->output_Fs ) + move32(); + SWITCH( hDecoderConfig->output_Fs ) { case 16000: one_by_outfs = 2048000000; - break; + move32(); + BREAK; case 32000: one_by_outfs = 1024000000; - break; + move32(); + BREAK; case 48000: one_by_outfs = 682666688; - break; + move32(); + BREAK; default: assert( 0 ); } - Word64 fade_start = (Word64) one_by_outfs * hSpar->hFbMixer->cross_fade_start_offset; + Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); + move64(); fade_start = W_shr( fade_start, 15 ); - xfade_start_ns_fx = ( (Word32) fade_start - encfb_delay_fx + L_shr( decfb_delay_fx, 1 ) ); - xfade_delay_subframes = (int16_t) ( xfade_start_ns_fx / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) ); + xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); - i_hist = 4 - xfade_delay_subframes; + i_hist = sub( 4, xfade_delay_subframes ); split_band = SPAR_DIRAC_SPLIT_START_BAND; + move16(); - if ( split_band < IVAS_MAX_NUM_BANDS ) + IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) ) { - if ( hSpar->i_subframe > 3 ) + IF( GT_16( hSpar->i_subframe, 3 ) ) { Word16 mod_res = time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES; - switch ( mod_res ) + move16(); + SWITCH( mod_res ) { case 0: weight_fx = 0; - break; + move16(); + BREAK; case 1: weight_fx = 8191; - break; + move16(); + BREAK; case 2: weight_fx = 16383; - break; + move16(); + BREAK; case 3: weight_fx = 24575; - break; + move16(); + BREAK; default: weight_fx = 0; - break; + move16(); + BREAK; } } - else + ELSE { weight_fx = 0; + move16(); } *time_slot_idx0 = i_hist; - *time_slot_idx1 = i_hist + 1; + move16(); + *time_slot_idx1 = add( i_hist, 1 ); + move16(); } - else + ELSE { /* determine cross-fade gain for current frame Parameters*/ *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; + move16(); *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; + move16(); weight_fx = *weight_lowfreq_fx; + move16(); } return weight_fx; @@ -1822,54 +1966,61 @@ static float ivas_spar_get_cldfb_slot_gain( * * *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_spar_get_parameters_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t ts, - const int16_t num_ch_out, - const int16_t num_ch_in, - const int16_t num_spar_bands, + const Word16 ts, + const Word16 num_ch_out, + const Word16 num_ch_in, + const Word16 num_spar_bands, Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { - int16_t spar_band, out_ch, in_ch; + Word16 spar_band, out_ch, in_ch; Word16 weight_fx, weight_20ms_fx; - int16_t ts0, ts1, split_band; + Word16 ts0, ts1, split_band; // weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); split_band = SPAR_DIRAC_SPLIT_START_BAND; - for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + move16(); + FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ ) { - if ( split_band < IVAS_MAX_NUM_BANDS - /* 20ms cross-fade for Transport channels in all frequency bands */ - && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ + test(); + IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) + /* 20ms cross-fade for Transport channels in all frequency bands */ + && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ ) { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ ) { - if ( hSpar->i_subframe > 3 ) + IF( GT_16( hSpar->i_subframe, 3 ) ) { par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ) ); + move32(); } - else + ELSE { par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; + move32(); } } } - else + ELSE { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ ) { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ - int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ + Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ + move16(); par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub( MAX_WORD16, weight_20ms_fx ) ), Mpy_32_16_1( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ) ); + move32(); } } } @@ -1878,7 +2029,6 @@ void ivas_spar_get_parameters_fx( return; } #else - void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -1933,6 +2083,7 @@ void ivas_spar_get_parameters( } #endif + /*-------------------------------------------------------------------* * ivas_spar_get_skip_mat() * @@ -2018,7 +2169,9 @@ static void ivas_spar_get_skip_mat_fx( FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ ) { skip_mat[out_ch][in_ch] = 1; + move16(); skip_flag = 1; + move16(); FOR( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -2026,6 +2179,7 @@ static void ivas_spar_get_skip_mat_fx( IF( hSpar->hMdDec->mixer_mat_prev_fx[1 + i_ts][out_ch][in_ch][spar_band] != 0 ) { skip_flag = 0; + move16(); BREAK; } } @@ -2033,19 +2187,21 @@ static void ivas_spar_get_skip_mat_fx( IF( skip_flag == 0 ) { skip_mat[out_ch][in_ch] = 0; + move16(); BREAK; } } - IF( skip_mat[out_ch][in_ch] == 1 ) + IF( EQ_16( skip_mat[out_ch][in_ch], 1 ) ) { FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band + i_ts * IVAS_MAX_NUM_BANDS] != 0 ) + IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( spar_band, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] != 0 ) { skip_flag = 0; + move16(); BREAK; } } @@ -2053,6 +2209,7 @@ static void ivas_spar_get_skip_mat_fx( IF( skip_flag == 0 ) { skip_mat[out_ch][in_ch] = 0; + move16(); BREAK; } } @@ -2064,6 +2221,7 @@ static void ivas_spar_get_skip_mat_fx( } #endif + #ifdef IVAS_FLOAT_FIXED static void ivas_spar_calc_smooth_facs_fx( Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i @@ -2083,89 +2241,118 @@ static void ivas_spar_calc_smooth_facs_fx( Word32 L_temp; Word16 exp_tmp, q_tmp; bin = 0; + move16(); FOR( b = 0; b < nbands_spar; b++ ) { - IF( GE_16( bin, CLDFB_NO_CHANNELS_MAX ) || ( GT_16( b, 0 ) && LT_16( bin2band->p_cldfb_map_to_spar_band[bin], bin2band->p_cldfb_map_to_spar_band[bin - 1] ) ) ) + test(); + test(); + IF( GE_16( bin, CLDFB_NO_CHANNELS_MAX ) || ( ( b > 0 ) && LT_16( bin2band->p_cldfb_map_to_spar_band[bin], bin2band->p_cldfb_map_to_spar_band[bin - 1] ) ) ) { BREAK; } /* calculate band-wise subframe energies */ subframe_band_nrg_fx[b] = 0; + move32(); WHILE( LT_16( bin, CLDFB_NO_CHANNELS_MAX ) && EQ_16( b, bin2band->p_cldfb_map_to_spar_band[bin] ) ) { + test(); FOR( ts = 0; ts < nSlots; ts++ ) { L_temp = L_add( L_shr( Mpy_32_32( cldfb_in_ts_re_fx[ts][bin], cldfb_in_ts_re_fx[ts][bin] ), 4 ), L_shr( Mpy_32_32( cldfb_in_ts_im_fx[ts][bin], cldfb_in_ts_im_fx[ts][bin] ), 4 ) ); // 2*q_cldfb - 35 subframe_band_nrg_fx[b] = L_add_sat( subframe_band_nrg_fx[b], L_temp ); // 2*q_cldfb - 35 (saturation reached in 1 orig pytest) + move32(); } - bin++; + bin = add( bin, 1 ); } - exp_tmp = sub( 66, i_mult( 2, q_cldfb ) ); + exp_tmp = sub( 66, shl( q_cldfb, 1 ) ); subframe_band_nrg_fx[b] = Sqrt32( subframe_band_nrg_fx[b], &exp_tmp ); - q_tmp = 31 - exp_tmp; + move32(); + q_tmp = sub( 31, exp_tmp ); + test(); IF( isFirstSubframe && LT_16( nSlots, MAX_PARAM_SPATIAL_SUBFRAMES ) ) { /* fill up to full 5ms subframe */ smooth_buf_fx[b][0] = L_add( smooth_buf_fx[b][0], L_shr( subframe_band_nrg_fx[b], q_tmp ) ); // Q0 + move32(); } ELSE { smooth_buf_fx[b][0] = L_shr( subframe_band_nrg_fx[b], q_tmp ); // Q0 + move32(); } /* calculate short and long energy averages */ smooth_short_avg_fx[b] = 0; + move32(); FOR( i = 0; i < 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i++ ) { smooth_short_avg_fx[b] = L_add( smooth_short_avg_fx[b], smooth_buf_fx[b][i] ); // Q0 + move32(); } smooth_long_avg_fx[b] = smooth_short_avg_fx[b]; // Q0 + move32(); FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i < 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i++ ) { smooth_long_avg_fx[b] = L_add( smooth_long_avg_fx[b], smooth_buf_fx[b][i] ); // Q0 + move32(); } smooth_short_avg_fx[b] = Mpy_32_16_1( smooth_short_avg_fx[b], 5461 /*(1/6 in Q15)*/ ); // Q0 - smooth_long_avg_fx[b] = Mpy_32_16_1( smooth_long_avg_fx[b], 1639 /*(1/20 in Q15)*/ ); // Q0 + move32(); + smooth_long_avg_fx[b] = Mpy_32_16_1( smooth_long_avg_fx[b], 1639 /*(1/20 in Q15)*/ ); // Q0 + move32(); /* calculate smoothing factor based on energy averages */ /* reduce factor for higher short-term energy */ IF( smooth_long_avg_fx[b] <= 0 ) { smooth_fac_fx[b] = 0; + move16(); } - ELSE IF( smooth_long_avg_fx[b] >= smooth_short_avg_fx[b] ) + ELSE IF( GE_32( smooth_long_avg_fx[b], smooth_short_avg_fx[b] ) ) { smooth_fac_fx[b] = MAX_16; // 1.0f in Q15 + move16(); } ELSE { smooth_fac_fx[b] = divide3232( smooth_long_avg_fx[b], smooth_short_avg_fx[b] ); // Q15 + move16(); } /* map factor to range [0;1] */ smooth_fac_fx[b] = shl( mult_r( s_max( 0, sub( smooth_fac_fx[b], 9830 ) ), 23405 /*Q14*/ ), 1 ); // Q15 + move16(); /* compress factor (higher compression in lowest bands) */ IF( LT_16( b, 2 ) ) { exp_tmp = 0; + move16(); smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp ); + move16(); smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp ); + move16(); smooth_fac_fx[b] = shl( smooth_fac_fx[b], exp_tmp ); // Q15 + move16(); } ELSE { exp_tmp = 0; + move16(); smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp ); + move16(); smooth_fac_fx[b] = shl( smooth_fac_fx[b], exp_tmp ); // Q15 + move16(); } /* apply upper bounds depending on band */ smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); + move16(); } /* only update if we collected a full 5ms worth of energies for the buffer */ + test(); IF( isFirstSubframe || EQ_16( nSlots, MAX_PARAM_SPATIAL_SUBFRAMES ) ) { FOR( b = 0; b < nbands_spar; b++ ) @@ -2173,6 +2360,7 @@ static void ivas_spar_calc_smooth_facs_fx( FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- ) { smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; + move32(); } } } @@ -2273,6 +2461,7 @@ static void ivas_spar_calc_smooth_facs( } #endif + /*-------------------------------------------------------------------* * ivas_spar_dec_agc_pca() * @@ -2372,7 +2561,6 @@ void ivas_spar_dec_agc_pca_fx( IF( hSpar->hMdDec->td_decorr_flag ) { num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - move16(); } ELSE { @@ -2396,11 +2584,13 @@ void ivas_spar_dec_agc_pca_fx( } #endif + /*-------------------------------------------------------------------* * ivas_spar_dec_set_render_map() * * *-------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_set_render_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -2454,7 +2644,8 @@ void ivas_spar_dec_set_render_map_fx( /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ - IF( !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) + test(); + IF( !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) { st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; move16(); @@ -2467,13 +2658,14 @@ void ivas_spar_dec_set_render_map_fx( } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() * * IVAS SPAR upmixer *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_set_render_params( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */ @@ -2504,7 +2696,9 @@ void ivas_spar_dec_set_render_params_fx( hSpar = st_ivas->hSpar; nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + move16(); ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); ivas_spar_dec_set_render_map_fx( st_ivas, n_cldfb_slots ); @@ -2513,11 +2707,13 @@ void ivas_spar_dec_set_render_params_fx( } #endif + /*-------------------------------------------------------------------* * ivas_spar_dec_digest_tc() * * *-------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -2610,7 +2806,7 @@ void ivas_spar_dec_digest_tc_fx( hSpar = st_ivas->hSpar; test(); test(); - IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + IF( hSpar->hMdDec->td_decorr_flag && !( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { Word16 nchan_internal, ch; Word16 ch_sba_idx; @@ -2619,12 +2815,13 @@ void ivas_spar_dec_digest_tc_fx( Word32 *p_tc[MAX_SPAR_INTERNAL_CHANNELS]; Word32 Pcm_tmp[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k]; Word16 q_format = Q11; + move16(); ch_sba_idx = 0; move16(); - IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { ch_sba_idx = st_ivas->nchan_ism; move16(); @@ -2632,15 +2829,17 @@ void ivas_spar_dec_digest_tc_fx( } /* TD decorrelator */ - default_frame = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + Word32 quo, rem; + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &quo, &rem, 0 ); + default_frame = extract_l( quo ); nSamplesLeftForTD = nSamplesForRendering; + move16(); nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); FOR( ch = 0; ch < nchan_internal; ch++ ) { pPcm_tmp[ch] = Pcm_tmp[ch]; - p_tc[ch] = st_ivas->hTcBuffer->tc_fx[ch + ch_sba_idx]; - move32(); + p_tc[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, ch_sba_idx )]; } WHILE( nSamplesLeftForTD ) @@ -2652,22 +2851,23 @@ void ivas_spar_dec_digest_tc_fx( ivas_td_decorr_process_fx( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr, &q_format ); st_ivas->hTcBuffer->q_tc_fx = s_min( st_ivas->hTcBuffer->q_tc_fx, q_format ); + move16(); IF( GE_16( hSpar->hTdDecorr->num_apd_outputs, sub( nchan_internal, nchan_transport ) ) ) { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); + Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); } } ELSE { FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ ) { - set32_fx( p_tc[nchan_internal - 1 - ch], 0, nSamplesToDecorr ); + set32_fx( p_tc[sub( sub( nchan_internal, 1 ), ch )], 0, nSamplesToDecorr ); } FOR( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) { - Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); + Copy32( pPcm_tmp[sub( sub( hSpar->hTdDecorr->num_apd_outputs, 1 ), ch )], p_tc[sub( sub( nchan_internal, 1 ), ch )], nSamplesToDecorr ); } } } @@ -2686,6 +2886,7 @@ void ivas_spar_dec_digest_tc_fx( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() @@ -2812,6 +3013,14 @@ void ivas_spar_dec_upmixer( return; } #endif + + +/*-------------------------------------------------------------------* + * ivas_spar_dec_upmixer_sf() + * + * IVAS SPAR upmixer + *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -2828,7 +3037,7 @@ void ivas_spar_dec_upmixer_sf_fx( Word16 slot_size, slot_idx_start; Word16 md_idx; Word32 *p_tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 Pcm_tmp_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k] = { 0 }; + Word32 Pcm_tmp_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; Word16 numch_out_dirac; Word32 mixer_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word16 b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -2836,34 +3045,45 @@ void ivas_spar_dec_upmixer_sf_fx( SPAR_DEC_HANDLE hSpar; Word16 num_md_sub_frames; Word16 q1 = 30; + move16(); push_wmops( "ivas_spar_dec_upmixer_sf" ); hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + move16(); numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + move16(); numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + move16(); slot_idx_start = hSpar->slots_rendered; + move16(); - IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { Word16 nchan_ism; nchan_ism = st_ivas->nchan_ism; + move16(); FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i + nchan_ism] + slot_idx_start * slot_size; + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[add( i, nchan_ism )] + i_mult( slot_idx_start, slot_size ); } - IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { FOR( i = 0; i < nchan_ism; i++ ) { - p_tc_fx[i + nchan_internal] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; + p_tc_fx[add( i, nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); } } } @@ -2871,7 +3091,7 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( i = 0; i < nchan_internal; i++ ) { - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; + p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + i_mult( slot_idx_start, slot_size ); } } @@ -2883,10 +3103,12 @@ void ivas_spar_dec_upmixer_sf_fx( IF( hSpar->hMdDec->td_decorr_flag ) { num_in_ingest = nchan_internal; + move16(); } ELSE { num_in_ingest = nchan_transport; + move16(); } /*---------------------------------------------------------------------* @@ -2894,22 +3116,26 @@ void ivas_spar_dec_upmixer_sf_fx( *---------------------------------------------------------------------*/ hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + move16(); /*---------------------------------------------------------------------* * Prepare CLDFB buffers *---------------------------------------------------------------------*/ +#ifdef MSAN_FIX + set_zero_fx( &Pcm_tmp_fx[0][0], ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ) * L_FRAME48k ); +#endif // MSAN_FIX /* set-up pointers */ - IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) + IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { /* at this point, output channels are used as intermediate procesing buffers */ FOR( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++ ) { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; } } } @@ -2919,8 +3145,8 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][i_mult( ts, num_cldfb_bands )]; + cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][add( i_mult( ts, num_cldfb_bands ), ( 4 * num_cldfb_bands ) )]; } } } @@ -2930,12 +3156,14 @@ void ivas_spar_dec_upmixer_sf_fx( *---------------------------------------------------------------------*/ num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + move16(); /* apply parameters */ /* determine if we can skip certain data */ ivas_spar_get_skip_mat_fx( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat, num_md_sub_frames ); /* this can be precomputed based on bitrate and format*/ numch_out_dirac = hDecoderConfig->nchan_out; + move16(); /* CLDFB analysis of incoming frame */ @@ -2944,35 +3172,45 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + move16(); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } - IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - FOR( ; in_ch < st_ivas->nchan_ism + numch_in; in_ch++ ) + FOR( ; in_ch < add( st_ivas->nchan_ism, numch_in ); in_ch++ ) { FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); + move16(); + cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][i_mult( ts, num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); } } } - IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + test(); + test(); + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { Word16 q_cldfb = 6; + move16(); ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx ); } FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; + md_idx = hSpar->render_to_md_map[add( ts, slot_idx_start )]; + move16(); floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); - IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + test(); + test(); + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { @@ -2980,8 +3218,10 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - mixer_mat_fx[out_ch][in_ch][spar_band] = L_add( Mult_32_16( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ), Mult_32_16( hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ) ); /*q1*/ + mixer_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] ) ), hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ); /*q1*/ + move32(); hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; + move32(); } } } @@ -2997,29 +3237,36 @@ void ivas_spar_dec_upmixer_sf_fx( FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { out_re_fx[out_ch] = 0; + move32(); out_im_fx[out_ch] = 0; + move32(); FOR( in_ch = 0; in_ch < numch_in; in_ch++ ) { - IF( EQ_16( b_skip_mat[out_ch][in_ch], 0 ) ) + IF( b_skip_mat[out_ch][in_ch] == 0 ) { IF( LT_16( cldfb_band, CLDFB_PAR_WEIGHT_START_BAND ) ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + move16(); cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; + move32(); } ELSE { cldfb_par_fx = 0; + move32(); FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ Word16 tmp = extract_l( L_shr( bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band], 7 ) ); - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mult_32_16( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ + cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], tmp ) ); /*q1*/ } } - out_re_fx[out_ch] = L_add( out_re_fx[out_ch], Mult_32_32( cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); /*q1-25*/ - out_im_fx[out_ch] = L_add( out_im_fx[out_ch], Mult_32_32( cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); /*q1-25*/ + out_re_fx[out_ch] = Madd_32_32( out_re_fx[out_ch], cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + move32(); + out_im_fx[out_ch] = Madd_32_32( out_im_fx[out_ch], cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/ + move32(); } } } @@ -3027,16 +3274,25 @@ void ivas_spar_dec_upmixer_sf_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { - cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], 31 - q1 ); /*Q=6*/ - cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], 31 - q1 ); /*Q=6*/ + cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); + cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sub( 31, q1 ) ); /*Q=6*/ + move32(); } } - IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ), ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) ) + + test(); + IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[add( add( slot_idx_start, ts ), 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - Word16 md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; + Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; split_band = SPAR_DIRAC_SPLIT_START_BAND; - md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; + move16(); + if ( NE_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + md_sf = 0; + move16(); + } IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) ) { Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); @@ -3050,17 +3306,22 @@ void ivas_spar_dec_upmixer_sf_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, i_mult( md_sf, IVAS_MAX_NUM_BANDS ) )]; + move32(); } } } - hSpar->i_subframe++; + hSpar->i_subframe = add( hSpar->i_subframe, 1 ); + move16(); hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + move16(); } } } - IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) + test(); + test(); + IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { ivas_dirac_dec_render_sf_fx( st_ivas, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); } @@ -3069,38 +3330,49 @@ void ivas_spar_dec_upmixer_sf_fx( { Word16 outchannels, idx_in, idx_lfe, ch; idx_in = 0; + move16(); idx_lfe = 0; + move16(); outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); FOR( ch = 0; ch < outchannels; ch++ ) { - IF( ( GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) && ( EQ_16( st_ivas->hOutSetup.index_lfe[idx_lfe], ch ) ) ) + test(); + IF( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( EQ_16( st_ivas->hOutSetup.index_lfe[idx_lfe], ch ) ) ) { - set_zero_fx( output_fx[ch], hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands ); - IF( LT_16( idx_lfe, ( sub( st_ivas->hDirACRend->hOutSetup.num_lfe, 1 ) ) ) ) + set_zero_fx( output_fx[ch], i_mult( hSpar->subframe_nbslots[hSpar->subframes_rendered], num_cldfb_bands ) ); + if ( LT_16( idx_lfe, ( sub( st_ivas->hDirACRend->hOutSetup.num_lfe, 1 ) ) ) ) { - idx_lfe++; + idx_lfe = add( idx_lfe, 1 ); } } ELSE { - IF( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) && - !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) && + !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, -6 ); st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); + move16(); Scale_sig32( output_fx[ch], out_len, -6 ); FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); + cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] ); } Scale_sig32( output_fx[ch], out_len, 6 ); Scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, 6 ); st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = add( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, 6 ); + move16(); } - idx_in++; + idx_in = add( idx_in, 1 ); } } } @@ -3111,26 +3383,29 @@ void ivas_spar_dec_upmixer_sf_fx( { Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, -6 ); st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = sub( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); + move16(); Scale_sig32( output_fx[out_ch], out_len, -6 ); FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { - cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); + cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] ); } Scale_sig32( output_fx[out_ch], out_len, 6 ); Scale_sig32( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx, st_ivas->cldfbSynDec[out_ch]->p_filter_length, 6 ); st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state = add( st_ivas->cldfbSynDec[out_ch]->Q_cldfb_state, 6 ); + move16(); } } hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); - hSpar->subframes_rendered++; + move16(); + hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); + move16(); pop_wmops(); return; } #else - void ivas_spar_dec_upmixer_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float *output[], /* o : output audio channels */ diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 6e7f24878bdaac155445c0ca76d0fe86b2d8b0a2..8fa79a7be0d316ce429b310294d36b38665ecb76 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -34,15 +34,13 @@ #include "options.h" #include "math.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include #include "wmc_auto.h" #include "ivas_stat_dec.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED @@ -69,7 +67,7 @@ static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0 *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t numch_out, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag ); +static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands_out, const Word16 n_ts, const Word16 bw, const Word16 dtx_vad, const Word16 nB, const Word16 numch_out, const Word16 active_w_vlbr, const Word16 dyn_active_w_flag ); #else static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t numch_out, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag ); #endif @@ -83,7 +81,7 @@ static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const #ifndef IVAS_FLOAT_FIXED static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t num_ch ); #else -static void ivas_mat_col_rearrange_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, Word32 ***mixer_mat, const int16_t bands, const int16_t num_ch ); +static void ivas_mat_col_rearrange_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 order[IVAS_SPAR_MAX_CH], const Word16 i_ts, Word32 ***mixer_mat, const Word16 bands, const Word16 num_ch ); #endif #ifndef IVAS_FLOAT_FIXED @@ -101,24 +99,33 @@ static void ivas_spar_md_fill_invalid_bands_fx( ivas_spar_dec_matrices_t *pSpar_ static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t numch_out, const int16_t num_md_sub_frames ); #endif +#ifdef IVAS_FLOAT_FIXED +static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, const Word16 *valid_bands, Word16 *base_band_age, Word16 *first_valid_frame, const Word16 num_bands ); +#else static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, int16_t *first_valid_frame, const int16_t num_bands ); +#endif + #ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, Word32 *pFC ); +static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const Word16 nchan_transport, Word32 *pFC ); #else static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, float *pFC ); #endif +#ifdef IVAS_FLOAT_FIXED +static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const Word16 bw, const Word16 num_bands, Word16 *num_dmx_per_band, Word16 *num_dec_per_band ); +#else static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band ); +#endif #ifndef IVAS_FLOAT_FIXED static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 ); #endif #ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_deindex_real_index_fx( const int16_t *index, const int16_t q_levels, const Word32 min_value, const Word32 max_value, Word32 *quant, const int16_t num_ch_dim2 ); +static ivas_error ivas_deindex_real_index_fx( const Word16 *index, const Word16 q_levels, const Word32 min_value, const Word32 max_value, Word32 *quant, const Word16 num_ch_dim2 ); #endif #ifdef IVAS_FLOAT_FIXED -static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); +static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, Word16 *nB, Word16 *bands_bw, Word16 *dtx_vad, const Word32 ivas_total_brate, const Word16 sba_inactive_mode ); #else static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); #endif @@ -299,90 +306,90 @@ ivas_error ivas_spar_md_dec_matrix_open( #else ivas_error ivas_spar_md_dec_matrix_open_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels, /* i : number of internal channels */ - const int16_t num_md_sub_frames /* i : number of MD subframes */ + const Word16 num_channels, /* i : number of internal channels */ + const Word16 num_md_sub_frames /* i : number of MD subframes */ ) { - int16_t i, j; - int16_t k; - if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * num_md_sub_frames * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) + Word16 i, j; + Word16 k; + IF( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( i_mult( i_mult( IVAS_MAX_NUM_BANDS, num_md_sub_frames ), sizeof( ivas_band_coeffs_t ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdDec->band_coeffs_prev = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) + IF( ( hMdDec->band_coeffs_prev = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdDec->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->mixer_mat_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->mixer_mat_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( i_mult( i_mult( num_md_sub_frames, IVAS_MAX_NUM_BANDS ), sizeof( Word32 ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( i_mult( i_mult( num_md_sub_frames, IVAS_MAX_NUM_BANDS ), sizeof( Word32 ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - if ( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( i_mult( num_md_sub_frames, IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - if ( ( hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } @@ -390,73 +397,77 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( } // Fix Memory - if ( ( hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } // Fix Memory - if ( ( hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } // Fix Memory - if ( ( hMdDec->spar_coeffs_tar.P_re_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.P_re_fx = (Word32 ***) malloc( i_mult( num_channels, sizeof( Word32 ** ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.P_re_fx[i] = (Word32 **) malloc( i_mult( num_channels, sizeof( Word32 * ) ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hMdDec->spar_coeffs_tar.P_re_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { hMdDec->spar_coeffs_prev.C_re_fx[i][j][k] = 0; + move32(); hMdDec->spar_coeffs_prev.P_re_fx[i][j][k] = 0; + move32(); hMdDec->spar_coeffs_tar.C_re_fx[i][j][k] = 0; + move32(); hMdDec->spar_coeffs_tar.P_re_fx[i][j][k] = 0; + move32(); } } } @@ -485,7 +496,7 @@ Word16 ivas_get_spar_dec_md_num_subframes( move16(); IF( GT_16( sba_order, SBA_FOA_ORDER ) ) { - IF( GE_32( ivas_total_brate, IVAS_512k ) ) + if ( GE_32( ivas_total_brate, IVAS_512k ) ) { num_subframes = 1; move16(); @@ -495,7 +506,7 @@ Word16 ivas_get_spar_dec_md_num_subframes( test(); test(); test(); - IF( ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && LT_32( ivas_last_active_brate, IVAS_24k4 ) ) || ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && LT_32( ivas_total_brate, IVAS_24k4 ) ) ) + if ( ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && LT_32( ivas_last_active_brate, IVAS_24k4 ) ) || ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && LT_32( ivas_total_brate, IVAS_24k4 ) ) ) { num_subframes = 1; move16(); @@ -541,51 +552,51 @@ int16_t ivas_get_spar_dec_md_num_subframes( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels, /* i : number of internal channels */ - const int16_t sba_order, /* i : SBA order */ - const int16_t sid_format, /* i : SID format */ - const int32_t last_active_ivas_total_brate /* i : IVAS last active bitrate */ + const Word16 num_channels, /* i : number of internal channels */ + const Word16 sba_order, /* i : SBA order */ + const Word16 sid_format, /* i : SID format */ + const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate */ ) { ivas_spar_md_dec_state_t *hMdDec; ivas_error error; - int16_t num_md_sub_frames; + Word16 num_md_sub_frames; error = IVAS_ERR_OK; + move32(); - if ( ( hMdDec = (ivas_spar_md_dec_state_t *) malloc( sizeof( ivas_spar_md_dec_state_t ) ) ) == NULL ) + IF( ( hMdDec = (ivas_spar_md_dec_state_t *) malloc( sizeof( ivas_spar_md_dec_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); -#ifndef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) ) { return error; } - if ( hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 ) + IF( EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { - if ( sid_format == SID_SBA_2TC ) + IF( EQ_16( sid_format, SID_SBA_2TC ) ) { hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + move16(); } - else + ELSE { hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_24k4, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + move16(); } } - else + ELSE { hMdDec->table_idx = ivas_get_spar_table_idx( hDecoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + move16(); } - if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels, sba_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels, sba_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -718,27 +729,27 @@ void ivas_spar_md_dec_matrix_close( #else void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const Word16 num_channels /* i : number of internal channels */ ) { - int16_t i, j; + Word16 i, j; - if ( hMdDecoder->spar_md.band_coeffs != NULL ) + IF( hMdDecoder->spar_md.band_coeffs != NULL ) { free( hMdDecoder->spar_md.band_coeffs ); hMdDecoder->spar_md.band_coeffs = NULL; } - if ( hMdDecoder->band_coeffs_prev != NULL ) + IF( hMdDecoder->band_coeffs_prev != NULL ) { free( hMdDecoder->band_coeffs_prev ); hMdDecoder->band_coeffs_prev = NULL; } - if ( hMdDecoder->mixer_mat_fx != NULL ) + IF( hMdDecoder->mixer_mat_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->mixer_mat_fx[i][j] ); } @@ -746,11 +757,11 @@ void ivas_spar_md_dec_matrix_close_fx( } free( hMdDecoder->mixer_mat_fx ); } - if ( hMdDecoder->spar_coeffs.C_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs.C_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs.C_re_fx[i][j] ); } @@ -758,11 +769,11 @@ void ivas_spar_md_dec_matrix_close_fx( } free( hMdDecoder->spar_coeffs.C_re_fx ); } - if ( hMdDecoder->spar_coeffs.P_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs.P_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs.P_re_fx[i][j] ); } @@ -771,11 +782,11 @@ void ivas_spar_md_dec_matrix_close_fx( free( hMdDecoder->spar_coeffs.P_re_fx ); } - if ( hMdDecoder->spar_coeffs_prev.C_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs_prev.C_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs_prev.C_re_fx[i][j] ); } @@ -784,11 +795,11 @@ void ivas_spar_md_dec_matrix_close_fx( free( hMdDecoder->spar_coeffs_prev.C_re_fx ); } - if ( hMdDecoder->spar_coeffs_prev.P_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs_prev.P_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs_prev.P_re_fx[i][j] ); } @@ -797,11 +808,11 @@ void ivas_spar_md_dec_matrix_close_fx( free( hMdDecoder->spar_coeffs_prev.P_re_fx ); } - if ( hMdDecoder->spar_coeffs_tar.C_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs_tar.C_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs_tar.C_re_fx[i][j] ); } @@ -809,11 +820,11 @@ void ivas_spar_md_dec_matrix_close_fx( } free( hMdDecoder->spar_coeffs_tar.C_re_fx ); } - if ( hMdDecoder->spar_coeffs_tar.P_re_fx != NULL ) + IF( hMdDecoder->spar_coeffs_tar.P_re_fx != NULL ) { - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { free( hMdDecoder->spar_coeffs_tar.P_re_fx[i][j] ); } @@ -837,16 +848,13 @@ void ivas_spar_md_dec_close( ) { ivas_spar_md_dec_state_t *hMdDecoder; - int16_t num_channels; + Word16 num_channels; hMdDecoder = *hMdDec; num_channels = hMdDecoder->spar_md_cfg.num_umx_chs; + move16(); -#ifndef IVAS_FLOAT_FIXED - ivas_spar_md_dec_matrix_close( hMdDecoder, num_channels ); -#else ivas_spar_md_dec_matrix_close_fx( hMdDecoder, num_channels ); -#endif free( *hMdDec ); *hMdDec = NULL; @@ -961,15 +969,12 @@ ivas_error ivas_spar_md_dec_init( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels, /* i : number of internal channels */ - const int16_t sba_order /* i : SBA order */ + const Word16 num_channels, /* i : number of internal channels */ + const Word16 sba_order /* i : SBA order */ ) { - int16_t i, j; - int16_t nchan_transport; -#ifndef IVAS_FLOAT_FIXED - Word32 pFC[IVAS_MAX_NUM_BANDS]; -#endif + Word16 i, j; + Word16 nchan_transport; Word32 *pFC_fx = NULL, PR_minmax_fx[2]; ivas_error error; @@ -977,20 +982,21 @@ ivas_error ivas_spar_md_dec_init( ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); - hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + IF( hMdDec->spar_hoa_md_flag ) + { + hMdDec->spar_md.num_bands = IVAS_MAX_NUM_BANDS; + move16(); + } + ELSE + { + hMdDec->spar_md.num_bands = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); + } ivas_spar_set_bitrate_config_fx( &hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, hMdDec->spar_hoa_dirac2spar_md_flag, 0, 0, 0 ); nchan_transport = hMdDec->spar_md_cfg.nchan_transport; - - -#ifndef IVAS_FLOAT_FIXED - /* get FB coefficients */ - FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) - { - pFC[i] = L_shr( Mpy_32_32( ivas_fb_fcs_12band_1ms_fx[i], hDecoderConfig->output_Fs ), 1 ); // Q0 - } -#endif + move16(); IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) { @@ -1012,86 +1018,78 @@ ivas_error ivas_spar_md_dec_init( { pFC_fx = pFC_48k; } - else + ELSE { assert( 0 ); // update sample rate } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC_fx ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC_fx ) ), IVAS_ERR_OK ) ) { return error; } - if ( nchan_transport != 2 && ( ( hMdDec->spar_md_cfg.remix_unmix_order == 2 ) || ( hMdDec->spar_md_cfg.remix_unmix_order == 1 ) ) ) + test(); + test(); + IF( NE_16( nchan_transport, 2 ) && ( EQ_16( hMdDec->spar_md_cfg.remix_unmix_order, 2 ) || EQ_16( hMdDec->spar_md_cfg.remix_unmix_order, 1 ) ) ) { return IVAS_ERR_INTERNAL; } /* DTX quant init */ PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; + move32(); PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; + move32(); ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); ivas_spar_arith_coeffs_com_init_fx( &hMdDec->arith_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); ivas_spar_huff_coeffs_com_init_fx( &hMdDec->huff_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); hMdDec->spar_md_cfg.prev_quant_idx = -1; + move16(); /* initialize PLC state */ - set_s( hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); - set_s( hMdDec->base_band_age, 0, IVAS_MAX_NUM_BANDS ); - set_s( hMdDec->base_band_coeffs_age, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( hMdDec->base_band_age, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( hMdDec->base_band_coeffs_age, 0, IVAS_MAX_NUM_BANDS ); hMdDec->spar_plc_num_lost_frames = 0; + move16(); hMdDec->spar_plc_enable_fadeout_flag = 1; + move16(); hMdDec->dtx_md_smoothing_cntr = 1; + move16(); -#ifndef IVAS_FLOAT_FIXED - ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); - ivas_clear_band_coeffs( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); -#else ivas_clear_band_coeffs_fx( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeffs_fx( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); -#endif + ivas_clear_band_coeff_idx( hMdDec->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); hMdDec->spar_md.dtx_vad = 0; + move16(); hMdDec->td_decorr_flag = 1; + move16(); set32_fx( hMdDec->spar_md.en_ratio_slow_fx, 0, IVAS_MAX_NUM_BANDS ); set32_fx( hMdDec->spar_md.ref_pow_slow_fx, 0, IVAS_MAX_NUM_BANDS ); set16_fx( hMdDec->smooth_fac_fx, 0, IVAS_MAX_NUM_BANDS ); -#ifndef IVAS_FLOAT_FIXED - set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); - set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); - set_zero( hMdDec->smooth_fac, IVAS_MAX_NUM_BANDS ); -#endif - for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { set32_fx( hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); -#ifndef IVAS_FLOAT_FIXED - set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); -#endif } - for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) { set32_fx( hMdDec->mixer_mat_prev2_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); -#ifndef IVAS_FLOAT_FIXED - set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); -#endif } } hMdDec->first_valid_frame = 1; + move16(); return IVAS_ERR_OK; } @@ -1107,53 +1105,64 @@ ivas_error ivas_spar_md_dec_init( #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, - const int16_t nchan_transport, + const Word16 nchan_transport, Word32 *pFC ) { - int16_t i, j, nchan, dmx_ch; + Word16 i, j, nchan, dmx_ch; - for ( i = 0; i < nchan_transport; i++ ) + FOR( i = 0; i < nchan_transport; i++ ) { hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; + move16(); } nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); - switch ( nchan ) + SWITCH( nchan ) { case 4: /* FOA_CHANNELS */ hMdDec->num_decorr = IVAS_TD_DECORR_OUT_3CH; - break; + move16(); + BREAK; case 9: /* IVAS_HOA_2_CH */ hMdDec->num_decorr = IVAS_TD_DECORR_OUT_5CH; - break; + move16(); + BREAK; case 6: /* IVAS_HOA_2_CH */ hMdDec->num_decorr = IVAS_TD_DECORR_OUT_2CH; - break; + move16(); + BREAK; case 8: /* IVAS_HOA_3_CH */ hMdDec->num_decorr = IVAS_TD_DECORR_OUT_4CH; - break; + move16(); + BREAK; } hMdDec->spar_md_cfg.num_umx_chs = nchan; + move16(); dmx_ch = 0; - for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + move16(); + FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { dmx_ch = 0; - for ( j = 0; j < nchan_transport; j++ ) + move16(); + FOR( j = 0; j < nchan_transport; j++ ) { - if ( pFC[i] < hMdDec->spar_md_cfg.max_freq_per_chan[j] ) + if ( LT_32( pFC[i], hMdDec->spar_md_cfg.max_freq_per_chan[j] ) ) { - dmx_ch += 1; + dmx_ch = add( dmx_ch, 1 ); } } hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; - hMdDec->spar_md_cfg.num_decorr_per_band[i] = nchan - hMdDec->spar_md_cfg.nchan_transport; + move16(); + hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); + move16(); } hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + move16(); return IVAS_ERR_OK; } @@ -1296,9 +1305,9 @@ static void ivas_dec_mono_sba_handling_fx( test(); test(); - IF( - ( NE_32( azimuth_fx, 0 ) ) || - ( NE_32( elevation_fx, 0 ) ) || + if ( + ( ( azimuth_fx != 0 ) ) || + ( ( elevation_fx != 0 ) ) || ( GT_32( energy_ratio_fx, 161061274 /* 0.15f in Q30 */ ) ) ) /* 0.15f is just above the lowest quantised value. */ { mono_flag = 0; @@ -1308,6 +1317,7 @@ static void ivas_dec_mono_sba_handling_fx( } /* Combine the SPAR prediction coefs flag with the azimuth, elevation and energy ratio flag.*/ + test(); mono_flag = mono_flag && ivas_spar_chk_zero_coefs_fx( st_ivas ); IF( mono_flag ) @@ -1361,7 +1371,16 @@ void ivas_spar_md_dec_process_fx( hMdDec = st_ivas->hSpar->hMdDec; - active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; + IF( LT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) + { + active_w_vlbr = 1; + move16(); + } + ELSE + { + active_w_vlbr = 0; + move16(); + } num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); @@ -1389,7 +1408,7 @@ void ivas_spar_md_dec_process_fx( } } } - else + ELSE { dyn_active_w_flag = 0; move16(); @@ -1399,23 +1418,6 @@ void ivas_spar_md_dec_process_fx( } } -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR (Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++) - { - FOR (Word16 ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) - { - FOR (Word16 jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) - { - hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] * (1 << 22)); - } - } - FOR (Word16 jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) - { - hMdDec->spar_md.band_coeffs[i].pred_re_fx[jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].pred_re[jj] * (1 << 22)); - hMdDec->spar_md.band_coeffs[i].P_re_fx[jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].P_re[jj] * (1 << 22)); - } - } -#endif ivas_spar_dec_parse_md_bs_fx( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hQMetaData->sba_inactive_mode ); @@ -1428,23 +1430,7 @@ void ivas_spar_md_dec_process_fx( &hMdDec->base_band_coeffs_age[0], &hMdDec->first_valid_frame, nB ); -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for (int i = 0; i < IVAS_MAX_NUM_BANDS; i++) - { - for (int ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) - { - for (int jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) - { - hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = (float)hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] / (1 << 22); - } - } - for (int jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) - { - hMdDec->spar_md.band_coeffs[i].pred_re[jj] = (float)hMdDec->spar_md.band_coeffs[i].pred_re_fx[jj] / (1 << 22); - hMdDec->spar_md.band_coeffs[i].P_re[jj] = (float)hMdDec->spar_md.band_coeffs[i].P_re_fx[jj] / (1 << 22); - } - } -#endif + ivas_dec_mono_sba_handling_fx( st_ivas ); /* SPAR to DirAC conversion */ @@ -1458,37 +1444,28 @@ void ivas_spar_md_dec_process_fx( move16(); /* expand DirAC MD to all time slots */ - for ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) + FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - for ( b = 0; b < hMdDec->spar_md.num_bands; b++ ) + FOR( b = 0; b < hMdDec->spar_md.num_bands; b++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; -#endif - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; move32(); } - for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) { - for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) + FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; -#endif - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; move32(); } } - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; -#endif - hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; move32(); } } @@ -1511,6 +1488,7 @@ void ivas_spar_md_dec_process_fx( hMdDec->dtx_md_smoothing_cntr = 1; + move16(); return; } @@ -1700,36 +1678,42 @@ Word16 ivas_spar_chk_zero_coefs_fx( Word16 j, k, b; ivas_spar_md_dec_state_t *hMdDec; Word16 mono = 1; + move16(); Word16 ndec, ndm; hMdDec = st_ivas->hSpar->hMdDec; ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + move16(); FOR( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ ) { - FOR( j = 0; j < ndm + ndec - 1; j++ ) + FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ ) { - IF( NE_32( hMdDec->spar_md.band_coeffs[b].pred_re_fx[j], 0 ) ) + if ( hMdDec->spar_md.band_coeffs[b].pred_re_fx[j] != 0 ) { mono = 0; + move16(); } } FOR( j = 0; j < ndec; j++ ) { - FOR( k = 0; k < ndm - 1; k++ ) + FOR( k = 0; k < sub( ndm, 1 ); k++ ) { - IF( NE_32( hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k], 0 ) ) + if ( hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k] != 0 ) { mono = 0; + move16(); } } } FOR( j = 0; j < ndec; j++ ) { - IF( NE_32( hMdDec->spar_md.band_coeffs[b].P_re_fx[j], 0 ) ) + if ( hMdDec->spar_md.band_coeffs[b].P_re_fx[j] != 0 ) { mono = 0; + move16(); } } } @@ -1805,7 +1789,7 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( k = dmx_ch; k < FOA_CHANNELS; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1814,7 +1798,7 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1822,6 +1806,7 @@ void ivas_spar_smooth_md_dtx_fx( } hMdDec->dtx_md_smoothing_cntr = s_min( add( hMdDec->dtx_md_smoothing_cntr, 1 ), IVAS_DEFAULT_DTX_CNG_RAMP ); + move16(); return; } @@ -2390,14 +2375,14 @@ static void ivas_get_spar_matrices( static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, - const int16_t num_bands_out, - const int16_t n_ts, - const int16_t bw, - const int16_t dtx_vad, - const int16_t nB, - const int16_t numch_out, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag ) + const Word16 num_bands_out, + const Word16 n_ts, + const Word16 bw, + const Word16 dtx_vad, + const Word16 nB, + const Word16 numch_out, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ) { Word16 num_bands, dmx_ch, split_band; Word16 i, j, k, m, b, i_ts, active_w; @@ -2405,9 +2390,11 @@ static void ivas_get_spar_matrices_fx( Word32 active_w_dm_fac_fx, re_fx, re_fx1; num_bands = num_bands_out; + move16(); order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; split_band = SPAR_DIRAC_SPLIT_START_BAND; + move16(); // Dead code as SPAR_DIRAC_SPLIT_START_BAND = 8 and IVAS_MAX_NUM_BANDS = 12 IF( GE_16( split_band, IVAS_MAX_NUM_BANDS ) ) @@ -2427,15 +2414,30 @@ static void ivas_get_spar_matrices_fx( } } - IF( bw == IVAS_RED_BAND_FACT ) + if ( EQ_16( bw, IVAS_RED_BAND_FACT ) ) { num_bands = shl( num_bands, 1 ); } + test(); active_w = EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hMdDec->spar_md_cfg.active_w, 1 ); - active_w_dm_fac_fx = EQ_16( dtx_vad, 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX_FX : ( EQ_16( active_w_vlbr, 1 ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX ); - move16(); + IF( dtx_vad == 0 ) + { + active_w_dm_fac_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + move32(); + } + ELSE IF( EQ_16( active_w_vlbr, 1 ) ) + { + active_w_dm_fac_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; + move32(); + } + ELSE + { + active_w_dm_fac_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; + move32(); + } + FOR( i_ts = 0; i_ts < n_ts; i_ts++ ) { FOR( i = 0; i < numch_out; i++ ) @@ -2443,18 +2445,20 @@ static void ivas_get_spar_matrices_fx( FOR( j = 0; j < numch_out; j++ ) { - set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); - set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); } } num_bands = min( num_bands, nB ); + move16(); FOR( b = 0; b < num_bands; b++ ) { Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( bw, b )]; + move16(); FOR( j = 0; j < numch_out; j++ ) { @@ -2472,7 +2476,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1]; // Q.22 + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 move32(); } @@ -2481,7 +2485,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1] ); // Q31 *Q22=Q22 + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 move32(); } re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 @@ -2494,23 +2498,29 @@ static void ivas_get_spar_matrices_fx( tmp_dm_re_fx[0][0] = L_shl( L_add( re_fx1, re_fx ), Q9 ); // (Q13+Q13) << Q9 = Q22; move32(); - if ( EQ_16( dyn_active_w_flag, 1 ) ) + IF( EQ_16( dyn_active_w_flag, 1 ) ) { tmp_dm_re_fx[0][0] = L_shl( Mpy_32_32( tmp_dm_re_fx[0][0], IVAS_SPAR_DYN_ACTIVEW_THRESH_FX ), Q9 ); // Q13 *Q31 =Q13 << Q9=Q.22 move32(); } tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + move32(); tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + move32(); tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + move32(); tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + move32(); tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + move32(); tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + move32(); IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) { @@ -2521,12 +2531,11 @@ static void ivas_get_spar_matrices_fx( { IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) { - ivas_mat_col_rearrange_fx( tmp_C1_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); } } - IF( GT_16( dmx_ch, 0 ) ) + IF( dmx_ch > 0 ) { Word32 tmpC_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmpP_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -2552,7 +2561,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = 1; k < dmx_ch; k++ ) { - tmpC_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j - dmx_ch][k - 1]; // Q22 + tmpC_re_fx[j][k] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[sub( j, dmx_ch )][k - 1]; // Q22 move32(); } } @@ -2563,7 +2572,7 @@ static void ivas_get_spar_matrices_fx( { IF( EQ_16( sub( j, dmx_ch ), sub( k, dmx_ch ) ) ) { - tmpP_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[k - dmx_ch]; // Q22 + tmpP_re_fx[j][k] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( k, dmx_ch )]; // Q22 move32(); } ELSE @@ -2581,9 +2590,9 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re_fx[m][k] ); // Q30*Q22 + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); move32(); } } @@ -2596,23 +2605,24 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re_fx[m][k] ); // Q30* Q22 + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); move32(); } } } - hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = - max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] ); + hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = + max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] ); + move32(); } } /* band mixing */ IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) { - FOR( b = 0; b < num_bands_out; b = b + bw ) + FOR( b = 0; b < num_bands_out; b = add( b, bw ) ) { dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; move16(); @@ -2620,8 +2630,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = dmx_ch; k < numch_out; k++ ) { - - hMdDec->spar_coeffs.P_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; + hMdDec->spar_coeffs.P_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; move32(); } } @@ -2630,9 +2639,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - - hMdDec->spar_coeffs.C_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; - + hMdDec->spar_coeffs.C_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; move32(); } } @@ -2697,7 +2704,7 @@ static void ivas_mat_col_rearrange_fx( FOR( j = 0; j < num_ch; j++ ) { - mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( in_re[j][idx], Q8 ); + mixer_mat[j][i][add( bands, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); move32(); } } @@ -2732,7 +2739,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); + hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); move32(); } } @@ -2743,7 +2750,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); + hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); move32(); } } @@ -2757,7 +2764,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8 ); + hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); move32(); } } @@ -2829,51 +2836,48 @@ void ivas_spar_dec_gen_umx_mat( static void ivas_spar_md_band_upmix( ivas_band_coeffs_t *band_coeffs, - int16_t *nB, - int16_t *bands_bw, - int16_t *valid_bands, - int16_t bw_final, - int16_t ndec, - int16_t ndm ) + Word16 *nB, + Word16 *bands_bw, + Word16 *valid_bands, + Word16 bw_final, + Word16 ndec, + Word16 ndm ) { - int16_t i, ii, jj, b, idx, bw_fact; + Word16 i, ii, jj, b, idx, bw_fact; - bw_fact = *bands_bw / bw_final; - for ( i = *nB - 1; i >= 0; i-- ) + bw_fact = idiv1616( *bands_bw, bw_final ); + FOR( i = sub( *nB, 1 ); i >= 0; i-- ) { - for ( b = bw_fact - 1; b >= 0; b-- ) + FOR( b = sub( bw_fact, 1 ); b >= 0; b-- ) { - idx = i * bw_fact + b; - for ( ii = 0; ii < ndec + ndm - 1; ii++ ) + idx = add( i_mult( i, bw_fact ), b ); + FOR( ii = 0; ii < sub( add( ndec, ndm ), 1 ); ii++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - band_coeffs[idx].pred_re[ii] = band_coeffs[i].pred_re[ii]; -#endif band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; + move32(); } - for ( ii = 0; ii < ndec; ii++ ) + FOR( ii = 0; ii < ndec; ii++ ) { - for ( jj = 0; jj < ndm - 1; jj++ ) + FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - band_coeffs[idx].C_re[ii][jj] = band_coeffs[i].C_re[ii][jj]; -#endif band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; + move32(); } } - for ( jj = 0; jj < ndec; jj++ ) + FOR( jj = 0; jj < ndec; jj++ ) { -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - band_coeffs[idx].P_re[jj] = band_coeffs[i].P_re[jj]; -#endif band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + move32(); } valid_bands[idx] = valid_bands[i]; + move16(); } } - *nB = ( *nB ) * ( *bands_bw ) / bw_final; + *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); + move16(); *bands_bw = bw_final; + move16(); return; } @@ -3122,99 +3126,112 @@ static void ivas_spar_dec_parse_md_bs( static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, - int16_t *nB, - int16_t *bands_bw, - int16_t *dtx_vad, - const int32_t ivas_total_brate, - const int16_t sba_inactive_mode ) + Word16 *nB, + Word16 *bands_bw, + Word16 *dtx_vad, + const Word32 ivas_total_brate, + const Word16 sba_inactive_mode ) { - int16_t i, j, k, num_bands; - int16_t ii, jj, ndec, ndm; - uint16_t qsi; + Word16 i, j, k, num_bands; + Word16 ii, jj, ndec, ndm; + UWord16 qsi; ivas_quant_strat_t qs; - int16_t strat, no_ec; - int16_t do_diff[IVAS_MAX_NUM_BANDS]; - // float quant[IVAS_SPAR_MAX_C_COEFF]; + Word16 strat, no_ec; + Word16 do_diff[IVAS_MAX_NUM_BANDS]; Word32 quant_fx[IVAS_SPAR_MAX_C_COEFF]; - int16_t do_repeat[IVAS_MAX_NUM_BANDS]; + Word16 do_repeat[IVAS_MAX_NUM_BANDS]; *dtx_vad = 1; + move16(); *bands_bw = 1; + move16(); qsi = 0; + move16(); num_bands = hMdDec->spar_md.num_bands; + move16(); - if ( ivas_total_brate > IVAS_SID_5k2 ) + IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - if ( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) + IF( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) { - if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) + IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ - qsi = get_next_indice( st0, 1 ); - if ( qsi == 1 ) + qsi = get_next_indice_fx( st0, 1 ); + if ( EQ_32( qsi, 1 ) ) { *dtx_vad = 0; + move16(); } } - else + ELSE { - if ( sba_inactive_mode == 1 ) + IF( EQ_16( sba_inactive_mode, 1 ) ) { *dtx_vad = 0; - qsi = hMdDec->spar_md_cfg.quant_strat_bits + 1; + move16(); + qsi = add( hMdDec->spar_md_cfg.quant_strat_bits, 1 ); } - else + ELSE { - qsi = get_next_indice( st0, hMdDec->spar_md_cfg.quant_strat_bits ); + qsi = get_next_indice_fx( st0, hMdDec->spar_md_cfg.quant_strat_bits ); } } } - else + ELSE { qsi = 0; + move16(); } } - else + ELSE { *dtx_vad = 0; + move16(); } hMdDec->dtx_vad = *dtx_vad; + move16(); - if ( *dtx_vad == 0 ) + IF( *dtx_vad == 0 ) { *nB = SPAR_DTX_BANDS; - *bands_bw = num_bands / *nB; + move16(); + *bands_bw = idiv1616( num_bands, *nB ); + move16(); - for ( i = 0; i < *nB; i++ ) + FOR( i = 0; i < *nB; i++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - // hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; hMdDec->spar_md.band_coeffs[i].pred_re_fx[j] = 0; - // hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; + move32(); hMdDec->spar_md.band_coeffs[i].P_re_fx[j] = 0; + move32(); } hMdDec->valid_bands[i] = 1; + move16(); } - for ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { - for ( j = 0; j < ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); j++ ) + FOR( j = 0; j < ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); j++ ) { - for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) + FOR( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) { - // hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; hMdDec->spar_md.band_coeffs[i].C_re_fx[j][k] = 0; + move32(); } } } ivas_parse_parameter_bitstream_dtx( &hMdDec->spar_md, st0, *bands_bw, *nB, hMdDec->spar_md_cfg.num_dmx_chans_per_band, hMdDec->spar_md_cfg.num_decorr_per_band ); - if ( *bands_bw != 1 ) + IF( NE_16( *bands_bw, 1 ) ) { ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + move16(); ivas_spar_md_band_upmix( hMdDec->spar_md.band_coeffs, nB, @@ -3229,124 +3246,175 @@ static void ivas_spar_dec_parse_md_bs_fx( } qs = hMdDec->spar_md_cfg.quant_strat[qsi]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); - strat = get_next_indice( st0, 3 ); + strat = get_next_indice_fx( st0, 3 ); no_ec = 0; + move16(); - if ( strat < 2 ) + IF( LT_16( strat, 2 ) ) { - *bands_bw = strat + 1; - *nB = num_bands / *bands_bw; - for ( i = 0; i < *nB; i++ ) + *bands_bw = add( strat, 1 ); + move16(); + *nB = idiv1616( num_bands, *bands_bw ); + move16(); + FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; + move16(); do_repeat[i] = 0; + move16(); } } - else if ( strat < 4 ) + ELSE IF( LT_16( strat, 4 ) ) { - *bands_bw = strat - 1; - *nB = num_bands / *bands_bw; - for ( i = 0; i < *nB; i++ ) + *bands_bw = sub( strat, 1 ); + move16(); + *nB = idiv1616( num_bands, *bands_bw ); + move16(); + FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; + move16(); do_repeat[i] = 0; + move16(); } no_ec = 1; + move16(); } - else if ( ivas_total_brate < IVAS_24k4 ) + ELSE IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { *bands_bw = 2; - *nB = num_bands / *bands_bw; + move16(); + *nB = idiv1616( num_bands, *bands_bw ); + move16(); - for ( i = 0; i < *nB; i++ ) + FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; - do_repeat[i] = ( ( strat % 2 ) == ( ( i + 1 ) % 2 ) ); + move16(); + do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); + move16(); } } - else + ELSE { *bands_bw = 1; + move16(); *nB = num_bands; + move16(); - for ( i = 0; i < *nB; i++ ) + FOR( i = 0; i < *nB; i++ ) { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 ); + do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); + move16(); do_repeat[i] = 0; + move16(); } - if ( hMdDec->spar_md_cfg.prev_quant_idx >= 0 ) + IF( hMdDec->spar_md_cfg.prev_quant_idx >= 0 ) { ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); } } hMdDec->spar_md_cfg.prev_quant_idx = qsi; + move16(); - if ( no_ec == 0 ) + IF( no_ec == 0 ) { ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, strat, ivas_total_brate ); } - else + ELSE { ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw ); } - for ( i = 0; i < *nB; i++ ) + FOR( i = 0; i < *nB; i++ ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[i_mult( ( *bands_bw ), i )]; + move16(); + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( ( *bands_bw ), i )]; + move16(); - // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); - ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, ndm + ndec - 1 ); + ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, sub( add( ndm, ndec ), 1 ) ); j = 0; - for ( ii = 0; ii < ndec; ii++ ) + move16(); + FOR( ii = 0; ii < ndec; ii++ ) { - for ( jj = 0; jj < ndm - 1; jj++ ) + FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - // quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; - j++; + move32(); + j = add( j, 1 ); } } - // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); - ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min_fx, qs.C.max_fx, quant_fx, ndec * ( ndm - 1 ) ); + ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min_fx, qs.C.max_fx, quant_fx, i_mult( ndec, sub( ndm, 1 ) ) ); j = 0; - for ( ii = 0; ii < ndec; ii++ ) + move16(); + FOR( ii = 0; ii < ndec; ii++ ) { - for ( jj = 0; jj < ndm - 1; jj++ ) + FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - // hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; - j++; + move32(); + j = add( j, 1 ); } } - // ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); - ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, ndm + ndec - 1 ); + ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, sub( add( ndm, ndec ), 1 ) ); /* Store prior coefficient indices */ - for ( j = 0; j < ndm + ndec - 1; j++ ) + FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + move16(); } - for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) + FOR( j = 0; j < i_mult( ndec, sub( ndm, 1 ) ); j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + move16(); } - for ( j = 0; j < ndec; j++ ) + FOR( j = 0; j < ndec; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + move16(); + } + test(); + IF( ( do_diff[i] == 0 ) && ( do_repeat[i] == 0 ) ) + { + hMdDec->valid_bands[i] = s_or( hMdDec->valid_bands[i], 1 ); + move16(); + } + ELSE + { + hMdDec->valid_bands[i] = s_or( hMdDec->valid_bands[i], 0 ); + move16(); } - hMdDec->valid_bands[i] |= ( do_diff[i] == 0 && do_repeat[i] == 0 ) ? 1 : 0; } ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; - if ( *bands_bw != 1 ) + move16(); + IF( NE_16( *bands_bw, 1 ) ) { ivas_spar_md_band_upmix( hMdDec->spar_md.band_coeffs, @@ -3702,37 +3770,47 @@ static void ivas_spar_get_plc_interp_weights( #endif static void ivas_spar_get_plc_interp_weights_fx( - int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], - int16_t last_valid_band_idx, - int16_t idx, - int16_t b, + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], + Word16 last_valid_band_idx, + Word16 idx, + Word16 b, Word16 *w, - int16_t *id0, - int16_t *id1 ) + Word16 *id0, + Word16 *id1 ) { - if ( last_valid_band_idx < 0 ) /* Extrapolation */ + IF( last_valid_band_idx < 0 ) /* Extrapolation */ { *id1 = valid_band_idx[0]; + move16(); *id0 = 0; + move16(); *w = MAX_WORD16; + move16(); } - else if ( last_valid_band_idx == idx ) /* Extrapolation */ + ELSE IF( EQ_16( last_valid_band_idx, idx ) ) /* Extrapolation */ { *id1 = valid_band_idx[last_valid_band_idx]; + move16(); *id0 = valid_band_idx[last_valid_band_idx]; + move16(); *w = 0; + move16(); } - else /* Interpolation */ + ELSE /* Interpolation */ { *id0 = valid_band_idx[last_valid_band_idx]; + move16(); *id1 = valid_band_idx[last_valid_band_idx + 1]; - if ( ( b - *id0 ) == 0 ) + move16(); + IF( sub( b, *id0 ) == 0 ) { *w = 0; + move16(); } - else + ELSE { - *w = divide3232( ( b - *id0 ), ( *id1 - *id0 ) ); + *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); + move16(); } } return; @@ -3756,13 +3834,15 @@ static void ivas_spar_md_fill_invalid_bands_fx( { Word16 i, j, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; + move16(); Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS]; Word16 w_fx = 0; + move16(); ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, last_valid_band_idx, valid_band_idx, &all_valid, &idx ); assert( idx > 0 ); /* some bands should be valid */ - IF( EQ_16( all_valid, 0 ) ) + IF( all_valid == 0 ) { FOR( b = 0; b < num_bands; b++ ) { @@ -3786,7 +3866,7 @@ static void ivas_spar_md_fill_invalid_bands_fx( } ELSE /* young invalid bands */ { - IF( EQ_16( valid_bands[b], 0 ) ) + IF( valid_bands[b] == 0 ) { FOR( i = 0; i < num_channels; i++ ) { @@ -3801,7 +3881,7 @@ static void ivas_spar_md_fill_invalid_bands_fx( } } - IF( EQ_16( valid_bands[b], 0 ) ) + IF( valid_bands[b] == 0 ) { Word16 i_ts; FOR( i = 0; i < num_channels; i++ ) @@ -3810,9 +3890,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - pSpar_coeffs->C_re_fx[i][j][add( b, i_ts * IVAS_MAX_NUM_BANDS )] = pSpar_coeffs->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; move32(); - pSpar_coeffs->P_re_fx[i][j][add( b, i_ts * IVAS_MAX_NUM_BANDS )] = pSpar_coeffs->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; move32(); } } @@ -3907,87 +3987,89 @@ static void ivas_spar_md_fill_invalid_bands( static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, - const int16_t *valid_bands, - int16_t *base_band_age, - int16_t *first_valid_frame, - const int16_t num_bands ) + const Word16 *valid_bands, + Word16 *base_band_age, + Word16 *first_valid_frame, + const Word16 num_bands ) { - int16_t j, k, b, all_valid; - int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; - int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; - // float w = 0; + Word16 j, k, b, all_valid; + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; + move16(); + Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS]; Word16 w_fx = 0; + move16(); ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, last_valid_band_idx, valid_band_idx, &all_valid, &idx ); assert( idx > 0 ); /* some bands should be valid */ - if ( all_valid == 0 ) + IF( all_valid == 0 ) { - for ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { /* check against non zero in if and else if */ - if ( ( base_band_age[b] > 3 ) || ( *first_valid_frame == 0 ) ) /* old invalid bands */ + test(); + IF( GT_16( base_band_age[b], 3 ) || ( *first_valid_frame == 0 ) ) /* old invalid bands */ { - int16_t id0, id1; - // ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], - // idx, b, &w, &id0, &id1 ); + Word16 id0, id1; + ivas_spar_get_plc_interp_weights_fx( valid_band_idx, last_valid_band_idx[b], idx, b, &w_fx, &id0, &id1 ); - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - // pBand_coeffs[b].pred_re[j] = ( 1 - w ) * pBand_coeffs[id0].pred_re[j] + w * pBand_coeffs[id1].pred_re[j]; pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); + move32(); } - for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) { - for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) + FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - // pBand_coeffs[b].C_re[j][k] = ( 1 - w ) * pBand_coeffs[id0].C_re[j][k] + w * pBand_coeffs[id1].C_re[j][k]; pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); + move32(); } } - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - // pBand_coeffs[b].P_re[j] = ( 1 - w ) * pBand_coeffs[id0].P_re[j] + w * pBand_coeffs[id1].P_re[j]; pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); + move32(); } } - else /* young invalid bands */ + ELSE /* young invalid bands */ { - if ( valid_bands[b] == 0 ) + IF( valid_bands[b] == 0 ) { - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - // pBand_coeffs[b].pred_re[j] = pBand_coeffs_prev[b].pred_re[j]; pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; + move32(); } - for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) { - for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) + FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - // pBand_coeffs[b].C_re[j][k] = pBand_coeffs_prev[b].C_re[j][k]; pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; + move32(); } } - for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - // pBand_coeffs[b].P_re[j] = pBand_coeffs_prev[b].P_re[j]; pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; + move32(); } } } } } - else + ELSE { *first_valid_frame = 1; + move16(); } return; @@ -4120,8 +4202,9 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( Word16 norm_nff; /*norm of num_fade_frames*/ num_fade_frames = s_max( sub( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ), 0 ); norm_nff = norm_s( num_fade_frames ); - gain_dB = -imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ - Word16 exp_gain; /*stores exponent for gain_fx*/ + gain_dB = negate( imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ) ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ + Word16 exp_gain = 0; + move16(); /*stores exponent for gain_fx*/ gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) @@ -4141,7 +4224,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ); + hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ); move32(); } } @@ -4227,56 +4310,47 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_unquant_dtx_indicies( ivas_spar_md_t *pSpar_md, - const int16_t nB, - const int16_t bw, - int16_t *ndm_per_band ) + const Word16 nB, + const Word16 bw, + Word16 *ndm_per_band ) { - int16_t i, b; - int16_t q_lvl; + Word16 i, b; + Word16 q_lvl; // float val; Word32 val_fx; - int16_t idx; + Word16 idx; // float pr_min_max[2]; Word32 pr_min_max_fx[2]; - // pr_min_max[0] = pSpar_md->min_max[0]; - // pr_min_max[1] = pSpar_md->min_max[1]; - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + move32(); pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + move32(); - for ( b = 0; b < nB; b++ ) + FOR( b = 0; b < nB; b++ ) { - for ( i = 0; i < FOA_CHANNELS - 1; i++ ) + FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) { - q_lvl = dtx_pr_real_q_levels[ndm_per_band[bw * b] - 1][i]; - // idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; - // ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 ); - // pSpar_md->band_coeffs[b].pred_re[i] = val; - // pSpar_md->band_coeffs[b].pred_re_fx[i] = val * (1 << 22); + q_lvl = dtx_pr_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + move16(); idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; + move16(); ivas_deindex_real_index_fx( &idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1 ); pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - pSpar_md->band_coeffs[b].pred_re[i] = (float)val_fx / (1 << 22); -#endif + move32(); } - for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ ) + FOR( i = 0; i < sub( FOA_CHANNELS, ndm_per_band[i_mult( bw, b )] ); i++ ) { - q_lvl = dtx_pd_real_q_levels[ndm_per_band[bw * b] - 1][i]; - // idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; - // ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 ); - // pSpar_md->band_coeffs[b].P_re[i] = val; - // pSpar_md->band_coeffs[b].P_re_fx[i] = val*(1<<22); + q_lvl = dtx_pd_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + move16(); idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; + move16(); ivas_deindex_real_index_fx( &idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1 ); pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; -#if 0 // ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - pSpar_md->band_coeffs[b].P_re[i] = (float)val_fx / (1 << 22); -#endif + move32(); } } @@ -4330,93 +4404,112 @@ static void ivas_spar_unquant_dtx_indicies( static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const int16_t bw, - const int16_t num_bands, - int16_t *num_dmx_per_band, - int16_t *num_dec_per_band ) + const Word16 bw, + const Word16 num_bands, + Word16 *num_dmx_per_band, + Word16 *num_dec_per_band ) { - int16_t i, j, ndec, ndm; - // float val; + Word16 i, j, ndec, ndm; Word32 val_fx; - int16_t idx; - // float pr_min_max[2]; + Word16 idx; Word32 pr_min_max_fx[2]; - int16_t pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; - int16_t zero_pad_bits, sid_bits_len; + Word16 pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; + Word16 zero_pad_bits, sid_bits_len; sid_bits_len = st0->next_bit_pos; - // pr_min_max[0] = pSpar_md->min_max[0]; + move16(); pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; - // pr_min_max[1] = pSpar_md->min_max[1]; + move32(); pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + move32(); - for ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { - ndec = num_dec_per_band[bw * i]; - ndm = num_dmx_per_band[bw * i]; + ndec = num_dec_per_band[i_mult( bw, i )]; + move16(); + ndm = num_dmx_per_band[i_mult( bw, i )]; + move16(); - for ( j = 0; j < FOA_CHANNELS - 1; j++ ) + FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) { - int16_t pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; - uint16_t value; + Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; + UWord16 value; pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + move16(); pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + move16(); pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + move16(); pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + move16(); - if ( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) + test(); + test(); + test(); + IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + move16(); - if ( ( j + 1 ) > ndec ) + IF( GT_16( add( j, 1 ), ndec ) ) { pd_q_lvls = 1; + move16(); } - else + ELSE { pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + move16(); } - pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); + pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); - value = get_next_indice( st0, pr_pd_bits ); + value = get_next_indice_fx( st0, pr_pd_bits ); - pr = (int16_t) floor( value / pd_q_lvls ); - pd = value - pr * pd_q_lvls; - // val = dtx_pd_real_min_max[0]; + IF( value != 0 ) + { + pr = idiv1616( value, pd_q_lvls ); + } + ELSE + { + pr = 0; + move16(); + } + pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); val_fx = dtx_pd_real_min_max_fx[0]; - // ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); + move32(); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); - pd = pd + idx; + pd = add( pd, idx ); - // val = pr_min_max[0]; val_fx = pr_min_max_fx[0]; - // ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + move32(); ivas_quantise_real_values_fx( &val_fx, pr_q_lvls, pr_min_max_fx[0], pr_min_max_fx[1], &idx, &val_fx, 1 ); - pr = pr + idx; + pr = add( pr, idx ); - if ( ( j + 1 ) <= ndec ) + if ( LE_16( add( j, 1 ), ndec ) ) { pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; + move16(); } pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; + move16(); } } } - sid_bits_len = st0->next_bit_pos - sid_bits_len; - zero_pad_bits = ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - sid_bits_len; + sid_bits_len = sub( st0->next_bit_pos, sid_bits_len ); + zero_pad_bits = sub( ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ), sid_bits_len ); assert( zero_pad_bits >= 0 ); - if ( num_dmx_per_band[0] == 2 ) + if ( EQ_16( num_dmx_per_band[0], 2 ) ) { - zero_pad_bits -= 1; + zero_pad_bits = sub( zero_pad_bits, 1 ); } - for ( j = 0; j < zero_pad_bits; j++ ) + FOR( j = 0; j < zero_pad_bits; j++ ) { - get_next_indice( st0, 1 ); + get_next_indice_fx( st0, 1 ); } ivas_spar_unquant_dtx_indicies( pSpar_md, num_bands, bw, num_dmx_per_band ); @@ -4558,34 +4651,36 @@ static ivas_error ivas_deindex_real_index( #else static ivas_error ivas_deindex_real_index_fx( - const int16_t *index, - const int16_t q_levels, + const Word16 *index, + const Word16 q_levels, const Word32 min_value, const Word32 max_value, Word32 *quant, - const int16_t dim ) + const Word16 dim ) { - int16_t i; + Word16 i; Word32 q_step_fx; - if ( q_levels == 0 ) + IF( q_levels == 0 ) { return IVAS_ERR_INTERNAL; } - if ( q_levels == 1 ) + IF( EQ_16( q_levels, 1 ) ) { - for ( i = 0; i < dim; i++ ) + FOR( i = 0; i < dim; i++ ) { quant[i] = 0; + move32(); } } - else + ELSE { q_step_fx = L_sub( max_value, min_value ); - q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[( q_levels - 1 )] ); - for ( i = 0; i < dim; i++ ) + q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] ); + FOR( i = 0; i < dim; i++ ) { quant[i] = Mpy_32_32( L_shl( index[i], 31 - 6 ), q_step_fx ); //(25+28)-31 = 22 + move32(); } } @@ -4873,122 +4968,157 @@ void ivas_spar_to_dirac( void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t dtx_vad, /* i : DTX frame flag */ - const int16_t num_bands_out, /* i : number of output bands */ - const int16_t bw, /* i : band joining factor */ - const int16_t dyn_active_w_flag ) + const Word16 dtx_vad, /* i : DTX frame flag */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bw, /* i : band joining factor */ + const Word16 dyn_active_w_flag ) { DIRAC_DEC_HANDLE hDirAC; - int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; - int16_t block, b; - int16_t *band_grouping; - // float diffuseness[IVAS_MAX_NUM_BANDS]; + Word16 start_band, end_band, band, qmf_band_start, qmf_band_end; + Word16 block, b; + Word16 *band_grouping; + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; - int16_t sba_order_internal; - // float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word16 sba_order_internal; + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - // float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t azi[IVAS_MAX_NUM_BANDS]; - int16_t ele[IVAS_MAX_NUM_BANDS]; - // float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; + Word16 azi[IVAS_MAX_NUM_BANDS]; + Word16 ele[IVAS_MAX_NUM_BANDS]; + Word32 dvx_fx[IVAS_MAX_NUM_BANDS], dvy_fx[IVAS_MAX_NUM_BANDS], dvz_fx[IVAS_MAX_NUM_BANDS]; - // float radius; + Word32 radius_fx; - // float en_ratio, res_pow; + Word32 en_ratio_fx, res_pow_fx; Word16 en_ratio_q; - int16_t num_slots_in_subfr; - int16_t tmp_write_idx_param_band; - int16_t tmp_write_idx_band; - // float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + Word16 num_slots_in_subfr; + Word16 tmp_write_idx_param_band; + Word16 tmp_write_idx_band; + Word32 pred_re_20ms_fx[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; - int16_t pred_idx; - int16_t *dirac_to_spar_md_bands; - int16_t enc_param_start_band; - int16_t active_w_vlbr; - int16_t i, num_subframes; - int16_t active_w; + Word16 pred_idx; + Word16 *dirac_to_spar_md_bands; + Word16 enc_param_start_band; + Word16 active_w_vlbr; + Word16 i, num_subframes; + Word16 active_w; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - active_w = ( dyn_active_w_flag == 1 ) || ( hMdDec->spar_md_cfg.active_w == 1 ); + test(); + active_w = EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hMdDec->spar_md_cfg.active_w, 1 ); sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + move16(); start_band = 0; - end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ) / bw; + move16(); + end_band = idiv1616( min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; - enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; - active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; - if ( hDirAC != NULL && ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) == 0 ) + IF( st_ivas->hSpar->enc_param_start_band > 0 ) + { + enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); + } + ELSE + { + enc_param_start_band = 0; + move16(); + } + + IF( LT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) + { + active_w_vlbr = 1; + move16(); + } + ELSE + { + active_w_vlbr = 0; + move16(); + } + + test(); + IF( hDirAC != NULL && ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) == 0 ) { band_grouping = hDirAC->band_grouping; - num_slots_in_subfr = st_ivas->hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - for ( band = start_band; band < end_band; band++ ) + IF( st_ivas->hDirAC->hConfig->dec_param_estim ) + { + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + } + ELSE + { + num_slots_in_subfr = 1; + move16(); + } + + FOR( band = start_band; band < end_band; band++ ) { - // float PR[3], Pd[3], dvnorm, g_pred; Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; Word16 q_g_pred; Word16 q_dvnorm; - // PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; - // PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; + move32(); PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; - // PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; + move32(); PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; - // g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - g_pred_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); + move32(); + g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); q_g_pred = Q22 + Q22 - Q31; - q_dvnorm = Q31 - q_g_pred; + move16(); + q_dvnorm = sub( Q31, q_g_pred ); q_g_pred = q_dvnorm; + move16(); IF( LE_32( g_pred_fx, EPSILON_FIX ) ) { dvx_fx[band] = ONE_IN_Q22; + move32(); dvy_fx[band] = 0; + move32(); dvz_fx[band] = 0; + move32(); azi[band] = 0; + move16(); ele[band] = 0; + move16(); q_g_pred = Q22; + move16(); q_dvnorm = Q22; + move16(); } - else + ELSE { - // g_pred = Sqrt32( g_pred, ); - // dvnorm = 1.0f / g_pred; dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); - if ( q_g_pred < 0 ) + IF( q_g_pred < 0 ) { - g_pred_fx = L_shr( g_pred_fx, ( -1 * q_g_pred ) ); + g_pred_fx = L_shr( g_pred_fx, negate( q_g_pred ) ); q_g_pred = 0; + move16(); } - /*dvx[band] = PR[0] * dvnorm; -dvy[band] = PR[1] * dvnorm; - dvz[band] = PR[2] * dvnorm;*/ - dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); + move32(); dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); + move32(); dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); - Word16 q_1 = ( 22 ) + ( 31 - q_dvnorm ) - 31; + move32(); + Word16 q_1 = sub( add( 22, sub( 31, q_dvnorm ) ), 31 ); - Word32 temp = Mpy_32_32( dvx_fx[band], dvx_fx[band] ) + Mpy_32_32( dvy_fx[band], dvy_fx[band] ); - Word16 q2 = q_1 + q_1 - 31; - Word16 q_temp = 31 - q2; + Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); + Word16 q2 = sub( add( q_1, q_1 ), 31 ); + Word16 q_temp = sub( 31, q2 ); radius_fx = Sqrt32( temp, &q_temp ); - // radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); - - // float check_qzi = atan2f(dvy[band], dvx[band]); Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); Word16 check_azi_fx_res; - IF( LT_32( check_azi_fx_32, 0 ) ) + IF( check_azi_fx_32 < 0 ) { check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 ) ); } @@ -4997,314 +5127,376 @@ dvy[band] = PR[1] * dvnorm; check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 ); } Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); - azi_intermediate = azi_intermediate + ONE_IN_Q21; - // Word16 azi_res = L_shr_r(azi_intermediate, 22); - Word16 azi_res = extract_l( azi_intermediate / ( 1 << 22 ) ); + azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); - Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, ( 9 + q_dvnorm ) - q_temp ); + Word16 azi_res; + IF( azi_intermediate < 0 ) + { + azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); + } + ELSE + { + azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); + } + + Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); Word16 check_ele_fx_res; - IF( LT_32( check_azi_fx_32, 0 ) ) + IF( check_azi_fx_32 < 0 ) { check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 ) ); } - else + ELSE { check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 ); } Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); - ele_intermediate = ele_intermediate + ONE_IN_Q21; - // Word16 ele_res = L_shr_r(ele_intermediate, 22); - Word16 ele_res = extract_l( ele_intermediate / ( 1 << 22 ) ); + ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); + Word16 ele_res; + IF( ele_intermediate < 0 ) + { + ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); + } + ELSE + { + ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); + } - // azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); azi[band] = max( -180, min( 180, azi_res ) ); - // ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); + move16(); ele[band] = max( -90, min( 180, ele_res ) ); + move16(); } - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { // float w_en_norm, f_scale; Word32 w_en_norm_fx, f_scale_fx; Word16 q_w_en_norm_fx; - if ( active_w ) + IF( active_w ) { - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - // f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + move32(); } - else + ELSE { - // f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; - f_scale_fx = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX; + IF( active_w_vlbr ) + { + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; + move32(); + } + ELSE + { + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; + move32(); + } } } - else + ELSE { - // f_scale = 0.0f; f_scale_fx = 0; + move32(); } - // w_en_norm = ( 1.0f - ( f_scale * g_pred * g_pred ) ); Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); temp_result = L_sub( L_shr( ONE_IN_Q31, q_g_pred ), temp_result ); - // w_en_norm *= w_en_norm; + w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); - q_w_en_norm_fx = q_g_pred + q_g_pred; - // Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; - // Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; - // Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; + q_w_en_norm_fx = add( q_g_pred, q_g_pred ); + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + move32(); Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + move32(); Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; - // en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); // 22+22-31 = 13 - Word32 Pd_temp_res = Mpy_32_32( Pd_fx[0], Pd_fx[0] ) + Mpy_32_32( Pd_fx[1], Pd_fx[1] ) + Mpy_32_32( Pd_fx[2], Pd_fx[2] ); // q = 22+22-31 = 13 - // res_pow = w_en_norm + en_ratio + ( Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2] ); - res_pow_fx = L_shr( w_en_norm_fx, ( 31 - q_w_en_norm_fx ) - 13 ) + en_ratio_fx + Pd_temp_res; - // res_pow_q = 13; + move32(); + + en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); // 22+22-31 = 13 + Word32 Pd_temp_res = L_add( L_add( Mpy_32_32( Pd_fx[0], Pd_fx[0] ), Mpy_32_32( Pd_fx[1], Pd_fx[1] ) ), Mpy_32_32( Pd_fx[2], Pd_fx[2] ) ); // q = 22+22-31 = 13 + + res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); + res_pow_fx = L_shr( res_pow_fx, 1 ); - // res_pow *= 0.5f; - // hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ) + Mpy_32_32( 536870912, en_ratio_fx ); - // hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; - hMdDec->spar_md.ref_pow_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ) + Mpy_32_32( 536870912, res_pow_fx ); - // en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ) / ( hMdDec->spar_md.ref_pow_slow[band] + EPSILON ); + + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + move32(); + + hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912, res_pow_fx ) ); + move32(); + en_ratio_q = 31 - 13; + move16(); en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); - if ( en_ratio_q < 0 ) + IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, -1 * ( en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); en_ratio_q = 0; + move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( 31 - en_ratio_q - 13 ) ); - if ( en_ratio_fx_scaled > hMdDec->spar_md.ref_pow_slow_fx[band] ) + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); + IF( GT_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { diffuseness_fx[band] = 0; + move32(); } - else if ( en_ratio_fx_scaled == 0 ) + ELSE IF( en_ratio_fx_scaled == 0 ) { diffuseness_fx[band] = ONE_IN_Q30; + move32(); } - else if ( en_ratio_fx_scaled == hMdDec->spar_md.ref_pow_slow_fx[band] ) + ELSE IF( EQ_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { diffuseness_fx[band] = ONE_IN_Q30; + move32(); } - else + ELSE { - en_ratio_fx = divide3232( en_ratio_fx_scaled, ( hMdDec->spar_md.ref_pow_slow_fx[band] + EPSILON_FX ) ); + en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); en_ratio_fx = L_shl( en_ratio_fx, 15 ); - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx; + diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx ); + move32(); } } - else + ELSE { - // en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32( PR_fx[0], PR_fx[0] ) + Mpy_32_32( PR_fx[1], PR_fx[1] ) + Mpy_32_32( PR_fx[2], PR_fx[2] ); - // hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ) + Mpy_32_32( 536870912, en_ratio_fx ); - // en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ); + en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + move32(); + en_ratio_q = 31 - 13; + move16(); en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); - if ( en_ratio_q < 0 ) + IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, -1 * ( en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); en_ratio_q = 0; + move16(); } Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); - if ( en_ratio_fx_scaled > ONE_IN_Q30 ) + IF( GT_32( en_ratio_fx_scaled, ONE_IN_Q30 ) ) { diffuseness_fx[band] = 0; + move32(); } - else + ELSE { - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx_scaled; + diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); + move32(); } } - // diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ - // diffuseness[band] = ( ( diffuseness[band] < 1.0f ) ? ( ( diffuseness[band] < 0.0f ) ? 0.f : diffuseness[band] ) : 1.0f ); - // diffuseness[band] = (float)diffuseness_fx[band] / (1 << 30); } - for ( band = start_band; band < end_band; band++ ) + FOR( band = start_band; band < end_band; band++ ) { - int16_t azi_dith, ele_dith; + Word16 azi_dith, ele_dith; tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; + move16(); + + en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); + + masa_sq_fx( L_sub( ONE_IN_Q30, en_ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - // en_ratio = 1.0f - diffuseness[band]; - en_ratio_fx = ONE_IN_Q30 - diffuseness_fx[band]; - // en_ratio = (float)en_ratio_fx / (1 << 30); - // cam delete the below function call - // masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - //#ifdef IVAS_FLOAT_FIXED - masa_sq_fx( ONE_IN_Q30 - en_ratio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - //#endif qmf_band_start = band_grouping[band]; + move16(); qmf_band_end = band_grouping[band + 1]; + move16(); - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - int16_t ts_start, ts_end, ts; + Word16 ts_start, ts_end, ts; ts_start = DirAC_block_grouping[block]; + move16(); ts_end = DirAC_block_grouping[block + 1]; - for ( b = qmf_band_start; b < qmf_band_end; b++ ) + move16(); + FOR( b = qmf_band_start; b < qmf_band_end; b++ ) { azi_dith = azi[band]; + move16(); ele_dith = ele[band]; + move16(); hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + move32(); tmp_write_idx_band = tmp_write_idx_param_band; + move16(); - if ( hDirAC->hConfig->dec_param_estim == FALSE ) + IF( hDirAC->hConfig->dec_param_estim == FALSE ) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + move16(); hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + move16(); hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + move32(); } - else + ELSE { - for ( ts = ts_start; ts < ts_end; ts++ ) + FOR( ts = ts_start; ts < ts_end; ts++ ) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + move16(); hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + move16(); hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; - tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + move32(); + tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } } } - tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_param_band = add( tmp_write_idx_param_band, num_slots_in_subfr ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } } /* update buffer write index */ - if ( hDirAC->hConfig->dec_param_estim == FALSE ) + IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } - else + ELSE { - hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } } - else + ELSE { band = end_band; + move16(); } /*read DirAC metadata, convert DirAC to SPAR*/ - for ( ; band < num_bands_out / bw; band++ ) + FOR( ; band < idiv1616( num_bands_out, bw ); band++ ) { - int16_t dirac_band_idx; + Word16 dirac_band_idx; - dirac_band_idx = dirac_to_spar_md_bands[band] - enc_param_start_band; + dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); if ( st_ivas->hQMetaData->useLowerRes ) { num_subframes = 1; + move16(); } - for ( block = 0; block < num_subframes; block++ ) + FOR( block = 0; block < num_subframes; block++ ) { - // if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f ) - //{ - // st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; - // } - if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) + + IF( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) { st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); + move32(); } - // azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; - // ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; - //#ifdef IVAS_FLOAT_FIXED + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + move32(); ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; - //#endif + move32(); } - // diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; - //#ifdef IVAS_FLOAT_FIXED - diffuseness_fx[band] = ONE_IN_Q30 - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0]; - //#endif + diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + move32(); } /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ - if ( hMdDec->spar_md_cfg.nchan_transport > 1 ) + IF( GT_16( hMdDec->spar_md_cfg.nchan_transport, 1 ) ) { -#ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#else - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#endif + Word16 order; + IF( hMdDec->spar_hoa_md_flag ) + { + order = 1; + move16(); + } + ELSE + { + order = sba_order_internal; + move16(); + } + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, order, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ - for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) + FOR( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) { - for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) + FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - // pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; + move32(); } } } - int16_t num_md_sub_frames; + Word16 num_md_sub_frames; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - //#ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); - //#else - // ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); - //#endif - if ( st_ivas->hQMetaData->useLowerRes && dtx_vad ) + + Word16 order; + IF( hMdDec->spar_hoa_md_flag ) { - for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) + order = 1; + move16(); + } + ELSE + { + order = sba_order_internal; + move16(); + } + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, idiv1616( num_bands_out, bw ), order, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); + + test(); + IF( st_ivas->hQMetaData->useLowerRes && dtx_vad ) + { + FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - for ( block = 1; block < num_md_sub_frames; block++ ) + FOR( block = 1; block < num_md_sub_frames; block++ ) { - for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + move32(); } - for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + move32(); } } } } /* expand DirAC TC 20ms MD for residual channels to all subframes*/ - for ( block = 0; block < num_md_sub_frames; block++ ) + FOR( block = 0; block < num_md_sub_frames; block++ ) { - for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) + FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + FOR( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - if ( ivas_is_res_channel( pred_idx + 1, hMdDec->spar_md_cfg.nchan_transport ) ) + IF( ivas_is_res_channel( add( pred_idx, 1 ), hMdDec->spar_md_cfg.nchan_transport ) ) { /* use 20ms coefficients only for residual channels */ - // hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + move32(); } } } } - for ( b = end_band * bw; b < num_bands_out; b++ ) + FOR( b = i_mult( end_band, bw ); b < num_bands_out; b++ ) { hMdDec->valid_bands[b] = 1; + move16(); } return; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index ba197492c257d77ec79c58ad6ce8edb19cabd442..1542469a438d974e0aaa5f2707e4b607753d9898 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -322,7 +322,11 @@ typedef struct stereo_dft_dec_data_struct Word16 Q_nrg_subr; Word16 prev_Q_stefi_sig; +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + Word16 q_td_gain[STEREO_DFT_CORE_HIST_MAX]; +#else Word32 q_td_gain[STEREO_DFT_CORE_HIST_MAX]; +#endif Word16 q_hb_stefi_sig_fx; #endif diff --git a/lib_dec/ivas_stereo_adapt_GR_dec.c b/lib_dec/ivas_stereo_adapt_GR_dec.c index 79b9d272f23bf36bced4fc77fba3066803073de1..3eed99635d62285fd9f829559778b26509de909c 100644 --- a/lib_dec/ivas_stereo_adapt_GR_dec.c +++ b/lib_dec/ivas_stereo_adapt_GR_dec.c @@ -38,6 +38,7 @@ #include "ivas_rom_com.h" #include "rom_dec.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -61,28 +62,35 @@ static Word16 read_GR2( p = bit_stream; nb = 0; + move16(); FOR( i = 0; i < len; i++ ) { ready = 0; + move16(); temp = 0; + move16(); DO { b = *p++; - IF( EQ_16( (Word16) b, 0 ) ) + move16(); + IF( b == 0 ) { ready = 1; + move16(); } ELSE { - temp = add( (Word16) temp, 1 ); + temp = (UWord16) ( L_add( temp, 1 ) ); } } - WHILE( EQ_16( (Word16) ready, 0 ) ); + WHILE( ready == 0 ); b = *p++; - b = (UWord16) add( shl( (Word16) b, 1 ), (Word16) *p++ ); - ind[i] = add( shl( (Word16) temp, 2 ), (Word16) b ); - nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 3 ) ); + move16(); + b = (UWord16) L_add( L_shl( b, 1 ), *p++ ); + ind[i] = extract_l( L_add( L_shl( temp, 2 ), b ) ); + move16(); + nb = (UWord16) L_add( nb, L_add( temp, 3 ) ); } return nb; @@ -108,28 +116,35 @@ static Word16 read_GR1( p = bit_stream; nb = 0; + move16(); FOR( i = 0; i < len; i++ ) { ready = 0; + move16(); temp = 0; + move16(); DO { b = *p++; - IF( EQ_16( (Word16) b, 0 ) ) + move16(); + IF( b == 0 ) { ready = 1; + move16(); } ELSE { - temp = add( (Word16) temp, 1 ); + temp = (UWord16) ( L_add( temp, 1 ) ); } } - WHILE( EQ_16( (Word16) ready, 0 ) ); + WHILE( ready == 0 ); b = *p++; - ind[i] = add( shl( (Word16) temp, 1 ), (Word16) b ); - nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 2 ) ); + move16(); + ind[i] = extract_l( L_add( L_shl( temp, 1 ), b ) ); + move16(); + nb = (UWord16) L_add( nb, L_add( temp, 2 ) ); } return nb; @@ -155,26 +170,32 @@ Word16 read_GR0( p = bit_stream; nb = 0; + move16(); FOR( i = 0; i < len; i++ ) { ready = 0; + move16(); temp = 0; + move16(); DO { b = *p++; - IF( EQ_16( (Word16) b, 0 ) ) + move16(); + IF( b == 0 ) { ready = 1; + move16(); } ELSE { - temp = add( (Word16) temp, 1 ); + temp = (UWord16) L_add( temp, 1 ); } } - WHILE( EQ_16( (Word16) ready, 0 ) ); + WHILE( ready == 0 ); ind[i] = temp; - nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 1 ) ); + move16(); + nb = (UWord16) L_add( nb, L_add( temp, 1 ) ); } return nb; @@ -196,10 +217,13 @@ static ivas_error find_map( ) { *map_idx = 0; + move16(); WHILE( ( NE_16( map[*map_idx], val ) ) && ( NE_16( *map_idx, len ) ) ) { - ( *map_idx )++; + test(); + *map_idx = add( *map_idx, 1 ); + move16(); } @@ -226,7 +250,7 @@ static void decode_adapt_GR_indices1( IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) ) { - map = &map0[15 * no_symb]; + map = &map0[i_mult( 15, no_symb )]; } ELSE { @@ -236,8 +260,9 @@ static void decode_adapt_GR_indices1( FOR( i = 0; i < len; i++ ) { map_symb = ind[i]; + move16(); find_map( out + i, map, map_symb, no_symb ); - map = &( map0[out[i] * no_symb] ); + map = &( map0[i_mult( out[i], no_symb )] ); } return; @@ -258,11 +283,13 @@ Word16 get_value( { Word16 i; UWord16 mask = 0, val = 0; + move16(); + move16(); - FOR( i = nbits - 1; i >= 0; i-- ) + FOR( i = sub( nbits, 1 ); i >= 0; i-- ) { - val = (UWord16) add( (Word16) val, shl( bit_stream[i], mask ) ); - mask = add( mask, 1 ); + val = (UWord16) L_add( val, L_shl( bit_stream[i], mask ) ); + mask = (UWord16) L_add( mask, 1 ); } return val; @@ -287,27 +314,31 @@ Word16 read_BS_GR( Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], tmp, i; *GR_ord = bit_stream[nb]; + move16(); b = 1; + move16(); - IF( EQ_16( *GR_ord, 0 ) ) + IF( *GR_ord == 0 ) { - b = add( b, read_GR0( &bit_stream[nb + b], ind1_tmp, len ) ); + b = add( b, read_GR0( &bit_stream[add( nb, b )], ind1_tmp, len ) ); } ELSE { - b = add( b, read_GR1( &bit_stream[nb + b], ind1_tmp, len ) ); + b = add( b, read_GR1( &bit_stream[add( nb, b )], ind1_tmp, len ) ); } FOR( i = 0; i < len; i++ ) { tmp = add( ind1_tmp[i], 1 ); - IF( tmp & 1 ) /* if odd number */ + IF( s_and( tmp, 1 ) ) /* if odd number */ { ind1[i] = negate( shr( ind1_tmp[i], 1 ) ); + move16(); } ELSE { ind1[i] = shr( tmp, 1 ); + move16(); } } @@ -335,30 +366,36 @@ Word16 read_BS_adapt_GR_sg( /* read first component */ b = 0; + move16(); b = add( b, read_GR1( &bit_stream[nb], ind1_tmp, 1 ) ); /* read GR ord */ - ord = bit_stream[nb + b]; + ord = bit_stream[add( nb, b )]; + move16(); b = add( b, 1 ); - IF( EQ_16( ord, 0 ) ) + IF( ord == 0 ) { *GR_ord = 1; - b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + move16(); + b = add( b, read_GR1( &bit_stream[add( nb, b )], &ind1_tmp[1], sub( len, 1 ) ) ); } ELSE { - ord = bit_stream[nb + b]; + ord = bit_stream[add( nb, b )]; + move16(); b = add( b, 1 ); - IF( EQ_16( ord, 0 ) ) + IF( ord == 0 ) { *GR_ord = 0; + move16(); - b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + b = add( b, read_GR0( &bit_stream[add( nb, b )], &ind1_tmp[1], sub( len, 1 ) ) ); } ELSE { *GR_ord = 2; - b = add( b, read_GR2( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + move16(); + b = add( b, read_GR2( &bit_stream[add( nb, b )], &ind1_tmp[1], sub( len, 1 ) ) ); } } @@ -381,44 +418,52 @@ Word16 read_itd( ) { Word16 huff_flag, sign_flag, I, i, nb = 0, ready; + move16(); - huff_flag = (Word16) get_next_indice( st, 1 ); - sign_flag = (Word16) get_next_indice( st, 1 ); + huff_flag = (Word16) get_next_indice_fx( st, 1 ); + sign_flag = (Word16) get_next_indice_fx( st, 1 ); nb = add( nb, 2 ); IF( EQ_16( huff_flag, 1 ) ) { ready = 0; + move16(); I = 0; + move16(); - WHILE( ( EQ_16( ready, 0 ) ) && ( LT_16( nb, 10 ) ) ) + WHILE( ( ready == 0 ) && ( LT_16( nb, 10 ) ) ) { - I = add( shl( I, 1 ), (Word16) get_next_indice( st, 1 ) ); + test(); + I = add( shl( I, 1 ), (Word16) get_next_indice_fx( st, 1 ) ); nb = add( nb, 1 ); FOR( i = 0; i < 20; i++ ) { + test(); IF( ( EQ_16( I, dft_code_itd[i] ) ) && ( EQ_16( dft_len_itd[i], ( sub( nb, 2 ) ) ) ) ) { I = i; + move16(); ready = 1; + move16(); BREAK; } } } - IF( EQ_16( ready, 0 ) ) + IF( ready == 0 ) { printf( "Error reading Huffman code for ITD: \n" ); } } ELSE { - I = (Word16) get_next_indice( st, STEREO_DFT_ITD_NBITS - 1 ); + I = (Word16) get_next_indice_fx( st, STEREO_DFT_ITD_NBITS - 1 ); nb = add( nb, STEREO_DFT_ITD_NBITS - 1 ); } I = add( I, shl( sign_flag, 8 ) ); *pI = I; + move16(); return nb; } @@ -451,22 +496,24 @@ Word16 read_BS_adapt_GR_rpg( FOR( i = start; i < total_no; i++ ) { ind1_pred[i] = 0; + move16(); } } ELSE { - *GR_ord = bit_stream[nb + b]; /* GR order */ + *GR_ord = bit_stream[add( nb, b )]; /* GR order */ + move16(); b = add( b, 1 ); - IF( EQ_16( *GR_ord, 0 ) ) + IF( *GR_ord == 0 ) { - b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + b = add( b, read_GR0( &bit_stream[add( nb, b )], &ind1_tmp[1], sub( len, 1 ) ) ); } ELSE { /* GR ord 1 */ - b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + b = add( b, read_GR1( &bit_stream[add( nb, b )], &ind1_tmp[1], sub( len, 1 ) ) ); } - decode_adapt_GR_indices1( ind1_tmp, total_no - start, NO_SYMB_GR_PRED_G, &ind1_pred[start], dft_maps_rpg ); + decode_adapt_GR_indices1( ind1_tmp, sub( total_no, start ), NO_SYMB_GR_PRED_G, &ind1_pred[start], dft_maps_rpg ); } return b; @@ -488,14 +535,17 @@ Word16 read_flag_EC_DFT( Word16 flg; flg = bit_stream[0]; - IF( EQ_16( flg, 0 ) ) + move16(); + IF( flg == 0 ) { *flag = flg; + move16(); return 1; } ELSE { *flag = add( 2, bit_stream[1] ); + move16(); return 2; } } diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 48394bd86677cb3973a0d2eae65968c04bb8475e..25d907d3c2792ef5acb49ee614f310643ca45b4b 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -41,10 +41,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#endif -#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_rom_com_fx.h" #endif @@ -81,6 +78,7 @@ #define STEREO_CNA_SOFT_VAD_DN 0.95f /* long-term averaging factor for downward soft VAD update in stereo CNA */ +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * stereo_dft_dec_sid_coh() * @@ -196,7 +194,6 @@ void stereo_dft_dec_sid_coh( } -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * stereo_dft_generate_comfort_noise() * @@ -727,6 +724,7 @@ static void stereo_dft_generate_comfort_noise_fx( q_shift = s_min( getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ), sub( hFdCngCom->cngNoiseLevelExp, 27 ) ); scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, q_shift ); hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, q_shift ); + move16(); enr = 0; /* Eliminates compiler warning. They are always set before they are used */ move32(); @@ -741,25 +739,29 @@ static void stereo_dft_generate_comfort_noise_fx( q_shb_shape = 0; move16(); - IF( EQ_16( chan, 0 ) ) + IF( chan == 0 ) { - pSideGain = hStereoDft->side_gain_fx + i_mult( STEREO_DFT_NBDIV, STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; FOR( b = 0; b < hStereoDft->nbands; b++ ) { - IF( EQ_16( hStereoCng->xfade_frame_counter, 0 ) ) + IF( hStereoCng->xfade_frame_counter == 0 ) { hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); + move16(); } ELSE { hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); + move16(); } + test(); IF( hStereoCng->first_SID ) { IF( hStereoCng->first_SID_after_TD ) { hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + move16(); } ELSE { @@ -772,15 +774,18 @@ static void stereo_dft_generate_comfort_noise_fx( IF( GT_16( hStereoCng->nr_corr_frames, CORR_INIT ) ) { hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + move16(); } ELSE { hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + move16(); } } ELSE { hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + move16(); } } @@ -794,8 +799,8 @@ static void stereo_dft_generate_comfort_noise_fx( { gamma = hStereoCng->cm_fx[b]; /* Q15 */ move16(); - gamma = BASOP_Util_Divide1616_Scale( gamma, 32767 - gamma, &q_div ); /* e(q_div) */ - q_sqrt2 = q_div + 16; + gamma = BASOP_Util_Divide1616_Scale( gamma, sub( 32767, gamma ), &q_div ); /* e(q_div) */ + q_sqrt2 = add( q_div, 16 ); tmp32_1 = BASOP_Util_Add_Mant32Exp( gamma, add( q_div, 16 ), sub( 32767, mult_r( hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b] ) ), 16, &q_sqrt1 ); /* e(q_sqrt1) */ tmp32_1 = Sqrt32( tmp32_1, &q_sqrt1 ); /* e(q_sqrt1) */ tmp32_2 = Sqrt32( gamma, &q_sqrt2 ); /* e(q_sqrt2) */ @@ -838,10 +843,11 @@ static void stereo_dft_generate_comfort_noise_fx( } scaleAvg = BASOP_Util_Divide1616_Scale( scaleAvg, hStereoDft->nbands, &q_div ); hStereoDft->scale_fx = shl_sat( scaleAvg, q_div ); + move16(); } } - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { set32_fx( cngNoiseLevel_upd, 0, st->L_frame ); @@ -850,26 +856,31 @@ static void stereo_dft_generate_comfort_noise_fx( move16(); dmpf[1] = negate( st->preemph_fac ); move16(); - mvs2s( st->Aq_cng, Atmp, M + 1 ); + Copy( st->Aq_cng, Atmp, M + 1 ); conv_fx_32( Atmp, dmpf, cngNoiseLevel_upd, M + 2 ); IF( EQ_16( st->L_frame, L_FRAME ) ) { pTrigo = hStereoDft->dft_trigo_12k8_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); } ELSE { pTrigo = hStereoDft->dft_trigo_16k_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); } - FOR( i = 0; i < st->L_frame / 4; i++ ) + FOR( i = 0; i < shr( st->L_frame, 2 ); i++ ) { trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; - trigo_dec[sub( shr( st->L_frame, 1 ), i )] = pTrigo[i_mult( i, trigo_step )]; + move16(); + trigo_dec[sub( st->L_frame / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + move16(); } - trigo_dec[shr( st->L_frame, 2 )] = pTrigo[i_mult( shr( st->L_frame, 2 ), trigo_step )]; + trigo_dec[st->L_frame / 4] = pTrigo[i_mult( st->L_frame / 4, trigo_step )]; + move16(); Word16 rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), getScaleFactor32( cngNoiseLevel_upd, st->L_frame ) ); v_shr_32( cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng ); @@ -886,7 +897,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr0 = cngNoiseLevel_upd; ptr1 = ptr0 + 2; ptr2 = ptr1 + 1; - assert( GT_32( st->lp_ener_fx, 0 ) ); + assert( st->lp_ener_fx > 0 ); // lp_ener_fx will be in Q6 at this point. // So applying appropriate left shift on the denominator. @@ -898,30 +909,34 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) { ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); - assert( GT_32( ftmp, 0 ) ); + assert( ftmp > 0 ); q_sqrt = sub( 62, shl( q_cngNoiseLevel_upd, 1 ) ); - IF( EQ_32( ftmp, 0 ) ) + IF( ftmp == 0 ) { ftmp = EPSILLON_FX; + move32(); q_sqrt = s_max( 0, q_sqrt ); } tmp = ISqrt32( ftmp, &q_sqrt ); e_norm_temp[i] = sub( 31, add( q_sqrt, q_div ) ); + move16(); *ptr0++ = Mpy_32_32( factor, tmp ); + move32(); ptr1 += 2; ptr2 += 2; } FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) { - q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, e_norm_temp[i] + norm_l( cngNoiseLevel_upd[i] ) ); + q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, add( e_norm_temp[i], norm_l( cngNoiseLevel_upd[i] ) ) ); } FOR( i = 0; i < st->L_frame; i++ ) { cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( q_cngNoiseLevel_upd, e_norm_temp[i] ) ); + move32(); } - IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) + IF( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ) > 0 ) { /* Transform shb LP spectrum */ set32_fx( shb_shape, 0, L_FRAME16k ); @@ -930,14 +945,18 @@ static void stereo_dft_generate_comfort_noise_fx( IF( NE_16( st->L_frame, L_FRAME16k ) ) { pTrigo = hStereoDft->dft_trigo_16k_fx; - trigo_step = i_mult( STEREO_DFT_TRIGO_SRATE_16k_STEP, STEREO_DFT_TRIGO_DEC_STEP ); + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; - trigo_dec[sub( shr( L_FRAME16k, 1 ), i )] = pTrigo[i_mult( i, trigo_step )]; + move16(); + trigo_dec[sub( L_FRAME16k / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + move16(); } - trigo_dec[shr( L_FRAME16k, 2 )] = pTrigo[i_mult( shr( L_FRAME16k, 2 ), trigo_step )]; + trigo_dec[L_FRAME16k / 4] = pTrigo[i_mult( L_FRAME16k / 4, trigo_step )]; + move16(); } Word16 rshift_shb = sub( find_guarded_bits_fx( L_FRAME16k ), getScaleFactor32( shb_shape, L_FRAME16k ) ); @@ -962,8 +981,9 @@ static void stereo_dft_generate_comfort_noise_fx( { ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); q_tmp = sub( shl( q_shb_shape, 1 ), 31 ); - assert( GT_32( ftmp, 0 ) ); + assert( ftmp > 0 ); q_div = 0; + move16(); ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); /* in float: both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. @@ -974,11 +994,14 @@ static void stereo_dft_generate_comfort_noise_fx( enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); tmp32_1 = Sqrt32( ftmp, &q_div ); *ptr0++ = tmp32_1; + move32(); e_norm_temp[i] = sub( 31, q_div ); + move16(); ptr1 += 2; ptr2 += 2; } q_shb_shape = MAX_16; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -987,20 +1010,26 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); + move32(); } } /* Update CNG noise level from MS noise estimation */ - mvl2l( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); + Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); ptr_cng = cngNoiseLevel_hist; - FOR( i = 0; i < sub( st->last_L_frame, hFdCngCom->startBand ) / 2; i++ ) + FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) { tmp = *( cngNoiseLevel_hist + shl( i, 1 ) ); + move32(); tmp = L_add( tmp, *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ) ); *ptr_cng++ = L_shr( tmp, 1 ); + move32(); } - IF( EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( chan, 0 ) && EQ_16( hStereoCng->xfade_frame_counter, 0 ) && GE_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) + test(); + test(); + test(); + IF( EQ_16( last_element_mode, IVAS_CPE_TD ) && ( chan == 0 ) && ( hStereoCng->xfade_frame_counter == 0 ) && GE_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; @@ -1017,6 +1046,7 @@ static void stereo_dft_generate_comfort_noise_fx( { tmp_16 = shl( tmp_16, q_div ); hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + move16(); } ELSE { @@ -1024,6 +1054,7 @@ static void stereo_dft_generate_comfort_noise_fx( tmp_16 = Invert16( tmp_16, &q_inv ); tmp_16 = shl( tmp_16, add( q_inv, q_div ) ); hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + move16(); } } @@ -1031,7 +1062,7 @@ static void stereo_dft_generate_comfort_noise_fx( { ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; - FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) + FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) { tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); tmp_16 = shl( tmp_16, q_div ); @@ -1051,13 +1082,13 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_i = ptr_r + 1; scale = shr( output_frame, 1 ); - FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) + FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); tmp32_1 = Mpy_32_16_1( *ptr_level, scale ); // Q(q_cngNoiseLevel_upd - 15) q_shift = norm_l( tmp32_1 ); - IF( GT_16( q_shift, sub( 46, q_cngNoiseLevel_upd ) ) ) + if ( GT_16( q_shift, sub( 46, q_cngNoiseLevel_upd ) ) ) { q_shift = sub( 46, q_cngNoiseLevel_upd ); } @@ -1065,21 +1096,23 @@ static void stereo_dft_generate_comfort_noise_fx( q_shift = sub( sub( 46, q_cngNoiseLevel_upd ), q_shift ); ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + move32(); ptr_i += 2; ptr_level++; } - IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) + IF( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ) > 0 ) { Word32 scale_32; Word16 q_res; /* high band generation, flipped spectrum */ - assert( NE_32( enr, 0 ) ); + assert( enr != 0 ); // 10 ^ (0.1 * st->hTdCngDec->shb_cng_gain) // Above expression equivalent to 2 ^ (3.321928094 * 0.1 * st->hTdCngDec->shb_cng_gain) // 3.321928094 * 0.1 = 0.3321928094 @@ -1091,19 +1124,23 @@ static void stereo_dft_generate_comfort_noise_fx( move16(); scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div ); // q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); - q_res = q_res - q_enr + q_div; + q_res = add( sub( q_res, q_enr ), q_div ); // q_div = sub(Q15, q_res); move16(); q_div = q_res; + move16(); inv_scale = ISqrt16( scale, &q_res ); scale = Sqrt16( scale, &q_div ); - ptr_shb = shb_shape + sub( shr( L_FRAME16k, 1 ), 1 ); + ptr_shb = shb_shape + ( L_FRAME16k / 2 - 1 ); /* Averaging for Nyquist frequency */ Word16 q1, q2; tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); tmp32_2 = *( ptr_shb - 1 ); + move32(); q1 = sub( add( q_cngNoiseLevel_upd, 1 ), q_res ); q2 = q_shb_shape; + move16(); *ptr_shb = BASOP_Util_Add_Mant32Exp( tmp32_1, sub( Q31, q1 ), tmp32_2, sub( Q31, q2 ), &q_tmp ); + move32(); q_tmp = sub( q_tmp, 1 ); IF( LT_16( sub( Q31, q_tmp ), q_shb_shape ) ) { @@ -1112,19 +1149,21 @@ static void stereo_dft_generate_comfort_noise_fx( } *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); + move32(); // *ptr_shb = 0.5f * ( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1] / scale + *( ptr_shb - 1 ) ); - ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + i_mult( k, STEREO_DFT32MS_N_MAX ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( s_min( output_frame, i_mult( hFdCngCom->regularStopBand, 16 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); tmp32_1 = *ptr_shb; + move32(); q_shift = norm_l( tmp32_1 ); - IF( GT_16( q_shift, sub( 31, q_shb_shape ) ) ) + if ( GT_16( q_shift, sub( 31, q_shb_shape ) ) ) { q_shift = sub( 31, q_shb_shape ); } @@ -1132,10 +1171,12 @@ static void stereo_dft_generate_comfort_noise_fx( q_shift = sub( sub( 31, q_shb_shape ), q_shift ); ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + move32(); ptr_i += 2; ptr_shb--; } @@ -1143,7 +1184,7 @@ static void stereo_dft_generate_comfort_noise_fx( /* rescale */ tmp32_1 = L_mult0( scale, shr( output_frame, 1 ) ); q_shift = norm_l( tmp32_1 ); - IF( GT_16( q_shift, add( Q16, q_div ) ) ) + if ( GT_16( q_shift, add( Q16, q_div ) ) ) { q_shift = add( Q16, q_div ); } @@ -1152,10 +1193,12 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); ptr_i = ptr_r + 1; - FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) + FOR( i = 0; i < shr( sub( min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) { ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + move32(); ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + move32(); ptr_r += 2; ptr_i += 2; } @@ -1171,10 +1214,12 @@ static void stereo_dft_generate_comfort_noise_fx( q_tmp = s_max( hFdCngCom->cngNoiseLevelExp, shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ) ); scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); hFdCngCom->cngNoiseLevelExp = q_tmp; + move16(); FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); + move32(); ptr_tmp--; *ptr_level = *( ptr_level + 1 ); move32(); @@ -1184,16 +1229,18 @@ static void stereo_dft_generate_comfort_noise_fx( ELSE { /* FD-CNG */ - IF( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + IF( !LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { - IF( hStereoCng->xfade_frame_counter <= MAX_K && hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan == 0 ) + test(); + test(); + IF( LE_16( hStereoCng->xfade_frame_counter, (Word16) MAX_K ) && EQ_16( hStereoCng->last_act_element_mode, IVAS_CPE_TD ) && ( chan == 0 ) ) { /* Fade MS -> SID/MS */ j = 0; move16(); - FOR( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) + FOR( k = 0; k < sub( hFdCngCom->nFFTpart, 2 ); k++ ) { - factor = BASOP_Util_Divide3232_Scale_cadence( ( hFdCngCom->sidNoiseEstLp[k] + DELTA_FX ), ( st->hFdCngDec->partNoiseShape[k] + DELTA_FX ), &q_div ); + factor = BASOP_Util_Divide3232_Scale_cadence( L_add( hFdCngCom->sidNoiseEstLp[k], DELTA_FX ), L_add( st->hFdCngDec->partNoiseShape[k], DELTA_FX ), &q_div ); factor = s_min( add( hStereoDft->scale_fx, extract_l( Mpy_32_16_1( L_mult( sub( extract_h( factor ), hStereoDft->scale_fx ), hStereoCng->xfade_frame_counter ), ONE_BY_MAX_K ) ) ), extract_h( factor ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { @@ -1208,7 +1255,7 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { ptr_level = hFdCngCom->cngNoiseLevel; - ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); ptr_i = ptr_r + 1; q_cngNoiseLevel = sub( Q31, hFdCngCom->cngNoiseLevelExp ); FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) @@ -1222,6 +1269,7 @@ static void stereo_dft_generate_comfort_noise_fx( q_sqrt = sub( Q31, q_cngNoiseLevel ); tmp = Sqrt32( tmp, &q_sqrt ); *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); + move32(); ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); move32(); ptr_r += 2; @@ -1231,8 +1279,8 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); ptr_i += 2; } - ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; - ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); ptr_i = ptr_r + 1; FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { @@ -1264,9 +1312,10 @@ static void stereo_dft_generate_comfort_noise_fx( } } - IF( hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan > 0 ) + test(); + IF( EQ_16( hStereoCng->last_act_element_mode, IVAS_CPE_TD ) && ( chan > 0 ) ) { - Word32 log_lp_noise = L_add( L_shl( hFdCngCom->cngNoiseLevelExp, Q25 ), BASOP_Util_Log2( lp_noise + DELTA_FX ) ); + Word32 log_lp_noise = L_add( L_shl( hFdCngCom->cngNoiseLevelExp, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 @@ -1274,11 +1323,11 @@ static void stereo_dft_generate_comfort_noise_fx( st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); move32(); } - ELSE IF( EQ_16( chan, 0 ) ) + ELSE IF( ( chan == 0 ) ) { Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. - Word32 log_lp_noise = L_add( L_shl( hFdCngCom->cngNoiseLevelExp, Q25 ), BASOP_Util_Log2( lp_noise + DELTA_FX ) ); move16(); + Word32 log_lp_noise = L_add( L_shl( hFdCngCom->cngNoiseLevelExp, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 @@ -1287,14 +1336,15 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); st->lp_noise = st->hFdCngDec->lp_noise; move32(); - st->hFdCngDec->hFdCngCom->flag_noisy_speech = (Word16) LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ); + st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); move16(); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); move32(); } - IF( EQ_16( chan, 0 ) && LE_32( st->core_brate, SID_2k40 ) ) + test(); + IF( ( chan == 0 ) && LE_32( st->core_brate, SID_2k40 ) ) { Word32 max_smoothed_psd = 0; move32(); @@ -1303,9 +1353,14 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) { Word16 l_shift_val = sub( st->hFdCngDec->q_smoothed_psd, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ); - move16(); - l_shift_val = max_smoothed_psd == 0 ? 0 : l_shift_val; - ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; + + if ( max_smoothed_psd == 0 ) + { + l_shift_val = 0; + move16(); + } + + ftmp = hFdCngCom->cngNoiseLevel[sub( i, hFdCngCom->startBand )]; move32(); IF( !st->hFdCngDec->first_cna_noise_updated ) { @@ -1317,10 +1372,10 @@ static void stereo_dft_generate_comfort_noise_fx( { alpha = (Word16) ( 0x799A ); move16(); - IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr_sat( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) + IF( ( st->hFdCngDec->smoothed_psd_fx[i] > 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr_sat( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) { /* prevent abrupt upward update steps */ - ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 2 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); + ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 1 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); l_shift_val = 0; move16(); } @@ -1338,9 +1393,10 @@ static void stereo_dft_generate_comfort_noise_fx( } /* update msNoiseEst in SID and NO_DATA frames */ - bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], ( Q31 - st->hFdCngDec->q_smoothed_psd ), hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp ); + bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], sub( Q31, st->hFdCngDec->q_smoothed_psd ), sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp ); Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; + move16(); st->hFdCngDec->first_cna_noise_updated = 1; move16(); Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); @@ -1412,7 +1468,8 @@ void stereo_dtf_cng_fx( { IF( LT_16( hCPE->hStereoCng->nr_dft_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_dft_frames++; + hCPE->hStereoCng->nr_dft_frames = add( hCPE->hStereoCng->nr_dft_frames, 1 ); + move16(); } IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -1420,7 +1477,8 @@ void stereo_dtf_cng_fx( test(); IF( LT_16( hCPE->hStereoCng->nr_sid_frames, SID_INIT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - hCPE->hStereoCng->nr_sid_frames++; + hCPE->hStereoCng->nr_sid_frames = add( hCPE->hStereoCng->nr_sid_frames, 1 ); + move16(); } FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -1459,7 +1517,8 @@ void stereo_cng_dec_update( } IF( LT_16( hCPE->hStereoCng->active_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->active_frame_counter++; + hCPE->hStereoCng->active_frame_counter = add( hCPE->hStereoCng->active_frame_counter, 1 ); + move16(); } } ELSE @@ -1468,14 +1527,15 @@ void stereo_cng_dec_update( move16(); IF( LT_16( hCPE->hStereoCng->xfade_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->xfade_frame_counter++; + hCPE->hStereoCng->xfade_frame_counter = add( hCPE->hStereoCng->xfade_frame_counter, 1 ); + move16(); } } IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { test(); - IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || ( ivas_total_brate == FRAME_NO_DATA ) ) { hCPE->hStereoCng->prev_sid_nodata = 1; move16(); @@ -1512,36 +1572,50 @@ void stereo_cng_compute_PScorr_fx( { Word16 i; Word32 enrP_fx = 0, enrS_fx = 0, dotPS_fx = 0, c_PS_fx; + move32(); + move32(); + move32(); Word32 outputResamp_fx[L_FRAME16k]; Word32 *outputPptr_fx, *outputSptr_fx; Word16 outputPptr_Q = 0, outputSptr_Q = 0; + move16(); + move16(); Word32 tmp1 = 0, tmp2 = 0, tmp3 = 0; + move32(); + move32(); + move32(); IF( GT_16( L_frame_0, L_frame_1 ) ) { outputPptr_fx = output_fx0; L_lerp_fx( output_fx1, outputResamp_fx, L_frame_0, L_frame_1, output_Q ); outputPptr_Q = *output_Q; + move16(); outputSptr_fx = outputResamp_fx; outputSptr_Q = 1; + move16(); } ELSE IF( GT_16( L_frame_1, L_frame_0 ) ) { outputSptr_fx = output_fx1; L_lerp_fx( output_fx0, outputResamp_fx, L_frame_1, L_frame_0, output_Q ); outputSptr_Q = *output_Q; + move16(); outputPptr_fx = outputResamp_fx; outputPptr_Q = 1; + move16(); } ELSE { outputPptr_fx = output_fx0; outputSptr_fx = output_fx1; outputPptr_Q = *output_Q; + move16(); outputSptr_Q = *output_Q; + move16(); } - Word16 guard_bits = (Word16) find_guarded_bits_fx( L_frame_0 ); + Word16 guard_bits = find_guarded_bits_fx( L_frame_0 ); FOR( i = 0; i < L_frame_0; i++ ) { @@ -1553,16 +1627,17 @@ void stereo_cng_compute_PScorr_fx( enrS_fx = L_add( enrS_fx, tmp2 ); tmp3 = Mpy_32_32( *outputPptr_fx++, *outputSptr_fx++ ); // outputSptr_Q + outputPptr_Q - 31 - tmp3 = L_shr( tmp3, guard_bits + 1 ); // outputSptr_Q + outputPptr_Q - 31 - guard_bits + tmp3 = L_shr( tmp3, add( guard_bits, 1 ) ); // outputSptr_Q + outputPptr_Q - 31 - guard_bits dotPS_fx = L_add( dotPS_fx, tmp3 ); } Word32 Var1 = Mpy_32_32( enrP_fx, enrS_fx ); // 2*( outputPptr_Q - 31 - guard_bits + outputSptr_Q - 31 - guard_bits ) - Word16 exp = 31 - ( 2 * ( outputPptr_Q - 31 - guard_bits + outputSptr_Q - 31 - guard_bits ) ); + Word16 exp = sub( 31, shl( add( sub( sub( outputPptr_Q, 31 ), guard_bits ), sub( sub( outputSptr_Q, 31 ), guard_bits ) ), 1 ) ); - IF( Var1 == 0 ) + if ( Var1 == 0 ) { Var1 = 1; + move32(); } Word32 Var2, Var3; @@ -1570,26 +1645,37 @@ void stereo_cng_compute_PScorr_fx( Var3 = L_add( dotPS_fx, 1 ); /*adding one in order to make temp non-zero. q = Q_outputSptr + Q_outputPptr - guard_bits*/ c_PS_fx = Mpy_32_32( Var3, Var2 ); /* outputSptr_Q + outputPptr_Q - guard_bits - exp */ - Word16 c_PS_fx_Q = outputSptr_Q + outputPptr_Q - guard_bits - exp - 31; + Word16 c_PS_fx_Q = add( outputSptr_Q, sub( sub( sub( outputPptr_Q, guard_bits ), exp ), 31 ) ); Word32 a = 0, b = 0; + move32(); + move32(); Word16 a_q = 0, b_q = 0, ab_q = 0; + move16(); + move16(); + move16(); a = Mpy_32_32( c_PS_fx, ONE_MINUS_STEREO_TD_PS_CORR_FILT_Q31 ); // Q(c_PS_fx_Q) a_q = c_PS_fx_Q; + move16(); b = Mpy_32_32( STEREO_TD_PS_CORR_FILT_Q31, *c_PS_LT_fx ); // Q(Q_c_PS_LT_fx) b_q = Q_c_PS_LT_fx; + move16(); IF( GT_16( a_q, b_q ) ) { - ab_q = a_q - b_q; - *c_PS_LT_fx = L_add( L_shr( a, (Word16) ab_q ), b ); + ab_q = sub( a_q, b_q ); + *c_PS_LT_fx = L_add( L_shr( a, ab_q ), b ); + move32(); Q_c_PS_LT_fx = b_q; + move16(); } ELSE IF( LT_16( b_q, a_q ) ) { - ab_q = b_q - a_q; - *c_PS_LT_fx = L_add( a, L_shr( b, (Word16) ab_q ) ); + ab_q = sub( b_q, a_q ); + *c_PS_LT_fx = L_add( a, L_shr( b, ab_q ) ); + move32(); Q_c_PS_LT_fx = a_q; + move16(); } return; @@ -1700,8 +1786,8 @@ static void stereo_cng_compute_LRcorr( static void stereo_cng_compute_LRcorr_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const int16_t output_frame, /* i : Output frame length */ - const int16_t tdm_ratio_idx /* i : TDM ratio index */ + const Word16 output_frame, /* i : Output frame length */ + const Word16 tdm_ratio_idx /* i : TDM ratio index */ ) { Word16 i; @@ -1723,139 +1809,169 @@ static void stereo_cng_compute_LRcorr_fx( beta_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; enrL_fx = 0; + move64(); enrR_fx = 0; + move64(); dotLR_fx = 0; + move64(); FOR( i = 0; i < output_frame; i++ ) { - - enrL_fx += ( (Word64) output_fx[0][i] ) * ( output_fx[0][i] ); - enrR_fx += ( (Word64) output_fx[1][i] ) * ( output_fx[1][i] ); - dotLR_fx += ( ( (Word64) output_fx[0][i] ) * ( output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); } - dotLR_fx = dotLR_fx + EPSILON_FX_SMALL; - IF( dotLR_fx < 0 ) + dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); + if ( dotLR_fx < 0 ) { dotLR_fx = W_neg( dotLR_fx ); } - enrL_fx = enrL_fx + EPSILON_FX_SMALL; - enrR_fx = enrR_fx + EPSILON_FX_SMALL; + enrL_fx = W_add( enrL_fx, EPSILON_FX_SMALL ); + enrR_fx = W_add( enrR_fx, EPSILON_FX_SMALL ); headroom_left_enrL = W_norm( enrL_fx ); headroom_left_enrR = W_norm( enrR_fx ); { - IF( headroom_left_enrL < 32 ) + IF( LT_16( headroom_left_enrL, 32 ) ) { - enrL_fx = W_shr( enrL_fx, ( 32 - headroom_left_enrL ) ); - enrL_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_enrL ) ) ); + enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_enrL ) ); + enrL_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_enrL ) ) ); } ELSE { - enrL_q = 31 - ( 2 * OUTPUT_Q ); + enrL_q = sub( 31, ( 2 * OUTPUT_Q ) ); } - IF( headroom_left_enrR < 32 ) + IF( LT_16( headroom_left_enrR, 32 ) ) { - enrR_fx = W_shr( enrR_fx, ( 32 - headroom_left_enrR ) ); - enrR_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_enrR ) ) ); + enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_enrR ) ); + enrR_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_enrR ) ) ); } ELSE { - enrR_q = 31 - ( 2 * OUTPUT_Q ); + enrR_q = sub( 31, ( 2 * OUTPUT_Q ) ); } enrL_inv_q = enrL_q; + move16(); enrR_inv_q = enrR_q; + move16(); - temp_x_inv = ISqrt32( (Word32) enrL_fx, &enrL_inv_q ); - temp_y_inv = ISqrt32( (Word32) enrR_fx, &enrR_inv_q ); + temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &enrL_inv_q ); + temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &enrR_inv_q ); energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); - res_q = enrL_inv_q + enrR_inv_q; + res_q = add( enrL_inv_q, enrR_inv_q ); headroom_left_dotLR = W_norm( dotLR_fx ); dotLR_q = OUTPUT_Q * 2; - IF( headroom_left_dotLR < 32 ) + move16(); + IF( LT_16( headroom_left_dotLR, 32 ) ) { - dotLR_fx = W_shr( dotLR_fx, 32 - headroom_left_dotLR ); - dotLR_q = dotLR_q - ( 32 - headroom_left_dotLR ); + dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR ) ); + dotLR_q = sub( dotLR_q, sub( 32, headroom_left_dotLR ) ); } - dotLR_fx = Mpy_32_32( (Word32) dotLR_fx, energy_xy_fx ); - dotLR_q = dotLR_q + ( 31 - res_q ) - 31; - dotLR_fx = W_shl( dotLR_fx, 31 - dotLR_q ); + dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); + dotLR_q = add( dotLR_q, sub( sub( 31, res_q ), 31 ) ); + dotLR_fx = W_shl( dotLR_fx, sub( 31, dotLR_q ) ); } - c_LR_fx = extract_h( (Word32) dotLR_fx ); + c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); Word16 div_q = 0; - c_fx = BASOP_Util_Divide3232_Scale( (Word32) enrL_fx, (Word32) enrR_fx, &div_q ); - c_q = 15 - div_q + ( enrR_q - enrL_q ); + move16(); + c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &div_q ); + c_q = add( sub( 15, div_q ), sub( enrR_q, enrL_q ) ); hCPE->hStereoTD->c_LR_LT_fx = L_add( Mpy_32_32( STEREO_TD_PS_CORR_FILT_FX, hCPE->hStereoTD->c_LR_LT_fx ), - Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( (Word16) c_LR_fx ) ) ); + Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( extract_l( c_LR_fx ) ) ) ); + move32(); hCPE->hStereoCng->c_LR_LT_fx = hCPE->hStereoTD->c_LR_LT_fx; + move32(); - Word16 sqrt_q = 31 - c_q; + Word16 sqrt_q = sub( 31, c_q ); Word32 sqrt_res = Sqrt32( c_fx, &sqrt_q ); tmp_fx = Mpy_32_32( beta_fx, L_sub( ONE_IN_Q31, beta_fx ) ); tmp_fx = Mpy_32_32( tmp_fx, hCPE->hStereoTD->c_LR_LT_fx ); tmp_fx = Mpy_32_32( tmp_fx, sqrt_res ); - Word16 tmp_q = ( 31 - sqrt_q ) - 1; // *2 handled with q reduction + Word16 tmp_q = sub( sub( 31, sqrt_q ), 1 ); // *2 handled with q reduction beta_sqr = Mpy_32_32( beta_fx, beta_fx ); one_minus_beta_sqr = Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), L_sub( ONE_IN_Q31, beta_fx ) ); - numer_1 = Mpy_32_16_1( one_minus_beta_sqr, (Word16) c_fx ); // c_q+31-15 - numer_1_q = c_q + 31 - 15; + numer_1 = Mpy_32_16_1( one_minus_beta_sqr, extract_l( c_fx ) ); // c_q+31-15 + numer_1_q = add( c_q, 31 - 15 ); numer_2 = beta_sqr; // 31 + move32(); numer_2_q = 31; + move16(); numer_3 = tmp_fx; // tmp_q + move32(); numer_3_q = tmp_q; + move16(); num_q = 31; - num_q = num_q < numer_1_q ? num_q : numer_1_q; - num_q = num_q < numer_2_q ? num_q : numer_2_q; - num_q = num_q < numer_3_q ? num_q : numer_3_q; + move16(); + + num_q = s_min( num_q, numer_1_q ); + + num_q = s_min( num_q, numer_2_q ); + num_q = s_min( num_q, numer_3_q ); - denom_1 = Mpy_32_16_1( beta_sqr, (Word16) c_fx ); // c_q+31-15; - denom_1_q = c_q + 31 - 15; + denom_1 = Mpy_32_16_1( beta_sqr, extract_l( c_fx ) ); // c_q+31-15; + denom_1_q = add( c_q, 31 - 15 ); denom_2 = one_minus_beta_sqr; // 31 + move32(); denom_2_q = 31; + move16(); denom_3 = tmp_fx; // tmp_q + move32(); denom_3_q = tmp_q; + move16(); denom_q = 31; - denom_q = denom_q < denom_1_q ? denom_q : denom_1_q; - denom_q = denom_q < denom_2_q ? denom_q : denom_2_q; - denom_q = denom_q < denom_3_q ? denom_q : denom_3_q; + move16(); + + denom_q = s_min( denom_q, denom_1_q ); + + denom_q = s_min( denom_q, denom_2_q ); + + denom_q = s_min( denom_q, denom_3_q ); - num = L_add( L_shr( numer_1, numer_1_q - num_q ), L_sub( L_shr( numer_2, numer_2_q - num_q ), L_shr( numer_3, numer_3_q - num_q ) ) ) + DELTA_FX; - denom = L_add( L_shr( denom_1, denom_1_q - denom_q ), L_add( L_shr( denom_2, denom_2_q - denom_q ), L_shr( denom_3, denom_3_q - denom_q ) ) ) + DELTA_FX; + num = L_add( L_add( L_shr( numer_1, sub( numer_1_q, num_q ) ), L_sub( L_shr( numer_2, sub( numer_2_q, num_q ) ), L_shr( numer_3, sub( numer_3_q, num_q ) ) ) ), DELTA_FX ); + denom = L_add( L_add( L_shr( denom_1, sub( denom_1_q, denom_q ) ), L_add( L_shr( denom_2, sub( denom_2_q, denom_q ) ), L_shr( denom_3, sub( denom_3_q, denom_q ) ) ) ), DELTA_FX ); Word16 q = 0; + move16(); sc_fx = BASOP_Util_Divide3232_Scale( num, denom, &q ); - sc_q = 15 - ( num_q - denom_q ) - q; + sc_q = sub( sub( 15, sub( num_q, denom_q ) ), q ); Word32 sc_thr = L_shr( sc_fx, sc_q ); - IF( sc_thr > 4 ) + IF( GT_32( sc_thr, 4 ) ) { sc_fx = MAX_WORD16; + move32(); } ELSE { - sc_fx = L_shr( sc_fx, sc_q - 13 ); + sc_fx = L_shr( sc_fx, sub( sc_q, 13 ) ); } sqrt_q = 2; + move16(); sqrt_res = Sqrt32( L_shl_sat( sc_fx, 16 ), &sqrt_q ); IF( sqrt_q < 0 ) { - sqrt_res = L_shr( sqrt_res, -1 * sqrt_q ); + sqrt_res = L_shr( sqrt_res, ( -sqrt_q ) ); sqrt_q = 0; + move16(); } hCPE->hStereoTD->SP_ratio_LT_fx = L_add_sat( Mpy_32_32( 1932735283, hCPE->hStereoTD->SP_ratio_LT_fx ), L_shl_sat( Mpy_32_32( 214748364, sqrt_res ), sqrt_q ) ); + move32(); - IF( hCPE->hStereoCng->nr_corr_frames < CM_INIT ) + IF( LT_16( hCPE->hStereoCng->nr_corr_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_corr_frames++; + hCPE->hStereoCng->nr_corr_frames = add( hCPE->hStereoCng->nr_corr_frames, 1 ); + move16(); } hCPE->hStereoCng->nr_dft_frames = 0; + move16(); return; } @@ -1916,51 +2032,58 @@ static void FindEmEs_fx( Word16 headroom_left_ener_fx, headroom_left_ener_side_fx; Word16 ener_q, ener_side_q; ener_fx = 1; + move64(); ener_side_fx = 1; + move64(); Word32 square_res, log_res, division_res; Word16 temp_q = 0; - for ( i = 0; i < len; i++ ) + move16(); + FOR( i = 0; i < len; i++ ) { mono_i_fx = L_add( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_fx = W_add( ener_fx, ( (Word64) mono_i_fx * mono_i_fx ) ); + ener_fx = W_add( ener_fx, W_mult0_32_32( mono_i_fx, mono_i_fx ) ); side_i_fx = L_sub( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_side_fx = W_add( ener_side_fx, ( (Word64) side_i_fx * side_i_fx ) ); + ener_side_fx = W_add( ener_side_fx, W_mult0_32_32( side_i_fx, side_i_fx ) ); } headroom_left_ener_fx = W_norm( ener_fx ); headroom_left_ener_side_fx = W_norm( ener_side_fx ); - IF( headroom_left_ener_fx < 32 ) + IF( LT_16( headroom_left_ener_fx, 32 ) ) { - ener_fx = W_shr( ener_fx, ( 32 - headroom_left_ener_fx ) ); - ener_q = ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_ener_fx ) ); + ener_fx = W_shr( ener_fx, sub( 32, headroom_left_ener_fx ) ); + ener_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_fx ) ); } ELSE { ener_q = ( 2 * OUTPUT_Q ); + move16(); } - IF( headroom_left_ener_side_fx < 32 ) + IF( LT_16( headroom_left_ener_side_fx, 32 ) ) { - ener_side_fx = W_shr( ener_side_fx, ( 32 - headroom_left_ener_side_fx ) ); - ener_side_q = ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_ener_side_fx ) ); + ener_side_fx = W_shr( ener_side_fx, sub( 32, headroom_left_ener_side_fx ) ); + ener_side_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_side_fx ) ); } ELSE { ener_side_q = ( 2 * OUTPUT_Q ); + move16(); } /**es_em = 10 * ( log10( sqrt( ener_side / len ) ) - log10( sqrt( ener / len ) ) ); */ - division_res = BASOP_Util_Divide3232_Scale( (Word32) ener_side_fx, (Word32) ener_fx, &temp_q ); - temp_q = temp_q - ( ener_side_q - ener_q ); - square_res = Sqrt32( L_deposit_h( (Word16) division_res ), &temp_q ); + division_res = BASOP_Util_Divide3232_Scale( W_extract_l( ener_side_fx ), W_extract_l( ener_fx ), &temp_q ); + temp_q = sub( temp_q, sub( ener_side_q, ener_q ) ); + square_res = Sqrt32( L_deposit_h( extract_l( division_res ) ), &temp_q ); IF( temp_q < 0 ) { - square_res = L_shr( square_res, -1 * temp_q ); + square_res = L_shr( square_res, ( -temp_q ) ); temp_q = 0; + move16(); } log_res = BASOP_Util_Log2( square_res ); es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30 /* long-term estimate */ *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); + move32(); return; } #endif @@ -2086,11 +2209,11 @@ void stereo_cna_update_params( void stereo_cna_update_params_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const int16_t output_frame, /* i : Output frame length */ - const int16_t tdm_ratio_idx /* i : TDM ratio index */ + const Word16 output_frame, /* i : Output frame length */ + const Word16 tdm_ratio_idx /* i : TDM ratio index */ ) { - int16_t i; + Word16 i; Word64 enrL_fx, enrR_fx, dotLR_fx; Word32 c_fx, c_LR_fx, c_ILD_fx; Decoder_State **sts; @@ -2113,110 +2236,124 @@ void stereo_cna_update_params_fx( ///// - if ( hCPE->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - if ( hCPE->nchan_out > 1 ) + IF( GT_16( hCPE->nchan_out, 1 ) ) { FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); } - else + ELSE { hCPE->lt_es_em_fx = 0; + move32(); } } - else if ( hCPE->element_mode == IVAS_CPE_TD ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); hCPE->hStereoCng->first_SID_after_TD = 1; + move16(); stereo_cng_compute_LRcorr_fx( hCPE, output_fx, output_frame, tdm_ratio_idx ); } - else + ELSE { return; } enrL_fx = 0; + move64(); enrR_fx = 0; + move64(); dotLR_fx = 0; + move64(); - - if ( hCPE->element_mode == IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_DFT && sts[0]->core_brate > SID_2k40 && sts[0]->VAD == 0 ) ) + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_32( sts[0]->core_brate, SID_2k40 ) && ( sts[0]->VAD == 0 ) ) ) { - if ( hCPE->nchan_out == 1 ) + IF( EQ_16( hCPE->nchan_out, 1 ) ) { c_LR_fx = MAX_WORD16; + move32(); c_ILD_fx = 0; + move32(); } - else + ELSE { FOR( i = 0; i < output_frame; i++ ) { - - enrL_fx += ( (Word64) output_fx[0][i] ) * ( output_fx[0][i] ); - enrR_fx += ( (Word64) output_fx[1][i] ) * ( output_fx[1][i] ); - dotLR_fx += ( ( (Word64) output_fx[0][i] ) * ( output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); } - dotLR_fx = dotLR_fx + EPSILON_FX_SMALL; + dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); if ( dotLR_fx < 0 ) { dotLR_fx = W_neg( dotLR_fx ); } - enrL_fx = enrL_fx + EPSILON_FX_SMALL; - enrR_fx = enrR_fx + EPSILON_FX_SMALL; + enrL_fx = W_add( enrL_fx, EPSILON_FX_SMALL ); + enrR_fx = W_add( enrR_fx, EPSILON_FX_SMALL ); headroom_left_x = W_norm( enrL_fx ); headroom_left_y = W_norm( enrR_fx ); - IF( headroom_left_x < 32 ) + IF( LT_16( headroom_left_x, 32 ) ) { - enrL_fx = W_shr( enrL_fx, ( 32 - headroom_left_x ) ); - x_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_x ) ) ); + enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_x ) ); + x_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ); } ELSE { - x_q = 31 - ( 2 * OUTPUT_Q ); + x_q = sub( 31, ( 2 * OUTPUT_Q ) ); } - IF( headroom_left_y < 32 ) + IF( LT_16( headroom_left_y, 32 ) ) { - enrR_fx = W_shr( enrR_fx, ( 32 - headroom_left_y ) ); - y_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_y ) ) ); + enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_y ) ); + y_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_y ) ) ); } ELSE { - y_q = 31 - ( 2 * OUTPUT_Q ); + y_q = sub( 31, ( 2 * OUTPUT_Q ) ); } x_inv_q = x_q; + move16(); y_inv_q = y_q; + move16(); - temp_x_inv = ISqrt32( (Word32) enrL_fx, &x_inv_q ); - temp_y_inv = ISqrt32( (Word32) enrR_fx, &y_inv_q ); + temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &x_inv_q ); + temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &y_inv_q ); energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); - temp_res_q = x_inv_q + y_inv_q; + temp_res_q = add( x_inv_q, y_inv_q ); headroom_left_dotLR_fx = W_norm( dotLR_fx ); dotLR_fx_q = OUTPUT_Q * 2; - IF( headroom_left_dotLR_fx < 32 ) + move16(); + IF( LT_16( headroom_left_dotLR_fx, 32 ) ) { - dotLR_fx = W_shr( dotLR_fx, 32 - headroom_left_dotLR_fx ); - dotLR_fx_q = dotLR_fx_q - ( 32 - headroom_left_dotLR_fx ); + dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR_fx ) ); + dotLR_fx_q = sub( dotLR_fx_q, sub( 32, headroom_left_dotLR_fx ) ); } - dotLR_fx = Mpy_32_32( (Word32) dotLR_fx, energy_xy_fx ); - dotLR_fx_q = dotLR_fx_q + ( 31 - temp_res_q ) - 31; - dotLR_fx = (Word64) L_shl_sat( (Word32) dotLR_fx, 31 - dotLR_fx_q ); + dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); + dotLR_fx_q = add( dotLR_fx_q, sub( sub( 31, temp_res_q ), 31 ) ); + dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); /* estimate L/R correlation factor and ILD in time domain */ - c_LR_fx = extract_h( (Word32) dotLR_fx ); + c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); temp_res_q = 0; - c_fx = BASOP_Util_Divide3232_Scale( (Word32) enrL_fx, (Word32) enrR_fx, &temp_res_q ); - c_q = 15 - temp_res_q + ( y_q - x_q ); + move16(); + c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &temp_res_q ); + c_q = add( sub( 15, temp_res_q ), sub( y_q, x_q ) ); Word32 one_in_c_q; IF( GT_16( c_q, 31 ) ) { c_q = 31; - c_fx = L_shr_sat( c_fx, c_q - 31 ); + move16(); + c_fx = L_shr_sat( c_fx, sub( c_q, 31 ) ); one_in_c_q = ONE_IN_Q31; + move32(); } ELSE { @@ -2227,28 +2364,34 @@ void stereo_cna_update_params_fx( Word32 denom_c_fx = L_add_sat( c_fx, one_in_c_q ); Word16 num_c_headroom = norm_l( L_sub_sat( c_fx, one_in_c_q ) ); Word16 denom_c_headroom = norm_l( L_add_sat( c_fx, one_in_c_q ) ); - Word16 min_headroom_left = num_c_headroom < denom_c_headroom ? num_c_headroom : denom_c_headroom; + Word16 min_headroom_left = s_min( num_c_headroom, denom_c_headroom ); + move16(); temp_res_q = 0; + move16(); c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); - if ( temp_res_q < 0 ) + IF( temp_res_q < 0 ) { - c_ILD_fx = L_shr( c_ILD_fx, -1 * temp_res_q ); + c_ILD_fx = L_shr( c_ILD_fx, negate( temp_res_q ) ); } } /* update of long-term ILD and LR correlation factors for stereo CNA */ - if ( !hFdCngDec->first_cna_noise_updated ) + IF( !hFdCngDec->first_cna_noise_updated ) { - hFdCngDec->cna_LR_LT_fx = (Word16) c_LR_fx; - hFdCngDec->cna_ILD_LT_fx = (Word16) c_ILD_fx; + hFdCngDec->cna_LR_LT_fx = extract_l( c_LR_fx ); + move16(); + hFdCngDec->cna_ILD_LT_fx = extract_l( c_ILD_fx ); + move16(); } - else + ELSE { hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), (Word16) c_LR_fx ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); + move16(); hFdCngDec->cna_ILD_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), (Word16) c_ILD_fx ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), extract_l( c_ILD_fx ) ) ) ); + move16(); } set16_fx( hFdCngDec->cna_g_state_fx, hFdCngDec->cna_ILD_LT_fx, hFdCngDec->cna_nbands ); @@ -2257,33 +2400,37 @@ void stereo_cna_update_params_fx( /* Soft VAD for stereo CNA */ - if ( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_DFT ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - if ( !hFdCngDec->first_cna_noise_updated ) + IF( !hFdCngDec->first_cna_noise_updated ) { hFdCngDec->cna_act_fact_fx = 0; + move16(); } - else + ELSE { - if ( hCPE->element_mode == IVAS_CPE_TD ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* quickly decrease in TD stereo mode */ hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); + move16(); } - else if ( ( sts[0]->VAD * MAX_WORD16 ) > hFdCngDec->cna_act_fact_fx ) // VAD is one bit + ELSE IF( GT_32( L_mult0( sts[0]->VAD, MAX_WORD16 ), hFdCngDec->cna_act_fact_fx ) ) // VAD is one bit { /* quickly increase during active frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) + ( 644245094 * sts[0]->VAD ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ), ( 644245094 * sts[0]->VAD ) ) ); + move16(); } - else + ELSE { /* slowly decrease during inactive frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ) + ( 107374184 * sts[0]->VAD ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ), ( 107374184 * sts[0]->VAD ) ) ); + move16(); } } } - return; } #endif @@ -2355,8 +2502,8 @@ void stereo_cng_init_dec_fx( hStereoCng->enableSecCNA = 0; move16(); hStereoCng->c_PS_LT_fx = 16384; /* 0.5 in Q15 */ - hStereoCng->frameSize = frameSize; move16(); + hStereoCng->frameSize = frameSize; hStereoCng->last_act_element_mode = IVAS_CPE_DFT; move16(); diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index daa92a594b572c8c919b5236c3a4e987e89ed8e1..0a644465cc0c716f03331caa0f6c45f280b7c097 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -38,7 +38,7 @@ #include "rom_com.h" #include "rom_dec.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -47,7 +47,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*-------------------------------------------------------------------* * Local constants @@ -695,20 +695,21 @@ void stereo_dft_dec_analyze_fx( * Initialization *-----------------------------------------------------------------*/ - IF( input_frame == output_frame ) + IF( EQ_16( input_frame, output_frame ) ) { trigo_fx = hStereoDft->dft_trigo_fx; - trigo_step = hStereoDft->dft_trigo_step * STEREO_DFT_TRIGO_DEC_STEP; + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); win_right_fx = hStereoDft->win32ms_fx; win_left_fx = hStereoDft->win32ms_fx; win2_fx = hStereoDft->win232ms_fx; - IF( ana_type == DFT_STEREO_DEC_ANA_BPF ) + test(); + IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); mem_fx = hCPE->input_mem_BPF_fx[chan]; } - ELSE IF( ana_type == DFT_STEREO_DEC_ANA_LB || ana_type == DFT_STEREO_DEC_ANA_LB_ADD ) + ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { mem_fx = hCPE->input_mem_LB_fx[chan]; } @@ -717,20 +718,22 @@ void stereo_dft_dec_analyze_fx( mem_fx = hCPE->input_mem_fx[chan]; } } - ELSE IF( input_frame == L_FRAME ) + ELSE IF( EQ_16( input_frame, L_FRAME ) ) { trigo_fx = hStereoDft->dft_trigo_12k8_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); win_right_fx = hStereoDft->win32ms_12k8_fx; win_left_fx = hStereoDft->win32ms_12k8_fx; win2_fx = hStereoDft->win232ms_12k8_fx; - IF( ana_type == DFT_STEREO_DEC_ANA_BPF ) + test(); + IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); mem_fx = hCPE->input_mem_BPF_fx[chan]; } - ELSE IF( ana_type == DFT_STEREO_DEC_ANA_LB || ana_type == DFT_STEREO_DEC_ANA_LB_ADD ) + ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { mem_fx = hCPE->input_mem_LB_fx[chan]; } @@ -740,34 +743,37 @@ void stereo_dft_dec_analyze_fx( mem_fx = hCPE->input_mem_fx[chan]; } } - ELSE IF( input_frame == L_FRAME16k ) + ELSE IF( EQ_16( input_frame, L_FRAME16k ) ) { trigo_fx = hStereoDft->dft_trigo_16k_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); win_right_fx = hStereoDft->win32ms_16k_fx; win_left_fx = hStereoDft->win32ms_16k_fx; win2_fx = hStereoDft->win232ms_16k_fx; - IF( ana_type == DFT_STEREO_DEC_ANA_BPF ) + test(); + IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); mem_fx = hCPE->input_mem_BPF_fx[chan]; } - ELSE IF( ana_type == DFT_STEREO_DEC_ANA_LB || ana_type == DFT_STEREO_DEC_ANA_LB_ADD ) + ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { mem_fx = hCPE->input_mem_LB_fx[chan]; } ELSE { - assert( ( chan == 1 ) && hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF && "16kHz sampling rate only FOR second channel with allpass signal" ); + assert( ( chan == 1 ) && ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) && "16kHz sampling rate only FOR second channel with allpass signal" ); mem_fx = hCPE->input_mem_fx[chan]; } } - ELSE IF( input_frame == L_FRAME8k ) + ELSE IF( EQ_16( input_frame, L_FRAME8k ) ) { assert( ( chan == 1 ) && "DFT stereo: 8kHz analysis only FOR residual coding" ); trigo_fx = hStereoDft->dft_trigo_8k_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); win_right_fx = hStereoDft->win32ms_8k_fx; win_left_fx = hStereoDft->win32ms_8k_fx; win2_fx = hStereoDft->win232ms_8k_fx; @@ -776,27 +782,32 @@ void stereo_dft_dec_analyze_fx( ELSE { IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error in DFT stereo: sampling rate not supported" ); - mem_fx = NULL; /* to avoid compilation warning */ - trigo_fx = NULL; /* to avoid compilation warning */ - trigo_step = -1; /* to avoid compilation warning */ + mem_fx = NULL; /* to avoid compilation warning */ + trigo_fx = NULL; /* to avoid compilation warning */ + trigo_step = -1; /* to avoid compilation warning */ + move16(); win_right_fx = NULL; /* to avoid compilation warning */ win_left_fx = NULL; /* to avoid compilation warning */ win2_fx = NULL; /* to avoid compilation warning */ } - inputFs = input_frame * FRAMES_PER_SEC; + inputFs = L_mult0( input_frame, FRAMES_PER_SEC ); delay_dec = NS2SA( inputFs, STEREO_DFT32MS_OVL_NS ); + move16(); zp = NS2SA( inputFs, STEREO_DFT32MS_ZP_NS ); + move16(); ovl = NS2SA( inputFs, STEREO_DFT32MS_OVL_NS ); + move16(); NFFT = NS2SA( inputFs, STEREO_DFT32MS_N_NS ); Word16 qfac_fx; fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); qfac_fx = sub( 31, qfac_fx ); ovl2 = NS2SA( inputFs, STEREO_DFT32MS_OVL2_NS ); + move16(); /* Offset FOR the time buffers */ - assert( ( delay >= -NS2SA( input_frame * FRAMES_PER_SEC, STEREO_DFT_DELAY_DEC_BWE_NS + STEREO_DFT_OVL_NS / 2 ) ) && ( delay <= NS2SA( input_frame * FRAMES_PER_SEC, STEREO_DFT_OVL_NS ) ) ); - mem_size = delay_dec + delay; + assert( ( delay >= -NS2SA( ( input_frame * FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS + STEREO_DFT_OVL_NS / 2 ) ) && ( delay <= NS2SA( ( input_frame * FRAMES_PER_SEC ), STEREO_DFT_OVL_NS ) ) ); + mem_size = add( delay_dec, delay ); /* Update buffers */ Copy32( mem_fx, input_buff_fx, mem_size ); @@ -804,7 +815,8 @@ void stereo_dft_dec_analyze_fx( Copy32( input_buff_fx + input_frame, mem_fx, mem_size ); pInput_buff_fx = input_buff_fx; - IF( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && ( hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) { pop_wmops(); return; @@ -815,145 +827,176 @@ void stereo_dft_dec_analyze_fx( * DFT Analysis: loop over frame *-----------------------------------------------------------------*/ - assert( k_offset <= STEREO_DFT_NBDIV ); + assert( ( k_offset <= STEREO_DFT_NBDIV ) ); - FOR( i = 0; i < NFFT / 4; i++ ) + FOR( i = 0; i < shr( NFFT, 2 ); i++ ) { - trigo_dec_fx[i] = trigo_fx[i * trigo_step]; - trigo_dec_fx[NFFT / 2 - i] = trigo_fx[i * trigo_step]; + trigo_dec_fx[i] = trigo_fx[i_mult( i, trigo_step )]; + move16(); + trigo_dec_fx[sub( NFFT / 2, i )] = trigo_fx[i_mult( i, trigo_step )]; + move16(); } - trigo_dec_fx[NFFT / 4] = trigo_fx[NFFT / 4 * trigo_step]; + trigo_dec_fx[NFFT / 4] = trigo_fx[i_mult( NFFT / 4, trigo_step )]; + move16(); - FOR( k = 0; k < STEREO_DFT_NBDIV - k_offset; k++ ) + FOR( k = 0; k < sub( STEREO_DFT_NBDIV, k_offset ); k++ ) { set32_fx( DFT_fx, 0, STEREO_DFT32MS_N_MAX ); IF( k == 0 ) { offset = 0; + move16(); } ELSE { /* If OVL2 = OVL offset = 10ms */ offset = NS2SA( inputFs, STEREO_DFT32MS_WIN_CENTER_NS - STEREO_DFT32MS_OVL2_NS / 2 ); + move16(); } pInput_fx = pInput_buff_fx + offset; - pDFT_out_fx = out_DFT_fx[chan] + k * STEREO_DFT32MS_N_MAX; + pDFT_out_fx = out_DFT_fx[chan] + i_mult( k, STEREO_DFT32MS_N_MAX ); /*Forwards FFT: L and R*/ /* Zero Padding & Flat Portion */ - Copy32( pInput_fx, DFT_fx + zp, NFFT - 2 * zp ); + Copy32( pInput_fx, DFT_fx + zp, sub( NFFT, i_mult( 2, zp ) ) ); /* Overlapping portions */ IF( k == 0 ) { FOR( i = 0; i < ovl; i++ ) { - DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win_left_fx[STEREO_DFT32MS_STEP * i] ); + DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win_left_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + move32(); } FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[NFFT - zp - 1 - i] = Mpy_32_16_1( DFT_fx[NFFT - zp - 1 - i], win2_fx[i] ); + DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )], win2_fx[i] ); + move32(); } } ELSE { FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win2_fx[i] ); + DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win2_fx[i] ); + move32(); } FOR( i = 0; i < ovl; i++ ) { - DFT_fx[NFFT - zp - i - 1] = Mpy_32_16_1( DFT_fx[NFFT - zp - i - 1], win_right_fx[STEREO_DFT32MS_STEP * i] ); + DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )], win_right_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + move32(); } } Word16 q_DFT, q_shift, guarded_bits; q_DFT = *q; + move16(); guarded_bits = find_guarded_bits_fx( NFFT ); - q_shift = L_norm_arr( DFT_fx, NFFT ) - guarded_bits; + q_shift = sub( L_norm_arr( DFT_fx, NFFT ), guarded_bits ); FOR( Word16 j = 0; j < NFFT; j++ ) { DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + move32(); } - q_DFT += q_shift; + q_DFT = add( q_DFT, q_shift ); rfft_fx( DFT_fx, trigo_dec_fx, NFFT, -1 ); - q_shift = L_norm_arr( DFT_fx, NFFT ) - ( 31 - qfac_fx ); + q_shift = sub( L_norm_arr( DFT_fx, NFFT ), sub( 31, qfac_fx ) ); FOR( Word16 j = 0; j < NFFT; j++ ) { DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + move32(); } - q_DFT += q_shift; - IF( q_out_DFT[chan] - q_DFT > 0 ) + q_DFT = add( q_DFT, q_shift ); + IF( sub( q_out_DFT[chan], q_DFT ) > 0 ) { - FOR( int j = 0; j < NFFT; j++ ) + FOR( Word32 j = 0; j < NFFT; j++ ) { - out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], q_out_DFT[chan] - q_DFT ); + out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], sub( q_out_DFT[chan], q_DFT ) ); + move32(); } q_out_DFT[chan] = q_DFT; + move16(); } ELSE { - FOR( int j = 0; j < NFFT; j++ ) + FOR( Word32 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shr( DFT_fx[j], q_DFT - q_out_DFT[chan] ); + DFT_fx[j] = L_shr( DFT_fx[j], sub( q_DFT, q_out_DFT[chan] ) ); + move32(); } q_DFT = q_out_DFT[chan]; + move16(); } /*Resampling: filtering+scaling*/ - IF( ana_type == DFT_STEREO_DEC_ANA_FB || ana_type == DFT_STEREO_DEC_ANA_LB || ana_type == DFT_STEREO_DEC_ANA_NOCORE ) + test(); + test(); + IF( ( ana_type == DFT_STEREO_DEC_ANA_FB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_NOCORE ) ) { - pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), 31 - qfac_fx ); /*DC*/ - IF( NFFT == hStereoDft->NFFT ) /*Nyquist*/ + pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ); /*DC*/ + move32(); + IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), 31 - qfac_fx ); + pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ); + move32(); } ELSE { pDFT_out_fx[1] = 0; + move32(); } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), 31 - qfac_fx ); + pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ); + move32(); } FOR( i = NFFT; i < hStereoDft->NFFT; i++ ) { pDFT_out_fx[i] = 0; + move32(); } } - ELSE IF( ana_type == DFT_STEREO_DEC_ANA_BPF ) + ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { - pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), 32 - qfac_fx ) ); + pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), sub( 32, qfac_fx ) ) ); + move32(); FOR( i = 1; i < STEREO_DFT_BPF_SIZE; i++ ) { - pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), 32 - qfac_fx ) ); - pDFT_out_fx[2 * i + 1] = L_sub( pDFT_out_fx[2 * i + 1], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i + 1], fac_fx ), dft_bpf_weights_fx[i] ), 32 - qfac_fx ) ); + pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + move32(); + pDFT_out_fx[add( 2 * i, 1 )] = L_sub( pDFT_out_fx[add( 2 * i, 1 )], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[add( 2 * i, 1 )], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + move32(); } } - ELSE IF( ana_type == DFT_STEREO_DEC_ANA_HB_ADD ) + ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_HB_ADD ) ) { - NFFT_core = NS2SA( hCPE->hCoreCoder[0]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_N_NS ); + NFFT_core = NS2SA( L_mult0( hCPE->hCoreCoder[0]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_N_NS ); + move16(); FOR( i = NFFT_core; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), 31 - qfac_fx ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + move32(); } } ELSE { - pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), 31 - qfac_fx ) ); /*DC*/ - IF( NFFT == hStereoDft->NFFT ) /*Nyquist*/ + pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ) ); /*DC*/ + move32(); + IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), 31 - qfac_fx ), pDFT_out_fx[1] ); + pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[1] ); + move32(); } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), 31 - qfac_fx ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + move32(); } } } @@ -2505,10 +2548,6 @@ void stereo_dft_dec_read_BS( hStereoDft->res_global_gain = ECSQ_dequantize_gain( I ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &hStereoDft->res_global_gain, 1, "float_res_global_gain.txt", NULL ); -#endif // DUMPS_ENABLED - ecsq_inst.config_index = 2 * hStereoDft->res_cod_mode[k_offset] - 1; ECSQ_decode( &ecsq_inst, hStereoDft->res_cod_line_max, dec ); @@ -2517,10 +2556,6 @@ void stereo_dft_dec_read_BS( set_zero( res_buf, STEREO_DFT_N_8k ); ECSQ_dequantize_vector( dec, hStereoDft->res_global_gain, hStereoDft->res_cod_line_max, res_buf ); - -#ifdef DUMPS_ENABLED - dbgwrite_txt( res_buf, hStereoDft->res_cod_line_max, "float_res_buf.txt", NULL ); -#endif // DUMPS_ENABLED } else { diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index 7250baa6b8fedfb20fe93dbf2b596a554cc0da55..bacc5a0abdaba8f318a3fafcb150bb3a67cf0e35 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -44,8 +44,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #endif diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 87831a269676c1b007324a2ffc0caa8a4f58e873..d981db15ef5d29ddc620e14ef3af4a40ba25a0e9 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -38,7 +38,7 @@ #include "rom_com.h" #include "rom_dec.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" @@ -49,7 +49,13 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "basop_util.h" -#include "prot_fx1.h" +#endif +#ifdef DEBUGGING +#include "debug.h" +#endif + + +#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants @@ -203,8 +209,11 @@ void stereo_dft_dec_reset_fx( set32_fx( hStereoDft->hb_stefi_sig_fx, 0, L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS ) ); set32_fx( hStereoDft->hb_nrg_fx, 0, STEREO_DFT_CORE_HIST_MAX ); set32_fx( hStereoDft->td_gain_fx, 0, STEREO_DFT_CORE_HIST_MAX ); +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + set16_fx( hStereoDft->q_td_gain, 0, STEREO_DFT_CORE_HIST_MAX ); +#else set32_fx( hStereoDft->q_td_gain, 0, STEREO_DFT_CORE_HIST_MAX ); - +#endif hStereoDft->q_dft = 0; move16(); @@ -334,7 +343,7 @@ static void stereo_dft_dec_open_fx( hStereoDft->win_8k_fx = dft_win_8k_fx; /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ - set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); + set16_fx( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); move16(); @@ -669,7 +678,11 @@ void stereo_dft_dec_update_fx( Copy32( hStereoDft->hb_stefi_sig_fx + output_frame, hStereoDft->hb_stefi_sig_fx, hStereoDft->hb_stefi_delay ); Copy32( hStereoDft->hb_nrg_fx, hStereoDft->hb_nrg_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); Copy32( hStereoDft->td_gain_fx, hStereoDft->td_gain_fx + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + Copy( hStereoDft->q_td_gain, hStereoDft->q_td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); +#else Copy32( hStereoDft->q_td_gain, hStereoDft->q_td_gain + 1, STEREO_DFT_CORE_HIST_MAX - 1 ); +#endif IF( sba_dirac_stereo_flag ) { @@ -740,7 +753,7 @@ void stereo_dft_dec_synthesize_fx( win2 = hStereoDft->win232ms_fx; p_DFT = DFT[chan]; - set_val_Word32( output, 0, NS2SA( outputFs, FRAME_SIZE_NS ) ); + set32_fx( output, 0, NS2SA( outputFs, FRAME_SIZE_NS ) ); /* deactivating the spectrum scrambling on active speech */ test(); @@ -1326,11 +1339,11 @@ void stereo_dft_dec_res_fx( /* flush memories when switching residual coding on */ IF( EQ_16( hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1], STEREO_DFT_RES_COD_OFF ) ) { - set_val_Word32( hCPE->hStereoDft->res_cod_mem_fx, 0, STEREO_DFT_OVL_8k ); + set32_fx( hCPE->hStereoDft->res_cod_mem_fx, 0, STEREO_DFT_OVL_8k ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; move16(); - set_val_Word32( hCPE->input_mem_fx[1], 0, NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) ); - set_val_Word16( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); + set32_fx( hCPE->input_mem_fx[1], 0, NS2SA( 8000, STEREO_DFT32MS_OVL_NS ) ); + set16_fx( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0; move16(); } @@ -1407,7 +1420,7 @@ void stereo_dft_dec_res_fx( } ELSE IF( hCPE->hCoreCoder[0]->last_core == ACELP_CORE ) { - set_val_Word16( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); + set16_fx( hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, STEREO_DFT_NBPSF_PIT_MAX_8k ); hCPE->hStereoDft->hBpf->pst_mem_deemp_err_fx = 0; move16(); Copy_Scale_sig_16_32( out_16, output, L_FRAME8k, 16 ); @@ -2153,7 +2166,7 @@ void stereo_dft_dec_fx( move16(); } l_gamma = L_deposit_l( gamma ); - op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult( g, g ) ) ), q_gamma ) ); + op1 = L_add( l_gamma, L_shr( L_deposit_l( sub( MAX_16, mult_sat( g, g ) ) ), q_gamma ) ); /*The mult_sat function is needed because -0.999979973 is being mapped to -32768. This value, when multiplied by -32768, is causing a crash.*/ q_loc2 = add( Q16, q_gamma ); q_loc1 = q_loc2; move16(); @@ -2853,7 +2866,7 @@ void stereo_dft_generate_res_pred_fx( dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); } - hStereoDft->hb_nrg_fx[0] = dmx_nrg, L_shr( hStereoDft->NFFT, 1 ); + hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); move32(); *stop = bin0; move16(); @@ -3668,7 +3681,7 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { - itd_mode = get_next_indice( st, STEREO_DFT_ITD_MODE_NBITS ); + itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit*/ hStereoDft->itd_fx[k + k_offset] = 0; @@ -3773,7 +3786,7 @@ void stereo_dft_dec_read_BS_fx( /* Read bit for adaptive SF (WB/SWB & FB) */ IF( EQ_16( hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - hStereoDft->reverb_flag = get_next_indice( st, STEREO_DFT_REVERB_MODE_NBITS ); + hStereoDft->reverb_flag = get_next_indice_fx( st, STEREO_DFT_REVERB_MODE_NBITS ); ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_REVERB_MODE_NBITS ); nb = add( nb, STEREO_DFT_REVERB_MODE_NBITS ); IF( hStereoDft->reverb_flag ) @@ -3927,9 +3940,9 @@ void stereo_dft_dec_read_BS_fx( rc_uni_dec_init_fx( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); hStereoDft->res_global_gain_fx = ECSQ_dequantize_gain_fx( I ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &hStereoDft->res_global_gain, 1, "fixed_res_global_gain.txt", NULL ); -#endif // DUMPS_ENABLED +#ifdef DEBUGGING + dbgwrite_txt( (const float *) ( &hStereoDft->res_global_gain_fx ), 1, "fixed_res_global_gain.txt", NULL ); +#endif ecsq_inst.config_index = sub( shl( hStereoDft->res_cod_mode[k_offset], 1 ), 1 ); @@ -3947,9 +3960,9 @@ void stereo_dft_dec_read_BS_fx( ECSQ_dequantize_vector_fx( dec, hStereoDft->res_global_gain_fx, hStereoDft->res_cod_line_max, res_buf_fx ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( res_buf, hStereoDft->res_cod_line_max, "fixed_res_buf.txt", NULL ); -#endif // DUMPS_ENABLED +#ifdef DEBUGGING + dbgwrite_txt( (const float *) res_buf_fx, hStereoDft->res_cod_line_max, "fixed_res_buf.txt", NULL ); +#endif } ELSE { diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 5abf182fe903c9abefabe8efe7ed1641836ac2d7..e0cd69ef6f5d22cc03908bec7b40616ea8130326 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -34,8 +34,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index 62bbbcdda0c06825f3d650ac32da86ab0e3e05fc..e96f22c03dee22d9fbeec2842ad8a3de81c12cc3 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -41,7 +41,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop32.h" #include "ivas_stat_dec.h" diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index ca3159f3e576f1456bb7ba9781a9a6b805b8d28c..d5acccc7a47daf615b92c266d4f8da55523ad0f0 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -37,8 +37,7 @@ #include "cnst.h" #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "wmc_auto.h" @@ -555,9 +554,9 @@ static Word16 FindScale( void stereo_icBWE_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q_syn/Q_syn - 1 */ - Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q_syn/Q_syn - 1 */ - const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Qx */ + Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ + Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Q11 */ const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ const Word16 output_frame, /* i : frame length */ Word16 *Q_syn /* i : Q of synth and synthRef buffers */ @@ -579,7 +578,11 @@ void stereo_icBWE_dec_fx( Word16 temp1_fx, temp2_fx; Word16 icbweM2Ref_fx, ratio_L_fx; Word16 gsMapping_fx; +#ifndef FIX_826_PRECISION_LOST_AND_COMPL Word32 hb_nrg_fx, hb_nrg2_fx; +#else + Word32 hb_nrg_fx; +#endif Word16 Q_syn_shb; Word16 shift_prev_pow, synthRef_shift; Word32 L_tmp; @@ -627,7 +630,9 @@ void stereo_icBWE_dec_fx( { hb_nrg_fx = 0; move32(); +#ifndef FIX_826_PRECISION_LOST_AND_COMPL hb_nrg2_fx = 0; +#endif move32(); maximum_abs_32_fx( synthRef_fx, output_frame, &maxVal ); synthRef_shift = norm_l( maxVal ); @@ -636,17 +641,47 @@ void stereo_icBWE_dec_fx( synthRef_shift = 31; move16(); } +#ifndef FIX_826_PRECISION_LOST_AND_COMPL /* Not needed Q11 is already enough */ synthRef_shift = sub( synthRef_shift, shr( add( find_guarded_bits_fx( output_frame ), 1 ), 1 ) ); +#else + synthRef_shift = sub( synthRef_shift, shr( add( find_guarded_bits_fx( shr( output_frame, 1 ) ), 1 ), 1 ) ); +#endif test(); - IF( st->core == ACELP_CORE || st->last_core == ACELP_CORE ) + IF( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->last_core, ACELP_CORE ) ) { - FOR( i = 0; i < output_frame / 2; i++ ) +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + Word64 W_tmp = 0; + move64(); + tmp = shl_sat( 1, synthRef_shift ); +#endif + FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { // needed to be adjusted for q +#ifndef FIX_826_PRECISION_LOST_AND_COMPL L_tmp = L_shl( synthRef_fx[i], synthRef_shift ); hb_nrg2_fx = L_add( hb_nrg2_fx, Mpy_32_32( L_tmp, L_tmp ) ); // 2*(Qx + SynthRef_shift) - 31 +#else + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); +#endif + } +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + hb_nrg_fx = W_round48_L( W_tmp ); + hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; + move32(); + hStereoDft->q_hb_nrg_subr = sub( shl( add( *Q_syn, synthRef_shift ), 1 ), 45 ); + move16(); + W_tmp = 0; + move64(); + FOR( ; i < output_frame; i++ ) + { + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); } + hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2*(Qx + SynthRef_shift) - 45 + hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); +#else hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2_fx; move32(); hStereoDft->q_hb_nrg_subr = sub( add( *Q_syn, synthRef_shift ), 31 ); @@ -663,10 +698,13 @@ void stereo_icBWE_dec_fx( hCPE->hStereoDft->hb_nrg_subr_fx[1] = hb_nrg2_fx; // 2*(Qx + SynthRef_shift) - 31 move32(); hb_nrg_fx = L_add( hb_nrg_fx, hb_nrg2_fx ); +#endif - Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); + Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); +#ifndef FIX_826_PRECISION_LOST_AND_COMPL Scale_sig32( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame, -5 ); +#endif } ELSE { @@ -682,7 +720,11 @@ void stereo_icBWE_dec_fx( move32(); hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 move32(); +#ifndef FIX_826_PRECISION_LOST_AND_COMPL hCPE->hStereoDft->q_hb_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 40 ); +#else + hCPE->hStereoDft->q_hb_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 45 + 9 ); +#endif hCPE->hStereoDft->hb_nrg_fx[0] = hb_nrg_fx; // 2 * (Qx + SynthRef_shift) - 31 move32(); hCPE->hStereoDft->td_gain_fx[0] = 0; @@ -760,6 +802,7 @@ void stereo_icBWE_dec_fx( move16(); FOR( i = 0; i < winLen_fx; i++ ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), ( hStereoICBWE->icbweM2Ref_prev_fx ) ); // Q15 + Q14; tmp = shl( round_fx( L_tmp ), 1 ); // Q = 15 + 14 - 16 + 1 = Q14 @@ -774,6 +817,20 @@ void stereo_icBWE_dec_fx( { alpha_fx = add( alpha_fx, winSlope_fx ); } +#else + /*synthRef[i] *= ( alpha * ( icbweM2Ref ) + ( 1.0f - alpha ) * ( hStereoICBWE->icbweM2Ref_prev ) );*/ + temp1_fx = sub( 32767, alpha_fx ); + L_tmp = L_mult( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 + 1 + L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 +1 ; + synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); + move32(); + /*synth[i] *= ( alpha * ( gsMapping ) + ( 1.0f - alpha ) * ( prevgsMapping ) );*/ + L_tmp = L_mult( alpha_fx, gsMapping_fx ); + L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); + synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); + move32(); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); +#endif } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { @@ -1327,7 +1384,7 @@ void stereo_icBWE_dec_fx( #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 #else - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 @@ -1676,15 +1733,22 @@ void stereo_icBWE_decproc_fx( Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ const Word16 last_core, /* i : last core, primary channel */ const Word16 last_bwidth, /* i : last bandwidth */ - const Word16 output_frame, /* i : frame length */ - Word16 q_output /* i : Q-fac of output */ + const Word16 output_frame /* i : frame length */ +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + , + Word16 q_output /* i : Q-fac of output */ +#endif ) { Word16 i, j, n, decoderDelay, icbweOLASize, dftOvlLen; Word16 core, memOffset, refChanIndx_bwe; Word32 temp0_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )], temp1_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; +#if defined FIX_826_PRECISION_LOST_AND_COMPL + Word16 winSlope_fx = 0, alpha_fx; +#else Word32 winSlope_fx = 0, alpha_fx; +#endif move32(); const Word16 *win_dft_fx; Word32 extl_brate, output_Fs; @@ -1755,7 +1819,11 @@ void stereo_icBWE_decproc_fx( /* stereo to mono downmix */ FOR( i = 0; i < output_frame; i++ ) { +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + outputHB[0][i] = W_extract_h( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ) ); +#else outputHB[0][i] = L_shr( ( outputHB[0][i] + outputHB[1][i] ), 1 ); +#endif move32(); } v_add_32( output[0], outputHB[0], output[0], output_frame ); @@ -1810,6 +1878,20 @@ void stereo_icBWE_decproc_fx( { SWITCH( memOffset ) { +#if defined FIX_826_PRECISION_LOST_AND_COMPL + case 15: + winSlope_fx = 2185; + move32(); + BREAK; + case 30: + winSlope_fx = 1092; + move32(); + BREAK; + case 45: + winSlope_fx = 728; + move32(); + BREAK; +#else case 15: winSlope_fx = 71582792; move32(); @@ -1822,6 +1904,7 @@ void stereo_icBWE_decproc_fx( winSlope_fx = 23860930; move32(); BREAK; +#endif } // memOffset for 16K 32K 48K are 15 30 45 respectively.camera } @@ -1830,11 +1913,20 @@ void stereo_icBWE_decproc_fx( winSlope_fx = 0; move32(); } +#if defined FIX_826_PRECISION_LOST_AND_COMPL + alpha_fx = 0; + move16(); +#endif FOR( i = 0; i < memOffset; i++ ) { +#if defined FIX_826_PRECISION_LOST_AND_COMPL + alpha_fx = add_sat( alpha_fx, winSlope_fx ); + outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // +#else Word32 mul_win = Mpy_32_16_1( winSlope_fx, ( i + 1 ) ); // Q30 + Q0 - 15 = Q15 mul_win = L_shl( mul_win, 15 ); // Q30 outputHB[refChanIndx_bwe][i] = L_shl( Mpy_32_32( outputHB[refChanIndx_bwe][i] /* Q11 + Q30 - 31 = Q10)*/, mul_win ), 1 ); // +#endif move32(); } } @@ -1861,6 +1953,24 @@ void stereo_icBWE_decproc_fx( assert( icbweOLASize > 0 ); SWITCH( icbweOLASize ) { +#if defined FIX_826_PRECISION_LOST_AND_COMPL + case 60: + winSlope_fx = 546; + move16(); + BREAK; + case 40: + winSlope_fx = 819; + move16(); + BREAK; + case 20: + winSlope_fx = 1638; + move16(); + BREAK; + default: + fprintf( stderr, "icbweOLASize of size %d not implemented \n", icbweOLASize ); + assert( 0 ); + BREAK; +#else case 60: winSlope_fx = 17895698; move32(); @@ -1873,16 +1983,25 @@ void stereo_icBWE_decproc_fx( winSlope_fx = 53687092; move32(); BREAK; +#endif } alpha_fx = winSlope_fx; // Q30 move32(); FOR( ; i < add( decoderDelay, icbweOLASize ); i++ ) { +#if defined FIX_826_PRECISION_LOST_AND_COMPL + temp0_fx[i] = W_round48_L( W_mult_32_16( temp0_fx[i], alpha_fx ) ); // Q11 + move32(); + temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); + move32(); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); +#else temp0_fx[i] = L_shl_sat( Mpy_32_32( temp0_fx[i], alpha_fx ), 1 ); // Q11 move32(); temp1_fx[i] = L_shl_sat( Mpy_32_32( temp1_fx[i], alpha_fx ), 1 ); move32(); alpha_fx = L_add( alpha_fx, winSlope_fx ); +#endif } } ELSE @@ -1893,6 +2012,20 @@ void stereo_icBWE_decproc_fx( { SWITCH( memOffset ) { +#if defined FIX_826_PRECISION_LOST_AND_COMPL + case 15: + winSlope_fx = 2185; + move16(); + BREAK; + case 30: + winSlope_fx = 1092; + move16(); + BREAK; + case 45: + winSlope_fx = 728; + move16(); + BREAK; +#else case 15: winSlope_fx = 71582792; move32(); @@ -1905,6 +2038,7 @@ void stereo_icBWE_decproc_fx( winSlope_fx = 23860930; // Q30 move32(); BREAK; +#endif } // memOffset for 16K 32K 48K are 15 30 45 respectively.camera } @@ -1913,14 +2047,27 @@ void stereo_icBWE_decproc_fx( winSlope_fx = 0; move32(); } +#if defined FIX_826_PRECISION_LOST_AND_COMPL + Word16 Incr = 0; + Word16 Decr = MAX_16; +#endif + move16(); + move16(); FOR( i = 0; i < memOffset; i++ ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL temp0_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, 1 - ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ) ); move32(); temp1_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( 1 - ( i + 1 ) ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ) ); +#else + Incr = add_sat( Incr, winSlope_fx ); + Decr = sub( Decr, winSlope_fx ); + temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); + temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); +#endif move32(); } } @@ -1933,14 +2080,25 @@ void stereo_icBWE_decproc_fx( IF( EQ_16( hCPE->nchan_out, 1 ) ) { +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + Word64 W_tmp; +#endif /* stereo to mono downmix */ FOR( i = 0; i < output_frame; i++ ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL temp0_fx[i] = L_add( temp0_fx[i], temp1_fx[i] ); move32(); temp0_fx[i] = L_shr( temp0_fx[i], 1 ); move32(); output[0][i] = L_add( output[0][i], temp0_fx[i] ); +#else + W_tmp = W_mult_32_16( output[0][i], 32767 ); + W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 ); + output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 ) ); + move32(); + +#endif move32(); } } @@ -1961,26 +2119,53 @@ void stereo_icBWE_decproc_fx( move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ + +#ifndef FIX_826_PRECISION_LOST_AND_COMPL j = 0; move16(); +#else + j = sub( dftOvlLen, 1 ); +#endif FOR( i = 0; i < memOffset; i++ ) { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); move32(); hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); move32(); j = add( j, 1 ); +#else + Word16 tmp_mul = i_mult( STEREO_DFT32MS_STEP, j ); + hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); + move32(); + hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + move32(); + j = sub( j, 1 ); +#endif } +#ifndef FIX_826_PRECISION_LOST_AND_COMPL FOR( i = 0; j < dftOvlLen; i++ ) +#else + FOR( i = 0; i < dftOvlLen; i++ ) +#endif { +#ifndef FIX_826_PRECISION_LOST_AND_COMPL Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); move32(); hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); move32(); j = add( j, 1 ); +#else + Word16 tmp_mul = i_mult( STEREO_DFT32MS_STEP, j ); + hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); + move32(); + hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + move32(); + j = sub( j, 1 ); +#endif } } @@ -2035,8 +2220,12 @@ void stereo_icBWE_decproc_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && GT_32( L_max( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->td_gain_fx[1] ), 0 ) ) { +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + Word32 win_in_fx, win_out_fx, tmp_fx; + Word64 W_tmp, W_tmp1; +#else Word32 win_in_fx, win_out_fx, tmp_fx, gain0_fx, gain1_fx; - +#endif win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; move16(); @@ -2045,6 +2234,31 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < dftOvlLen; i++ ) { +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + j = i_mult( STEREO_DFT32MS_STEP, i ); + win_in_fx = L_mult( win_dft_fx[j], win_dft_fx[j] ); /* Q31 */ + win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */ + /* hCPE->hStereoDft->q_hb_stefi_sig_fx is always 31 here */ + /* tmp = ( win_in * hCPE->hStereoDft->td_gain[0] + win_out * hCPE->hStereoDft->td_gain[1] ) * hCPE->hStereoDft->hb_stefi_sig[i]; */ + + W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); + if ( hCPE->hStereoDft->q_td_gain[0] != 0 ) + { + W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); + } + W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); + if ( hCPE->hStereoDft->q_td_gain[1] != 0 ) + { + W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); + } + tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); + tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); + + output[0][i] = L_add_sat( output[0][i], tmp_fx ); + move32(); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + move32(); +#else win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */ @@ -2064,13 +2278,18 @@ void stereo_icBWE_decproc_fx( move32(); output[1][i] = L_sub_sat( output[1][i], tmp_fx ); move32(); +#endif } FOR( i = dftOvlLen; i < output_frame; i++ ) { +#ifdef FIX_826_PRECISION_LOST_AND_COMPL + tmp_fx = W_extract_h( W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); /* Q11 --> Q11 */ +#else #ifdef FIX_736_BWE_SECT_C tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), 2 * q_output + 14 ) ); /* Q --> q_output */ #else tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ +#endif #endif output[0][i] = L_add_sat( output[0][i], tmp_fx ); move32(); diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index de1bb794dd505d605881f6a9e68037a83fe7d69b..273a4c097f429cd67f9f024e2159d370343b8980 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -40,23 +40,17 @@ #include "ivas_prot.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#endif -#ifndef IVAS_FLOAT_FIXED static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ); -#endif + /*-------------------------------------------------------------------* * convert_coeffs_to_higher_res() @@ -65,55 +59,6 @@ static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ) * by applying high- and lowpass filters to subdivide bins *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#define POINT_5_Q31 ONE_IN_Q30 - -void convert_coeffs_to_higher_res_fx( - const Word32 *in1, /* i : first subframe input */ - const Word32 *in2, /* i : second subframe input */ - Word32 *out, /* o : converted output */ - const Word16 len /* i : length of subframes */ -) -{ - Word16 i; - Word32 tmp1, tmp2; - - IF( in1 == out ) - { - FOR( i = 0; i < len; i += 2 ) - { - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - out[2 * i] = tmp1; - move32(); - out[2 * i + 1] = tmp2; - move32(); - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - out[2 * i + 2] = tmp1; - move32(); - out[2 * i + 3] = tmp2; - move32(); - } - } - ELSE - { - FOR( i = 0; i < len; i += 2 ) - { - out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - move32(); - out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - move32(); - out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); - move32(); - out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); - move32(); - } - } - - return; -} -#endif void convert_coeffs_to_higher_res( const float *in1, /* i : first subframe input */ const float *in2, /* i : second subframe input */ @@ -159,7 +104,6 @@ void convert_coeffs_to_higher_res( * decode core and MDCT stereo information *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void stereo_mdct_dec_stereo( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t ms_mask[2][MAX_SFB] /* o : bandwise MS mask */ @@ -184,9 +128,8 @@ static void stereo_mdct_dec_stereo( return; } -#endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * stereo_mdct_core_dec() * @@ -208,11 +151,6 @@ void stereo_mdct_core_dec( int16_t param_lpc[CPE_CHANNELS][NPRM_LPC_NEW]; float Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; -#ifdef IVAS_FLOAT_FIXED - /* NOTE: temporary fix to avoid garbage values while calculating its - q-factor when not initialised. */ - set_zero( (float *) Aq, CPE_CHANNELS * ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); -#endif float *x[CPE_CHANNELS][NB_DIV]; /*needed to allocate N_MAX to prevent stereo switching crash */ @@ -240,11 +178,6 @@ void stereo_mdct_core_dec( int16_t nTnsBitsTCX10[CPE_CHANNELS][NB_DIV]; float signal_outFB_tmp[CPE_CHANNELS][L_FRAME_PLUS]; float signal_out_tmp[CPE_CHANNELS][L_FRAME_PLUS]; -#ifdef IVAS_FLOAT_FIXED - Word32 signal_out_tmp_fx[CPE_CHANNELS][L_FRAME_PLUS]; - Word32 *x_fx[CPE_CHANNELS][NB_DIV]; -#endif - push_wmops( "stereo_mdct_core_dec" ); /*--------------------------------------------------------------------------------* @@ -260,26 +193,12 @@ void stereo_mdct_core_dec( for ( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ -#ifdef IVAS_FLOAT_FIXED - /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_init_dec_fx( sts[ch], 0, hCPE->last_element_mode ); - /*============*/ - stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); -#else stereo_tcx_init_dec( sts[ch], 0, hCPE->last_element_mode ); -#endif // IVAS_FLOAT_FIXED sts[ch]->hTcxDec->tnsActive[0] = sts[ch]->hTcxDec->tnsActive[1] = 0; sts[ch]->enablePlcWaveadjust = 0; set_zero( signal_out_tmp[ch], L_FRAME_PLUS ); x[ch][0] = &signal_out_tmp[ch][0]; x[ch][1] = &signal_out_tmp[ch][0] + L_FRAME_PLUS / 2; -#ifdef IVAS_FLOAT_FIXED - set32_fx( signal_out_tmp_fx[ch], 0, L_FRAME_PLUS ); - x_fx[ch][0] = &signal_out_tmp_fx[ch][0]; - x_fx[ch][1] = &signal_out_tmp_fx[ch][0] + L_FRAME_PLUS / 2; -#endif set_zero( x_0_buf[ch], N_MAX ); x_0[ch][0] = &x_0_buf[ch][0]; @@ -397,38 +316,11 @@ void stereo_mdct_core_dec( { float sns_int_scf[FDNS_NPTS]; -#ifdef IVAS_FLOAT_FIXED - Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[SNS_NPTS]; - FOR( int c = 0; c < SNS_NPTS; c++ ) - { - Aq_fx[c] = (Word32) ( Aq[ch][k * M + c] * ONE_IN_Q16 ); - } - - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx, DEC ); - - FOR( int c = 0; c < FDNS_NPTS; c++ ) - { - sns_int_scf[c] = ( (float) sns_int_scf_fx[c] / ONE_IN_Q16 ); - } -#else sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#endif // IVAS_FLOAT_FIXED if ( st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) { -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx_[N_MAX]; - Word16 x_e, scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; - f2me_buf( x[ch][k], x_fx_, &x_e, L_frameTCX[ch] ); - for ( int j = 0; j < st->hTonalMDCTConc->nScaleFactors; j++ ) - { - f2me_16( sns_int_scf[j], &scf_fx[j], &scf_e[j] ); - } - TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx_, x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - // st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); -#else TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); -#endif } } @@ -444,41 +336,7 @@ void stereo_mdct_core_dec( stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); } -#ifdef IVAS_FLOAT_FIXED1 - Word32 Aq_fx[2][102]; - Word16 x_e[2][2]; - FOR( Word16 ind = 0; ind < 2; ind++ ) - { - FOR( Word16 ind2 = 0; ind2 < 102; ind2++ ) - { - Aq_fx[ind][ind2] = (Word32) ( Aq[ind][ind2] * ( ONE_IN_Q16 ) ); - } - FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) - { - f2me_buf( x[ind][ind2], x_fx[ind][ind2], &x_e[ind][ind2], L_frameTCX[ind] ); - } - } - st->hTcxDec->cummulative_damping_tcx = (Word16) ( st->hTcxDec->cummulative_damping_tcx * ( ONE_IN_Q15 ) ); - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); - } - FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) - { - f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); - } - FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground[i] = float_to_fix16( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); - } - st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); - st->old_fpitch = float_to_fix( st->old_fpitch_float, 16 ); - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - - ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0, x_e ); -#else ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); -#endif if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { @@ -771,10 +629,7 @@ static void run_min_stats( noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; -#ifdef IVAS_FLOAT_FIXED - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); -#endif + st->lp_noise_float = st->hFdCngDec->lp_noise_float; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 88b25b872c2d102c3f5cba574d55ec96fe382443..c1c4a40b0d19fd16c7921fb37d29b7d2896e04f5 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -41,23 +41,82 @@ #include "ivas_prot.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define POINT_5_Q31 ONE_IN_Q30 + + /*------------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------------*/ static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#ifndef IVAS_FLOAT_FIXED -static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#endif static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV] ); + /*-------------------------------------------------------------------* - * stereo_mdct_dec_stereo() + * convert_coeffs_to_higher_res_fx() + * + * convert MDCT coefficients to higher frequency resolution + * by applying high- and lowpass filters to subdivide bins + *-------------------------------------------------------------------*/ + +void convert_coeffs_to_higher_res_fx( + const Word32 *in1, /* i : first subframe input */ + const Word32 *in2, /* i : second subframe input */ + Word32 *out, /* o : converted output */ + const Word16 len /* i : length of subframes */ +) +{ + Word16 i; + Word32 tmp1, tmp2; + + IF( in1 == out ) + { + FOR( i = 0; i < len; i += 2 ) + { + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + out[2 * i] = tmp1; + move32(); + out[2 * i + 1] = tmp2; + move32(); + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + out[2 * i + 2] = tmp1; + move32(); + out[2 * i + 3] = tmp2; + move32(); + } + } + ELSE + { + FOR( i = 0; i < len; i += 2 ) + { + out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + move32(); + out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + move32(); + out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); + move32(); + out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); + move32(); + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * stereo_mdct_dec_stereo_fx() * * decode core and MDCT stereo information *-------------------------------------------------------------------*/ @@ -80,7 +139,9 @@ static void stereo_mdct_dec_stereo_fx( splitAvailableBits_fx( availableBits, hCPE->hStereoMdct->split_ratio, hCPE->hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + move16(); sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + move16(); sts[1]->bit_stream = &sts[0]->bit_stream[add( add( sts[0]->next_bit_pos, sts[0]->bits_frame_channel ), i_mult( sts[0]->core, NF_GAIN_BITS ) )]; @@ -89,7 +150,7 @@ static void stereo_mdct_dec_stereo_fx( /*-------------------------------------------------------------------* - * stereo_mdct_core_dec() + * stereo_mdct_core_dec_fx() * * MDCT stereo core/stereo decoder *--------------------------------------------------------------------*/ @@ -176,7 +237,7 @@ void stereo_mdct_core_dec_fx( nTnsBitsTCX10[ch][1] = 0; move16(); - set_s( param_lpc[ch], 0, NPRM_LPC_NEW ); + set16_fx( param_lpc[ch], 0, NPRM_LPC_NEW ); } set16_fx( ms_mask[0], 0, MAX_SFB ); @@ -502,204 +563,9 @@ void stereo_mdct_core_dec_fx( return; } -#ifndef IVAS_FLOAT_FIXED -static void apply_dmx_weights( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - float *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ - int16_t transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch */ - int16_t transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch */ -) -{ - int16_t b, k, l, i, ch; - int16_t nsub, nsub2[2], nChannels; - int16_t transform_type[2][2]; - int16_t numCoeffs[2], frameSize; - int16_t tcx_10_only, w_idx; - int16_t start, stop, start_tcx5, stop_tcx5; - STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; - float mdst[CPE_CHANNELS][NB_DIV][L_FRAME48k]; - float convertRes[CPE_CHANNELS][L_FRAME48k]; - float *sig[CPE_CHANNELS][NB_DIV], *pTmp[CPE_CHANNELS][NB_DIV]; - - nChannels = CPE_CHANNELS; - frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; - - transform_type[0][0] = transform_type_left[0]; - transform_type[0][1] = transform_type_left[1]; - transform_type[1][0] = transform_type_right[0]; - transform_type[1][1] = transform_type_right[1]; - - /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ - if ( transform_type[0][0] == TCX_20 || transform_type[1][0] == TCX_20 ) - { - /* use TCX20 band config for TCX20 in both channels and mixed frames */ - sfbConf = &hCPE->hStereoMdct->stbParamsTCX20; - nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 */ - tcx_10_only = 0; - } - else - { - /* use TCX10 band config only if none of the channels is TCX20 */ - sfbConf = &hCPE->hStereoMdct->stbParamsTCX10; - nsub = 2; - /* set resolution per subframe, subdivide again if subframe is TCX5 in both channels */ - nsub2[0] = ( transform_type[0][0] == TCX_5 && transform_type[1][0] == TCX_5 ) ? 2 : 1; - nsub2[1] = ( transform_type[0][1] == TCX_5 && transform_type[1][1] == TCX_5 ) ? 2 : 1; - tcx_10_only = 1; - } - - /* for subframes with only TCX5 in both channels number of coefficients is only half (in 2 quarterframes) */ - numCoeffs[0] = ( nsub2[0] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; - numCoeffs[1] = ( nsub2[1] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; - - /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0][0] = pTmp[0][0] = x[0][0]; - sig[0][1] = pTmp[0][1] = x[0][1]; - sig[1][0] = pTmp[1][0] = x[1][0]; - sig[1][1] = pTmp[1][1] = x[1][1]; - - /* convert (sub)frames to higher frequency resolution */ - for ( ch = 0; ch < nChannels; ch++ ) - { - for ( k = 0; k < NB_DIV; k++ ) - { - if ( transform_type[ch][k] == TCX_5 && nsub2[k] == 1 ) - { - /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[ch][k] = sig[ch][k] = convertRes[ch] + k * frameSize / 2; - convert_coeffs_to_higher_res( x[ch][k], x[ch][k] + frameSize / 4, pTmp[ch][k], frameSize / 4 ); - } - } - - if ( transform_type[ch][0] != TCX_20 && nsub == 1 ) - { - /* TCX20 and TCX10 in same frame -> convert channel with TCX10 to TCX20 resolution */ - sig[ch][0] = convertRes[ch]; - convert_coeffs_to_higher_res( pTmp[ch][0], pTmp[ch][1], sig[ch][0], frameSize / 2 ); - } - } - - /* MDST estimate */ - for ( ch = 0; ch < nChannels; ch++ ) - { - for ( k = 0; k < nsub; k++ ) - { - for ( l = 0; l < nsub2[k]; l++ ) - { - mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0.f; - for ( i = l * numCoeffs[k] + 1; i < ( l + 1 ) * numCoeffs[k] - 1; i++ ) - { - mdst[ch][k][i] = sig[ch][k][i + 1] - sig[ch][k][i - 1]; - } - } - } - } - - /* compute and apply bandwise weigths for active downmix (similar to DFT Stereo) */ - stop_tcx5 = 0; - for ( b = 0; b < sfbConf->sfbCnt; b++ ) - { - float w[CPE_CHANNELS][4]; - - for ( k = 0; k < nsub; k++ ) - { - for ( l = 0; l < nsub2[k]; l++ ) - { - float sum_nrg_L = EPSILON, sum_nrg_R = EPSILON; - float dot_prod_real = EPSILON, dot_prod_imag = EPSILON; - float sum_nrg_Mid, sum_abs, dot_prod_abs; - - start = l * numCoeffs[k] + sfbConf->sfbOffset[b] / nsub2[k]; - stop = l * numCoeffs[k] + sfbConf->sfbOffset[b + 1] / nsub2[k]; - - /* compute band energies and cross correlation */ - for ( i = start; i < stop; i++ ) - { - sum_nrg_L += sig[0][k][i] * sig[0][k][i] + mdst[0][k][i] * mdst[0][k][i]; - sum_nrg_R += sig[1][k][i] * sig[1][k][i] + mdst[1][k][i] * mdst[1][k][i]; - dot_prod_real += sig[0][k][i] * sig[1][k][i] + mdst[0][k][i] * mdst[1][k][i]; - dot_prod_imag += mdst[0][k][i] * sig[1][k][i] - sig[0][k][i] * mdst[1][k][i]; - } - sum_nrg_Mid = max( 0.f, sum_nrg_L + sum_nrg_R + 2.f * dot_prod_real ); - sum_abs = sqrtf( sum_nrg_L ) + sqrtf( sum_nrg_R ) + EPSILON; - dot_prod_abs = sqrtf( dot_prod_real * dot_prod_real + dot_prod_imag * dot_prod_imag ); - - /* calculate weights */ - if ( hCPE->hStereoMdct->reverse_dmx == 0 ) - { - w[1][2 * k + l] = sqrtf( 0.5f * ( sum_nrg_L + sum_nrg_R ) + dot_prod_abs ) / sum_abs; - w[0][2 * k + l] = w[1][2 * k + l] + sqrtf( 2.f ) * ( 1.f - sqrtf( sum_nrg_Mid ) / sum_abs ); - } - else - { - w[0][2 * k + l] = sqrtf( 0.5f * ( sum_nrg_L + sum_nrg_R ) + dot_prod_abs ) / sum_abs; - w[1][2 * k + l] = w[0][2 * k + l] + sqrtf( 2.f ) * ( 1.f - sqrtf( sum_nrg_Mid ) / sum_abs ); - } - } - } - - /* apply weights to channels with their original frequency resolutions */ - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - if ( transform_type[ch][0] == TCX_20 ) - { - for ( i = sfbConf->sfbOffset[b]; i < sfbConf->sfbOffset[b + 1]; i++ ) - { - x[ch][0][i] *= w[ch][0]; - } - } - else - { - start = sfbConf->sfbOffset[b]; - stop = sfbConf->sfbOffset[b + 1]; - if ( !tcx_10_only ) /* TCX20 band config is used */ - { - start /= 2; - stop /= 2; - } - - for ( k = 0; k < NB_DIV; k++ ) - { - w_idx = ( nsub == 1 ) ? 0 : 2 * k; - if ( transform_type[ch][k] == TCX_10 ) - { - for ( i = start; i < stop; i++ ) - { - x[ch][k][i] *= w[ch][w_idx]; - } - } - else /* TCX_5 */ - { - start_tcx5 = stop_tcx5; - stop_tcx5 = ( stop + 1 ) / 2; - - for ( i = start_tcx5; i < stop_tcx5; i++ ) - { - x[ch][k][i] *= w[ch][w_idx]; - } - - if ( nsub2[k] == 2 ) - { - w_idx++; - } - - for ( i = start_tcx5; i < stop_tcx5; i++ ) - { - x[ch][k][i + ( frameSize >> 2 )] *= w[ch][w_idx]; - } - } - } - } - } - } - - return; -} -#endif - /*-------------------------------------------------------------------* - * apply_dmx_weights() + * apply_dmx_weights_fx() * * apply bandwise weighting for later dmx in case of mono output *--------------------------------------------------------------------*/ @@ -1091,7 +957,7 @@ static void apply_dmx_weights_fx( /*-------------------------------------------------------------------* - * run_min_stats() + * run_min_stats_fx() * * run the minimum statistics noise estimation algorithm * directly on the MDCT spectrum diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index d88e311983b3e558895942f6a8f93f3fedce3bb1..a745752bd28011c9842bac048f86909b9d8d7dd7 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -39,10 +39,9 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*-------------------------------------------------------------------* @@ -1296,7 +1295,7 @@ void updateBuffersForDmxMdctStereo_fx( } delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); - tcxltp_mem_in_len = NS2SA_fx2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); + tcxltp_mem_in_len = NS2SA_FX2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); move16(); assert( delay_buf_out_len > tcxltp_mem_in_len ); diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 7337086579ff713fbdc5eb63e5c48d6c425ca7dc..6ec395ccc3799bab7da70e3035c3f061c5d64699 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -35,17 +35,15 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "assert.h" #include "wmc_auto.h" #include -#include "prot_fx2.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_rom_com_fx.h" #endif @@ -1282,7 +1280,7 @@ ivas_error stereo_memory_dec_fx( DEC_CORE_HANDLE st; Word16 i, n, delay_comp_DFT; ivas_error error; - Word16 div_m, div_e; + Word16 div_m, div_e, tmp16; error = IVAS_ERR_OK; @@ -1764,7 +1762,16 @@ ivas_error stereo_memory_dec_fx( IF( hCPE->hCoreCoder[0]->bfi == 0 ) { st = hCPE->hCoreCoder[1]; - hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], L_add( hCPE->element_brate, hCPE->brate_surplus ), ( sub( add( sub( extract_l( Mpy_32_16_1( hCPE->element_brate, INV_FRAME_PER_SEC_Q15 ) ), nb_bits_metadata ), extract_l( Mpy_32_16_1( hCPE->brate_surplus, INV_FRAME_PER_SEC_Q15 ) ) ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); + IF( hCPE->brate_surplus < 0 ) + { + tmp16 = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + } + ELSE + { + tmp16 = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + } + + hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], L_add( hCPE->element_brate, hCPE->brate_surplus ), ( sub( add( sub( extract_l( Mpy_32_16_1( hCPE->element_brate, INV_FRAME_PER_SEC_Q15 ) ), nb_bits_metadata ), tmp16 ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); move16(); IF( hCPE->hStereoTD->tdm_LRTD_flag != 0 ) @@ -3096,7 +3103,7 @@ void stereo_switching_dec( test(); test(); test(); - IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || n == 0 || EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->nchan_out, 1 ) ) + IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || n == 0 || NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->nchan_out, 1 ) ) { FOR( i = 0; i < dft32ms_ovl; i++ ) { @@ -3221,9 +3228,9 @@ void stereo_switching_dec( { /* reset CLDFB memories */ #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - cldfb_reset_memory_ivas( sts[0]->cldfbAna ); - cldfb_reset_memory_ivas( sts[0]->cldfbBPF ); - cldfb_reset_memory_ivas( sts[0]->cldfbSyn ); + // cldfb_reset_memory_ivas( sts[0]->cldfbAna ); + // cldfb_reset_memory_ivas( sts[0]->cldfbBPF ); + // cldfb_reset_memory_ivas( sts[0]->cldfbSyn ); #endif cldfb_reset_memory_fx( sts[0]->cldfbAna ); @@ -3288,9 +3295,9 @@ void stereo_switching_dec( /* reset CLDFB memories */ #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - cldfb_reset_memory_ivas( sts[1]->cldfbAna ); - cldfb_reset_memory_ivas( sts[1]->cldfbBPF ); - cldfb_reset_memory_ivas( sts[1]->cldfbSyn ); + // cldfb_reset_memory_ivas( sts[1]->cldfbAna ); + // cldfb_reset_memory_ivas( sts[1]->cldfbBPF ); + // cldfb_reset_memory_ivas( sts[1]->cldfbSyn ); #endif cldfb_reset_memory_fx( sts[1]->cldfbAna ); diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 83b6d67a4c76ec863b09bab8bc2f53f55653f900..55b793bda35bcd3ad29e1eb553fe879067435129 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -36,14 +36,14 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif #ifndef IVAS_FLOAT_FIXED @@ -137,7 +137,7 @@ Word32 power_table[32 + 1] = { 850883136, 954706496, 1071198464, 1201904384, 1348558720, 1513107968, 1697734912, 1904890240, 2137321728 }; // Q29 -void tdm_configure_dec( +void tdm_configure_dec_fx( const Word16 ivas_format, /* i : IVAS format */ const Word16 ism_mode, /* i : ISM mode in combined format */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -196,7 +196,7 @@ void tdm_configure_dec( /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ - sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); + sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); move16(); /* Get the LRTD config flag: 1 = LRTD configuration, favor closer bitrate per channel; @@ -316,7 +316,6 @@ void tdm_configure_dec( /*sts[1]->tdm_inst_ratio_idx = sts[0]->tdm_inst_ratio_idx;*/ - test(); test(); IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDftDmx != NULL ) { @@ -371,7 +370,7 @@ void tdm_configure_dec( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ - tdm_bit_alloc( ivas_format, ism_mode, hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + tdm_bit_alloc( ivas_format, ism_mode, L_add( L_sub( hCPE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ), hCPE->brate_surplus ), hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 630e24d4e0918dfeda66fe360ceef6fb79316093..9156aa7180b1b50b99c907d55a22652226c227b9 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -38,8 +38,7 @@ #include "ivas_cnst.h" #include #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------* @@ -52,7 +51,7 @@ #ifdef NONBE_FIX_1069_SVD_TUNING #define SVD_MINIMUM_VALUE 1e-32f /* minimum value */ #define CONVERGENCE_FACTOR 1.0e-04f /* factor for SVD convergence */ -#define SVD_ZERO_FLUSH_THRESHOLD 0.0f +#define SVD_ZERO_FLUSH_THRESHOLD 1.0e-20f #else #define SVD_MINIMUM_VALUE 1e-32f /* minimum value */ #define CONVERGENCE_FACTOR 1.19209290e-07f /* factor for SVD convergence */ diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index d51543302e0a607c2c57c0e22047e2d42f8510bf..877cbb938cc3739575c250f363a5e17d535243cc 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -35,14 +35,13 @@ #include "options.h" #include #include "prot.h" -#include "prot_fx1.h" #include "rom_com.h" #include "stat_dec.h" #include "wmc_auto.h" #include "basop_proto_func.h" #include "stat_com.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" /*-------------------------------------------------------------* @@ -86,7 +85,7 @@ void stereo_tcx_init_dec_fx( /*sampling rate*/ st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); move32(); - st->fscale = sr2fscale( st->sr_core ); + st->fscale = sr2fscale_fx( st->sr_core ); move16(); /*frame size*/ @@ -815,9 +814,9 @@ void stereo_tcx_core_dec_fx( /* Update past buffers */ Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); - Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ) ); Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); - Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy( st->hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); Copy( &lspnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); Copy( &lsfnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index feae9373c294c31f87ab8e97e082670c03938032..e1eaca3d3256429b99fcf3f9ac68f86add0fb6c2 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -38,8 +38,7 @@ #include "ivas_rom_com.h" #include "ivas_cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "wmc_auto.h" #ifndef IVAS_FLOAT_FIXED @@ -639,8 +638,8 @@ void decod_gen_2sbfr_ivas_fx( /* update LP filtered gains for the case of frame erasures */ // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame); // lp_gain_updt(i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame); - lp_gain_updt_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); - lp_gain_updt_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 095868940e00d996e48074206d998467f79ce11e..3ba8a4331423dc812037643a8719e3ef9af3491c 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -49,7 +49,7 @@ #include "jbm_jb4_jmf.h" #include "jbm_jb4sb.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #define WMC_TOOL_SKIP #define INV_500_Q31 4294967 /*1/500 IN Q_31*/ @@ -1490,7 +1490,7 @@ static void JB4_popFromBuffer( partialCopyDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, searchpos ); IF( EQ_64( partialCopyDu->timeStamp, W_add( nextDataUnit->timeStamp, partialCopyDu->duration ) ) ) { - get_NextCoderType( partialCopyDu->data, &nextDataUnit->nextCoderType ); + get_NextCoderType_fx( partialCopyDu->data, &nextDataUnit->nextCoderType ); BREAK; } } diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 72e57c5b5bb1094b96a7275a7c3609870826063d..b3a7886ea0308f66104e5ceb9f5126ce1b451b19 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -54,7 +54,7 @@ #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #define INV_100_Q15 328 #define INV_400_Q15 82 #define INV_80_Q15 410 @@ -1683,54 +1683,56 @@ static Word8 logarithmic_search_fx( const apa_state_t *ps, } /* update max corr */ - IF( LT_16( ps->scale, 100 ) ){ + IF( LT_16( ps->scale, 100 ) ) + { /* shrinking: prefer greater synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF_EVS - IF( GE_32( coeff, coeff_max ) ){ - coeff_max = L_add( coeff, 0 ); - *synchpos = i; - move16(); + BASOP_SATURATE_WARNING_OFF_EVS; + IF( GE_32( coeff, coeff_max ) ) + { + coeff_max = L_add( coeff, 0 ); + *synchpos = i; + move16(); + } + BASOP_SATURATE_WARNING_ON_EVS; + } + ELSE + { + /* extending: prefer smaller synchpos for equal coeff */ + BASOP_SATURATE_WARNING_OFF_EVS; + IF( GT_32( coeff, coeff_max ) ) + { + coeff_max = L_add( coeff, 0 ); + *synchpos = i; + move16(); + } + BASOP_SATURATE_WARNING_ON_EVS; + } } - BASOP_SATURATE_WARNING_ON_EVS - } - ELSE - { - /* extending: prefer smaller synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF_EVS - IF( GT_32( coeff, coeff_max ) ) + /* backup old search range */ + s_start_old = s_start; + move16(); + s_len_old = inlen; + move16(); + + css = shr( css, 1 ); + inlen = shr( inlen, 1 ); + s_start_old = s_start; + move16(); + s_start = sub( *synchpos, shr( inlen, 1 ) ); + + if ( LT_16( s_start, s_start_old ) ) { - coeff_max = L_add( coeff, 0 ); - *synchpos = i; + s_start = s_start_old; move16(); } - BASOP_SATURATE_WARNING_ON_EVS - } -} -/* backup old search range */ -s_start_old = s_start; -move16(); -s_len_old = inlen; -move16(); - -css = shr( css, 1 ); -inlen = shr( inlen, 1 ); -s_start_old = s_start; -move16(); -s_start = sub( *synchpos, shr( inlen, 1 ) ); - -if ( LT_16( s_start, s_start_old ) ) -{ - s_start = s_start_old; - move16(); -} -IF( GT_16( add( s_start, inlen ), add( s_start_old, s_len_old ) ) ) -{ - inlen = add( sub( s_start_old, s_start ), s_len_old ); -} -} -WHILE( GT_16( css, 2 ) ); -return 0; + IF( GT_16( add( s_start, inlen ), add( s_start_old, s_len_old ) ) ) + { + inlen = add( sub( s_start_old, s_start ), s_len_old ); + } + } + WHILE( GT_16( css, 2 ) ); + return 0; } #endif /* diff --git a/lib_dec/jbm_pcmdsp_window.h b/lib_dec/jbm_pcmdsp_window.h index 1abf57f3374bd448df90f5aab5e3c932edf29410..9a20fdab2d8dac8533dd2503d04a2946bde9ad69 100644 --- a/lib_dec/jbm_pcmdsp_window.h +++ b/lib_dec/jbm_pcmdsp_window.h @@ -41,6 +41,7 @@ #include #include "options.h" +#include "typedef.h" /*! Generates a Hann window (cos-shaped) of length n. * Roughly: diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 2e9ea383f9e968291a44d88b8e2e04c663d1aded..80508277f5bf2e0d84c14e7856d75dfa056cdd85 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" #include "rom_com.h" #include "rom_dec.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * Local function prototype diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 2b66b10845fe6656680aae962027b4444a0b7d2a..51b5af294eaf9cf63081ef228578247df9e12d8d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -30,21 +30,20 @@ *******************************************************************************************************/ +#include +#include +#include #include "lib_dec.h" +#include "wmc_auto.h" #ifndef IVAS_FLOAT_FIXED #include "ivas_cnst.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" -#include -#include -#include -#include "wmc_auto.h" /*---------------------------------------------------------------------* * Local structs diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 900aa4d5413fdb8c1594eb79a795485eae8d0d3f..7e740a311eefc6aa04853edf336ecadef069406c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -36,8 +36,7 @@ #include "ivas_prot_rend.h" #include "prot.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" @@ -1445,9 +1444,11 @@ static ivas_error IVAS_DEC_Setup( { // fixedToFloat_arrL( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, 26, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_len ); IF( st_ivas->hParamMC->diff_proto_info ) - FOR( i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++ ) { - fixedToFloat_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], st_ivas->hParamMC->diff_proto_info->proto_fac[i], 26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i] ); + FOR( i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + fixedToFloat_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], st_ivas->hParamMC->diff_proto_info->proto_fac[i], 26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i] ); + } } } } @@ -2407,7 +2408,7 @@ ivas_error IVAS_DEC_FeedCustomLsData( /* Loudspeaker LFE */ hLsSetupCustom->num_lfe = hLsCustomData.num_lfe; move16(); - mvs2s( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe ); + Copy( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe ); return IVAS_ERR_OK; } @@ -2704,7 +2705,7 @@ ivas_error IVAS_DEC_GetDelay( } move32(); - nSamples[1] = NS2SA_fx2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); + nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); move16(); nSamples[2] = (Word16) W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ); move16(); @@ -2714,7 +2715,7 @@ ivas_error IVAS_DEC_GetDelay( IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) ) { /* note: in MASA, all delay is compensated at the decoder by default, so subtract the encoder delay for print-out */ - nSamples[1] = sub( nSamples[1], NS2SA_fx2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) ); + nSamples[1] = sub( nSamples[1], NS2SA_FX2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) ); move16(); } @@ -2871,7 +2872,7 @@ ivas_error IVAS_DEC_VoIP_FeedFrame( } /* check if frame contains a partial copy and get its offset */ - evs_dec_previewFrame_float( au, auSize, &partialCopyFrameType, &partialCopyOffset ); + evs_dec_previewFrame( au, auSize, &partialCopyFrameType, &partialCopyOffset ); /* create data unit for primary copy in the frame */ dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM ); @@ -3895,7 +3896,6 @@ static ivas_error input_format_API_to_internal( BREAK; default: return IVAS_ERR_INVALID_BITSTREAM; - BREAK; } move16(); diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index 40318b376206ce1c9ff0a02eee4e89cb701247fa..56deb5dd5a1601062e886aaf9c977a64b3b1eaaf 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ /*======================================================================*/ /* FUNCTION : lp_filt_exc_dec_fx() */ @@ -54,7 +53,7 @@ void lp_filt_exc_dec_fx( { IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { - lp_flag = (Word16) get_next_indice( st_fx, 1 ); + lp_flag = (Word16) get_next_indice_fx( st_fx, 1 ); } } IF( EQ_16( lp_flag, LOW_PASS ) ) diff --git a/lib_dec/lsf_dec.c b/lib_dec/lsf_dec.c index 2fb00b693aa48b4b70326384d4a4736bb07a91db..0628ccd33da84a4ccb9aa00ee1fffd99ba07e3a1 100644 --- a/lib_dec/lsf_dec.c +++ b/lib_dec/lsf_dec.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_proto_func.h" #include "ivas_prot.h" #include "ivas_rom_com.h" diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 39466c34bd2aeab8cc71d26bfeb7ded58416afc6..4d9a93586cbf8e7e3b9aadd9dcaf8aabbc40503a 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE #include "ivas_prot.h" //#include "ivas_rom_com.h" @@ -38,15 +37,15 @@ static void dqlsf_CNG_fx( Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16) get_next_indice( st_fx, 4 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); move16(); - indice[1] = (Word16) get_next_indice( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); move16(); - indice[2] = (Word16) get_next_indice( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { ber_flag = deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); @@ -57,6 +56,7 @@ static void dqlsf_CNG_fx( deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); } st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); + move16(); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). If the last decoded LSF coefficient is larger than 6350 the decoded frame is WB2 with sampling rate of 16 kHz @@ -122,8 +122,11 @@ void lsf_dec_fx( Word16 param_lpc[NPRM_LPC_NEW]; Word32 L_tmp; Word16 nBits = 0; + move16(); Word16 tmp_old[M + 1], tmp_new[M + 1]; Word16 enr_old = 0, enr_new = 0; + move16(); + move16(); Word16 lsf_diff, coder_type; /* initialize */ @@ -134,7 +137,7 @@ void lsf_dec_fx( move16(); } test(); - if ( EQ_16( coder_type, AUDIO ) && GT_16( st_fx->GSC_IVAS_mode, 0 ) ) + if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) { coder_type = GENERIC; move16(); @@ -164,7 +167,7 @@ void lsf_dec_fx( { nBits = 30; move16(); - if ( EQ_16( st_fx->bwidth, NB ) ) + if ( st_fx->bwidth == NB ) { nBits = 32; move16(); @@ -195,10 +198,11 @@ void lsf_dec_fx( { st_fx->seed_acelp = 0; move16(); - FOR( i = no_param_lpc - 1; i >= 0; i-- ) + FOR( i = sub( no_param_lpc, 1 ); i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = (int16_t) ( ( ( ( st_fx->seed_acelp ) >> 1 ) + param_lpc[i] ) * 31821L + 13849L ); + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L ) ); + move16(); // PMTE() /*IVAS_CODE to be completed */ } } @@ -218,6 +222,7 @@ void lsf_dec_fx( L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ + move16(); } test(); @@ -245,7 +250,7 @@ void lsf_dec_fx( * Mid-frame LSF decoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ - if ( st_fx->rate_switching_reset ) + IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ Copy( lsp_new, st_fx->lsp_old_fx, M ); @@ -277,7 +282,7 @@ void lsf_dec_fx( test(); test(); test(); - if ( EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) || EQ_16( st_fx->clas_dec, SIN_ONSET ) || EQ_16( st_fx->clas_dec, INACTIVE_CLAS ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) + if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) { st_fx->relax_prev_lsf_interp = 1; move16(); @@ -286,12 +291,13 @@ void lsf_dec_fx( } } test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) + IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ Copy( lsp_mid, st_fx->lsp_old_fx, M ); lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); } + test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) { // PMT("To be verified") @@ -314,13 +320,15 @@ void lsf_dec_fx( * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ + move16(); } - else + ELSE { st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + move16(); } return; @@ -413,13 +421,14 @@ void lsf_end_dec_fx( test(); test(); #ifdef LSF_RE_USE_SECONDARY_CHANNEL + test(); IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) && ( st->idchan == 0 ) ) #else IF( ( EQ_16( coder_type_org, GENERIC ) ) && ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( mode2_flag == 0 ) ) #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16) get_next_indice( st, 1 ); + coder_type = (Word16) get_next_indice_fx( st, 1 ); coder_type = add( coder_type, 2 ); test(); test(); @@ -461,6 +470,8 @@ void lsf_end_dec_fx( * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + test(); + test(); IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ @@ -484,6 +495,8 @@ void lsf_end_dec_fx( } ELSE { + test(); + test(); IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { /* read from param_lpc */ @@ -494,7 +507,7 @@ void lsf_end_dec_fx( } ELSE { - safety_net = (Word16) get_next_indice( st, 1 ); + safety_net = (Word16) get_next_indice_fx( st, 1 ); } } @@ -505,11 +518,12 @@ void lsf_end_dec_fx( * Read indices from array *--------------------------------------------------------------------------*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + test(); /* Make sure there are the correct bit allocations */ IF( EQ_16( st->idchan, 1 ) && GT_16( predmode, 2 ) ) { /* use same AR prediction bit allocation for intra and inter modes*/ - lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); stages0 = stages1; Copy( levels1, levels0, stages0 ); Copy( bits1, bits0, stages0 ); @@ -527,8 +541,8 @@ void lsf_end_dec_fx( { *nb_indices = 10; move16(); - move16(); TCQIdx[0] = safety_net; + move16(); FOR( i = 1; i < *nb_indices; i++ ) { TCQIdx[i] = *p_lpc_param++; @@ -542,7 +556,7 @@ void lsf_end_dec_fx( move16(); FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice( st, Bit_alloc1[i] ); + TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); move16(); } } @@ -571,7 +585,7 @@ void lsf_end_dec_fx( test(); IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { - FOR( i = 0; i < stages - 1; i++ ) + FOR( i = 0; i < sub( stages, 1 ); i++ ) { num_bits = bits[i]; move16(); @@ -606,7 +620,8 @@ void lsf_end_dec_fx( { num_bits = bits[i]; move16(); - lindice[i + 1] = (Word16) get_next_indice( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + move16(); } cumleft = levels[sub( stages, 1 )]; @@ -626,7 +641,8 @@ void lsf_end_dec_fx( move16(); } - lindice[i + 1] = (Word16) get_next_indice( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + move16(); i = add( i, 1 ); } } @@ -639,6 +655,7 @@ void lsf_end_dec_fx( move16(); } st->reset_mem_AR = 0; + move16(); } /*------------------------------------------------------------------------------------------* @@ -653,7 +670,7 @@ void lsf_end_dec_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, nBits - 1 ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Update mem_MA */ Copy( qlsf, st->mem_MA_fx, M ); @@ -667,6 +684,7 @@ void lsf_end_dec_fx( FOR( i = 0; i < M; i++ ) { pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/ + move16(); } *LSF_Q_prediction = AUTO_REGRESSIVE; move16(); @@ -682,10 +700,11 @@ void lsf_end_dec_fx( FOR( i = 0; i < M; i++ ) { pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + move16(); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) + IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } @@ -694,30 +713,34 @@ void lsf_end_dec_fx( { /* LVQ */ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE - if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) + test(); + test(); + IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ - st->BER_detect = st->BER_detect | - vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ); + st->BER_detect = s_or( st->BER_detect, + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); + move16(); Vr_add( qlsf, pred3, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } - else + ELSE #endif { - if ( st->element_mode != EVS_MONO ) + IF( st->element_mode != EVS_MONO ) { ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); } - else + ELSE { ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); } st->BER_detect = s_or( st->BER_detect, ber_flag ); + move16(); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -733,17 +756,18 @@ void lsf_end_dec_fx( move16(); } #endif - if ( st->element_mode != EVS_MONO ) + IF( st->element_mode != EVS_MONO ) { ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); } - else + ELSE { ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); } st->BER_detect = s_or( st->BER_detect, ber_flag ); + move16(); #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */ @@ -762,6 +786,7 @@ void lsf_end_dec_fx( FOR( i = 0; i < M; i++ ) { pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + move16(); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -905,14 +930,15 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16) get_next_indice( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Calculation of mid-LSF vector */ FOR( j = 0; j < M; j++ ) { - L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); /*Q(x2.56+13+1)->Q(x2.56+14)*/ - L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); /*Q(x2.56+14)*/ - qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); /*Q(x2.56)*/ + L_tmp = L_mult( sub( 0x2000, ratio[add( i_mult( idx, M ), j )] ), qlsf0[j] ); /*Q(x2.56+13+1)->Q(x2.56+14)*/ + L_tmp = L_mac( L_tmp, ratio[add( i_mult( idx, M ), j )], qlsf1[j] ); /*Q(x2.56+14)*/ + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); /*Q(x2.56)*/ + move16(); } /* check for incorrect LSF ordering */ diff --git a/lib_dec/lsf_msvq_ma_dec.c b/lib_dec/lsf_msvq_ma_dec.c index d18d49fffb896bc8d8e3c6efd30bb1d0e8bc3bf5..32fdcb28c4f2e359b2be332301ac88f7e994f87c 100644 --- a/lib_dec/lsf_msvq_ma_dec.c +++ b/lib_dec/lsf_msvq_ma_dec.c @@ -42,6 +42,7 @@ #include "basop_proto_func.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * lsf_msvq_ma_decprm_ivas() * @@ -278,3 +279,4 @@ int16_t dec_lsf_tcxlpc_ivas( return st->next_bit_pos - start_bit_pos; } +#endif diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 13e41a8d2890746007fb71c1c05e5e254f1625fd..3fc69d5884f1afe86b4e685e25e226274d678606 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" @@ -42,19 +41,16 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) { find_pred_mode( &predmode, GENERIC, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); - move16(); } ELSE { IF( EQ_16( st->core, TCX_20_CORE ) ) { find_pred_mode( &predmode, AUDIO, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); - move16(); } ELSE { find_pred_mode( &predmode, st->coder_type, sub( 1, st->narrowBand ) /*st->bwidth*/, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); - move16(); } } lsf_allocate_fx( sub( ENDLSF_NBITS, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); @@ -100,15 +96,18 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) FOR( i = 0; i < tmp; i++ ) { *param_lpc = get_next_indice_fx( st, bits[i] ); + move16(); param_lpc++; nbits_lpc = add( nbits_lpc, bits[i] ); } *param_lpc = get_next_indice_fx( st, LEN_INDICE ); + move16(); param_lpc++; nbits_lpc = add( nbits_lpc, LEN_INDICE ); - *param_lpc = get_next_indice_fx( st, bits[i] - LEN_INDICE ); + *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); + move16(); param_lpc++; nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); @@ -119,6 +118,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) { *param_lpc = get_next_indice_fx( st, bits_midlpc ); + move16(); nbits_lpc = add( nbits_lpc, bits_midlpc ); } @@ -135,14 +135,17 @@ Word16 lsf_bctcvq_decprm( const Word16 *bits1; num_par = 10; + move16(); bits1 = BC_TCVQ_BIT_ALLOC_40B; nbits_lpc = 0; + move16(); FOR( i = 0; i < num_par; i++ ) { *param_lpc = get_next_indice_fx( st, bits1[i] ); + move16(); param_lpc++; nbits_lpc = add( nbits_lpc, bits1[i] ); } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index dfafc8d09e2a9ec5d067089ad82e213d9671a656..b873d398d1a067ff80b162481ea20b4dda7b1735 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -3,9 +3,8 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /*===================================================================*/ @@ -32,6 +31,7 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) { Word16 i; Word16 max_s = 0; + move16(); FOR( i = 0; i < size; i++ ) { @@ -46,7 +46,8 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) move16(); } - *qf = *qf - hdr; + *qf = sub( *qf, hdr ); + move16(); FOR( i = 0; i < size; i++ ) { @@ -88,10 +89,12 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type, Word16 *gain_buf ) { Word16 i, fid = 0; + move16(); Word16 ptr[L_FRAME], filtRes[L_FRAME], gain_fac; /*ptr, filtRes - Q0, gain_fac - Q14 */ Word16 Gains[10]; /* Q0 */ Word32 Gain, E3, E2; Word16 BP1_ORDER = 4; + move16(); Word16 ptr_tmp[L_FRAME]; /* Q0 */ Word16 iG1, iG2[2]; Word16 exp_E2, exp_E3, frac_E2, frac_E3; @@ -101,20 +104,25 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Word32 max_exc_sqr; Word16 n; Word16 max_val = 0, norm_val = 0; + move16(); + move16(); Word16 qGain = 0; + move16(); SC_VBR_DEC_HANDLE hSC_VBR; hSC_VBR = st_fx->hSC_VBR; + test(); if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) && NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) { st_fx->last_nelp_mode_dec = 0; + move16(); } test(); test(); test(); - IF( EQ_16( coder_type, UNVOICED ) && EQ_16( st_fx->bwidth, NB ) ) + IF( EQ_16( coder_type, UNVOICED ) && st_fx->bwidth == NB ) { IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { @@ -130,7 +138,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 move16(); IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - set16_fx( hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, BP1_ORDER * 2 ); + set16_fx( hSC_VBR->bp1_filt_mem_wb_dec_fx, 0, shl( BP1_ORDER, 1 ) ); } } @@ -147,17 +155,20 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { iG1 = st_fx->rf_indx_nelp_iG1; + move16(); iG2[0] = st_fx->rf_indx_nelp_iG2[0]; + move16(); iG2[1] = st_fx->rf_indx_nelp_iG2[1]; + move16(); } ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 = (Word16) get_next_indice( st_fx, 5 ); + iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); move16(); - iG2[0] = (Word16) get_next_indice( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); - iG2[1] = (Word16) get_next_indice( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); } @@ -169,10 +180,11 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { fid = st_fx->rf_indx_nelp_fid; + move16(); } ELSE { - fid = (Word16) get_next_indice( st_fx, 2 ); + fid = (Word16) get_next_indice_fx( st_fx, 2 ); move16(); } } @@ -220,8 +232,8 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 frac = round_fx( L_shl( Gain, n ) ); n = sub( add( n, 24 ), 30 ); frac = div_s( 16384, frac ); - Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ - tmp = round_fx( L_shl( Gain, sub( n + exp, 15 ) ) ); /*Q0 */ + Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ + tmp = round_fx( L_shl( Gain, sub( add( n, exp ), 15 ) ) ); /*Q0 */ } ELSE { @@ -245,6 +257,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 move16(); /* 1.16f - Q14 */ } + test(); IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) { /* Normalize Gains[10] with headroom 4, qGain is the new Q value os Gains, not Q0*/ @@ -261,17 +274,17 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { BP1_ORDER = 4; move16(); - Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, 2 * BP1_ORDER, qGain ); /* bring filter prev memory from Q0 to qGain */ + Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), qGain ); /* bring filter prev memory from Q0 to qGain */ pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_WB_QF ) ) ); - Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, 2 * BP1_ORDER, -qGain ); /* bring filter prev memory from qGain to Q0 */ - Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ + Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), negate( qGain ) ); /* bring filter prev memory from qGain to Q0 */ + Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ Copy( ptr_tmp, ptr, L_FRAME ); } test(); - IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) + IF( EQ_16( coder_type, UNVOICED ) && ( st_fx->bwidth == NB ) ) { BP1_ORDER = 7; move16(); @@ -296,6 +309,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); Scale_sig( ptr, L_FRAME, norm_val ); *Q_exc = add( norm_val, *Q_exc ); + move16(); } BP1_ORDER = 7; @@ -306,7 +320,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( norm_val > 0 ) { - Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), -norm_val ); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), negate( norm_val ) ); } Copy( ptr_tmp, ptr, L_FRAME ); /*Q_exc */ @@ -387,7 +401,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 #else frac_E2 = round_fx( L_shl( E2, exp_E2 ) ); #endif - exp_E2 = sub( 30, add( exp_E2, 2 * ( *Q_exc ) ) ); + exp_E2 = sub( 30, add( exp_E2, shl( ( *Q_exc ), 1 ) ) ); scale = shr( sub( frac_E3, frac_E2 ), 15 ); frac_E2 = shl( frac_E2, scale ); @@ -402,6 +416,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { L_tmp = Mult_32_16( L_tmp1, ptr[i] ); /*Q(16-exp+Q_exc) */ ptr[i] = round_fx( L_shl( L_tmp, exp ) ); /*Q_exc */ + move16(); } } diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index cb93bdd7c34099e1762509661ca7b91413b85be4..5658d7ef12df28add5131f56e3dabaef09e1cb76 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "enh64.h" @@ -43,10 +42,11 @@ void hvq_dec_fx( Word16 noise_level_idx; bits = num_bits; + move16(); FOR( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) { - noise_level_idx = get_next_indice( st_fx, 2 ); /* 2-bits => max noise_level-idx = 3 */ + noise_level_idx = get_next_indice_fx( st_fx, 2 ); /* 2-bits => max noise_level-idx = 3 */ noise_level[i] = i_mult( noise_level_idx, PK_VQ_NOISE_DELTA ); move16(); /* max noise_level=3*0.1 => Q15 is good enough */ @@ -114,7 +114,7 @@ static void peak_vq_dec_fx( assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); // PMT("max_peaks equation needs to be converted") - max_peaks = (Word16) ( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA ); + max_peaks = extract_l( Mpy_32_32( ( L_add( imult3216( core_brate, HVQ_PEAKS_PER_DELTA ), HVQ_PEAKS_PER_DELTA_OFFS ) ), 282564 ) ); /* 1 / HVQ_PEAKS_BPS_DELTA in Q31 = 282564*/ /*max_peaks = ((core_brate * HVQ_PEAKS_PER_DELTA / HVQ_PEAKS_BPS_DELTA + HVQ_PEAKS_PER_DELTA_OFFS / HVQ_PEAKS_BPS_DELTA) );*/ #if 0 { @@ -126,16 +126,19 @@ static void peak_vq_dec_fx( } #endif bin_th = HVQ_THRES_BIN_24k; + move16(); bin_th2 = HVQ_THRES_BIN_24k / HVQ_NF_GROUPS; + move16(); IF( GE_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { bin_th = HVQ_THRES_BIN_32k; + move16(); bin_th2 = HVQ_THRES_BIN_32k / HVQ_NF_GROUPS; move16(); } /* Get number of peaks */ - vq_peaks = get_next_indice( st_fx, 5 ); + vq_peaks = get_next_indice_fx( st_fx, 5 ); vq_peaks = sub( max_peaks, vq_peaks ); *Npeaks = vq_peaks; move16(); @@ -169,10 +172,12 @@ static void peak_vq_dec_fx( test(); FOR( i = 0; i < bin_th && j < vq_peaks; i++ ) /* safety check in case of bit errors */ { + test(); IF( res_vec[i] != 0 ) { - vq_peak_idx[j++] = i; + vq_peak_idx[j] = i; move16(); + j = add( j, 1 ); } } @@ -183,13 +188,15 @@ static void peak_vq_dec_fx( move16(); vq_peaks = sub( j, 1 ); *Npeaks = sub( j, 1 ); + move16(); } /* Huffman or differential coding */ - FlagN = (Word16) get_next_indice( st_fx, 1 ); + FlagN = (Word16) get_next_indice_fx( st_fx, 1 ); /* De-quantize peak gains */ - pgain_difidx[0] = get_next_indice( st_fx, GAIN0_BITS ); + pgain_difidx[0] = get_next_indice_fx( st_fx, GAIN0_BITS ); + move16(); /* safety check in case of bit errors */ IF( GT_16( pgain_difidx[0], 44 ) ) @@ -211,7 +218,7 @@ static void peak_vq_dec_fx( move16(); IF( FlagN ) { - huff_dec_fx( st_fx, vq_peaks - 1, MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); + huff_dec_fx( st_fx, sub( vq_peaks, 1 ), MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); FOR( i = 1; i < vq_peaks; i++ ) { @@ -223,7 +230,7 @@ static void peak_vq_dec_fx( { FOR( i = 1; i < vq_peaks; i++ ) { - pgain_difidx[i] = get_next_indice( st_fx, GAINI_BITS ); + pgain_difidx[i] = get_next_indice_fx( st_fx, GAINI_BITS ); move16(); hcode_l = add( hcode_l, GAINI_BITS ); } @@ -284,7 +291,7 @@ static void peak_vq_dec_fx( FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - nf_gains_idx[i] = get_next_indice( st_fx, 5 ); + nf_gains_idx[i] = get_next_indice_fx( st_fx, 5 ); move16(); nf_gains_fx[i] = L_shr( dicn_fx[nf_gains_idx[i]], 1 ); move32(); /* nf_gains in Q14 */ @@ -298,7 +305,7 @@ static void peak_vq_dec_fx( /* safety check in case of bit errors */ test(); - if ( pvq_bands == 0 && EQ_16( st_fx->element_mode, EVS_MONO ) ) /* PVQ bands may be zero for IVAS */ + if ( pvq_bands == 0 && st_fx->element_mode == EVS_MONO ) /* PVQ bands may be zero for IVAS */ { st_fx->BER_detect = 1; move16(); @@ -328,11 +335,10 @@ static void peak_vq_dec_fx( pPvqVector = pvq_vector; pCoefsOut = coefs_out; pSelBnds = sel_bnds; - move16(); FOR( k = 0; k < pvq_bands; k++ ) { - pvq_norm[k] = get_next_indice( st_fx, HVQ_PVQ_GAIN_BITS ); - pvq_norm[k] = add( pvq_norm[k], 8 ); + pvq_norm[k] = add( get_next_indice_fx( st_fx, HVQ_PVQ_GAIN_BITS ), 8 ); + // pvq_norm[k] = add( pvq_norm[k], 8 ); move16(); diff = add( diff, HVQ_PVQ_GAIN_BITS ); @@ -343,13 +349,12 @@ static void peak_vq_dec_fx( { i = band_start_harm[*pSelBnds++]; move16(); - move16(); pCoefsOut = coefs_out + i; } normq = L_add( dicn_fx[pvq_norm[k]], 0 ); WHILE( LT_16( j, hvq_band_width[k] ) ) { - IF( EQ_32( *pCoefsOut, 0 ) ) + IF( *pCoefsOut == 0 ) { Mpy_32_16_ss( normq, *pPvqVector++, &acc, &dontCare ); /* acc(Q11), normq(Q14), pvq_vector(Q12) */ *pCoefsOut = L_shl( acc, 12 - 11 ); /* Q12 */ @@ -398,8 +403,8 @@ static void dequant_peaks_fx( Word32 absPeakGain1, absPeakGain; UWord16 dontCare; - hvq_cb_rev = get_next_indice( st_fx, 1 ); - cb_idx = get_next_indice( st_fx, 8 ); + hvq_cb_rev = get_next_indice_fx( st_fx, 1 ); + cb_idx = get_next_indice_fx( st_fx, 8 ); indx = shl( cb_idx, 2 ); IF( hvq_cb_rev ) @@ -439,6 +444,7 @@ static void dequant_peaks_fx( } ELSE { + test(); IF( vect_out[1] == 0 || ( LE_32( absPeakGain1, absPeakGain ) ) ) { Mpy_32_16_ss( *peak_gain, xq[1], &vect_out[1], &dontCare ); @@ -446,6 +452,7 @@ static void dequant_peaks_fx( } } vect_out[2] = *peak_gain; /* vect_out in Q12 */ + move16(); Mpy_32_16_ss( *peak_gain, xq[2], &vect_out[3], &dontCare ); Mpy_32_16_ss( *peak_gain, xq[3], &vect_out[4], &dontCare ); @@ -478,7 +485,7 @@ static Word16 hvq_dec_pos_fx( move16(); set16_fx( pos_vec, 0, length ); - mode = get_next_indice( st_fx, 1 ); + mode = get_next_indice_fx( st_fx, 1 ); num_bits = add( num_bits, 1 ); IF( mode == HVQ_CP_DELTA ) @@ -491,6 +498,7 @@ static Word16 hvq_dec_pos_fx( } peak_idx[0] = sub( delta[0], HVQ_CP_HUFF_OFFSET ); + move16(); /* safety check in case of bit errors */ IF( peak_idx[0] < 2 ) { @@ -527,7 +535,7 @@ static Word16 hvq_dec_pos_fx( FOR( i = 0; i < num_peaks; i++ ) { - IF( get_next_indice_1( st_fx ) == 0 ) + IF( get_next_indice_1_fx( st_fx ) == 0 ) { sign_vec[i] = -1; move16(); @@ -584,7 +592,7 @@ static Word16 sparse_dec_pos_fx( FOR( i = 0; i < layer_length; i++ ) { - layer2[i] = get_next_indice_1( st_fx ); + layer2[i] = get_next_indice_1_fx( st_fx ); move16(); } bits = add( bits, layer_length ); @@ -593,7 +601,7 @@ static Word16 sparse_dec_pos_fx( { IF( EQ_16( layer2[j], 1 ) ) { - idx = get_next_indice( st_fx, HVQ_CP_MAP_IDX_LEN ); + idx = get_next_indice_fx( st_fx, HVQ_CP_MAP_IDX_LEN ); bits = add( bits, HVQ_CP_MAP_IDX_LEN ); val = hvq_cp_layer1_map5[idx]; diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index e4e6f48066cdbca4b010d0c67bc709578e8c71e9..f99c8ac16fba3786da924733a214432c14a7d29f 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #define inv_T0_res InvIntTable @@ -80,6 +79,7 @@ Word32 Mode2_pit_decode( /* o: floating pitch value ELSE IF( EQ_16( coder_type, 3 ) ) /* 9/6/6/6 (HRs- VC) */ { Word16 pit_res_max2 = pit_res_max; + move16(); if ( EQ_16( pit_min, PIT_MIN_16k ) ) { pit_res_max2 = shr( pit_res_max, 1 ); @@ -100,6 +100,7 @@ Word32 Mode2_pit_decode( /* o: floating pitch value ELSE IF( EQ_16( coder_type, 4 ) ) /* 9/6/9/6 (AMRWB) */ { Word16 pit_res_max2 = pit_res_max; + move16(); if ( EQ_16( pit_min, PIT_MIN_16k ) ) { pit_res_max2 = shr( pit_res_max, 1 ); @@ -127,6 +128,7 @@ Word32 Mode2_pit_decode( /* o: floating pitch value { limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); *T0_res = shr( pit_res_max, 1 ); + move16(); Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } @@ -140,6 +142,7 @@ Word32 Mode2_pit_decode( /* o: floating pitch value { limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); *T0_res = shr( pit_res_max, 1 ); + move16(); Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice ); } } @@ -183,6 +186,7 @@ void Mode2_abs_pit_dec( index = **pt_indice; move16(); ( *pt_indice )++; + move16(); pit_res_max_half = shr( pit_res_max, 1 ); tmp1 = i_mult( sub( pit_fr2, pit_min ), pit_res_max ); @@ -199,9 +203,11 @@ void Mode2_abs_pit_dec( } *T0 = mult( index, inv_T0_res[res] ); + move16(); if ( EQ_16( pit_res_max, 6 ) ) { *T0 = shr( *T0, 1 ); + move16(); } *T0 = add( pit_min, *T0 ); @@ -266,18 +272,22 @@ void Mode2_delta_pit_dec( index = **pt_indice; move16(); ( *pt_indice )++; + move16(); *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] ); + move16(); if ( EQ_16( T0_res, 6 ) ) { *T0 = shr( *T0, 1 ); + move16(); } *T0 = add( *T0_min, *T0 ); move16(); *T0_frac = add( index, sub( *T0_min_frac, i_mult( sub( *T0, *T0_min ), T0_res ) ) ); + move16(); return; } @@ -335,6 +345,7 @@ Word16 pit_decode_fx( /* o : floating pitch value Word16 pitch_index, nBits, pit_flag; pitch_index = 0; + move16(); /*----------------------------------------------------------------* * Set pit_flag = 0 for every subframe with absolute pitch search @@ -395,8 +406,7 @@ Word16 pit_decode_fx( /* o : floating pitch value /* find the number of bits */ nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); - pitch_index = (Word16) get_next_indice( st_fx, nBits ); - move16(); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); } /*-------------------------------------------------------* @@ -422,15 +432,13 @@ Word16 pit_decode_fx( /* o : floating pitch value move16(); } - pitch_index = (Word16) get_next_indice( st_fx, nBits ); - move16(); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); test(); test(); IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */ { pitch_index = shr( pitch_index, 1 ); - move16(); st_fx->BER_detect = 1; move16(); } @@ -551,7 +559,7 @@ Word16 pit_decode_fx( /* o : floating pitch value } } - pitch_index = (Word16) get_next_indice( st_fx, nBits ); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } @@ -617,6 +625,7 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value Word16 pitch_index, nBits, pit_flag; pitch_index = 0; + move16(); /*----------------------------------------------------------------* * Set pit_flag = 0 for every subframe with absolute pitch search @@ -675,16 +684,24 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value IF( NE_16( coder_type, AUDIO ) ) { /* find the number of bits */ - nBits = st_fx->acelp_cfg.pitch_bits[i_subfr / L_subfr]; - move16(); - pitch_index = (Word16) get_next_indice( st_fx, nBits ); + IF( i_subfr ) + { + nBits = st_fx->acelp_cfg.pitch_bits[idiv1616( i_subfr, L_subfr )]; + } + ELSE + { + nBits = st_fx->acelp_cfg.pitch_bits[0]; + } move16(); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); } /*-------------------------------------------------------* * Pitch decoding in AUDIO mode * (both ACELP@12k8 and ACELP@16k cores) *-------------------------------------------------------*/ + test(); + test(); IF( EQ_16( coder_type, AUDIO ) ) { test(); @@ -704,15 +721,13 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value move16(); } - pitch_index = (Word16) get_next_indice( st_fx, nBits ); - move16(); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); test(); test(); IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */ { pitch_index = shr( pitch_index, 1 ); - move16(); st_fx->BER_detect = 1; move16(); } @@ -736,8 +751,6 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value #if 1 // def ADD_LRTD ELSE IF( EQ_16( st_fx->idchan, 1 ) && ( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) ) { - test(); - test(); /*-------------------------------------------------------* * Pitch decoding with reusing of primary channel information *-------------------------------------------------------*/ @@ -832,7 +845,7 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value } } - pitch_index = (Word16) get_next_indice( st_fx, nBits ); + pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); } @@ -872,17 +885,23 @@ void pit_Q_dec_fx( IF( limit_flag == 0 ) { *T0 = add( PIT_MIN, shr( pitch_index, 2 ) ); + move16(); *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN ), 2 ) ); + move16(); } ELSE IF( EQ_16( limit_flag, 1 ) ) { *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 2 ) ); + move16(); *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 2 ) ); + move16(); } ELSE /* limit_flag == 2 */ { *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 2 ) ); + move16(); *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 2 ) ); + move16(); } } ELSE IF( EQ_16( nBits, 9 ) ) /* absolute decoding with 9 bits */ @@ -935,7 +954,7 @@ void pit_Q_dec_fx( /* biterror detection mechanism */ test(); test(); - IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), add( ( PIT_MAX << 2 ), 2 ) ) && pit_flag == 0 && !Opt_AMR_WB ) + IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), ( PIT_MAX << 2 ) + 2 ) && pit_flag == 0 && !Opt_AMR_WB ) { *T0 = L_SUBFR; move16(); @@ -988,9 +1007,11 @@ void pit16k_Q_dec_fx( { index = sub( pitch_index, shl( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ), 2 ) ); *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); + move16(); *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); /*(*T0_frac) *= 2;*/ ( *T0_frac ) = shl( *T0_frac, 1 ); + move16(); } } } @@ -1011,7 +1032,8 @@ void pit16k_Q_dec_fx( move16(); *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_9b ), 1 ) ); move16(); - ( *T0_frac ) *= shl( ( *T0_frac ), 1 ); + ( *T0_frac ) = imult1616( ( *T0_frac ), shl( ( *T0_frac ), 1 ) ); + move16(); } ELSE { @@ -1029,7 +1051,7 @@ void pit16k_Q_dec_fx( /* biterror detection mechanism */ test(); - IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), ( PIT16k_MAX << 2 ) ) && GE_16( nBits, 9 ) ) + IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), ( PIT16k_MAX << 2 ) ) && GE_16( nBits, 9 ) ) { *T0 = L_SUBFR; move16(); @@ -1122,6 +1144,7 @@ void abs_pit_dec_fx( *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 1 ) ); move16(); *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 1 ) ); + move16(); *T0_frac = shl( *T0_frac, 1 ); move16(); } @@ -1149,7 +1172,9 @@ void abs_pit_dec_fx( /*pitch_index -= (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4;*/ pitch_index = sub( pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ); *T0 = add( PIT_FR2_EXTEND_9b, shr( pitch_index, 1 ) ); + move16(); *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_FR2_EXTEND_9b ), 1 ) ); + move16(); ( *T0_frac ) = shl( *T0_frac, 1 ); move16(); } diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 78d0fc1f0fa1bc1fd1d7276ed1762884731ad880..9b42a9b576a2a44e7dc711d03f8f249bed584d4f 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -7,8 +7,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" @@ -61,6 +60,11 @@ void pitch_pred_linear_fit( Word16 pg[8]; /* local buffer for pitch gain*/ Word32 ml[8]; /* local buffer for mem_lag*/ Word16 const timeWeight[5] = { 20480 /*1.25f Q14*/, 18432 /*1.125f Q14*/, 16384 /*1.f Q14*/, 14336 /*0.875f Q14*/, 12288 /*.75f Q14*/ }; /*Q14*/ + move16(); + move16(); + move16(); + move16(); + move16(); /*timeweight*/ Word16 no_subfr_pred; Word16 a1, a2, a3, a4, a5, tmpa, tmpb, b1, b2, b3, b4, b5; Word16 a_e, b_e, sum0_q; @@ -84,16 +88,13 @@ void pitch_pred_linear_fit( move32(); } } - move16(); - move16(); - move16(); - move16(); - move16(); /*timeweight*/ IF( LT_16( pit_max, extract_h( *old_fpitch ) ) ) { *extrapolationFailed = 1; + move16(); *T0_out = pit_max; + move16(); return; } @@ -114,8 +115,8 @@ void pitch_pred_linear_fit( } /* copy to local buffers, depending on availability of info about future subframes */ - Copy( mem_pitch_gain + no_subfr_pred - 2, pg, 8 ); - Copy32( mem_lag + no_subfr_pred - 2, ml, 8 ); + Copy( mem_pitch_gain + sub( no_subfr_pred, 2 ), pg, 8 ); + Copy32( mem_lag + sub( no_subfr_pred, 2 ), ml, 8 ); mdy = L_deposit_l( 0 ); @@ -164,6 +165,7 @@ void pitch_pred_linear_fit( Word16 e1, e2, e3, e4, e5, e6, e7; t1 = L_mult0( pg[4], pg[3] ); /*Q24*/ /* t1 = pg[4]*pg[3] */ e1 = 7; + move16(); t2 = L_add( L_deposit_l( pg[3] ), L_shl( L_deposit_l( pg[4] ), 2 ) ); /*Q12*/ e2 = norm_l( t2 ); t2 = L_shl( t2, e2 ); /*Q12,-e2*/ @@ -339,6 +341,7 @@ void get_subframe_pitch( pitchDelta = L_deposit_l( BASOP_Util_Divide3216_Scale( L_sub( pitchEnd, pitchStart ), nSubframes, &s ) ); /*Q15*/ pitchDelta = L_shl( pitchDelta, add( s, 1 ) ); /*Q16*/ pitchBuf[0] = L_add( pitchStart, pitchDelta ); + move32(); FOR( i = 1; i < nSubframes; i++ ) { pitchBuf[i] = L_add( pitchBuf[i - 1], pitchDelta ); diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index 1071b23892a7324ff40524f6858408fa6fb7022e..071bc51886135681fde867ec44e9a3095d6a600e 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #ifdef IVAS_FLOAT_FIXED @@ -61,7 +60,7 @@ void post_decoder( move16(); bitrate = L_add( st->total_brate, 0 ); - if ( st->core_brate <= SID_2k40 ) + if ( LE_32( st->core_brate, SID_2k40 ) ) { bitrate = L_add( st->last_active_brate, 0 ); } @@ -89,7 +88,7 @@ void post_decoder( ELSE { /*Formant enhancement*/ - IF( EQ_16( st->last_bwidth, NB ) ) + IF( st->last_bwidth == NB ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; @@ -114,11 +113,12 @@ void post_decoder( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( st->bwidth == NB ) { st->hPFstat->on = 1; move16(); tmp_noise = 0; + move16(); nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, GENERIC, st->BER_detect, tmp ); } ELSE @@ -126,6 +126,7 @@ void post_decoder( st->hPFstat->on = 0; move16(); tmp_noise = 0; + move16(); nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); } Copy( synth2_pe, synth2, L_frame ); @@ -217,7 +218,7 @@ void post_decoder_ivas_fx( } bitrate = L_add( st->total_brate, 0 ); - IF( LE_32( st->core_brate, SID_2k40 ) ) + if ( LE_32( st->core_brate, SID_2k40 ) ) { bitrate = L_add( st->last_active_brate, 0 ); } @@ -240,17 +241,17 @@ void post_decoder_ivas_fx( IF( pfstat_on_previous ) { Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, synth - M, M ); - Word16 L_subfr = st->L_frame / st->nb_subfr; + Word16 L_subfr = idiv1616( st->L_frame, st->nb_subfr ); Residu3_fx( st->old_Aq_12_8_fx, synth, synth_buf, L_subfr, 1 ); E_UTIL_synthesis( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_subfr, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); scale_st_fx( synth, synth2, &st->hPFstat->gain_prec, L_subfr ); - blend_subfr2_fx( synth2 + L_subfr / 2, synth + L_subfr / 2, synth2 + L_subfr / 2 ); + blend_subfr2_fx( synth2 + shr( L_subfr, 1 ), synth + shr( L_subfr, 1 ), synth2 + shr( L_subfr, 1 ) ); } } ELSE { /*Formant enhancement*/ - IF( EQ_16( st->last_bwidth, NB ) ) + IF( st->last_bwidth == NB ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; @@ -270,16 +271,17 @@ void post_decoder_ivas_fx( move16(); } - IF( EQ_16( pfstat_on_previous, 0 ) ) + if ( pfstat_on_previous == 0 ) { st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( st->bwidth == NB ) { st->hPFstat->on = 1; move16(); tmp_noise = 0; + move16(); nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, GENERIC, st->BER_detect, tmp ); } ELSE @@ -287,6 +289,7 @@ void post_decoder_ivas_fx( st->hPFstat->on = 0; move16(); tmp_noise = 0; + move16(); nb_post_filt_fx( L_frame, st->hPFstat, &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); } Copy( synth2_pe, synth2, L_frame ); @@ -297,7 +300,7 @@ void post_decoder_ivas_fx( } ELSE { - IF( EQ_16( pfstat_on_previous, 0 ) ) + if ( pfstat_on_previous == 0 ) { st->hPFstat->reset = 1; move16(); @@ -383,7 +386,7 @@ static void bass_pf_1sf_delay( lg = 0; move16(); } - if ( lg > l_subfr ) + if ( GT_16( lg, l_subfr ) ) { lg = l_subfr; move16(); @@ -412,12 +415,12 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult( syn[i + i_subfr - T], 0x4000 ); - tmp32 = L_mac( tmp32, syn[i + i_subfr + T], 0x4000 ); + tmp32 = L_mult( syn[sub( add( i, i_subfr ), T )], 0x4000 ); + tmp32 = L_mac( tmp32, syn[add( add( i, i_subfr ), T )], 0x4000 ); tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -432,9 +435,9 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl( syn[i + i_subfr - T], s1 ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp16 = shl( syn[sub( add( i, i_subfr ), T )], s1 ); /* Q0+s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -474,10 +477,10 @@ static void bass_pf_1sf_delay( Word64 ener2_64 = W_deposit32_l( ener2 ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, gain, syn[i + i_subfr - T] ); - tmp32 = L_msu0( tmp32, gain, syn[i + i_subfr + T] ); + tmp32 = L_msu0( 0, gain, syn[sub( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( tmp32, gain, syn[add( add( i, i_subfr ), T )] ); #ifdef BASOP_NOGLOB - tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ + tmp16 = mac_r_sat( tmp32, gain, syn[add( i, i_subfr )] ); /* Q0 */ #else tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif @@ -504,8 +507,8 @@ static void bass_pf_1sf_delay( FOR( i = lg; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_mult0( gain, syn[i + i_subfr] ); - tmp32 = L_msu0_sat( tmp32, gain, syn[i + i_subfr - T] ); /* Q0 */ + tmp32 = L_mult0( gain, syn[add( i, i_subfr )] ); + tmp32 = L_msu0_sat( tmp32, gain, syn[sub( add( i, i_subfr ), T )] ); /* Q0 */ tmp16 = round_fx_sat( tmp32 ); lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); @@ -541,6 +544,7 @@ static void bass_pf_1sf_delay( } *lp_error_ener = L_add( Mpy_32_16_1( L_sub( *lp_error_ener, ener2 ), 32440 /*0.99f Q15*/ ), ener2 ); /* 15Q16 */ + move32(); st = add( st, 6 ); ener2 = L_sub( *lp_error_ener, L_deposit_h( sub( 31, st ) ) ); @@ -587,11 +591,12 @@ static void bass_pf_1sf_delay( { FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, tmp16, syn[i + i_subfr - T] ); + tmp32 = L_msu0( 0, tmp16, syn[sub( add( i, i_subfr ), T )] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr + T] ); - tmp32 = L_mac_sat( tmp32, tmp16, syn[i + i_subfr] ); - bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[add( add( i, i_subfr ), T )] ); + tmp32 = L_mac_sat( tmp32, tmp16, syn[add( i, i_subfr )] ); + bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); tmp32 = L_mac( tmp32, tmp16, syn[i + i_subfr] ); @@ -604,10 +609,11 @@ static void bass_pf_1sf_delay( { FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); + tmp32 = L_mult0( tmp16, syn[add( i, i_subfr )] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); - bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[sub( add( i, i_subfr ), T )] ); + bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); bpf_noise_buf[i + i_subfr] = round_fx( tmp32 ); /* Q0 */ @@ -650,6 +656,7 @@ void cldfb_synth_set_bandsToZero( Word16 i, k, tmp1, tmp2, tmp3, tmp, update_perc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -660,16 +667,23 @@ void cldfb_synth_set_bandsToZero( set32_fx( nrg_band, 0, CLDFB_NO_CHANNELS_MAX ); max_nrg = 0; + move32(); offset = 250; + move16(); WBcnt = 20; - perc_miss = 13107; /*0.80 in Q14*/ + move16(); + perc_miss = 13107; /*0.80 in Q14*/ + move16(); perc_detect = 14746; /*0.90 in Q14*/ + move16(); IF( EQ_16( st->VAD, 1 ) ) { st->active_frame_cnt_bwddec = add( st->active_frame_cnt_bwddec, 1 ); + move16(); st->total_frame_cnt_bwddec = add( st->total_frame_cnt_bwddec, 1 ); + move16(); if ( GT_16( st->active_frame_cnt_bwddec, 99 ) ) { st->active_frame_cnt_bwddec = 100; @@ -681,15 +695,15 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < ( st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero ); i++ ) + FOR( i = 0; i < sub( st->cldfbSyn->no_channels, st->cldfbSyn->bandsToZero ); i++ ) { nrgQ31 = 0; move32(); FOR( k = 0; k < nTimeSlots; k++ ) { /* use 16-bit precision of real and imag buffers */ - realQ1 = extract_l( L_shr( rAnalysis[k][i], 31 - ( 15 + scaleFactor.lb_scale ) + 3 ) ); - imagQ1 = extract_l( L_shr( iAnalysis[k][i], 31 - ( 15 + scaleFactor.lb_scale ) + 3 ) ); /* Q(-3), headroom */ + realQ1 = extract_l( L_shr( rAnalysis[k][i], sub( 31 + 3 - 15, scaleFactor.lb_scale ) ) ); /*31 - (15 + scaleFactor.lb_scale) + 3 )*/ + imagQ1 = extract_l( L_shr( iAnalysis[k][i], sub( 31 + 3 - 15, scaleFactor.lb_scale ) ) ); /* Q(-3), headroom */ #ifdef BASOP_NOGLOB nrgQ31 = L_mac0_o( nrgQ31, realQ1, realQ1, &Overflow ); nrgQ31 = L_mac0_o( nrgQ31, imagQ1, imagQ1, &Overflow ); /* keep in Q(-6) */ @@ -723,6 +737,7 @@ void cldfb_synth_set_bandsToZero( tempQ31 = L_shr( nrgQ31, 9 ); st->avg_nrg_LT = L_add( Mult_32_16( st->avg_nrg_LT, 32440 ), Mult_32_16( tempQ31, 327 ) ); /*0.99*avg_nrg_LT + 0.01*tempQ31*/ + move32(); update_perc = 1; move16(); if ( st->ini_frame >= 25 && tempQ31 < Mult_32_16( st->avg_nrg_LT, 164 ) ) @@ -739,7 +754,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < WBcnt - 1; i++ ) + FOR( i = 0; i < sub( WBcnt, 1 ); i++ ) { st->flag_buffer[i] = st->flag_buffer[i + 1]; move16(); @@ -753,6 +768,7 @@ void cldfb_synth_set_bandsToZero( IF( flag != 0 ) { tmp1 = sub( 16384, st->perc_bwddec ); /*Q14*/ + move16(); tmp = norm_s( st->active_frame_cnt_bwddec ); tmp3 = shl( st->active_frame_cnt_bwddec, tmp ); /*Qtmp*/ @@ -760,10 +776,12 @@ void cldfb_synth_set_bandsToZero( tmp2 = div_s( 16384, tmp3 ); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ tmp2 = mult_r( tmp2, tmp1 ); /*(1-perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ st->perc_bwddec = add( st->perc_bwddec, shl( tmp2, sub( tmp, 14 ) ) ); /* Q14 */ + move16(); } ELSE { tmp1 = ( st->perc_bwddec ); /*Q14*/ + move16(); tmp = norm_s( st->active_frame_cnt_bwddec ); tmp3 = shl( st->active_frame_cnt_bwddec, tmp ); /*Qtmp*/ @@ -771,11 +789,14 @@ void cldfb_synth_set_bandsToZero( tmp2 = div_s( 16384, tmp3 ); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ tmp2 = mult_r( tmp2, tmp1 ); /*(perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ st->perc_bwddec = sub( st->perc_bwddec, shl( tmp2, sub( tmp, 14 ) ) ); /* Q14 */ + move16(); } } test(); IF( GT_16( st->total_frame_cnt_bwddec, offset ) && GT_16( st->active_frame_cnt_bwddec, 50 ) ) { + test(); + test(); IF( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); @@ -797,6 +818,7 @@ void cldfb_synth_set_bandsToZero( IF( sum16_fx( st->flag_buffer, WBcnt ) == 0 ) { st->perc_bwddec = 0; + move16(); st->active_frame_cnt_bwddec = 0; move16(); st->total_frame_cnt_bwddec = 0; @@ -807,12 +829,13 @@ void cldfb_synth_set_bandsToZero( } ELSE { - IF( st->last_flag_filter_NB == 1 ) + if ( EQ_16( st->last_flag_filter_NB, 1 ) ) { st->cldfbSyn->bandsToZero = st->last_active_bandsToZero_bwdec; move16(); } st->total_frame_cnt_bwddec = add( st->total_frame_cnt_bwddec, 1 ); + move16(); if ( GT_16( st->total_frame_cnt_bwddec, 500 ) ) { st->total_frame_cnt_bwddec = 500; @@ -821,6 +844,7 @@ void cldfb_synth_set_bandsToZero( } st->last_active_bandsToZero_bwdec = st->cldfbSyn->bandsToZero; + move16(); return; } diff --git a/lib_dec/ppp_dec.c b/lib_dec/ppp_dec.c index be326a76449483b710455054c4b9fc20614e7495..84cc2802fed1855a5a0332c1a594a5128a51eef6 100644 --- a/lib_dec/ppp_dec.c +++ b/lib_dec/ppp_dec.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * DTFS_dequant_cw() * @@ -181,3 +182,4 @@ ivas_error ppp_quarter_decoder( return error; } +#endif diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 24461a7fb5ce7becb26309088bcdaa41c972b9a1..7d8bcb0056c5b4640c1fd93be4646f45e20cf550 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /*===================================================================*/ @@ -58,12 +57,12 @@ static void DTFS_dequant_cw_fx( Word32 L_tmp, L_temp; Word32 L_tmp2; - IF( num_erb_fx == NUM_ERB_NB ) + IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { PowerCB_fx = PowerCB_NB_fx; move16(); } - ELSE IF( num_erb_fx == NUM_ERB_WB ) + ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { PowerCB_fx = PowerCB_WB_fx; move16(); @@ -73,12 +72,14 @@ static void DTFS_dequant_cw_fx( erb_add_fx( curr_erb_fx, X_fx->lag_fx, lasterbD_fx, pl_fx, AMP_IDX_fx, num_erb_fx ); - curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ + curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ + move16(); curr_erb_fx[sub( num_erb_fx, 2 )] = mult_r( curr_erb_fx[sub( num_erb_fx, 3 )], 9830 ); /* Q13 */ - move16(); + curr_erb_fx[sub( num_erb_fx, 1 )] = 0; + move16(); erb_slot_fx( X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx ); @@ -93,7 +94,8 @@ static void DTFS_dequant_cw_fx( /* Need to unify the Q factors of both bands */ X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ - n = sub( Ql, Qh ); /* compare band Q factors */ + move16(); + n = sub( Ql, Qh ); /* compare band Q factors */ /* This logic adjusts difference between Q formats of both bands */ @@ -115,6 +117,8 @@ static void DTFS_dequant_cw_fx( *lastLgainD_fx = add( *lastLgainD_fx, PowerCB_fx[tmp_fx] ); /* Q11 */ *lastHgainD_fx = add( *lastHgainD_fx, PowerCB_fx[tmp_fx + 1] ); /* Q11 */ #endif + move16(); + move16(); L_tmp = L_deposit_h( X_fx->lag_fx ); /* Q16 */ exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); @@ -171,6 +175,7 @@ static void DTFS_dequant_cw_fx( L_temp = L_shl( L_tmp, exp1 + 15 ); /* Q15 */ #endif L_tmp2 = L_temp; + move32(); if ( GE_32( L_temp, 2147483647 ) ) { L_temp = L_shl( L_tmp, 15 ); /*Q(15-exp1) */ @@ -192,7 +197,8 @@ static void DTFS_dequant_cw_fx( /* Need to unify the Q factors of both bands */ X_fx->Q = s_min( Ql, Qh ); /* set Q factor to be the smaller one */ - n = sub( Ql, Qh ); /* compare band Q factors */ + move16(); + n = sub( Ql, Qh ); /* compare band Q factors */ IF( n < 0 ) @@ -255,11 +261,16 @@ ivas_error ppp_quarter_decoder_fx( DTFS_STRUCTURE *PREVDTFS_FX; Word16 AMP_IDX_fx[2]; Word16 temp_pl_fx = prevCW_lag_fx, temp_l_fx = CURRCW_Q_DTFS_FX->lag_fx; + move16(); + move16(); Word16 temp_fx; Word16 l_fx = CURRCW_Q_DTFS_FX->lag_fx; + move16(); Word16 POWER_IDX_fx; Word16 Erot_fx = 0; + move16(); Word16 num_erb_fx = 24; + move16(); Word32 temp32d_fx, temp32n_fx; Word32 L_tmp, L_tmp1; Word16 tmp, exp; @@ -267,7 +278,7 @@ ivas_error ppp_quarter_decoder_fx( error = IVAS_ERR_OK; move16(); - IF( ( error = DTFS_new_fx( &PREVDTFS_FX ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVDTFS_FX ) ), IVAS_ERR_OK ) ) { return error; } @@ -286,11 +297,10 @@ ivas_error ppp_quarter_decoder_fx( DTFS_copy_fx( PREVDTFS_FX, PREV_CW_D_FX ); IF( bfi == 0 ) { - POWER_IDX_fx = (Word16) get_next_indice( st_fx, 6 ); - move16(); - AMP_IDX_fx[0] = (Word16) get_next_indice( st_fx, 6 ); + POWER_IDX_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + AMP_IDX_fx[0] = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); - AMP_IDX_fx[1] = (Word16) get_next_indice( st_fx, 6 ); + AMP_IDX_fx[1] = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); /* Amplitude Dequantization */ @@ -299,18 +309,22 @@ ivas_error ppp_quarter_decoder_fx( This logic of normalisation is not employed in adjustlag, hence denormalisation is necessury.*/ /*As the upper cut of freqencies are normalized to 12800, we have to multiply upper cut off freq by 2.56(1/12800 in Q15) */ - temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 10486 ); /* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16) L_shr( temp32n_fx, 13 ); /*Q15 */ - temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx, 10486 ); /* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16) L_shr( temp32n_fx, 13 ); /*Q15 */ + temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = extract_l( L_shr( temp32n_fx, 13 ) ); /*Q15 */ + move16(); + temp32n_fx = L_mult( CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx, 10486 ); /* Q0+Q27 = Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = extract_l( L_shr( temp32n_fx, 13 ) ); /*Q15 */ + move16(); DTFS_dequant_cw_fx( prevCW_lag_fx, POWER_IDX_fx, AMP_IDX_fx, lastLgainD_fx, lastHgainD_fx, lasterbD_fx, CURRCW_Q_DTFS_FX, num_erb_fx ); /*De-normalize cut off frequencies */ - temp32n_fx = L_shl( (Word32) CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx, 13 ); /*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16) find_remd( temp32n_fx, 20971, &temp32d_fx ); - temp32n_fx = L_shl( (Word32) CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx, 13 ); /*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16) find_remd( temp32n_fx, 20971, &temp32d_fx ); + temp32n_fx = L_shl( L_deposit_l( CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx ), 13 ); /*Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = extract_l( find_remd( temp32n_fx, 20971, &temp32d_fx ) ); + move16(); + temp32n_fx = L_shl( L_deposit_l( CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx ), 13 ); /*Q28 */ + CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = extract_l( find_remd( temp32n_fx, 20971, &temp32d_fx ) ); + move16(); } /* Copying phase spectrum over */ @@ -344,13 +358,13 @@ ivas_error ppp_quarter_decoder_fx( copy_phase_fx( PREVDTFS_FX, *CURRCW_Q_DTFS_FX, CURRCW_Q_DTFS_FX ); { - temp_fx = (Word16) get_next_indice( st_fx, 3 ); + temp_fx = (Word16) get_next_indice_fx( st_fx, 3 ); temp_fx = sub( temp_fx, 3 ); temp_fx = shl( temp_fx, 2 ); /*Q2 */ Q2phaseShift_fx( CURRCW_Q_DTFS_FX, temp_fx, CURRCW_Q_DTFS_FX->lag_fx, S_fx, C_fx ); } - count_free( PREVDTFS_FX ); + free( PREVDTFS_FX ); return error; } diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 6333fd52db795093a0381bb7d345e78566364601..5d66001daba27bd341627ba011728d82a17233cb 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -43,6 +43,7 @@ #include "stl.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local prototypes * @@ -521,3 +522,4 @@ static int16_t get_pvq_splits( return Np; } +#endif diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 65f94c31742942cdea1ffa76a2a713a1fc5bdabd..cf904fac67d7c8b4920f6946e7b860d9a2a23c0c 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_dec/pvq_decode.c b/lib_dec/pvq_decode.c index b5be8605b60fecdbed56dcbf66f3fe80cda9072b..294838e9a90e7b7e7cc912b6f674acedf8db1f48 100644 --- a/lib_dec/pvq_decode.c +++ b/lib_dec/pvq_decode.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function pvq_decode() * * * @@ -107,3 +108,4 @@ void pvq_decode( return; } +#endif diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index 1ae7b0988433d98d4cd1b43a63709103b0fc5d9d..24aa0cfac335eadccd4b666f93925e8481083323 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" /* Compilation switches */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /*-------------------------------------------------------------------* diff --git a/lib_dec/range_dec.c b/lib_dec/range_dec.c index 1aa0f116e61e7a09399de77d695085aa6321cca1..4ad813b42e0f37ab5bb2d001fb9b59789859a32b 100644 --- a/lib_dec/range_dec.c +++ b/lib_dec/range_dec.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ @@ -243,3 +244,4 @@ static int16_t rc_dec_read( return get_next_indice( st, 8 ); } } +#endif diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index 440137a9595fdf8b0a330add1285fb992ccf5bdd..960662e76730180f955d8b3b5eb59f26e5efa0ef 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -3,11 +3,10 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -216,10 +215,10 @@ static Word16 rc_dec_read_fx( /* If the end of the buffer has been reached, pad the last byte with zeros */ IF( sub( bits, 8 ) < 0 ) { - return shl( get_next_indice( st_fx, bits ), sub( 8, bits ) ); + return shl( get_next_indice_fx( st_fx, bits ), sub( 8, bits ) ); } ELSE { - return get_next_indice( st_fx, 8 ); + return get_next_indice_fx( st_fx, 8 ); } } diff --git a/lib_dec/re8_dec_fx.c b/lib_dec/re8_dec_fx.c index e1177d1ec19595a381976fe446d638ef100a1386..e6c35e29339fc8dc0f9080434b1ab8ed19f6f9e9 100644 --- a/lib_dec/re8_dec_fx.c +++ b/lib_dec/re8_dec_fx.c @@ -3,9 +3,8 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------------- * re8_dec_fx() diff --git a/lib_dec/rom_dec.c b/lib_dec/rom_dec.c index 062f4df35b5b9a5926d08d1092dc8e046fe4354c..8a2169f802dc3b1b331cd5021e5c6b7619601169 100644 --- a/lib_dec/rom_dec.c +++ b/lib_dec/rom_dec.c @@ -47,7 +47,7 @@ *----------------------------------------------------------------------------------*/ const float h_low[5] = { -0.0125f, 0.1090f, 0.7813f, 0.1090f, -0.0125f }; -const Word16 H_low[5] = +const Word16 h_low_fx[5] = { -410, 3572, 25602, 3572, -410 }; diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index 6402bb6d3d32c94a431b0ceb057bedf265b08b53..dca09eedf89754a4a28bf76ac1ed2e7139f9a976 100644 --- a/lib_dec/rom_dec.h +++ b/lib_dec/rom_dec.h @@ -42,7 +42,7 @@ #include "cnst.h" extern const float h_low[]; /* LP filter for filtering periodic part of excitation in artificial onset construction after FEC */ -extern const Word16 H_low[5]; +extern const Word16 h_low_fx[5]; extern const Word16 inv_sqi[15]; extern const Word16 sqi[15]; extern const int16_t mult_avq_tab[]; diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index a4810115b23a880ded13935e3c241b43dffcae4a..50aa1b9068f66daeaafbc8cf25e9e16ecb29e42b 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -4,10 +4,9 @@ #include "options.h" /* Compilation switches */ #include "stl.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*----------------------------------------------------------------------------------* * CNG_reset_dec() diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index b3c6998b6db95a0306842b792e7c758f0da3a28d..7f8823cd1aedbf0c17e1e7bfcceb9f5e728ee4c6 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -3,9 +3,8 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ /*---------------------------------------------------------* @@ -38,7 +37,7 @@ void stat_noise_uv_dec_fx( IF( ( EQ_16( coder_type, UNVOICED ) && !uc_two_stage_flag ) || ( coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) { /* read the noisiness parameter */ - noisiness = (Word16) get_next_indice( st_fx, 5 ); + noisiness = (Word16) get_next_indice_fx( st_fx, 5 ); } /*-----------------------------------------------------------------* diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index f2b096d725929ed1ef77db77b70e52c5750b0b16..967070b7814d76aa7840954256ee64114e2215c8 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -39,15 +39,12 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" #include "basop_proto_func.h" #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#endif // IVAS_FLOAT_FIXED #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -528,9 +525,7 @@ static int16_t WB_BWE_gain_deq( return ( mode ); } -#endif -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * wb_bwe_dec_flt() * @@ -640,7 +635,6 @@ void wb_bwe_dec_flt( return; } -#endif /*-------------------------------------------------------------------* * swb_bwe_gain_deq_flt() @@ -846,7 +840,7 @@ int16_t swb_bwe_gain_deq_flt( * * SWB BWE decoder *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void swb_bwe_dec_flt( Decoder_State *st, /* i/o: decoder state structure */ const float output[], /* i : synthesis @internal Fs */ @@ -1055,7 +1049,6 @@ void swb_bwe_dec_flt( #endif #ifdef IVAS_FLOAT_FIXED - Word16 swb_bwe_dec_fx32( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ @@ -1241,7 +1234,7 @@ Word16 swb_bwe_dec_fx32( { IF( !st_fx->bfi ) { - idxGain = (Word16) get_next_indice( st_fx, NUM_BITS_FB_FRAMEGAIN ); + idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN ); fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */ } ELSE IF( st_fx->bfi ) diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 742706db389313627d88c363c2b921208e470516..3fc6c961788b1971a1aabf7d5e430ab3c6496c81 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "rom_enc.h" #include "ivas_prot_fx.h" @@ -316,8 +315,8 @@ Word16 WB_BWE_gain_deq_fx( Word32 L_tmp; Word16 tmp, exp, frac; - index = (Word16) get_next_indice( st_fx, 5 ); - mode = add( extract_l( get_next_indice( st_fx, 1 ) ), 2 ); + index = (Word16) get_next_indice_fx( st_fx, 5 ); + mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); L_tmp = L_shr( F_2_5_fx[index2], 1 ); @@ -708,10 +707,10 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class IF( hqswb_clas > 0 ) { - mode = (Word16) get_next_indice( st_fx, 1 ); + mode = (Word16) get_next_indice_fx( st_fx, 1 ); IF( mode == 0 ) { - mode = (Word16) get_next_indice( st_fx, 1 ); + mode = (Word16) get_next_indice_fx( st_fx, 1 ); } ELSE { @@ -721,7 +720,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class } ELSE { - mode = (Word16) get_next_indice( st_fx, 2 ); + mode = (Word16) get_next_indice_fx( st_fx, 2 ); } test(); @@ -729,14 +728,14 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class { FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { - index = (Word16) get_next_indice( st_fx, 4 ); + index = (Word16) get_next_indice_fx( st_fx, 4 ); SWB_tenv[n_band] = shl_sat( 1, index ); move16(); } - indice[0] = (Word16) get_next_indice( st_fx, 7 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 7 ); move16(); - indice[1] = (Word16) get_next_indice( st_fx, 6 ); + indice[1] = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); tmp = shl( indice[0], 1 ); @@ -822,13 +821,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < 5; n_band++ ) { - indice[n_band] = (Word16) get_next_indice( st_fx, nb_bits[n_band] ); + indice[n_band] = (Word16) get_next_indice_fx( st_fx, nb_bits[n_band] ); move16(); } IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - indice[n_band] = (Word16) get_next_indice( st_fx, 5 ); + indice[n_band] = (Word16) get_next_indice_fx( st_fx, 5 ); move16(); } @@ -1114,7 +1113,7 @@ Word16 swb_bwe_dec_fx( { IF( !st_fx->bfi ) { - idxGain = (Word16) get_next_indice( st_fx, NUM_BITS_FB_FRAMEGAIN ); + idxGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_FB_FRAMEGAIN ); fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */ } ELSE IF( st_fx->bfi ) diff --git a/lib_dec/swb_bwe_dec_hr.c b/lib_dec/swb_bwe_dec_hr.c index 5d090e7088ccab3ec7ab946dd07d6e71eed2062c..949b45481b52e5434463bb90f4ae7fa8c9bb8b99 100644 --- a/lib_dec/swb_bwe_dec_hr.c +++ b/lib_dec/swb_bwe_dec_hr.c @@ -41,8 +41,8 @@ #include "rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* * swb_bwe_dec_hr() diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index ed6ed4ae62d40f1cdbe3ffe83fb7ee70d19583b7..51880fe619ec660fd521a1451d6b0647223105db 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -2,12 +2,11 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_dec.h" /* Static table prototypes */ -#include "cnst.h" /* Static table prototypes */ +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" /* Function prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_dec.h" /* Static table prototypes */ +#include "cnst.h" /* Static table prototypes */ #define Q_GUARD 1 #define Q_32_BITS 14 /* scaling of 't_audio32' */ @@ -506,7 +505,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * get transient frame flag *---------------------------------------------------------------------*/ - is_transient = (Word16) get_next_indice( st_fx, 1 ); + is_transient = (Word16) get_next_indice_fx( st_fx, 1 ); IF( is_transient ) { @@ -546,21 +545,21 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB *---------------------------------------------------------------------*/ /* get global gain */ - ind1 = (Word16) get_next_indice( st_fx, NBITS_GLOB_GAIN_BWE_HR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_GLOB_GAIN_BWE_HR ); gain_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); /* get energy per band */ IF( k == 0 ) { - ind1 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR_TR ); ind2 = ind1; move16(); nBits = sub( nBits, NBITS_ENVELOPE_BWE_HR_TR ); } ELSE { - ind1 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR_TR - 1 ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR_TR - 1 ); if ( GE_16( ind2, 8 ) ) { ind1 = add( ind1, NUM_ENVLOPE_CODE_HR_TR2 ); @@ -586,7 +585,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - ind1 = (Word16) get_next_indice( st_fx, NBITS_HF_GAIN_BWE_HR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_HF_GAIN_BWE_HR ); nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); IF( EQ_16( ind1, 1 ) ) @@ -780,12 +779,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB *---------------------------------------------------------------------*/ /* get global gain */ - ind1 = (Word16) get_next_indice( st_fx, NBITS_GLOB_GAIN_BWE_HR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_GLOB_GAIN_BWE_HR ); gain_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); /* get energy per band */ - ind1 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR1 ); - ind2 = (Word16) get_next_indice( st_fx, NBITS_ENVELOPE_BWE_HR2 ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR1 ); + ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); en_band[0] = swb_hr_env_code1_fx[temp]; @@ -841,7 +840,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) ) { - ind1 = (Word16) get_next_indice( st_fx, NBITS_HF_GAIN_BWE_HR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_HF_GAIN_BWE_HR ); nBits = sub( nBits, NBITS_HF_GAIN_BWE_HR ); if ( EQ_16( ind1, 1 ) ) @@ -881,7 +880,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB test(); IF( GE_16( nBits, 9 + NBITS_GLOB_GAIN_BWE_HR ) && sum16_fx( nq, Nsv ) > 0 ) { - ind1 = (Word16) get_next_indice( st_fx, NBITS_GLOB_GAIN_BWE_HR ); + ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_GLOB_GAIN_BWE_HR ); gain2_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp2 ); /* gain2_flt *= 0.0625f */ exp2 = add( exp2, 4 ); diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index 52c200bc4a97369dfe70d856579e1dd16d1ec16c..fa9dcfc588f084f52a594e139e042f4cc1c95677 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -4,8 +4,7 @@ #include "options.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" /*-------------------------------------------------------------------* @@ -30,14 +29,14 @@ static void DecodeSWBGenericParameters_fx( { IF( EQ_16( hq_swb_clas_fx, HQ_HARMONIC ) ) { - lagIndices_fx[sb] = (Word16) get_next_indice( st_fx, bits_lagIndices_mode0_Har[sb] ); + lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_mode0_Har[sb] ); move16(); } ELSE { IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) { - lagIndices_fx[sb] = (Word16) get_next_indice( st_fx, bits_lagIndices_modeNormal[sb] ); + lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); move16(); } ELSE @@ -144,7 +143,7 @@ static void DecodeSWBSubbands_fx( /* Generate HF noise */ genhf_noise_fx( sspectra_diff_fx, Qss, L_xSynth_har, QsL, sspectra_fx, BANDS_fx, har_bands_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow_fx, fLenHigh_fx, sbWidth_fx, lagIndices_fx, subband_offsets_fx, subband_search_offset_fx ); - imin_fx = (Word16) get_next_indice( st_fx, 2 ); + imin_fx = (Word16) get_next_indice_fx( st_fx, 2 ); /* g= pow(10.0f, gain_table_SWB_BWE[imin]) */ L_temp = L_mult( gain_table_SWB_BWE_fx[imin_fx], 27213 ); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ L_temp = L_shr( L_temp, 12 ); /* Q28-Q12 -> Q16 */ diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 613e82b3f007487001a7f8d04985c4bf01a662ec..5b2e33cfe4fb3035dcfaaf8087a34a67fcd84e38 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -39,8 +39,7 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "rom_dec.h" #include "wmc_auto.h" @@ -338,6 +337,15 @@ void wb_tbe_dec( prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD / 4 ); curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD / 4, L_SHB_LAHEAD / 4 ); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + if ( st->element_mode > EVS_MONO ) + { + /* prevent too low values of energy */ + prev_pow = max( 0.00001f, prev_pow ); + curr_pow = max( 0.00001f, curr_pow ); + } +#endif + if ( voice_factors[0] > 0.75f ) { curr_pow *= 0.25; @@ -1973,8 +1981,11 @@ void ivas_swb_tbe_dec_fx( #endif } } - ener_fx = s_max( 1, round_fx( L_shl( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ - +#ifdef BASOP_NOGLOB /* Saturation fix taken from EVS*/ + ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ +#else + ener_fx = s_max( 1, round_fx( L_shl( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ +#endif /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { @@ -2654,7 +2665,11 @@ void ivas_swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); +#ifdef BASOP_NOGLOB /* Saturation fix taken from EVS*/ + st->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else st->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif move16(); } @@ -2672,7 +2687,11 @@ void ivas_swb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); - tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#ifdef BASOP_NOGLOB /* Saturation fix taken from EVS*/ + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#else + tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ +#endif } set16_fx( st->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } @@ -3438,6 +3457,15 @@ void swb_tbe_dec( prev_pow = sum2_f( shaped_shb_excitation, L_SHB_LAHEAD + 10 ); curr_pow = sum2_f( shaped_shb_excitation + L_SHB_LAHEAD + 10, L_SHB_LAHEAD + 10 ); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + if ( st->element_mode > EVS_MONO ) + { + /* prevent too low values of energy */ + prev_pow = max( 0.00001f, prev_pow ); + curr_pow = max( 0.00001f, curr_pow ); + } +#endif + if ( voice_factors[0] > 0.75f ) { curr_pow *= 0.25; @@ -4795,7 +4823,7 @@ void TBEreset_dec( hBWE_TD->bwe_non_lin_prev_scale = 0.f; #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word16( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); st->prev_Q_bwe_exc = 31; #endif @@ -4815,16 +4843,16 @@ void TBEreset_dec( set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word16( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set_val_Word16( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set_val_Word16( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); + set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); #endif set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_csfilt, 0, 2 ); #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word32( hBWE_TD->mem_csfilt_fx, 0, 2 ); + set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); #endif } else if ( st->bwidth == SWB || st->bwidth == FB ) @@ -4837,7 +4865,7 @@ void TBEreset_dec( #ifdef IVAS_FLOAT_FIXED swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set_val_Word16( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); #endif set_f( hBWE_TD->int_3_over_2_tbemem_dec, 0.f, INTERP_3_2_MEM_LEN ); @@ -4869,7 +4897,7 @@ void TBEreset_dec( fb_tbe_reset_synth( hBWE_TD->fbbwe_hpf_mem, &hBWE_TD->prev_fbbwe_ratio ); #endif #ifdef IVAS_FLOAT_FIXED - set_val_Word16( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); #endif diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 333361cc8b0042ebf4805193b4188de398e17d6c..091915667571a8d7c23df57c502fd0766bc5d713 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_dec.h" #include "stl.h" @@ -678,7 +677,7 @@ void ivas_wb_tbe_dec_fx( #endif TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - set_val_Word32( &dummy2[0], 0, HILBERT_MEM_SIZE ); + set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); IF( st_fx->bws_cnt == 0 ) { /* Initialization */ @@ -909,6 +908,17 @@ void ivas_wb_tbe_dec_fx( prev_pow = 0; move32(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#else + prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ @@ -934,6 +944,17 @@ void ivas_wb_tbe_dec_fx( curr_pow = 0; move32(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ +#else + curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ @@ -1325,7 +1346,7 @@ void wb_tbe_dec_fx( #endif TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - set_val_Word32( &dummy2[0], 0, HILBERT_MEM_SIZE ); + set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); IF( st_fx->bws_cnt == 0 ) { /* Initialization */ @@ -1555,6 +1576,17 @@ void wb_tbe_dec_fx( prev_pow = 0; move32(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#else + prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1589,6 +1621,17 @@ void wb_tbe_dec_fx( curr_pow = 0; move32(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ +#else + curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -4076,8 +4119,8 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); - idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); } Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); @@ -4086,11 +4129,11 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - *uv_flag = (Word16) get_next_indice( st_fx, 1 ); + *uv_flag = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); - idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); + idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain ); + idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_WB_LSF ); Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); @@ -4130,14 +4173,14 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); } ELSE { - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); } } @@ -4146,7 +4189,7 @@ void ivas_dequantizeSHBparams_fx_9_1( test(); IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) { - *MSFlag = (Word16) get_next_indice( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + *MSFlag = (Word16) get_next_indice_fx( st_fx, STEREO_ICBWE_MSFLAG_BITS ); move16(); } ELSE @@ -4164,7 +4207,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ @@ -4187,7 +4230,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], @@ -4205,7 +4248,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); } *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); move16(); @@ -4218,7 +4261,7 @@ void ivas_dequantizeSHBparams_fx_9_1( test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); move16(); } @@ -4246,7 +4289,7 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) { set16_fx( lsf_idx, 0, 5 ); - lsf_idx[0] = (Word16) get_next_indice( st_fx, 8 ); + lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); move16(); grid_idx = 0; move16(); @@ -4274,7 +4317,7 @@ void ivas_dequantizeSHBparams_fx_9_1( /* VQ part */ num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; - Idx = get_next_indice( st_fx, num_bits_lvq ); + Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ @@ -4286,13 +4329,13 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( EQ_16( num_bits_lvq, 16 ) ) { /* MSLVQ part */ - Idx_lvq = L_add( get_next_indice( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice( st_fx, 1 ), 15 ) ); + Idx_lvq = L_add( get_next_indice_fx( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice_fx( st_fx, 1 ), 15 ) ); deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); } ELSE { /* MSLVQ part */ - Idx_lvq = get_next_indice( st_fx, num_bits_lvq ); + Idx_lvq = get_next_indice_fx( st_fx, num_bits_lvq ); deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); } @@ -4309,7 +4352,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - Idx_pred = (Word16) get_next_indice( st_fx, 1 ); + Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); move16(); lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); @@ -4318,7 +4361,7 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) { - Idx_pred = (Word16) get_next_indice( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); + Idx_pred = (Word16) get_next_indice_fx( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); } v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); @@ -4344,7 +4387,7 @@ void ivas_dequantizeSHBparams_fx_9_1( { FOR( i = 0; i < NUM_Q_LSF; i++ ) { - lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); + lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); move16(); } } @@ -4358,7 +4401,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); + m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); } Dequant_mirror_point_fx( lsf_q, m_idx, &m ); @@ -4379,7 +4422,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); } Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); @@ -4528,11 +4571,11 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - *uv_flag = (Word16) get_next_indice( st_fx, 1 ); + *uv_flag = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); - idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); + idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain ); + idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_WB_LSF ); Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); @@ -4572,8 +4615,8 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); } test(); @@ -4586,7 +4629,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ @@ -4609,7 +4652,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], @@ -4627,7 +4670,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); } *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); move16(); @@ -4671,7 +4714,7 @@ static void dequantizeSHBparams_fx_9_1( { FOR( i = 0; i < NUM_Q_LSF; i++ ) { - lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); + lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); move16(); } } @@ -4685,7 +4728,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); + m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); } Dequant_mirror_point_fx( lsf_q, m_idx, &m ); @@ -4706,7 +4749,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); } Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); @@ -4815,7 +4858,7 @@ void fb_tbe_dec_fx( } ELSE { - i = (Word16) get_next_indice( st, 4 ); + i = (Word16) get_next_indice_fx( st, 4 ); } #ifdef BASOP_NOGLOB ratio = shl_sat( 1, i ); @@ -4882,7 +4925,7 @@ void fb_tbe_dec_ivas_fx( } ELSE { - i = (Word16) get_next_indice( st, 4 ); + i = (Word16) get_next_indice_fx( st, 4 ); } #ifdef BASOP_NOGLOB ratio = shl_sat( 1, i ); @@ -4943,11 +4986,11 @@ void tbe_read_bitstream_fx( IF( ( EQ_16( st_fx->rf_flag, 1 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) && EQ_16( st_fx->bwidth, WB ) ) { /* WB LSF */ - hBWE_TD->lsf_WB = (Word16) get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); + hBWE_TD->lsf_WB = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); move16(); /* WB frame gain */ - hBWE_TD->gFrame_WB = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + hBWE_TD->gFrame_WB = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); move16(); } ELSE IF( ( GE_32( st_fx->total_brate, ACELP_9k60 ) ) && ( LE_32( st_fx->total_brate, ACELP_32k ) ) && @@ -4958,18 +5001,18 @@ void tbe_read_bitstream_fx( { FOR( i = 0; i < NUM_Q_LSF; i++ ) { - hBWE_TD->lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); + hBWE_TD->lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); move16(); } - hBWE_TD->m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); + hBWE_TD->m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); move16(); - hBWE_TD->grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + hBWE_TD->grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); move16(); } ELSE { - hBWE_TD->lsf_idx[0] = (Word16) get_next_indice( st_fx, 8 ); + hBWE_TD->lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); move16(); hBWE_TD->m_idx = 0; move16(); @@ -4978,36 +5021,36 @@ void tbe_read_bitstream_fx( } /* shape gains */ - hBWE_TD->idxSubGains = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + hBWE_TD->idxSubGains = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); move16(); /* frame gain */ - hBWE_TD->idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + hBWE_TD->idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); move16(); IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { /* sub frame energy*/ - hBWE_TD->idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + hBWE_TD->idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); move16(); /* gain shapes residual */ FOR( i = 0; i < NB_SUBFR16k; i++ ) { - hBWE_TD->idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + hBWE_TD->idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } /* voicing factor */ - hBWE_TD->idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + hBWE_TD->idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); move16(); } IF( EQ_16( st_fx->tec_tfa, 1 ) ) { - st_fx->tec_flag = (Word16) get_next_indice( st_fx, BITS_TEC ); + st_fx->tec_flag = (Word16) get_next_indice_fx( st_fx, BITS_TEC ); move16(); - st_fx->tfa_flag = (Word16) get_next_indice( st_fx, BITS_TFA ); + st_fx->tfa_flag = (Word16) get_next_indice_fx( st_fx, BITS_TFA ); move16(); test(); IF( st_fx->tfa_flag && st_fx->tec_flag ) @@ -5029,7 +5072,7 @@ void tbe_read_bitstream_fx( IF( EQ_16( st_fx->bwidth, FB ) ) { - hBWE_TD->idxGain = (Word16) get_next_indice( st_fx, 4 ); + hBWE_TD->idxGain = (Word16) get_next_indice_fx( st_fx, 4 ); move16(); } } diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 67399e2dd2e1b6c3ce32debe490a94eb52cd3d1e..0cdf219731e787f98811661b847a02f8d4bf9947 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -3,10 +3,9 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Debug prototypes */ -#include "prot_fx2.h" /* Debug prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Debug prototypes */ /*-------------------------------------------------------------------* * syn_output() diff --git a/lib_dec/tcq_core_dec.c b/lib_dec/tcq_core_dec.c index d7e61dfe47d64e034ee17833e22ade4d77e3cc94..78a0356c421ee30941cb969d73d6317613492e2f 100644 --- a/lib_dec/tcq_core_dec.c +++ b/lib_dec/tcq_core_dec.c @@ -43,6 +43,7 @@ #include "basop_proto_func.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * tcq_core_LR_enc() * @@ -471,3 +472,4 @@ void tcq_core_LR_dec( return; } +#endif diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 0e3fa5f90340e3f81664983aa5e54bb454f94291..0986f5d17677b77a0881b3ae717f40b8242bcc8b 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -6,8 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*---------------------------------------------------------------------* * tcq_core_LR_dec() * @@ -164,14 +163,14 @@ void tcq_core_LR_dec_fx( k = sub( bit_budget, shl( nb_bytes, 3 ) ); FOR( i = 0; i < nb_bytes; i++ ) { - pbs_fx->buf[i] = (UWord8) get_next_indice( st_fx, 8 ); + pbs_fx->buf[i] = (UWord8) get_next_indice_fx( st_fx, 8 ); move16(); } IF( k > 0 ) { Word16 tmp; - tmp = (Word16) get_next_indice( st_fx, k ); + tmp = (Word16) get_next_indice_fx( st_fx, k ); pbs_fx->buf[nb_bytes] = (UWord8) shl( tmp, sub( 8, k ) ); move16(); /* i++; diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index 7eb2d7576d44539613040eadf397736733d8aa9d..e6a0dd26200f7157e421ae139e283f2fc27100e2 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -8,8 +8,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_basop_util.h" #include "basop_util.h" #include "rom_com.h" diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 5ef1756b7df69ef604f2587dc1aa4b66b8b01c0c..0631dad11f99245ea847f9793ed79ebc5f338379 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include #include "rom_com.h" diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 8e2097d74fffdc8677b5e7e65e3f44c744d7859f..328c00d184ff0059b2282f67adfcbdbcb8de3e5f 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -45,9 +45,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*******************************************************/ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 9881d47ec9bd63fb1e6694006432e47ca012f5bf..b2828ae9f6a1cb101cdb029f74ce394cd2427603 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -12,8 +12,7 @@ #include "options.h" #include "typedef.h" #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stat_com.h" #include "prot.h" #include "ivas_prot_fx.h" @@ -146,12 +145,12 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( hTonalMDCTConc->tcx_cfg = hTcxCfg; hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0]; #ifdef MSAN_FIX - set_s( hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX ); + set16_fx( hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX ); #endif move16(); hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1]; #ifdef MSAN_FIX - set_s( hTonalMDCTConc->secondLastBlockData.spectralData, 0, L_FRAME_MAX ); + set16_fx( hTonalMDCTConc->secondLastBlockData.spectralData, 0, L_FRAME_MAX ); #endif move16(); hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; @@ -160,12 +159,12 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0]; #ifdef MSAN_FIX - set_s( hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS ); + set16_fx( hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS ); #endif move16(); hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1]; #ifdef MSAN_FIX - set_s( hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS ); + set16_fx( hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS ); #endif move16(); hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0]; @@ -842,6 +841,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( power_spectrum_q = sub( 31, powerSpectrum_exp ); old_power_spectrum_q = power_spectrum_q; move16(); + Word16 length = 0; + move16(); /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ IF( psychParamsCurrent == NULL ) { @@ -854,25 +855,29 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( invScaleFactors_fx[i] = L_shl( invScaleFactors[i], add( 1, invScaleFactors_exp[i] ) ); // Q16 move32(); } - sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore, NULL ); + sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore, &length ); power_spectrum_q = add( power_spectrum_q, 1 ); // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); // nBands = psychParamsCurrent->nBands; } IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { - Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, sub( old_power_spectrum_q, power_spectrum_q ) ); + Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); } ELSE { - Scale_sig32( powerSpectrum + hTonalMDCTConc->nSamplesCore, sub( nSamples, hTonalMDCTConc->nSamplesCore ), sub( power_spectrum_q, old_power_spectrum_q ) ); + Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); powerSpectrum_exp = sub( 31, power_spectrum_q ); } Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ powerSpectrum_exp = add( powerSpectrum_exp, 3 ); FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { +#ifdef BASOP_NOGLOB + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); +#else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); +#endif move32(); } @@ -2775,13 +2780,14 @@ void TonalMDCTConceal_InsertNoise( } void TonalMDCTConceal_Apply( - const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ - Word16 *mdctSpectrum_exp /*IN */ + const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, /*IN/OUT*/ + Word16 *mdctSpectrum_exp /*IN */ #ifdef IVAS_CODE_MDCT_GSHAPE - ,const PsychoacousticParameters* psychParamsCurrent) + , + const PsychoacousticParameters *psychParamsCurrent #endif - ) +) { Word16 i, l, exp; Word16 *phaseDiff, *pCurrentPhase; diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 46bb39bf9974d5ae801ec7b5f787f468f3982031..4ebfeaf88045dfb41ea2a846926a86a6d4c0c273 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -2,11 +2,10 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "stl.h" /*----------------------------------------------------------------------* @@ -202,7 +201,7 @@ void transition_dec_fx( pit_limit = add( shl( pit_start, 1 ), *position ); /* 7 bit pitch DECODER */ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *T0 = add( pit_start, shr( ( index ), 1 ) ); move16(); @@ -233,7 +232,7 @@ void transition_dec_fx( /* 7bit pitch DECODER */ pit_start = sub( 2 * L_SUBFR, ( *position ) ); - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); *T0 = add( pit_start, shr( ( index ), 1 ) ); move16(); @@ -281,7 +280,7 @@ void transition_dec_fx( pit_limit = sub( 2 * L_FRAME - PIT_MAX, add( shl( ( *position ), 1 ), 2 ) ); - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); IF( LT_16( index, shl( sub( pit_limit, pit_start ), 1 ) ) ) { @@ -329,7 +328,7 @@ void transition_dec_fx( *--------------------------------------------------------*/ - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); delta_pit_dec_fx( 2, index, T0, T0_frac, *T0_min ); /* Find the adaptive codebook vector. ACELP long-term prediction */ @@ -349,7 +348,7 @@ void transition_dec_fx( *------------------------------------------------------------*/ ELSE { - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); pit_Q_dec_fx( 0, index, nBits, 8, pit_flag, limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); @@ -474,7 +473,7 @@ void transition_dec_fx( nBits = st_fx->acelp_cfg.pitch_bits[i_subfridx]; move16(); - index = (Word16) get_next_indice( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*-----------------------------------------------------------------* * Find adaptive part of excitation, encode pitch period @@ -541,7 +540,7 @@ void transition_dec_fx( { /* no adaptive excitation in the second subframe */ set16_fx( &exc[i_subfr], 0, L_SUBFR + 1 ); - get_next_indice( st_fx, 1 ); /* this bit is actually not needed */ + get_next_indice_fx( st_fx, 1 ); /* this bit is actually not needed */ set16_fx( &bwe_exc[i_subfr * 2], 0, L_SUBFR * 2 ); } ELSE @@ -665,7 +664,7 @@ static void tc_dec_fx( } ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) { - i = (Word16) get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice_fx( st_fx, nBits ); IF( EQ_16( nBits, 9 ) ) { @@ -678,7 +677,7 @@ static void tc_dec_fx( } ELSE { - i = (Word16) get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); IF( i == 0 ) @@ -703,7 +702,7 @@ static void tc_dec_fx( } ELSE /* L_frame == L_FRAME16k */ { - i = (Word16) get_next_indice( st_fx, nBits ); + i = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); IF( EQ_16( nBits, 10 ) ) @@ -738,13 +737,13 @@ static void tc_dec_fx( * decode other TC parameters *----------------------------------------------------------------*/ - imp_shape = (Word16) get_next_indice( st_fx, 3 ); + imp_shape = (Word16) get_next_indice_fx( st_fx, 3 ); move16(); - imp_pos = (Word16) get_next_indice( st_fx, 6 ); + imp_pos = (Word16) get_next_indice_fx( st_fx, 6 ); move16(); - imp_sign = (Word16) get_next_indice( st_fx, 1 ); + imp_sign = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); - imp_gain = (Word16) get_next_indice( st_fx, 3 ); + imp_gain = (Word16) get_next_indice_fx( st_fx, 3 ); move16(); /*----------------------------------------------------------------* @@ -840,19 +839,19 @@ Word16 tc_classif_fx( #endif IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - IF( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = TC_0_0; move16(); } ELSE { - IF( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = 0; move16(); - IF( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = TC_0_192; move16(); @@ -861,7 +860,7 @@ Word16 tc_classif_fx( { tc_subfr = TC_0_128; move16(); - if ( get_next_indice( st_fx, 1 ) ) + if ( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = TC_0_64; move16(); @@ -870,7 +869,7 @@ Word16 tc_classif_fx( } ELSE { - IF( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = L_SUBFR; move16(); @@ -879,7 +878,7 @@ Word16 tc_classif_fx( { tc_subfr = 3 * L_SUBFR; move16(); - if ( get_next_indice( st_fx, 1 ) ) + if ( get_next_indice_fx( st_fx, 1 ) ) { tc_subfr = 2 * L_SUBFR; move16(); @@ -890,7 +889,7 @@ Word16 tc_classif_fx( } ELSE /* L_frame == L_FRAME16k */ { - indice = (Word16) get_next_indice( st_fx, 2 ); + indice = (Word16) get_next_indice_fx( st_fx, 2 ); IF( LT_16( indice, 3 ) ) { @@ -900,7 +899,7 @@ Word16 tc_classif_fx( { tc_subfr = 4 * L_SUBFR; move16(); - if ( get_next_indice( st_fx, 1 ) == 0 ) + if ( get_next_indice_fx( st_fx, 1 ) == 0 ) { tc_subfr = 3 * L_SUBFR; move16(); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index a92130a62da642c24d702f1157b9c1a84bf18036..1518fa50c0ec4dd87335395a2ab41360a09d23e8 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -5,10 +5,9 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ /*-------------------------------------------------------------------* * updt_dec() @@ -576,7 +575,7 @@ void updt_dec_common_fx( test(); IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Copy_Scale_sig( synth + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); + Copy_Scale_sig( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); } test(); test(); @@ -969,7 +968,7 @@ void ivas_updt_dec_common_fx( test(); IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Copy_Scale_sig_32_16( synth + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); + Copy_Scale_sig_32_16( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); } test(); test(); @@ -994,7 +993,7 @@ void ivas_updt_dec_common_fx( IF( st_fx->element_mode != EVS_MONO ) { Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); - Word16 output_frame = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS ); + Word16 output_frame = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS ); move16(); Word32 sum_val = sum_32_32_fx( synth, output_frame ); Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div ); diff --git a/lib_dec/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index 5d89a7696b5eeb67746d965cc2fb50cbe2adce0f..1ba7a64d0f188dd92a9a52d528506ac041d2fb1a 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index df4d8e53e3def8608ee562b012890035011ab6d3..3aa39e86aa543aa8b5302c1d328a7f3c02912800 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -5,8 +5,7 @@ #include #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" //#ifdef DEBUGGING to be removed #include //#endif diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index e31032d4c867dd8674df277ee930729e1d03254f..a0f47e75bec4e8aeb48a030c5cb6ee0555e34069 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" #include "log2.h" @@ -147,7 +146,7 @@ ivas_error ppp_voiced_decoder_fx( } pl = s_min( rint_new_fx( st_fx->old_pitch_buf_fx[( 2 * NB_SUBFR ) - 1] ), MAX_LAG_PIT ); - delta_lag_D = (Word16) get_next_indice( st_fx, 5 ); + delta_lag_D = (Word16) get_next_indice_fx( st_fx, 5 ); l = s_min( MAX_LAG_PIT, add( pl, sub( delta_lag_D, 11 ) ) ); @@ -396,9 +395,9 @@ ivas_error ppp_voiced_decoder_fx( hSC_VBR->dtfs_dec_Q = dtfs_temp_fx->Q; move16(); - count_free( TMPDTFS_FX ); - count_free( CURRP_Q_D_FX ); - count_free( dtfs_temp_fx ); + free( TMPDTFS_FX ); + free( CURRP_Q_D_FX ); + free( dtfs_temp_fx ); return IVAS_ERR_OK; } diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index e7aadde27cd978e085693c2f13d4c2fe571e08f9..083c7854cc7fa7948d7042a7638537b455d7c99d 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -6,8 +6,7 @@ #include #include #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "stat_com.h" #include "rom_com.h" @@ -921,7 +920,7 @@ void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_ IF( EQ_16( curr_mode, 1 ) ) { /* copy the data of the last frame */ - mvr2r_Word32( plcInfo->data_reci2_fx, invkoef, N ); + MVR2R_WORD32( plcInfo->data_reci2_fx, invkoef, N ); *invkoef_scale = plcInfo->data_reci2_scale; move16(); /* sign randomization */ @@ -1417,7 +1416,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /* use last good signal for noise generation */ add_noise( sbuf, outx_new_n1, outdata2, tmp, nsapp_gain, nsapp_gain_n, 1 ); /* save current (noisy) output from IMDCT */ - mvr2r_Word16( outx_new, data_noise, tmp ); + MVR2R_WORD16( outx_new, data_noise, tmp ); /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ Copy( pitch125_data, &overlapbuf[Framesize / 4], shr( imult1616( 3, Framesize ), 2 ) ); } @@ -1482,7 +1481,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, /* save current (noisy) output from IMDCT */ IF( bfi ) { - mvr2r_Word16( outx_new, noise_ptr, size ); + MVR2R_WORD16( outx_new, noise_ptr, size ); } } test(); diff --git a/lib_enc/ACcontextMapping_enc.c b/lib_enc/ACcontextMapping_enc.c index a83ae0aca6f93e06882f85fdf322c48a86edccf8..0f37e51ded41f98065b81bd6e9cf82cdc36ea635 100644 --- a/lib_enc/ACcontextMapping_enc.c +++ b/lib_enc/ACcontextMapping_enc.c @@ -371,6 +371,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t find_last_nz_pair( const int16_t x[], const int16_t length, @@ -413,6 +414,53 @@ static int16_t find_last_nz_pair( return last_nz; } +#else +static Word16 find_last_nz_pair( + const Word16 x[], + const Word16 length, + const CONTEXT_HM_CONFIG *hm_cfg ) +{ + Word16 last_nz, i; + const Word16 *tmp; + + last_nz = 2; + move16(); + + IF( hm_cfg ) + { + /* mapped kernel */ + tmp = hm_cfg->indexBuffer; + + FOR( i = length; i >= 4; i -= 2 ) + { + test(); + IF( x[tmp[i - 2]] || x[tmp[i - 1]] ) + { + last_nz = i; + move16(); + BREAK; + } + } + } + ELSE + { + /* unmapped kernel */ + + FOR( i = length; i >= 4; i -= 2 ) + { + test(); + IF( x[i - 2] || x[i - 1] ) + { + last_nz = i; + move16(); + BREAK; + } + } + } + + return last_nz; +} +#endif /*-------------------------------------------------------------------* @@ -1011,6 +1059,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS( * Range coder bit-estimation *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( int16_t *x, /* Spectral coefficients */ const int16_t nt, /* L - size of spectrum (no. of spectral coefficients) */ @@ -1366,6 +1415,426 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( return tot_bits2; } } +#else +Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS( + Word16 *x, /* Spectral coefficients */ + const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) */ + Word16 *lastnz_out, + Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */ + const Word16 target, /* Target bits */ + Word16 *stop, + Word16 mode, + CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ +) +{ + /* Common variables */ + Word16 a1, b1; + Word16 k, pki, lev1; + UWord16 t; + Word16 lastnz, lastnz2; + Word16 rateFlag; + Word32 bit_estimate_fx; + Word16 bit_estimate_e; + Word16 symbol; + const UWord8 *lookup; + Word32 nbits2_fx; // Q23 + Word16 nbits2_e; // Q23 + + /* Initialization */ + bit_estimate_fx = 2 * ONE_IN_Q29; + bit_estimate_e = 2; + move32(); + nbits2_fx = 0; + nbits2_e = 0; + move32(); + + /* bits to encode lastnz */ + k = 1; + move16(); + + WHILE( LT_16( k, nt / 2 ) ) + { + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ONE_IN_Q30, 1, &bit_estimate_e ); + k = k << 1; + /* check while condition */ + } + + nbits2_fx = bit_estimate_fx; + nbits2_e = bit_estimate_e; + + IF( hm_cfg ) + { + Word16 a1_i, b1_i; + Word16 stop2; + Word16 total_output_bits; + Word16 nt_half; + Word32 c[2], *ctx; + Word32 p1, p2; + Word16 ii[2]; + Word16 idx1, idx2, idx; + Word16 numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */ + move16(); + move16(); + + /* Rate flag */ + IF( GT_16( target, 400 ) ) + { + rateFlag = 2 << NBITS_CONTEXT; /* Select context-A for higher bitrates */ + move16(); + } + ELSE + { + rateFlag = 0; /* Select context-B for lower bitrates */ + move16(); + } + + nt_half = shr( nt, 1 ); + move16(); + stop2 = 0; + move16(); + c[0] = c[1] = 0; + move32(); + move32(); + + /* Find last non-zero tuple in the mapped domain signal */ + lastnz = find_last_nz_pair( x, nt, hm_cfg ); + + lastnz2 = 2; + move16(); + + /* mapped domain */ + numPeakIndicesOrig = hm_cfg->numPeakIndices; + move16(); + hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); + move16(); + numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); + + /* Mark hole indices beyond lastnz as pruned */ + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) + { + hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); + move16(); + } + + ii[0] = numPeakIndicesOrig; + move16(); + ii[1] = 0; + move16(); + + p1 = p2 = 0; /* to avoid compilation warnings */ + move32(); + move32(); + + /* Main Loop through the 2-tuples */ + FOR( k = 0; k < lastnz; k += 2 ) + { + a1_i = get_next_coeff_mapped_ivas( ii, &p1, &idx1, hm_cfg ); + b1_i = get_next_coeff_mapped_ivas( ii, &p2, &idx2, hm_cfg ); + + idx = s_min( idx1, idx2 ); + + /* Get context */ + ctx = &c[L_or( p1, p2 )]; + + t = (UWord16) L_add( *ctx, rateFlag ); + IF( LT_16( nt_half, idx ) ) + { + t = add( t, ( 1 << NBITS_CONTEXT ) ); + } + + /* Init current 2-tuple encoding */ + a1 = (Word16) abs( x[a1_i] ); + b1 = (Word16) abs( x[b1_i] ); + lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + + /* check while condition */ + /* MSBs coding */ + WHILE( GE_16( s_max( a1, b1 ), A_THRES ) ) + { + pki = lookup[lev1]; /* ESC symbol */ + + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane */ + + ( a1 ) = shr( a1, 1 ); + ( b1 ) = shr( b1, 1 ); + + lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + + /* check while condition */ + } + + pki = lookup[lev1]; + + symbol = add( a1, i_mult( A_THRES, b1 ) ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); + + /* Should we truncate? */ + IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) ) + { + stop2 = 1; + move16(); + + IF( *stop ) + { + BREAK; + } + } + ELSE + { + lastnz2 = add( b1_i, 1 ); + nbits2_fx = bit_estimate_fx; + move32(); + nbits2_e = bit_estimate_e; + move16(); + } + + /* Update context for next 2-tuple */ + IF( EQ_32( p1, p2 ) ) /* peak-peak or hole-hole context */ + { + lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); + + IF( lev1 <= 0 ) + { + t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) ); + } + ELSE + { + t = add( 13, lev1 ); + } + + *ctx = L_add( imult3216( L_and( *ctx, 0xf ), 16 ), t ); + move32(); + } + ELSE + { + /* mixed context */ + + IF( s_and( idx1, 1 ) ) + { + /* update first context */ + c[p1] = update_mixed_context_ivas( c[p1], (int16_t) abs( x[a1_i] ) ); + move32(); + } + + IF( s_and( idx2, 1 ) ) + { + /* update second context */ + c[p2] = update_mixed_context_ivas( c[p2], (int16_t) abs( x[b1_i] ) ); + move32(); + } + } + + } /*end of the 2-tuples loop*/ + + total_output_bits = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); + + IF( *stop ) + { + total_output_bits = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) ); + } + + IF( stop2 ) + { + stop2 = total_output_bits; + move16(); + } + + *nEncoded = lastnz2; + move16(); + *stop = stop2; /* If zero, it means no overflow occured during bit-estimation */ + move16(); + *lastnz_out = lastnz; + move16(); + + /* Restore hole indices beyond lastnz */ + FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) + { + hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt ); + move16(); + } + hm_cfg->numPeakIndices = numPeakIndicesOrig; + move16(); + + return round_fx( L_add( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ), ONE_IN_Q14 ) ); + } + ELSE /* if (!hm_cfg) */ + { + Word16 esc_nb, cp, rateQ; + UWord16 s; + Word16 tot_bits2; + Word16 overflow_flag = 0; + + /* Rate flag */ + IF( GT_16( target, 400 ) ) + { + rateFlag = 2; + move16(); + } + ELSE + { + rateFlag = 0; /* Select context-B for lower bitrates */ + move16(); + } + + t = 0; + move16(); + s = 0; + move16(); + cp = 0; + move16(); + lastnz = 1; + move16(); + lastnz2 = 0; + move16(); + tot_bits2 = 0; + move16(); + + /* Find last non-zero tuple in the mapped domain signal */ + FOR( lastnz = sub( nt, 2 ); lastnz >= 0; lastnz -= 2 ) + { + test(); + IF( ( x[lastnz] != 0 ) || ( x[lastnz + 1] != 0 ) ) + { + BREAK; + } + } + lastnz = add( lastnz, 2 ); + IF( LT_16( lastnz, 2 ) ) + { + lastnz = 2; /* At least one tuple is coded */ + move16(); + } + + lastnz2 = 2; + move16(); + + /* Main Loop through the 2-tuples */ + FOR( k = 0; k < lastnz; k += 2 ) + { + /* Init current 2-tuple encoding */ + a1 = abs_s( x[k] ); + b1 = abs_s( x[k + 1] ); + lev1 = 0; + move16(); + esc_nb = 0; + move16(); + rateQ = add( rateFlag, (Word16) GT_16( k, shr( nt, 1 ) ) ); + + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t + shl( rateQ, NBITS_CONTEXT )]; + + /* check while condition */ + /* MSBs coding */ + WHILE( GE_16( s_max( a1, b1 ), A_THRES ) ) + { + pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane */ + + ( a1 ) = shr( a1, 1 ); + ( b1 ) = shr( b1, 1 ); + + lev1 = add( lev1, 1 ); + esc_nb = s_min( lev1, 3 ); + + /* check while condition */ + } + + pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; + + symbol = add( a1, i_mult( A_THRES, b1 ) ); + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); + + /* Should we truncate? */ + IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) ) /* Overflow occured */ + { + overflow_flag = 1; + move16(); + } + ELSE + { + IF( abs_s( x[k] ) || abs_s( x[k + 1] ) ) /* No overflow & non-zero tuple */ + { + nbits2_fx = bit_estimate_fx; + nbits2_e = bit_estimate_e; + move32(); + lastnz2 = add( k, 2 ); + } + } + + /* Update context for next 2-tuple */ + IF( LT_16( esc_nb, 2 ) ) + { + cp = add( 1, i_mult( add( a1, b1 ), add( esc_nb, 1 ) ) ); + } + ELSE + { + cp = add( 12, esc_nb ); + } + /*shift old bits and replace last 4 bits*/ + s = ( s << 4 ) + cp; + t = ( s & 0xFF ); + + } /*end of the 2-tuples loop*/ + + tot_bits2 = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) ); + IF( lastnz2 < lastnz ) /* Overflow occured because unable to code all tuples */ + { + overflow_flag = 1; + move16(); + } + IF( EQ_16( mode, -1 ) ) + { + tot_bits2 = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); + } + IF( overflow_flag == 0 ) /* No overflow */ + { + *stop = 0; + move16(); + } + ELSE /* Overflow */ + { + IF( *stop ){ + *stop = tot_bits2; + move16(); + } + ELSE + { + *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); + move16(); + } +} + +*lastnz_out = lastnz; +move16(); +*nEncoded = lastnz2; +move16(); +/* Safety mechanism to avoid overflow */ +test(); +IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) +{ + FOR( k = 0; k < lastnz2; k++ ) + { + x[k] = 0; + move16(); + } +} + +return tot_bits2; +} +} +#endif /*-------------------------------------------------------------------* * RCcontextMapping_encode2_estimate_bandWise_start() @@ -1373,6 +1842,7 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS( * Range coder - start bandwise bit-estimation *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t RCcontextMapping_encode2_estimate_bandWise_start( int16_t *x, const int16_t nt, @@ -1427,6 +1897,81 @@ int16_t RCcontextMapping_encode2_estimate_bandWise_start( return (int16_t) hContextMem->bit_estimate; } +#else +Word16 RCcontextMapping_encode2_estimate_bandWise_start( + Word16 *x, + const Word16 nt, + const Word16 target, + HANDLE_RC_CONTEXT_MEM hContextMem ) +{ + Word16 i, k; + + /* Rate flag */ + IF( GT_16( target, 400 ) ) + { + hContextMem->rateFlag = 2 << NBITS_CONTEXT; + move16(); + } + ELSE + { + hContextMem->rateFlag = 0; + move16(); + } + + hContextMem->bit_estimate_fx = 2; + move32(); + hContextMem->bit_estimate_e = Q31; + move16(); + + + /* Init */ + hContextMem->nt_half = shr( nt, 1 ); + move16(); + + /* bits to encode lastnz */ + k = 1; + move16(); + + WHILE( LT_16( k, hContextMem->nt_half ) ) + { + hContextMem->bit_estimate_fx = L_add( hContextMem->bit_estimate_fx, 1 ); + move32(); + + k = shl( k, 1 ); + /* check while condition */ + } + + /* bits to encode lastnz */ + hContextMem->nbits_old = extract_l( hContextMem->bit_estimate_fx ); + move16(); + + hContextMem->ctx = 0; + move16(); + hContextMem->lastnz = 2; + move16(); + + /* Find last non-zero tuple */ + + FOR( i = nt; i >= 4; i -= 2 ) + { + test(); + IF( x[i - 2] != 0 || x[i - 1] != 0 ) + { + hContextMem->lastnz = i; + move16(); + break; + } + } + Word16 tmp2 = extract_l( hContextMem->bit_estimate_fx ); + Word16 tmp = norm_l( hContextMem->bit_estimate_fx ); + hContextMem->bit_estimate_e = sub( Q31, tmp ); + move16(); + hContextMem->bit_estimate_fx = L_shl( hContextMem->bit_estimate_fx, tmp ); + move32(); + + return tmp2; +} +#endif /*-------------------------------------------------------------------* * RCcontextMapping_encode2_estimate_bandWise() @@ -1434,6 +1979,7 @@ int16_t RCcontextMapping_encode2_estimate_bandWise_start( * Range coder - bandwise bit-estimation *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t RCcontextMapping_encode2_estimate_bandWise( int16_t *x, const int16_t start_line, @@ -1515,3 +2061,94 @@ int16_t RCcontextMapping_encode2_estimate_bandWise( return bandBits; } +#else +Word16 RCcontextMapping_encode2_estimate_bandWise( + Word16 *x, + const Word16 start_line, + const Word16 end_line, + HANDLE_RC_CONTEXT_MEM hContextMem ) +{ + Word16 a1, b1, a1_i, b1_i; + Word16 k, pki, lev1; + UWord16 t; + Word16 bandBits = 0; + move16(); + Word16 total_output_bits; /* No. of bits after finalization */ + Word16 symbol; + const UWord8 *lookup; + Word16 idx; + + /* Main Loop through the 2-tuples */ + /*hContextMem->nt_half = end_line >> 1;*/ + FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 ) + { + a1_i = k; + move16(); + b1_i = add( k, 1 ); + + idx = k; + move16(); + + /* Get context */ + t = add( hContextMem->ctx, hContextMem->rateFlag ); + t = add( t, GE_16( hContextMem->nt_half, idx ) ? 0 : ( 1 << NBITS_CONTEXT ) ); + + /* Init current 2-tuple encoding */ + a1 = abs_s( x[a1_i] ); + b1 = abs_s( x[b1_i] ); + lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + + /* Signs Bits */ + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, Q1, &hContextMem->bit_estimate_e ); + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, Q1, &hContextMem->bit_estimate_e ); + + /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + + /* check while condition */ + /* MSBs coding */ + WHILE( GE_16( s_max( a1, b1 ), A_THRES ) ) + { + pki = lookup[lev1]; + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out */ + // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; + // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */ + + ( a1 ) = shr( a1, 1 ); + ( b1 ) = shr( b1, 1 ); + + lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); + /* check while condition */ + } + + pki = lookup[lev1]; + symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol */ + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); + // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + + /* Update context */ + lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); + + IF( lev1 <= 0 ) + { + t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) ); + } + ELSE + { + t = add( 13, lev1 ); + } + + hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); + + } /*end of the 2-tuples loop*/ + total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); + // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); + + bandBits = sub( total_output_bits, hContextMem->nbits_old ); + hContextMem->nbits_old = total_output_bits; + move16(); + + return bandBits; +} +#endif diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 62516fe35a8fedda859820bdd7e11da43c2deb6e..11d60b85474b1ce6b8f1858a3168b1d2a863c6e3 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" +#include "prot_fx.h" #include "rom_com.h" //#include "prot_fx.h" #include "prot_fx_enc.h" diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c index 8338409fb17823162cdde692407fcc0a406a885a..d35f18b61a9dcf5be4bf1727d91abeb852530913 100644 --- a/lib_enc/FEC_enc_fx.c +++ b/lib_enc/FEC_enc_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index f39bc2b866ab546b5eda0a9cc6a4aa03e1a025be..674467cf4f6b249b5805f5a9865f11aeea324d88 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -6,8 +6,7 @@ #include "options.h" #include "basop_util.h" #include "vad_basop.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 771e0bc9efa26efa539b5bca9bd23cd891471d72..fc418f6526d36c0c7008364841f31cf8d93c4edb 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -43,7 +43,8 @@ #include "prot.h" #include "ivas_cnst.h" #include "ivas_prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -52,7 +53,1487 @@ * * ACELP core encoder *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error acelp_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float inp[], /* i : input signal of the current frame */ + const float ener, /* i : residual energy from Levinson-Durbin*/ + float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/ + float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ + const float epsP[M + 1], /* i : LP prediction errors */ + float lsp_new[M], /* i : LSPs at the end of the frame */ + float lsp_mid[M], /* i : LSPs in the middle of the frame */ + const int16_t vad_hover_flag, /* i : VAD hangover flag */ + const int16_t attack_flag, /* i : attack flag (GSC or TC) */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + int16_t *unbits, /* o : number of unused bits */ + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +) +{ + int16_t i, nBits; /* reserved bits */ + LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ + float old_exc_flt[L_EXC], *exc; /* excitation signal buffer */ + float lsf_new[M]; /* ISFs at the end of the frame */ + float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ + float syn[L_FRAME16k]; /* synthesis signal buffer */ + float res[L_FRAME16k]; /* Residual signal for FER protection */ + float exc2[L_FRAME16k]; /* enhanced excitation */ + float Es_pred; /* predicited scaled innovation energy */ + float tmp_noise; /* NB post-filter long-term noise energy*/ + int16_t tc_subfr; /* TC sub-frame indication */ + float old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ + float *bwe_exc; /* excitation for SWB TBE */ + int16_t allow_cn_step; + int32_t int_fs; + float att; + int16_t nb_bits; /* parameters handling */ + + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + int16_t pstreaklen; + float mem_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT / 2], lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; + float clip_var, mem_w0_bck, streaklimit; + + float q_env[NUM_ENV_CNG]; + int16_t sid_bw = -1; + float exc3[L_FRAME16k]; + float syn1[L_FRAME16k]; + + float tilt_code_bck; + float gc_threshold_bck; + float clip_var_bck[6]; + int16_t next_force_sf_bck; + int16_t uc_two_stage_flag; + int16_t position; + float tmpF; + int16_t ppp_mode, nelp_mode; + int16_t tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; + float *tdm_Pri_pitch_buf; + + /* bitstream */ + BSTR_ENC_HANDLE hBstr = st->hBstr; +#if 0 + //Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ + Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ + Word16 Aq_fx[NB_SUBFR16k*(M + 1)]; /* A(z) quantized for the 4 subframes */ + Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ + Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ + Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ + Word16 Es_pred_fx; /* predicited scaled innovation energy */ + Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ + Word16 tc_subfr_fx; /* TC sub-frame indication */ + Word16 old_bwe_exc_fx[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + Word16 *bwe_exc_fx; /* excitation for SWB TBE */ + Word16 allow_cn_step_fx; + Word16 int_fs_fx; + Word32 L_epsP[2]; + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + Word16 mCb1_fx, pstreaklen_fx; + Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; + Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; + Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; + Word16 indice; + Word16 tmp16; + Word16 enr_index; + Word16 enr; + + Word16 tilt_code_bck_fx; + Word32 gc_threshold_bck_fx; + Word16 clip_var_bck_fx[6]; + Word16 next_force_sf_bck_fx; + Word32 q_env_fx[NUM_ENV_CNG]; + Word16 coder_type; + Word16 exc3_fx[L_FRAME16k]; + Word16 syn1_fx[L_FRAME16k]; + Word16* tdm_Pri_pitch_buf_fx; + Word16 att_fx; + + Word16 lsp_new_fx[M]; /* i : LSPs at the end of the frame */ + Word16 lsp_mid_fx[M]; /* i : LSPs in the middle of the frame */ + Word16 old_syn_12k8_16k_fx[L_FRAME16k]; +#endif + ivas_error error; + + error = IVAS_ERR_OK; + + if ( st->element_mode == IVAS_CPE_MDCT && st->core_brate <= SID_2k40 ) + { + /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ + return error; + } + + push_wmops( "acelp_core_enc" ); + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + hLPDmem = st->hLPDmem; + + Es_pred = 0; + + exc = old_exc_flt + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM ); + + if ( st->hBWE_TD != NULL ) + { + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ + mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); + } + else + { + bwe_exc = NULL; + } + + st->bpf_off = 0; + if ( st->last_core == HQ_CORE || st->last_codec_mode == MODE2 || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + /* in case of HQ->ACELP switching, do not apply BPF */ + st->bpf_off = 1; + /* reset the GSC pre echo energy threshold in case of switching */ + if ( st->hGSCEnc != NULL ) + { + st->hGSCEnc->Last_frame_ener = (float) MAX_32; + } + } + + /* force safety-net LSFQ in the first frames after CNG segment */ + if ( st->last_core_brate <= SID_2k40 ) + { + st->Nb_ACELP_frames = 0; + } + st->Nb_ACELP_frames++; + + if ( st->L_frame == L_FRAME ) + { + int_fs = INT_FS_12k8; + } + else + { + int_fs = INT_FS_16k; + } + + tmp_noise = 0; + tc_subfr = -1; + position = -1; + + /* SC-VBR temporary variables */ + pstreaklen = 0; + clip_var = 0; + mem_w0_bck = 0; + streaklimit = 0; + + /* channel-aware mode */ + reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); + + /* VBR modes */ + if ( st->Opt_SC_VBR ) + { + ppp_mode = st->hSC_VBR->ppp_mode; + nelp_mode = st->hSC_VBR->nelp_mode; + } + else + { + ppp_mode = 0; + nelp_mode = 0; + } + + /* TD stereo */ + if ( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) + { + tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; + tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; + tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; + tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf; + } + else + { + tdm_lp_reuse_flag = 0; + tdm_low_rate_mode = 0; + if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) + { + tdm_low_rate_mode = 1; + } + tdm_Pitch_reuse_flag = 0; + tdm_Pri_pitch_buf = NULL; + } + + /*-----------------------------------------------------------------* + * ACELP@12k8 / ACELP@16k switching + *-----------------------------------------------------------------*/ + + if ( st->last_L_frame != st->L_frame && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) + { + /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */ + st->bpf_off = 1; + + /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ + st->Nb_ACELP_frames = 1; + + /* convert old quantized LSP vector */ + if ( st->L_frame == L_FRAME ) + { + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + } + else + { + st->rate_switching_reset = st->rate_switching_reset_16kHz; + mvr2r( st->lsp_old16k, st->lsp_old, M ); + } + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, int_fs ); + + /* interpolation of unquantized ISPs */ + if ( st->rate_switching_reset ) + { + /*extrapolation in case of unstable LSP*/ + int_lsp4( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); + } + else + { + int_lsp4( st->L_frame, st->lsp_old, lsp_mid, lsp_new, A, M, 0 ); + } + + /* Reset LPC mem */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC ); + mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM ); + mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn1_flt, M ); + mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn3_flt, M ); + + /* update Aw[] coefficients */ + weight_a_subfr( st->L_frame / L_SUBFR, A, Aw, st->gamma_flt, M ); + } + + if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------* + * Encoding of CNG frames + *----------------------------------------------------------------*/ + + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + if ( st->cng_type == LP_CNG ) + { + /* Run CNG post parameter update */ + cng_params_postupd( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); + + /* encode CNG parameters */ + CNG_enc( st, Aq, inp, ener, lsp_mid, lsp_new, lsf_new, &allow_cn_step, q_env, &sid_bw ); + + /* comfort noise generation */ + CNG_exc( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew, &st->hTdCngEnc->cng_seed, exc, exc2, &st->hTdCngEnc->lp_ener, st->last_core_brate, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO ); + } + else + { + if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) + { + FdCng_encodeSID( st ); + st->hDtxEnc->last_CNG_L_frame = st->L_frame; + } + + generate_comfort_noise_enc( st ); + + FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc ); + mvr2r( exc2, exc3, st->L_frame ); + + if ( st->core_brate == SID_2k40 ) + { + if ( st->hTdCngEnc != NULL ) + { + tmpF = cng_energy( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att, exc, st->L_frame ); + i = (int16_t) ( ( tmpF + 2.0f ) * STEP_SID ); + i = min( max( i, 0 ), 127 ); + st->hTdCngEnc->old_enr_index = i; + } + } + } + + /* Reset HO counter in the first SID frame */ + if ( st->hTdCngEnc != NULL ) + { + st->hTdCngEnc->burst_ho_cnt = 0; + } + + /* synthesis at 12.8kHz sampling rate */ + syn_12k8( st->L_frame, Aq, exc3, syn1, hLPDmem->mem_syn3_flt, 1 ); + + /* reset the encoder */ + CNG_reset_enc( st, pitch_buf, voice_factors, 0 ); + + /* update st->mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn1_flt, M ); + + /* update ACELP core synthesis filter memory */ + mvr2r( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn1 + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + + /*Update MODE2 core switching memory*/ + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + } + + /*----------------------------------------------------------------* + * Encoding of all other frames + *----------------------------------------------------------------*/ +#if 0 + ELSE + { +#if 1 + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + + if ( !nelp_mode && !ppp_mode ) + { + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if (st->hDtxEnc != NULL && (st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40)) +#else + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) +#endif + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 Q_new = 0; + IF ( !tdm_lp_reuse_flag ) + { +#if 1 + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + FOR(Word16 idx = 0; idx < M; idx++) + { + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + lsf_new_fx[idx] = lsf_new_fx[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + tdm_lsfQ_PCh_fx[idx] = tdm_lsfQ_PCh[idx] * 2.56; + st->lsfoldbfi1_fx[idx] = st->lsfoldbfi1[idx] * 2.56; + st->lsfoldbfi0_fx[idx] = st->lsfoldbfi0[idx] * 2.56; + } + + FOR(Word16 idx = 0; idx < 6; idx++) + { + st->clip_var_fx[idx] = st->clip_var[idx] * 2.56; + } + + Q_new = Q_factor_arr(st->Bin_E, 256); + + floatToFixed_arrL(st->Bin_E_old, st->Bin_E_old_fx, 0, L_FFT ); + floatToFixed_arrL(st->Bin_E, st->Bin_E_fx, Q_new, L_FFT); + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + + st->stab_fac_fx = st->stab_fac * (1 << 15); + st->streaklimit_fx = st->streaklimit * (1 << 15); + st->pstreaklen_fx = st->pstreaklen; + + lsf_enc_ivas_fx(st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh_fx, Q_new); + + Scale_sig(Aq_fx, NB_SUBFR16k * (M + 1), 14 - norm_l(Aq_fx[0])); + fixedToFloat_arr(Aq_fx, Aq, 12, NB_SUBFR16k * (M + 1)); + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); + fixedToFloat_arr(lsp_mid_fx, lsp_mid, 15, M); + st->stab_fac = (float)st->stab_fac_fx / (1 << 15); + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56; + st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56; + } + st->streaklimit = (float)st->streaklimit_fx / (1 << 15); + st->pstreaklen = st->pstreaklen_fx; +#else + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); +#endif + } + ELSE + { + const float *pt_interp_2; + + IF ( NE_16(st->active_cnt, 1 )) + { +#if 0 + Word16 beta_index; + Word16 lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf_fx(lsp_new_fx, lsf_new_fx, M, 12800); + + Unified_weighting_fx(&st->Bin_E_fx[L_FFT / 2], Q_new, lsf_new_fx, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M); + + tdm_SCh_lsf_reuse_fx(ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts, &beta_index); +#else + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); + + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); +#endif + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, st->L_frame ); + + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ + + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } + + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } +#else + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; +#if 0 // Both are in fixed point, but 1st one giveing crash for one file. + IF ( !nelp_mode && !ppp_mode ) + { + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } +#else + if (!nelp_mode && !ppp_mode) + { + config_acelp1_IVAS(ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &(st->acelp_cfg), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode); + } +#endif + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ +#if 0 + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + IF (st->hDtxEnc != NULL && (st->last_core_brate == FRAME_NO_DATA || EQ_32(st->last_core_brate, SID_2k40))) +#else + IF(EQ_32(st->last_core_brate, FRAME_NO_DATA) || EQ_32(st->last_core_brate, SID_2k40)) +#endif + { + Copy(st->hDtxEnc->lspCNG_fx, st->lsp_old_fx, M); + lsp2lsf_fx(st->hDtxEnc->lspCNG_fx, st->lsf_old_fx, M, int_fs); + } + for (int i = 0; i < M; i++) { + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + } +#else +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if (st->hDtxEnc != NULL && (st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40)) +#else + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) +#endif + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } +#endif + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ +#if 1 + IF (!st->use_acelp_preq) + { + st->mem_deemp_preQ_fx = 0; + st->mem_preemp_preQ_fx = 0; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + if (!st->use_acelp_preq) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } +#else + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; +#endif + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ +#if 0 + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + floatToFixed_arr(st->Bin_E_old, st->Bin_E_old_fx, 15, L_FFT / 2); + floatToFixed_arr(st->clip_var, st->clip_var_fx, 8, 6); + FOR(Word16 idx = 0; idx < M; idx++) + { + + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + } + hLPDmem->tilt_code = hLPDmem->tilt_code_flt; + hLPDmem->gc_threshold = hLPDmem->gc_threshold_flt; + st->next_force_safety_net_fx = st->next_force_safety_net; + + lsf_syn_mem_backup_fx(st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx); + + fixedToFloat_arr(clip_var_bck_fx, clip_var_bck, 8, 6); + fixedToFloat_arr(lsp_new_bck_fx, lsp_new_bck, 15, M); + fixedToFloat_arr(lsp_mid_bck_fx, lsp_mid_bck, 15, M); + fixedToFloat_arr(lsp_mid_bck_fx, lsp_mid_bck, 15, M); + fixedToFloat_arr(Bin_E_fx, Bin_E, 15, L_FFT); + fixedToFloat_arr(Bin_E_old_fx, Bin_E_old, 15, L_FFT / 2); + fixedToFloat_arr(mem_syn_bck_fx, mem_syn_bck, 15, M); + + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + mem_MA[i] = mem_MA_fx[i] / 2.56; + mem_AR[i] = mem_AR_fx[i] / 2.56; + } + + clip_var = (float)clip_var_fx / (1 << 8); + mem_w0_bck = mem_w0_bck_fx; + streaklimit = streaklimit_fx; + mem_w0_bck = mem_w0_bck_fx; +#else + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); +#endif + if ( !tdm_lp_reuse_flag ) + { +#if 1 + Word16 Q_new = 0; + Word16 tdm_lsfQ_PCh_fx[M]; + + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + FOR(Word16 idx = 0; idx < M; idx++) + { + st->lsf_old_fx[idx] = st->lsf_old[idx] * 2.56; + lsf_new_fx[idx] = lsf_new_fx[idx] * 2.56; + st->lsf_adaptive_mean_fx[idx] = st->lsf_adaptive_mean[idx] * 2.56; + st->mem_MA_fx[idx] = st->mem_MA[idx] * 2.56; + st->mem_AR_fx[idx] = st->mem_AR[idx] * 2.56; + tdm_lsfQ_PCh_fx[idx] = tdm_lsfQ_PCh[idx] * 2.56; + } + + FOR(Word16 idx = 0; idx < 6; idx++) + { + st->clip_var_fx[idx] = st->clip_var[idx] * 2.56; + } + + floatToFixed_arrL(st->Bin_E_old, st->Bin_E_old_fx, 0, L_FFT / 2); + floatToFixed_arrL(st->Bin_E, st->Bin_E_fx, 0, L_FFT / 2); + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M); + floatToFixed_arr(lsp_mid, lsp_mid_fx, 15, M); + + st->stab_fac_fx = st->stab_fac * (1 << 15); + + lsf_enc_ivas_fx(st, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh_fx, Q_new); + + Scale_sig(Aq_fx, NB_SUBFR16k * (M + 1), 14 - norm_l(Aq_fx[0])); + fixedToFloat_arr(Aq_fx, Aq, 12, NB_SUBFR16k * (M + 1)); + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); + fixedToFloat_arr(lsp_mid_fx, lsp_mid, 15, M); + st->stab_fac = (float)st->stab_fac_fx / (1 << 15); + for (int i = 0; i < M; i++) { + + lsf_new[i] = lsf_new_fx[i] / 2.56; + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56; + st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56; + st->mem_MA[i] = st->mem_MA_fx[i] / 2.56; + st->mem_AR[i] = st->mem_AR_fx[i] / 2.56; + } +#else + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); +#endif + } + else + { + const float *pt_interp_2; + + if ( st->active_cnt != 1 ) + { + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); + + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); + + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ +#if 0 + floatToFixed_arr(Aq, Aq_fx, 12, NB_SUBFR16k*(M + 1)); + calc_residu_fx(st, inp_fx, res_fx, Aq_fx); +#else + calc_residu( inp, res, Aq, st->L_frame ); +#endif + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ +#if 0 + Es_pred_fx = Es_pred * (1 << 8); + IF(nb_bits > 0) + { + Es_pred_enc_fx(&Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, 0); + push_indice(hBstr, IND_ES_PRED, i, nb_bits); + } + + Es_pred = (float)Es_pred_fx / (1 << 8); +#else + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } +#endif + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + Copy(hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + Copy(syn_fx + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM); + /* save and delay synthesis to be used by SWB BWE */ +#if 1 + floatToFixed_arr(hLPDmem->mem_syn_r, hLPDmem->mem_syn_r_flt, 0, L_SYN_MEM); + floatToFixed_arr(hLPDmem->mem_syn1_fx, hLPDmem->mem_syn1_flt, 0, M); +#endif +#if 0 + floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, 0, 36); + floatToFixed_arr(syn, syn_fx, -1, L_FRAME16k); + st->hBWE_FD->mem_deemph_old_syn_fx = st->hBWE_FD->mem_deemph_old_syn; + st->preemph_fac = st->preemph_fac_flt * (1 << 15); + + save_old_syn_fx(st->L_frame, syn_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx); + + fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k, -1, 320); + fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, 0, 36); + st->hBWE_FD->mem_deemph_old_syn = st->hBWE_FD->mem_deemph_old_syn_fx; +#else + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } +#endif + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); +#if 0 + deemph(syn1, st->preemph_fac_flt, st->L_frame, &(hLPDmem->syn_flt[M])); +#else + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); +#endif + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } + +#endif + } /* end of active inp coding */ +#else + else + { + /*-----------------------------------------------------------------* + * Configure ACELP bit allocation + *-----------------------------------------------------------------*/ + + nb_bits = 0; + st->acelp_cfg.FEC_mode = 0; + uc_two_stage_flag = 0; + + if ( !nelp_mode && !ppp_mode ) + { + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if ( st->hDtxEnc != NULL && ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) ) +#else + if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) +#endif + { + mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); + lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if ( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_code_preq = 0; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup( st, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); + + if ( !tdm_lp_reuse_flag ) + { + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh ); + } + else + { + const float *pt_interp_2; + + if ( st->active_cnt != 1 ) + { + int16_t beta_index; + float lsf_wgts[M]; + + /* intra_frame prediction for the LSFs */ + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + + Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); +#ifdef IVAS_FLOAT_FIXED + Word16 lsf_new_fx[M]; + Word16 lsp_new_fx[M]; + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 lsf_wgts_fx[M]; + for ( int ii = 0; ii < M; ii++ ) + { + lsf_new_fx[ii] = (Word16) ( ( lsf_new[ii] ) * 2.56f ); + tdm_lsfQ_PCh_fx[ii] = (Word16) ( ( tdm_lsfQ_PCh[ii] ) * 2.56f ); + lsf_wgts_fx[ii] = (Word16) ( ( lsf_wgts[ii] ) * 2.56f ); + } + floatToFixed_arr( lsp_new, lsp_new_fx, 15, M ); + + tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index ); + + for ( int ii = 0; ii < M; ii++ ) + { + lsf_new[ii] = (Word16) ( ( lsf_new_fx[ii] ) / 2.56f ); + lsf_wgts[ii] = (Word16) ( ( lsf_wgts_fx[ii] ) / 2.56f ); + } + fixedToFloat_arr( lsp_new_fx, lsp_new, 15, M ); +#else + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); +#endif + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); + } + + pt_interp_2 = interpol_frac_12k8; + if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + { + pt_interp_2 = interpol_frac2; + } + + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame ); + } + + if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + tmpF = hLPDmem->old_exc_flt[0]; + preemph( hLPDmem->old_exc_flt, st->preemph_fac_flt, st->L_frame, &tmpF ); + mvr2r( hLPDmem->old_exc_flt + st->L_frame - M, hLPDmem->mem_syn_flt, M ); + residu( Aq, M, hLPDmem->old_exc_flt, old_exc_flt, st->L_frame ); + } + + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + if ( st->L_frame == L_FRAME ) + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + else + { + lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + } + } + + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, st->L_frame ); + + calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); + if ( att != 1.0f ) + { + v_multc( res, att, res, st->L_frame ); + } + + /*-----------------------------------------------------------------* + * Determine TC subframe classification + *-----------------------------------------------------------------*/ + + if ( st->coder_type == TRANSITION ) + { + tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); + + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ + + if ( nb_bits > 0 ) + { + Es_pred_enc( &Es_pred, &i, st->L_frame, L_SUBFR, res, st->voicing, nb_bits, uc_two_stage_flag ); + push_indice( hBstr, IND_ES_PRED, i, nb_bits ); + } + + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + { + if ( st->coder_type <= UNVOICED ) + { + tdm_low_rate_enc( st, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, 0 /*attack_flag*/, lsf_new, &tmp_noise ); + } + else /* GENERIC */ + { + encod_gen_2sbfr( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, inp, Aw, Aq, Es_pred, uc_two_stage_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if ( st->coder_type == TRANSITION ) + { + encod_tran( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, tc_subfr, position, unbits ); + } + else if ( ppp_mode ) + { + /* SC-VBR - PPP frames */ + if ( ( error = encod_ppp( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ) ) != IVAS_ERR_OK ) + { + return error; + } + + + if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* Configure ACELP bit allocation */ + config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + + /* redo LSF quantization */ + lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->hTdCngEnc->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + } + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + } + + + /* update mem_syn1_flt for ACELP core switching */ + mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn1_flt, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r_flt, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + if ( st->hBWE_FD != NULL ) + { + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_flt, &st->hBWE_FD->mem_deemph_old_syn ); + } + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); + deemph( syn1, st->preemph_fac_flt, st->L_frame, &( hLPDmem->syn_flt[M] ) ); + mvr2r( syn1 + st->L_frame - M - 1, hLPDmem->syn_flt, M + 1 ); + + if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) + { + mvr2r( syn1 + st->L_frame / 2, st->hTcxEnc->Txnq_flt, st->L_frame / 2 ); + } + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && nelp_mode != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame ); + stat_noise_uv_enc( st, epsP, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( hBstr, st->acelp_cfg, syn, st->coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate ); + + if ( st->hBWE_TD != NULL ) + { + if ( st->L_frame == L_FRAME ) + { + mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + else + { + mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) ); + } + } + + + } /* end of active inp coding */ +#endif + + /*-----------------------------------------------------------------* + * Write ACELP unused bits + *-----------------------------------------------------------------*/ + + if ( st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA && st->core_brate != PPP_NELP_2k80 ) + { + nBits = st->acelp_cfg.ubits; + + while ( nBits > 0 ) + { + i = min( nBits, 16 ); + push_indice( hBstr, IND_UNUSED, 0, i ); + nBits -= i; + } + } + + /*-----------------------------------------------------------------* + * Apply non linearity in case of SWB TBE + *-----------------------------------------------------------------*/ + + if ( st->hBWE_TD != NULL ) + { + if ( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + } + + if ( !st->Opt_SC_VBR && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) + { + /* Apply a non linearity to the SHB excitation */ + non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame ); + } + + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; + } + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + updt_enc( st, old_exc_flt, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); + + if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && st->core_brate > SID_2k40 ) + { + /* update CNG parameters in active frames */ + cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); + + if ( st->L_frame == L_FRAME ) + { + /* store LSPs@16k, potentially to be used in CNG@16k */ + mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); + } + + /* set LSP@16k flag for the first buffer */ + st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); + + /* efficient DTX hangover control */ + if ( st->hTdCngEnc->burst_ho_cnt > 1 ) + { + dtx_hangover_control( st, lsp_new ); + } + } + + /* SC-VBR update of average data rate */ + if ( st->vad_flag == 1 ) + { + /* reset in case of bitrate switching in EVS */ + if ( st->hSC_VBR != NULL ) + { + update_average_rate( st->hSC_VBR, st->core_brate ); + } + } + + pop_wmops(); + + return error; +} +#else ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ const float inp[], /* i : input signal of the current frame */ @@ -373,7 +1854,11 @@ ivas_error acelp_core_enc( * After inactive period, use the most up-to-date ISPs *-----------------------------------------------------------------*/ +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + if ( st->hDtxEnc != NULL && ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) ) +#else if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) +#endif { mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M ); lsp2lsf( st->hDtxEnc->lspCNG, st->lsf_old, M, int_fs ); @@ -726,3 +2211,4 @@ ivas_error acelp_core_enc( return error; } +#endif diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 3d4eda605e42c66ec845bb9ec0e55bf527a00c4a..a21f4adbb08c9233c87999f3dcf7a8c561252f26 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "stat_enc.h" #include "rom_com.h" #include "rom_enc.h" /* Encoder static table prototypes */ @@ -396,7 +395,7 @@ ivas_error acelp_core_enc_fx( IF( !nelp_mode && !ppp_mode ) { config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, + st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } @@ -406,7 +405,12 @@ ivas_error acelp_core_enc_fx( *-----------------------------------------------------------------*/ test(); +#ifdef NON_BE_FIX_807_MASA_DTX_BRSW + test(); + IF( st_fx->hDtxEnc != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) +#else IF( EQ_32( st_fx->last_core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) +#endif { Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); @@ -528,10 +532,10 @@ ivas_error acelp_core_enc_fx( IF( EQ_16( st_fx->coder_type, TRANSITION ) ) { - tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch_fx[0], res_fx ); + tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch[0], res_fx ); config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } @@ -599,7 +603,7 @@ ivas_error acelp_core_enc_fx( /* Configure ACELP bit allocation */ config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index e71900fc295c6cf7cdaa7352fb630b6450788469..9ab60f5d76c32855bc03b007e9cc6f56e55d054e 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -63,9 +62,9 @@ void acelp_core_switch_enc_fx( Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); - T_op[0] = st_fx->pitch_fx[0]; + T_op[0] = st_fx->pitch[0]; move16(); - T_op[1] = st_fx->pitch_fx[1]; + T_op[1] = st_fx->pitch[1]; move16(); /*----------------------------------------------------------------* @@ -138,7 +137,7 @@ void acelp_core_switch_enc_fx( /*----------------------------------------------------------------* * Excitation encoding *----------------------------------------------------------------*/ - config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, + config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); @@ -160,11 +159,11 @@ void acelp_core_switch_enc_fx( #else FOR( i = 0; i < 20; i++ ) { - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].value; + hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].value; move16(); - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; + hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; move16(); - hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; + hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; move16(); } #endif @@ -438,7 +437,7 @@ static void bwe_switch_enc_fx( Flag Overflow = 0; #endif hBstr = st_fx->hBstr; - L = NS2SA_fx2( st_fx->input_Fs, FRAME_SIZE_NS ); + L = NS2SA_FX2( st_fx->input_Fs, FRAME_SIZE_NS ); /* set multiplication factor according to the sampling rate */ tmp = extract_l( L_shr( st_fx->input_Fs, 14 ) ); diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 8dde5a31946e9da10aa854ee06f07476adffe9c1..ffdf837c4ee090fe1ff596ceb0a61a9e3395b058 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -9,8 +9,7 @@ //#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "rom_com.h" diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 3f5ddbb4bb5ddc42bdc75532b5c3c96162d7ae41..4a3d44fe3d58017caa1f8ad96f823d36458cdd01 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -10,8 +10,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" @@ -161,7 +160,7 @@ void amr_wb_enc_fx( *----------------------------------------------------------------*/ /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); @@ -255,8 +254,8 @@ void amr_wb_enc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - - modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); /* update signal buffer */ Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME ); @@ -400,7 +399,7 @@ void amr_wb_enc_fx( /* reset the OL pitch tracker memories during inactive frames */ pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); } - old_pitch1 = st->pitch_fx[1]; + old_pitch1 = st->pitch[1]; move16(); analy_lp_AMR_WB_fx( inp, &ener, A, epsP_h, epsP_l, isp_new, st->lsp_old1_fx, isf_new, st->old_pitch_la, st->old_voicing_la, Q_new, Q_r ); @@ -422,8 +421,8 @@ void amr_wb_enc_fx( shift = -1; move16(); } - pitch_ol_fx( st->pitch_fx, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth, st->Opt_SC_VBR ); - st->old_pitch_la = st->pitch_fx[2]; + pitch_ol_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth, st->Opt_SC_VBR ); + st->old_pitch_la = st->pitch[2]; move16(); st->old_voicing_la = st->voicing_fx[2]; move16(); @@ -452,14 +451,14 @@ void amr_wb_enc_fx( IF( EQ_32( st->input_Fs, 16000 ) ) { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - tmps = NS2SA_fx2( 16000, DELAY_FIR_RESAMPL_NS ); + tmps = NS2SA_FX2( 16000, DELAY_FIR_RESAMPL_NS ); Copy_Scale_sig( &st->mem_decim16k_fx[tmps], new_inp_16k, tmps, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ Copy_Scale_sig( st->input_fx, new_inp_16k + tmps, sub( input_frame, tmps ), -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ Copy( st->input_fx + input_frame - shl( tmps, 1 ), st->mem_decim16k_fx, shl( tmps, 1 ) ); /* memory still in Q0 */ } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { - modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0 ); + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0, &Q_new_inp, &mem_decim_size ); } /*----------------------------------------------------------------* diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 51c40ec5ec11dc44f28d8084f864f7912341c2b8..314f7a9c2ffe687d944c448f70dcbeb1dd4f1589 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -9,8 +9,7 @@ #include "rom_com.h" /* Static table prototypes */ #include "rom_enc.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -146,7 +145,7 @@ void analy_lp_AMR_WB_fx( /* Initialization */ wind_length = L_LP_AMR_WB; move16(); - wind = Hamcos_Window; + wind = hamcos_window_fx; /* Autocorrelations */ autocorr_fx( speech - L_SUBFR, M, r_h, r_l, &Q_r[0], wind_length, wind, 0, 0 ); diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index fd96bfe4e7b43d590b3f46c4de6d1a8feaa2543c..e23c9b9a5eb4701391cfe37e7c43a7149f6ca0b5 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" #include "basop_util.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index 2908310f8b3336ff601a1a745eae981624162d69..8481d6c94a0a7228fd23a8b30f264bc622c9d9c5 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "stat_com.h" #include "basop_util.h" #include "wmc_auto.h" @@ -81,7 +82,21 @@ void ari_start_encoding_14bits( return; } +#ifdef IVAS_FLOAT_FIXED +void ari_start_encoding_14bits_ivas_fx( + Tastat *s ) +{ + /* : addressing is made with walking pointer s */ + s->low = 0; + s->high = ari_q4new; + s->bits_to_follow = 0; + move32(); + move32(); + move32(); + return; +} +#endif /*--------------------------------------------------------------- * ari_done_encoding_14bits() diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 5e01f8f3589ecf0c65fb0db6787275f5cdbb73ed..54c21c9d1f6a29f2cfc3dbfaf3272d6139731def 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -9,8 +9,7 @@ #include "cnst.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------- diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c index bc4c225df9676f7a97bf93c7df1617f49fcae932..8414c56daa0ef4f918647baca5fb7deb4d38b42c 100644 --- a/lib_enc/ari_hm_enc_fx.c +++ b/lib_enc/ari_hm_enc_fx.c @@ -12,8 +12,7 @@ #include "rom_enc.h" #include "prot.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c index eedd260ee011e983310327d02ac85da4e594319e..3b5c8dea9a3967142cc744009efc352d49bde169 100644 --- a/lib_enc/arith_coder_enc.c +++ b/lib_enc/arith_coder_enc.c @@ -248,11 +248,11 @@ static float tcx_arith_find_max_scale( /*! r: index of highest freq. nonzero line (-1 if all zeros) */ static int16_t tcx_arith_find_kMax( - const float abs_spectrum[], /* i : absolute MDCT coefficients */ - const int16_t L_frame, /* i : number of spectral lines */ - const float scale, /* i : scalar quantizer scale */ - const float deadzone, /* i : deadzone (0.5f = no deadzone) */ - const int16_t deadzone_flags[] /* i : line-wise deadzone control */ + const float abs_spectrum[], /* i : absolute MDCT coefficients */ + const int16_t L_frame, /* i : number of spectral lines */ + const float scale, /* i : scalar quantizer scale */ + const float deadzone, /* i : deadzone (0.5f = no deadzone) */ + const int8_t deadzone_flags[] /* i : line-wise deadzone control */ ) { int16_t kMax; @@ -275,15 +275,15 @@ static int16_t tcx_arith_find_kMax( /*! r: best scale */ static float tcx_arith_rateloop( - const float abs_spectrum[], /* i : absolute MDCT coefficients */ - const int16_t L_frame, /* i : number of spectral lines */ - const Word16 envelope[], /* i : scaled envelope (Q15-e) */ - const Word16 envelope_e, /* i : scaled envelope exponent (Q0) */ - const Word16 exps[], /* i : expfp_evs(-(integer)envelope[]/2) */ - const int16_t target_bits, /* i : target bit budget */ - const float deadzone, /* i : deadzone (0.5f = no deadzone) */ - const int16_t deadzone_flags[], /* i : line-wise deadzone control */ - float *target_bits_fac /* i/o: scale estimator compensation */ + const float abs_spectrum[], /* i : absolute MDCT coefficients */ + const int16_t L_frame, /* i : number of spectral lines */ + const Word16 envelope[], /* i : scaled envelope (Q15-e) */ + const Word16 envelope_e, /* i : scaled envelope exponent (Q0) */ + const Word16 exps[], /* i : expfp_evs(-(integer)envelope[]/2) */ + const int16_t target_bits, /* i : target bit budget */ + const float deadzone, /* i : deadzone (0.5f = no deadzone) */ + const int8_t deadzone_flags[], /* i : line-wise deadzone control */ + float *target_bits_fac /* i/o: scale estimator compensation */ ) { int16_t k, idx, kMax, q; @@ -594,7 +594,7 @@ void tcx_arith_encode_envelope( float scale; int16_t k, kMax; float deadzone; - const int16_t *deadzone_flags; + const int8_t *deadzone_flags; float gamma_w, gamma_uw; int16_t hm_bits; @@ -609,7 +609,7 @@ void tcx_arith_encode_envelope( gamma_uw = 1.0f / st->gamma_flt; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_ivas( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP for ( k = 0; k < L_spec; ++k ) @@ -644,7 +644,7 @@ void tcx_arith_encode_envelope( L_spec_core = min( L_spec_core, st->hIGFEnc->infoStartLine ); } envelope = (Word16 *) env; - tcx_arith_scale_envelope_flt( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); + tcx_arith_scale_envelope_ivas( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); #define WMC_TOOL_SKIP tmp = sub( envelope_e, 1 ); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 5c96532bea9756db06a95d8f9270ce0a65977a71..6b137f31e1b30c7a61fc9386be150537360c3a62 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -6,8 +6,7 @@ #include #include "options.h" #include "cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" #include "rom_com.h" @@ -716,7 +715,7 @@ void tcx_arith_encode_envelope_fx( hTcxCfg = st->hTcxCfg; deadzone = hTcxCfg->sq_rounding; move16(); - deadzone_flags = hTcxEnc->memQuantZeros_fx; + deadzone_flags = hTcxEnc->memQuantZeros; *signaling_bits = 0; move16(); diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index 5b1756bfdd8f1ae9331dc881e051a5d6a37421fe..ece84e4e95cd46448e961427e032bc582020773f 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -8,8 +8,7 @@ #include /* Compilation switches */ #include "prot.h" /* Function prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index c8ea49bf33f8f48fc87718baf8b060875e12bca2..df52213c2bdc3d56ff7cbb9302ceaae8b3d78479 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index eb3e62ddf06092200ba91466c495288752e7d520..3cc6784de9b795e56998411f326094f11979fb4e 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -5,14 +5,13 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" #include "basop_util.h" #include "ivas_cnst.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "ivas_prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * Local constants @@ -312,16 +311,14 @@ void bw_detect_fx( } ELSE { -#ifdef IVAS_CODE_DFT - l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); - if ( st->core == TCX_10_CORE ) + Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); + IF( EQ_16( st->core, TCX_10_CORE ) ) { - l_frame /= 2; + l_frame = shr( l_frame, 1 ); } - bin_width *= ( l_frame / BWD_TOTAL_WIDTH ); - mvr2r( spectrum, spect, l_frame ); -#endif + bin_width = i_mult( bin_width, l_frame / BWD_TOTAL_WIDTH ); + Copy( spectrum, spect, l_frame ); } /*---------------------------------------------------------------------* * compute energy per spectral bins @@ -1070,7 +1067,7 @@ void set_bw_stereo( return; } - +#endif /*-------------------------------------------------------------------* * set_bw_mct() * @@ -1078,54 +1075,58 @@ void set_bw_stereo( *-------------------------------------------------------------------*/ /*! r: flag indicating whether the coded BW has changed */ -int16_t set_bw_mct( +Word16 set_bw_mct_fx( CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ - const int16_t nCPE /* i : number of CPEs */ + const Word16 nCPE /* i : number of CPEs */ ) { - Encoder_State *sts[MCT_MAX_CHANNELS]; - int16_t ch, cpe_id; - int16_t mct_bwidth, last_mct_bwidth, bw_changed; + Encoder_State *st; + Word16 ch, cpe_id; + Word16 mct_bwidth, last_mct_bwidth, bw_changed; mct_bwidth = WB; /* minimum coded audio band-width */ last_mct_bwidth = hCPE[0]->hCoreCoder[0]->last_bwidth; /* supposes that LFE is not in the first channel */ + move16(); + move16(); - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; - if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + st = hCPE[cpe_id]->hCoreCoder[ch]; + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - continue; + CONTINUE; } - mct_bwidth = max( mct_bwidth, sts[ch]->input_bwidth ); + mct_bwidth = s_max( mct_bwidth, st->input_bwidth ); } } - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - if ( hCPE[cpe_id]->element_brate > BWD_MAX_BRATE_WIDER_BW_MDCT ) + IF( GT_32( hCPE[cpe_id]->element_brate, BWD_MAX_BRATE_WIDER_BW_MDCT ) ) { - mct_bwidth = max( mct_bwidth, hCPE[cpe_id]->hCoreCoder[0]->max_bwidth ); + mct_bwidth = s_max( mct_bwidth, hCPE[cpe_id]->hCoreCoder[0]->max_bwidth ); } } + bw_changed = 0; - if ( mct_bwidth != last_mct_bwidth ) + move16(); + IF( NE_16( mct_bwidth, last_mct_bwidth ) ) { bw_changed = 1; + move16(); - for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - sts[ch] = hCPE[cpe_id]->hCoreCoder[ch]; - sts[ch]->bwidth = mct_bwidth; + st = hCPE[cpe_id]->hCoreCoder[ch]; + st->bwidth = mct_bwidth; + move16(); } } } - return bw_changed; } - -#endif diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 401eb6412be817097b5b6be024b796e358c7ae00..e94da2f7c565401d11853a307c95ea02fbffa48e 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" @@ -759,7 +758,8 @@ void CNG_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0 ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0, &Q_new_inp, &mem_decim_size ); } fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); @@ -1318,8 +1318,8 @@ static void shb_CNG_encod_fx( push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4 ); push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); #ifndef IVAS_CODE - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits ); - hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_CNG_ENV1].nb_bits ); + hBstr->ind_list[IND_CNG_ENV1].nb_bits = -1; #else delete_indice( hBstr, IND_CNG_ENV1 ); #endif diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index afb4d7ff3575095a38e99b755f43273a2fe98ec5..06c4d31f0dcacd6f72b95dc16bb8afd8738254f4 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index 43d1e643445718e753796ec1d5685e7f3991eb00..b20c94daf7d2157509a14463a5470d41ec60f68e 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -8,8 +8,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 667843880922ca8eda869918b337a2c5d68006f6..efa0e0d4c06c5213554cb068d28dd8850da8e43b 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -11,8 +11,7 @@ #include "options.h" #include "rom_basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -240,7 +239,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * { /* Adaptive Codebook (GC and VC) */ - Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm, &exc[i_subfr], st->pitch_fx, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, + Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm, &exc[i_subfr], st->pitch, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); E_ACELP_adaptive_codebook( exc, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode, i_subfr, L_SUBFR, L_frame, h1, clip_gain, xn, diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 96acb8f40145e6b1bc233d723601bf0cd1b2cc5f..77da3cd29fbdec4d3f9b06be5791473340db4bc6 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -580,7 +580,7 @@ void TNSAnalysis( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const float ltp_gain, /* i : ltp gain */ STnsData *pTnsData, /* o : TNS data */ - int16_t *pfUseTns, /* o : Flag indicating if TNS is used */ + int8_t *pfUseTns, /* o : Flag indicating if TNS is used */ float *predictionGain /* o : TNS prediction gain */ ) { @@ -615,7 +615,7 @@ void TNSAnalysis( } } - *pfUseTns = DetectTnsFilt( hTcxCfg->pCurrentTnsConfig, spectrum, hTranDet, transform_type != TCX_20, ltp_gain, pTnsData, predictionGain ); + *pfUseTns = (Word8) DetectTnsFilt( hTcxCfg->pCurrentTnsConfig, spectrum, hTranDet, transform_type != TCX_20, ltp_gain, pTnsData, predictionGain ); /* If TNS should be used then get the residual after applying it inplace in the spectrum */ @@ -661,7 +661,7 @@ void ShapeSpectrum( const int16_t L_frame_glob, /* i : frame length */ int16_t L_spec, /* i : length of the spectrum */ float spectrum[], /* i/o: MDCT spectrum */ - const int16_t fUseTns, /* i : Flag indicating if TNS is used */ + const int8_t fUseTns, /* i : Flag indicating if TNS is used */ Encoder_State *st, /* i/o: encoder state structure */ float *scf /* i : scale factors */ ) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 0c3f7d4df719ed2d98a149e99aeb6a8cdc08ecec..86ca20698746a0e43461bdec0f0a08f8567bcd4d 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -9,8 +9,7 @@ #include "rom_com.h" #include "stat_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_util.h" #include "stl.h" //#include "basop_mpy.h" @@ -1202,7 +1201,7 @@ void QuantizeSpectrum_fx( move16(); aldo = 0; move16(); - nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); + nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); move16(); /* Modified the overlap to the delay in case of short blocks*/ tcx_offset = hTcxCfg->tcx_offset; @@ -1407,7 +1406,7 @@ void QuantizeSpectrum_fx( L_spec, sqGain, sqGain_e, hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, + hTcxEnc->memQuantZeros, tcxonly ); /* Estimate original bitrate */ @@ -1501,7 +1500,7 @@ void QuantizeSpectrum_fx( L_spec, sqGain, sqGain_e, hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, + hTcxEnc->memQuantZeros, tcxonly ); /* Estimate bitrate */ @@ -1567,7 +1566,7 @@ void QuantizeSpectrum_fx( L_spec, &sqGain, &sqGain_e, hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, + hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, @@ -1699,7 +1698,7 @@ void QuantizeSpectrum_fx( L_spec, sqGain, sqGain_e, hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros_fx, + hTcxEnc->memQuantZeros, tcxonly ); move16(); @@ -2886,25 +2885,25 @@ void coder_tcx_fx( test(); SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, st->last_core == 0 ); - TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns_fx, &st->hIGFEnc->tns_predictionGain ); + TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain ); } ELSE { - hTcxEnc->fUseTns_fx[0] = hTcxEnc->fUseTns_fx[1] = 0; + hTcxEnc->fUseTns[0] = hTcxEnc->fUseTns[1] = 0; move16(); move16(); } IF( st->igf ) { - ProcessIGF_fx( st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns_fx[0], ( st->last_core == ACELP_CORE ), 0 ); + ProcessIGF_fx( st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns[0], ( st->last_core == ACELP_CORE ), 0 ); } ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e, L_frame_glob, L_spec, spectrum, - hTcxEnc->fUseTns_fx[0], + hTcxEnc->fUseTns[0], st ); if ( st->igf ) { @@ -2927,7 +2926,7 @@ void coder_tcx_fx( tcxonly, spectrum, spectrum_e, hTcxEnc->tnsData, - hTcxEnc->fUseTns_fx[0], + hTcxEnc->fUseTns[0], tnsSize, prm, n, diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index bf20ecfd0d467de373c1764463f122307818071a..1af9e346388cb7ec4b3a2a0d65a4e4a65a65af32 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -7,8 +7,7 @@ #include //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index 2fa8069f8a8215a57c4995cf91345d18fd63461a..98816e768d91e0666a6fade90f54a9201054fa04 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -11,8 +11,7 @@ //#include "prot_fx.h" #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 6645155ef2a7ab2e1664561ce60af7669e61678c..1120235052e6863cee83f1794f0cc5697929428a 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index 37df43e37ab2174df9a189afa44b385fdf2a23bb..151561b091bea6801e7c95d3ddd5cc9bdfba53c4 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -11,8 +11,7 @@ //#include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -79,7 +78,7 @@ void core_encode_twodiv_fx( FOR( i = 0; i < 3; i++ ) { move16(); - T_op[i] = st->pitch_fx[i]; + T_op[i] = st->pitch[i]; /* check minimum pitch for quantization */ IF( LT_16( T_op[i], PIT_MIN_SHORTER ) ) @@ -179,7 +178,7 @@ void core_encode_twodiv_fx( shr( st->L_frame, 1 ), shr( st->hTcxCfg->tcx_coded_lines, 1 ), spectrum[n], - hTcxEnc->fUseTns_fx[n], + hTcxEnc->fUseTns[n], st ); st->last_core = st->core; @@ -239,7 +238,7 @@ void core_encode_twodiv_fx( spectrum[n], &spectrum_e[n], hTcxEnc->tnsData + n, - hTcxEnc->fUseTns_fx[n], + hTcxEnc->fUseTns[n], tnsSize[n], param_core + n * NPRM_DIV, n, @@ -275,7 +274,7 @@ void core_encode_twodiv_fx( st->L_frame, st->hTcxCfg->tcx_coded_lines, spectrum[0], - hTcxEnc->fUseTns_fx[0], + hTcxEnc->fUseTns[0], st ); /*_DIFF_FLOAT_FIX_ -> The line below is present in float */ @@ -315,7 +314,7 @@ void core_encode_twodiv_fx( spectrum[0], &spectrum_e[0], &hTcxEnc->tnsData[0], - hTcxEnc->fUseTns_fx[0], + hTcxEnc->fUseTns[0], tnsSize[0], param_core, 0, diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 74a0f62e67d3285d1ef2d86a4eb45bbe1ea77084..855ff8e89badccf2c5f5505c71770ff6019cc745 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -255,8 +255,17 @@ static void init_tcx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ +#if 1 + hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; + hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#endif + hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long; hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef IVAS_FLOAT_FIXED + hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; + hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#endif init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac_flt, st->tcxonly, st->rf_mode, st->igf, st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag ); @@ -267,7 +276,7 @@ static void init_tcx( hTcxEnc->noiseLevelMemory_cnt = 0; set_f( hTcxEnc->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS ); - set_s( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); + set_c( hTcxEnc->memQuantZeros, 0, L_FRAME_PLUS ); /* TCX-LTP */ hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 938997bd4b7a99bc9e3b5253adb4fb38ea477d2f..58657bb6b78f737852110fc86262ef8ab352ae90 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -15,8 +15,7 @@ #include #include "rom_com.h" /* Common constants */ #include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -98,9 +97,9 @@ void init_coder_ace_plus_fx( } /* Core Lookahead */ - st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); + st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); move16(); - st->encoderLookahead_FB = NS2SA_fx2( st->input_Fs, ACELP_LOOK_NS ); + st->encoderLookahead_FB = NS2SA_FX2( st->input_Fs, ACELP_LOOK_NS ); move16(); IF( st->ini_frame == 0 ) @@ -341,7 +340,7 @@ static void init_tcx_fx( FOR( i = 0; i < L_FRAME_PLUS; i++ ) { - hTcxEnc->memQuantZeros_fx[i] = 0; + hTcxEnc->memQuantZeros[i] = 0; move16(); } diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 4a7db5f6925bec3d5cfd7365e261052323d5ee81..9957ccdef4d3e7d169f40b5a4a3bf175ac09a424 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -10,8 +10,7 @@ #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -430,7 +429,7 @@ void core_encode_openloop_fx( /* Update ACELP quantizer state */ lsf_update_memory( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); - st->pstreaklen_fx = 0; + st->pstreaklen = 0; st->streaklimit_fx = 32767; /* check resonance for pitch clipping algorithm */ gp_clip_test_lsf_fx( st->element_mode, st->lsf_old_fx, st->clip_var_fx, 0 ); @@ -613,7 +612,7 @@ void core_encode_openloop_fx( IF( NE_16( hRF->rf_frame_type, RF_NO_DATA ) ) { /* coder_acelp_rf_fx does the partial copy encoding based on the rf frame type chosen for the RF encoding */ - coder_acelp_rf_fx( &( hRF->acelp_cfg_rf ), coder_type, Aw, Aq_rf, st->speech_enc_pe, st->voicing_fx, st->pitch_fx, + coder_acelp_rf_fx( &( hRF->acelp_cfg_rf ), coder_type, Aw, Aq_rf, st->speech_enc_pe, st->voicing_fx, st->pitch, stab_fac_rf, st, hRF->rf_target_bits, hRF->rf_frame_type, exc_rf, syn_rf, Q_new, shift ); } } @@ -660,7 +659,7 @@ void core_encode_openloop_fx( && ( EQ_16( hTcxEnc->tcxltp_pitch_int, hRF->rf_tcxltp_pitch_int_past ) ) /*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ && ( hRF->rf_last_tns_active == 0 ) /*!st->rf_last_tns_active*/ && ( hRF->rf_second_last_tns_active == 0 ) /*!st->rf_second_last_tns_active*/ - && ( ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0] ) == 0 ) /*!(st->hTcxCfg->fIsTNSAllowed & st->fUseTns[0])*/ + && ( ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns[0] ) == 0 ) /*!(st->hTcxCfg->fIsTNSAllowed & st->fUseTns[0])*/ ) { rf_PLC_Mode = 1; @@ -699,7 +698,7 @@ void core_encode_openloop_fx( move16(); hRF->rf_second_last_tns_active = hRF->rf_last_tns_active; move16(); - hRF->rf_last_tns_active = ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns_fx[0] ); + hRF->rf_last_tns_active = ( st->hTcxCfg->fIsTNSAllowed & hTcxEnc->fUseTns[0] ); move16(); hRF->rf_second_last_core = st->last_core; move16(); @@ -824,7 +823,7 @@ void core_acelp_tcx20_switching_fx( /* Check minimum pitch for quantization */ FOR( i = 0; i < 3; i++ ) { - tmp16 = st->pitch_fx[i]; + tmp16 = st->pitch[i]; move16(); /* check minimum pitch for quantization */ if ( LT_16( tmp16, PIT_MIN_SHORTER ) ) @@ -839,12 +838,12 @@ void core_acelp_tcx20_switching_fx( /*pitch[i] = (short)(pitch[i] * 1.25f + 0.5f);*/ tmp16 = add( tmp16, s ); } - st->pitch_fx[i] = tmp16; + st->pitch[i] = tmp16; move16(); } IF( st->narrowBand != 0 ) { - pitchDoubling_det_fx( st->wspeech_enc, st->pitch_fx, pitch_fr, voicing_fr ); + pitchDoubling_det_fx( st->wspeech_enc, st->pitch, pitch_fr, voicing_fr ); } E_LPC_f_lsp_a_conversion( lsp_mid, A_q_tcx, M ); @@ -860,7 +859,7 @@ void core_acelp_tcx20_switching_fx( st->speech_enc + st->encoderLookahead_enc, hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->wspeech_enc + st->encoderLookahead_enc, - st->pitch_fx[1], + st->pitch[1], hTcxEnc->tcxltp_param, &hTcxEnc->tcxltp_bits, &hTcxEnc->tcxltp_pitch_int, diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index 7eab3e742a9fad3bcc0da159ae4efac861f0ca67..67238f036306394659e80ce7c6c311ca3e89117b 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -223,13 +223,13 @@ void core_coder_reconfig( if ( st->total_brate < ACELP_24k40 && ( ( st->total_brate > last_total_brate ) || ( st->last_codec_mode == MODE1 ) ) ) { /* low-freq memQuantZeros must be reset partially if bitrate increased */ - set_s( hTcxEnc->memQuantZeros, 0, hTcxEnc->nmStartLine ); + set_c( hTcxEnc->memQuantZeros, 0, hTcxEnc->nmStartLine ); } else { if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_32k && last_total_brate >= ACELP_13k20 && last_total_brate < ACELP_24k40 ) { - set_s( hTcxEnc->memQuantZeros, 0, st->L_frame ); + set_c( hTcxEnc->memQuantZeros, 0, st->L_frame ); } } } diff --git a/lib_enc/core_enc_reconf_fx.c b/lib_enc/core_enc_reconf_fx.c index 49631b17808cecb1a81945c1f1af753090493a29..c4e4b16cd6a9694998664d9b34fa9cd1802c6f00 100644 --- a/lib_enc/core_enc_reconf_fx.c +++ b/lib_enc/core_enc_reconf_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -311,7 +310,7 @@ void core_coder_reconfig_fx( /* low-freq memQuantZeros_fx must be reset partially if bitrate increased */ FOR( i = 0; i < hTcxEnc->nmStartLine; i++ ) { - hTcxEnc->memQuantZeros_fx[i] = 0; + hTcxEnc->memQuantZeros[i] = 0; move16(); } } @@ -319,7 +318,7 @@ void core_coder_reconfig_fx( { FOR( i = 0; i < st->L_frame; i++ ) /* memQuantZeros_fx won't be updated */ { - hTcxEnc->memQuantZeros_fx[i] = 0; + hTcxEnc->memQuantZeros[i] = 0; move16(); } } diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 0eede724a6cf61e01465ed7d318687c934694ae3..268bd58ac41688fb95ff719de1bd70fa71522808 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -11,8 +11,7 @@ #include "ivas_cnst.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index 9fa4f0ff3a53cb4d3d996d7b0215a182a88b7e48..bd6f5b5482e700c59c0be1cca2375df718a2e21f 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -8,8 +8,7 @@ #include "cnst.h" /* Common constants */ #include "basop_util.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index 457d93bd8d40d96d8473bd82d01daf8e6acdcb47..fe470af2df29bc6a5dc5242a86f45f6985fcf17b 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -431,8 +430,8 @@ void core_switching_post_enc_fx( test(); IF( ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) /* core switching ==> CELP subframe encoding */ { - acelp_core_switch_enc_fx( st_fx, old_inp_12k8 + L_INP_MEM - NS2SA_fx2( INT_FS_FX, ACELP_LOOK_NS ), - old_inp_16k + L_INP_MEM - NS2SA_fx2( INT_FS_16k, ACELP_LOOK_NS ), A, Qshift, Q_new ); + acelp_core_switch_enc_fx( st_fx, old_inp_12k8 + L_INP_MEM - NS2SA_FX2( INT_FS_FX, ACELP_LOOK_NS ), + old_inp_16k + L_INP_MEM - NS2SA_FX2( INT_FS_16k, ACELP_LOOK_NS ), A, Qshift, Q_new ); } hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 698d14830dd4af944d4aed8ad83cf73171eaa4bd..86ba92c7a7c28d0cd2e92e551d1b6d195ab784c7 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -5,8 +5,7 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index 5f0eaf0cd43c927ccc9dd676356657bc4b9504d6..922883ffc4b46ffb89a5e85986cf8a4f489b95ae 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -10,8 +10,7 @@ #include "stat_enc.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 0d86e3aabecd436a0c3c62a8eb9614855d4af965..e21579cd0acce22f264bab94c352c0bb40480af5 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -37,8 +37,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------*/ diff --git a/lib_enc/diffcod_fx.c b/lib_enc/diffcod_fx.c index 5fd01046a8a462d16d2c4fd8ad2130cb72cf8aac..7ff48d81667335768cc737aa75033fd6b998d258 100644 --- a/lib_enc/diffcod_fx.c +++ b/lib_enc/diffcod_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Compilation switches */ #include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function Prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------*/ diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 2043d082f958035427f2ab5121333b7ec2dc1619..afc6fbe38c21d881a7a4d2600fe2e4c1dc11e412 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -4,14 +4,13 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" #include "rom_com.h" -//#include "basop_mpy.h" +// #include "basop_mpy.h" #include -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ +#include "prot.h" /*-------------------------------------------------------------------* * Local constants @@ -34,6 +33,7 @@ /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ #define LP_NOISE_LV 5 /* LP_NOISE level */ + #define MAX_BRATE_DTX_EVS ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */ #define MAX_BRATE_DTX_IVAS IVAS_64k /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */ @@ -42,7 +42,511 @@ *-------------------------------------------------------------------*/ static void update_SID_cnt( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, const Word16 Opt_AMR_WB ); +/*==================================================================================*/ +/* FUNCTION : dtx_ivas_fx() */ +/*----------------------------------------------------------------------------------*/ +/* PURPOSE : Discontinuous transmission operation */ +/*----------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Encoder_State_Fx) st_fx : encoder state structure */ +/* _ (Word16) vad : vad flag Q0 */ +/* _ (Word16[]) speech_fx : Pointer to the speech frame qSpeech */ +/* _ (Word16) qSpeech : speech buffer qformat value */ +/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ +/*----------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ +/* _ (Encoder_State_Fx) st_fx : encoder state structure */ +/*----------------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*==================================================================================*/ +void dtx_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 vad, /* i : vad flag for DTX */ + const Word16 speech[] /* i : Pointer to the speech frame */ + +) +{ + Word16 alpha; + Word32 L_tmp; + DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; + TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + + Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; + + IF( st_fx->dtx_sce_sba != 0 ) + { + last_br_cng_flag = 1; + last_br_flag = 1; + br_dtx_flag = 1; + move16(); + move16(); + move16(); + } + ELSE + { + /* _DIFF_FLOAT_FIX_ : lp_noise_fx threshold is different between float (15) and fix (5*256) */ + last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, ACELP_32k ) ); + + last_br_flag = LE_32( st_fx->last_total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate, ACELP_32k ) ); + br_dtx_flag = 0; + move16(); + } + /* Initialization */ + IF( st_fx->ini_frame == 0 ) + { + st_fx->active_fr_cnt_fx = CNG_TYPE_HO; + move16(); + + st_fx->cng_type = FD_CNG; + move16(); + test(); + if ( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && EQ_16( st_fx->element_mode, IVAS_SCE ) && EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + st_fx->cng_type = LP_CNG; + move16(); + } + } + test(); + test(); + IF( st_fx->Opt_DTX_ON && vad == 0 && + GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ + st_fx->fd_cng_reset_flag == 0 && + NE_16( st_fx->last_core, AMR_WB_CORE ) && + st_fx->Opt_AMR_WB == 0 ) + { + test(); + test(); + test(); + IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) && + NE_32( st_fx->last_total_brate_cng, st_fx->total_brate ) && last_br_cng_flag ) + { + st_fx->total_brate = st_fx->last_total_brate_cng; + move32(); + test(); + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) + { + st_fx->Opt_SC_VBR = 0; + move16(); + } + st_fx->rf_mode = st_fx->last_rf_mode_cng; + move16(); + st_fx->bwidth = st_fx->last_bwidth_cng; + move16(); + st_fx->codec_mode = st_fx->last_codec_mode_cng; + move16(); + } + test(); + test(); + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag ) + + { + st_fx->total_brate = st_fx->last_total_brate; + move32(); + test(); + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) + { + st_fx->Opt_SC_VBR = 0; + move16(); + } + + st_fx->Opt_RF_ON = 0; + move16(); + test(); + test(); + test(); + if ( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && NE_16( st_fx->bwidth, NB ) ) + { + st_fx->Opt_RF_ON = 1; + move16(); + } + st_fx->rf_mode = st_fx->Opt_RF_ON; + move16(); + st_fx->bwidth = st_fx->last_bwidth; + move32(); + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->codec_mode = MODE1; + move16(); + } + ELSE + { + st_fx->codec_mode = get_codec_mode( st_fx->total_brate ); + } + } + } + + /*------------------------------------------------------------------------* + * Select SID or FRAME_NO_DATA frame if DTX is enabled + *------------------------------------------------------------------------*/ + if ( st_fx->dtx_sce_sba == 0 ) + { +#if 0 + br_dtx_flag = LE_32( st_fx->total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, LP_NOISE_LV * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || + EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st_fx->element_brate, IVAS_64k ) || LT_16( st_fx->lp_noise_fx, 15 * 256 ) ) ); +#else + br_dtx_flag = ( EQ_16( st_fx->element_mode, EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) || + ( NE_16( st_fx->element_mode, EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || + LT_16( st_fx->lp_noise_fx, shl( 15, Q8 ) ); +#endif + } + test(); + test(); + test(); + test(); + IF( st_fx->Opt_DTX_ON && vad == 0 && + GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ + br_dtx_flag && + st_fx->fd_cng_reset_flag == 0 ) + { + /* reset counter */ + st_fx->active_fr_cnt_fx = 0; + move16(); + + IF( st_fx->Opt_AMR_WB ) + { + st_fx->last_total_brate_cng = -1; + st_fx->last_rf_mode_cng = st_fx->rf_mode; + move16(); + } + ELSE + { + st_fx->last_total_brate_cng = st_fx->total_brate; + st_fx->last_bwidth_cng = st_fx->bwidth; + st_fx->last_codec_mode_cng = st_fx->codec_mode; + } + + IF( hDtxEnc->cnt_SID == 0 ) + { + /* this will be a SID frame */ + IF( st_fx->Opt_AMR_WB ) + { + st_fx->core_brate = SID_1k75; + move32(); + } + ELSE + { + st_fx->core_brate = SID_2k40; + move32(); + } + } + ELSE + { + /* this will be a no data frame */ + st_fx->core_brate = FRAME_NO_DATA; + move32(); + } + + test(); + test(); + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_16( st_fx->last_core, ACELP_CORE ) && !st_fx->Opt_AMR_WB ) + { + /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */ + st_fx->core_brate = SID_2k40; + move32(); + } + // PMT("dtx_sce_sba code is missing") + IF( ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) ) + { + st_fx->cng_type = FD_CNG; + move16(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_48k ) || EQ_32( st_fx->total_brate, HQ_96k ) || EQ_32( st_fx->total_brate, HQ_128k ) ) ) + { + st_fx->codec_mode = MODE2; + move16(); + } + } + ELSE + { + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, ACELP_24k40 ) || ( NE_16( st_fx->element_mode, EVS_MONO ) && LE_32( st_fx->total_brate, ACELP_32k ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */ + { + test(); + test(); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) ) + { + st_fx->codec_mode = MODE2; + move16(); + } + } + ELSE + { + st_fx->cng_type = LP_CNG; + move16(); + IF( st_fx->codec_mode == MODE2 ) + { + hTdCngEnc->lp_cng_mode2 = 1; + move16(); + } + st_fx->codec_mode = MODE1; + move16(); + } + } + /* reset the bitstream (IVAS format signalling was already written) */ + IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL ) + { + reset_indices_enc( st_fx->hBstr, st_fx->hBstr->nb_ind_tot ); + } + } + + /*------------------------------------------------------------------------* + * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame) + *------------------------------------------------------------------------*/ + /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ + test(); + test(); + IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) ) ) + { + IF( hDtxEnc != NULL ) + { + hDtxEnc->cnt_SID = 0; + move16(); + + /* change SID update rate */ + /* first SID update is only 8 (3) frames after the active speech end */ + IF( !st_fx->Opt_AMR_WB ) + { + hDtxEnc->max_SID = FIXED_SID_RATE; + move16(); + } + ELSE + { + hDtxEnc->max_SID = 3; + move16(); /* first SID update is only 3 frames after the active speech end */ + } + + IF( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) ) + { + hDtxEnc->max_SID = hDtxEnc->interval_SID; + move16(); /* change SID update rate */ + } + + hDtxEnc->cng_cnt = 0; + move16(); /* reset the counter of CNG frames for averaging */ + } + test(); + IF( GE_16( st_fx->active_fr_cnt_fx, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st_fx->element_mode, IVAS_SCE ) ) + { + Word32 lp_thresh, fd_thresh; + // PMT( "lp_thresh scaling is to be found" ) + test(); + IF( st_fx->Opt_DTX_ON && EQ_16( st_fx->dtx_sce_sba, 1 ) ) + { + lp_thresh = L_shl( 5, Q27 ); + fd_thresh = L_shl( 2, Q27 ); + } + ELSE + + { + lp_thresh = L_shl( 10, Q27 ); + fd_thresh = L_shl( 5, Q27 ); + } + + /*More conservative selection of LP-CNG for SCE*/ + if ( st_fx->cng_type == LP_CNG && ( st_fx->bckr_tilt_lt > lp_thresh ) ) + { + st_fx->cng_type = FD_CNG; + } + else if ( st_fx->cng_type == FD_CNG && ( st_fx->bckr_tilt_lt < fd_thresh ) && ( st_fx->lp_noise > L_shl( 2, Q27 ) ) ) + { + st_fx->cng_type = LP_CNG; + } + } + ELSE + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->cng_type, LP_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 589824l /*9.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) ) + { + st_fx->cng_type = FD_CNG; + move16(); + } + ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) ) + { + st_fx->cng_type = LP_CNG; + move16(); + } + } + st_fx->last_total_brate_cng = -1; + } + ELSE IF( st_fx->Opt_AMR_WB ) + { + st_fx->cng_type = LP_CNG; + move16(); + } + st_fx->active_fr_cnt_fx = add( st_fx->active_fr_cnt_fx, 1 ); + st_fx->active_fr_cnt_fx = s_min( st_fx->active_fr_cnt_fx, 200 ); + } + + /*------------------------------------------------------------------------* + * Update speech and background noise long-term energy + *------------------------------------------------------------------------*/ + IF( hDtxEnc != NULL ) + { + hDtxEnc->frame_ener_fx = L_deposit_l( 0 ); + + IF( st_fx->Opt_DTX_ON ) + { +#if 0 + Q_speech2 = add( shl( Q_speech, 1 ), 7 ); + FOR( j = 0; j < 16; j++ ) + { + L_tmp = L_mult0( *speech, *speech ); + speech++; + FOR( i = 1; i < L_FRAME / 16; i++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); +#else /* BASOP_NOGLOB */ + L_tmp = L_mac0( L_tmp, *speech, *speech ); +#endif /* BASOP_NOGLOB */ + speech++; + } + hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /*Q(-7) */ + + } +#endif + // hDtxEnc->frame_ener = sum2_f( speech, L_FRAME ); + Word16 guard_bits = find_guarded_bits_fx( L_FRAME ); + // Word16 Q_frame_ener = 2 * Q_speech; + hDtxEnc->frame_ener_fx = sum2_f_16_gb_fx( speech, L_FRAME, guard_bits ); // 2*Q_speech-guard_bits + + /* Active speech (voiced) */ + + IF( EQ_16( st_fx->clas, VOICED_CLAS ) ) + { + alpha = ALPHA_ENER_SLOW_FX; + move16(); + if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) ) + { + alpha = ALPHA_ENER_FAST_FX; + move16(); /*Q15 */ + } + + /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ + L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); + L_tmp = Mult_32_16( L_tmp, alpha ); + hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*2*Q_speech-guard_bits */ + + hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 ); + + hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ); + } + /* Background noise */ + ELSE IF( !st_fx->Opt_AMR_WB ) + { + alpha = ALPHA_ENER_SLOW_FX; + move16(); + if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) ) + { + alpha = ALPHA_ENER_FAST_FX; + move16(); + } + + /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ + L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); + L_tmp = Mult_32_16( L_tmp, alpha ); + hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); + move32(); /*2*Q_speech-guard_bits */ + + hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 ); + + hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ); + } + } + } + + /* Update of the SID counter */ + update_SID_cnt( hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB ); + + /* Update encoded bandwidth */ + test(); + test(); + IF( st_fx->Opt_DTX_ON && ( st_fx->core_brate == SID_2k40 || st_fx->core_brate == FRAME_NO_DATA ) ) + { + + st_fx->bwidth = st_fx->last_bwidth; + move16(); + test(); + if ( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) ) + { + st_fx->bwidth = st_fx->last_bwidth_cng; + move16(); + } + + test(); + test(); + IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( EQ_16( st_fx->bwidth, NB ) ) ) + { + st_fx->codec_mode = MODE1; + move16(); + reset_rf_indices_fx( st_fx ); + st_fx->Opt_RF_ON = 0; + move16(); + st_fx->rf_mode = 0; + move16(); + } + + test(); + test(); + IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) ) + { + reset_rf_indices_fx( st_fx ); + move16(); + st_fx->Opt_RF_ON = 0; + move16(); + st_fx->rf_mode = 0; + } + + /* Set and limit the encoded bandwidth */ + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + Word16 n, bits_frame_nominal; + + UWord16 lsb; + Word16 tmpbandwidthMin; + + Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + + FOR( n = 0; n < FRAME_SIZE_NB; n++ ) + { + IF( EQ_16( FrameSizeConfig[n].frame_bits, bits_frame_nominal ) ) + { + BREAK; + } + } + if ( n == FRAME_SIZE_NB ) + { + assert( !"Bitrate not supported: not part of EVS" ); + } + tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min; + if ( EQ_16( st_fx->rf_mode, 1 ) ) + { + tmpbandwidthMin = WB; + } + st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); + } + } + + return; +} /*==================================================================================*/ /* FUNCTION : dtx_fx() */ diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index b8aacc9982b3cf6430fe9286c812bb16140bd6b9..a601728279d581792ef508ec6de55c86d601b63e 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -12,8 +12,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index 0688f731132085b7655f9c11539cf3d28fda72de..0ee3c51856af219d536d57f65af0ff536d9fa766 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index b24bcd066bf9250d5e6e8fa74da46e10d76f0e67..cac1c81edd1f42f47732c45a6ee66f5c2061200d 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -8,8 +8,7 @@ #include "basop_util.h" #include "options.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------------------* diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 492dd620dec27b40671ed1f7642b6f70a24221b1..5d5ee6c48af075fa34ded5aadf29b936f275607e 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -90,7 +89,7 @@ void encod_amr_wb_fx( pt_pitch = pitch_buf; shift_wsp = add( Q_new, shift ); - Copy( st->pitch_fx, T_op, 2 ); + Copy( st->pitch, T_op, 2 ); if ( LE_16( T_op[0], PIT_MIN ) ) { T_op[0] = shl( T_op[0], 1 ); diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index 8cd87ad1038660cd250d60c41abde351c4c2bba0..3bf3db1aa705c07972ac8d67bb437604ce668cdb 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -11,8 +11,7 @@ #include "rom_com.h" #include "rom_enc.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr ); diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 1b9823e7320deb8eae7c3df67adaf7a9ab5e6f6a..8b7d12fba23ed41a6c85162c0459da449bffc0cd 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -200,7 +199,7 @@ void encod_gen_voic_fx( Scale_sig( xn_fx, L_SUBFR, shift ); *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); diff --git a/lib_enc/enc_gen_voic_rf.c b/lib_enc/enc_gen_voic_rf.c index ae4458960f4be4807d15335a2e319d749a3c707c..7c38a433dbf59f39d705f1fcd026970252dc57dc 100644 --- a/lib_enc/enc_gen_voic_rf.c +++ b/lib_enc/enc_gen_voic_rf.c @@ -40,7 +40,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * reset_rf_indices() diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index c60767394e538c16d247d2fcfa6b12cc6d1daab7..a4d506291546539e6790ade2018ec2cacb862d50 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -11,8 +11,7 @@ #include "rom_basop_util.h" //#include "basop_mpy.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index a67071533f4bb35a8ac16e624e864906431d4696..a228b0b6d8e14f86261685f6f2ddf0b4c0aec31e 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot_fx_enc.h" /*---------------------------------------------------------------------* @@ -375,7 +374,7 @@ void transf_cdbk_enc_fx( st->last_code_preq = (int16_t) code_preQ[L_SUBFR - 1]; #endif - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); + PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); /*--------------------------------------------------------------* * For inactive segments @@ -441,7 +440,7 @@ static void find_cn_fx( Copy( xn, tmp_fl + M, L_SUBFR ); tmp = 0; move16(); - preemph_fx( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); + PREEMPH_FX( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); syn_filt_s_lc_fx( 0, Ap, tmp_fl + M, tmp_fl + M, L_SUBFR ); Residu3_lc_fx( p_Aq, M, tmp_fl + M, cn, L_SUBFR, 1 ); diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index bca4d2a772d9ae6c34cc4f2c007a0f302c2e2e3a..4be45c7e9d7ca2dce71cc0f1ea4620d6df486c69 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index f8d6eb8a4e0e08a6c488a398f508f44a20a8c018..6385420fe81a161f1a934be3fe2cf9a131ddb0c0 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*======================================================================*/ @@ -266,7 +265,7 @@ void enc_pit_exc_fx( * Adaptive exc. construction *----------------------------------------------------------------*/ *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, st_fx->pitch_fx, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index 31cdc0a5c993f09dbe5fb11fc9906d3bcc3edd60..1070bcc49fbe43cab4cfecad8f46ef24462e5fd1 100644 --- a/lib_enc/enc_ppp_fx.c +++ b/lib_enc/enc_ppp_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -126,7 +125,7 @@ ivas_error encod_ppp_fx( /* last frame-end lpc and curr frame-end lpc */ IF( ( error = ppp_voiced_encoder_fx( hBstr, hSC_VBR, st_fx->bwidth, st_fx->last_coder_type_raw, st_fx->old_pitch_buf_fx, res_fx, - excQ_ppp_fx, st_fx->pitch_fx[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new ) ) != IVAS_ERR_OK ) + excQ_ppp_fx, st_fx->pitch[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/enc_prm.c b/lib_enc/enc_prm.c index d3c52faec12fd4a9189edf4cbecbd37f93af48be..7c58087d982bfd70386641a6141d4185fc129c4b 100644 --- a/lib_enc/enc_prm.c +++ b/lib_enc/enc_prm.c @@ -49,6 +49,159 @@ * write TCX mode *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void writeTCXMode( + Encoder_State *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + Word16 *nbits_start /* o : nbits start */ +) +{ + UWord16 index; + Word16 idx, start_idx; + Word16 nBits; + + IF( st->tcxonly ) + { + push_next_indice( hBstr, (UWord16) EQ_16( st->core, TCX_10_CORE ), 1 ); + + test(); + IF( EQ_16( st->clas, UNVOICED_CLAS ) ) + { + index = 0; + move16(); + } + ELSE IF( EQ_16( st->clas, VOICED_TRANSITION ) || EQ_16( st->clas, UNVOICED_TRANSITION ) ) + { + index = 1; + move16(); + } + ELSE IF( EQ_16( st->clas, VOICED_CLAS ) ) + { + index = 2; + move16(); + } + ELSE + { + index = 3; + move16(); + } + + push_next_indice( hBstr, index, 2 ); + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) + { + push_next_indice( hBstr, st->vad_flag, 1 ); + } + } + ELSE + { + IF( EQ_16( st->core, ACELP_CORE ) ) + { + /* write the RF signaling information */ + IF( EQ_16( st->rf_mode, 1 ) ) + { + /* find the section in the ACELP signaling table corresponding to bitrate */ + idx = 0; + move16(); + WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) /* total bitrate is kept at 13.2kbps */ + { + idx = add( idx, 1 ); + } + + /* retrieve the number of bits for signaling */ + idx = add( idx, 1 ); + nBits = extract_l( acelp_sig_tbl[idx] ); + + /* retrieve the signaling index */ + idx = add( idx, 1 ); + start_idx = idx; + move16(); + WHILE( NE_32( acelp_sig_tbl[idx], SIG2IND( st->coder_type, st->bwidth, st->sharpFlag, st->rf_mode ) ) ) + { + idx = add( idx, 1 ); + } + push_next_indice( hBstr, sub( idx, start_idx ), nBits ); + push_next_indice( hBstr, 0, 1 ); /* Indicate to the decoder that the core is ACELP*/ + *nbits_start = 3; + move16(); + } + ELSE + { + push_next_indice( hBstr, st->coder_type, 3 ); + } + } + ELSE + { + IF( EQ_16( st->mdct_sw, MODE1 ) ) + { + /* 2 bits instead of 3 as TCX is already signaled */ + push_next_indice( hBstr, st->hTcxCfg->coder_type, 2 ); + } + ELSE + { + IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) + { + push_next_indice( hBstr, 1, 1 ); /* TCX */ + push_next_indice( hBstr, 0, 1 ); /* not HQ_CORE */ + push_next_indice( hBstr, st->hTcxCfg->coder_type, 2 ); + } + ELSE + { + /*write the RF signaling information*/ + IF( EQ_16( st->rf_mode, 1 ) ) + { + /* find the section in the ACELP signaling table corresponding to bitrate */ + idx = 0; + move16(); + WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) + { + idx = add( idx, 1 ); + } + + /* retrieve the number of bits for signaling */ + idx = add( idx, 1 ); + nBits = extract_l( acelp_sig_tbl[idx] ); + + test(); + test(); + IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) || EQ_16( st->hTcxCfg->coder_type, GENERIC ) || EQ_16( st->hTcxCfg->coder_type, TRANSITION ) ) + { + st->sharpFlag = 1; + move16(); + } + ELSE + { + st->sharpFlag = 0; + move16(); + } + + /* retrieve the signaling index */ + idx = add( idx, 1 ); + start_idx = idx; + move16(); + WHILE( NE_32( acelp_sig_tbl[idx], SIG2IND( st->hTcxCfg->coder_type, st->bwidth, st->sharpFlag, st->rf_mode ) ) ) + { + idx = add( idx, 1 ); + } + push_next_indice( hBstr, sub( idx, start_idx ), nBits ); + push_next_indice( hBstr, 1, 1 ); /* Indicate to the decoder that the core is TCX*/ + *nbits_start = 3; + move16(); + } + ELSE + { + push_next_indice( hBstr, add( ACELP_MODE_MAX, st->hTcxCfg->coder_type ), 3 ); + } + } + } + } + } + + return; +} +#else void writeTCXMode( Encoder_State *st, /* i/o: encoder state structure */ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ @@ -180,6 +333,7 @@ void writeTCXMode( return; } +#endif /*-------------------------------------------------------------------* @@ -188,6 +342,29 @@ void writeTCXMode( * write TCX transform type *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void writeTCXWindowing( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 overlap_mode /* i : overlap mode */ +) +{ + + IF( EQ_16( overlap_mode, MIN_OVERLAP ) ) + { + push_next_indice( hBstr, 2, 2 ); + } + ELSE IF( EQ_16( overlap_mode, HALF_OVERLAP ) ) + { + push_next_indice( hBstr, 3, 2 ); + } + ELSE + { + push_next_indice( hBstr, 0, 1 ); + } + + return; +} +#else void writeTCXWindowing( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const int16_t overlap_mode /* i : overlap mode */ @@ -209,6 +386,7 @@ void writeTCXWindowing( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index 93b4698fc45eab10263473af9848a73e42b6f1ed..f59fdf08f3b96ee1a2136183fb6f6911e167d742 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -12,8 +12,7 @@ #include "rom_com.h" #include "stl.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -301,7 +300,7 @@ void enc_prm_fx( move16(); move16(); j = 0; - nbits_start = hBstr->nb_bits_tot_fx; + nbits_start = hBstr->nb_bits_tot; /*--------------------------------------------------------------------------------* @@ -514,7 +513,7 @@ void enc_prm_fx( st->glr_reset = 0; move16(); - nbits_header = sub( hBstr->nb_bits_tot_fx, nbits_start ); + nbits_header = sub( hBstr->nb_bits_tot, nbits_start ); /*--------------------------------------------------------------------------------* @@ -744,7 +743,7 @@ void enc_prm_fx( IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); } } - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); if ( EQ_16( st->rf_mode, 1 ) ) { total_nbbits = add( total_nbbits, st->rf_target_bits_write ); @@ -798,7 +797,7 @@ void enc_prm_fx( j = 0; move16(); - nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); test(); IF( st->enablePlcWaveadjust && k ) @@ -878,7 +877,7 @@ void enc_prm_fx( } j = add( j, NPRM_CTX_HM ); - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) ); @@ -903,7 +902,7 @@ void enc_prm_fx( *--------------------------------------------------------------------------------*/ - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index a0a9ff9021f03f4780bd59d0bdeb0f1da3c25a45..d3127ccda1e79619dae577f0381a8fff783ef81b 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*=================================================================================*/ diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index c67a5781e7cef9d19972fe81009a0171e68044d5..981d02a868bfe60a1a220de6e22de478ff260342 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index f14e0b407ae8430d009ff205bf3abd344bb2e1b3..4bd16df2e21b8f85a1bf87ca66e6e568b0ef80fd 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -9,8 +9,7 @@ #include "rom_enc.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * est_energy_fx() diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index 308f3ec4eedc354821a95790f03e29a1057e6d93..f1cc5460619b07d9c50026ef6388f2a21bcbb1a1 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -382,10 +381,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) { #ifndef IVAS_CODE_BITSTREAM - IF( hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( hBstr->ind_list[i].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[i].nb_bits ); - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); + hBstr->ind_list[i].nb_bits = -1; move16(); } #else @@ -394,10 +393,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit } #ifndef IVAS_CODE_BITSTREAM - IF( hBstr->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) + IF( hBstr->ind_list[IND_ES_PRED].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_ES_PRED].nb_bits ); - hBstr->ind_list_fx[IND_ES_PRED].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); + hBstr->ind_list[IND_ES_PRED].nb_bits = -1; move16(); } #else diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 53b52d3dc74b7021ad5530434875d8e0bb6fcf7a..40b1d7b56f54d06f427ef151a0f3c44a7229ca4b 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -7,8 +7,7 @@ #include "prot.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ #include "prot_fx_enc.h" @@ -138,7 +137,7 @@ ivas_error evs_enc_fx( *----------------------------------------------------------------*/ /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); @@ -301,7 +300,7 @@ ivas_error evs_enc_fx( #ifndef FIX_I4_OL_PITCH IF( EQ_16( st->core, HQ_CORE ) ) { - Copy( pitch_orig, st->pitch_fx, 3 ); /* original open-loop pitch values might be altered in core_acelp_tcx20_switching_fx() */ + Copy( pitch_orig, st->pitch, 3 ); /* original open-loop pitch values might be altered in core_acelp_tcx20_switching_fx() */ } #endif } @@ -328,7 +327,7 @@ ivas_error evs_enc_fx( bwe_exc_extended, voice_factors, pitch_buf, vad_hover_flag, &Q_new, &shift ); #ifndef FIX_I4_OL_PITCH - Copy( pitch_orig, st->pitch_fx, 3 ); /* populate the original OL pitch values back */ + Copy( pitch_orig, st->pitch, 3 ); /* populate the original OL pitch values back */ #endif /*---------------------------------------------------------------------* @@ -410,13 +409,13 @@ ivas_error evs_enc_fx( { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ tmp = add( get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ), sub( st->rf_target_bits_write, st->rf_mode ) ); - padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot_fx ), tmp ); + padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot ), tmp ); } ELSE { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ tmp = sub( st->rf_target_bits_write, st->rf_mode ); - padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot_fx, tmp ) ); + padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot, tmp ) ); } FOR( i = 0; i < padBits; i++ ) diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index a24b15f881f3309eb25dcf99a7397e8b0767376b..ee7c572c007f2ff86af1fc1530307bca09676481 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -9,8 +9,7 @@ //#include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -75,9 +74,11 @@ void core_signal_analysis_high_bitrate_fx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; #ifndef IVAS_CODE + /* dummy */ (void) vad_hover_flag; (void) last_element_mode; #endif + #ifdef IVAS_CODE if ( NE_16( last_element_mode, st->element_mode ) ) { @@ -175,9 +176,9 @@ void core_signal_analysis_high_bitrate_fx( { lsp[0] = lsp_new; lsp[1] = lsp_mid; - alw_pitch_lag_12k8[0] = st->pitch_fx[0]; + alw_pitch_lag_12k8[0] = st->pitch[0]; move16(); - alw_pitch_lag_12k8[1] = st->pitch_fx[1]; + alw_pitch_lag_12k8[1] = st->pitch[1]; move16(); alw_voicing[0] = st->voicing_fx[0]; move16(); @@ -552,67 +553,71 @@ void core_signal_analysis_high_bitrate_fx( { set_f( &mdst_spectrum[frameno][MCT_LFE_MAX_LINE], 0.f, L_subframe - MCT_LFE_MAX_LINE ); } -#endif } - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, - st->hTcxCfg->tcx_coded_lines, - transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), - spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns_fx[frameno], NULL ); +#endif + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + test(); + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, + st->hTcxCfg->tcx_coded_lines, + transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), + spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); #ifdef IVAS_CODE - IF( st->hTcxCfg->fIsTNSAllowed ) + IF( st->hTcxCfg->fIsTNSAllowed ) #endif + { + EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], + param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); + } + IF( EQ_16( transform_type[frameno], TCX_5 ) ) + { + /* group sub-windows: interleave bins according to their frequencies */ + FOR( i = 0; i < tcx5SizeFB; i++ ) { - EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], - param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); - } - IF( EQ_16( transform_type[frameno], TCX_5 ) ) - { - /* group sub-windows: interleave bins according to their frequencies */ - FOR( i = 0; i < tcx5SizeFB; i++ ) - { - interleaveBuf[2 * i] = spectrum[frameno][i]; - move32(); - interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; - move32(); - } - Copy32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); + interleaveBuf[2 * i] = spectrum[frameno][i]; + move32(); + interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; + move32(); } + MVR2R_WORD32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); + } - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ + /*--------------------------------------------------------------* + * LPC analysis + *---------------------------------------------------------------*/ #ifdef IVAS_CODE - IF( st->tcxonly ) + IF( st->tcxonly ) #endif - { - HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], - shr( L_frame, sub( nSubframes, 1 ) ), r, M ); - - FOR( i = 0; i <= M; i++ ) - { - move16(); - move16(); - r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] ); - } - - adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - - E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, epsP, M, NULL ); + { + HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], + shr( L_frame, sub( nSubframes, 1 ) ), r, M ); - E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); - } - IF( st->igf ) + FOR( i = 0; i <= M; i++ ) { - ProcessIGF_fx( st->hIGFEnc, st, spectrum[frameno], &( spectrum_e[frameno] ), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns_fx[frameno], ( st->last_core == ACELP_CORE ), frameno ); + move16(); + move16(); + r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] ); } - /* Copy memory */ - mvr2r_Word16( lsp_new, st->lspold_enc_fx, M ); + adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); + + E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, epsP, M, NULL ); + + E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); } + IF( st->igf ) + { + ProcessIGF_fx( st->hIGFEnc, st, spectrum[frameno], &( spectrum_e[frameno] ), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns[frameno], ( st->last_core == ACELP_CORE ), frameno ); + } + + /* Copy memory */ + MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); } } + + return; +} diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index fad93012f130ac1cbcbb79d506166f1c0ef56394..38803594fbbff31f413528e27f94f77be9fa3458 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -41,7 +41,9 @@ #include "rom_enc.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "stat_enc.h" #include "wmc_auto.h" @@ -1036,7 +1038,19 @@ void FdCngEncodeMDCTStereoSID( /* M/S transform on log envelopes */ if ( is_inp_ms == 0 ) { +#ifndef IVAS_FLOAT_FIXED convertToMS( N, ms_ptr[0], ms_ptr[1], 0.5f ); +#else + Word32 ms_ptr_fx[2][NPART]; + Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1; + floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N ); + floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N ); + + convertToMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q30 ); + + fixedToFloat_arrL( ms_ptr_fx[0], ms_ptr[0], q, N ); + fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, N ); +#endif } side_energy = sum2_f( ms_ptr[1], N ); @@ -1125,7 +1139,19 @@ void FdCngEncodeMDCTStereoSID( /* undo M/S */ if ( is_inp_ms == 0 ) { +#ifndef IVAS_FLOAT_FIXED convertToMS( N, ms_ptr[0], ms_ptr[1], 1.0f ); +#else + Word32 ms_ptr_fx[2][NPART]; + Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1; + floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N ); + floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N ); + + convertToMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q31 ); + + fixedToFloat_arrL( ms_ptr_fx[0], ms_ptr[0], q, N ); + fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, N ); +#endif } /* Compute gain against original left and right channels */ @@ -1260,7 +1286,19 @@ void FdCngEncodeDiracMDCTStereoSID( } /* M/S transform on log envelopes */ +#ifndef IVAS_FLOAT_FIXED convertToMS( N[0], ms_ptr[0], ms_ptr[1], 0.5f ); +#else + Word32 ms_ptr_fx[2][NPART]; + Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N[0] ), Q_factor_arrL( ms_ptr[1], N[0] ) ) - 1; + floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N[0] ); + floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N[0] ); + + convertToMS_fx( N[0], ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q30 ); + + fixedToFloat_arrL( ms_ptr_fx[0], ms_ptr[0], q, N[0] ); + fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, N[0] ); +#endif E[0] = sum_f( ms_ptr[0], N[0] ); @@ -1309,7 +1347,18 @@ void FdCngEncodeDiracMDCTStereoSID( gain[1] = gain[0]; /* undo M/S */ +#ifndef IVAS_FLOAT_FIXED convertToMS( NPART, ms_ptr[0], ms_ptr[1], 1.0f ); +#else + q = s_min( Q_factor_arrL( ms_ptr[0], NPART ), Q_factor_arrL( ms_ptr[1], NPART ) ) - 1; + floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, NPART ); + floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, NPART ); + + convertToMS_fx( NPART, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q31 ); + + fixedToFloat_arrL( ms_ptr_fx[0], ms_ptr[0], q, NPART ); + fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, NPART ); +#endif /* restore channel noise envelopes */ for ( ch = 0; ch < CPE_CHANNELS; ch++ ) diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 410cec20268f1fd2f96e62991231942f8dc75e8b..33f693d4b0ea22a9d2ea1f7e1e3c71582d9a1afc 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -12,8 +12,7 @@ #include "rom_com.h" #include "rom_enc.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot_fx_enc.h" #include "basop_util.h" #include "rom_basop_util.h" diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index 14de5fe44c22a797af3d524c23158649469ee925..1fb28ca9752e1f632da001ddde6abae13863cd33 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -4,8 +4,7 @@ #include #include "options.h" /* Compilation switches */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "cnst.h" /* Common constants */ #include "basop_util.h" diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 11106323e07568151398a0b2c69e28ca00bc91ed..f0c39eee21dafe9fe30de6bee54dbdd2d4a6854c 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index dbe7714c96f22fe2268938044bb2eea1b4cf5c7c..778e7b51a80dbabf5cc77cdc978df6cfbed03b26 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -477,22 +476,27 @@ Word16 find_uv_fx( /* o : coding type test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ -#else /* BASOP_NOGLOB */ - if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ -#endif -#ifdef BASOP_NOGLOB - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ #else + if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */ ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ #endif - ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); diff --git a/lib_enc/find_wsp.c b/lib_enc/find_wsp.c index d38fd99d8dc2a254cdfc47249842ae50ac5d6cf2..97df5db897a0ec12625d376e68a48b5cd4fb4554 100644 --- a/lib_enc/find_wsp.c +++ b/lib_enc/find_wsp.c @@ -39,13 +39,12 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" - +#include "prot_fx.h" /*-------------------------------------------------------------------* * find_wsp() * * Compute weighted speech used in open-loop pitch search *-------------------------------------------------------------------*/ - void find_wsp( const int16_t L_frame, /* i : length of the frame */ const int16_t L_subfr, /* i : length of subframe */ @@ -93,3 +92,47 @@ void find_wsp( return; } +void ivas_find_wsp( + const Word16 L_frame, /* i : length of the frame */ + const Word16 L_subfr, /* i : length of subframe */ + const Word16 nb_subfr, /* i : number of subframes */ + const Word16 *A_fx, /* i : A(z) filter coefficients */ + Word16 *Aw_fx, /* o : weighted A(z) filter coefficients */ + const Word16 *speech_fx, /* i : pointer to the denoised speech frame */ + const Word16 tilt_fact, /* i : tilt factor */ + Word16 *wsp_fx, /* o : poitnter to the weighted speech frame */ + Word16 *mem_wsp_fx, /* i/o: W(Z) denominator memory */ + const Word16 gamma, /* i : weighting factor */ + const Word16 L_look /* i : look-ahead */ +) +{ + Word16 *p_Aw_fx, tmp_fx; + Word16 i_subfr; + + + /*-----------------------------------------------------------------* + * Compute weighted A(z) unquantized for subframes + *-----------------------------------------------------------------*/ + weight_a_subfr_fx( nb_subfr, A_fx, Aw_fx, gamma, M ); + + /*-----------------------------------------------------------------* + * Compute weighted speech for all subframes + *-----------------------------------------------------------------*/ + p_Aw_fx = Aw_fx; + for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr ) + { + Residu3_fx( p_Aw_fx, &speech_fx[i_subfr], &wsp_fx[i_subfr], L_subfr, 0 ); + p_Aw_fx += ( M + 1 ); + } + p_Aw_fx -= ( M + 1 ); + + /*-----------------------------------------------------------------* + * Weighted speech computation is extended on look-ahead + *-----------------------------------------------------------------*/ + + deemph_fx( wsp_fx, tilt_fact, L_frame, mem_wsp_fx ); + Residu3_fx( p_Aw_fx, &speech_fx[L_frame], &wsp_fx[L_frame], L_look, 0 ); + tmp_fx = *mem_wsp_fx; + deemph_fx( &wsp_fx[L_frame], tilt_fact, L_look, &tmp_fx ); + return; +} diff --git a/lib_enc/find_wsp_fx.c b/lib_enc/find_wsp_fx.c index 21be0073b0ab8b58cd9c9e819f7cb9cc82674491..de81f19214e626801376295422c993120a79672c 100644 --- a/lib_enc/find_wsp_fx.c +++ b/lib_enc/find_wsp_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index fb0930579bec9e9de0543202c3904b17363e23e1..c7fa5eb1cab5d0ca8b4c15038cb232529d6ffc05 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -10,8 +10,7 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index ad366278c3be1641c8fd0a5147debcb1c9dae785..abb66a8b899578dc0ad57e6b4db41bedec9d0e72 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 56ac45f26aa4e9eb1f5ac9b00f35d1a6afab918b..57a336ec25f80eb161e363fbd6b232fe4ef512f7 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_com.h" /* Static table prototypes */ #include "rom_enc.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ //#include "basop_mpy.h" diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 1a1f1debfec6e8d3a4f339094832cce889f6131b..73a5c35ea29ce16c5128b2b367ca005e69b75671 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -37,8 +37,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index a0396a97f31b3456cce21c521bf7b1f67653007b..e2d1f4aa9233138ef1fddfc9d493a4d14466b89d 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -303,7 +302,7 @@ void encod_audio_fx( *--------------------------------------------------------------------------------------*/ /* Find the current total number of bits used */ - tmp_nb_bits_tot = hBstr->nb_bits_tot_fx; + tmp_nb_bits_tot = hBstr->nb_bits_tot; move16(); diff --git a/lib_enc/guided_plc_enc_fx.c b/lib_enc/guided_plc_enc_fx.c index aebdfb748e773b68f5be71bb97180bf9e41c41a5..6470e0a3c88fa8bcf420af79d496ecb0f73d570b 100644 --- a/lib_enc/guided_plc_enc_fx.c +++ b/lib_enc/guided_plc_enc_fx.c @@ -7,8 +7,7 @@ #include "options.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "basop_util.h" diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index 0fa53be5155d81f61b1ec4cf268ffe646901caa7..7c2060fa8663df927207db78e0a59227df997424 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" #include "cnst.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index ebf3855ee9c41c5ca56521ee82bdb792addb3648..842f2029ed253cfdb0bb3dc8c0444e292b5c69cd 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 700ac87264c8fafaa7a39f3f6d14c91a04baff6b..55e37a3b55db153f6adb30bd2d56a16434d451ba 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------------- @@ -147,7 +146,7 @@ void hq_core_enc_fx( } #ifndef ADD_IVAS_HQ_CODE /* subtract signalling bits */ - num_bits = sub( num_bits, hBstr->nb_bits_tot_fx ); + num_bits = sub( num_bits, hBstr->nb_bits_tot ); #endif direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode ); diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index d64685ddabf1384cbbb4c978b770bd12c4cd873a..bfb9836412263025dc8ff7188884c53698fba089 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_enc.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------------------* diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 3049e6c21c37a4dcf40999d6199579ff7d3dc478..ca7d941eecb1ed2e97a238e9382ab4e5cf993f99 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index d1f3520570e646758db955b49f76eaa71205192b..85827b9a1d619dfb291e469458548a84271758f1 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -9,8 +9,7 @@ #include "rom_enc.h" //#include "basop_mpy.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 107905ccbff764c39835817144fb89492be5432d..b2adfef24cd5adf5d658e1900c966b5bc79a4520 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #define HVQ_ENC_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 230df02486440b6009c3e125876c2ce3c6e0ec56..dcc61747dc51197603fc56a9a3f29c056f659c32 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -43,14 +43,37 @@ #include "cnst.h" #include "stat_enc.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#include "prot_fx.h" +#endif // IVAS_FLOAT_FIXED +#define INV_Log2_10_Q15 9864 /*1/log2(10) in Q15*/ +#define INV_Log2_e_Q15 22713 /*1/log2(e) in Q15*/ /*-------------------------------------------------------------------* * IGF_write_bit() * * write single bit to stream *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void IGF_write_bit( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /* i/o: bit counter */ + const Word16 value /* i : value */ +) +{ + IF( hBstr ) + { + push_next_indice( hBstr, value, 1 ); + } + + ( *bitCount ) = add( ( *bitCount ), 1 ); + move16(); + return; +} +#else static void IGF_write_bit( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t *bitCount, /* i/o: bit counter */ @@ -67,13 +90,36 @@ static void IGF_write_bit( return; } +#endif /*-------------------------------------------------------------------* * IGF_write_bits() * * write bits to stream *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void IGF_write_bits( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *bitCount, /* i/o: bit counter */ + const Word16 value, /* i/o: value */ + Word16 bits /* i : number of bits */ +) +{ + WHILE( bits-- ) + { + IF( s_and( value, shl( 1, bits ) ) == 0 ) + { + IGF_write_bit( hBstr, bitCount, 0 ); + } + ELSE + { + IGF_write_bit( hBstr, bitCount, 1 ); + } + } + return; +} +#else static void IGF_write_bits( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t *bitCount, /* i/o: bit counter */ @@ -88,6 +134,7 @@ static void IGF_write_bits( return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -97,6 +144,67 @@ static void IGF_write_bits( *-------------------------------------------------------------------*/ /*! r: crest factor */ +#ifdef IVAS_FLOAT_FIXED +static Word16 IGF_getCrest_new_fx( + const Word16 *logSpec, /* i : power spectrum */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + Word16 *crest_exp /*Stores the exponent of the result(return value)*/ +) +{ + Word16 i; + Word16 x; + Word32 x_eff; + Word16 x_max; + Word16 exp; + Word16 temp; + Word16 temp_e; + Word16 crest; /*1.0f in Q15*/ + x_eff = 0; + x_max = 0; + exp = 0; + temp = 0; + crest = 32767; /*1.0f in Q15*/ + move32(); + move16(); + move16(); + move16(); + move16(); + + FOR( i = start; i < stop; i++ ) + { + x = logSpec[i]; + move16(); + x_eff = L_add( x_eff, L_mult0( x, x ) ); + + IF( GT_16( x, x_max ) ) + { + x_max = x; + move16(); + } + } + + x_eff = BASOP_Util_Divide3216_Scale( x_eff, sub( stop, start ), &temp_e ); + temp_e = add( temp_e, 16 ); /*exp += 31 - 15 + 16(because x_eff is word32)*/ + temp = Sqrt16( extract_l( x_eff ), &temp_e ); + + IF( x_eff > 0 && x_max > 0 ) + { + temp = BASOP_Util_Divide1616_Scale( x_max, temp, &exp ); + exp = add( exp, sub( 15, temp_e ) ); + IF( exp < 0 ) + { + temp = shl( temp, exp ); + exp = 0; + move16(); + } + crest = s_max( shl_sat( 1, sub( 15, exp ) ), temp ); + } + *crest_exp = exp; + move16(); + return crest; +} +#endif static float IGF_getCrest_new( const int16_t *logSpec, /* i : power spectrum */ const int16_t start, /* i : start subband index */ @@ -138,6 +246,61 @@ static float IGF_getCrest_new( *-------------------------------------------------------------------*/ /*! r: SFM value */ +#ifdef IVAS_FLOAT_FIXED +static Word16 IGF_getSFM_new_fx( + const Word32 *powerSpectrum, /* i : power spectrum */ + const Word16 *logSpec, /* i : log of power spectrum */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + Word16 e_ps /*Stores exp related to power spectrum*/ +) +{ + Word16 n; + Word16 i; + Word16 num; + Word32 denom; + Word16 numf; + Word32 tmp; + Word16 sfm; + Word16 sfm_e; + Word16 denom_e; + Word16 numf_e; /*stores exponent for numf*/ + Word16 tmp_e; + + num = 0; + denom = 1; + denom_e = 31; + sfm = 1; + move16(); + move32(); + move16(); + move16(); + + FOR( i = start; i < stop; i++ ) + { + tmp = powerSpectrum[i]; + n = logSpec[i /*-start*/]; + move32(); + move16(); + num = add( num, n ); + denom = BASOP_Util_Add_Mant32Exp( tmp, e_ps, denom, denom_e, &denom_e ); + } + + numf = BASOP_Util_Divide1616_Scale( num, sub( stop, start ), &numf_e ); + denom = BASOP_Util_Divide3216_Scale( denom, sub( stop, start ), &tmp_e ); + denom_e = add( add( denom_e, tmp_e ), 1 ); /*denom_e+tmp_e-15 +16(because type of denom is word32)*/ + + IF( denom != 0 ) + { + tmp = BASOP_util_Pow2( L_add( numf, shl_sat( 1, sub( 14, numf_e ) ) ), 16 + numf_e, &tmp_e ); + sfm = BASOP_Util_Divide3232_Scale( tmp, denom, &sfm_e ); + sfm_e = add( sfm_e, sub( tmp_e, denom_e ) ); + sfm = shl_sat( extract_l( L_min( sfm, L_shl( 1, 15 - sfm_e ) ) ), sfm_e ); + } + + return sfm; +} +#endif static float IGF_getSFM_new( const float *powerSpectrum, /* i : power spectrum */ const int16_t *logSpec, /* i : log of power spectrum */ @@ -184,6 +347,64 @@ static float IGF_getSFM_new( *-------------------------------------------------------------------*/ /*! r: spectral tilt value */ +#if 0 +#ifdef IVAS_FLOAT_FIXED +static Word16 IGF_getTilt_fx( + const Word32 *powerSpectrum, /* i : energies */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + Word16 q_powerSpectrum, /*Stores q reated to powerSpectrum*/ + Word16 *slope_e /*stores the exponent of returned slope value*/ +) +{ + Word16 i; + Word16 x; + Word16 width; + Word32 y; + Word32 mean_x, mean_y, mean_xy, mean_x2; + Word32 max_mean_x_e; + Word16 mean_x_e, mean_y_e, mean_xy_e, mean_x2_e; + Word16 slope; + Word16 slope_e; + + x = 1; + mean_x = mean_y = mean_xy = mean_x2 = 0; + move16(); + move32(); + move32(); + move32(); + move32(); + + width = sub( stop, start ); + for ( i = start; i < stop; i++ ) + { + mean_x = L_add( mean_x, x ); /*Q0*/ + mean_x2 = L_add( mean_x2, L_mult0( x, x ) ); /*Q0*/ + y = imult3216( Mult_32_16( L_add( BASOP_Util_Log2( L_max( L_shl( 1, q_powerSpectrum ), powerSpectrum[i] ) ), L_shl( sub( 31, q_powerSpectrum ), Q25 ) ) /*Q25*/, INV_Log2_10_Q15 ) /*Q25*/, 20 ); /*Q25*/ + mean_y = L_add( mean_y, y ); /*Q25*/ + mean_xy = L_add( mean_xy, Mult_32_16( y, x ) ); /*Q25+0-Q15=>Q10*/ + + x = add( x, 1 ); /*Q0*/ + } + mean_y = BASOP_Util_Divide3216_Scale( mean_y, width, &mean_y_e ); + mean_y_e = add( mean_y_e, -9 ) /*6 -15*/; + mean_x = BASOP_Util_Divide3216_Scale( mean_x, width, &mean_x_e ); + mean_x_e = add( mean_x_e, 16 ) /*31 -15*/; + mean_xy = BASOP_Util_Divide3216_Scale( mean_xy, width, mean_xy_e ); + mean_xy_e = add( mean_xy_e, 6 ) /*21 -15*/; + mean_x2 = BASOP_Util_Divide3216_Scale( mean_x2, width, mean_x2_e ); + mean_x2_e = add( mean_x2_e, 16 ) /*31 -15*/; + max_mean_x_e = s_max( mean_x_e, s_max( mean_xy_e, mean_x2_e ) ); + mean_x = shr( mean_x, sub( mean_x_e, max_mean_x_e ) ); /*mean_x_e=max_mean_x_e*/ + mean_xy = shr( mean_xy, sub( mean_xy_e, max_mean_x_e ) ); /*mean_xy_e=max_mean_x_e*/ + mean_x2 = shr( mean_x2, sub( mean_x2_e, max_mean_x_e ) ); /*mean_x2_e=mean_x2_e*/ + slope = BASOP_Util_Divide3232_Scale( L_mult0( extract_l( L_sub( mean_xy, mean_x ) ), extract_l( mean_y ) ) /*max_mean_x_e+mean_y_e*/, L_mult0( extract_l( L_sub( mean_x2, mean_x ) ), extract_l( mean_x ) ) /*2*max_mean_x_e*/, slope_e ); /*q_powerSpectrum-15*/ + *slope_e = add( *slope_e, sub( mean_y_e, max_mean_x_e ) ); + move16(); + return slope; +} +#endif +#endif static float IGF_getTilt( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ @@ -228,6 +449,90 @@ static float IGF_getTilt( *-------------------------------------------------------------------*/ /*! r: spectral tilt value */ +#ifdef IVAS_FLOAT_FIXED +/* Returns value with exponent as 9 and Q as 22*/ +static Word32 IGF_getTNR_fx( + const Word32 *powerSpectrum, /* i : energies */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + const Word16 adap, /* i : SFB width adaptation */ + Word16 e_ps, /*Stores exponent for powerSpectrum*/ + Word16 e_adap /*Stores exponent for adap*/ +) +{ + Word16 i; + Word16 width; + Word32 avg; + Word32 tonal; + Word16 tonal_e; /* holds exp for tonal*/ + Word32 noise; + Word16 noise_e; /* holds exp for noise*/ + Word32 tonalToNoise; + Word32 rootSpec[300]; + Word16 rootSpec_e[300]; /*rootSpec_e[i] holds exp for rootSpec[i]*/ + Word16 avg_e; /* holds exp for avg*/ + Word16 tmp_e; + avg = 0; + tonal = 0; + noise = EPSILON_FX; + tonal_e = 0; + noise_e = 0; + avg_e = 0; + tmp_e = 0; + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + + set32_fx( rootSpec, 0, 300 ); + set16_fx( rootSpec_e, 0, 300 ); + + width = sub( stop, start ); + FOR( i = start; i < stop; i++ ) + { + rootSpec_e[sub( i, start )] = e_ps; + move16(); + rootSpec[sub( i, start )] = Sqrt32( powerSpectrum[i], &rootSpec_e[sub( i, start )] ); /*rootSpec[i - start] = sqrtf( powerSpectrum[i] );*/ + move32(); + avg = BASOP_Util_Add_Mant32Exp( avg, avg_e, rootSpec[sub( i, start )], rootSpec_e[sub( i, start )], &avg_e ); /*avg += rootSpec[i - start];resultant exponent is avg_e*/ + } + avg = BASOP_Util_Divide3216_Scale( avg, width, &tmp_e ); /*avg /= width;*/ + avg_e = add( 16, sub( add( avg_e, tmp_e ), 15 ) ); + + FOR( i = start; i < stop; i++ ) + { + Word16 normSpec_e; /*stores resultant exponent for normSpec*/ + Word16 normSpec = BASOP_Util_Divide3232_Scale( rootSpec[sub( i, start )], avg, &normSpec_e ); /*rootSpec[i - start] / avg;*/ + normSpec_e = add( normSpec_e, sub( rootSpec_e[sub( i, start )], avg_e ) ); + IF( GT_32( normSpec, L_add( L_shl( 1, sub( 15, normSpec_e ) ), L_shl( adap, sub( e_adap, normSpec_e ) ) ) ) ) + { + tonal = BASOP_Util_Add_Mant32Exp( tonal, tonal_e, rootSpec[sub( i, start )], rootSpec_e[sub( i, start )], &tonal_e ); /*tonal += rootSpec[i - start];*/ + } + ELSE IF( LT_32( normSpec, L_shl( 1, sub( 15, normSpec_e ) ) ) ) + { + noise = BASOP_Util_Add_Mant32Exp( noise, noise_e, rootSpec[sub( i, start )], rootSpec_e[sub( i, start )], &noise_e ); /*noise += rootSpec[i - start];*/ + } + } + + /*tonalToNoise=20.f * log10f( max( 1e-018f, tonal / noise ) )*/ + Word16 temp = BASOP_Util_Divide3232_Scale( tonal, noise, &tmp_e ); /*tonal / noise*/ + tmp_e = add( tmp_e, sub( tonal_e, noise_e ) ); + IF( GE_16( temp, 1 ) ) + { + tonalToNoise = L_shr( imult3216( Mult_32_16( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), Q25 ) ) /*Q25*/, INV_Log2_10_Q15 ) /*25+15-15*/, 20 ) /*25*/, 3 ); /*Q22*/ + } + ELSE + { + tonalToNoise = -1509949440; /*-360.f Q22*/ + move32(); + } + + return tonalToNoise; +} +#endif // IVAS_FLOAT_FIXED static float IGF_getTNR( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ @@ -279,7 +584,7 @@ static float IGF_getTNR( *-------------------------------------------------------------------*/ /*! r: crest factor */ -static float IGF_getCrest( +static float IGF_getCrest_ivas( const float *powerSpectrum, /* i : power spectrum */ const int16_t start, /* i : start subband index */ const int16_t stop /* i : stop subband index */ @@ -320,7 +625,7 @@ static float IGF_getCrest( *-------------------------------------------------------------------*/ /*! r: SFM value */ -static float IGF_getSFM( +static float IGF_getSFM_ivas( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ const int16_t stop /* i : stop subband index */ @@ -595,11 +900,495 @@ static void IGF_CalculateEnvelope( /*-------------------------------------------------------------------* - * IGF_CalculateStereoEnvelope() + * IGF_CalculateStereoEnvelope_fx() * * envelope estimation + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void IGF_CalculateStereoEnvelope_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + const Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ + Word16 pMDCTSpectrum_e, /* i : exponent for pMDCTSpectrum_fx */ + const Word32 *pMDCTSpectrumMsInv_fx, /* i : MDCT spectrum */ + Word16 pMDCTSpectrumMsInv_e, /* i : expontent for pMDCTSpectrumMsInv_fx */ + const Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ + const Word32 *pPowerSpectrumMsInv_fx, /* i : inverse power spectrum */ + Word16 pPowerSpectrumMsInv_e, /* i : exponent for pPowerSpectrumMsInv_fx */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word16 coreMsMask[N_MAX], /* i : line wise ms Mask */ + const Word16 isTransient, /* i : flag indicating if transient is detected */ + const Word16 last_core_acelp /* i : indicator if last frame was ACELP core */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 *swb_offset; + Word16 sfb; /* this is the actual scalefactor band */ + Word16 width; /* this is width in subbands of the actual scalefactor band */ + Word16 tile_idx; + Word16 strt_cpy; + Word32 gain_fx; /* the gain which has to be applied to the source tile to get the destination energy */ + Word16 sb; + Word16 sfbEnergyR_fx; + Word32 sfbEnergyC_fx; /* the energy of the destination region of the tile */ + Word32 sfbEnergyTileR_fx; + Word32 sfbEnergyTileC_fx; /* the energy of the destination region of the tile */ + Word16 tmp, x, y; + Word16 mean_x_fx, mean_y_fx; + Word32 mean_xy_fx, mean_x2_fx; + Word16 slope_fx; + Word16 tmp_tb_fx; + Word16 tmp_sb_fx; + Word16 sfbCnt; + Word32 tileSrcSpec_fx[MAX_IGF_SFB_LEN]; + Word16 sfm; + Word16 crest; + Word16 temp; + Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ + Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ + Word16 tileSrcSpec_e; /*Exponent for tileSrcSpec_fx*/ + Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR_fx*/ + Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC_fx*/ + Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC_fx*/ + Word16 gain_e; /*exponent for gain_fx*/ + Word16 crest_exp; /*stores exponent for output from crest*/ + Word16 sfm_exp; /*stores exponent for ouput from sfm*/ + Word16 tmp_tb_e; /*Stores exponent for tmp_tb_fx*/ + Word16 tmp_sb_e; /*stores exponent for tmp_sb_fx*/ + Word16 slope_e; /*stores exponent for slope_fx*/ + Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ + Word16 tmp_e; + hPrivateData = &hIGFEnc->igfData; + hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; + swb_offset = hGrid->swb_offset; + move16(); + + IF( NE_16( igfGridIdx, IGF_GRID_LB_NORM ) ) + { + FOR( sfbCnt = 0; sfbCnt < sub( hGrid->sfbWrap[hGrid->nTiles], hGrid->sfbWrap[0] ); sfbCnt++ ) + { + /* reset filter */ + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfbCnt] = 0; /* Exponent is hPrivateData->sfb_tb_e*/ + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfbCnt] = 0; /* Exponent is hPrivateData->sfb_tb_e*/ + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfbCnt] = 0; /* Exponent is hPrivateData->sfb_sb_e*/ + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfbCnt] = 0; /* Exponent is hPrivateData->sfb_sb_e*/ + hPrivateData->sfb_sb_e[sfbCnt] = 0; + hPrivateData->sfb_tb_e[sfbCnt] = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + } + + IF( pPowerSpectrum_fx ) + { + FOR( sb = hGrid->sbWrap[0]; sb < swb_offset[hGrid->sfbWrap[hGrid->nTiles]]; sb++ ) + { + /*hPrivateData->logSpec[sb] = max( 0, (int16_t) ( logf( max( FLT_MIN, pPowerSpectrum[sb] ) ) * INV_LOG_2 ) );*/ + IF( LE_32( 1, pPowerSpectrum_fx[sb] ) ) + { + hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e, Q25 ) ), 25 ) ); + } + ELSE + { + hPrivateData->logSpec[sb] = 0; /*max(0,-126) is always 0*/ + } + move16(); + } + } + + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) + { + strt_cpy = hGrid->sbWrap[tile_idx]; + move16(); + + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) + { + width = sub( swb_offset[sfb + 1], swb_offset[sfb] ); + sfbEnergyTileR_fx = EPSILON_FX; + sfbEnergyTileC_fx = EPSILON_FX; + sfbEnergyC_fx = EPSILON_FX; + sfbEnergyTileR_e = 0; + sfbEnergyTileC_e = 0; + sfbEnergyC_e = 0; + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); + IF( pPowerSpectrum_fx ) + { + Word16 final_exp; + Word16 norm_exp; + Word32 scaled_value; + tmp = strt_cpy; + move16(); + + FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) + { + IF( NE_16( coreMsMask[sb], coreMsMask[strt_cpy] ) ) + { + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e, &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + norm_exp = norm_l( pMDCTSpectrumMsInv_fx[strt_cpy] ); + final_exp = sub( pMDCTSpectrumMsInv_e, norm_exp ); + scaled_value = L_shl( pMDCTSpectrumMsInv_fx[strt_cpy], norm_exp ); + sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], pPowerSpectrumMsInv_e, &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[sub( strt_cpy, tmp )] = pPowerSpectrumMsInv_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e = pPowerSpectrumMsInv_e; + } + ELSE + { + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e, &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + norm_exp = norm_l( pMDCTSpectrum_fx[strt_cpy] ); + final_exp = sub( pMDCTSpectrum_e, norm_exp ); + scaled_value = L_shl( pMDCTSpectrum_fx[strt_cpy], norm_exp ); + sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], pPowerSpectrum_e, &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[sub( strt_cpy, tmp )] = pPowerSpectrum_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e = pPowerSpectrum_e; + } + move32(); + strt_cpy = add( strt_cpy, 1 ); + } + + sfbEnergyTileR_fx = BASOP_Util_Divide3216_Scale( sfbEnergyTileR_fx, width, &tmp_e ); + sfbEnergyTileR_e = sub( add( sfbEnergyTileR_e, tmp_e ), 15 ); /*stores the resultant exponent for sfbEnergyTileR_fx*/ + + /*gain = (float) ( sfbEnergyTileR * ( sfbEnergyC / sfbEnergyTileC ) );*/ + temp = BASOP_Util_Divide3232_Scale( sfbEnergyC_fx, L_add( sfbEnergyTileC_fx, EPSILON_FX ), &tmp_e ); + gain_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); + gain_fx = Mult_32_16( sfbEnergyTileR_fx, temp ); + gain_e = add( 16, add( gain_e, sfbEnergyTileR_e ) ); /*stores the resultant exponent for gain_fx*/ + + IF( !isTransient ) + { + Word16 diffSFM_fx; + Word16 diffSFM_e; + Word16 shiftedSFM_fx; + Word16 shiftedSFM_e; /*stores the resultant exponent for shiftedSFM_fx*/ + shiftedSFM_fx = 0; + shiftedSFM_e = 0; + move16(); + move16(); + + // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); + tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); + tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ + + // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp); + sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, &tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); + crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); + tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); + tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/ + + IF( last_core_acelp || hPrivateData->wasTransient ) + { + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = tmp_tb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] values stored in hPrivateData->sfb_tb_e[sfb] */ + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = tmp_sb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] values stored in hPrivateData->sfb_sb_e[sfb]*/ + hPrivateData->sfb_tb_e[sfb] = tmp_tb_e; + hPrivateData->sfb_sb_e[sfb] = tmp_sb_e; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + /* Purpose of this block: + -to make the exponent of hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] equal to that of tmp_tb_fx + -to make the exponent of hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] equal to that of tmp_sb_fx + */ + Word16 diff_sb_e; /*stores the difference of exponents for sb*/ + Word16 diff_tb_e; /*stores the difference of exponents for tb*/ + diff_sb_e = sub( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ); + diff_tb_e = sub( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ); + IF( LE_16( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ) ) + { + tmp_tb_fx = shl( tmp_tb_fx, diff_tb_e ); + tmp_tb_e = hPrivateData->sfb_tb_e[sfb]; + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], diff_tb_e ); + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], diff_tb_e ); + hPrivateData->sfb_tb_e[sfb] = tmp_tb_e; + move16(); + move16(); + move16(); + } + IF( LE_16( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ) ) + { + tmp_sb_fx = shl( tmp_sb_fx, diff_sb_e ); + tmp_sb_e = hPrivateData->sfb_sb_e[sfb]; + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], diff_sb_e ); + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], diff_sb_e ); + hPrivateData->sfb_sb_e[sfb] = tmp_sb_e; + move16(); + move16(); + move16(); + } + } + tmp_tb_fx = shr( tmp_tb_fx, 2 ); /*taking 2 guard bits so it's exponent tmp_sb_e=+2*/ + tmp_sb_fx = shr( tmp_sb_fx, 2 ); /*taking 2 guard bits so it's exponent tmp_tb_e=+2 */ + tmp_sb_e = add( tmp_sb_e, 2 ); + tmp_tb_e = add( tmp_tb_e, 2 ); + hPrivateData->SFM_tb_fx[sfb] = add( tmp_tb_fx, add( shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], 2 ), shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], 3 ) ) ); + hPrivateData->SFM_tb_fx[sfb] = extract_l( L_min( L_shl( 22118 /*2.7f Q13*/, sub( 2, tmp_tb_e ) ), hPrivateData->SFM_tb_fx[sfb] ) ); /* resultant exponent stored in hPrivateData->sfb_sb_e[sfb]*/ + hPrivateData->SFM_sb_fx[sfb] = add( tmp_sb_fx, add( shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], 2 ), shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], 3 ) ) ); + hPrivateData->SFM_sb_fx[sfb] = extract_l( L_min( L_shl( 22118 /*2.7f Q13*/, sub( 2, tmp_sb_e ) ), hPrivateData->SFM_sb_fx[sfb] ) ); /*resultant exponent stores in hPrivateData->sfb_tb_e[sfb]*/ + hPrivateData->sfb_sb_e[sfb] = tmp_sb_e; + hPrivateData->sfb_tb_e[sfb] = tmp_tb_e; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + diffSFM_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], tmp_sb_e, negate( hPrivateData->SFM_tb_fx[sfb] ), tmp_tb_e, &diffSFM_fx ); /*stores the resultant exponent for diffSFM_fx*/ + + UNUSED_PARAM( diffSFM_e ); + + IF( diffSFM_fx > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, tmp_tb_e ) ) ) /* check whether target SFB is more tonal than source SFB */ + { + Word16 currDampingFactor_fx, dampingFactor_fx, alpha_fx; + Word16 threshold_e, threshold_fx, alpha_e, currDampingFactor_e, dampingFactor_e; + /* calculate spectral tilt to detect sudden drops (or increases) in energy in the current SFB */ + x = 1; + mean_x_fx = mean_y_fx = 0; + mean_xy_fx = mean_x2_fx = 0; + mean_x_e = mean_y_e = 15; + mean_xy_e = mean_x2_e = 31; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) + { + mean_x_fx = add( mean_x_fx, x ); /*Q0*/ + mean_x2_fx = L_add( mean_x2_fx, L_mult0( x, x ) ); /*Q0*/ + + /*y = 20 * (int16_t) log10f( max( 1e-018f, pPowerSpectrum[sb] ) );*/ + IF( LT_32( pPowerSpectrum_fx[sb], 1 ) ) + { + y = 20 * ( -18 ); + } + ELSE + { + y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e, Q25 ) ) ), INV_Log2_10_Q15 ), 25 ) ) ); /*Q0*/ + } + mean_y_fx = add( mean_y_fx, y ); /*Q0*/ + mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ + + x = add( x, 1 ); + } + mean_y_fx = BASOP_Util_Divide1616_Scale( mean_y_fx, width, &tmp_e ); /* resultant exp stores in mean_y_e*/ + mean_y_e = add( mean_y_e, sub( tmp_e, 15 ) ); + mean_x_fx = BASOP_Util_Divide1616_Scale( mean_x_fx, width, &tmp_e ); /* resultant exp stores in mean_x_e*/ + mean_x_e = add( mean_x_e, sub( tmp_e, 15 ) ); + mean_xy_fx = BASOP_Util_Divide3216_Scale( mean_xy_fx, width, &tmp_e ); /* resultant exp stores in mean_xy_e*/ + mean_xy_e = add( mean_xy_e, sub( tmp_e, 15 ) ); + mean_x2_fx = BASOP_Util_Divide3216_Scale( mean_x2_fx, width, &tmp_e ); /* resultant exp stores in mean_x2_e*/ + mean_x2_e = add( mean_x2_e, sub( tmp_e, 15 ) ); + + /*slope = ( mean_xy - mean_x * mean_y ) / ( mean_x2 - mean_x * mean_x );*/ + slope_fx = BASOP_Util_Divide3232_Scale( ( L_sub( mean_xy_fx, L_shl( mult( mean_x_fx, mean_y_fx ), sub( add( mean_x_e, mean_y_e ), mean_xy_e ) ) ) ), ( L_sub( mean_x2_fx, L_shl( mult( mean_x_fx, mean_x_fx ), sub( add( mean_x_e, mean_x_e ), mean_x2_e ) ) ) ), &slope_e ); + slope_e = add( slope_e, sub( mean_xy_e, mean_x2_e ) ); /*stores resultant exponent for slope_fx*/ + + /* determine whether strong tilt is due to a step in the spectrum (e.g. band limitation, no damping) + or a tonal component close the band border (apply damping) by calculating SFM for a shift of 1/2 SFB width*/ + threshold_fx = BASOP_Util_Divide1616_Scale( 60, width, &threshold_e ); /*stores resultant exponent for threshold_fx*/ + + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), negate( threshold_fx ), add( threshold_e, 16 ) ), -1 ) ) + { + Word16 shift = shr( width, 1 ); + // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); + shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); + } + ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), threshold_fx, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) + { + Word16 shift; + shift = shr( width, 1 ); + // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, &pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); + shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); + } + shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); /* stores resultant exponent for shiftedSFM_fx*/ + + // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); + temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); + alpha_fx = extract_l( L_min( temp, L_shl( 20480 /*1.25 Q14*/, sub( 1, alpha_e ) ) ) ); /* exponent is alpha_e*/ + temp = BASOP_Util_Divide1616_Scale( hPrivateData->SFM_tb_fx[sfb], hPrivateData->SFM_sb_fx[sfb], &tmp_e ); + tmp_e = add( tmp_e, sub( hPrivateData->sfb_tb_e[sfb], hPrivateData->sfb_sb_e[sfb] ) ); /* stores resultant exponent for temp */ + + // currDampingFactor = expf( alpha * logf( hPrivateData->SFM_tb[sfb] / hPrivateData->SFM_sb[sfb] ) ); + currDampingFactor_fx = round_fx( BASOP_util_Pow2( Mpy_32_16_1( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), 25 ) ), alpha_fx ), add( alpha_e, 6 ), &currDampingFactor_e ) ); /*exp is currDampingFactor_e*/ + + IF( GT_32( shiftedSFM_fx, L_shl( 1311 /*0.04f Q15*/, negate( shiftedSFM_e ) ) ) ) + { + currDampingFactor_fx = 32767; /*1.f Q15*/ + currDampingFactor_e = 0; + move16(); + move16(); + } + + IF( last_core_acelp || hPrivateData->wasTransient || EQ_32( hPrivateData->prevDampingFactor_IIR_fx[sfb], L_shl( -1, sub( 15, hPrivateData->prevDampingFactor_IIR_e[sfb] ) ) ) ) + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = s_max( currDampingFactor_fx, shr( 3277 /*0.1f * 32767*/, currDampingFactor_e ) ); /*resultant exponent stored in hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + hPrivateData->prevDampingFactor_IIR_e[sfb] = currDampingFactor_e; + move16(); + move16(); + } + + { + Word32 tonalToNoise; + Word16 adap; + Word16 adap_e; /*stores exp for adap*/ + Word16 tonalToNoise_e; /*stores exponent for tonalToNoise*/ + tonalToNoise_e = 9; /*stores exponent for tonalToNoise*/ + move16(); + adap = BASOP_Util_Divide1616_Scale( width, 30, &adap_e ); + tonalToNoise = IGF_getTNR_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, pPowerSpectrum_e, adap_e ); /*Q22*/ + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) + { + // currDampingFactor += 0.1f * ( ( 10 + adap ) - tonalToNoise ); + Word32 temp2 = BASOP_Util_Add_Mant32Exp( L_add( L_shl( 10, sub( 15, adap_e ) ) /*exp:adap_e*/, adap ), add( adap_e, 16 ), L_negate( tonalToNoise ), tonalToNoise_e, &tmp_e ); /* resultant exp is tmp_e*/ + currDampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, extract_l( Mult_32_32( 3277 /*0.1f Q15*/, temp2 ) ), tmp_e, &currDampingFactor_fx ); /*stores resultant exp for currDampingFactor_fx*/ + } + } + + dampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb], &dampingFactor_fx ); + dampingFactor_fx = shr( dampingFactor_fx, 1 ); /* resultant exponent is dampingFactor_e*/ + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( dampingFactor_fx, add( dampingFactor_e, 16 ), shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ), add( hPrivateData->prevDampingFactor_IIR_e[sfb], 16 ) ), -1 ) ) + { + // do nothing + } + ELSE + { + dampingFactor_fx = shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ); /* resultant exponent is hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + dampingFactor_e = hPrivateData->prevDampingFactor_IIR_e[sfb]; + move16(); + } + IF( dampingFactor_e < 0 ) + { + dampingFactor_fx = shl( dampingFactor_fx, dampingFactor_e ); + dampingFactor_e = 0; + move16(); + } + gain_fx = Mult_32_16( gain_fx, shl_sat( extract_l( L_min( L_add( dampingFactor_fx, Mult_32_16( L_shl( hPrivateData->dampingFactorSmoothing[sfb], sub( 15, dampingFactor_e ) ) /*Q:15-dampingFactor_e*/, 3277 /*0.1f Q15*/ ) /*Q:15-dampingFactor_e*/ ), shl_sat( 1, sub( 15, dampingFactor_e ) ) ) ), dampingFactor_e ) /*Q15*/ ); + + hPrivateData->prevDampingFactor_IIR_fx[sfb] = dampingFactor_fx; + hPrivateData->prevDampingFactor_IIR_e[sfb] = dampingFactor_e; + move16(); + move16(); + if ( hPrivateData->dampingFactorSmoothing[sfb] > 0 ) + { + hPrivateData->dampingFactorSmoothing[sfb] = sub( hPrivateData->dampingFactorSmoothing[sfb], 1 ); + move16(); + } + } + ELSE + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = -( 1 << 15 ); /* resultant exp which is 0 stores in hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + hPrivateData->dampingFactorSmoothing[sfb] = 1; + move16(); + move16(); + move16(); + } + + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = tmp_tb_fx; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = hPrivateData->SFM_tb_fx[sfb]; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = tmp_sb_fx; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = hPrivateData->SFM_sb_fx[sfb]; + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; + + hPrivateData->dampingFactorSmoothing[sfb] = 2; + move16(); + move16(); + move16(); + move16(); + move16(); + } + } + ELSE + { + tmp_e = pMDCTSpectrum_e; + sfbEnergyR_fx = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); + sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) ); /* stores resultant exponent for sfbEnergyR_fx*/ + gain_fx = sfbEnergyR_fx; /*resultant exponent stored in gain_e=sfbEnergyR_e*/ + gain_e = add( sfbEnergyR_e, 16 ); /* because gain_fx is word32;only after adding 16 q of gain_fx is 15-sfbEnergyR_e*/ + + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; + move16(); + move16(); + move16(); + move16(); + } + /*gain=0.5f+log2f(gain)*2+16 becuase 2.885390081777927f=2*1/loge(2) so 2*1/loge(2)*loge(x) can be written as 2*log2(x)*/ + gain_fx = L_add( ONE_IN_Q22, L_add( L_add( L_shr( BASOP_Util_Log2( gain_fx ), 1 ), L_shl( gain_e, Q24 ) ), L_shl( 16, Q23 ) ) ); /*Q23*/ + IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) + { + gain_fx = L_add( gain_fx, ONE_IN_Q21 ); /* better preservation of original HF band energy */ + } + IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_64000_CPE ) ) ) + { + gain_fx = L_add( gain_fx, ONE_IN_Q20 ); + } + gain_fx = L_min( gain_fx, 91 << Q23 ); /* 13+15+63, see arithcode encode residual */ + gain_fx = L_max( gain_fx, 0 ); + gain_e = 8; /* stores exponent for gain_fx*/ + move16(); + hPrivateData->igfScfQuantized[sfb] = (Word16) ( L_shr( gain_fx, 23 ) ); /*Q0*/ + } + } + + return; +} +#endif +/*-------------------------------------------------------------------* + * IGF_CalculateStereoEnvelope() + * + * envelope estimation + *-------------------------------------------------------------------*/ static void IGF_CalculateStereoEnvelope( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ const float *pMDCTSpectrum, /* i : MDCT spectrum */ @@ -699,8 +1488,8 @@ static void IGF_CalculateStereoEnvelope( float diffSFM; float shiftedSFM = 0.f; - tmp_tb = IGF_getSFM( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1] ); - tmp_sb = IGF_getSFM( tileSrcSpec, 0, strt_cpy - tmp ) / IGF_getCrest( tileSrcSpec, 0, strt_cpy - tmp ); + tmp_tb = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1] ); + tmp_sb = IGF_getSFM_ivas( tileSrcSpec, 0, strt_cpy - tmp ) / IGF_getCrest_ivas( tileSrcSpec, 0, strt_cpy - tmp ); if ( last_core_acelp || hPrivateData->wasTransient ) { @@ -744,12 +1533,12 @@ static void IGF_CalculateStereoEnvelope( if ( slope < -threshold ) { int16_t shift = width >> 1; - shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); + shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); } else if ( ( slope > 1.f * threshold ) && ( sfb != hGrid->sfbWrap[hGrid->nTiles] - 1 ) ) { int16_t shift = width >> 1; - shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); + shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); } alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); @@ -920,7 +1709,7 @@ static int16_t IGF_WriteEnvelope( *-------------------------------------------------------------------*/ /*! r: highPassEnergy */ -static float IGF_ErodeSpectrum( +static float IGF_ErodeSpectrum_ivas( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ float *pSpectrum, /* i/o: MDCT spectrum */ float *pPowerSpectrum, /* i/o: power spectrum */ @@ -1049,6 +1838,453 @@ static float IGF_ErodeSpectrum( * * calculates the IGF whitening levels by SFM and crest *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void IGF_Whitening_ivas_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ + Word32 *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ + Word16 *powerSpectrum_e, /* i : Q31 | MDCT/MDST power spectrum */ + const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ + const Word16 isTransient, /* i : Q0 | flag indicating if transient is detected */ + const Word16 last_core_acelp, /* i : Q0 | indicator if last frame was ACELP core */ + const Word16 isTNSActive, /* i : Q0 | indicator if TNS is active */ + const Word16 sp_aud_decision0, /* i : Q0 | first stage classifier decision */ + const Word32 brate, /* i : Q0 | bitrate */ + const Word16 element_mode /* i : Q0 | element mode */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 p; /*Q0*/ + Word16 tmp; + Word16 tmp_e; + Word16 SFM_src; + Word16 SFM_tar; + Word16 SFM_src_e; + Word16 SFM_tar_e; + Word16 num_Tiles; + Word16 SFM; + Word16 crest_e; + + SFM = -ONE_IN_Q13; /*1.0f Q13*/ + move16(); + + hPrivateData = &hIGFEnc->igfData; + hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; + + IF( NE_16( igfGridIdx, IGF_GRID_LB_NORM ) ) + { + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + /* reset filter */ + hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); + hPrivateData->prevSFM_IIR[p] = 0; + move16(); + + /* preset values: */ + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + } + + FOR( p = 0; p < IGF_MAX_TILES; p++ ) + { + /* update prev data: */ + hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; + /* preset values: */ + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + move16(); + } + + test(); + IF( !( isTransient || hPrivateData->wasTransient ) ) + { + IF( powerSpectrum ) + { + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + Word16 sb; + + IF( isTNSActive ) + { + FOR( sb = hGrid->tile[p]; sb < hGrid->tile[p + 1]; sb++ ) + { + IF( LT_32( powerSpectrum[sb], 1 ) ) + hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP )*/ + ELSE + hPrivateData->logSpec[sb] = extract_l( L_max( 0, L_shr( L_add( BASOP_Util_Log2( powerSpectrum[sb] ), L_shl( *powerSpectrum_e, Q25 ) ), Q25 ) ) ); + move16(); + } + } + + /* if current tile contains only a single SFB, reuse already computed SFM values */ + test(); + IF( GT_16( element_mode, EVS_MONO ) && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) + { + tmp = hPrivateData->SFM_tb_fx[p]; + tmp_e = hPrivateData->sfb_tb_e[p]; + move16(); + move16(); + } + ELSE + { + tmp = BASOP_Util_Divide1616_Scale( IGF_getSFM_new_fx( powerSpectrum, hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], *powerSpectrum_e ), IGF_getCrest_new_fx( hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], &crest_e ), &tmp_e ); + tmp_e = sub( tmp_e, crest_e ); + } + + test(); + IF( last_core_acelp || hPrivateData->wasTransient ) + { + hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*16-(15-exp)=>15Q16*/ + hPrivateData->prevSFM_IIR[p] = shl( tmp, sub( tmp_e, 2 ) ); /*13-(15-exp)=>2Q13*/ + move32(); + move16(); + } + + test(); + IF( LE_32( brate, IVAS_48k ) && EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + Word16 temp; + num_Tiles = 0; + SFM_src = 0; + SFM_tar = 0; + SFM_src_e = 0; + SFM_tar_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( sb = hGrid->sfbWrap[p]; sb < hGrid->sfbWrap[p + 1]; sb++ ) + { + num_Tiles = add( num_Tiles, 1 ); + SFM_src_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sb], hPrivateData->sfb_sb_e[sb], SFM_src, SFM_src_e, &SFM_src ); + SFM_tar_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_tb_fx[sb], hPrivateData->sfb_tb_e[sb], SFM_tar, SFM_tar_e, &SFM_tar ); + } + + /* compute the average */ + SFM_src = shr( BASOP_Util_Divide1616_Scale( SFM_src, num_Tiles, &temp ), 2 ); + SFM_src_e = add( SFM_src_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ + SFM_tar = shr( BASOP_Util_Divide1616_Scale( SFM_tar, num_Tiles, &temp ), 2 ); + SFM_tar_e = add( SFM_tar_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ + + IF( LT_16( SFM_tar_e, SFM_src_e ) ) + { + SFM_tar = shl( SFM_tar, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ + SFM_tar_e = SFM_src_e; + } + ELSE + { + SFM_src = shr( SFM_src, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ + SFM_src_e = SFM_tar_e; + } + move16(); + + test(); + test(); + IF( ( p > 0 ) && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) + { + test(); + if ( EQ_16( p, 1 ) && EQ_16( abs_s( sub( hPrivateData->igfCurrWhiteningLevel[0], hPrivateData->igfCurrWhiteningLevel[1] ) ), 2 ) ) /* OFF vs. STRONG */ + { + hPrivateData->igfCurrWhiteningLevel[0] = IGF_WHITENING_MID; + move16(); + } + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p - 1]; + move16(); + } + ELSE IF( sp_aud_decision0 ) + { + /* Music */ + /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ + test(); + if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + + /* whitening mid: */ + test(); + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + + /* whitening strong */ + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + } + ELSE + { + /* Speech */ + /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ + test(); + if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + + /* whitening mid: */ + test(); + if ( GT_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + + /* whitening strong */ + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + } + + SFM = shl( SFM_tar, sub( SFM_tar_e, 2 ) ); /*2Q13*/ + } + ELSE + { + test(); + IF( GT_16( element_mode, EVS_MONO ) && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) + { + SFM = shl( tmp, sub( tmp_e, 2 ) ); /*2Q13*/ + } + ELSE + { + Word32 temp; + temp = L_add( L_shl( tmp, sub( tmp_e, 2 ) ), L_add( L_shr( hPrivateData->prevSFM_FIR[p], 3 ), L_shr( hPrivateData->prevSFM_IIR[p], 1 ) ) ); + SFM = extract_l( L_min( 22118 /*2.7*/, temp ) ); /*2Q13*/ + } + hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*15Q16*/ + hPrivateData->prevSFM_IIR[p] = SFM; + move32(); + move16(); + + IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + ELSE + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + } + + IF( GT_16( element_mode, EVS_MONO ) ) + { + IF( last_core_acelp ) /* reset */ + { + set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); + hPrivateData->igfWhiteningHangoverCnt[p] = 2; + move16(); + } + ELSE + { + test(); + test(); + test(); + test(); + /* check whether change in whitening level should be allowed or not (if SFM is inside a certain margin around thresholds) */ + IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) && + ( ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[0][p], 1229 /*0.15f Q13*/ ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[0][p], 1229 ) ) ) || + ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[1][p], 1229 ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[1][p], 1229 ) ) ) ) ) + { + Word16 mean_past_SFM; + Word16 mean_past_SFM_e; + Word16 countable; + Word16 i; + mean_past_SFM = 0; + mean_past_SFM_e = 0; + countable = 0; + move16(); + move16(); + move16(); + + /* compute mean of last (available) SFM values */ + FOR( i = 0; i < IGF_PAST_SFM_LEN; i++ ) + { + IF( hPrivateData->igfPastSFM_fx[p][i] >= 0 ) + { + mean_past_SFM_e = BASOP_Util_Add_MantExp( mean_past_SFM, mean_past_SFM_e, hPrivateData->igfPastSFM_fx[p][i], 2, &mean_past_SFM ); + countable = add( countable, 1 ); + } + } + IF( countable ) + { + Word16 temp; + mean_past_SFM = BASOP_Util_Divide1616_Scale( mean_past_SFM, countable, &temp ); + mean_past_SFM_e = add( mean_past_SFM_e, sub( temp, 15 ) ); + mean_past_SFM = shl( mean_past_SFM, sub( mean_past_SFM_e, 2 ) ); /*mean_past_SFM_e=2*/ + /* deny change in whitening level for small deviations from mean SFM */ + if ( LT_16( abs_s( sub( SFM, mean_past_SFM ) ), 1638 ) /*0.2 in Q13*/ ) + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; + move16(); + } + } + } + } + + hPrivateData->igfPastSFM_fx[p][hPrivateData->igfPastSFM_pos] = SFM; /*2Q13*/ + move16(); + } + } + + SWITCH( hPrivateData->igfInfo.bitRateIndex ) + { + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_WB_13200_CPE: + case IGF_BITRATE_WB_16400_CPE: + case IGF_BITRATE_RF_SWB_13200: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_13200_CPE: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_24400_CPE: + case IGF_BITRATE_SWB_32000_CPE: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_24400_CPE: + case IGF_BITRATE_FB_32000_CPE: + case IGF_BITRATE_FB_32000: + hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; + move16(); + break; + default: + break; + } + } + ELSE + { + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + } + } + ELSE + { + /* reset filter */ + FOR( p = 0; p < IGF_MAX_TILES; p++ ) + { + hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); + hPrivateData->prevSFM_IIR[p] = 0; + move32(); + move16(); + } + } + + IF( GT_16( element_mode, EVS_MONO ) ) + { + IF( EQ_16( SFM, -ONE_IN_Q13 /*1.0f 2Q13*/ ) ) /* reset */ + { + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); + hPrivateData->igfWhiteningHangoverCnt[p] = 2; + move16(); + } + } + + /* vibrato handling */ + FOR( p = 0; p < hGrid->nTiles; p = p + 2 ) + { + test(); + test(); + test(); + IF( ( EQ_16( hPrivateData->igfPrevWhiteningLevel[p], IGF_WHITENING_OFF ) && NE_16( hPrivateData->igfCurrWhiteningLevel[p], IGF_WHITENING_OFF ) ) || + ( EQ_16( hPrivateData->igfPrevWhiteningLevel[p + 1], IGF_WHITENING_OFF ) && NE_16( hPrivateData->igfCurrWhiteningLevel[p + 1], IGF_WHITENING_OFF ) ) ) + { + Word16 i; + Word16 pastSfm_a[4], pastSfm_b[4]; + Word16 pastSfmDiffSum_a, pastSfmDiffSum_b; + + FOR( i = 0; i < 4; i++ ) + { + pastSfm_a[i] = hPrivateData->igfPastSFM_fx[p][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; + pastSfm_b[i] = hPrivateData->igfPastSFM_fx[p + 1][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; + move16(); + move16(); + } + pastSfmDiffSum_a = pastSfmDiffSum_b = 0; + move16(); + move16(); + FOR( i = 0; i < 3; i++ ) + { + IF( NE_16( pastSfm_a[i + 1], -ONE_IN_Q13 ) ) + { + pastSfmDiffSum_a = add( pastSfmDiffSum_a, sub( pastSfm_a[i], pastSfm_a[i + 1] ) ); + pastSfmDiffSum_b = add( pastSfmDiffSum_b, sub( pastSfm_b[i], pastSfm_b[i + 1] ) ); + } + ELSE + { + break; + } + } + + /* if tonality oscillates between two tiles, turn whitening off in both */ + IF( ( ( pastSfmDiffSum_a > 0 && pastSfmDiffSum_b < 0 ) || + ( pastSfmDiffSum_a < 0 && pastSfmDiffSum_b > 0 ) ) && + ( GT_16( abs_s( sub( pastSfmDiffSum_a, pastSfmDiffSum_b ) ), ONE_IN_Q13 ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p + 1] = IGF_WHITENING_OFF; + move16(); + move16(); + } + } + } + + /* hangover */ + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) ) + { + hPrivateData->igfWhiteningHangoverCnt[p] = add( hPrivateData->igfWhiteningHangoverCnt[p], 1 ); + IF( EQ_16( hPrivateData->igfWhiteningHangoverCnt[p], 3 ) ) + { + hPrivateData->igfWhiteningHangoverCnt[p] = 0; + } + ELSE + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; + } + move16(); + move16(); + } + ELSE + { + hPrivateData->igfWhiteningHangoverCnt[p] = 0; + move16(); + } + } + + hPrivateData->igfPastSFM_pos = add( hPrivateData->igfPastSFM_pos, 1 ) % IGF_PAST_SFM_LEN; + move16(); + } + + hPrivateData->wasTransient = isTransient; + move16(); + + return; +} +#endif // IVAS_FLOAT_FIXED static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ @@ -1056,7 +2292,7 @@ static void IGF_Whitening( const int16_t igfGridIdx, /* i : Q0 | IGF grid index */ const int16_t isTransient, /* i : Q0 | flag indicating if transient is detected */ const int16_t last_core_acelp, /* i : Q0 | indicator if last frame was ACELP core */ - const int16_t isTNSActive, /* i : Q0 | indicator if TNS is active */ + const int8_t isTNSActive, /* i : Q0 | indicator if TNS is active */ const int16_t sp_aud_decision0, /* i : Q0 | first stage classifier decision */ const int32_t brate, /* i : Q0 | bitrate */ const int16_t element_mode /* i : Q0 | element mode */ @@ -1567,7 +2803,7 @@ static int16_t IGF_WriteFlatteningTrigger( * updates the start/stop frequency of IGF according to igfGridIdx *-------------------------------------------------------------------*/ -static void IGF_UpdateInfo( +static void IGF_UpdateInfo_ivas( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ const int16_t igfGridIdx /* i : IGF grid index */ ) @@ -1864,7 +3100,7 @@ void IGFEncApplyMono( float *pMDCTSpectrum, /* i/o: MDCT spectrum */ float *pPowerSpectrum, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ const int16_t isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const int16_t isTNSActive, /* i : flag indicating if the TNS is active */ + const int8_t isTNSActive, /* i : flag indicating if the TNS is active */ const int16_t sp_aud_decision0, /* i : first stage switching decision */ const int16_t vad_hover_flag /* i : VAD hangover flag */ ) @@ -1877,7 +3113,7 @@ void IGFEncApplyMono( pPowerSpectrumParameter = !isTNSActive && isTCX20 ? pPowerSpectrum : NULL; - IGF_UpdateInfo( st->hIGFEnc, igfGridIdx ); + IGF_UpdateInfo_ivas( st->hIGFEnc, igfGridIdx ); if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) { @@ -1891,7 +3127,7 @@ void IGFEncApplyMono( IGF_Whitening( st->hIGFEnc, pPowerSpectrumParameter, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, isTNSActive, sp_aud_decision0, ( st->element_mode == IVAS_CPE_MDCT ? st->element_brate : st->total_brate ), st->element_mode ); - IGF_ErodeSpectrum( st->hIGFEnc, pMDCTSpectrum, pPowerSpectrumParameter, igfGridIdx, 0 ); + IGF_ErodeSpectrum_ivas( st->hIGFEnc, pMDCTSpectrum, pPowerSpectrumParameter, igfGridIdx, 0 ); return; } @@ -1902,6 +3138,99 @@ void IGFEncApplyMono( * * apply the IGF encoder, main encoder interface *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +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 */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const Word16 frameno, /* i : flag indicating index of current subfr. */ + const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on /* i : flag mct block (1) or stereo (0) */ +) +{ + UNUSED_PARAM( mct_on ); + Word16 highPassEner_exp; + Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ + Word32 *pPowerSpectrumParameterMsInv_fx[NB_DIV]; + Word16 coreMsMask[N_MAX]; + Word16 sfb, ch, last_core_acelp; + STEREO_MDCT_BAND_PARAMETERS *sfbConf; + + /* assumptions: stereo filling was already done on the flattened spectra + * IGF region is always coded M/S, never L/R (to be done in the encoder) + * for residual bands with stereo filling infoTcxNoise is set to zero + * both channels have the same IGF configuration + */ + + /* sanity checks: check if both channels have the same configuration...*/ + assert( ( sts[0]->core == sts[1]->core ) ); + + /* initialization */ + IF( EQ_16( sts[0]->core, TCX_20_CORE ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20; + } + ELSE + { + sfbConf = &hStereoMdct->stbParamsTCX10; + } + if ( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; + } + + /* create line wise ms mask for the core bands */ + set16_fx( coreMsMask, 0, N_MAX ); + FOR( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) + { + set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[frameno][sfb], sub( sfbConf->sfbOffset[sfb + 1], sfbConf->sfbOffset[sfb] ) ); + } + + test(); + test(); + IF( EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->hTcxEnc->fUseTns[frameno] && !sts[1]->hTcxEnc->fUseTns[frameno] ) + { + pPowerSpectrumParameter_fx[0] = &pPowerSpectrum_fx[0][0]; + pPowerSpectrumParameter_fx[1] = &pPowerSpectrum_fx[1][0]; + pPowerSpectrumParameterMsInv_fx[0] = pPowerSpectrumMsInv_fx[0][0]; + pPowerSpectrumParameterMsInv_fx[1] = pPowerSpectrumMsInv_fx[1][0]; + } + ELSE + { + pPowerSpectrumParameter_fx[0] = NULL; + pPowerSpectrumParameter_fx[1] = NULL; + pPowerSpectrumParameterMsInv_fx[0] = NULL; + pPowerSpectrumParameterMsInv_fx[1] = NULL; + } + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + last_core_acelp = extract_l( EQ_16( sts[ch]->last_core, ACELP_CORE ) ); + + IGF_UpdateInfo( hIGFEnc[ch], igfGridIdx ); + IGF_CalculateStereoEnvelope_fx( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], sts[ch]->hTcxEnc->spectrum_e[frameno], inv_spectrum_fx[ch][frameno], sts[ch]->hTcxEnc->spectrum_e[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], pPowerSpectrumParameterMsInv_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx, coreMsMask, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp ); + + IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) + { + pPowerSpectrumParameter_fx[ch] = pPowerSpectrum_fx[ch]; + } + ELSE + { + pPowerSpectrumParameter_fx[ch] = NULL; + } + + IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], &sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); + + IGF_ErodeSpectrum( &highPassEner_exp, hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx ); + } + return; +} +#endif // IVAS_FLOAT_FIXED void IGFEncApplyStereo( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ @@ -1966,7 +3295,7 @@ void IGFEncApplyStereo( { last_core_acelp = ( sts[ch]->last_core == ACELP_CORE ); - IGF_UpdateInfo( hIGFEnc[ch], igfGridIdx ); + IGF_UpdateInfo_ivas( hIGFEnc[ch], igfGridIdx ); IGF_CalculateStereoEnvelope( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum[frameno], inv_spectrum[ch][frameno], pPowerSpectrumParameter[ch], pPowerSpectrumParameterMsInv[ch], igfGridIdx, coreMsMask, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp ); @@ -1974,7 +3303,7 @@ void IGFEncApplyStereo( IGF_Whitening( hIGFEnc[ch], pPowerSpectrumParameter[ch], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); - IGF_ErodeSpectrum( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum[frameno], pPowerSpectrumParameter[ch], igfGridIdx, mct_on ); + IGF_ErodeSpectrum_ivas( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum[frameno], pPowerSpectrumParameter[ch], igfGridIdx, mct_on ); } return; @@ -1993,7 +3322,7 @@ void IGFSaveSpectrumForITF( const float *pITFSpectrum /* i : MDCT spectrum */ ) { - IGF_UpdateInfo( hIGFEnc, igfGridIdx ); + IGF_UpdateInfo_ivas( hIGFEnc, igfGridIdx ); mvr2r( pITFSpectrum + IGF_START_MN, hIGFEnc->spec_be_igf_flt, hIGFEnc->infoStopLine - IGF_START_MN ); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 1841bd93a809fe6189943dd6bdb7a149852d2c59..61b844fde1d5bbcc0710fcbb89fa2bf8c1816ba0 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -9,8 +9,7 @@ #include "cnst.h" #include "stl.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" #include "basop_util.h" @@ -252,14 +251,19 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< } #ifdef BASOP_NOGLOB BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyR[sfb] ), + sfbEnergyR_exp[sfb], + width, + 15, + &gain, + &gain_exp ); #else BASOP_Util_Divide_MantExp( round_fx( sfbEnergyR[sfb] ), -#endif sfbEnergyR_exp[sfb], width, 15, &gain, &gain_exp ); +#endif L_tmp = L_deposit_h( gain ); } @@ -366,12 +370,12 @@ static void IGF_WriteEnvelope( /**< ou /**********************************************************************/ /* identifies significant spectral content **************************************************************************/ -static void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ - Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -566,12 +570,12 @@ static void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou /**********************************************************************/ /* crest factor calculation **************************************************************************/ -static Word16 IGF_getCrest( /**< out: Q15| crest factor */ - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ - const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +Word16 IGF_getCrest( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ) { Word16 i; @@ -655,12 +659,12 @@ static Word16 IGF_getCrest( /**< ou /************************************************************************* calculates spectral flatness measurment **************************************************************************/ -static Word16 IGF_getSFM( /**< out: Q15| SFM value */ - Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ - const Word32 *energy, /**< in: Q31| energies */ - const Word16 *energy_exp, /**< in: | exponent of energies */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +Word16 IGF_getSFM( /**< out: Q15| SFM value */ + Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ + const Word32 *energy, /**< in: Q31| energies */ + const Word16 *energy_exp, /**< in: | exponent of energies */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ ) { Word16 n, i, s; @@ -1084,8 +1088,8 @@ static void IGF_WriteFlatteningTrigger( /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ -static void IGF_UpdateInfo( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +void IGF_UpdateInfo( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index b5a74687ac5b33a8ad82fd3170b1500eff093647..58b8358037850a5a035f8b0c3d53a94c184be044 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -9,8 +9,7 @@ #include "stat_enc.h" #include "stat_com.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index c5d5a39a58ac792fd6ea4c9b2f8f13dfda6fdd53..ac191c7ff89ed31926c142caf352b1aa5eb3a745 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -41,12 +41,12 @@ #include "rom_enc.h" #include "prot.h" #include "ivas_prot.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif -#include "tools_fx.c" #include "prot_fx_enc.h" /*-----------------------------------------------------------------------* @@ -162,7 +162,11 @@ ivas_error init_encoder( st->mem_preemph = 0.0f; st->mem_preemph16k = 0.0f; st->mem_preemph_enc_flt = 0.0; - +#ifdef IVAS_FLOAT_FIXED + st->mem_preemph_fx = 0; + st->mem_preemph16k_fx = 0; + st->mem_preemph_enc = 0; +#endif /* AVQ pre-quantizer memory */ st->mem_preemp_preQ = 0.0f; st->mem_deemp_preQ = 0.0f; @@ -233,9 +237,13 @@ ivas_error init_encoder( set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - +#ifdef IVAS_FLOAT_FIXED + st->mem_preemph_DFT_fx = 0; + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + st->mem_preemph16k_DFT_fx = 0; + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; - +#endif /* Stationary noise UV modification */ st->ge_sm = 10; st->uv_count = 0; @@ -268,7 +276,13 @@ ivas_error init_encoder( st->predecision_flag = 0; st->diff_sm = 0; st->energy_sm = 0; - +#ifdef IVAS_FLOAT_FIXED + st->voicing0_sm_fx = 0; + st->voicing_sm_fx = 0; + st->LF_EnergyRatio_sm_fx = ONE_IN_Q7; + st->diff_sm_fx = 0; + st->energy_sm_fx = 0; +#endif set_s( st->pitch, L_SUBFR, 3 ); set_f( st->voicing, 0.0f, 3 ); @@ -284,32 +298,73 @@ ivas_error init_encoder( } st->Bin_E_old = st->hSignalBuf->Bin_E_old_flt; +#ifdef IVAS_FLOAT_FIXED + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; +#endif st->mem_decim = st->hSignalBuf->mem_decim_flt; st->mem_decim16k = st->hSignalBuf->mem_decim16k_flt; st->old_inp_12k8 = st->hSignalBuf->old_inp_12k8_flt; st->old_inp_16k = st->hSignalBuf->old_inp_16k_flt; +#ifdef IVAS_FLOAT_FIXED + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; + st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; + st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; +#endif st->buf_speech_enc_pe_flt = st->hSignalBuf->buf_speech_enc_pe_flt; st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; +#ifdef IVAS_FLOAT_FIXED + st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; + st->buf_synth = st->hSignalBuf->buf_synth; + st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; + st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; +#endif /* initializations */ set_f( st->Bin_E_old, 0, L_FFT / 2 ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); +#endif set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); set_f( st->old_inp_12k8, 0, L_INP_MEM ); set_f( st->old_inp_16k, 0, L_INP_MEM ); - +#ifdef IVAS_FLOAT_FIXED + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); + set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); + set16_fx( st->mem_decim_fx, 0, 2 * L_FILT_MAX ); + st->input_buff_fx = st->hSignalBuf->input_buff; + st->input_buff32_fx = st->hSignalBuf->input_buff32; +#endif st->input_buff = st->hSignalBuf->input_buff_flt; set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); st->old_input_signal = st->input_buff; +#ifdef IVAS_FLOAT_FIXED + st->input_buff_fx = st->hSignalBuf->input_buff; + set16_fx( st->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + st->old_input_signal_fx = st->input_buff_fx; +#endif if ( st->element_mode == EVS_MONO ) { +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); +#endif // IVAS_FLOAT_FIXED st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); } else { +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; + st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC; +#endif // IVAS_FLOAT_FIXED st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; +#endif } } else @@ -317,12 +372,18 @@ ivas_error init_encoder( st->hSignalBuf = NULL; st->Bin_E_old = NULL; st->mem_decim = NULL; +#ifdef IVAS_FLOAT_FIXED + st->mem_decim_fx = NULL; +#endif st->mem_decim16k = NULL; st->old_inp_12k8 = NULL; st->old_inp_16k = NULL; st->buf_speech_enc_pe_flt = NULL; st->buf_synth_flt = NULL; st->buf_speech_enc_flt = NULL; +#ifdef IVAS_FLOAT_FIXED + st->buf_speech_enc = NULL; +#endif st->buf_wspeech_enc_flt = NULL; st->input_buff = NULL; } @@ -428,10 +489,16 @@ ivas_error init_encoder( st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ st->lp_noise = 0.0f; +#ifdef IVAS_FLOAT_FIXED + st->lp_noise_fx = 0; +#endif st->flag_noisy_speech_snr = 0; st->fd_cng_reset_flag = 0; st->cng_type = -1; st->bckr_tilt_lt_flt = 0.f; +#ifdef IVAS_FLOAT_FIXED + st->bckr_tilt_lt = 0; +#endif st->active_cnt = 0; if ( ( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO ) || ( st->element_mode == IVAS_CPE_MDCT && st->Opt_DTX_ON ) ) @@ -441,6 +508,9 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } dtx_enc_init( st, var_SID_rate_flag, interval_SID ); +#ifdef IVAS_FLOAT_FIXED + dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); +#endif } else { @@ -504,7 +574,11 @@ ivas_error init_encoder( if ( ( st->element_mode != IVAS_CPE_MDCT && idchan == 0 ) || ( st->element_mode == IVAS_CPE_MDCT && st->Opt_DTX_ON ) ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -513,7 +587,10 @@ ivas_error init_encoder( { st->cldfbAnaEnc = NULL; } - +#ifdef IVAS_FLOAT_FIXED + st->energyCoreLookahead_Fx = 0; + st->sf_energyCoreLookahead_Fx = 0; +#endif st->currEnergyLookAhead = 6.1e-5f; /*-----------------------------------------------------------------* @@ -604,8 +681,11 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -720,8 +800,16 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } +#ifdef MSAN_FIX + set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); +#endif // MSAN_FIX /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ +#ifdef IVAS_FLOAT_FIXED + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#endif // IVAS_FLOAT_FIXED + st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; @@ -841,7 +929,9 @@ ivas_error init_encoder( } initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale_flt ); - +#ifdef IVAS_FLOAT_FIXED + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#endif /* initialization for IVAS modes happens in first frame pre-processing */ if ( st->element_mode == EVS_MONO ) { @@ -879,7 +969,22 @@ ivas_error init_encoder( st->cng_sba_flag = 0; st->bits_frame_channel = 0; st->side_bits_frame_channel = 0; - +#ifdef IVAS_FLOAT_FIXED + st->Q_syn2 = 0; + move16(); + st->Q_syn = 0; + move16(); + set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); + st->Q_old = 15; + move16(); + st->old_wsp_max = 0; + move16(); + st->old_wsp_shift = 0; + move16(); + st->sharpFlag = 0; + move16(); +#endif return error; } #ifdef IVAS_FLOAT_FIXED @@ -1058,9 +1163,9 @@ ivas_error init_encoder_ivas_fx( /* stereo switching memories */ st->mem_preemph_DFT_fx = 0; - set32_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); st->mem_preemph16k_DFT_fx = 0; - set32_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; @@ -1335,7 +1440,7 @@ ivas_error init_encoder_ivas_fx( IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - IF( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1436,7 +1541,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - IF( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1694,8 +1799,9 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - /* (int16_t) ( st->input_Fs / FRAMES_PER_SEC ) */ - Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); + frame_length = shr( frame_length, sub( 15, temp ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { @@ -1714,6 +1820,20 @@ ivas_error init_encoder_ivas_fx( st->cng_sba_flag = 0; st->bits_frame_channel = 0; st->side_bits_frame_channel = 0; + st->Q_syn2 = 0; + move16(); + st->Q_syn = 0; + move16(); + set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); + st->Q_old = 15; + move16(); + st->old_wsp_max = 0; + move16(); + st->old_wsp_shift = 0; + move16(); + st->sharpFlag = 0; + move16(); return error; } diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 2607c50a5f276a00daed5fe99d1771a4a46fe128..aa7a2954988e09070aab8c9222cd631d69faec8a 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -10,8 +10,7 @@ #include "stl.h" #include "ivas_cnst.h" #include "ivas_error.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -41,7 +40,7 @@ ivas_error init_encoder_fx( *-----------------------------------------------------------------*/ IF( !vad_only_flag ) { - IF( ( st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) count_malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); } @@ -130,7 +129,7 @@ ivas_error init_encoder_fx( IF( !vad_only_flag ) { - IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } @@ -149,7 +148,7 @@ ivas_error init_encoder_fx( { st_fx->hBstr = NULL; } - st_fx->hBstr->nb_bits_tot_fx = 0; + st_fx->hBstr->nb_bits_tot = 0; move16(); @@ -160,7 +159,7 @@ ivas_error init_encoder_fx( init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); st_fx->next_force_safety_net_fx = 0; - st_fx->pstreaklen_fx = 0; + st_fx->pstreaklen = 0; move16(); st_fx->streaklimit_fx = 32767; move16(); /*1;//Q15 */ @@ -175,7 +174,7 @@ ivas_error init_encoder_fx( test(); IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) count_malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } @@ -300,7 +299,7 @@ ivas_error init_encoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hGSCEnc = (GSC_ENC_HANDLE) count_malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } @@ -350,7 +349,7 @@ ivas_error init_encoder_fx( test(); IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && ( !vad_only_flag ) ) { - if ( ( st_fx->hVAD = (VAD_HANDLE) count_malloc( sizeof( VAD_DATA ) ) ) == NULL ) + if ( ( st_fx->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); } @@ -404,7 +403,7 @@ ivas_error init_encoder_fx( // PMT("deal with idchan ") IF( /*idchan == 0 ||*/ EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - if ( ( st_fx->hNoiseEst = (NOISE_EST_HANDLE) count_malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) + if ( ( st_fx->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); } @@ -422,7 +421,7 @@ ivas_error init_encoder_fx( test(); IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE) count_malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) + IF( ( st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE) malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } @@ -501,7 +500,7 @@ ivas_error init_encoder_fx( test(); IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->Opt_DTX_ON ) ) { - if ( ( st_fx->hDtxEnc = (DTX_ENC_HANDLE) count_malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) + if ( ( st_fx->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } @@ -534,7 +533,7 @@ ivas_error init_encoder_fx( test(); IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) { - IF( ( st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE) count_malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } @@ -555,7 +554,7 @@ ivas_error init_encoder_fx( test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hLPDmem = (LPD_state_HANDLE) count_malloc( sizeof( LPD_state ) ) ) == NULL ) + IF( ( st_fx->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } @@ -622,7 +621,7 @@ ivas_error init_encoder_fx( test(); IF( st_fx->Opt_SC_VBR || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE) count_malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE) malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } @@ -636,7 +635,7 @@ ivas_error init_encoder_fx( /* PLC encoder */ IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE) count_malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) + IF( ( st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE) malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n" ) ); } @@ -651,7 +650,7 @@ ivas_error init_encoder_fx( IF( st_fx->element_mode == EVS_MONO ) { - IF( ( st_fx->hTECEnc = (TEC_ENC_HANDLE) count_malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTECEnc = (TEC_ENC_HANDLE) malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); } @@ -667,7 +666,7 @@ ivas_error init_encoder_fx( IF( !vad_only_flag ) { - IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } @@ -682,7 +681,7 @@ ivas_error init_encoder_fx( *-----------------------------------------------------------------*/ IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE) count_malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } @@ -705,7 +704,7 @@ ivas_error init_encoder_fx( IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE) count_malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -727,7 +726,7 @@ ivas_error init_encoder_fx( IF( st_fx->Opt_RF_ON || EQ_16( st_fx->element_mode, EVS_MONO ) ) { - IF( ( st_fx->hRF = (RF_ENC_HANDLE) count_malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n" ) ); } @@ -747,7 +746,7 @@ ivas_error init_encoder_fx( st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_fx2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); + st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); st_fx->Energy_Old_fx = 0; @@ -768,7 +767,7 @@ ivas_error init_encoder_fx( // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) count_malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } @@ -787,7 +786,7 @@ ivas_error init_encoder_fx( /* MDCT classifier */ MDCT_classifier_reset_fx( st_fx->hTcxEnc ); - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } @@ -805,7 +804,7 @@ ivas_error init_encoder_fx( test(); IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) { - IF( ( st_fx->hHQ_core = (HQ_ENC_HANDLE) count_malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) + IF( ( st_fx->hHQ_core = (HQ_ENC_HANDLE) malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } @@ -866,7 +865,7 @@ ivas_error init_encoder_fx( test(); IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) count_malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + IF( ( st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } @@ -908,7 +907,7 @@ ivas_error init_encoder_fx( init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); // PMT("Transient detector init needs review, handle hTranDet is missing") InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), - NS2SA_fx2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), + NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), &st_fx->transientDetection ); // reset_indices_enc_fx( st_fx->hBstr); @@ -940,7 +939,7 @@ ivas_error init_encoder_fx( st_fx->low_rate_mode = 0; /* low-rate mode flag */ // st_fx->coder_type = GENERIC; /* low-rate mode flag */ - set16_fx( st_fx->pitch_fx, L_SUBFR, 3 ); + set16_fx( st_fx->pitch, L_SUBFR, 3 ); set16_fx( st_fx->voicing_fx, 0, 3 ); diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 3b21cb7e7b94d223cb72c74438d22eed1def261b..bb573b1c421e7674dbcaeb10e8f2eea1a7dddb00 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -8,8 +8,7 @@ #include "basop_util.h" #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/isf_enc_amr_wb_fx.c b/lib_enc/isf_enc_amr_wb_fx.c index 8d19855a4b1539b9f330f91d416b9ce8c4f2e649..505d3f2903eb9f1ea7156dc154357103dd07d8be 100644 --- a/lib_enc/isf_enc_amr_wb_fx.c +++ b/lib_enc/isf_enc_amr_wb_fx.c @@ -34,8 +34,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index acfd266eb4c22725620dbc3a83902285169760bc..2e4c17c8396836b3beaf0616d97286f3778c5769 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -39,8 +39,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop_util.h" #endif @@ -399,7 +398,7 @@ ivas_error ivas_spar_agc_enc_open_fx( } input_frame = (Word16) Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ); - delay = NS2SA_fx2( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); + delay = NS2SA_FX2( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); if ( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index ebc6bd649cf2cc12072983b0593b6122d7ce99bf..37b321bb59cd845855b3fdca821fe743a8abf00f 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -40,6 +40,7 @@ #include "wmc_auto.h" #include #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -49,7 +50,7 @@ * * Principal IVAS core coder routine, where number of core channels is 1 or 2 *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_core_enc( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ @@ -90,6 +91,10 @@ ivas_error ivas_core_enc( float hb_speech[L_FRAME16k / 4]; float *new_swb_speech; float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX]; +#ifdef IVAS_FLOAT_FIXED + Word32 *new_swb_speech_fx; + Word32 new_swb_speech_buffer_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; +#endif float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; int16_t Voicing_flag[CPE_CHANNELS]; @@ -363,11 +368,18 @@ ivas_error ivas_core_enc( *---------------------------------------------------------------------*/ new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; +#ifdef IVAS_FLOAT_FIXED + new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; +#endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) { /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ +#ifdef IVAS_FLOAT_FIXED + swb_pre_proc_ivas_fx( st, new_swb_speech, new_swb_speech_fx, shb_speech, realBuffer[n], imagBuffer[n], hCPE ); +#else swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE ); +#endif } else if ( input_Fs >= 32000 ) { @@ -455,3 +467,399 @@ ivas_error ivas_core_enc( return error; } +#else +ivas_error ivas_core_enc( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const int16_t n_CoreChannels, /* i : number of core channels to be coded */ + float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */ + float old_inp_16k[][L_INP], /* i : buffer of old input signal */ + float ener[], /* i : residual energy from Levinson-Durbin */ + float A[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ + float Aw[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ + float epsP[][M + 1], /* i : LP prediction errors */ + float lsp_new[][M], /* i : LSPs at the end of the frame */ + float lsp_mid[][M], /* i : LSPs in the middle of the frame */ + const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ + int16_t attack_flag[], /* i : attack flag (GSC or TC) */ + float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[][L_WSP], /* i : weighted input signal buffer */ + const int16_t loc_harm[], /* i : harmonicity flag */ + const float cor_map_sum[], /* i : speech/music clasif. parameter */ + const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ + float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ + float fft_buff[][2 * L_FFT], /* i : FFT buffer */ + const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ + const int16_t ivas_format, /* i : IVAS format */ + const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ +) +{ + int16_t n, input_frame; + int16_t cpe_id, MCT_flag; + Encoder_State **sts, *st; + STEREO_ICBWE_ENC_HANDLE hStereoICBWE; + STEREO_TD_ENC_DATA_HANDLE hStereoTD; + float *inp[CPE_CHANNELS]; + float new_inp_resamp16k[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ + float shb_speech[L_FRAME16k]; + float hb_speech[L_FRAME16k / 4]; + float *new_swb_speech; + float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX]; + float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; + int16_t Voicing_flag[CPE_CHANNELS]; + float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; + int16_t unbits[CPE_CHANNELS]; + float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; + int16_t last_element_mode, tdm_Pitch_reuse_flag; + int32_t element_brate, last_element_brate, input_Fs; + int16_t diff_nBits; + ivas_error error; + int16_t max_num_indices_BWE; + + push_wmops( "ivas_core_enc" ); + + error = IVAS_ERR_OK; + + /*------------------------------------------------------------------* + * General initialization + *-----------------------------------------------------------------*/ + + if ( hSCE != NULL ) + { + cpe_id = -1; + MCT_flag = 0; + sts = hSCE->hCoreCoder; + hStereoTD = NULL; + hStereoICBWE = NULL; + element_brate = hSCE->element_brate; + last_element_brate = hSCE->last_element_brate; + last_element_mode = IVAS_SCE; + tdm_Pitch_reuse_flag = -1; + } + else + { + cpe_id = hCPE->cpe_id; + MCT_flag = 0; + if ( hMCT != NULL ) + { + MCT_flag = 1; + } + sts = hCPE->hCoreCoder; + hStereoICBWE = hCPE->hStereoICBWE; + element_brate = hCPE->element_brate; + last_element_brate = hCPE->last_element_brate; + last_element_mode = hCPE->last_element_mode; + + if ( hCPE->hStereoTD != NULL ) + { + hStereoTD = hCPE->hStereoTD; + tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag; + } + else + { + hStereoTD = NULL; + tdm_Pitch_reuse_flag = -1; + } + } + + input_Fs = sts[0]->input_Fs; + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + + set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + + for ( n = 0; n < n_CoreChannels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initializiation per core-coder channel + *-----------------------------------------------------------------*/ + + + st->extl = -1; + unbits[n] = 0; + + st->element_brate = element_brate; + + /*---------------------------------------------------------------------* + * Pre-processing, incl. Decision matrix + *---------------------------------------------------------------------*/ + + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) + { + st->enablePlcWaveadjust = 0; + } + } + + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + diff_nBits = 0; + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits ); + } + + /*---------------------------------------------------------------------* + * Core Encoding + *---------------------------------------------------------------------*/ + + for ( n = 0; n < n_CoreChannels; n++ ) + { + st = sts[n]; + + /* update pointer to the buffer of indices of the second channel */ + if ( n == 1 && st->element_mode == IVAS_CPE_TD ) + { + /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */ + max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate ); + st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot + max_num_indices_BWE; + + /* write TD stereo spatial parameters */ + move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); + st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot; + st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot; + + reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP ); + } + + /*---------------------------------------------------------------------* + * Write signaling info into the bitstream + *---------------------------------------------------------------------*/ + + if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) ) + { + ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); + } + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode ); + + /*---------------------------------------------------------------------* + * ACELP core encoding + * TCX core encoding + * HQ core encoding + *---------------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE ) + { + /* ACELP core encoder */ + if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) + { + /* TCX core encoder */ + stereo_tcx_core_enc( st, old_inp_12k8[n] + L_INP_MEM, old_inp_16k[n] + L_INP_MEM, Aw[n], lsp_new[n], lsp_mid[n], pitch_buf[n], last_element_mode, vad_hover_flag[0] ); + } + + if ( st->core == HQ_CORE ) + { + /* HQ core encoder */ + hq_core_enc( st, st->input, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); + } + + /*---------------------------------------------------------------------* + * TD stereo updates + *---------------------------------------------------------------------*/ + + if ( st->element_mode == IVAS_CPE_TD && n == 0 ) + { + td_stereo_param_updt( st->lsp_old, st->lsf_old, pitch_buf[0], tdm_lspQ_PCh, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); + } + } + + + /*---------------------------------------------------------------------* + * MDCT stereo: joint TCX Core Encoding + *---------------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_MDCT ) + { + if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 ) + { + if ( MCT_flag ) + { + ivas_mdct_core_whitening_enc( hCPE, old_inp_16k, old_wsp, pitch_buf, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id], + hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE ); + } + else + { + stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf ); + } + } + else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 ) + { + /* synch CNG configs between channels */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st = sts[n]; + if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) ) + { + configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); + } + } + + if ( sts[0]->cng_sba_flag ) + { + FdCngEncodeDiracMDCTStereoSID( hCPE ); + } + else + { + FdCngEncodeMDCTStereoSID( hCPE ); + } + } + } + + + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and Updates + *---------------------------------------------------------------------*/ + + for ( n = 0; n < n_CoreChannels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n] ); + + /*---------------------------------------------------------------------* + * WB TBE encoding + * WB BWE encoding + *---------------------------------------------------------------------*/ + + if ( input_Fs >= 16000 && st->bwidth < SWB && st->hBWE_TD != NULL ) + { + /* Common pre-processing for WB TBE and WB BWE */ + wb_pre_proc( st, last_element_mode, new_inp_resamp16k[n], hb_speech ); + } + + if ( st->extl == WB_TBE ) + { + /* WB TBE encoder */ + wb_tbe_enc( st, hb_speech, bwe_exc_extended[n], voice_factors[n], pitch_buf[n] ); + } + else if ( st->extl == WB_BWE && n == 0 && st->element_mode != IVAS_CPE_MDCT ) + { + /* WB BWE encoder */ + wb_bwe_enc( st, new_inp_resamp16k[n] ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE encoding + * SWB(FB) BWE encoding + *---------------------------------------------------------------------*/ + + new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; + + if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) + { + /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ + swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE ); + } + else if ( input_Fs >= 32000 ) + { + if ( st->hBWE_TD != NULL ) + { + InitSWBencBufferStates( st->hBWE_TD, shb_speech ); + } + } + + /* SWB TBE encoder */ + if ( st->extl == SWB_TBE || st->extl == FB_TBE ) + { + if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) + { + float fb_exc[L_FRAME16k]; + + swb_tbe_enc( st, hStereoICBWE, shb_speech, bwe_exc_extended[n], voice_factors[n], fb_exc, pitch_buf[n] ); + + if ( st->extl == FB_TBE ) + { + /* FB TBE encoder */ + fb_tbe_enc( st, st->input, fb_exc ); + } + } + } + else if ( st->extl == SWB_BWE || st->extl == FB_BWE ) + { + /* SWB(FB) BWE encoder */ + swb_bwe_enc( st, last_element_mode, old_inp_12k8[n], old_inp_16k[n], old_syn_12k8_16k[n], new_swb_speech, shb_speech ); + } + + /*---------------------------------------------------------------------* + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ + + if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( input_frame >= L_FRAME32k || st->element_mode == IVAS_CPE_DFT ) ) + { + /* SHB DTX/CNG encoder */ + swb_CNG_enc( st, shb_speech, old_syn_12k8_16k[n] ); + } + + /*-------------------------------------------------------------------* + * Inter-channel BWE encoding + *-------------------------------------------------------------------*/ + + if ( n == 0 && input_Fs >= 32000 && hStereoICBWE != NULL ) + { + stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ ); + + stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] ); + } + + /*---------------------------------------------------------------------* + * Channel-aware mode - write signaling information into the bitstream + *---------------------------------------------------------------------*/ + + signaling_enc_rf( st ); + + /*---------------------------------------------------------------------* + * Common updates + *---------------------------------------------------------------------*/ + + if ( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ + { + updt_enc_common( st ); + } + } + + /*------------------------------------------------------------------* + * Write potentially unused bits in combined format coding + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + while ( diff_nBits > 0 ) + { + n = min( diff_nBits, 16 ); + push_indice( sts[0]->hBstr, IND_UNUSED, 0, n ); + diff_nBits -= n; + } + } + + + pop_wmops(); + + return error; +} +#endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index d08241540eba965e145c48aa0a098dc4b141c0c6..33a06a43a3c91a4db81c42cd24bc4e9773e24cd7 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -37,10 +37,15 @@ #include "rom_enc.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_prot.h" #include "wmc_auto.h" #include +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#endif /*---------------------------------------------------------------* * Local constants @@ -52,7 +57,16 @@ /*-------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------*/ - +#if 0 +static void change_q( Word16 *buff, Word16 size, Word16 Q ) +{ + Flag Overflow; + for ( Word16 i = 0; i < size; i++ ) + { + buff[i] = shr_o( buff[i], Q, &Overflow ); + } +} +#endif static void calculate_energy_buffer( CPE_ENC_HANDLE hCPE, float enerBuffer_dft[], const int16_t no_channels, const int32_t input_Fs ); #ifdef IVAS_FIXED_ENC static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_dft_fx[], Word16 *enerBuffer_dft_q_fx, const Word16 no_channels, const Word32 input_Fs ); @@ -64,7 +78,6 @@ static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_d * Front Pre-processing for IVAS * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) *--------------------------------------------------------------------*/ - ivas_error pre_proc_front_ivas( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ @@ -836,8 +849,1264 @@ ivas_error pre_proc_front_ivas( pop_wmops(); return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error pre_proc_front_ivas_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const int32_t element_brate, /* i : SCE/CPE element bitrate */ + const int16_t nb_bits_metadata, /* i : number of metadata bits */ + const int16_t input_frame, /* i : frame length */ + const int16_t n, /* i : channel number */ + float old_inp_12k8[], /* o : buffer of old input signal */ + float old_inp_16k[], /* o : buffer of old input signal @16kHz */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float *relE, /* o : frame relative energy */ + float A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ + float epsP[M + 1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + int16_t *vad_hover_flag, /* o : VAD hangover flag */ + int16_t *attack_flag, /* o : flag signaling attack */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + float old_wsp[], /* o : weighted input signal buffer */ + float pitch_fr[NB_SUBFR], /* o : fractional pitch values */ + float voicing_fr[NB_SUBFR], /* o : fractional pitch gains */ + int16_t *loc_harm, /* o : harmonicity flag */ + float *cor_map_sum, /* o : speech/music clasif. parameter */ + int16_t *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ + float fft_buff[2 * L_FFT], /* o : FFT buffer */ + const float tdm_A_PCh[M + 1], /* i : unq. LP coeff. of primary channel */ + const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ + const float currFlatness, /* i : flatness parameter */ + const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel Q8*/ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ +) +{ + float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ + float *wsp; /* weighted input signal buffer */ + float Etot; /* total energy */ + float fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ + float lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + float tmpN[NB_BANDS]; /* Temporary noise update */ + float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + float tmpN_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ + float tmpE_LR[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + float cor_map_sum_LR[CPE_CHANNELS]; /* speech/music clasif. parameter */ + float non_staX_LR; /* non-stationarity for sp/mus classifier */ + float ncharX_LR; /* noise character for sp/mus classifier */ + float sp_div_LR; /* spectral diversity feature */ + float S_map_LR[L_FFT / 2]; /* short-term correlation map */ + float corr_shiftL; /* correlation shift */ + float corr_shiftR; /* correlation shift */ + int16_t loc_harmLR[CPE_CHANNELS]; /* harmonicity flag */ + int16_t lr_vad_enabled; /* LR VAD indicator */ + float ee[2]; /* Spectral tilt */ + float corr_shift; /* correlation shift */ + float sp_div, PS[128]; /* speech/music clasif. parameters */ + int16_t L_look; /* length of look-ahead */ +#if 1 + float snr_sum_he; /* HE SAD parameters */ +#endif + float mem_decim_dummy[2 * L_FILT_MAX]; /* dummy decimation filter memory */ + float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ + float hp_E[2]; /* Energy in HF */ + int16_t flag_spitch; + int16_t high_lpn_flag; + float lsf_new[M]; + float band_energies[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + int16_t localVAD_HE_SAD; + float non_staX; + float stab_fac; + int16_t alw_pitch_lag_12k8[2]; + float alw_voicing[2]; + int16_t last_core_orig; + float dummy; + float S_map[L_FFT / 2]; + int16_t i, lMemRecalc, lMemRecalc_12k8; + int16_t smc_dec; + float ncharX, dE1X; + Encoder_State *st; + float *signal_in; + int16_t element_mode; + int32_t input_Fs, last_element_brate; + int16_t *tdm_SM_last_clas, tmpS; + float *res_cod_SNR_M, tmpF[STEREO_DFT_BAND_MAX]; + STEREO_CLASSIF_HANDLE hStereoClassif; + int16_t old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ + int16_t LR_localVAD; + ivas_error error; + + push_wmops( "pre_proc_front" ); + +#ifdef IVAS_FLOAT_FIXED + Word16 *signal_in_fx; + Word16 *new_inp_12k8_fx; /* pointers to current frame and new data */ + CLDFB_SCALE_FACTOR cldfbScale; + Word32 *enerBuffer_fx; + Word16 enerBuffer_exp; /*[CLDFB_NO_CHANNELS_MAX];*/ + Word16 *temp1F_icatdmResampBuf_fx; + Word16 *old_inp_12k8_fx; + Word16 *old_inp_16k_fx; + Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word32 Etot_fx; /* total energy */ +#if 0 + Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ + Word16 Q_new; + Word16 new_inp_out_size, mem_decim_size; + Word16 snr_sum_he_fx; /* HE SAD parameters */ + Word16 Q_new_inp; + Word16 corr_shift_fx; + Word16 dummy_fx; + Word16 Etot_LR_fx[2]; + Word16 Q_exp; + Word32 Le_min_scaled; + Word32 fr_bands_LR_fx[2][2 * NB_BANDS]; + Word16 relE_fx; + Word32 tmpN_fx[NB_BANDS]; /* Temporary noise update */ + Word32 tmpE_fx[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + Word32 tmpN_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary noise update */ + Word32 tmpE_LR_fx[CPE_CHANNELS][NB_BANDS]; /* Temporary averaged energy of 2 sf. */ +#endif + + signal_in_fx = (Word16 *) malloc( 2 * 1965 * sizeof( Word16 * ) ); + enerBuffer_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) ); + old_inp_12k8_fx = (Word16 *) malloc( 496 * sizeof( Word16 * ) ); + old_inp_16k_fx = (Word16 *) malloc( 880 * sizeof( Word16 * ) ); + mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); + temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); + + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; + +#ifndef MSAN_FIX + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, 0, 496 ); +#endif // MSAN_FIX +#endif + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + error = IVAS_ERR_OK; + + tmpS = 0; + tdm_SM_last_clas = &tmpS; + set_f( tmpF, 0, STEREO_DFT_BAND_MAX ); + res_cod_SNR_M = tmpF; + + LR_localVAD = 0; + + if ( hSCE != NULL ) + { + st = hSCE->hCoreCoder[n]; + signal_in = hSCE->hCoreCoder[n]->input; + element_mode = IVAS_SCE; + last_element_brate = hSCE->last_element_brate; + hStereoClassif = NULL; + lr_vad_enabled = 0; + } + else /* CPE */ + { + st = hCPE->hCoreCoder[n]; + signal_in = hCPE->hCoreCoder[n]->input; + element_mode = hCPE->element_mode; + last_element_brate = hCPE->last_element_brate; + hStereoClassif = hCPE->hStereoClassif; + lr_vad_enabled = 0; + if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) + { + lr_vad_enabled = 1; + } + + if ( lr_vad_enabled && n == 0 ) + { + /* Combine localVAD and vad_flag from LR processing */ + LR_localVAD = hCPE->hCoreCoder[0]->localVAD || hCPE->hCoreCoder[1]->localVAD; + } + + if ( hCPE->hStereoTD != NULL ) + { + tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; + mvs2s( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); + } + + if ( hCPE->hStereoDft != NULL ) + { + res_cod_SNR_M = hCPE->hStereoDft->res_cod_SNR_M; + } + } +#if 0 + set32_fx( tmpF_fx, 0, STEREO_DFT_BAND_MAX ); + res_cod_SNR_M_fx = tmpF_fx; + + LR_localVAD = 0; + + IF ( hSCE != NULL ) + { + st = hSCE->hCoreCoder[n]; + signal_in_fx = hSCE->hCoreCoder[n]->input_fx; + element_mode = IVAS_SCE; + last_element_brate = hSCE->last_element_brate; + hStereoClassif = NULL; + lr_vad_enabled = 0; + } + ELSE /* CPE */ + { + st = hCPE->hCoreCoder[n]; + signal_in_fx = hCPE->hCoreCoder[n]->input_fx; + element_mode = hCPE->element_mode; + last_element_brate = hCPE->last_element_brate; + hStereoClassif = hCPE->hStereoClassif; + lr_vad_enabled = 0; + IF ( hCPE->hFrontVad[0] != NULL && NE_16(hCPE->element_mode, IVAS_CPE_MDCT )) + { + lr_vad_enabled = 1; + } + + IF ( lr_vad_enabled && EQ_16(n, 0 )) + { + /* Combine localVAD and vad_flag from LR processing */ + LR_localVAD = hCPE->hCoreCoder[0]->localVAD || hCPE->hCoreCoder[1]->localVAD; + } + + IF ( hCPE->hStereoTD != NULL ) + { + tdm_SM_last_clas = &hCPE->hStereoTD->tdm_SM_last_clas[n]; + Copy( hCPE->hStereoTD->tdm_SM_last_clas, hCPE->hStereoTD->tdm_SM_last2_clas, CPE_CHANNELS ); + } + + IF ( hCPE->hStereoDft != NULL ) + { + res_cod_SNR_M_fx = hCPE->hStereoDft->res_cod_SNR_M_fx; + } + } +#endif + lMemRecalc_12k8 = 0; + lMemRecalc = 0; + IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + lMemRecalc = NS2SA( st->input_Fs, L_MEM_RECALC_NS ); + lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); + } + + input_Fs = st->input_Fs; + + localVAD_HE_SAD = 0; +#if 1 + snr_sum_he = 0; +#endif + corr_shiftL = 0; + corr_shiftR = 0; +#if 0 + snr_sum_he_fx = 0; +#endif + IF( hSCE != NULL ) + { + *vad_hover_flag = 0; + } + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + st->coder_type = GENERIC; + IF( st->hGSCEnc != NULL ) + { + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP0; + } + *attack_flag = 0; + + IF( st->Opt_SC_VBR ) + { + st->hSC_VBR->bump_up = 0; + st->hSC_VBR->ppp_mode = 0; + st->hSC_VBR->nelp_mode = 0; + st->hSC_VBR->avoid_HQ_VBR_NB = 0; + } + + L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ + + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ +#ifdef IVAS_FLOAT_FIXED + new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ +#if 0 + inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ +#endif +#endif + if ( element_mode != IVAS_CPE_DFT ) + { + new_inp_12k8 -= L_FILT; + } + + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - STEREO_DFT_OVL_12k8 ); + } + else if ( element_mode == IVAS_CPE_TD ) + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - lMemRecalc_12k8 - L_FILT ); + } + else + { + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - L_FILT ); + } + + mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + IF( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + new_inp_12k8_fx -= L_FILT; + } +#if 0 + IF(EQ_16(element_mode, IVAS_CPE_DFT)) + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8); + } + ELSE IF(EQ_16(element_mode, IVAS_CPE_TD)) + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - lMemRecalc_12k8 - L_FILT); + } + ELSE + { + Copy(st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT); + } + Copy(st->old_wsp, old_wsp, L_WSP_MEM); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ +#endif + st->rf_mode = st->Opt_RF_ON; + + last_core_orig = st->last_core; + + /*--------------------------------------------------------------* + * energy analysis + *---------------------------------------------------------------*/ + + floatToFixed_arr( signal_in - (Word16) ( input_Fs / 50 ), signal_in_fx, 0, (Word16) ( input_Fs / 25 ) ); + signal_in_fx = signal_in_fx + input_Fs / 50; + IF( EQ_16( element_mode, IVAS_SCE ) || ( EQ_16( element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + { + analysisCldfbEncoder_ivas_fx( st, signal_in_fx, realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[i][j] = (float) realBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + imagBuffer[i][j] = (float) imagBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + } + } + cldfbScale.hb_scale = cldfbScale.lb_scale; + fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); + } + ELSE IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) || ( EQ_16( st->idchan, 1 ) && st->tdm_LRTD_flag ) ) + { + /* cldfb analysis only for pri. channel */ + analysisCldfbEncoder_ivas_fx( st, signal_in_fx - NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ), realBuffer_fx, imagBuffer_fx, realBuffer16, imagBuffer16, enerBuffer_fx, &enerBuffer_exp, &cldfbScale ); + for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + for ( int j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + realBuffer[i][j] = (float) realBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + imagBuffer[i][j] = (float) imagBuffer_fx[i][j] / ( 1 << ( 16 - cldfbScale.lb_scale ) ); + } + } + cldfbScale.hb_scale = cldfbScale.lb_scale; + fixedToFloat_arrL( enerBuffer_fx, enerBuffer, 31 - enerBuffer_exp, 60 ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + calculate_energy_buffer( hCPE, enerBuffer, st->cldfbAnaEnc->no_channels, input_Fs ); + f2me_buf( enerBuffer, enerBuffer_fx, &enerBuffer_exp, 60 ); + } + ELSE + { + set32_fx( enerBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); + enerBuffer_exp = 31; + } + + /*----------------------------------------------------------------* + * Change the sampling frequency to 12.8 kHz + * (if not available from downsampled DMX) + *----------------------------------------------------------------*/ +#if 0 // Disabled due to high mld -- Scaling needs to be handled. + IF( element_mode == IVAS_SCE ) + { + new_inp_out_size = modify_Fs_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, Q_new_inp, new_inp_out_size ); // To be removed + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + + change_q( new_inp_12k8_fx, new_inp_out_size, Q_new_inp ); + + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); + + set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); + + new_inp_out_size = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); + + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, Q_new_inp, new_inp_out_size ); // To be removed + change_q( new_inp_12k8_fx + L_FRAME, new_inp_out_size, Q_new_inp ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); + + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, Q_new_inp ); + } + + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, Q_new_inp, new_inp_out_size ); // To be removed + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, 0, mem_decim_size ); // To be removed + + change_q( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, Q_new_inp ); + + IF( GT_16( lMemRecalc, 0 ) ) + { + new_inp_out_size = modify_Fs_fx( signal_in_fx + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_out_size, Q_new_inp ); + } + set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); + new_inp_out_size = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, Q_new_inp, new_inp_out_size ); // To be removed + + change_q( new_inp_12k8_fx + L_FRAME, new_inp_out_size, Q_new_inp ); + } + ELSE /* DFT stereo */ + { + /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ + Copy( signal_in_fx + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); // To be removed + } +#else + if ( element_mode == IVAS_SCE ) + { + modify_Fs( signal_in, input_frame, input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim, 0 ); + } + + modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_12k8 - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + + if ( lMemRecalc > 0 ) + { + modify_Fs( signal_in + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy, ( st->max_bwidth == NB ) ); + } + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else /* DFT stereo */ + { + /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ + mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + } +#endif + /* save input resampled at 12.8kHz, non-preemhasised */ + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8, st->buf_speech_enc_flt + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + mvr2r( new_inp_12k8 - lMemRecalc_12k8, st->buf_speech_enc_flt + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); + } + else + { + mvr2r( new_inp_12k8, st->buf_speech_enc_flt + L_FRAME32k, L_FRAME ); + } +#ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ +#if 1 + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); + Scale_sig( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, 1 ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + Copy( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); + Scale_sig( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT, 1 ); + } + ELSE + { + Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); + Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); + } +#endif +#endif // !MSAN_FIX + /*------------------------------------------------------------------* + * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 + *-----------------------------------------------------------------*/ +#if 0 // Disabled due to high mld +#if 0 // EVS-Version + Word16 headroom = 1; + IF( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) + { + headroom = add( headroom, 1 ); + } + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + Preemph_scaled( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, new_inp_12k8 - STEREO_DFT_OVL_12k8, Q_new, L_FRAME ); // To be removed + dummy_fx = st->mem_preemph_fx; + Preemph_scaled( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, STEREO_DFT_OVL_12k8, st->last_coder_type, 1 ); + + st->mem_preemph = (float) st->mem_preemph_fx; + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, Q_new, STEREO_DFT_OVL_12k8 ); // To be removed + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st->idchan, 0 ) ) + { + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + { + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + Preemph_scaled( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, st->last_coder_type, 1 ); + + st->mem_preemph = (float) st->mem_preemph_fx; + fixedToFloat_arr( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), Q_new, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + } + + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, length_12k8, st->last_coder_type, 1 ); + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, Q_new, length_12k8 ); // To be removed + } + + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + dummy_fx = st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, Q_new, L_FRAME ); // To be removed + + Preemph_scaled( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, lMemRecalc_12k8 + L_FILT, st->last_coder_type, 1 ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, Q_new, lMemRecalc_12k8 + L_FILT ); // To be removed + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + { + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + + Preemph_scaled( new_inp_12k8_fx, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type, 1 ); + dummy_fx = st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, Q_new, L_FRAME ); // To be removed + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + + Preemph_scaled( new_inp_12k8_fx + L_FRAME, &Q_new, &dummy_fx, st->Q_max, PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FILT, st->last_coder_type, 1 ); + st->mem_preemph = (float) st->mem_preemph_fx; + + fixedToFloat_arr( new_inp_12k8_fx + 256, new_inp_12k8 + 256, Q_new, 12 ); // To be removed + } + + Q_exp = sub( Q_new, st->Q_old ); + st->prev_Q_old = st->Q_old; + move16(); + st->Q_old = Q_new; + move16(); +#else // IVAS-Version + + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + floatToFixed_arr( new_inp_12k8 - STEREO_DFT_OVL_12k8, new_inp_12k8_fx - STEREO_DFT_OVL_12k8, 0, L_FRAME + STEREO_DFT_OVL_12k8 ); // To be removed + st->mem_preemph_fx = (Word16) st->mem_preemph; + st->mem_preemph_DFT_fx = (Word16) st->mem_preemph_DFT; + + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ +#if 1 // TOBE removed later + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; +#endif + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8, &dummy_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, new_inp_12k8 - STEREO_DFT_OVL_12k8, 0, L_FRAME + STEREO_DFT_OVL_12k8 ); // To be removed + st->mem_preemph = (float) st->mem_preemph_fx; + st->mem_preemph_DFT = (float) st->mem_preemph_DFT_fx; + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st->idchan, 0 ) ) + { + + st->mem_preemph_fx = (Word16) st->mem_preemph; + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + { +#if 1 // TOBE removed later + + floatToFixed_arr( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + st->mem_preemph_DFT_fx = (Word16) st->mem_preemph_DFT; + + mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); +#endif + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); // To be removed + } + + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ +#if 1 // TOBE removed later + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ // TO be remove later +#endif + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + floatToFixed_arr( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, 0, length_12k8 ); // To be removed + + PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, 0, length_12k8 ); // To be removed + } + + floatToFixed_arr( new_inp_12k8 - lMemRecalc_12k8, new_inp_12k8_fx - lMemRecalc_12k8, 0, L_FRAME + lMemRecalc_12k8 + L_FILT ); // To be removed + + PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, 0, L_FRAME + lMemRecalc_12k8 + L_FILT ); // To be removed + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + { + floatToFixed_arr( new_inp_12k8, new_inp_12k8_fx, 0, L_FRAME + L_FILT ); // To be removed + st->mem_preemph_fx = (Word16) st->mem_preemph; + + PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + + st->mem_preemph = (float) st->mem_preemph_fx; + dummy = (float) dummy_fx; + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, 0, L_FRAME + L_FILT ); // To be removed + } +#endif +#else + if ( element_mode == IVAS_CPE_DFT ) + { + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + + st->mem_preemph = st->mem_preemph_DFT; + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8, &dummy ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + if ( st->idchan == 0 ) + { + if ( hCPE->last_element_mode == IVAS_CPE_DFT ) + { + st->mem_preemph = st->mem_preemph_DFT; + mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + preemph( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC_FLT, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph ); + } + + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + preemph( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC_FLT, length_12k8, &st->mem_preemph ); + } + + preemph( new_inp_12k8 - lMemRecalc_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC_FLT, lMemRecalc_12k8 + L_FILT, &dummy ); + } + else /* IVAS_SCE or IVAS_CPE_MDCT */ + { + preemph( new_inp_12k8, PREEMPH_FAC_FLT, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 + L_FRAME, PREEMPH_FAC_FLT, L_FILT, &dummy ); + } +#endif + +#if 0 + /*------------------------------------------------------------------* + * Scaling of memories + *-----------------------------------------------------------------*/ + Q_new = 0; + floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->ave_enr2, st->hNoiseEst->ave_enr2_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->fr_bands1, st->hNoiseEst->fr_bands1_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->fr_bands2, st->hNoiseEst->fr_bands2_fx, Q_new + QSCALE, 20 ); + + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame, Q_exp, &Q_new, old_inp_12k8_fx, &( st->mem_wsp_fx ), st->hNoiseEst->enrO_fx, st->hNoiseEst->bckr_fx, + st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->fr_bands1_fx, st->hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); +#endif + /*-------------------------------------------------------------------------* + * Spectral analysis + *--------------------------------------------------------------------------*/ + analy_sp( element_mode, hCPE, input_Fs, inp_12k8, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, band_energies, PS, fft_buff ); + + if ( hStereoClassif != NULL ) + { + if ( st->lp_speech - Etot > 25 ) + { + hStereoClassif->silence_flag = 2; + } + else + { + hStereoClassif->silence_flag = hStereoClassif->silence_flag - 1; + } + hStereoClassif->silence_flag = max( 0, hStereoClassif->silence_flag ); + } + + /*----------------------------------------------------------------* + * SAD (1-signal, 0-noise) + *----------------------------------------------------------------*/ + + Etot_fx = (Word32) ( Etot * ( 1 << 24 ) ); + st->hNoiseEst->Etot_h_32fx = (Word32) ( st->hNoiseEst->Etot_h * 16777216.0 ); + st->hNoiseEst->Etot_l_32fx = (Word32) ( st->hNoiseEst->Etot_l * 16777216.0 ); + st->hNoiseEst->Etot_l_lp_32fx = (Word32) ( st->hNoiseEst->Etot_l_lp * 16777216.0 ); + st->hNoiseEst->Etot_last_32fx = (Word32) ( st->hNoiseEst->Etot_last * 16777216.0 ); + st->hNoiseEst->Etot_v_h2_32fx = (Word32) ( st->hNoiseEst->Etot_v_h2 * 16777216.0 ); + st->hNoiseEst->Etot_lp_32fx = (Word32) ( st->hNoiseEst->Etot_lp * 16777216.0 ); + st->hNoiseEst->sign_dyn_lp_32fx = (Word32) ( st->hNoiseEst->sign_dyn_lp * 16777216.0 ); + + noise_est_pre_32fx( Etot_fx, st->ini_frame, st->hNoiseEst, st->idchan, element_mode, hCPE != NULL ? hCPE->last_element_mode : element_mode ); + + st->hNoiseEst->Etot_h = (float) ( st->hNoiseEst->Etot_h_32fx / 16777216.0 ); + st->hNoiseEst->Etot_l = (float) ( st->hNoiseEst->Etot_l_32fx / 16777216.0 ); + st->hNoiseEst->Etot_l_lp = (float) ( st->hNoiseEst->Etot_l_lp_32fx / 16777216.0 ); + st->hNoiseEst->Etot_last = (float) ( st->hNoiseEst->Etot_last_32fx / 16777216.0 ); + st->hNoiseEst->Etot_v_h2 = (float) ( st->hNoiseEst->Etot_v_h2_32fx / 16777216.0 ); + st->hNoiseEst->Etot_lp = (float) ( st->hNoiseEst->Etot_lp_32fx / 16777216.0 ); + st->hNoiseEst->sign_dyn_lp = (float) ( st->hNoiseEst->sign_dyn_lp_32fx / 16777216.0 ); + + IF( EQ_16( element_mode, IVAS_CPE_TD ) && ( ( abs( hCPE->hStereoTD->tdm_last_ratio_idx - tdm_ratio_idx ) > 5 && EQ_16( st->idchan, 1 ) ) || abs( hCPE->hStereoTD->tdm_last_inst_ratio_idx - hCPE->hStereoTD->tdm_inst_ratio_idx ) > 10 ) ) + { + st->ini_frame = 1; + } +#if 0 // Disbaled due to high MLD + Q_new = Q_factor_arr( fr_bands, 40 ); + floatToFixed_arrL( fr_bands, fr_bands_fx, Q_new + QSCALE, 40 ); + st->lp_noise_fx = (Word16) ( st->lp_noise * ( 1 << 8 ) ); + st->lp_speech_fx = (Word16) ( st->lp_speech * ( 1 << 8 ) ); + floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); + floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); + st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; + st->hVAD->bcg_flux_fx = (Word16) st->hVAD->bcg_flux * ( 1 << 4 ); + st->hNoiseEst->Etot_v_h2_fx = (Word16) ( st->hNoiseEst->Etot_v_h2 * ( 1 << 8 ) ); + st->hNoiseEst->sign_dyn_lp_fx = (Word16) ( st->hNoiseEst->sign_dyn_lp * ( 1 << 8 ) ); + st->hVAD->snr_sum_vad_fx = (Word16) ( st->hVAD->snr_sum_vad * 32767 ); + st->hVAD->prim_act_quick_fx = (Word16) ( st->hVAD->prim_act_quick * 32767 ); + st->hVAD->prim_act_slow_fx = (Word16) ( st->hVAD->prim_act_slow * 32767 ); + st->hVAD->prim_act_fx = (Word16) ( st->hVAD->prim_act * 32767 ); + st->hVAD->prim_act_quick_he_fx = (Word16) ( st->hVAD->prim_act_quick_he * 32767 ); + st->hVAD->prim_act_slow_he_fx = (Word16) ( st->hVAD->prim_act_slow_he * 32767 ); + st->hVAD->prim_act_he_fx = (Word16) ( st->hVAD->prim_act_he * 32767 ); + + + st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr_fx ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float + + st->hNoiseEst->Etot_v_h2 = (float) ( st->hNoiseEst->Etot_v_h2_fx / ( 256.0 ) ); + st->hNoiseEst->sign_dyn_lp = (float) ( st->hNoiseEst->sign_dyn_lp_fx / ( 256.0 ) ); + st->hVAD->bcg_flux = (float) ( st->hVAD->bcg_flux_fx / ( 16.0 ) ); + st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; + st->hVAD->snr_sum_vad = (float) ( st->hVAD->snr_sum_vad_fx / 32767.0 ); + st->hVAD->prim_act_quick = (float) ( st->hVAD->prim_act_quick_fx / 32767.0 ); + st->hVAD->prim_act_slow = (float) ( st->hVAD->prim_act_slow_fx / 32767.0 ); + st->hVAD->prim_act = (float) ( st->hVAD->prim_act_fx / 32767.0 ); + st->hVAD->prim_act_quick_he = (float) ( st->hVAD->prim_act_quick_he_fx / 32767.0 ); + st->hVAD->prim_act_slow_he = (float) ( st->hVAD->prim_act_slow_he_fx / 32767.0 ); + st->hVAD->prim_act_he = (float) ( st->hVAD->prim_act_he_fx / 32767.0 ); +#else + st->vad_flag = wb_vad( st, fr_bands, &i, &i, &i, &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -1000.0f, -1000.0f ); +#endif + + IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) + { + /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ + st->vad_flag = front_vad_flag; + st->localVAD = front_vad_flag; + } + IF( ( hCPE != NULL && !( lr_vad_enabled && EQ_16( st->idchan, 0 ) ) ) || hSCE != NULL ) + { + st->lp_noise_fx = (Word16) ( st->lp_noise * ( 1 << 8 ) ); + st->lp_speech_fx = (Word16) ( st->lp_speech * ( 1 << 8 ) ); + st->hVAD->prim_act_he_fx = (Word16) ( st->hVAD->prim_act_he * MAX_16 ); + st->hNoiseEst->Etot_lp_fx = (Word16) ( st->hNoiseEst->Etot_lp * ( 1 << 8 ) ); + + *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, vad_hover_flag, NULL, NULL ); + } + ELSE + { + /* This only applies to st->idchan==0 now */ + /* Add down mix stereo activity to LR vad_flag_dtx */ + *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; + + + /* Determine hangover flag status based on LR localVAD and downmix localVAD */ + *vad_hover_flag = *vad_flag_dtx && !( LR_localVAD || st->localVAD ); + } + + IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_dtx_flag, 1 ) ) + { + /* overwrite VAD decision with front-VAD decision if external VAD is set to 1*/ + *vad_flag_dtx = front_vad_dtx_flag; + } + + /*----------------------------------------------------------------* + * NB/WB/SWB/FB bandwidth detector + *----------------------------------------------------------------*/ + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + sf_energySum[i] = enerBuffer_exp; + move16(); + } + + IF( EQ_16( st->idchan, 0 ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + st->cldfbAnaEnc->scale = (Word16) ( st->cldfbAnaEnc->scale_flt * ( 1 << 8 ) ); + floatToFixed_arr( st->input, st->input_fx, 0, 480 ); +#ifdef MSAN_FIX + st->lt_mean_NB_fx = (Word16) st->lt_mean_NB * ( 1 << 11 ); + st->lt_mean_WB_fx = (Word16) st->lt_mean_WB * ( 1 << 11 ); + st->lt_mean_SWB_fx = (Word16) st->lt_mean_SWB * ( 1 << 11 ); + st->lp_noise_fx = (Word16) st->lp_noise * ( 1 << 8 ); // have taken Q8 as above one functions uses Q8 +#endif + + bw_detect_fx( st, st->input_fx, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); + + st->lt_mean_NB = (float) st->lt_mean_NB_fx / ( 1 << 11 ); + st->lt_mean_WB = (float) st->lt_mean_WB_fx / ( 1 << 11 ); + st->lt_mean_SWB = (float) st->lt_mean_SWB_fx / ( 1 << 11 ); + } + + IF( NE_16( element_mode, IVAS_CPE_MDCT ) ) /* in MDCT stereo, set_bw_stereo() is used instead */ + { + set_bw( element_mode, element_brate, st, MODE1 ); + } + + /* set the BW of the TD secondary channel in LRTD mode same as BW of the primary channel (only at higher bitrates) */ + IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->tdm_LRTD_flag, 1 ) && st->bits_frame_channel >= IVAS_16k4 / FRAMES_PER_SEC ) + { + st->bwidth = hCPE->hCoreCoder[0]->bwidth; + } + + /*----------------------------------------------------------------* + * Noise energy down-ward update and total noise energy estimation + * Long-term energies and relative frame energy updates + * Correlation correction as a function of total noise level + *----------------------------------------------------------------*/ + + noise_est_down( fr_bands, st->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &st->hNoiseEst->totalNoise, Etot, &st->hNoiseEst->Etot_last, &st->hNoiseEst->Etot_v_h2 ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + noise_est_down( fr_bands_LR[0], hCPE->hFrontVad[0]->hNoiseEst->bckr, tmpN_LR[0], tmpE_LR[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise, Etot_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2 ); + noise_est_down( fr_bands_LR[1], hCPE->hFrontVad[1]->hNoiseEst->bckr, tmpN_LR[1], tmpE_LR[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise, Etot_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2 ); + corr_shiftL = correlation_shift( hCPE->hFrontVad[0]->hNoiseEst->totalNoise ); + corr_shiftR = correlation_shift( hCPE->hFrontVad[1]->hNoiseEst->totalNoise ); + } + + *relE = Etot - st->lp_speech; + + corr_shift = correlation_shift( st->hNoiseEst->totalNoise ); + + /*----------------------------------------------------------------* + * FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + if ( st->hFdCngEnc != NULL ) + { + resetFdCngEnc( st ); + + if ( st->idchan == 0 || element_mode == IVAS_CPE_MDCT ) + { + if ( element_mode == IVAS_CPE_TD && lr_vad_enabled && band_energies_LR != NULL ) + { + perform_noise_estimation_enc( band_energies_LR, enerBuffer, st->hFdCngEnc, input_Fs, hCPE ); + } + else + { + perform_noise_estimation_enc( band_energies, enerBuffer, st->hFdCngEnc, input_Fs, hCPE ); + } + } + } + + /*-----------------------------------------------------------------* + * Select SID or FRAME_NO_DATA frame if DTX enabled + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && element_mode != IVAS_CPE_DFT && element_mode != IVAS_CPE_MDCT ) + { + *vad_flag_dtx = 1; + } + + if ( st->Opt_DTX_ON == 1 && *vad_flag_dtx == 0 && element_mode == IVAS_CPE_DFT && element_brate <= ACELP_16k40 && hCPE->hStereoDft->hConfig->force_mono_transmission == 1 ) /* force LP_CNG usage for MASA DTX when mono tranmission */ + { + st->cng_type = LP_CNG; + } + + dtx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); + + if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) + { + /* Add another period of expected xcorr updates */ + hCPE->hStereoDft->expectedNumUpdates += st->hDtxEnc->max_SID; + } + + /*----------------------------------------------------------------* + * Adjust FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + + if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) + { + int32_t total_brate; + + total_brate = ( element_mode == IVAS_SCE ) ? st->total_brate : st->bits_frame_nominal * FRAMES_PER_SEC; + configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), total_brate ); + if ( hCPE != NULL ) + { + st->hFdCngEnc->hFdCngCom->CngBitrate = hCPE->element_brate - 1; + } + } + + if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) + { + AdjustFirstSID( st ); + } + + /*----------------------------------------------------------------* + * LP analysis + *----------------------------------------------------------------*/ + + alw_pitch_lag_12k8[0] = st->old_pitch_la; + alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_voicing[0] = st->voicing[2]; + alw_voicing[1] = st->voicing[2]; + + i = 0; + if ( element_mode == IVAS_CPE_TD && st->idchan == 1 && hCPE->hStereoTD->tdm_low_rate_mode == 1 ) + { + i = 1; + } + + analy_lp( inp_12k8, L_FRAME, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, i ); + + lsp2lsf( lsp_new, lsf_new, M, INT_FS_12k8 ); + stab_fac = lsf_stab( lsf_new, st->lsf_old1, 0, L_FRAME ); + mvr2r( lsf_new, st->lsf_old1, M ); + + if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) + { + /*----------------------------------------------------------------* + * Comparison of the LP coefficents to determine if it is possible + * to reuse the primary channel LP coefficients in the secondary channel + *----------------------------------------------------------------*/ + + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison( hCPE->hStereoTD, hCPE->hStereoClassif, st, inp_12k8, tdm_A_PCh, A, M, tdm_lsp_new_PCh, lsp_new, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC ); + } + + /*----------------------------------------------------------------* + * Compute weighted input (for OL pitch analysis) + * OL pitch analysis + * stable high pitch detection + * 1/4 pitch precision improvement + *----------------------------------------------------------------*/ + + find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_look ); + + if ( st->vad_flag == 0 ) + { + /* reset the OL pitch tracker memories during inactive frames */ + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + } + + old_pitch1 = st->pitch[1]; + + pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, *relE, L_look, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + + /* Updates for adaptive lag window memory */ + st->old_pitch_la = st->pitch[2]; + + /* Detection of very short stable pitch period */ + StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); + + /* 1/4 pitch precision improvement */ + if ( element_brate <= IVAS_32k ) + { + pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); + } + else + { + pitch_fr[0] = st->pitch[0]; + pitch_fr[1] = st->pitch[0]; + pitch_fr[2] = st->pitch[1]; + pitch_fr[3] = st->pitch[1]; + + voicing_fr[0] = st->voicing[0]; + voicing_fr[1] = st->voicing[0]; + voicing_fr[2] = st->voicing[1]; + voicing_fr[3] = st->voicing[1]; + } + + /*------------------------------------------------------------------* + * Update estimated noise energy and voicing cut-off frequency + *-----------------------------------------------------------------*/ + + noise_est( st, old_pitch1, tmpN, epsP, Etot, *relE, corr_shift, tmpE, fr_bands, cor_map_sum, &ncharX, &sp_div, + &non_staX, loc_harm, lf_E, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp, &dummy /*sp_floor*/, S_map, hStereoClassif, NULL, st->ini_frame ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + /* Run noise_est for Left and Right channel */ + *loc_harmLR = *loc_harm; + noise_est( st, old_pitch1, tmpN_LR[0], epsP, Etot_LR[0], Etot_LR[0] - hCPE->hFrontVad[0]->lp_speech, corr_shiftL, tmpE_LR[0], fr_bands_LR[0], &cor_map_sum_LR[0], &ncharX_LR, &sp_div_LR, + &non_staX_LR, loc_harmLR, lf_E_LR[0], &hCPE->hFrontVad[0]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[0]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[0], hCPE->hFrontVad[0]->ini_frame ); + + /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ + noise_est( st, old_pitch1, tmpN_LR[1], epsP, Etot_LR[1], Etot_LR[1] - hCPE->hFrontVad[1]->lp_speech, corr_shiftR, tmpE_LR[1], fr_bands_LR[1], &cor_map_sum_LR[1], &ncharX_LR, &sp_div_LR, + &non_staX_LR, loc_harmLR, lf_E_LR[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp, &dummy, S_map_LR, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); + } + + /*------------------------------------------------------------------* + * Update parameters used in the VAD and DTX + *-----------------------------------------------------------------*/ + + vad_param_updt( st, corr_shift, corr_shift, A, old_pitch1, NULL, 1 ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + vad_param_updt( st, corr_shiftL, corr_shiftR, A, old_pitch1, &hCPE->hFrontVad[0], CPE_CHANNELS ); + } + + /*-----------------------------------------------------------------* + * Find spectral tilt + * UC and VC frame selection + *-----------------------------------------------------------------*/ + + find_tilt( fr_bands, st->hNoiseEst->bckr, ee, st->pitch, st->voicing, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, MODE1, &( st->bckr_tilt_lt_flt ), st->Opt_SC_VBR ); + + st->coder_type = find_uv( st, pitch_fr, voicing_fr, inp_12k8, ee, &dE1X, corr_shift, *relE, Etot, hp_E, &flag_spitch, last_core_orig, hStereoClassif ); + + /*-----------------------------------------------------------------* + * channel aware mode configuration * + *-----------------------------------------------------------------*/ + + st->rf_mode = 0; + st->rf_target_bits_write = 0; + + /*-----------------------------------------------------------------* + * Signal classification for FEC + * TC frame selection + *-----------------------------------------------------------------*/ + + st->clas = signal_clas( st, inp_12k8, ee, *relE, L_look, tdm_SM_last_clas ); + + select_TC( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); + + if ( st->Opt_SC_VBR ) + { + st->hSC_VBR->Local_VAD = st->localVAD; + } + + /*-----------------------------------------------------------------* + * Collect stereo classifier features + *-----------------------------------------------------------------*/ + + if ( hStereoClassif != NULL ) + { + stereo_classifier_features( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new, epsP, st->pitch, st->voicing, *cor_map_sum, non_staX, sp_div, st->clas ); + } + + /*----------------------------------------------------------------* + * 1st stage speech/music classification (GMM model) + *----------------------------------------------------------------*/ + + smc_dec = ivas_smc_gmm( st, hStereoClassif, localVAD_HE_SAD, Etot, lsp_new, *cor_map_sum, epsP, PS, non_staX, *relE, &high_lpn_flag, flag_spitch ); + + + /*----------------------------------------------------------------* + * VAD energy updates + * Update of old per-band energy spectrum + *----------------------------------------------------------------*/ + + long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); + + mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); + + if ( lr_vad_enabled && st->idchan == 0 ) + { + long_enr( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR ); + + mvr2r( fr_bands_LR[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO, NB_BANDS ); + mvr2r( fr_bands_LR[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO, NB_BANDS ); + } + + /*----------------------------------------------------------------* + * SNR-based speech/music classification + * AC frame selection + *----------------------------------------------------------------*/ + + st->GSC_IVAS_mode = 0; + if ( st->idchan == 1 && element_mode == IVAS_CPE_TD ) + { + /* No speech/music classification in the secondary channel of TD stereo */ + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + + st->GSC_noisy_speech = 0; + if ( st->hGSCEnc != NULL ) + { + st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; + } + } + else if ( element_mode != IVAS_CPE_MDCT ) + { + /* SNR-based speech/music classification */ + if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) + { + if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + st->sba_br_sw_while_no_data = 0; + } + else if ( ivas_format == SBA_FORMAT && st->core_brate == FRAME_NO_DATA && element_brate != last_element_brate ) + { + st->sba_br_sw_while_no_data = 1; + } + + if ( flag_16k_smc ) + { + /* Compute core-coder buffers at internal sampling rate */ + error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, A, Aw, epsP, lsp_new, lsp_mid ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + + smc_dec = ivas_acelp_tcx20_switching( st, st->speech_enc_flt, st->wspeech_enc_flt, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); + } + else + { + smc_dec = ivas_acelp_tcx20_switching( st, inp_12k8, wsp, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); + } + } + /* Switch to ACELP for non-harmonic transient signals */ + else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) + { + if ( element_mode == IVAS_SCE ) + { + if ( transient_analysis( st->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) + { + smc_dec = SPEECH; + } + } + else if ( element_mode == IVAS_CPE_DFT ) + { + for ( i = 0; i < CPE_CHANNELS; i++ ) + { + if ( smc_dec != SPEECH && transient_analysis( hCPE->hCoreCoder[i]->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) + { + smc_dec = SPEECH; /* overwrite initial music decision, initial SPEECH_MUSIC never changed */ + } + } + } + } + + /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ + ivas_smc_mode_selection( st, element_brate, smc_dec, *relE, Etot, attack_flag, inp_12k8, S_map, flag_spitch ); + } + + /*----------------------------------------------------------------* + * Final VAD correction (when HE-SAD is used instead of the normal VAD, + * rewrite the VAD flag by VAD flag with DTX hangover for further processing) + *----------------------------------------------------------------*/ + + if ( st->Opt_DTX_ON && element_mode != IVAS_CPE_DFT ) + { + st->vad_flag = *vad_flag_dtx; + } + + /*-----------------------------------------------------------------* + * Update old input signal buffer + *-----------------------------------------------------------------*/ + + mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); + +#ifdef IVAS_FLOAT_FIXED + free( signal_in_fx - ( input_Fs / 50 ) ); + free( enerBuffer_fx ); + free( old_inp_12k8_fx ); + free( old_inp_16k_fx ); + free( mem_decim_dummy_fx ); + free( temp1F_icatdmResampBuf_fx ); +#endif + pop_wmops(); + return error; +} +#endif + #ifdef IVAS_FIXED_ENC /*-------------------------------------------------------------------* * calculate_energy_buffer_fx() diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 55f76e4300eddc3f95d3347fddb1276dd88f9e4b..9b8b4bfc50cccfd4d7297ac7f287e18521d09c0a 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif @@ -58,12 +59,12 @@ static void stereo_mode_combined_format_enc( const Encoder_Struct *st_ivas, CPE_ * * Channel Pair Element (CPE) encoding routine *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ - const float data_f_ch0[], /* i : input signal for channel 0 */ - const float data_f_ch1[], /* i : input signal for channel 1 */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ const int16_t input_frame, /* i : input frame length per channel */ const int16_t nb_bits_metadata /* i : number of metadata bits */ ) @@ -71,8 +72,14 @@ ivas_error ivas_cpe_enc( CPE_ENC_HANDLE hCPE; Encoder_State **sts; int16_t n, n_CoreChannels; - float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ - float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ + float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ +#ifdef IVAS_FLOAT_FIXED + Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ +#endif + float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ +#ifdef IVAS_FLOAT_FIXED + Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ +#endif float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ float relE[CPE_CHANNELS]; /* frame relative energy */ float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ @@ -155,9 +162,15 @@ ivas_error ivas_cpe_enc( } mvr2r( data_f_ch0, sts[0]->input, input_frame ); +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arr16( data_f_ch0, sts[0]->input_fx, 0, input_frame ); +#endif if ( data_f_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ { mvr2r( data_f_ch1, sts[1]->input, input_frame ); +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arr16( data_f_ch1, sts[1]->input_fx, 0, input_frame ); +#endif } /*----------------------------------------------------------------* @@ -448,6 +461,83 @@ ivas_error ivas_cpe_enc( internal_Fs = getTcxonly_ivas( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); /* iDFT at input sampling rate */ +#ifdef IVAS_FLOAT_FIXED + /*flt2fix*/ + f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); + f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + { + floatToFixed_arr( sts[1]->old_inp_12k8, sts[1]->old_inp_12k8_fx, 0, L_INP_MEM ); + } + f2me( hCPE->hStereoDft->icbweRefEner, &hCPE->hStereoDft->icbweRefEner_fx, &hCPE->hStereoDft->icbweRefEner_fx_e ); + f2me( hCPE->hStereoDft->lbEner, &hCPE->hStereoDft->lbEner_fx, &hCPE->hStereoDft->lbEner_fx_e ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k, hCPE->hStereoDft->output_mem_dmx_16k_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb, hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_32k, hCPE->hStereoDft->output_mem_dmx_32k_fx, 16, STEREO_DFT_OVL_32k ); + /*flt2fix end*/ + + // stereo_dft_enc_synthesize( hCPE->hStereoDft, sts[0]->input, 0, input_Fs, input_Fs, 0 ); + Word16 out_start_ind, out_end_ind; + Word16 out_12k8_start_ind[CPE_CHANNELS], out_12k8_end_ind[CPE_CHANNELS]; + Word16 out_16k_start_ind = 0, out_16k_end_ind = 0; + move16(); + move16(); + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL ); + + /* iDFT & resampling to 12.8kHz internal sampling rate */ + // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[0] + L_INP_MEM, 0, input_Fs, INT_FS_12k8, 0 ); + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[0] + L_INP_MEM, &out_12k8_start_ind[0], &out_12k8_end_ind[0], 0, input_Fs, INT_FS_12k8, 0, NULL ); + + /* iDFT & resampling to 16kHz internal sampling rate for M channel */ + IF( EQ_32( input_Fs, internal_Fs ) ) + { + // mvr2r( sts[0]->input - STEREO_DFT_OVL_16k, old_inp_16k[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); + Copy32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); + out_16k_start_ind = -STEREO_DFT_OVL_16k; + out_16k_end_ind = out_16k_start_ind + input_frame + STEREO_DFT_OVL_16k; + } + ELSE + { + // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_16k[0] + L_INP_MEM, 0, input_Fs, internal_Fs, 0 ); + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_16k_fx[0] + L_INP_MEM, &out_16k_start_ind, &out_16k_end_ind, 0, input_Fs, internal_Fs, 0, NULL ); + } + + /* DFT Stereo: iDFT of residual signal at 8kHz sampling rate */ + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + { + // mvr2r( sts[1]->old_inp_12k8, old_inp_12k8[1], L_INP_MEM ); + Copy_Scale_sig_16_32_no_sat( sts[1]->old_inp_12k8_fx, old_inp_12k8_fx[1], L_INP_MEM, 16 - 0 ); + // stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM, 1, input_Fs, 8000, 0 ); + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[1] + L_INP_MEM, &out_12k8_start_ind[1], &out_12k8_end_ind[1], 1, input_Fs, 8000, 0, NULL ); + + /* update old input signal buffer */ + // mvr2r( old_inp_12k8[1] + L_FRAME8k, sts[1]->old_inp_12k8, L_INP_MEM ); + Copy_Scale_sig_32_16( old_inp_12k8_fx[1] + L_FRAME8k, sts[1]->old_inp_12k8_fx, L_INP_MEM, 0 - 16 ); + } + + /*fix2flt*/ + hCPE->hStereoDft->icbweRefEner = me2f( hCPE->hStereoDft->icbweRefEner_fx, hCPE->hStereoDft->icbweRefEner_fx_e ); + hCPE->hStereoDft->lbEner = me2f( hCPE->hStereoDft->lbEner_fx, hCPE->hStereoDft->lbEner_fx_e ); + fixedToFloat_arrL( sts[0]->input32_fx + out_start_ind, sts[0]->input + out_start_ind, 16, out_end_ind - out_start_ind ); + fixedToFloat_arrL( old_inp_12k8_fx[0] + L_INP_MEM + out_12k8_start_ind[0], old_inp_12k8[0] + L_INP_MEM + out_12k8_start_ind[0], 16, out_12k8_end_ind[0] - out_12k8_start_ind[0] ); + fixedToFloat_arrL( old_inp_16k_fx[0] + L_INP_MEM + out_16k_start_ind, old_inp_16k[0] + L_INP_MEM + out_16k_start_ind, 16, out_16k_end_ind - out_16k_start_ind ); + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + { + fixedToFloat_arr( sts[1]->old_inp_12k8_fx, sts[1]->old_inp_12k8, 0, L_INP_MEM ); + fixedToFloat_arrL( old_inp_12k8_fx[1] + L_INP_MEM + out_12k8_start_ind[1], old_inp_12k8[1] + L_INP_MEM + out_12k8_start_ind[1], 16, out_12k8_end_ind[1] - out_12k8_start_ind[1] ); + } + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_fx, hCPE->hStereoDft->output_mem_dmx_16k, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, hCPE->hStereoDft->output_mem_dmx_16k_shb, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_32k_fx, hCPE->hStereoDft->output_mem_dmx_32k, 16, STEREO_DFT_OVL_32k ); + /*fix2flt end*/ +#else stereo_dft_enc_synthesize( hCPE->hStereoDft, sts[0]->input, 0, input_Fs, input_Fs, 0 ); /* iDFT & resampling to 12.8kHz internal sampling rate */ @@ -472,7 +562,7 @@ ivas_error ivas_cpe_enc( /* update old input signal buffer */ mvr2r( old_inp_12k8[1] + L_FRAME8k, sts[1]->old_inp_12k8, L_INP_MEM ); } - +#endif /* no iDFT at input sampling rate for Side channel -> reset the buffer */ set_zero( sts[1]->input, input_frame ); } @@ -484,10 +574,17 @@ ivas_error ivas_cpe_enc( for ( n = 0; n < n_CoreChannels; n++ ) { +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], + &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); +#else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; @@ -769,7 +866,664 @@ ivas_error ivas_cpe_enc( pop_wmops(); return error; } +#else +ivas_error ivas_cpe_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t cpe_id, /* i : CPE # identifier */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ + const int16_t input_frame, /* i : input frame length per channel */ + const int16_t nb_bits_metadata /* i : number of metadata bits */ +) +{ + CPE_ENC_HANDLE hCPE; + Encoder_State **sts; + int16_t n, n_CoreChannels; + float old_inp_12k8[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + float old_inp_16k[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz */ + float ener[CPE_CHANNELS]; /* residual energy from Levinson-Durbin */ + float relE[CPE_CHANNELS]; /* frame relative energy */ + float A[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ + float Aw[CPE_CHANNELS][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ + float epsP[CPE_CHANNELS][M + 1]; /* LP prediction errors */ + float lsp_new[CPE_CHANNELS][M]; /* LSPs at the end of the frame */ + float lsp_mid[CPE_CHANNELS][M]; /* ISPs in the middle of the frame */ + int16_t vad_hover_flag[CPE_CHANNELS]; /* VAD hangover flag */ + int16_t attack_flag[CPE_CHANNELS]; /* attack flag (GSC or TC) */ + float realBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[CPE_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float old_wsp[CPE_CHANNELS][L_WSP]; /* old weighted input signal */ + float pitch_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[CPE_CHANNELS][NB_SUBFR]; /* fractional pitch gains */ + int16_t loc_harm[CPE_CHANNELS]; /* harmonicity flag */ + float cor_map_sum[CPE_CHANNELS]; /* speech/music clasif. parameter */ + int16_t vad_flag_dtx[CPE_CHANNELS]; /* HE-SAD flag with additional DTX HO */ + float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + float currFlatness[CPE_CHANNELS]; /* flatness parameter */ + float fft_buff[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ + int16_t tdm_ratio_idx, tdm_ratio_idx_SM; /* temp. TD stereo parameters */ + int16_t tdm_SM_or_LRTD_Pri; /* temp. TD stereo parameters */ + float tdm_last_ratio; /* temp. TD stereo parameters */ + int16_t nb_bits; /* number of DFT stereo side bits */ + float fr_bands[CPE_CHANNELS][2 * NB_BANDS]; /* energy in frequency bands */ + float Etot_LR[CPE_CHANNELS]; /* total energy */ + float lf_E[CPE_CHANNELS][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + int16_t localVAD_HE_SAD[CPE_CHANNELS]; /* HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + float orig_input[CPE_CHANNELS][L_FRAME48k]; + float Etot_last[CPE_CHANNELS]; + int32_t tmp, input_Fs; + int16_t max_bwidth, ivas_format; + ENCODER_CONFIG_HANDLE hEncoderConfig; + int32_t ivas_total_brate; + ivas_error error; + int32_t cpe_brate; + int32_t element_brate_ref; + int16_t last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ + + error = IVAS_ERR_OK; + push_wmops( "ivas_cpe_enc" ); + + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + hEncoderConfig = st_ivas->hEncoderConfig; + max_bwidth = hEncoderConfig->max_bwidth; + ivas_format = hEncoderConfig->ivas_format; + input_Fs = hEncoderConfig->input_Fs; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + element_brate_ref = hCPE->element_brate; + last_bits_frame_nominal = sts[0]->bits_frame_nominal; + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + + tdm_SM_or_LRTD_Pri = 0; + tdm_ratio_idx = -1; + tdm_ratio_idx_SM = -1; + tdm_last_ratio = 0; + + + /*------------------------------------------------------------------* + * CPE initialization - core coder + *-----------------------------------------------------------------*/ + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + sts[n]->idchan = n; + sts[n]->core = -1; + sts[n]->core_brate = -1; /* updated in dtx() */ + sts[n]->max_bwidth = max_bwidth; + if ( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ + { + sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD */ + sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ + } + sts[n]->rate_switching_reset = 0; + } + + mvr2r( data_f_ch0, sts[0]->input, input_frame ); + if ( data_f_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ + { + mvr2r( data_f_ch1, sts[1]->input, input_frame ); + } + + /*----------------------------------------------------------------* + * Stereo technology selection + * Front-VAD on input L and R channels + *----------------------------------------------------------------*/ + + if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) + { + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); + } + + stereo_mode_combined_format_enc( st_ivas, hCPE ); + + if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + + sts[0]->element_mode = hCPE->element_mode; + sts[1]->element_mode = hCPE->element_mode; + + n_CoreChannels = 2; + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + n_CoreChannels = 1; /* in DFT stereo, only M channel is coded */ + + sts[1]->vad_flag = 0; + } + + /*----------------------------------------------------------------* + * dynamically allocate data structures depending on the actual stereo mode + *----------------------------------------------------------------*/ + + if ( ( error = stereo_memory_enc( hCPE, input_Fs, max_bwidth, &tdm_last_ratio, ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + + + /*----------------------------------------------------------------* + * Set TD stereo parameters + *----------------------------------------------------------------*/ + + if ( ( error = stereo_set_tdm( hCPE, input_frame ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*----------------------------------------------------------------* + * Resets/updates in case of stereo switching + *----------------------------------------------------------------*/ + + stereo_switching_enc( hCPE, sts[0]->old_input_signal, input_frame ); + /*----------------------------------------------------------------* + * Temporal inter-channel alignment, stereo adjustment + *----------------------------------------------------------------*/ + + stereo_tca_enc( hCPE, input_frame ); + + /*----------------------------------------------------------------* + * Input signal buffering - needed in IC-BWE and TD ITD in MDCT stereo + *----------------------------------------------------------------*/ + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( sts[n]->input, orig_input[n], input_frame ); + + if ( hCPE->hStereoICBWE != NULL ) + { + hCPE->hStereoICBWE->dataChan[n] = &orig_input[n][0]; + } + } + + /*---------------------------------------------------------------* + * Time Domain Transient Detector + *---------------------------------------------------------------*/ + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( sts[n]->hTranDet == NULL ) + { + currFlatness[n] = 0; + continue; + } + + if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + { + RunTransientDetection( sts[n]->input, input_frame, sts[n]->hTranDet ); + } + currFlatness[n] = GetTCXAvgTemporalFlatnessMeasure( sts[n]->hTranDet, NSUBBLOCKS, 0 ); + } + + /* Synchonize detection for downmix-based stereo */ + if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) + { + set_transient_stereo( hCPE, currFlatness ); + } + + /*----------------------------------------------------------------* + * Configuration of stereo encoder + *----------------------------------------------------------------*/ + + for ( n = 0; n < n_CoreChannels; n++ ) + { + /* Force to MODE1 in IVAS */ + sts[n]->codec_mode = MODE1; + + sts[n]->element_mode = hCPE->element_mode; + } + + + if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || + ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ + { + if ( st_ivas->hQMetaData != NULL ) + { + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) + { + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + else + { + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + } + else + { + /* note; "bits_frame_nominal" needed in TD stereo as well */ + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + } + + if ( hCPE->element_mode == IVAS_CPE_TD ) + { + if ( hCPE->hStereoTD->tdm_LRTD_flag ) + { + sts[0]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); + sts[1]->bits_frame_nominal = (int16_t) ( ( hCPE->element_brate >> 1 ) / FRAMES_PER_SEC ); + } + else + { + stereo_dft_config( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + } + + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + /* compute bit-rate surplus per channel in combined format coding */ + int32_t brate_surplus[CPE_CHANNELS]; + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; + brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; + } + + /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */ + for ( n = 0; n < n_CoreChannels; n++ ) + { + if ( st_ivas->hMCT ) + { + int16_t lfe_bits; + lfe_bits = ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ? st_ivas->hLFE->lfe_bits : 0 ); + sts[n]->total_brate = hCPE->element_brate; + sts[n]->bits_frame_nominal = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); + sts[n]->bits_frame_channel = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC - lfe_bits - nb_bits_metadata ) / st_ivas->hMCT->nchan_out_woLFE ); + } + else + { + sts[n]->bits_frame_nominal = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); + sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_CoreChannels ); + sts[n]->total_brate = hCPE->element_brate / n_CoreChannels; + + /* subtract bit-rate for combined format coding */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); + sts[n]->total_brate += brate_surplus[n]; + } + } + } + + /* reconfiguration in case of bitrate switching */ + if ( hCPE->element_brate != hCPE->last_element_brate && st_ivas->hMCT == NULL ) + { + initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 0 ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + } + } + + /*----------------------------------------------------------------* + * Stereo processing + * Stereo down-mix + *----------------------------------------------------------------*/ + + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + stereo_dft_hybrid_ITD_flag( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max ); + + /* Time Domain ITD compensation using extrapolation */ + stereo_td_itd( hCPE->hStereoDft->hItd, hCPE->hStereoDft->input_mem_itd, hCPE->hStereoDft->hConfig->hybrid_itd_flag, hCPE->hStereoDft->dft_ovl, sts, input_frame, hCPE->input_mem ); + + /* DFT on right and left input channels */ + stereo_dft_enc_analyze( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT, hCPE->input_mem ); + + sts[0]->total_brate = ( sts[0]->bits_frame_nominal + 10 ) * FRAMES_PER_SEC; /* add small overhead; st[0]->total_brate used in coder_type_modif() */ + /* Update DFT Stereo memories */ + stereo_dft_enc_update( hCPE->hStereoDft, sts[0]->max_bwidth ); + + /* DFT stereo processing */ + stereo_dft_enc_process( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); + } + else if ( hCPE->element_mode == IVAS_CPE_TD ) + { + /* Determine the energy ratio between the 2 channels */ + tdm_ratio_idx = stereo_tdm_ener_analysis( + ivas_format, + hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); + + /* Compute the downmix signal based on the ratio index */ + stereo_tdm_downmix( hCPE->hStereoTD, sts[0]->input, sts[1]->input, input_frame, tdm_ratio_idx, ( ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) ? tdm_SM_or_LRTD_Pri : 0 ), tdm_ratio_idx_SM ); + + /* signal the bitrate for BW selection in the SCh */ + sts[0]->bits_frame_channel = 0; + sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); + sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + if ( st_ivas->hQMetaData != NULL ) + { + sts[1]->bits_frame_channel -= st_ivas->hQMetaData->metadata_max_bits; + } + + Etot_last[0] = sts[0]->hNoiseEst->Etot_last; + Etot_last[1] = sts[1]->hNoiseEst->Etot_last; + } + else if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + stereo_td_itd_mdct_stereo( hCPE, vad_flag_dtx, vad_hover_flag, input_frame ); + } + + /*----------------------------------------------------------------* + * DFT stereo: iDFT and resampling on both channels + *----------------------------------------------------------------*/ + + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + int32_t internal_Fs; + + internal_Fs = getTcxonly_ivas( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); + + /* iDFT at input sampling rate */ + stereo_dft_enc_synthesize( hCPE->hStereoDft, sts[0]->input, 0, input_Fs, input_Fs, 0 ); + + /* iDFT & resampling to 12.8kHz internal sampling rate */ + stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[0] + L_INP_MEM, 0, input_Fs, INT_FS_12k8, 0 ); + + /* iDFT & resampling to 16kHz internal sampling rate for M channel */ + if ( input_Fs == internal_Fs ) + { + mvr2r( sts[0]->input - STEREO_DFT_OVL_16k, old_inp_16k[0] + L_INP_MEM - STEREO_DFT_OVL_16k, input_frame + STEREO_DFT_OVL_16k ); + } + else + { + stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_16k[0] + L_INP_MEM, 0, input_Fs, internal_Fs, 0 ); + } + + /* DFT Stereo: iDFT of residual signal at 8kHz sampling rate */ + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) + { + mvr2r( sts[1]->old_inp_12k8, old_inp_12k8[1], L_INP_MEM ); + stereo_dft_enc_synthesize( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM, 1, input_Fs, 8000, 0 ); + + /* update old input signal buffer */ + mvr2r( old_inp_12k8[1] + L_FRAME8k, sts[1]->old_inp_12k8, L_INP_MEM ); + } + + /* no iDFT at input sampling rate for Side channel -> reset the buffer */ + set_zero( sts[1]->input, input_frame ); + } + + + /*----------------------------------------------------------------* + * Front Pre-processing + *----------------------------------------------------------------*/ + + for ( n = 0; n < n_CoreChannels; n++ ) + { + error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], + &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + } + + /* sanity check -> DTX not supported for more than one SCEs/CPEs */ + if ( st_ivas->nSCE + st_ivas->nCPE > 1 ) + { + if ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) + { + sts[0]->core_brate = -1; + sts[0]->total_brate = hCPE->element_brate; + } + } + + /*----------------------------------------------------------------* + * Stereo DTX updates + *----------------------------------------------------------------*/ + + if ( ivas_format == MASA_FORMAT && nb_bits_metadata > 0 && hCPE->hCoreCoder[0]->Opt_DTX_ON ) + { + if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) + { + reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + } + } + + /* MDCT stereo DTX: active/inactive frame decision; compute FD CNG coherence */ + if ( hCPE->element_mode == IVAS_CPE_MDCT && hEncoderConfig->Opt_DTX_ON ) + { + stereoFdCngCoherence( sts, hCPE->last_element_mode, fft_buff ); + + /* Reset metadata */ + if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT ) ) + { + reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata ); + } + } + + /*----------------------------------------------------------------* + * Core codec configuration + *----------------------------------------------------------------*/ + + /* IGF reconfiguration */ + for ( n = 0; n < n_CoreChannels; n++ ) + { + if ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->element_mode != hCPE->last_element_mode || ( hCPE->element_mode == IVAS_CPE_TD && sts[0]->bits_frame_nominal != last_bits_frame_nominal ) || sts[n]->last_bwidth != sts[n]->bwidth ) && ( n == 0 || hCPE->element_mode == IVAS_CPE_MDCT ) ) + { + int16_t igf; + igf = getIgfPresent( sts[n]->element_mode, sts[n]->bits_frame_nominal * FRAMES_PER_SEC, sts[n]->max_bwidth, sts[n]->rf_mode ); + if ( ( error = IGF_Reconfig( &sts[n]->hIGFEnc, igf, 0, sts[n]->bits_frame_nominal * FRAMES_PER_SEC, sts[n]->max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + if ( hCPE->element_mode == IVAS_CPE_MDCT && st_ivas->hMCT == NULL ) + { + /* set coded BW for MDCT stereo */ + set_bw_stereo( hCPE ); + + /* reconfiguration of MDCT stereo */ + if ( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) ) + { + initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, sts[0]->bwidth, 0, NULL, 0 ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + + if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) + { + if ( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + + /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ + for ( n = 0; n < n_CoreChannels; n++ ) + { + if ( ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) && hCPE->element_mode == IVAS_CPE_DFT ) + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->core_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + } + else + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, sts[0]->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + } + } + + /* configure TD stereo encoder */ + if ( hCPE->element_mode == IVAS_CPE_TD ) + { + tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); + + tdm_configure_enc( ivas_format, st_ivas->ism_mode, hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); + + if ( hEncoderConfig->Opt_DTX_ON ) + { + stereo_cng_upd_counters( hCPE->hStereoCng, hCPE->element_mode, -1, NULL, sts[0]->hTdCngEnc->burst_ho_cnt, NULL ); + } + } + + /* modify the coder_type depending on the total_brate per channel */ + for ( n = 0; n < n_CoreChannels; n++ ) + { + if ( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->element_mode != IVAS_CPE_TD ) || n == 0 ) /* modify coder_type of primary channel */ + { + /* limit coder_type depending on the bitrate */ + coder_type_modif( sts[n], relE[n] ); + } + } + + /*----------------------------------------------------------------* + * Write IVAS format signaling in SID frames + *----------------------------------------------------------------*/ + + if ( sts[0]->core_brate == SID_2k40 ) + { + ivas_write_format_sid( ivas_format, hCPE->element_mode, sts[0]->hBstr ); + } + + /*----------------------------------------------------------------* + * DFT Stereo residual coding + * DFT Stereo parameters writing into the bitstream + *----------------------------------------------------------------*/ + + cpe_brate = 0; + if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + if ( hEncoderConfig->Opt_DTX_ON ) + { + if ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) + { + /* Reconfigure DFT Stereo for inactive frames */ + if ( sts[0]->core_brate == SID_2k40 ) + { + stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + else + { + stereo_dft_config( hCPE->hStereoDft->hConfig, FRAME_NO_DATA, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + + stereo_dft_cng_side_gain( hCPE->hStereoDft, hCPE->hStereoCng, sts[0]->core_brate, sts[0]->last_core_brate, sts[0]->bwidth ); + } + else + { + stereo_cng_upd_counters( hCPE->hStereoCng, hCPE->element_mode, hCPE->hStereoDft->nbands, hCPE->hStereoDft->sidSideGain, sts[0]->hTdCngEnc->burst_ho_cnt, &hCPE->hStereoDft->coh_fade_counter ); + } + } + + /* Write stereo bitstream */ + cpe_brate = st_ivas->hCPE[0]->element_brate; + + /* DFT stereo side bits */ + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && cpe_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) + { + nb_bits = 0; /* Only mono downmix is transmitted in this case */ + } + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) + { + nb_bits = hCPE->hMetaData->nb_bits_tot; + } + else + { + stereo_dft_enc_write_BS( hCPE, &nb_bits ); + } + + /* Residual coding in MDCT domain */ + if ( !( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) ) + { + int16_t max_bits = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + max_bits -= nb_bits_metadata; + if ( hCPE->brate_surplus < 0 ) + { + max_bits += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + } + } + + stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); + } + + if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 ) + { + assert( ( nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); + } + else + { + /* Flexible total bitrate in M channel */ + sts[0]->total_brate = hCPE->element_brate - ( nb_bits * FRAMES_PER_SEC ); + } + + /* subtract metadata bitbudget */ + sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); + + /* subtract bit-rate for combined format coding */ + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + sts[0]->total_brate += hCPE->brate_surplus; + } + } + + + /*----------------------------------------------------------------* + * Core Encoder + *----------------------------------------------------------------*/ + + if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + hCPE->last_element_brate = hCPE->element_brate; + hCPE->last_element_mode = hCPE->element_mode; + + if ( ivas_format == MASA_ISM_FORMAT ) + { + hCPE->element_brate = element_brate_ref; + } + + if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) + { + /* update input samples buffer */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( orig_input[n], sts[n]->old_input_signal, input_frame ); + } + } + else if ( hCPE->element_mode == IVAS_CPE_DFT ) + { + mvr2r( sts[0]->input, sts[0]->old_input_signal, input_frame ); + } + else if ( st_ivas->hMCT == NULL ) /* note: in MCT, input buffers are updated later in ivas_mct_enc() */ + { + /* update input samples buffer */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( sts[n]->input, sts[n]->old_input_signal, input_frame ); + } + } + + if ( hCPE->hFrontVad[0] != NULL ) + { + hCPE->hFrontVad[0]->ini_frame++; + hCPE->hFrontVad[0]->ini_frame = min( hCPE->hFrontVad[0]->ini_frame, MAX_FRAME_COUNTER ); + } + + /* Store previous attack detection flag */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + sts[n]->hTranDet->transientDetector.prev_bIsAttackPresent = sts[n]->hTranDet->transientDetector.bIsAttackPresent; + } + + + pop_wmops(); + return error; +} +#endif /*------------------------------------------------------------------------- * create_cpe_enc() @@ -1275,7 +2029,7 @@ ivas_error create_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_16( ivas_format, STEREO_FORMAT ) ) { - IF( ( error = initMdctItdHandling_fx( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = initMdctItdHandling( hCPE->hStereoMdct, input_Fs ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index bd7b63a4c24ff068cce870fa0c716dca88254ea2..61a8092ca67773bdba18e7689be0b88932ce8f3c 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -36,8 +36,7 @@ #include #include "cnst.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 23dee7bc6ff0b7091ea2b6f7b0fa00962849c6ce..821389abc036812cfb0161a315d60f77a485a1c2 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -40,13 +40,17 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* * ivas_enc() * * Principal IVAS encoder routine *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t *data, /* i : input signal */ @@ -60,6 +64,9 @@ ivas_error ivas_enc( BSTR_ENC_HANDLE hMetaData; int16_t nb_bits_metadata[MAX_SCE + 1]; float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#ifdef IVAS_FLOAT_FIXED + Word16 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#endif int32_t ivas_total_brate; ivas_error error; error = IVAS_ERR_OK; @@ -108,7 +115,30 @@ ivas_error ivas_enc( set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); } } +#ifdef IVAS_FLOAT_FIXED + FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + data_fx[n] = st_ivas->p_data_fx[n]; + } + + n = 0; + WHILE( n < nchan_inp ) + { + FOR( i = 0; i < n_samples_chan; i++ ) + { + data_fx[n][i] = (Word16) ( data[i * nchan_inp + n] ); + } + n++; + } + IF( n_samples_chan < input_frame ) + { + FOR( n = 0; n < nchan_inp; n++ ) + { + set16_fx( data_fx[n] + n_samples_chan, 0, input_frame - n_samples_chan ); + } + } +#endif if ( ivas_format == SBA_FORMAT ) { @@ -376,12 +406,68 @@ ivas_error ivas_enc( { n = hEncoderConfig->nchan_ism; hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; +#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 ) ) + { + hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( 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, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hCPE[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, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif /* SBA metadata encoding and SBA metadata bitstream writing */ if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { @@ -433,75 +519,571 @@ ivas_error ivas_enc( { st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; -#ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + } - for ( int ii = 0; ii < input_frame; ii++ ) + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { - if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) - max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + return error; } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - if ( (Word32) max_val == 0 ) - q_data_lfe_ch = 31; - else - q_data_lfe_ch = norm_l( (Word32) max_val ); + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); - for ( int ii = 0; ii < input_frame; ii++ ) + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { - data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + return error; } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + /* encode Parametric MC parameters and write bitstream */ + ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); + + if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ + } + + ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); + + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; + + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + - ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); + pop_wmops(); + return error; +} #else - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); -#endif // IVAS_FLOAT_FIXED +ivas_error ivas_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal */ + const Word16 n_samples /* i : number of input samples */ +) +{ + Word16 i, n, input_frame, n_samples_chan, nchan_inp /*, scale*/; + Word32 input_Fs; + IVAS_FORMAT ivas_format; + ENCODER_CONFIG_HANDLE hEncoderConfig; + BSTR_ENC_HANDLE hMetaData; + Word16 nb_bits_metadata[MAX_SCE + 1]; + float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 ivas_total_brate; + ivas_error error; + error = IVAS_ERR_OK; + move32(); + + push_wmops( "ivas_enc" ); + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + + hEncoderConfig = st_ivas->hEncoderConfig; + + input_Fs = hEncoderConfig->input_Fs; + ivas_format = hEncoderConfig->ivas_format; + nchan_inp = hEncoderConfig->nchan_inp; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + move32(); + move16(); + move32(); + + input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); + IF( NE_16( nchan_inp, 1 ) ) + { + n_samples_chan = div_l( L_deposit_l( n_samples ), nchan_inp ); + n_samples_chan = shl( n_samples_chan, 1 ); + } + ELSE + { + n_samples_chan = n_samples; + move16(); + } + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /*----------------------------------------------------------------* + * convert 'Word16' input data to 'Word32' in Q11 format + *----------------------------------------------------------------*/ + + FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed + data_fx[n] = st_ivas->p_data_fx[n]; + } + + st_ivas->q_data_fx = 11; // Q-factor of the input buffer + move16(); + n = 0; + move16(); + WHILE( LT_16( n, nchan_inp ) ) + { + FOR( i = 0; i < n_samples_chan; i++ ) + { + data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed + data_fx[n][i] = L_mult0( data[add( imult1616( i, nchan_inp ), n )], shl( 1, st_ivas->q_data_fx ) ); + move32(); } + n = add( n, 1 ); + } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( LT_16( n_samples_chan, input_frame ) ) + { + FOR( n = 0; n < nchan_inp; n++ ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed + set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); + } + } + + IF( EQ_32( ivas_format, SBA_FORMAT ) ) + { + IF( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) + { + IF( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*----------------------------------------------------------------* + * HP filtering + *----------------------------------------------------------------*/ + + n = getNumChanAnalysis_fx( st_ivas ); + + /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ + FOR( i = 0; i < n; i++ ) + { + test(); + test(); + IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) + { + hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); +#if 0 // To be enabled, precision loss observed + hp20_fix32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif + } + ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) + { + hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); // To be removed +#if 0 // To be enabled, precision loss observed + hp20_fix32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); +#endif + } + } + +#if 0 /* Fixed to float conversion To be removed */ + for ( i = 0; i < n; i++ ) + { + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); + } +#endif // 1 + + + /*----------------------------------------------------------------* + * write IVAS format signaling + *----------------------------------------------------------------*/ + + ivas_write_format( st_ivas ); + + /*----------------------------------------------------------------* + * Encoding + *----------------------------------------------------------------*/ + + if ( ivas_format == STEREO_FORMAT ) + { + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the ISM format encoder */ + if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + ivas_param_ism_enc( st_ivas, data_f, input_frame ); + + /* Stereo DMX generation */ + ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); + + /* Core coding of Stereo DMX */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + else if ( st_ivas->ism_mode == ISM_MODE_DISC ) { - /* encode MC ParamUpmix parameters and write bitstream */ - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + { + /* MASA configuration */ + if ( ivas_format == MASA_FORMAT ) + { + ivas_masa_enc_reconfigure( st_ivas ); + } - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; -#ifdef IVAS_FLOAT_FIXED - Word16 q_data_lfe_ch; - Word32 data_lfe_ch_fx[L_FRAME48k]; - float max_val = 0; + if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + { + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ + + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_FORMAT ) + { + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_format == SBA_FORMAT ) + { + ivas_sba_getTCs( data_f, st_ivas, input_frame ); + } - for ( int ii = 0; ii < input_frame; ii++ ) + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - if ( max_val < (float) fabs( data_f[LFE_CHANNEL][ii] ) ) - max_val = (float) fabs( data_f[LFE_CHANNEL][ii] ); + return error; } + } + } + else if ( ivas_format == MASA_ISM_FORMAT ) + { + float *data_separated_object; - if ( (Word32) max_val == 0 ) - q_data_lfe_ch = 31; + int16_t idx_separated_object; + int16_t flag_omasa_ener_brate; + + flag_omasa_ener_brate = 0; + + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) + { + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); + } + + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + idx_separated_object = 0; + + data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + } + + /* Encode ISMs transport channels */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); + + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + n = st_ivas->hEncoderConfig->nchan_ism; + } + + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + if ( st_ivas->nSCE > 0 ) + { + /* update pointer to the buffer of indices (ISM indices were alredy written) */ + hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; + } + + /* Encode MASA parameters and write MASA metadata bitstream */ + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_enc( st_ivas ); + + /* Encode MASA transport channels */ + if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_ISM_FORMAT ) + { + int16_t planar_sba_orig; + planar_sba_orig = hEncoderConfig->sba_planar; + + /* Analyze objects and determine needed audio signals */ + ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + /*once SBA and ISM are combined into SBA signal then disable planar flag*/ + hEncoderConfig->sba_planar = 0; + if ( st_ivas->nchan_transport == 1 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } else - q_data_lfe_ch = norm_l( (Word32) max_val ); + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } - for ( int ii = 0; ii < input_frame; ii++ ) + hEncoderConfig->sba_planar = planar_sba_orig; + } + else + { + n = hEncoderConfig->nchan_ism; + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { - data_lfe_ch_fx[ii] = (Word32) ( data_f[LFE_CHANNEL][ii] * ( 1 << q_data_lfe_ch ) ); + return error; } - ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); -#else - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); -#endif // IVAS_FLOAT_FIXED + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* get SBA TCs */ + ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + } + + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( EQ_32( ivas_format, MC_FORMAT ) ) + { + /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ + if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + // hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + IF( st_ivas->nSCE > 0 ) + { + hMetaData = st_ivas->hSCE[sub( st_ivas->nSCE, 1 )]->hMetaData; + } + ELSE + { + hMetaData = st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hMetaData; + } + + /* LFE low pass filter */ + ivas_lfe_lpf_enc_apply_fx( st_ivas->hLfeLpf, data_fx[LFE_CHANNEL], input_frame ); + + /* LFE channel encoder */ + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + IF( st_ivas->nSCE > 0 ) + { + st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + } + ELSE + { + st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + } + + ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); + } +#if 1 // To be removed + fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); +#endif + + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); + + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); +#if 1 // To be removed + fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); +#endif if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; @@ -586,3 +1168,4 @@ ivas_error ivas_enc( pop_wmops(); return error; } +#endif diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index cda2b4676e8a766b91ee14424b0df442fb8a959d..06691ff51941e2e2e22e9e55dff86ad8b282f633 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -37,20 +37,21 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ -#define MIN_POOL_SIZE 24 -#define MAX_UPDATE_RATE 0.8f -#define MIN_POOL_SIZE_DTX 40 -#define MAX_UPDATE_RATE_DTX 0.4f +#define MIN_POOL_SIZE 24 +#define MIN_POOL_SIZE_DTX 40 #ifdef IVAS_FLOAT_FIXED #define MAX_UPDATE_RATE_Q31 ( 1717986944 ) #define MAX_UPDATE_RATE_DTX_Q31 ( 858993472 ) +#else +#define MAX_UPDATE_RATE 0.8f +#define MAX_UPDATE_RATE_DTX 0.4f #endif @@ -60,9 +61,80 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word16 *q_In_FR, const Word16 num_chans, const Word16 num_bins, Word16 stride, Word32 **pFb_bin_to_band, const Word16 *pFb_start_bin_per_band, const Word16 *pFb_active_bins_per_band, const Word16 start_band, const Word16 end_band, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_cov_real[IVAS_SPAR_MAX_CH], const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); -#endif +#else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); +#endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_spar_covar_enc_open_fx() + * + * Allocate and initialize SPAR Covar. encoder handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_spar_covar_enc_open_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +) +{ + ivas_enc_cov_handler_state_t *hCovState; + ivas_cov_smooth_cfg_t cov_smooth_cfg; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + IF( ( hCovState = (ivas_enc_cov_handler_state_t *) malloc( sizeof( ivas_enc_cov_handler_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); + } + + cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; + move16(); + cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_Q31; + move32(); + cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; + move16(); + IF( EQ_32( smooth_mode, COV_SMOOTH_MC ) ) + { + cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 + move32(); + cov_smooth_cfg.min_pool_size = 20; + move16(); + } + + IF( NE_32( ( error = ivas_spar_covar_smooth_enc_open_fx( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } + + cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_DTX_Q31; + move32(); + cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; + move16(); + + IF( NE_32( ( error = ivas_spar_covar_smooth_enc_open_fx( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } + + hCovState->num_bins = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + hCovState->prior_dtx_present = 0; + move16(); + + set_zero_fx( hCovState->bb_var_lt_fx, FOA_CHANNELS ); + hCovState->prior_var_flag = -1; + move16(); + + *hCovEnc = hCovState; + + return error; +} +#else /*------------------------------------------------------------------------- * ivas_spar_covar_enc_open() * @@ -90,16 +162,10 @@ ivas_error ivas_spar_covar_enc_open( } cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_Q31; -#endif cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; if ( smooth_mode == COV_SMOOTH_MC ) { -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 -#endif cov_smooth_cfg.max_update_rate = 1.0f; cov_smooth_cfg.min_pool_size = 20; } @@ -109,9 +175,6 @@ ivas_error ivas_spar_covar_enc_open( return error; } -#ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = MAX_UPDATE_RATE_DTX_Q31; -#endif cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE_DTX; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; @@ -130,8 +193,41 @@ ivas_error ivas_spar_covar_enc_open( return error; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_spar_covar_enc_close_fx() + * + * Deallocate SPAR Covar. encoder handle + *------------------------------------------------------------------------*/ + +void ivas_spar_covar_enc_close_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +) +{ + ivas_enc_cov_handler_state_t *hCovState; + + test(); + IF( hCovEnc == NULL || *hCovEnc == NULL ) + { + return; + } + + hCovState = *hCovEnc; + + ivas_spar_covar_smooth_enc_close_fx( &hCovState->pCov_state, nchan_inp ); + + ivas_spar_covar_smooth_enc_close_fx( &hCovState->pCov_dtx_state, nchan_inp ); + + free( *hCovEnc ); + *hCovEnc = NULL; + + return; +} +#else /*------------------------------------------------------------------------- * ivas_spar_covar_enc_close() * @@ -161,6 +257,7 @@ void ivas_spar_covar_enc_close( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -325,9 +422,7 @@ ELSE IF( EQ_16( nchan_transport, 3 ) ) return activeW_flag; } -#endif - - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_spar_get_activeW_flag() * @@ -438,6 +533,7 @@ static int16_t ivas_spar_get_activeW_flag( return activeW_flag; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -544,7 +640,7 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - mvl2l( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); q_cov_dtx_real[i][j] = q_cov_real[i][j]; move16(); } @@ -558,9 +654,9 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - mvl2l( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], pFb->filterbank_num_bands ); - mvl2l( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); - mvs2s( hCovEnc->pCov_state->q_cov_real_per_band[i][j], hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], pFb->filterbank_num_bands ); + Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy( hCovEnc->pCov_state->q_cov_real_per_band[i][j], hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); } } hCovEnc->prior_dtx_present = 1; @@ -588,7 +684,7 @@ void ivas_enc_cov_handler_process_fx( { FOR( j = 0; j < num_ch; j++ ) { - mvl2l( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + Copy32( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); } } hCovEnc->prior_dtx_present = 1; @@ -599,8 +695,7 @@ void ivas_enc_cov_handler_process_fx( return; } -#endif - +#else /*-----------------------------------------------------------------------------------------* * Function ivas_enc_cov_handler_process() * @@ -707,6 +802,7 @@ void ivas_enc_cov_handler_process( return; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -843,9 +939,7 @@ static void ivas_band_cov_fx( return; } -#endif - - +#else static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, @@ -914,3 +1008,4 @@ static void ivas_band_cov( return; } +#endif diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 14ed149e12b1a901742b6478ae3b11898e2e3d45..900f0bb49b0850738f755240febb8c93c0f38e41 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -31,17 +31,20 @@ *******************************************************************************************************/ #include +#include #include "options.h" #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include "math.h" -#include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif +#ifdef DEBUGGING +#include "debug.h" +#endif #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -83,7 +86,7 @@ static ivas_error ivas_get_dyn_freq_model( curr_bps -= ( curr_dist[i] * pArith->saved_dist_arr[0][i] ); } curr_bps_min = curr_bps; -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING dbgwrite_txt( &curr_bps_min, 1, "float_curr_bps_min.txt", NULL ); #endif model_idx = 0; @@ -95,7 +98,7 @@ static ivas_error ivas_get_dyn_freq_model( { curr_bps_new -= ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ); } -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING dbgwrite_txt( &curr_bps_new, 1, "float_curr_bps_new.txt", NULL ); #endif if ( curr_bps_new < curr_bps_min ) @@ -159,7 +162,7 @@ static ivas_error ivas_get_dyn_freq_model_fx( curr_bps = L_sub( curr_bps, curr_dist[i] * pArith->saved_dist_arr[0][i] ); } curr_bps_min = curr_bps; -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING { float a = curr_bps_min / 32768.0f; dbgwrite_txt( &a, 1, "fixed_curr_bps_min.txt", NULL ); @@ -174,7 +177,7 @@ static ivas_error ivas_get_dyn_freq_model_fx( { curr_bps_new = L_sub( curr_bps_new, ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ) ); } -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING { float a = curr_bps_new / 32768.0f; dbgwrite_txt( &a, 1, "fixed_curr_bps_new.txt", NULL ); @@ -246,15 +249,22 @@ static Word16 ivas_arith_encode_array( FOR( i = 0; i < in_len; i++ ) { ind = sub( pInput[i], pArith->vals[0] ); - +#ifdef IVAS_FLOAT_FIXED + ivas_ari_encode_14bits_ext_fx( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); +#else ivas_ari_encode_14bits_ext( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); +#endif IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; } } +#ifdef IVAS_FLOAT_FIXED + ivas_ari_done_encoding_14bits_fx( hMetaData, &as ); +#else ivas_ari_done_encoding_14bits( hMetaData, &as ); +#endif IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 65748bfbae9e1cf386c67c7db023c8a8a3fcfbc3..78e265baaddab83f174a90ae1d969612b288481b 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -39,11 +39,13 @@ #include "prot.h" #include "ivas_prot.h" #include "prot_fx_enc.h" -#include "prot_fx1.h" #include #include "wmc_auto.h" #include - +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#include "prot_fx.h" +#endif /*-----------------------------------------------------------------------------------------* * Function front_vad() @@ -323,8 +325,8 @@ ivas_error front_vad_create_fx( hFrontVad->lp_speech_fx = 23040; /* Initialize the long-term active speech level in dB */ hFrontVad->lp_noise_fx = 0; /* Initialize the long-term noise level in dB */ - set32_fx( hFrontVad->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); - set32_fx( hFrontVad->buffer_12k8_fx, 0, i_mult( 3, shr( L_FRAME, 1 ) ) ); + set16_fx( hFrontVad->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( hFrontVad->buffer_12k8_fx, 0, i_mult( 3, shr( L_FRAME, 1 ) ) ); hFrontVad->mem_preemph_fx = 0; hFrontVad->ini_frame = 0; hFrontVad->hVAD->vad_flag = 1; @@ -384,7 +386,501 @@ void front_vad_destroy( * * Standalone front-VAD module for SPAR *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error front_vad_spar( + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const float *omni_in, /* i : omnidirectional input signal */ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const int16_t input_frame /* i : input frame length */ +) +{ + FRONT_VAD_ENC_HANDLE hFrontVad; + float input[L_FRAME48k]; + int16_t vad_flag_dtx[1]; + float fr_bands[1][2 * NB_BANDS]; + Word32 fr_bands_fx[1][2 * NB_BANDS] = { { 0 } }; + float Etot[1]; + Word16 Etot_fx[1]; + float lf_E[1][2 * VOIC_BINS]; + + int16_t localVAD_HE_SAD[1]; + int16_t vad_hover_flag[1]; + float band_energies[2 * NB_BANDS]; + int16_t high_lpn_flag; + Encoder_State *st; + float tmpN[NB_BANDS], tmpE[NB_BANDS]; + Word32 tmpN_fx[NB_BANDS] = { 0 }; + Word32 tmpE_fx[NB_BANDS] = { 0 }; + float corr_shift; + float dummy, res_energy; + Word16 corr_shift_fx; +#if 1 + + // Word32 res_energy_fx; + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], Aw_fx[NB_SUBFR16k * ( M + 1 )]; + +// Word32 epsP_fx[M + 1]; +// Word16 epsP_h[M + 1]; +// Word16 epsP_l[M + 1]; +// Word16 alw_voicing_fx[2]; +// Word16 lsp_new_fx[M]; +// Word16 lsp_mid_fx[M]; +#endif + float A[NB_SUBFR16k * ( M + 1 )], Aw[NB_SUBFR16k * ( M + 1 )]; + float epsP[M + 1]; + float lsp_new[M]; + float lsp_mid[M]; + int16_t alw_pitch_lag_12k8[2]; + float alw_voicing[2]; + float cor_map_sum; + float ncharX; + float sp_div; + float non_staX; + int16_t loc_harm; + float S_map[L_FFT / 2]; +#if 1 + + + // Word32 lf_E_fx[1][2 * VOIC_BINS]; + + + // Word16 non_staX_fx; + +#endif + + // Word16 sp_floor; + // Word16 sp_div_fx; + // Word16 Q_sp_div; + Word16 cor_map_sum_fx; + Word16 dummy_fx; + Word16 S_map_fx[L_FFT / 2]; + // Word16 relE_fx; + Word16 *wsp_fx; + float *inp_12k8; +#if 1 + Word16 *inp_12k8_fx; +#endif + float old_wsp[L_WSP]; + Word16 old_wsp_fx[L_WSP]; + float *wsp; + + float relE; + + int16_t flag_spitch; + float PS[L_FRAME / 2]; + int16_t old_pitch; + ivas_error error; +#ifdef DUMP_VAD_SPAR + FILE *fptmpN_fl = fopen( "tmpN_fl.txt", "ab+" ); + FILE *fptmpE_fl = fopen( "tmpE_fl.txt", "ab+" ); + FILE *fpbckr_fl = fopen( "bckr_fl.txt", "ab+" ); + + FILE *fptmpN_fx = fopen( "tmpN_fx.txt", "ab+" ); + FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); + FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" ); +#endif +#if 1 + FILE *fp_pitch = fopen( "fp_pitch.txt", "ab+" ); + FILE *fp_voice = fopen( "fp_voice.txt", "ab+" ); + /* FILE *fpbckr_fl = fopen( "bckr_fl.txt", "ab+" ); + + FILE *fptmpN_fx = fopen( "tmpN_fx.txt", "ab+" ); + FILE *fptmpE_fx = fopen( "tmpE_fx.txt", "ab+" ); + FILE *fpbckr_fx = fopen( "bckr_fx.txt", "ab+" );*/ +#endif + push_wmops( "front_vad_SPAR" ); + error = IVAS_ERR_OK; + hFrontVad = hSpar->hFrontVad; + st = hSpar->hCoreCoderVAD; + + if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= SBA_DTX_BITRATE_THRESHOLD ) + { + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + inp_12k8 = hFrontVad->buffer_12k8; + Word16 Q_bands = Q31; +#if 1 + Word16 Q_inp_12k8 = Q10; +#endif +#if 1 + inp_12k8_fx = hFrontVad->buffer_12k8_fx; + +#endif + mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); + floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q10, L_WSP_MEM ); + floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q10, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q10, 3 ); + // st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); + + MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); + wsp = old_wsp + L_WSP_MEM; + wsp_fx = old_wsp_fx + L_WSP_MEM; + + st->core_brate = -1; /* updated in dtx() */ + st->input_bwidth = st->last_input_bwidth; + + /*------------------------------------------------------------------* + * compensate for SPAR filterbank delay + *-----------------------------------------------------------------*/ + + st->input = input; + mvr2r( omni_in, st->input, input_frame ); + + delay_signal_float( st->input, input_frame, hFrontVad->delay_buf, hFrontVad->delay_samples ); + + /*------------------------------------------------------------------* + * Front-VAD + *-----------------------------------------------------------------*/ + + if ( ( error = front_vad( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands, Etot, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies, &PS[0], &st->Bin_E[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + Q_bands = Q10; + // floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); + // Q_bands = Q_factor_arrL( fr_bands[0], 2 * NB_BANDS ); + floatToFixed_arrL( fr_bands[0], fr_bands_fx[0], Q_bands + QSCALE, 2 * NB_BANDS ); + floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_bands + QSCALE, NB_BANDS ); +#ifndef MSAN_FIX + floatToFixed_arrL( tmpE, tmpE_fx, Q_bands + QSCALE, NB_BANDS ); +#endif + hFrontVad->hNoiseEst->totalNoise_fx = (Word16) ( hFrontVad->hNoiseEst->totalNoise * ONE_IN_Q8 ); + Etot_fx[0] = (Word16) ( Etot[0] * ONE_IN_Q8 ); + hFrontVad->hNoiseEst->Etot_last_fx = (Word16) ( hFrontVad->hNoiseEst->Etot_last * ONE_IN_Q8 ); + hFrontVad->hNoiseEst->Etot_v_h2_fx = (Word16) ( hFrontVad->hNoiseEst->Etot_v_h2 * ONE_IN_Q8 ); + noise_est_down_fx( fr_bands_fx[0], hFrontVad->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise_fx, Etot_fx[0], &hFrontVad->hNoiseEst->Etot_last_fx, &hFrontVad->hNoiseEst->Etot_v_h2_fx, Q_bands, Q_bands + QSCALE ); + // noise_est_down( fr_bands[0], hFrontVad->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise, Etot[0], &hFrontVad->hNoiseEst->Etot_last, &hFrontVad->hNoiseEst->Etot_v_h2 ); +#ifdef DUMP_VAD_SPAR + for ( Word16 i = 0; i < 20; i++ ) + { + fprintf( fptmpN_fl, "%f\n", tmpN[i] ); + fprintf( fptmpE_fl, "%f\n", tmpE[i] ); + fprintf( fpbckr_fl, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); + } +#endif + // fixedToFloat_arrL( fr_bands_fx[0], fr_bands[0], Q_bands, 2 * NB_BANDS ); + fixedToFloat_arrL( hFrontVad->hNoiseEst->bckr_fx, hFrontVad->hNoiseEst->bckr, Q_bands + Q7, NB_BANDS ); + hFrontVad->hNoiseEst->totalNoise = (float) hFrontVad->hNoiseEst->totalNoise_fx / ONE_IN_Q8; + fixedToFloat_arrL( tmpN_fx, tmpN, Q_bands + QSCALE, 20 ); + fixedToFloat_arrL( tmpE_fx, tmpE, Q_bands + QSCALE, 20 ); + // Etot[0] = (float) Etot_fx[0] / ONE_IN_Q8; + hFrontVad->hNoiseEst->Etot_last = (float) hFrontVad->hNoiseEst->Etot_last_fx / ONE_IN_Q8; + hFrontVad->hNoiseEst->Etot_v_h2 = (float) hFrontVad->hNoiseEst->Etot_v_h2_fx / ONE_IN_Q8; +#ifdef DUMP_VAD_SPAR + for ( Word16 i = 0; i < 20; i++ ) + { + fprintf( fptmpN_fx, "%f\n", tmpN[i] ); + fprintf( fptmpE_fx, "%f\n", tmpE[i] ); + fprintf( fpbckr_fx, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); + } +#endif + // corr_shift = correlation_shift( hFrontVad->hNoiseEst->totalNoise ); + corr_shift_fx = correlation_shift_fx( hFrontVad->hNoiseEst->totalNoise_fx ); + corr_shift = fixedToFloat( corr_shift_fx, Q15 ); +#if 1 + Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8, 3 * L_FRAME / 2 ); + floatToFixed_arr( inp_12k8, inp_12k8_fx, Q_inp_12k8, 3 * L_FRAME / 2 ); + // Q_lp_noise = Q_factor( st->lp_noise ); + st->lp_noise_fx = (Word16) floatToFixed( st->lp_noise, Q8 ); + dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx ); + Word16 guard_bits = find_guarded_bits_fx( L_FRAME ); + IF( st->Opt_DTX_ON ) + { + st->hDtxEnc->frame_ener = fixedToFloat( st->hDtxEnc->frame_ener_fx, 2 * Q_inp_12k8 - guard_bits ); // 2*Q_speech + } +#else + dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); +#endif + /* linear prediction analysis */ + alw_pitch_lag_12k8[0] = st->old_pitch_la; + alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_voicing[0] = st->voicing[2]; + alw_voicing[1] = st->voicing[2]; +#if 1 + analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); +#else + // analy_lp( inp_12k8, L_FRAME, L_LOOK_12k8, &res_energy, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */ ); + + Word16 Q_r[2] = { 0 }; + floatToFixed_arr( st->lsp_old1, st->lsp_old1_fx, Q15, M ); + floatToFixed_arr( alw_voicing, alw_voicing_fx, Q15, 2 ); + Q_inp_12k8 = Q12; // Q_factor_arr( inp_12k8 - 90, 3 * L_FRAME / 2 + 90 ); + floatToFixed_arr( inp_12k8 - 90, inp_12k8_fx - 90, Q_inp_12k8, 3 * L_FRAME / 2 + 90 ); + analy_lp_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); + for ( Word16 i = 0; i <= M; i++ ) + { + epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); + } + fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] - 24, M + 1 ); + fixedToFloat_arr( A_fx, A, Q14, NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); + fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); + fixedToFloat_arr( st->lsp_old1_fx, st->lsp_old1, Q15, M ); + fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q12, 3 ); + +#endif + relE = Etot[0] - st->lp_speech; +#if 0 + find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1_FLT, L_LOOK_12k8 ); +#else + + Q_inp_12k8 = Q9; // Q_factor_arr( inp_12k8-M, (3 * L_FRAME / 2)+M ); + floatToFixed_arr( inp_12k8 - M, inp_12k8_fx - M, Q_inp_12k8, ( 3 * L_FRAME / 2 ) + M ); +#ifdef MSAN_FIX + floatToFixed_arr( A, A_fx, Q12, ( L_FRAME / L_SUBFR ) * ( M + 1 ) ); +#else + floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); +#endif // MSAN_FIX + + st->mem_wsp_fx = (Word16) floatToFixed( st->mem_wsp, Q_inp_12k8 ); + // find_wsp_fx( A_fx, inp_12k8_fx, wsp_fx, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw_fx, GAMMA1, NB_SUBFR ); + ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + fixedToFloat_arr( wsp_fx, wsp, Q_inp_12k8, 368 ); + fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); + // st->mem_wsp = fixedToFloat( st->mem_wsp_fx, Q_inp_12k8 ); +#endif + + if ( st->vad_flag == 0 ) + { + /* reset the OL pitch tracker memories during inactive frames */ +#if 1 + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); +#else + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); +#endif + } + + old_pitch = st->pitch[1]; +#if 0 + floatToFixed_arr( st->voicing, st->voicing_fx, Q15,3 ); + floatToFixed_arr( wsp, wsp_fx, Q12, 368 ); + floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q12, 115 ); + floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q12, 3 ); + // st->old_corr_fx = (Word16)floatToFixed( st->old_corr, Q15 ); + corr_shift_fx = (Word16)floatToFixed( corr_shift, Q15); + // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); + relE_fx = (Word16) floatToFixed( relE, Q8 ); + pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + + //pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + + fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); + fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q12, 115 ); + fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q12, 3 ); + st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); + // corr_shift_fx = floatToFixed( corr_shift, Q15 ); + st->old_thres = fixedToFloat( st->old_thres_fx, Q15 ); + //st->old_thres_fx = floatToFixed( relE, Q8 ); + for ( Word16 i = 0; i < 3; i++ ) + { + fprintf( fp_pitch, "%d\n", st->pitch[i] ); + fprintf( fp_voice, "%f\n", st->voicing[i] ); + } + // fprintf( fpbckr_fl, "%f\n", hFrontVad->hNoiseEst->bckr[i] ); +#else + pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, st->clas, st->input_bwidth, st->Opt_SC_VBR ); +#endif + /* Updates for adaptive lag window memory */ + st->old_pitch_la = st->pitch[2]; +#if 0 + /* Detection of very short stable pitch period */ + StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); +#else + // StableHighPitchDetect( &flag_spitch, st->pitch, st->voicing, st->Bin_E, wsp, st->localVAD, &st->voicing_sm, &st->voicing0_sm, &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); + floatToFixed_arr( wsp, wsp_fx, Q9, 368 ); + floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); + floatToFixed_arr( st->Bin_E, st->lgBin_E_fx, Q7, 128 ); + StableHighPitchDetect_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q12, st->lgBin_E_fx ); + fixedToFloat_arr( st->lgBin_E_fx, st->Bin_E, Q7, 128 ); + st->LF_EnergyRatio_sm = fixedToFloat( st->LF_EnergyRatio_sm_fx, Q7 ); + st->voicing_sm = fixedToFloat( st->voicing_sm_fx, Q15 ); + st->voicing0_sm = fixedToFloat( st->voicing0_sm_fx, Q15 ); +#endif + if ( st->hSpMusClas != NULL ) + { + int16_t dummy_int; + dummy_int = 0; +#if 0 + loc_harm = multi_harm( st->Bin_E, hFrontVad->hNoiseEst->old_S, hFrontVad->hNoiseEst->cor_map, &hFrontVad->hNoiseEst->multi_harm_limit, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn, &st->hSpMusClas->last_sw_dyn, &cor_map_sum, &dummy, S_map ); +#else + floatToFixed_arr( hFrontVad->hNoiseEst->old_S, hFrontVad->hNoiseEst->old_S_fx, Q7, 128 ); + floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->cor_map_fx, Q15, 128 ); + // floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->old_S_fx, Q15, 128 ); + hFrontVad->hNoiseEst->multi_harm_limit_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->multi_harm_limit, Q9 ); + st->hSpMusClas->mean_avr_dyn_fx = (Word16) floatToFixed( st->hSpMusClas->mean_avr_dyn, Q7 ); + st->hSpMusClas->last_sw_dyn_fx = (Word16) floatToFixed( st->hSpMusClas->last_sw_dyn, Q7 ); + // cor_map_sum_fx = (Word16) floatToFixed( cor_map_sum, Q8 ); + // dummy_fx = (Word16) floatToFixed( dummy, Q7 ); + floatToFixed_arr( hFrontVad->hNoiseEst->old_S, hFrontVad->hNoiseEst->old_S_fx, Q7, 128 ); + // loc_harm = multi_harm( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn, &st->hSpMusClas->last_sw_dyn, &cor_map_sum, &dummy, S_map ); + loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, ( st->hGSCEnc != NULL ) ? &st->hGSCEnc->cor_strong_limit : &dummy_int, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); + fixedToFloat_arr( hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->old_S, Q7, 128 ); + fixedToFloat_arr( hFrontVad->hNoiseEst->cor_map_fx, hFrontVad->hNoiseEst->cor_map, Q15, 128 ); + // floatToFixed_arr( hFrontVad->hNoiseEst->cor_map, hFrontVad->hNoiseEst->old_S_fx, Q15, 128 ); + hFrontVad->hNoiseEst->multi_harm_limit = fixedToFloat( hFrontVad->hNoiseEst->multi_harm_limit_fx, Q9 ); + st->hSpMusClas->mean_avr_dyn = fixedToFloat( st->hSpMusClas->mean_avr_dyn_fx, Q7 ); + st->hSpMusClas->last_sw_dyn = fixedToFloat( st->hSpMusClas->last_sw_dyn_fx, Q7 ); + cor_map_sum = fixedToFloat( cor_map_sum_fx, Q8 ); + // dummy = fixedToFloat( dummy_fx, Q7 ); + fixedToFloat_arr( hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->old_S, Q7, 128 ); + +#endif + } +#if 1 + noise_est( st, old_pitch, tmpN, epsP, Etot[0], Etot[0] - hFrontVad->lp_speech, corr_shift, tmpE, fr_bands[0], &cor_map_sum, &ncharX, &sp_div, &non_staX, &loc_harm, lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp, &dummy, S_map, NULL, hFrontVad, hFrontVad->ini_frame ); +#else + // noise_est( st, old_pitch, tmpN, epsP, Etot[0], Etot[0] - hFrontVad->lp_speech, corr_shift, tmpE, fr_bands[0], &cor_map_sum, &ncharX, &sp_div, &non_staX, &loc_harm, lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp, &dummy, S_map, NULL, hFrontVad, hFrontVad->ini_frame ); + Word16 Q_esp = Q_factor_arrL( epsP, M + 1 ); + floatToFixed_arrL( epsP, epsP_fx, Q_esp, M + 1 ); + FOR( Word16 i = 0; i <= M; i++ ) + { + L_Extract( epsP_fx[i], &epsP_h[i], &epsP_l[i] ); + } + + floatToFixed_arrL( lf_E[0], lf_E_fx[0], Q_bands + QSCALE - 2, 148 ); + floatToFixed_arrL( hFrontVad->hNoiseEst->fr_bands1, hFrontVad->hNoiseEst->fr_bands1_fx, Q_bands + QSCALE, NB_BANDS ); + floatToFixed_arrL( hFrontVad->hNoiseEst->fr_bands2, hFrontVad->hNoiseEst->fr_bands2_fx, Q_bands + QSCALE, NB_BANDS ); + floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr, hFrontVad->hNoiseEst->ave_enr_fx, Q_bands + QSCALE, NB_BANDS ); + floatToFixed_arrL( hFrontVad->hNoiseEst->ave_enr2, hFrontVad->hNoiseEst->ave_enr2_fx, Q_bands + QSCALE, NB_BANDS ); + hFrontVad->hNoiseEst->noise_char_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->noise_char, Q11 ); + hFrontVad->hNoiseEst->act_pred_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->act_pred, Q15 ); + hFrontVad->hNoiseEst->lt_haco_ev_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->lt_haco_ev, Q15 ); + hFrontVad->hNoiseEst->lt_tn_track_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->lt_tn_track, Q15 ); + hFrontVad->hNoiseEst->lt_aEn_zero_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->lt_aEn_zero, Q15 ); + hFrontVad->hNoiseEst->epsP_0_2_ad_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->epsP_0_2_ad_lp, Q12 ); + hFrontVad->hNoiseEst->epsP_0_2_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->epsP_0_2_lp, Q12 ); + hFrontVad->hNoiseEst->epsP_2_16_dlp_lp2_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->epsP_2_16_dlp_lp2, Q12 ); + hFrontVad->hNoiseEst->epsP_2_16_lp2_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->epsP_2_16_lp2, Q12 ); + hFrontVad->hNoiseEst->epsP_2_16_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->epsP_2_16_lp, Q12 ); + // hFrontVad->hNoiseEst->totalNoise_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->lt_tn_track, Q15 ); + + hFrontVad->hNoiseEst->Etot_l_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_l_lp, Q8 ); + hFrontVad->hNoiseEst->Etot_lp_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_lp, Q8 ); + hFrontVad->hNoiseEst->Etot_v_h2_fx = (Word16) floatToFixed( hFrontVad->hNoiseEst->Etot_v_h2, Q8 ); + hFrontVad->lp_speech_fx = (Word16) floatToFixed( hFrontVad->lp_speech, Q8 ); + corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); + noise_est_ivas_fx( st, old_pitch, tmpN_fx, epsP_h, epsP_l, Etot_fx[0], Etot_fx[0] - hFrontVad->lp_speech_fx, corr_shift_fx, tmpE_fx, fr_bands_fx[0], &cor_map_sum_fx, &sp_div_fx, &Q_sp_div, &non_staX_fx, &loc_harm, lf_E_fx[0], &hFrontVad->hNoiseEst->harm_cor_cnt, hFrontVad->hNoiseEst->Etot_l_lp_fx, hFrontVad->hNoiseEst->Etot_v_h2_fx, &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_bands, Q_bands + QSCALE, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); + cor_map_sum = fixedToFloat( cor_map_sum_fx, Q8 ); + non_staX = fixedToFloat( non_staX_fx, Q8 ); + fixedToFloat_arr( S_map_fx, S_map, Q7, 128 ); +#endif +#if 0 + vad_param_updt( st, corr_shift, corr_shift, A, st->pitch[1], &hFrontVad, 1 ); +#else + MVR2R_WORD16( st->pitch, st->pitch, 3 ); + corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); + hFrontVad->hVAD->running_avg_fx = (Word16) floatToFixed( hFrontVad->hVAD->running_avg, Q15 ); + hFrontVad->hVAD->ra_deltasum_fx = (Word16) floatToFixed( hFrontVad->hVAD->ra_deltasum, Q15 ); +#ifdef MSAN_FIX + floatToFixed_arr( A, A_fx, Q12, ( L_FRAME / L_SUBFR ) * ( M + 1 ) ); +#else + floatToFixed_arr( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); +#endif // MSAN_FIX + floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); + vad_param_updt_fx( st, st->pitch[1], corr_shift_fx, corr_shift_fx, A_fx, &hFrontVad, 1 ); + hFrontVad->hVAD->running_avg = fixedToFloat( hFrontVad->hVAD->running_avg_fx, Q15 ); + hFrontVad->hVAD->ra_deltasum = fixedToFloat( hFrontVad->hVAD->ra_deltasum_fx, Q15 ); + +#endif + /* 1st stage speech/music classification (GMM model) */ + /* run only to get 'high_lpn_flag' parameter */ +#if 0 + ivas_smc_gmm( st, NULL, localVAD_HE_SAD[0], Etot[0], lsp_new, cor_map_sum, epsP, PS, non_staX, relE, &high_lpn_flag, flag_spitch ); +#else + SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; +#if 1 + Word16 relE_fx; + Word16 lsp_new_fx[M]; + Word32 PS_fx[128]; + Word32 epsP_fx[M + 1]; + cor_map_sum_fx = (Word16) floatToFixed( cor_map_sum, Q8 ); + Word16 non_sta_fx = (Word16) floatToFixed( non_staX, Q8 ); + // Word32 epsP_fx[M + 1]; + Word16 Etot_fx_0 = (Word16) floatToFixed( Etot[0], Q8 ); + floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); + hSpMusClas->wdlp_0_95_sp_fx = (Word16) floatToFixed( hSpMusClas->wdlp_0_95_sp, Q8 ); + hSpMusClas->wdlp_xtalk_fx = floatToFixed( hSpMusClas->wdlp_xtalk, Q19 ); + hSpMusClas->wrise_fx = (Word16) ( hSpMusClas->wrise * ONE_IN_Q9 ); + relE_fx = (Word16) ( relE * ONE_IN_Q9 ); + hSpMusClas->prev_relE_fx = (Word16) ( hSpMusClas->prev_relE * ONE_IN_Q9 ); + hSpMusClas->relE_attack_sum_fx = (Word16) ( hSpMusClas->relE_attack_sum * ONE_IN_Q9 ); + Word16 Qfact_PS = Q_factor_arrL( PS, 128 ); + floatToFixed_arr32( PS, PS_fx, Qfact_PS, 128 ); + Word16 Q_esp = Q_factor_arrL( epsP, M + 1 ); + floatToFixed_arrL( epsP, epsP_fx, Q_esp, M + 1 ); + Word16 Qfact_PS_past = Q_factor_arrL( hSpMusClas->past_PS, 67 ); + floatToFixed_arr32( hSpMusClas->past_PS, hSpMusClas->past_PS_fx, Qfact_PS_past, 67 ); +#endif + ivas_smc_gmm_fx( st, NULL, localVAD_HE_SAD[0], Etot_fx_0, lsp_new_fx, cor_map_sum_fx, epsP_fx, PS_fx, non_sta_fx, relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, Q_esp, Qfact_PS_past ); +#if 1 + fixedToFloat_arr( hSpMusClas->past_dlp_fx, hSpMusClas->past_dlp, Q9, HANG_LEN - 1 ); + hSpMusClas->lpm = (Word16) fixedToFloat( hSpMusClas->lpm_fx, Q8 ); // Q8 + hSpMusClas->lps = (Word16) fixedToFloat( hSpMusClas->lps_fx, Q8 ); // Q8 + hSpMusClas->lpn = (Word16) fixedToFloat( hSpMusClas->lpn_fx, Q8 ); // Q8 + hSpMusClas->wdrop = (Word16) fixedToFloat( hSpMusClas->wdrop_fx, Q9 ); // Q8 + hSpMusClas->wrise = (Word16) fixedToFloat( hSpMusClas->wrise_fx, Q9 ); // Q8 + hSpMusClas->lt_dec_thres = (Word16) fixedToFloat( hSpMusClas->lt_dec_thres_fx, Q9 ); // Q8 + hSpMusClas->wdlp_0_95_sp = fixedToFloat( hSpMusClas->wdlp_0_95_sp_fx, Q8 ); + hSpMusClas->dlp_mean_LT = fixedToFloat_32( hSpMusClas->dlp_mean_LT_fx, Q19 ); + hSpMusClas->wdlp_xtalk = fixedToFloat( hSpMusClas->wdlp_xtalk_fx, Q19 ); + hSpMusClas->dlp_var_LT = fixedToFloat_32( hSpMusClas->dlp_var_LT_fx, Q19 ); + hSpMusClas->prev_relE = (Word16) fixedToFloat( hSpMusClas->prev_relE_fx, Q9 ); + hSpMusClas->prev_Etot = (Word16) fixedToFloat( hSpMusClas->prev_Etot_fx, Q8 ); + fixedToFloat_arrL32( hSpMusClas->past_PS_fx, hSpMusClas->past_PS, Qfact_PS_past, 67 ); + hSpMusClas->relE_attack_sum = (Word16) fixedToFloat( hSpMusClas->relE_attack_sum_fx, Q9 ); + fixedToFloat_arrL32( hSpMusClas->FV_st_fx, hSpMusClas->FV_st, Q20, 15 ); +#endif +#endif +#if 0 + /* long-term energy update */ + long_enr( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot ); +#else + hFrontVad->lp_speech_fx = (Word16) floatToFixed( hFrontVad->lp_speech, Q8 ); + hFrontVad->lp_noise_fx = (Word16) floatToFixed( hFrontVad->lp_noise, Q8 ); + /* long-term energy update */ + ivas_long_enr_fx( st, -1, localVAD_HE_SAD[0], high_lpn_flag, &hFrontVad, 1, localVAD_HE_SAD, Etot_fx ); + hFrontVad->lp_speech = fixedToFloat( hFrontVad->lp_speech_fx, Q8 ); + hFrontVad->lp_noise = fixedToFloat( hFrontVad->lp_noise_fx, Q8 ); + hFrontVad->hNoiseEst->Etot_last = fixedToFloat( hFrontVad->hNoiseEst->Etot_last_fx, Q8 ); +#endif + /* increase ini_frame counter */ + hFrontVad->ini_frame = min( hFrontVad->ini_frame + 1, MAX_FRAME_COUNTER ); + st->ini_frame = hFrontVad->ini_frame; + + hSpar->front_vad_flag = st->vad_flag; + hSpar->front_vad_dtx_flag = 1; + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + { + hSpar->front_vad_dtx_flag = 0; + } + hSpar->force_front_vad = 1; + st->last_core = 0; + } + else + { + hSpar->front_vad_flag = 1; + hSpar->front_vad_dtx_flag = 0; + hSpar->force_front_vad = 0; + } +#ifdef DUMP_VAD_SPAR + fclose( fptmpN_fl ); + fclose( fptmpE_fl ); + fclose( fpbckr_fl ); + + fclose( fptmpN_fx ); + fclose( fptmpE_fx ); + fclose( fpbckr_fx ); +#endif +#if 1 + fclose( fp_pitch ); + fclose( fp_voice ); +#endif + pop_wmops(); + return error; +} +#else ivas_error front_vad_spar( SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ const float *omni_in, /* i : omnidirectional input signal */ @@ -436,7 +932,6 @@ ivas_error front_vad_spar( /*------------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - inp_12k8 = hFrontVad->buffer_12k8; mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); wsp = old_wsp + L_WSP_MEM; @@ -532,3 +1027,4 @@ ivas_error front_vad_spar( pop_wmops(); return error; } +#endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1daf86b23182bbf690903ae3492cc2bf47f885c0..10fae03212f1cef0e55672acdee4cef3a557988d 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "prot_fx_enc.h" +#include "prot_fx.h" #endif @@ -240,6 +241,50 @@ int16_t getNumChanAnalysis( return n; } +#ifdef IVAS_FLOAT_FIXED +Word16 getNumChanAnalysis_fx( + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +) +{ + Word16 n; + + n = add( st_ivas->nSCE, CPE_CHANNELS * st_ivas->nCPE ); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) ) + { + n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) || EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + move16(); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + move16(); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + move16(); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + move16(); + } + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) + { + n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); + } + + return n; +} +#endif /*-------------------------------------------------------------------* * copy_encoder_config() @@ -461,7 +506,20 @@ ivas_error ivas_init_encoder( { st_ivas->p_data_f[n] = NULL; } - +#ifdef IVAS_FLOAT_FIXED + FOR( n = 0; n < nchan_inp_buff; n++ ) + { + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_data_fx[n] = (Word32 *) malloc( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) ); + } + } + FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + st_ivas->p_data_fx[n] = NULL; + } +#endif /*-----------------------------------------------------------------* * Allocate and initialize buffer of indices *-----------------------------------------------------------------*/ @@ -811,7 +869,11 @@ ivas_error ivas_init_encoder( st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); #endif +#ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -976,7 +1038,29 @@ ivas_error ivas_init_encoder( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } +#ifdef IVAS_FLOAT_FIXED + IF( n > 0 ) + { + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + ELSE + { + st_ivas->mem_hp20_in_fx = NULL; + } + + FOR( i = 0; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } +#endif return error; } #ifdef IVAS_FLOAT_FIXED @@ -1030,7 +1114,7 @@ ivas_error ivas_init_encoder_fx( nchan_inp_buff++; /* for *data_separated_object */ } - +#if 1 /* To be removed */ FOR( n = 0; n < nchan_inp_buff; n++ ) { /* note: these are intra-frame heap memories */ @@ -1043,6 +1127,20 @@ ivas_error ivas_init_encoder_fx( { st_ivas->p_data_f[n] = NULL; } +#endif + FOR( n = 0; n < nchan_inp_buff; n++ ) + { + /* note: these are intra-frame heap memories */ + IF( ( st_ivas->p_data_fx[n] = (Word32 *) malloc( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) ); + } + } + FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + st_ivas->p_data_fx[n] = NULL; + } + /*-----------------------------------------------------------------* * Allocate and initialize buffer of indices @@ -1393,7 +1491,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); #endif - if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -1535,8 +1633,8 @@ ivas_error ivas_init_encoder_fx( *-----------------------------------------------------------------*/ /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis( st_ivas ); - + n = getNumChanAnalysis_fx( st_ivas ); +#if 1 // To be removed if ( n > 0 ) { if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -1558,6 +1656,29 @@ ivas_error ivas_init_encoder_fx( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } +#endif + /*Fixed point init*/ + IF( n > 0 ) + { + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + ELSE + { + st_ivas->mem_hp20_in_fx = NULL; + } + + FOR( i = 0; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } return error; } @@ -1723,7 +1844,154 @@ void destroy_core_enc( * * Close IVAS encoder handles *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_destroy_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t i, n, nchan_inp; + nchan_inp = st_ivas->hEncoderConfig->nchan_inp; + + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_enc( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } + + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) + { + destroy_cpe_enc( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } + /* HP20 filter handles */ + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis_fx( st_ivas ); + + for ( i = 0; i < n; i++ ) + { + free( st_ivas->mem_hp20_in_fx[i] ); + st_ivas->mem_hp20_in_fx[i] = NULL; + } + free( st_ivas->mem_hp20_in_fx ); + st_ivas->mem_hp20_in_fx = NULL; + } + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis_fx( st_ivas ); + + for ( i = 0; i < n; i++ ) + { + free( st_ivas->mem_hp20_in[i] ); + st_ivas->mem_hp20_in[i] = NULL; + } + free( st_ivas->mem_hp20_in ); + st_ivas->mem_hp20_in = NULL; + } + + /* ISM metadata handles */ + ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); + + /* ISM DTX Handle */ + if ( st_ivas->hISMDTX != NULL ) + { + free( st_ivas->hISMDTX ); + st_ivas->hISMDTX = NULL; + } + + /* Q Metadata handle */ + ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); + + /* DirAC handle */ + ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); + + /* ParamISM handle */ + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); + + /* SPAR handle */ + ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); + + /* MASA handle */ + ivas_masa_enc_close( &( st_ivas->hMasa ) ); + + /* MCT handle */ + ivas_mct_enc_close( &( st_ivas->hMCT ) ); + + /* LFE handle */ + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + + /* LFE low pass filter state */ + ivas_lfe_lpf_enc_close( &( st_ivas->hLfeLpf ) ); + + /* Param-Upmix MC handle */ + ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs ); + + /* Parametric MC handle */ + ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); + + /* Multi-channel MASA handle */ + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); + + /* OMASA handle */ + ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); + + /* OSBA handle */ + ivas_osba_enc_close( &( st_ivas->hOSba ) ); + + /* Stereo downmix for EVS encoder handle */ + stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); + + /* Encoder configuration handle */ + if ( st_ivas->hEncoderConfig != NULL ) + { + free( st_ivas->hEncoderConfig ); + st_ivas->hEncoderConfig = NULL; + } + + /* Buffer of indices */ + if ( st_ivas->ind_list != NULL ) + { + free( st_ivas->ind_list ); + } + + if ( st_ivas->ind_list_metadata != NULL ) + { + free( st_ivas->ind_list_metadata ); + } + + /* floating-point input audio buffers */ + for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + if ( st_ivas->p_data_f[n] != NULL ) + { + free( st_ivas->p_data_f[n] ); + st_ivas->p_data_f[n] = NULL; + } + } + for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + if ( st_ivas->p_data_fx[n] != NULL ) + { + free( st_ivas->p_data_fx[n] ); + st_ivas->p_data_fx[n] = NULL; + } + } + + /* main IVAS handle */ + free( st_ivas ); + + return; +} +#else void ivas_destroy_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -1843,6 +2111,13 @@ void ivas_destroy_enc( free( st_ivas->p_data_f[n] ); st_ivas->p_data_f[n] = NULL; } +#ifdef IVAS_FLOAT_FIXED + if ( st_ivas->p_data_fx[n] != NULL ) + { + free( st_ivas->p_data_fx[n] ); + st_ivas->p_data_fx[n] = NULL; + } +#endif } /* main IVAS handle */ @@ -1850,6 +2125,7 @@ void ivas_destroy_enc( return; } +#endif /*------------------------------------------------------------------------- * ivas_initialize_MD_bstr_enc() diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index db27d9085057f0a94cf45b6b8308291a6b627267..eea3314d86edb30c9d4bff7e3a5abcc61add93cc 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -37,11 +37,21 @@ #include "prot.h" #include "ivas_prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#include "prot_fx_enc.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +#define MD_MAX_DIFF_AZIMUTH_FX 41943040 +#define MD_MAX_DIFF_ELEVATION_FX 41943040 +#endif // IVAS_FLOAT_FIXED #define MD_MAX_DIFF_AZIMUTH 10 #define MD_MAX_DIFF_ELEVATION 10 @@ -93,6 +103,247 @@ ivas_error ivas_ism_dtx_open( *-------------------------------------------------------------------*/ /*! r: indication of DTX frame */ +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +) +{ + Word16 ch, dtx_flag; + Word16 nBits, nBits_MD_max; + Word16 nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; + Word16 lp_noise_fx[MAX_NUM_OBJECTS], lp_noise_variation_fx, lp_noise_mean_fx; + Word16 lp_noise_max_fx; + Word32 tmp1_fx, tmp2_fx; + /* initialization */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; + move16(); + } + + /*------------------------------------------------------------------* + * compute global ISM DTX flag + *-----------------------------------------------------------------*/ + + /* compute global ISM based on localVAD */ + dtx_flag = 1; + move16(); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + dtx_flag = s_and( dtx_flag, !vad_flag[ch] ); + } + + /* compute global ISM based on long-term background noise */ + /* one of the channels is active -> no DTX */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + lp_noise_fx[ch] = hSCE[ch]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ + move16(); + } + + lp_noise_variation_fx = var_fx( lp_noise_fx, Q8, nchan_transport ); /*Q8*/ + lp_noise_mean_fx = mean_fx( lp_noise_fx, nchan_transport ); /*Q8*/ + + test(); + test(); + if ( GT_16( lp_noise_mean_fx, ( 50 << 8 ) ) || ( GT_16( lp_noise_mean_fx, ( 25 << 8 ) ) && GT_16( lp_noise_variation_fx, ( 32 << 8 ) ) ) ) + { + dtx_flag = 0; + move16(); + } + + + /* default DTX is applied at lower bitrates; otherwise DTX is applied only in silence */ + maximum_fx( lp_noise_fx, nchan_transport, &lp_noise_max_fx ); /*Q8*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( !( ( EQ_16( nchan_ism, 1 ) && LE_32( ivas_total_brate, IVAS_24k4 ) ) || + ( EQ_16( nchan_ism, 2 ) && LE_32( ivas_total_brate, IVAS_48k ) ) || + ( EQ_16( nchan_ism, 3 ) && LE_32( ivas_total_brate, IVAS_80k ) ) || + ( EQ_16( nchan_ism, 4 ) && LE_32( ivas_total_brate, IVAS_96k ) ) || + LT_16( lp_noise_max_fx, ( 15 << 8 ) ) ) ) + { + dtx_flag = 0; + move16(); + } + + /*------------------------------------------------------------------* + * Reset the bitstream + *-----------------------------------------------------------------*/ + + IF( dtx_flag ) + { + /* reset the bitstream (IVAS format signaling was already written) */ + reset_indices_enc( hSCE[0]->hCoreCoder[0]->hBstr, hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot ); + } + + /*------------------------------------------------------------------* + * decide about SID metadata to be sent or not (per object) + * estimate the MD bit-budget consumption + *-----------------------------------------------------------------*/ + + IF( dtx_flag ) + { + ivas_get_ism_sid_quan_bitbudget_fx( nchan_ism, &nBits_azimuth, &nBits_elevation, &tmp1_fx, &tmp2_fx, &nBits_coh, &nBits_sce_id ); + + nBits = 0; + move16(); + FOR( ch = 0; ch < nchan_ism; ch++ ) + { + /* check difference between current and last metadata */ + md_diff_flag[ch] = 0; + move16(); + if ( GT_32( L_abs( L_sub( hIsmMeta[ch]->azimuth_fx, hIsmMeta[ch]->last_azimuth_fx ) ), MD_MAX_DIFF_AZIMUTH_FX ) ) + { + md_diff_flag[ch] = 1; + move16(); + } + + if ( GT_32( L_abs( L_sub( hIsmMeta[ch]->elevation_fx, hIsmMeta[ch]->last_elevation_fx ) ), MD_MAX_DIFF_ELEVATION_FX ) ) + { + md_diff_flag[ch] = 1; + move16(); + } + + /* estimate SID metadata bit-budget */ + nBits = add( nBits, 1 ); /* number of objects */ + nBits = add( nBits, 1 ); /* SID metadata flag */ + IF( EQ_16( md_diff_flag[ch], 1 ) ) + { + nBits = add( nBits, nBits_azimuth ); + nBits = add( nBits, nBits_elevation ); + } + } + + /* calculate maximum available MD bit-budget */ + nBits_MD_max = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; + move16(); + nBits_MD_max = sub( nBits_MD_max, SID_FORMAT_NBITS ); + + if ( GT_16( nchan_transport, 1 ) ) + { + nBits_MD_max = sub( nBits_MD_max, nBits_sce_id ); + } + + FOR( ch = 0; ch < nchan_transport - 1; ch++ ) + { + nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence */ + } + + if ( GT_16( nchan_ism, 3 ) ) + { + nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag */ + } + + /* too many metadata bits -> switch to active coding */ + if ( GT_16( nBits, nBits_MD_max ) ) + { + dtx_flag = 0; + move16(); + } + } + + /*------------------------------------------------------------------* + * set core_brate for all channels + * get 'sid_flag' value + *-----------------------------------------------------------------*/ + + *sid_flag = 0; + move16(); + + IF( !dtx_flag ) + { + /* at least one of the channels is active -> no DTX */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->core_brate = -1; + move32(); + set_bw_fx( IVAS_SCE, hSCE[ch]->element_brate, hSCE[ch]->hCoreCoder[0], MODE1 ); + } + + hISMDTX->cnt_SID_ISM = -1; + move16(); + + /* IVAS format signaling was erased in dtx() */ + IF( EQ_16( hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot, 0 ) ) + { + /* replicate ivas_write_format() */ + Word16 ind = 2; + nBits = IVAS_FORMAT_SIGNALING_NBITS; + move16(); + move16(); + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) + { + ind = 4; + nBits = IVAS_FORMAT_SIGNALING_NBITS_EXTENDED; + move16(); + move16(); + } + + push_indice( hSCE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits ); + } + } + ELSE /* ism_dtx_flag == 1 */ + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->cng_type = FD_CNG; + move16(); + } + + /* * update the global SID counter */ + hISMDTX->cnt_SID_ISM = add( hISMDTX->cnt_SID_ISM, 1 ); + move16(); + IF( GE_16( hISMDTX->cnt_SID_ISM, hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID ) ) + { + /* adaptive SID update interval */ + hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID = hSCE[0]->hCoreCoder[0]->hDtxEnc->interval_SID; + hISMDTX->cnt_SID_ISM = 0; + move16(); + move16(); + } + + /* encode SID in one channel only */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->core_brate = FRAME_NO_DATA; + move32(); + } + + IF( EQ_16( hISMDTX->cnt_SID_ISM, 0 ) ) + { + hSCE[hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate = SID_2k40; + *sid_flag = 1; + move32(); + move16(); + } + } + + test(); + IF( EQ_16( dtx_flag, 1 ) && EQ_16( *sid_flag, 0 ) ) + { + set16_fx( md_diff_flag, 0, nchan_transport ); + } + + return dtx_flag; +} +#endif // IVAS_FLOAT_FIXED + int16_t ivas_ism_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -301,6 +552,85 @@ int16_t ivas_ism_dtx_enc( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + Word32 tmp_energy[MAX_NUM_OBJECTS]; + Word16 tmp_energy_e[MAX_NUM_OBJECTS]; + Word16 i, j; + Word16 long_term_energy_stereo_dmx_enc_e[MAX_NUM_OBJECTS]; + Word16 max_exp; + + set16_fx( long_term_energy_stereo_dmx_enc_e, hISMDTX->long_term_energy_stereo_dmx_enc_e, nchan_transport ); + IF( EQ_16( nchan_transport, 1 ) ) + { + hISMDTX->sce_id_dtx = 0; + move16(); + + return; + } + + /* Initialize*/ + set32_fx( tmp_energy, 0, MAX_NUM_OBJECTS ); + set16_fx( tmp_energy_e, 0, MAX_NUM_OBJECTS ); + + /* compute long term energy parameter */ + FOR( j = 0; j < nchan_transport; j++ ) + { + FOR( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) + { + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i + 1]; + move32(); + } + long_term_energy_stereo_dmx_enc_e[j] = 20; + move16(); + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = sum2_32_fx( hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, &long_term_energy_stereo_dmx_enc_e[j] ); /*Resultant Q_lte=2*Q(input_fx)+1=2*-5+1=>-9*/ + move32(); + tmp_energy[j] = L_deposit_l( 0 ); + move32(); + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE - 1; i++ ) + { + tmp_energy[j] = BASOP_Util_Add_Mant32Exp( tmp_energy[j], tmp_energy_e[j], hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], hISMDTX->long_term_energy_stereo_dmx_enc_e, &tmp_energy_e[j] ); /*Resultant Q(tmp_energy)=Q_lte*/ + move32(); + } + tmp_energy[j] = BASOP_Util_Add_Mant32Exp( tmp_energy[j], tmp_energy_e[j], hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], long_term_energy_stereo_dmx_enc_e[j], &tmp_energy_e[j] ); /*Resultant Q(tmp_energy)=Q_lte*/ + move32(); + } + + maximum_fx( long_term_energy_stereo_dmx_enc_e, nchan_transport, &max_exp ); + max_exp = s_max( max_exp, hISMDTX->long_term_energy_stereo_dmx_enc_e ); + FOR( j = 0; j < nchan_transport; j++ ) + { + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE - 1; i++ ) + { + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], max_exp - hISMDTX->long_term_energy_stereo_dmx_enc_e ); + move32(); + } + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], max_exp - long_term_energy_stereo_dmx_enc_e[j] ); + move32(); + } + hISMDTX->long_term_energy_stereo_dmx_enc_e = max_exp; + move16(); + /* determine the sce_id */ + hISMDTX->sce_id_dtx = 0; + move16(); + FOR( j = 1; j < nchan_transport; j++ ) + { + if ( BASOP_Util_Cmp_Mant32Exp( tmp_energy[j], tmp_energy_e[j], tmp_energy[hISMDTX->sce_id_dtx], tmp_energy_e[hISMDTX->sce_id_dtx] ) ) + { + hISMDTX->sce_id_dtx = j; + move16(); + } + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -354,6 +684,93 @@ void ivas_ism_get_sce_id_dtx( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +) +{ + Encoder_State *st, *st_id0; + Word16 sce_id, i; + Word32 acorr_ene_fx[MAX_NUM_OBJECTS], xcorr_ene_fx; + Word16 acorr_ene_e[MAX_NUM_OBJECTS], xcorr_ene_e; + Word16 norm_inp; + Word16 tot_exp; + Word32 scaled_inp; + set16_fx( acorr_ene_e, 0, MAX_NUM_OBJECTS ); + + IF( EQ_16( nchan_transport, 1 ) ) + { + hISMDTX->coh_fx[0] = 0; + move16(); + return; + } + + /* Compute Coherence */ + acorr_ene_fx[hISMDTX->sce_id_dtx] = 0; + move32(); + st_id0 = hSCE[hISMDTX->sce_id_dtx]->hCoreCoder[0]; + + FOR( i = 0; i < input_frame; i++ ) + { + norm_inp = norm_l( st_id0->input32_fx[i] ); + scaled_inp = L_shl( st_id0->input32_fx[i], norm_inp ); + tot_exp = shl( sub( 20, norm_inp ), 1 ); + acorr_ene_fx[hISMDTX->sce_id_dtx] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_e[hISMDTX->sce_id_dtx], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[hISMDTX->sce_id_dtx] ); + move32(); + } + + FOR( sce_id = 0; sce_id < nchan_transport; sce_id++ ) + { + IF( EQ_16( sce_id, hISMDTX->sce_id_dtx ) ) + { + hISMDTX->coh_fx[sce_id] = 32767; + move16(); + continue; + } + + st = hSCE[sce_id]->hCoreCoder[0]; + + acorr_ene_fx[sce_id] = 0; + xcorr_ene_fx = 0; + xcorr_ene_e = 0; + move32(); + move32(); + move16(); + + FOR( i = 0; i < input_frame; i++ ) + { + norm_inp = norm_l( st->input32_fx[i] ); + scaled_inp = L_shl( st->input32_fx[i], norm_inp ); + tot_exp = shl( sub( 20, norm_inp ), 1 ); + acorr_ene_fx[sce_id] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[sce_id], acorr_ene_e[sce_id], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[sce_id] ); + move32(); + xcorr_ene_fx = BASOP_Util_Add_Mant32Exp( xcorr_ene_fx, xcorr_ene_e, Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &xcorr_ene_e ); + } + Word16 coh_e; + Word16 temp_e = acorr_ene_e[hISMDTX->sce_id_dtx] + acorr_ene_e[sce_id]; + Word32 temp = Sqrt32( L_add( Mult_32_32( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_fx[sce_id] ), EPSILON_FX ), &temp_e ); /*fabsf( xcorr_ene ) / ( sqrtf( ( acorr_ene[hISMDTX->sce_id_dtx] * acorr_ene[sce_id] ) + EPSILON ) );*/ + hISMDTX->coh_fx[sce_id] = BASOP_Util_Divide3232_Scale( L_abs( xcorr_ene_fx ), temp, &coh_e ); + move16(); + coh_e = add( coh_e, sub( xcorr_ene_e, temp_e ) ); + IF( coh_e < 0 ) + { + hISMDTX->coh_fx[sce_id] = shl( hISMDTX->coh_fx[sce_id], coh_e ); + move16(); + coh_e = 0; + } + /* ensure value of coherence is between [0,1] */ + hISMDTX->coh_fx[sce_id] = check_bounds_s( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) ); + hISMDTX->coh_fx[sce_id] = shl_sat( hISMDTX->coh_fx[sce_id], coh_e ); + move16(); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 296323cf9c4ec57b0bd7e1d80be1b1a17c4a2cab..7e51c82bf83de8ddd0627c956dceaae138e03e32 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -39,6 +39,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif @@ -167,11 +168,17 @@ 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; @@ -194,6 +201,38 @@ 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 */ @@ -204,6 +243,7 @@ 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 } /*------------------------------------------------------------------* @@ -211,7 +251,7 @@ ivas_error ivas_ism_enc( * Metadata quantization and encoding *-----------------------------------------------------------------*/ - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + 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; @@ -219,15 +259,86 @@ 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 */ { @@ -245,12 +356,74 @@ 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 ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 8eaf2d7a0f60b92bbe9e0d4dab15b2027ec8621c..3bf1bb5c8899d52855a79c9785782bbac809a6d2 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -39,18 +39,18 @@ #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_prot_fx.h" +#include "ivas_rom_com_fx.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif - /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ @@ -61,11 +61,14 @@ #define ISM_MAX_ELEVATION_DIFF_IDX ( ISM_ELEVATION_NBITS - 1 /*zero*/ - 1 /*sign*/ ) #define ISM_MAX_RADIUS_DIFF_IDX ( ISM_RADIUS_NBITS - 1 /*zero*/ - 1 /*sign*/ ) -#define ISM_FEC_MAX 10 -#define ISM_MD_FEC_DIFF 10 -#define ISM_MD_INC_DIFF_CNT_MAX 6 -#define ISM_MD_FEC_CNT_MAX 25 -#define ISM_MD_RAD_FEC_DIFF 1 +#define ISM_FEC_MAX 10 +#define ISM_MD_FEC_DIFF 10 +#define ISM_MD_FEC_DIFF_Q22 41943040 +#define ISM_MD_INC_DIFF_CNT_MAX 6 +#define ISM_MD_FEC_CNT_MAX 25 +#define ISM_MD_RAD_FEC_DIFF 1 +#define ISM_MD_RAD_FEC_DIFF_Q9 ONE_IN_Q9 + #define INTER_OBJECT_PARAM_CHECK ( ( ISM_FEC_MAX / 2 ) - 2 ) /* note: constant must be less than (ISM_FEC_MAX / number of coded parameters) */ @@ -83,7 +86,43 @@ static void encode_radius( BSTR_ENC_HANDLE hBstr, int16_t *last_radius_idx, int1 * * Set metadata of one ISM MD handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag*/ +) +{ + + IF( hIsmMeta == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIsmMeta->ism_metadata_flag = 1; + move16(); + /* save read metadata parameters to the internal codec structure */ + hIsmMeta->azimuth_fx = azimuth; + move32(); + hIsmMeta->elevation_fx = elevation; + move32(); + hIsmMeta->radius_fx = radius_meta; + move16(); + hIsmMeta->yaw_fx = yaw; + move16(); + hIsmMeta->pitch_fx = pitch; + move16(); + hIsmMeta->non_diegetic_flag = non_diegetic_flag; + move16(); + + return IVAS_ERR_OK; +} +#else ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -111,7 +150,7 @@ ivas_error ivas_set_ism_metadata( return IVAS_ERR_OK; } - +#endif /*-------------------------------------------------------------------------* * rate_ism_importance() @@ -119,6 +158,63 @@ ivas_error ivas_set_ism_metadata( * Rate importance of particular ISM streams *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void rate_ism_importance( + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word16 lowrate_metadata_flag[MAX_NUM_OBJECTS], /* i : low-rate MD flag */ + Word16 ism_imp[] /* o : ISM importance flags */ +) +{ + Word16 ch, ctype; + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + IF( hSCE[ch]->hCoreCoder[0]->tcxonly ) + { + IF( EQ_16( hSCE[ch]->hCoreCoder[0]->localVAD, 0 ) ) + { + ctype = INACTIVE; + move16(); + } + ELSE IF( EQ_16( ctype, UNVOICED ) ) + { + ctype = GENERIC; + move16(); + } + } + + test(); + test(); + test(); + IF( ( EQ_16( hIsmMeta[ch]->ism_metadata_flag, 0 ) || EQ_16( lowrate_metadata_flag[ch], 1 ) ) && EQ_16( hSCE[ch]->hCoreCoder[0]->localVAD, 0 ) ) + { + ism_imp[ch] = ISM_NO_META; + move16(); + } + ELSE IF( EQ_16( ctype, INACTIVE ) || EQ_16( ctype, UNVOICED ) ) + { + ism_imp[ch] = ISM_LOW_IMP; + move16(); + } + ELSE IF( EQ_16( ctype, VOICED ) ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + move16(); + } + ELSE /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + move16(); + } + } + + return; +} +#else static void rate_ism_importance( const int16_t nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ @@ -165,7 +261,7 @@ static void rate_ism_importance( return; } - +#endif /*-------------------------------------------------------------------------* * ivas_ism_metadata_enc() @@ -175,42 +271,43 @@ static void rate_ism_importance( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc( - int32_t *ism_total_brate, /* i/o: ISM total bitrate */ - const int16_t nchan_ism, /* i : number of ISM channels */ - const int16_t nchan_transport, /* i : number of transport channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - int16_t nb_bits_metadata[], /* o : number of metadata bits */ - const int16_t vad_flag[], /* i : VAD flag */ - const int16_t ism_mode, /* i : ISM mode */ - const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ - const int16_t ism_extended_metadata_flag, /* i : Extended metadata flag */ - const float lp_noise_CPE, - const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ - int16_t *omasa_stereo_sw_cnt, - const int16_t ini_frame ) + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 vad_flag[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word32 lp_noise_CPE_fx, + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame ) { - int16_t i, ch, nb_bits_start = 0; - int16_t flag_abs_azimuth[MAX_NUM_OBJECTS]; - int16_t flag_abs_elevation[MAX_NUM_OBJECTS]; - int16_t idx_angle1_abs = 0; - int16_t idx_angle2_abs = 0; - int16_t flag_abs_yaw[MAX_NUM_OBJECTS]; - int16_t flag_abs_pitch[MAX_NUM_OBJECTS]; - int16_t idx_radius_abs = 0, flag_abs_radius[MAX_NUM_OBJECTS]; - float valQ; -#ifdef IVAS_FLOAT_FIXED + Word16 i, ch, nb_bits_start = 0; + move16(); + Word16 flag_abs_azimuth[MAX_NUM_OBJECTS]; + Word16 flag_abs_elevation[MAX_NUM_OBJECTS]; + Word16 idx_angle1_abs = 0; + move16(); + Word16 idx_angle2_abs = 0; + move16(); + Word16 flag_abs_yaw[MAX_NUM_OBJECTS]; + Word16 flag_abs_pitch[MAX_NUM_OBJECTS]; + Word16 idx_radius_abs = 0, flag_abs_radius[MAX_NUM_OBJECTS]; + move16(); Word32 valQ_fx; -#endif ISM_METADATA_HANDLE hIsmMetaData; int32_t element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; - int16_t ism_metadata_flag_global; - int16_t non_diegetic_flag_global; - int16_t ism_imp[MAX_NUM_OBJECTS]; - int16_t null_metadata_flag[MAX_NUM_OBJECTS]; - int16_t lowrate_metadata_flag[MAX_NUM_OBJECTS]; - int16_t nbands, nblocks; + Word16 ism_metadata_flag_global; + Word16 non_diegetic_flag_global; + Word16 ism_imp[MAX_NUM_OBJECTS]; + Word16 null_metadata_flag[MAX_NUM_OBJECTS]; + Word16 lowrate_metadata_flag[MAX_NUM_OBJECTS]; + Word16 nbands, nblocks; ivas_error error; error = IVAS_ERR_OK; @@ -219,6 +316,8 @@ ivas_error ivas_ism_metadata_enc( /* initialization */ ism_metadata_flag_global = 0; non_diegetic_flag_global = 0; + move16(); + move16(); set_s( nb_bits_metadata, 0, nchan_transport ); set_s( flag_abs_azimuth, 0, nchan_ism ); set_s( flag_abs_elevation, 0, nchan_ism ); @@ -228,69 +327,82 @@ ivas_error ivas_ism_metadata_enc( set_s( null_metadata_flag, 0, nchan_ism ); set_s( lowrate_metadata_flag, 0, nchan_ism ); - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /*----------------------------------------------------------------* * Rate importance of particular ISM streams in combined format coding *----------------------------------------------------------------*/ - - ivas_set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + ivas_set_ism_importance_interformat_fx( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE_fx, ism_imp ); } - else + ELSE { /*----------------------------------------------------------------* * Set Metadata presence / importance flag *----------------------------------------------------------------*/ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { - if ( ism_mode == ISM_MODE_PARAM ) + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { hIsmMeta[ch]->ism_metadata_flag = 1; + move16(); } - else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { null_metadata_flag[ch] = !hIsmMeta[ch]->ism_metadata_flag; + move16(); - if ( hIsmMeta[ch]->ism_metadata_flag == 1 ) + IF( EQ_16( hIsmMeta[ch]->ism_metadata_flag, 1 ) ) { - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { /* In case of low level noise for low bitrate inactive frames, do not sent metadata */ - hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10 || hSCE[ch]->hCoreCoder[0]->tcxonly; + hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || GT_16( hSCE[ch]->hCoreCoder[0]->lp_noise_fx, 2560 /*10 Q8*/ ) || hSCE[ch]->hCoreCoder[0]->tcxonly; + move16(); } /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + IF( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || - ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) || ( fabsf( hIsmMeta[ch]->radius - hIsmMeta[ch]->last_true_radius ) > ISM_MD_RAD_FEC_DIFF ) ) + test(); + test(); + IF( ( GT_32( L_abs( L_sub( hIsmMeta[ch]->azimuth_fx, hIsmMeta[ch]->last_true_azimuth_fx ) ), ISM_MD_FEC_DIFF_Q22 ) ) || + ( GT_32( L_abs( L_sub( hIsmMeta[ch]->elevation_fx, hIsmMeta[ch]->last_true_elevation_fx ) ), ISM_MD_FEC_DIFF_Q22 ) ) || ( GT_16( abs_s( sub( hIsmMeta[ch]->radius_fx, hIsmMeta[ch]->last_true_radius_fx ) ), ISM_MD_RAD_FEC_DIFF_Q9 ) ) ) { lowrate_metadata_flag[ch] = 1; + move16(); hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; + move16(); } - else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) + ELSE IF( LT_16( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ) ) { lowrate_metadata_flag[ch] = 1; - - if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + move16(); + IF( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) { hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); } - else + ELSE { hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + move16(); } } - else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + ELSE IF( EQ_16( hIsmMeta[ch]->ism_md_fec_cnt_enc, ISM_MD_FEC_CNT_MAX ) ) { lowrate_metadata_flag[ch] = 1; - + move16(); hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); } } } @@ -301,7 +413,7 @@ ivas_error ivas_ism_metadata_enc( * Rate importance of particular ISM streams *----------------------------------------------------------------*/ - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { rate_ism_importance( nchan_transport, hIsmMeta, hSCE, lowrate_metadata_flag, ism_imp ); } @@ -310,18 +422,19 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Write ISM common signaling *----------------------------------------------------------------*/ - - if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && ism_mode != ISM_SBA_MODE_DISC ) + test(); + test(); + IF( NE_16( ism_mode, ISM_MASA_MODE_DISC ) && NE_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) && NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { /* write number of objects - unary coding */ - for ( ch = 1; ch < nchan_ism; ch++ ) + FOR( ch = 1; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); } push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { ism_metadata_flag_global |= hIsmMeta[ch]->ism_metadata_flag; ism_metadata_flag_global |= lowrate_metadata_flag[ch]; @@ -329,50 +442,56 @@ ivas_error ivas_ism_metadata_enc( } /* write extended metadata presence flag */ - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && *ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) + test(); + test(); + IF( ( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) && GE_32( *ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) { push_indice( hBstr, IND_ISM_EXTENDED_FLAG, ism_extended_metadata_flag, ISM_EXTENDED_METADATA_BITS ); /* Write global non-diegetic object flag */ - if ( ism_extended_metadata_flag ) + IF( ism_extended_metadata_flag ) { push_indice( hBstr, IND_ISM_EXTENDED_NDP_FLAG, non_diegetic_flag_global, ISM_EXTENDED_METADATA_BITS ); } } /* write ISM metadata flag (one per object) */ - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* flags will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_imp = ism_imp[ch]; + move16(); hIsmMeta[ch]->ism_md_null_flag = null_metadata_flag[ch]; + move16(); hIsmMeta[ch]->ism_md_lowrate_flag = lowrate_metadata_flag[ch]; + move16(); } - else + ELSE { - if ( null_metadata_flag[ch] ) + IF( null_metadata_flag[ch] ) { /* signal NULL metadata frame */ push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 1, ISM_METADATA_MD_FLAG_BITS ); /* write the ISM class to ISM_NO_META and again the true ISM class */ - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, ISM_METADATA_FLAG_BITS ); push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); } - else + ELSE { push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, 1 ); } } - else if ( ism_mode != ISM_SBA_MODE_DISC ) + ELSE IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); - if ( ism_imp[ch] == ISM_NO_META ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 0, ISM_METADATA_MD_FLAG_BITS ); @@ -381,7 +500,7 @@ ivas_error ivas_ism_metadata_enc( push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, lowrate_metadata_flag[ch], ISM_METADATA_INACTIVE_FLAG_BITS ); } } - else /*ism_mode == ISM_SBA_MODE_DISC*/ + ELSE /*ism_mode == ISM_SBA_MODE_DISC*/ { /* all objects are considered active*/ push_indice( hBstr, IND_ISM_METADATA_FLAG, 1, 1 ); @@ -390,129 +509,134 @@ ivas_error ivas_ism_metadata_enc( } - if ( ism_metadata_flag_global ) + IF( ism_metadata_flag_global ) { /*----------------------------------------------------------------* * Metadata quantization and coding, loop over all objects *----------------------------------------------------------------*/ - int16_t total_bits_metadata = 0; - int16_t bits_metadata_ism = 0; - int16_t nb_bits_objcod_written; + Word16 total_bits_metadata = 0; + move16(); + Word16 bits_metadata_ism = 0; + move16(); + Word16 nb_bits_objcod_written; - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { nb_bits_start = hBstr->nb_bits_tot; + move16(); } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMetaData = hIsmMeta[ch]; - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { nb_bits_start = hBstr->nb_bits_tot; + move16(); } - - if ( hIsmMeta[ch]->ism_metadata_flag || lowrate_metadata_flag[ch] ) + test(); + IF( hIsmMeta[ch]->ism_metadata_flag || lowrate_metadata_flag[ch] ) { /*----------------------------------------------------------------* * Quantize and encode azimuth and elevation *----------------------------------------------------------------*/ - - if ( ism_extended_metadata_flag && non_diegetic_flag_global ) + test(); + IF( ism_extended_metadata_flag && non_diegetic_flag_global ) { /* Write non-diegetic flag for each object */ push_indice( hBstr, IND_ISM_NDP_FLAG, hIsmMeta[ch]->non_diegetic_flag, ISM_METADATA_IS_NDP_BITS ); } - - if ( hIsmMeta[ch]->non_diegetic_flag && ism_extended_metadata_flag ) + test(); + IF( hIsmMeta[ch]->non_diegetic_flag && ism_extended_metadata_flag ) { /* Map azimuth to panning range [-90:90] */ - if ( hIsmMetaData->azimuth > 90.0f ) + IF( GT_32( hIsmMetaData->azimuth_fx, 377487360 /*90.0f Q22*/ ) ) { - hIsmMetaData->azimuth = 180.0f - hIsmMetaData->azimuth; + hIsmMetaData->azimuth_fx = L_sub( 754974720 /*180.0f Q22*/, hIsmMetaData->azimuth_fx ); + move32(); } - if ( hIsmMetaData->azimuth < -90.0f ) + IF( LT_32( hIsmMetaData->azimuth_fx, L_negate( 377487360 ) ) ) { - hIsmMetaData->azimuth = -180.0f - hIsmMetaData->azimuth; + hIsmMetaData->azimuth_fx = L_sub( L_negate( 754974720 ), hIsmMetaData->azimuth_fx ); + move32(); } #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ #else idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); #endif encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, 0, &flag_abs_azimuth[ch], NULL ); } - else + ELSE { - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); - hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ + // valQ = fixedToFloat( valQ_fx, Q22 ); #else idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); #endif } - else /* ISM_MODE_PARAM */ + ELSE /* ISM_MODE_PARAM */ { idx_angle1_abs = hParamIsm->azi_index[ch]; + move16(); idx_angle2_abs = hParamIsm->ele_index[ch]; + move16(); } encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); - /*----------------------------------------------------------------* * Quantize and encode radius, yaw, and pitch *----------------------------------------------------------------*/ - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && ism_extended_metadata_flag ) + test(); + test(); + IF( ( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) && ism_extended_metadata_flag ) { #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->yaw_fx = floatToFixed( hIsmMetaData->yaw, Q22 ); - hIsmMetaData->pitch_fx = floatToFixed( hIsmMetaData->pitch, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->yaw_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->pitch_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ + Word16 valQ_fx_tmp = extract_h( valQ_fx ); // 22 - 16 = 6 + idx_radius_abs = usquant_fx( hIsmMetaData->radius_fx, &valQ_fx_tmp, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8, 1 << ISM_RADIUS_NBITS ); + valQ_fx = L_shr( L_deposit_h( valQ_fx_tmp ), 3 ); // Q22 + // valQ = fixedToFloat( valQ_fx, Q22 ); #else idx_angle1_abs = ism_quant_meta( hIsmMetaData->yaw, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta( hIsmMetaData->pitch, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); -#endif idx_radius_abs = usquant( hIsmMetaData->radius, &valQ, ISM_RADIUS_MIN, ISM_RADIUS_DELTA, 1 << ISM_RADIUS_NBITS ); - +#endif encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } } /* save number of metadata bits written */ - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; } /* Updates */ - hIsmMeta[ch]->last_true_azimuth = hIsmMeta[ch]->azimuth; - hIsmMeta[ch]->last_true_elevation = hIsmMeta[ch]->elevation; - hIsmMeta[ch]->last_true_radius = hIsmMeta[ch]->radius; + hIsmMeta[ch]->last_true_azimuth_fx = hIsmMeta[ch]->azimuth_fx; + move32(); + hIsmMeta[ch]->last_true_elevation_fx = hIsmMeta[ch]->elevation_fx; + move32(); + hIsmMeta[ch]->last_true_radius_fx = hIsmMeta[ch]->radius_fx; + move16(); } } @@ -522,61 +646,64 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ i = 0; - while ( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) + WHILE( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) { - int16_t num, abs_num, abs_first, abs_next, pos_zero; - int16_t abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; + Word16 num, abs_num, abs_first, abs_next, pos_zero; + Word16 abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; num = min( INTER_OBJECT_PARAM_CHECK, nchan_ism - i * INTER_OBJECT_PARAM_CHECK ); i++; set_s( abs_matrice, 0, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); - for ( ch = 0; ch < num; ch++ ) + FOR( ch = 0; ch < num; ch++ ) { - if ( flag_abs_azimuth[ch] == 1 ) + IF( EQ_16( flag_abs_azimuth[ch], 1 ) ) { abs_matrice[ch * ISM_NUM_PARAM] = 1; + move16(); } - if ( flag_abs_elevation[ch] == 1 ) + IF( EQ_16( flag_abs_elevation[ch], 1 ) ) { abs_matrice[ch * ISM_NUM_PARAM + 1] = 1; + move16(); } } abs_num = sum_s( abs_matrice, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); abs_first = 0; - while ( abs_num > 1 ) + move16(); + WHILE( GT_16( abs_num, 1 ) ) { /* find first "1" entry */ - while ( abs_matrice[abs_first] == 0 ) + WHILE( abs_matrice[abs_first] == 0 ) { abs_first++; } /* find next "1" entry */ abs_next = abs_first + 1; - while ( abs_matrice[abs_next] == 0 ) + WHILE( abs_matrice[abs_next] == 0 ) { abs_next++; } /* find "0" position */ pos_zero = 0; - while ( abs_matrice[pos_zero] == 1 ) + WHILE( abs_matrice[pos_zero] == 1 ) { pos_zero++; } ch = abs_next / ISM_NUM_PARAM; - if ( abs_next % ISM_NUM_PARAM == 0 ) + IF( abs_next % ISM_NUM_PARAM == 0 ) { hIsmMeta[ch]->position_angle.angle1_diff_cnt = abs_num - 1; } - if ( abs_next % ISM_NUM_PARAM == 1 ) + IF( abs_next % ISM_NUM_PARAM == 1 ) { hIsmMeta[ch]->position_angle.angle2_diff_cnt = abs_num - 1; /*hIsmMeta[ch]->elevation_diff_cnt = min( hIsmMeta[ch]->elevation_diff_cnt, ISM_FEC_MAX );*/ @@ -587,22 +714,23 @@ ivas_error ivas_ism_metadata_enc( } } - if ( ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { - int16_t md_diff_flag[MAX_NUM_OBJECTS]; + Word16 md_diff_flag[MAX_NUM_OBJECTS]; set_s( md_diff_flag, 1, nchan_ism ); - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + IF( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; } - else + ELSE { hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + move16(); } hIsmMeta[ch]->ism_md_inc_diff_cnt++; hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); @@ -613,18 +741,18 @@ ivas_error ivas_ism_metadata_enc( pop_wmops(); return error; } - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { /* Keep the metdata transmission as is during active parts */ /* But send the flag with 1 bit */ push_next_indice( hBstr, hParamIsm->flag_noisy_speech, 1 ); /* Loop over multiwave to write the object indices into bitstream */ - for ( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) + FOR( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) { - for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + FOR( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) { - for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + FOR( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) { push_next_indice( hBstr, hParamIsm->obj_indices[nbands][nblocks][ch], PARAM_ISM_OBJ_IND_NBITS ); } @@ -632,29 +760,29 @@ ivas_error ivas_ism_metadata_enc( } /* Loop over bands to write the power ratio's indices into bitstream */ - for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + FOR( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) { - for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + FOR( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) { push_next_indice( hBstr, hParamIsm->power_ratios_idx[nbands][nblocks], PARAM_ISM_POW_RATIO_NBITS ); } } /* total metadata bits */ - total_bits_metadata = hBstr->nb_bits_tot - nb_bits_start; + total_bits_metadata = sub( hBstr->nb_bits_tot, nb_bits_start ); /* bits per ISM*/ - bits_metadata_ism = (int16_t) ( total_bits_metadata / nchan_transport ); + bits_metadata_ism = (Word16) ( total_bits_metadata / nchan_transport ); /* Divide the metadata bits into n_Isms*/ nb_bits_objcod_written = 0; - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ch == nchan_transport - 1 ) + IF( EQ_16( ch, sub( nchan_transport, 1 ) ) ) { nb_bits_metadata[ch] = total_bits_metadata - nb_bits_objcod_written; } - else + ELSE { nb_bits_metadata[ch] = bits_metadata_ism; nb_bits_objcod_written += bits_metadata_ism; @@ -662,7 +790,7 @@ ivas_error ivas_ism_metadata_enc( } } } - else if ( ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF( EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { pop_wmops(); return error; @@ -671,12 +799,12 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Take into account the combined format bit-budget distribution *----------------------------------------------------------------*/ - - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; - int16_t brate_limit_flag; - int32_t ism_total_brate_ref; + Word16 bits_ism, bits_element[MAX_NUM_OBJECTS]; + Word16 brate_limit_flag; + Word32 ism_total_brate_ref; ism_total_brate_ref = *ism_total_brate; #ifndef IVAS_FLOAT_FIXED brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); @@ -684,44 +812,44 @@ ivas_error ivas_ism_metadata_enc( brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, nchan_ism ); #endif - bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SEC ); + bits_ism = (Word16) ( *ism_total_brate / FRAMES_PER_SEC ); set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); bits_element[nchan_ism - 1] += bits_ism % nchan_ism; bitbudget_to_brate( bits_element, element_brate, nchan_ism ); *ism_total_brate = 0; - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { #ifndef IVAS_FLOAT_FIXED *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); #else *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); - move32(); #endif - - if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) + IF( GT_16( ism_imp[ch], 1 ) && EQ_16( flag_omasa_ener_brate, 1 ) && brate_limit_flag >= 0 ) { *ism_total_brate -= ADJUST_ISM_BRATE_NEG; } - if ( brate_limit_flag == -1 && ism_imp[ch] >= 1 && nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) + IF( EQ_16( brate_limit_flag, -1 ) && GE_16( ism_imp[ch], 1 ) && GE_16( nchan_ism, 3 ) && ( GT_32( L_sub( ism_total_brate_ref, *ism_total_brate ), IVAS_48k ) ) ) { *ism_total_brate += ADJUST_ISM_BRATE_POS; } } ism_metadata_flag_global = 1; + move16(); - if ( ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) { brate_limit_flag = 0; - for ( int16_t n = 0; n < nchan_ism; n++ ) + FOR( Word16 n = 0; n < nchan_ism; n++ ) { brate_limit_flag += ism_imp[n]; } - if ( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) + IF( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) { *omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + move16(); } } } @@ -730,62 +858,69 @@ ivas_error ivas_ism_metadata_enc( * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + move16(); - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + IF( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; } - else + ELSE { hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + move16(); } hIsmMeta[ch]->ism_md_inc_diff_cnt++; - hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); + hIsmMeta[ch]->ism_md_inc_diff_cnt = s_min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); } - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; - if ( ism_mode == ISM_MODE_DISC ) + move16(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) ) { - if ( ism_imp[ch] == ISM_NO_META && ( ( total_brate[ch] < ACELP_8k00 && element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) || - ( total_brate[ch] <= ACELP_16k_LOW_LIMIT && element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) ) ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || + ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + move16(); } hSCE[ch]->element_brate = element_brate[ch]; + move32(); } - else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ism_imp[ch] == ISM_INACTIVE_IMP ) + IF( EQ_16( ism_imp[ch], ISM_INACTIVE_IMP ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + move16(); } } hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; + move32(); /* write metadata only in active frames */ - if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) + IF( GT_32( hSCE[0]->hCoreCoder[0]->core_brate, SID_2k40 ) ) { reset_indices_enc( hSCE[ch]->hMetaData, hSCE[ch]->hMetaData->nb_ind_tot ); } @@ -1374,24 +1509,25 @@ ivas_error ivas_ism_metadata_enc( } #endif - /*------------------------------------------------------------------------- * ivas_ism_metadata_enc_create() * * Create, allocate, initialize and configure IVAS encoder ISM metadata handles *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc_create( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t n_ISms, /* i : number of objects */ - int32_t element_brate_tmp[] /* o : element bitrate per object */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t n_ISms, /* i : number of objects */ + Word32 element_brate_tmp[] /* o : element bitrate per object */ ) { - int16_t ch, nchan_transport; + Word16 ch, nchan_transport; ivas_error error; nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + move16(); + IF( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { nchan_transport = MAX_PARAM_ISM_WAVE; #ifndef IVAS_FLOAT_FIXED @@ -1400,65 +1536,97 @@ ivas_error ivas_ism_metadata_enc_create( ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); #endif } - else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) { nchan_transport = n_ISms; } - else + ELSE { - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( st_ivas->ism_mode == ISM_MODE_NONE ) { nchan_transport = st_ivas->nchan_transport; + move16(); - if ( nchan_transport == 1 ) + IF( nchan_transport == 1 ) { st_ivas->nSCE = 1; + move16(); st_ivas->nCPE = 0; + move16(); } - else + ELSE { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = 1; + move16(); } } - else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) { nchan_transport = 2; + move16(); } - else + ELSE { nchan_transport = n_ISms; + move16(); } st_ivas->nchan_transport = nchan_transport; st_ivas->nSCE = nchan_transport; st_ivas->nCPE = 0; + move16(); + move16(); + move16(); } /* allocate ISM metadata handles */ - for ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + IF( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); } st_ivas->hIsmMetaData[ch]->position_angle.last_angle1_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.last_angle2_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX - 1; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle1_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.angle1_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle2_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.angle2_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->last_radius_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->radius_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_imp = -1; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; - st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; - st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; + move16(); + + st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx = 0; + move16(); + st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; + move16(); + /*===============fix-to-flt====================*/ + st_ivas->hIsmMetaData[ch]->q_azimuth_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->q_elevation_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx, Q22 ); + /*===============fix-to-flt====================*/ + #ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); @@ -1466,36 +1634,48 @@ ivas_error ivas_ism_metadata_enc_create( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); #endif - st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; - st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; - st_ivas->hIsmMetaData[ch]->last_true_azimuth = 0.0f; - st_ivas->hIsmMetaData[ch]->last_true_elevation = 0.0f; + st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; - st_ivas->hIsmMetaData[ch]->last_true_radius = 1.0f; + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + + /*===============fix-to-flt====================*/ + 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 ); + + 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-to-flt====================*/ } - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) { return error; } } } - else + ELSE { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1503,14 +1683,243 @@ ivas_error ivas_ism_metadata_enc_create( return IVAS_ERR_OK; } - - -/*------------------------------------------------------------------------- - * encode_radius() - * - * Radius index encoding - *-------------------------------------------------------------------------*/ - +#else +ivas_error ivas_ism_metadata_enc_create( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t n_ISms, /* i : number of objects */ + int32_t element_brate_tmp[] /* o : element bitrate per object */ +) +{ + int16_t ch, nchan_transport; + ivas_error error; + + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + nchan_transport = MAX_PARAM_ISM_WAVE; +#ifndef IVAS_FLOAT_FIXED + ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#else + ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#endif + } + else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + { + nchan_transport = n_ISms; + } + else + { + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan_transport = st_ivas->nchan_transport; + + if ( nchan_transport == 1 ) + { + st_ivas->nSCE = 1; + st_ivas->nCPE = 0; + } + else + { + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; + } + } + else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + nchan_transport = 2; + } + else + { + nchan_transport = n_ISms; + } + + st_ivas->nchan_transport = nchan_transport; + st_ivas->nSCE = nchan_transport; + st_ivas->nCPE = 0; + } + + /* allocate ISM metadata handles */ + for ( ch = 0; ch < n_ISms; ch++ ) + { + if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); + } + st_ivas->hIsmMetaData[ch]->position_angle.last_angle1_idx = 0; + st_ivas->hIsmMetaData[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + st_ivas->hIsmMetaData[ch]->position_angle.last_angle2_idx = 0; + st_ivas->hIsmMetaData[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX - 1; + st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle1_idx = 0; + st_ivas->hIsmMetaData[ch]->orientation_angle.angle1_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle2_idx = 0; + st_ivas->hIsmMetaData[ch]->orientation_angle.angle2_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->last_radius_idx = 0; + st_ivas->hIsmMetaData[ch]->radius_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; + + st_ivas->hIsmMetaData[ch]->ism_imp = -1; + st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; + st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; + st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; + st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; + +#ifdef IVAS_FLOAT_FIXED + ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); +#else + ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); +#endif + + st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; + st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; + + st_ivas->hIsmMetaData[ch]->last_true_azimuth = 0.0f; + st_ivas->hIsmMetaData[ch]->last_true_elevation = 0.0f; + st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; + st_ivas->hIsmMetaData[ch]->last_true_radius = 1.0f; + } + + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return IVAS_ERR_OK; +} +#endif + +/*------------------------------------------------------------------------- + * encode_radius() + * + * Radius index encoding + *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void encode_radius( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 *last_radius_idx, /* i/o: last radius index */ + Word16 *radius_diff_cnt, /* i/o: radius diff coding counter */ + const Word16 last_ism_metadata_flag, /* last frame ism_metadata_flag */ + const Word16 idx_radius_abs, /* i : Azimuth index */ + Word16 *flag_abs_radius /* o : Radius encoding mode */ +) +{ + Word16 idx_radius, nbits_diff_radius, diff; + + idx_radius = idx_radius_abs; + nbits_diff_radius = 0; + move16(); + *flag_abs_radius = 0; /* differential coding by default */ + move16(); + + test(); + IF( EQ_16( *radius_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_radius = 1; + move16(); + } + + diff = sub( idx_radius_abs, *last_radius_idx ); + + /* try differential coding */ + IF( EQ_16( *flag_abs_radius, 0 ) ) + { + IF( EQ_16( diff, 0 ) ) + { + idx_radius = 0; + move16(); + nbits_diff_radius = 1; + move16(); + } + ELSE IF( LE_16( ABSVAL( diff ), ISM_MAX_RADIUS_DIFF_IDX ) ) + { + idx_radius = shl( 1, 1 ); + nbits_diff_radius = 1; + move16(); + + IF( LT_16( diff, 0 ) ) + { + idx_radius = add( idx_radius, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_radius = add( idx_radius, 0 ); /* positive sign */ + } + + idx_radius = shl( idx_radius, diff ); + nbits_diff_radius = add( nbits_diff_radius, 1 ); + + /* unary coding of "diff */ + idx_radius = add( idx_radius, sub( shl( 1, diff ), 1 ) ); + nbits_diff_radius = add( nbits_diff_radius, diff ); + + IF( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) ) + { + /* add stop bit */ + idx_radius = shl( idx_radius, 1 ); + nbits_diff_radius = add( nbits_diff_radius, 1 ); + } + } + ELSE + { + *flag_abs_radius = 1; + move16(); + } + } + + /* update counter */ + IF( EQ_16( *flag_abs_radius, 0 ) ) + { + ( *radius_diff_cnt )++; + *radius_diff_cnt = min( *radius_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + *radius_diff_cnt = 0; + move16(); + } + + /* Write radius */ + push_indice( hBstr, IND_ISM_RADIUS_DIFF_FLAG, *flag_abs_radius, 1 ); + + IF( *flag_abs_radius ) + { + push_indice( hBstr, IND_ISM_RADIUS, idx_radius, ISM_RADIUS_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_RADIUS, idx_radius, nbits_diff_radius ); + } + + /* Updates */ + *last_radius_idx = idx_radius_abs; + move16(); + + return; +} +#else static void encode_radius( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ int16_t *last_radius_idx, /* i/o: last radius index */ @@ -1606,7 +2015,7 @@ static void encode_radius( return; } - +#endif /*----------------------------------------------------------------* * encode_angle_indices() @@ -1614,6 +2023,268 @@ static void encode_radius( * Encoding of an angle *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void encode_angle_indices( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ + const Word16 last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ + const Word16 ini_frame, /* i : initialization frames counter */ + const Word16 idx_angle1_abs, /* i : Azimuth index */ + const Word16 idx_angle2_abs, /* i : Elevation index */ + Word16 *flag_abs_angle1, /* o : Azimuth/yaw encoding mode */ + Word16 *flag_abs_angle2 /* o : Elevation/pitch encoding mode */ +) +{ + Word16 idx_angle1, nbits_diff_angle1, diff; + Word16 idx_angle2, nbits_diff_angle2; + + /*----------------------------------------------------------------* + * Azimuth/yaw index encoding + *----------------------------------------------------------------*/ + + idx_angle1 = idx_angle1_abs; + + nbits_diff_angle1 = 0; + move16(); + *flag_abs_angle1 = 0; /* differential coding by default */ + test(); + if ( EQ_16( angle->angle1_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_angle1 = 1; + move16(); + } + + /* try differential coding */ + IF( *flag_abs_angle1 == 0 ) + { + diff = sub( idx_angle1_abs, angle->last_angle1_idx ); + + /* azimuth is on a circle - check for diff coding for -180° -> 180° and vice versa changes */ + IF( abs( diff ) > ( ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) - ISM_MAX_AZIMUTH_DIFF_IDX ) + { + IF( diff > 0 ) + { + diff = sub( diff, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); + } + ELSE + { + diff = add( diff, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); + } + } + + IF( diff == 0 ) + { + idx_angle1 = 0; + move16(); + nbits_diff_angle1 = 1; + move16(); + } + ELSE IF( LT_16( ABSVAL( diff ), ISM_MAX_AZIMUTH_DIFF_IDX ) ) /* when diff bits >= abs bits, prefer abs */ + { + idx_angle1 = shl( 1, 1 ); + nbits_diff_angle1 = 1; + move16(); + + IF( diff < 0 ) + { + idx_angle1 = add( idx_angle1, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_angle1 = add( idx_angle1, 0 ); /* positive sign */ + } + + idx_angle1 = shl( idx_angle1, diff ); + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); + + /* unary coding of "diff */ + idx_angle1 = add( idx_angle1, sub( shl( 1, diff ), 1 ) ); + nbits_diff_angle1 = add( nbits_diff_angle1, diff ); + + IF( LT_16( nbits_diff_angle1, ( ISM_AZIMUTH_NBITS - 1 ) ) ) + { + /* add stop bit - only for codewords shorter than ISM_AZIMUTH_NBITS */ + idx_angle1 = shl( idx_angle1, 1 ); + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); + } + } + ELSE + { + *flag_abs_angle1 = 1; + move16(); + } + } + + /* update counter */ + IF( *flag_abs_angle1 == 0 ) + { + angle->angle1_diff_cnt = add( angle->angle1_diff_cnt, 1 ); + angle->angle1_diff_cnt = s_min( angle->angle1_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + angle->angle1_diff_cnt = 0; + move16(); + } + + /* Write azimuth/yaw */ + push_indice( hBstr, IND_ISM_AZIMUTH_DIFF_FLAG, *flag_abs_angle1, 1 ); + + IF( *flag_abs_angle1 ) + { + push_indice( hBstr, IND_ISM_AZIMUTH, idx_angle1, ISM_AZIMUTH_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_AZIMUTH, idx_angle1, nbits_diff_angle1 ); + } + + /*----------------------------------------------------------------* + * Elevation/pitch index encoding + *----------------------------------------------------------------*/ + + IF( flag_abs_angle2 ) + { + idx_angle2 = idx_angle2_abs; + move16(); + nbits_diff_angle2 = 0; + move16(); + *flag_abs_angle2 = 0; /* differential coding by default */ + move16(); + IF( EQ_16( angle->angle2_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_angle2 = 1; + move16(); + } + + /* note: elevation/pitch is coded starting from the second frame only (it is meaningless in the init_frame) */ + IF( ini_frame == 0 ) + { + *flag_abs_angle2 = 1; + move16(); + angle->last_angle2_idx = idx_angle2_abs; + move16(); + } + + diff = sub( idx_angle2_abs, angle->last_angle2_idx ); + + /* avoid absolute coding of elevation/pitch if absolute coding was already used for azimuth/yaw */ + IF( EQ_16( *flag_abs_angle1, 1 ) ) + { + Word16 diff_orig = diff; + + *flag_abs_angle2 = 0; + move16(); + + + IF( diff >= 0 ) + { + diff = min( diff, ISM_MAX_ELEVATION_DIFF_IDX ); + } + ELSE + { + diff = imult1616( -1, min( -diff, ISM_MAX_ELEVATION_DIFF_IDX ) ); + } + + IF( last_ism_metadata_flag == 0 || abs( diff_orig - diff ) > ISM_MAX_ELEVATION_DIFF_IDX ) + { + angle->angle2_diff_cnt = ISM_FEC_MAX - 1; + move16(); + } + } + + /* try differential coding */ + IF( *flag_abs_angle2 == 0 ) + { + IF( diff == 0 ) + { + idx_angle2 = 0; + move16(); + nbits_diff_angle2 = 1; + move16(); + } + ELSE IF( LE_16( ABSVAL( diff ), ISM_MAX_ELEVATION_DIFF_IDX ) ) + { + idx_angle2 = shl( 1, 1 ); + nbits_diff_angle2 = 1; + move16(); + + IF( diff < 0 ) + { + idx_angle2 = add( idx_angle2, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_angle2 = add( idx_angle2, 0 ); /* positive sign */ + } + + idx_angle2 = shl( idx_angle2, diff ); + nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); + + /* unary coding of "diff */ + idx_angle2 = add( idx_angle2, sub( shl( 1, diff ), 1 ) ); + nbits_diff_angle2 = add( nbits_diff_angle2, diff ); + + IF( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) + { + /* add stop bit */ + idx_angle2 = shl( idx_angle2, 1 ); + nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); + } + } + ELSE + { + *flag_abs_angle2 = 1; + move16(); + } + } + + /* update counter */ + IF( *flag_abs_angle2 == 0 ) + { + angle->angle2_diff_cnt = add( angle->angle2_diff_cnt, 1 ); + angle->angle2_diff_cnt = s_min( angle->angle2_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + angle->angle2_diff_cnt = 0; + move16(); + } + + /* Write elevation */ + IF( *flag_abs_angle1 == 0 ) /* do not write "flag_abs_elevation/pitch" if "flag_abs_azimuth/yaw == 1" */ + { + push_indice( hBstr, IND_ISM_ELEVATION_DIFF_FLAG, *flag_abs_angle2, 1 ); + } + + IF( *flag_abs_angle2 ) + { + push_indice( hBstr, IND_ISM_ELEVATION, idx_angle2, ISM_ELEVATION_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_ELEVATION, idx_angle2, nbits_diff_angle2 ); + } + } + + /*----------------------------------------------------------------* + * Updates + *----------------------------------------------------------------*/ + + angle->last_angle1_idx = idx_angle1_abs; + move16(); + angle->last_angle2_idx = idx_angle2_abs; + move16(); + + return; +} +#else static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ @@ -1852,7 +2523,7 @@ static void encode_angle_indices( return; } - +#endif /*-------------------------------------------------------------------* * ivas_ism_metadata_sid_enc() @@ -1862,34 +2533,30 @@ static void encode_angle_indices( #ifdef IVAS_FLOAT_FIXED void ivas_ism_metadata_sid_enc( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - const int16_t flag_noisy_speech, /* i : noisy speech flag */ - const int16_t nchan_ism, /* i : number of objects */ - const int16_t nchan_transport, /* i : number of transport channels */ - const ISM_MODE ism_mode, /* i : ISM mode */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const int16_t sid_flag, /* i : indication of SID frame */ - const int16_t md_diff_flag[], /* i : metadata differental flag */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - int16_t nb_bits_metadata[] /* o : number of metadata bits */ + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + const Word16 flag_noisy_speech, /* i : noisy speech flag */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + const ISM_MODE ism_mode, /* i : ISM mode */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const Word16 sid_flag, /* i : indication of SID frame */ + const Word16 md_diff_flag[], /* i : metadata differental flag */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[] /* o : number of metadata bits */ ) { - int16_t i, ch, nBits, nBits_start, nBits_unused; - float q_step, q_step_border; -#ifdef IVAS_FLOAT_FIXED + Word16 i, ch, nBits, nBits_start, nBits_unused; Word32 q_step_fx, q_step_border_fx; -#endif - int16_t idx, idx_azimuth, idx_elevation; - int16_t nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; -#ifdef IVAS_FLOAT_FIXED + Word16 idx, idx_azimuth, idx_elevation; + Word16 nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; Word32 valQ_fx; -#endif + ISM_METADATA_HANDLE hIsmMetaData; - if ( sid_flag ) + IF( sid_flag ) { nBits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; - nBits -= SID_FORMAT_NBITS; + nBits = sub( nBits, SID_FORMAT_NBITS ); nBits_start = hBstr->nb_bits_tot; /*----------------------------------------------------------------* @@ -1897,14 +2564,14 @@ void ivas_ism_metadata_sid_enc( *----------------------------------------------------------------*/ /* write number of objects - unary coding */ - for ( ch = 1; ch < nchan_ism; ch++ ) + FOR( ch = 1; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); } push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); /* write SID metadata flag (one per object) */ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, md_diff_flag[ch], 1 ); } @@ -1913,25 +2580,25 @@ void ivas_ism_metadata_sid_enc( * Set quantization bits based on the number of coded objects *----------------------------------------------------------------*/ - ivas_get_ism_sid_quan_bitbudget( nchan_ism, &nBits_azimuth, &nBits_elevation, &q_step, &q_step_border, &nBits_coh, &nBits_sce_id ); + ivas_get_ism_sid_quan_bitbudget_fx( nchan_ism, &nBits_azimuth, &nBits_elevation, &q_step_fx, &q_step_border_fx, &nBits_coh, &nBits_sce_id ); /*----------------------------------------------------------------* * Spatial parameters, loop over TCs - 1 *----------------------------------------------------------------*/ /* write ISM mode flag to explicitly signal number of spatial parameters */ - if ( nchan_ism > 2 ) + IF( GT_16( nchan_ism, 2 ) ) { - if ( ism_mode == ISM_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 0, 1 ); } - else + ELSE { push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 1, 1 ); } - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { /* write noisy speech flag */ push_indice( hBstr, IND_ISM_NOISY_SPEECH_FLAG, flag_noisy_speech, 1 ); @@ -1939,20 +2606,22 @@ void ivas_ism_metadata_sid_enc( } } - if ( nchan_transport > 1 ) + IF( GT_16( nchan_transport, 1 ) ) { /* write sce id */ push_indice( hBstr, IND_ISM_SCE_ID_DTX, hISMDTX->sce_id_dtx, nBits_sce_id ); /* quantize and write coherence */ - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ch == hISMDTX->sce_id_dtx ) + IF( EQ_16( ch, hISMDTX->sce_id_dtx ) ) { continue; } - - idx = (int16_t) ( hISMDTX->coh[ch] * ( ( 1 << nBits_coh ) - 1 ) + 0.5f ); + Word32 tmp = Mpy_32_32( L_shr( L_deposit_h( hISMDTX->coh_fx[ch] ), 1 ) /*Q30*/, L_deposit_h( sub( shl( 1, nBits_coh ), 1 ) ) ); // Q15 + Word32 tmp_2 = L_add( tmp, 16384 /*0.5f in Q15*/ ); + idx = (Word16) L_shr( tmp_2, Q15 ); + // idx = (Word16) ( hISMDTX->coh[ch] * sub( shl( 1, nBits_coh ), 1 ) + 0.5f ); assert( ( idx >= 0 ) && ( idx <= ( ( 1 << nBits_coh ) - 1 ) ) ); push_indice( hBstr, IND_ISM_DTX_COH_SCA, idx, nBits_coh ); } @@ -1962,9 +2631,9 @@ void ivas_ism_metadata_sid_enc( * Metadata quantization and coding, loop over all objects *----------------------------------------------------------------*/ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { - if ( md_diff_flag[ch] == 1 ) + IF( md_diff_flag[ch] == 1 ) { hIsmMetaData = hIsmMeta[ch]; @@ -1972,8 +2641,6 @@ void ivas_ism_metadata_sid_enc( /*===============================flt-2-fix======================================*/ hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); - q_step_fx = floatToFixed( q_step, Q22 ); - q_step_border_fx = floatToFixed( q_step_border, Q22 ); /*===============================flt-2-fix======================================*/ idx_azimuth = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_azimuth ); idx_elevation = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_elevation ); @@ -1981,20 +2648,19 @@ void ivas_ism_metadata_sid_enc( idx_azimuth = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, q_step, q_step_border, 1 << nBits_azimuth ); idx_elevation = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, q_step, q_step_border, 1 << nBits_elevation ); #endif - push_indice( hBstr, IND_ISM_AZIMUTH, idx_azimuth, nBits_azimuth ); push_indice( hBstr, IND_ISM_ELEVATION, idx_elevation, nBits_elevation ); /* update last indexes to correspond to active frames coding */ - if ( nBits_azimuth > ISM_AZIMUTH_NBITS ) + IF( GT_16( nBits_azimuth, ISM_AZIMUTH_NBITS ) ) { - hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth >> ( nBits_azimuth - ISM_AZIMUTH_NBITS ); - hIsmMetaData->position_angle.last_angle2_idx = idx_elevation >> ( nBits_elevation - ISM_ELEVATION_NBITS ); + hIsmMetaData->position_angle.last_angle1_idx = shr( idx_azimuth, sub( nBits_azimuth, ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->position_angle.last_angle2_idx = shr( idx_elevation, sub( nBits_elevation, ISM_ELEVATION_NBITS ) ); } - else + ELSE { - hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth << ( ISM_AZIMUTH_NBITS - nBits_azimuth ); - hIsmMetaData->position_angle.last_angle2_idx = idx_elevation << ( ISM_ELEVATION_NBITS - nBits_elevation ); + hIsmMetaData->position_angle.last_angle1_idx = shl( idx_azimuth, sub( ISM_AZIMUTH_NBITS, nBits_azimuth ) ); + hIsmMetaData->position_angle.last_angle2_idx = shl( idx_elevation, sub( ISM_ELEVATION_NBITS, nBits_elevation ) ); } hIsmMetaData->ism_md_fec_cnt_enc = 0; @@ -2003,15 +2669,15 @@ void ivas_ism_metadata_sid_enc( } /* Write unused (padding) bits */ - nBits_unused = nBits - hBstr->nb_bits_tot; - while ( nBits_unused > 0 ) + nBits_unused = sub( nBits, hBstr->nb_bits_tot ); + WHILE( nBits_unused > 0 ) { i = min( nBits_unused, 16 ); push_indice( hBstr, IND_UNUSED, 0, i ); - nBits_unused -= i; + nBits_unused = sub( nBits_unused, i ); } - nb_bits_metadata[0] = hBstr->nb_bits_tot - nBits_start; + nb_bits_metadata[0] = sub( hBstr->nb_bits_tot, nBits_start ); } return; diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 10efa2f167d92f76e028f28654293aab3a085d94..eed03579efa702d021df487882f8fba2c50d8ea4 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -37,8 +37,7 @@ #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "cnst.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -548,6 +547,65 @@ void ivas_param_ism_enc( * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_param_ism_compute_noisy_speech_flag( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 i; + + /* Move the Noisy speech buffer */ + FOR( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = st_ivas->hParamIsm->noisy_speech_buffer[i + 1]; + move16(); + } + + /* Set flag_noisy_speech to 0 for cases where object energies are not roughly equal */ + IF( !st_ivas->hParamIsm->flag_equal_energy ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + st_ivas->hParamIsm->flag_noisy_speech = 0; + move16(); + move16(); + } + ELSE + { + /* For the current frame, make a decision based on some core-coder flags */ + test(); + IF( st_ivas->hSCE[0]->hCoreCoder[0]->flag_noisy_speech_snr && st_ivas->hSCE[1]->hCoreCoder[0]->flag_noisy_speech_snr ) + { + test(); + IF( st_ivas->hSCE[0]->hCoreCoder[0]->vad_flag || st_ivas->hSCE[1]->hCoreCoder[0]->vad_flag ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + move16(); + } + ELSE + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 1; + move16(); + } + } + ELSE + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + move16(); + } + + /* Do a decision based on hysteresis */ + st_ivas->hParamIsm->flag_noisy_speech = 1; + move16(); + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE; i++ ) + { + test(); + st_ivas->hParamIsm->flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech && st_ivas->hParamIsm->noisy_speech_buffer[i]; + } + } + + return; +} +#else void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -595,3 +653,4 @@ void ivas_param_ism_compute_noisy_speech_flag( return; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 26829a6d7d0a7ca6f96bc8bff0a0d85da1c9308d..636658d2562ed2b8279f9bba5c3368acc427a8e8 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -38,12 +38,10 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" - #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*-----------------------------------------------------------------------------------------* @@ -51,7 +49,7 @@ * * LFE Arithmetic coding block. Writes encoded data to bitstream. *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_lfe_arith_coding( LFE_ENC_HANDLE hLFE, BSTR_ENC_HANDLE hBstr, @@ -87,14 +85,55 @@ static void ivas_lfe_arith_coding( return; } +#else +static void ivas_lfe_arith_coding_fx( + LFE_ENC_HANDLE hLFE, + BSTR_ENC_HANDLE hBstr, + const Word16 quant_strategy, + Word16 *values ) +{ + Tastat as; + Word16 index, i; + Word16 max_value, offset; + UWord16 num_ele_per_grp; + Word16 num_groups; + index = 0; + num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1; + num_groups = shr( ivas_lfe_num_dct_pass_bins_tbl[quant_strategy], 1 ); + move16(); + move16(); + move16(); + + FOR( i = 0; i < num_groups; i++ ) + { + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; + move16(); + ari_start_encoding_14bits_ivas_fx( &as ); + offset = imult1616( 4, i ); + + FOR( index = 0; index < num_ele_per_grp; index++ ) + { + IF( values[index + offset] > max_value ) + { + values[add( index, offset )] = max_value; + move16(); + } + ivas_ari_encode_14bits_ext_fx( hBstr, &as, values[index + offset], hLFE->cum_freq_models[quant_strategy][i] ); + } + ivas_ari_done_encoding_14bits_fx( hBstr, &as ); + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_enc_quant() * * LFE quatization block, calls arithmetic coding block inside *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_lfe_enc_quant( LFE_ENC_HANDLE hLFE, float *pLfe_dct, @@ -319,7 +358,7 @@ static void ivas_lfe_enc_quant( } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_lfe_enc_quant_fx( LFE_ENC_HANDLE hLFE, @@ -537,7 +576,7 @@ static void ivas_lfe_enc_quant_fx( push_next_indice( hBstr, coding_strategy, 1 ); base2_num_bits_tot = sub( hBstr->nb_bits_tot, bits_written ); - ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values ); + ivas_lfe_arith_coding_fx( hLFE, hBstr, quant_strategy, values ); FOR( i = 0; i < num_groups; i++ ) { @@ -626,7 +665,7 @@ static void ivas_lfe_enc_quant_fx( * * LFE channel encoder *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_enc( LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ float data_lfe_ch[], /* i : input LFE signal */ @@ -669,7 +708,7 @@ void ivas_lfe_enc( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_lfe_enc_fx( LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ @@ -779,7 +818,85 @@ void ivas_lfe_enc_fx( * * Create, allocate and initialize IVAS encoder LFE handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_create_lfe_enc( + LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + Word16 input_frame; + LFE_ENC_HANDLE hLFE; + Word16 i, j; + + input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); + + /*-----------------------------------------------------------------* + * Allocate LFE handle + *-----------------------------------------------------------------*/ + + IF( ( hLFE = (LFE_ENC_HANDLE) malloc( sizeof( LFE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) ); + } + + /* initializations */ + hLFE->lfe_bits = 0; + move16(); + hLFE->pWindow_state = NULL; + hLFE->hBstr = NULL; + + /*-----------------------------------------------------------------* + * Input memory buffer: allocate and initialize + *-----------------------------------------------------------------*/ + + IF( ( hLFE->old_wtda_audio_fx = (Word32 *) malloc( sizeof( hLFE->old_wtda_audio_fx[0] ) * NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n" ) ); + } + + set32_fx( hLFE->old_wtda_audio_fx, 0, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); + hLFE->q_old_wtda_audio = 31; + move16(); + + /*-----------------------------------------------------------------* + * LFE Window: allocate and initialize + *-----------------------------------------------------------------*/ + + IF( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) ); + } + + ivas_lfe_window_init_fx( hLFE->pWindow_state, input_Fs, input_frame ); + + /* Initialization for entropy coding */ + hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1; + hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2; + hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3; + hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4; + hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1; + hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2; + hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3; + hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4; + /* Initialization base2 bits for each subgroup for no entropy coding */ + FOR( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ ) + { + FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ ) + { + // hLFE->lfe_enc_indices_coeffs_tbl[i][j] = + // (int16_t) ceilf( log2f( (float) ( ivas_lfe_num_ele_in_coder_models[i][j] + 1 ) ) ); + hLFE->lfe_enc_indices_coeffs_tbl[i][j] = + floor_log_2( add( ivas_lfe_num_ele_in_coder_models[i][j], 1 ) ); + move16(); + } + } + + *hLFE_out = hLFE; + + return IVAS_ERR_OK; +} +#else ivas_error ivas_create_lfe_enc( LFE_ENC_HANDLE *hLFE_out, /* o : IVAS LFE encoder structure */ const int32_t input_Fs /* i : input sampling rate */ @@ -866,14 +983,42 @@ ivas_error ivas_create_lfe_enc( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_lfe_enc_close() * * Destroy IVAS cncoder LFE handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_enc_close( + LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ +) +{ + test(); + IF( hLFE == NULL || *hLFE == NULL ) + { + return; + } + IF( ( *hLFE )->old_wtda_audio_fx != NULL ) + { + free( ( *hLFE )->old_wtda_audio_fx ); + ( *hLFE )->old_wtda_audio_fx = NULL; + } + + IF( ( *hLFE )->pWindow_state ) + { + free( ( *hLFE )->pWindow_state ); + ( *hLFE )->pWindow_state = NULL; + } + + free( ( *hLFE ) ); + ( *hLFE ) = NULL; + + return; +} +#else void ivas_lfe_enc_close( LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ) @@ -908,14 +1053,43 @@ void ivas_lfe_enc_close( return; } - +#endif /*------------------------------------------------------------------------- * ivas_create_lfe_lpf_enc() * * Create, allocate and initialize IVAS encoder LFE low pass filter state handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_create_lfe_lpf_enc_fx( + ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + const Word32 *filt_coeff; + const Word16 *filt_coeff_e = NULL; + + IF( hLfeLpf == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Can not allocate memory for LFE LPF\n" ) ); + } + + /*-----------------------------------------------------------------* + * Allocate LFE LPF handle + *-----------------------------------------------------------------*/ + IF( ( *hLfeLpf = (ivas_filters_process_state_t *) malloc( sizeof( ivas_filters_process_state_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE LPF\n" ) ); + } + + ivas_lfe_lpf_select_filt_coeff_fx( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff, &filt_coeff_e ); + + ivas_filters_init_fx( *hLfeLpf, filt_coeff, filt_coeff_e, IVAS_FILTER_ORDER_4 ); + + return IVAS_ERR_OK; +} +#else ivas_error ivas_create_lfe_lpf_enc( ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -943,14 +1117,30 @@ ivas_error ivas_create_lfe_lpf_enc( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_lfe_lpf_enc_close() * * Destroy IVAS cncoder LFE low pass filter state *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_lpf_enc_close( + ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ +) +{ + test(); + IF( hLfeLpf == NULL || *hLfeLpf == NULL ) + { + return; + } + + free( ( *hLfeLpf ) ); + ( *hLfeLpf ) = NULL; + return; +} +#else void ivas_lfe_lpf_enc_close( ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ ) @@ -965,6 +1155,7 @@ void ivas_lfe_lpf_enc_close( return; } +#endif /*------------------------------------------------------------------------- @@ -972,7 +1163,18 @@ void ivas_lfe_lpf_enc_close( * * Apply IVAS cncoder LFE low pass filter *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_lpf_enc_apply_fx( + ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ + Word32 data_lfe_ch[], /* i/o: LFE signal */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + ivas_filter_process_fx( hLfeLpf, data_lfe_ch, input_frame, (Word16) Q11 ); + return; +} +#else void ivas_lfe_lpf_enc_apply( ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ float data_lfe_ch[], /* i/o: LFE signal */ @@ -983,3 +1185,4 @@ void ivas_lfe_lpf_enc_apply( return; } +#endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6c2d569af9752a7b5b4ce7c9128823e8de833632..1684d34a143e64468438dbfc56e7cd18b596dac0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -39,11 +39,8 @@ #include "ivas_stat_enc.h" #include "wmc_auto.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED @@ -136,7 +133,11 @@ ivas_error ivas_masa_enc_open( for ( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index db20e7bc260a0c93f4e75ecfce531cea273e1d92..06c9dde4d4464ddcf5f7345ba92b68b30eea4bbf 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -40,11 +40,15 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" +#ifdef DEBUGGING +#include "debug.h" +#endif /*------------------------------------------------------------------------- * Local function prototypes @@ -52,7 +56,11 @@ static void ivas_mc_paramupmix_dmx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *data_f[], const int16_t input_frame ); +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *input_frame_t[], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); +#else static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *input_frame_t[], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); +#endif static void get_huff_table( const PAR_TYPE par_type, HUFF_TAB *df0, HUFF_TAB *df ); @@ -197,10 +205,17 @@ ivas_error ivas_mc_paramupmix_enc_open( for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, COV_SMOOTH_MC, st_ivas->hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else if ( ( error = ivas_spar_covar_enc_open( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, COV_SMOOTH_MC, st_ivas->hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif } for ( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) @@ -333,7 +348,11 @@ void ivas_mc_paramupmix_enc_close( /* Covariance handle */ if ( ( *hMCParamUpmix )->hCovEnc[i] != NULL ) { +#ifdef IVAS_FLOAT_FIXED + ivas_spar_covar_enc_close_fx( &( *hMCParamUpmix )->hCovEnc[i], ( MC_PARAMUPMIX_NCH + 1 ) ); +#else ivas_spar_covar_enc_close( &( *hMCParamUpmix )->hCovEnc[i], ( MC_PARAMUPMIX_NCH + 1 ) ); +#endif } } @@ -664,12 +683,21 @@ static void ivas_mc_paramupmix_dmx( * estimate the input and down mix covariances *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_mc_paramupmix_param_est_enc( + MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + float *data_f[], /* i : Input frame in the time domain */ + const int16_t input_frame, /* i : Input frame length */ + float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], + float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ) +#else static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ float *data_f[], /* i : Input frame in the time domain */ const int16_t input_frame, /* i : Input frame length */ float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ) +#endif { float *pcm_in[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float fr_realbuffer[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH][L_FRAME48k]; @@ -679,8 +707,19 @@ static void ivas_mc_paramupmix_param_est_enc( float *p_fr_imagbuffer[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float *pp_in_fr_real[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; float *pp_in_fr_imag[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; +#ifdef IVAS_FLOAT_FIXED + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 *q_cov_real[IVAS_SPAR_MAX_CH]; + Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH]; + Word32 cov_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 cov_dtx_real_buf_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 *pp_in_fr_real_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH], *pp_in_fr_imag_fx[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; + Word16 q_ppIn_FR[MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH]; +#else float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#endif float rxx, rxy, ryy, cmat, rxxest, drxx, wetaux; int16_t l_ts; int16_t b, i, j, ts, bnd; @@ -721,14 +760,14 @@ static void ivas_mc_paramupmix_param_est_enc( ivas_transient_det_process( hMCParamUpmix->hTranDet[2 * i + 1], pcm_in[2 * i + 1], input_frame, transient_det_r ); #else ivas_transient_det_process_fx( hMCParamUpmix->hTranDet[2 * i], pcm_in_fx[2 * i], input_frame, transient_det_l ); -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING float a[2]; a[0] = transient_det_l[0]; a[1] = transient_det_l[1]; dbgwrite_txt( a, 2, "fixed.txt", NULL ); #endif ivas_transient_det_process_fx( hMCParamUpmix->hTranDet[2 * i + 1], pcm_in_fx[2 * i + 1], input_frame, transient_det_r ); -#ifdef DUMPS_ENABLED +#ifdef DEBUGGING a[0] = transient_det_r[0]; a[1] = transient_det_r[1]; dbgwrite_txt( a, 2, "fixed.txt", NULL ); @@ -785,12 +824,89 @@ static void ivas_mc_paramupmix_param_est_enc( { for ( j = 0; j < MC_PARAMUPMIX_NCH; j++ ) { +#ifdef IVAS_FLOAT_FIXED + cov_real_fx[i][j] = cov_real_buf_fx[i][j]; + cov_dtx_real_fx[i][j] = cov_dtx_real_buf_fx[i][j]; +#else cov_real[i][j] = hMCParamUpmix->cov_real[b][i][j]; cov_dtx_real[i][j] = hMCParamUpmix->cov_dtx_real[b][i][j]; +#endif + } +#ifdef IVAS_FLOAT_FIXED + IF( ( q_cov_real[i] = (Word16 *) malloc( sizeof( Word16 ) * MC_PARAMUPMIX_NCH ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set_s( q_cov_real[i], Q31, MC_PARAMUPMIX_NCH ); + IF( ( q_cov_dtx_real[i] = (Word16 *) malloc( sizeof( Word16 ) * MC_PARAMUPMIX_NCH ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } + set_s( q_cov_dtx_real[i], Q31, MC_PARAMUPMIX_NCH ); +#endif } +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) + { + IF( ( pp_in_fr_real_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); + } + set_zero_fx( pp_in_fr_real_fx[i], input_frame ); + IF( ( pp_in_fr_imag_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * input_frame ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder Fixed" ); + } + set_zero_fx( pp_in_fr_imag_fx[i], input_frame ); + } + set_s( q_ppIn_FR, Q31, MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); + +#ifdef MSAN_FIX + FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) +#else + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) +#endif + { + q_ppIn_FR[i] = L_get_q_buf1( pp_in_fr_real[i], input_frame ); + q_ppIn_FR[i] = min( q_ppIn_FR[i], L_get_q_buf1( pp_in_fr_imag[i], input_frame ) ); + floatToFixed_arrL( pp_in_fr_real[i], pp_in_fr_real_fx[i], q_ppIn_FR[i], input_frame ); + floatToFixed_arrL( pp_in_fr_imag[i], pp_in_fr_imag_fx[i], q_ppIn_FR[i], input_frame ); + } +#endif + +#ifdef IVAS_FLOAT_FIXED + ivas_enc_cov_handler_process_fx( hMCParamUpmix->hCovEnc[b], pp_in_fr_real_fx, pp_in_fr_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); +#else ivas_enc_cov_handler_process( hMCParamUpmix->hCovEnc[b], pp_in_fr_real, pp_in_fr_imag, cov_real, cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); +#endif + +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) + { + FOR( j = 0; j < MC_PARAMUPMIX_NCH; j++ ) + { + FOR( k = 0; k < hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands; k++ ) + { + hMCParamUpmix->cov_real[b][i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[i][j][k] ) ); + hMCParamUpmix->cov_dtx_real[b][i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, hMCParamUpmix->hCovEnc[b]->pCov_dtx_state->q_cov_real_per_band[i][j][k] ) ); + } + } + free( q_cov_real[i] ); + q_cov_real[i] = NULL; + free( q_cov_dtx_real[i] ); + q_cov_dtx_real[i] = NULL; + } + // Note: No need to convert pp_in_fr_real_fx and pp_in_fr_imag_fx back to float as they are not used after ivas_mc_paramupmix_param_est_enc() + + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) + { + free( pp_in_fr_real_fx[i] ); + pp_in_fr_real_fx[i] = NULL; + free( pp_in_fr_imag_fx[i] ); + pp_in_fr_imag_fx[i] = NULL; + } +#endif } maxbands = hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands; @@ -824,5 +940,9 @@ static void ivas_mc_paramupmix_param_est_enc( } } +#ifdef IVAS_FLOAT_FIXED + return IVAS_ERR_OK; +#else return; +#endif } diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 34f1c22495057ae53510d6f9beb6d187a839d14c..3a49e4aae9573acc0c63caa782918fa80a519610 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -39,8 +39,7 @@ #include "ivas_prot_fx.h" #include "options.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" @@ -1018,7 +1017,34 @@ void ivas_mcmasa_param_est_enc( { mvr2r( intensity_real[2], &( hMcMasa->buffer_intensity_real_vert[index - 1][0] ), num_freq_bands ); computeVerticalDiffuseness( hMcMasa->buffer_intensity_real_vert, hMcMasa->buffer_energy, hMcMasa->no_col_avg_diff, num_freq_bands, vertical_diffuseness_vector ); +#ifdef IVAS_FLOAT_FIXED + //////////////////////// to be removed /////////////////////////////// + Word32 x1_fx[MASA_FREQUENCY_BANDS]; + Word32 x2_fx[MASA_FREQUENCY_BANDS]; + Word32 y_fx[MASA_FREQUENCY_BANDS]; + Word16 x1_q_fx[MASA_FREQUENCY_BANDS]; + Word16 x2_q_fx[MASA_FREQUENCY_BANDS]; + Word16 y_q_fx[MASA_FREQUENCY_BANDS]; + FOR( i = 0; i < num_freq_bands; i++ ) + { + x1_q_fx[i] = Q_factor_L( diffuseness_vector[i] ); + x1_fx[i] = (Word32) ( diffuseness_vector[i] * ( W_shl( 1, x1_q_fx[i] ) ) ); + x2_q_fx[i] = Q_factor_L( vertical_diffuseness_vector[i] ); + x2_fx[i] = (Word32) ( vertical_diffuseness_vector[i] * ( W_shl( 1, x2_q_fx[i] ) ) ); + } + ///////////////////////////////////////////////////////////////////////// + + v_min_fx( (const Word32 *) x1_fx, x1_q_fx, (const Word32 *) x2_fx, x2_q_fx, y_fx, y_q_fx, num_freq_bands ); + + //////////////////////// to be removed //////////////////////////////// + FOR( i = 0; i < num_freq_bands; i++ ) + { + diffuseness_vector[i] = (Float32) y_fx[i] / ( W_shl( 1, y_q_fx[i] ) ); + } + /////////////////////////////////////////////////////////////////////// +#else v_min( diffuseness_vector, vertical_diffuseness_vector, diffuseness_vector, num_freq_bands ); +#endif } for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index cc18b15cf3420e7334c85be6ff8538d4a1a94e3f..ba72415325d6461cbb10c0083e3cb2f499fd0543 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -39,7 +39,10 @@ #include "rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif @@ -112,7 +115,11 @@ static void AdjustChannelRatios( float cur_ratio, tar_ratio, sum_ratio, sum_tar_ratio; int16_t ratio_diff, i; +#ifdef IVAS_FLOAT_FIXED + ivas_spar_bitrate_dist_fx( temp_brs, nAvailBits, ivas_total_brate, sba_order, (Word16) FB ); +#else ivas_spar_bitrate_dist( temp_brs, nAvailBits, ivas_total_brate, sba_order, (int16_t) FB ); +#endif sum_ratio = 0.0f; for ( i = 0; i < nChannels; i++ ) @@ -174,7 +181,7 @@ static void AdjustChannelRatios( * * joint mct encoding *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_mct_core_enc( const IVAS_FORMAT ivas_format, /* i : IVAS format */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ @@ -186,6 +193,15 @@ void ivas_mct_core_enc( const int16_t sba_order /* i : Ambisonic (SBA) order */ ) { +#ifdef IVAS_FLOAT_FIXED + Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ + Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k]; + Word32 powerSpecMsInv_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* MS inv power spectrum, also inverse MDST spectrum */ + Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][2]; + Word32 *inv_mdst_spectrum_fx[MCT_MAX_CHANNELS][2]; + Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][2]; + Word32 inv_spectrum_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ +#endif // IVAS_FLOAT_FIXED int16_t ch, ch_core, nSubframes, L_subframeTCX; int16_t i, cpe_id, n, nAvailBits; int16_t nCPE; @@ -224,6 +240,13 @@ void ivas_mct_core_enc( for ( ch = 0; ch < nChannels; ch++ ) { +#ifdef IVAS_FLOAT_FIXED + inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; + inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + inv_spectrum_fx[ch][0] = inv_spectrum_long_fx[ch]; + inv_spectrum_fx[ch][1] = inv_spectrum_long_fx[ch] + N_TCX10_MAX; + UNUSED_PARAM( inv_mdst_spectrum_fx ); +#endif inv_mdst_spectrum[ch][0] = powerSpecMsInv[ch][0] = powerSpecMsInv_long[ch]; inv_mdst_spectrum[ch][1] = powerSpecMsInv[ch][1] = powerSpecMsInv_long[ch] + N_TCX10_MAX; inv_spectrum[ch][0] = inv_spectrum_long[ch]; @@ -241,8 +264,14 @@ void ivas_mct_core_enc( continue; } +#ifdef IVAS_FLOAT_FIXED + orig_spectrum_fx[i][0] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch]; + orig_spectrum_fx[i][1] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch] + N_TCX10_MAX; +#endif // IVAS_FLOAT_FIXED + mdst_spectrum[i][0] = hMCT->p_mdst_spectrum_long[cpe_id][ch]; mdst_spectrum[i][1] = hMCT->p_mdst_spectrum_long[cpe_id][ch] + N_TCX10_MAX; + orig_spectrum[i][0] = hMCT->p_orig_spectrum_long[cpe_id][ch]; orig_spectrum[i][1] = hMCT->p_orig_spectrum_long[cpe_id][ch] + N_TCX10_MAX; @@ -263,28 +292,16 @@ void ivas_mct_core_enc( if ( switch_bw ) { -#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); -#else - initMdctStereoEncData_fx( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, - sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); -#endif } if ( sts[ch_core]->igf ) { -#ifndef IVAS_FLOAT_FIXED /* calculate the igf start band from the igf start line */ stereo_mdct_init_igf_start_band( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20, 1.0f, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); stereo_mdct_init_igf_start_band( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10, 0.5f, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); -#else - /* calculate the igf start band from the igf start line */ - stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20, 16384 /* 1.0f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); - - stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10, 8192 /* 0.5f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); -#endif } else { @@ -412,7 +429,11 @@ void ivas_mct_core_enc( { if ( hMCT->currBlockDataCnt > 0 ) { +#ifdef IVAS_FLOAT_FIXED + mctStereoIGF_enc_fx( hMCT, sts, orig_spectrum_fx, powerSpec_fx, powerSpecMsInv_fx, inv_spectrum_fx, orig_spectrum, powerSpec, powerSpecMsInv, inv_spectrum, sp_aud_decision0 ); +#else mctStereoIGF_enc( hMCT, sts, orig_spectrum, powerSpec, powerSpecMsInv, inv_spectrum, sp_aud_decision0 ); +#endif // IVAS_FLOAT_FIXED } else { @@ -555,3 +576,587 @@ void ivas_mct_core_enc( return; } +#else +void ivas_mct_core_enc( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ + const Word16 nChannels, /* i : number of channels to be coded */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 switch_bw, /* i : flag bandwidth switch occurance */ + const Word16 lfe_bits, /* i : bits spent for LFE */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +) +{ + Word16 ch, ch_core, nSubframes, L_subframeTCX; + Word16 i, cpe_id, n, nAvailBits; + Word16 nCPE; + float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ + float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k]; + float powerSpecMsInv_long[MCT_MAX_CHANNELS][L_FRAME48k]; /* MS inv power spectrum, also inverse MDST spectrum */ + float *powerSpecMsInv[MCT_MAX_CHANNELS][2]; + float *inv_mdst_spectrum[MCT_MAX_CHANNELS][2]; + float *inv_spectrum[MCT_MAX_CHANNELS][2]; + float *mdst_spectrum[MCT_MAX_CHANNELS][2] = { NULL }; + float inv_spectrum_long[MCT_MAX_CHANNELS][L_FRAME48k]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ +#if 0 + Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ +#endif + Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k]; + Word32 mdst_fx; + Word32 powerSpecMsInv_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* MS inv power spectrum, also inverse MDST spectrum */ + Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][2]; + Word32 *inv_mdst_spectrum_fx[MCT_MAX_CHANNELS][2]; + Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][2]; + Word32 *mdst_spectrum_fx[MCT_MAX_CHANNELS][2] = { NULL }; + Word32 inv_spectrum_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ + Word16 total_side_bits; + Word16 chBitRatios[MCT_MAX_CHANNELS]; + Word16 q_powSpec[MCT_MAX_CHANNELS], q_spec, tmp_s; + Word16 tmp_q_powSpec[L_FRAME48k], tmp_q_powSpecInv[L_FRAME48k], *tmp_q_psi[2]; + Word64 W_tmp; + Encoder_State *sts[MCT_MAX_CHANNELS]; + Encoder_State *st; + Word16 sp_aud_decision0[MCT_MAX_CHANNELS]; + BSTR_ENC_HANDLE hBstr; + + push_wmops( "mct_encoding" ); + + /*--------------------------------------------------------------* + * Initialization + *---------------------------------------------------------------*/ + + total_side_bits = 0; + move16(); + + nCPE = shr( nChannels, 1 ); // nChannels / CPE_CHANNELS + + /*in case of odd number of channels*/ + if ( NE_16( ( nCPE * CPE_CHANNELS ), nChannels ) ) + { + nCPE = add( nCPE, 1 ); + } + + FOR( ch = 0; ch < nChannels; ch++ ) + { +#if 1 // Float initialization to be removed + inv_mdst_spectrum[ch][0] = powerSpecMsInv[ch][0] = powerSpecMsInv_long[ch]; + inv_mdst_spectrum[ch][1] = powerSpecMsInv[ch][1] = powerSpecMsInv_long[ch] + N_TCX10_MAX; + inv_spectrum[ch][0] = inv_spectrum_long[ch]; + inv_spectrum[ch][1] = inv_spectrum_long[ch] + N_TCX10_MAX; +#endif + + set32_fx( inv_spectrum_long_fx[ch], 0, L_FRAME48k ); + set32_fx( powerSpec_fx[ch], 0, L_FRAME48k ); + set32_fx( powerSpecMsInv_long_fx[ch], 0, L_FRAME48k ); + + inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; + inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + inv_spectrum_fx[ch][0] = inv_spectrum_long_fx[ch]; + inv_spectrum_fx[ch][1] = inv_spectrum_long_fx[ch] + N_TCX10_MAX; + } + + set16_fx( tmp_q_powSpecInv, 63, L_FRAME48k ); + set16_fx( tmp_q_powSpec, 63, L_FRAME48k ); + + tmp_q_psi[0] = tmp_q_powSpecInv; + tmp_q_psi[1] = &tmp_q_powSpecInv[N_TCX10_MAX]; + + FOR( ( cpe_id = 0, i = 0 ); cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = hCPE[cpe_id]->hCoreCoder[ch]; + IF( EQ_32( hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + i = add( i, 1 ); + CONTINUE; + } +#if 1 // Float initialization to be removed + mdst_spectrum[i][0] = hMCT->p_mdst_spectrum_long[cpe_id][ch]; + mdst_spectrum[i][1] = hMCT->p_mdst_spectrum_long[cpe_id][ch] + N_TCX10_MAX; + orig_spectrum[i][0] = hMCT->p_orig_spectrum_long[cpe_id][ch]; + orig_spectrum[i][1] = hMCT->p_orig_spectrum_long[cpe_id][ch] + N_TCX10_MAX; +#endif + mdst_spectrum_fx[i][0] = hMCT->p_mdst_spectrum_long_fx[cpe_id][ch]; + mdst_spectrum_fx[i][1] = hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] + N_TCX10_MAX; +#if 0 + orig_spectrum_fx[i][0] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch]; + orig_spectrum_fx[i][1] = hMCT->p_orig_spectrum_long_fx[cpe_id][ch] + N_TCX10_MAX; +#endif + + sp_aud_decision0[i] = hCPE[cpe_id]->hCoreCoder[0]->sp_aud_decision0; + move16(); + + sts[i]->hTcxEnc->tns_ms_flag[0] = 0; + sts[i]->hTcxEnc->tns_ms_flag[1] = 0; + move16(); + move16(); + + i = add( i, 1 ); + } + } + + hBstr = sts[0]->hBstr; + + FOR( ch = 0; ch < shr( hMCT->nchan_out_woLFE, 1 ); ch++ ) + { + ch_core = imult1616( ch, CPE_CHANNELS ); + + IF( switch_bw ) + { + initMdctStereoEncData_fx( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, + sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); + } + + IF( sts[ch_core]->igf ) + { + /* calculate the igf start band from the igf start line */ + stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20, 16384 /* 1.0f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); + + stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10, 8192 /* 0.5f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); + } + ELSE + { + hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; + hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; + hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10.nBandsStereoCore = hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10.sfbCnt; + hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20.nBandsStereoCore = hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20.sfbCnt; + move16(); + move16(); + move16(); + move16(); + } + } + + FOR( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + CONTINUE; + } + + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + } + + FOR( n = 0; n < nSubframes; n++ ) + { + st->side_bits_frame_channel = add( st->side_bits_frame_channel, NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + move16(); + } + + /* Add estimated stereo bits */ + st->side_bits_frame_channel = add( st->side_bits_frame_channel, NBBITS_MCT_RATIO ); + move16(); + } + + /*--------------------------------------------------------------* + * MCT algorithm + *---------------------------------------------------------------*/ + + apply_MCT_enc_fx( hMCT, sts, mdst_spectrum_fx, inv_spectrum_fx, inv_mdst_spectrum_fx, nChannels ); + + /*--------------------------------------------------------------* + * Power spectrum calculation for Noise Estimation + *---------------------------------------------------------------*/ + FOR( ch = 0; ch < nChannels; ch++ ) + { + IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + CONTINUE; + } + IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + L_subframeTCX = sts[ch]->hTcxEnc->L_frameTCX; + move16(); + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); + } + + /* in MCT only relevant for bitrate switching from non-MCT bitrates */ + IF( EQ_16( sts[ch]->last_core, ACELP_CORE ) ) + { + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + } + + FOR( n = 0; n < nSubframes; n++ ) + { + q_spec = sub( 31, sts[ch]->hTcxEnc->spectrum_e[0] ); + + IF( sts[ch]->hTcxEnc->tns_ms_flag[n] ) + { + /* power spectrum: MDCT^2 + MDST^2 */ + FOR( i = 0; i < L_subframeTCX; i++ ) + { + W_tmp = W_mac_32_32( W_mult_32_32( mdst_spectrum_fx[ch][n][i], mdst_spectrum_fx[ch][n][i] ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); + tmp_q_powSpec[add( i, imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + + W_tmp = W_mac_32_32( W_mult_32_32( inv_mdst_spectrum_fx[ch][n][i], inv_mdst_spectrum_fx[ch][n][i] ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); + tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + } + } + ELSE + { + IF( hMCT->currBlockDataCnt > 0 ) + { + /* power spectrum: MDCT^2 + MDST^2 */ + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp ); + tmp_q_psi[n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + + FOR( i = 1; i < L_subframeTCX - 1; i++ ) + { + mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); /* An MDST estimate */ + + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); + tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + } + + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp ); + tmp_q_psi[n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + } + + /* power spectrum: MDCT^2 + MDST^2 */ + W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][0], sts[ch]->hTcxEnc->spectrum_fx[n][0] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpec_fx[ch][n * L_subframeTCX] = W_extract_h( W_tmp ); + tmp_q_powSpec[n * L_subframeTCX] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + + FOR( i = 1; i < L_subframeTCX - 1; i++ ) + { + mdst_fx = L_sub( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], sts[ch]->hTcxEnc->spectrum_fx[n][i - 1] ); /* An MDST estimate */ + + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); + tmp_q_powSpec[add( i, imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + } + + W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1], sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1] ); + tmp_s = sub( W_norm( W_tmp ), 1 ); + W_tmp = W_shl( W_tmp, tmp_s ); + powerSpec_fx[ch][add( sub( L_subframeTCX, 1 ), imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); + tmp_q_powSpec[add( sub( L_subframeTCX, 1 ), imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + move32(); + move16(); + } + } + + /* Aligning the Q-factors */ + { + /* NOTE: This logic has been added because using a constant headroom while computing `powSpec` and `powSpecMsInv` leads to significant precision loss, which results in poor quality. */ + FOR( i = 0; i < L_FRAME48k; i++ ) + { + if ( powerSpec_fx[ch][i] == 0 ) + { + tmp_q_powSpec[i] = 63; + move16(); + } + if ( powerSpecMsInv_fx[ch][0][i] == 0 ) + { + tmp_q_powSpecInv[i] = 63; + move16(); + } + } + minimum_s( tmp_q_powSpec, L_FRAME48k, &q_powSpec[ch] ); + minimum_s( tmp_q_powSpecInv, L_FRAME48k, &tmp_s ); + q_powSpec[ch] = s_min( q_powSpec[ch], tmp_s ); + move16(); + + FOR( n = 0; n < nSubframes; n++ ) + { + FOR( i = 0; i < L_subframeTCX; i++ ) + { + powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powSpec[ch] ) ); + powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) ); + move32(); + move32(); + } + } + } + } + + FOR( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + CONTINUE; + } + + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + L_subframeTCX = st->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframeTCX = shr( st->hTcxEnc->L_frameTCX, 1 ); + } + + /* in MCT only relevant for bitrate switching from non-MCT bitrates */ + IF( st->last_core == ACELP_CORE ) + { + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + } + + test(); + test(); + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) && ( LT_32( st->total_brate, HQ_96k ) || st->igf ) ) + { + /*-----------------------------------------------------------* + * Compute noise-measure flags for spectrum filling * + * and quantization (0: tonal, 1: noise-like). * + * Detect low pass if present. * + *-----------------------------------------------------------*/ + + test(); + ComputeSpectrumNoiseMeasure_fx( powerSpec_fx[ch], st->hTcxEnc->L_frameTCX, st->hTcxEnc->nmStartLine, NE_32( imult3216( st->last_sr_core, st->L_frame ), imult3216( st->sr_core, st->L_frame_past ) ) || NE_16( st->last_core, TCX_20_CORE ), st->hTcxEnc->memQuantZeros, st->hTcxEnc->L_frameTCX ); + } + +#if 1 // Float initialization to be removed + st->hTcxEnc->measuredBwRatio_flt = 1.f; /* No bandwidth limit for the noise filling */ +#endif + st->hTcxEnc->measuredBwRatio = ONE_IN_Q14; /* No bandwidth limit for the noise filling, Q14 */ + } + +#if 1 // Fixed to float conversions, to be removed + Word16 length; + q_spec = 31; + move16(); + for ( ch = 0; ch < nChannels; ch++ ) + { + if ( sts[ch]->hTcxEnc->spectrum[0] ) + { + q_spec = 31 - sts[ch]->hTcxEnc->spectrum_e[0]; + } + length = sts[ch]->hTcxEnc->L_frameTCX / ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + if ( sts[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + for ( Word16 k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + if ( sts[ch]->hTcxEnc->spectrum[0] ) + { + fixedToFloat_arrL32( sts[ch]->hTcxEnc->spectrum_fx[k], sts[ch]->hTcxEnc->spectrum[k], q_spec, length ); + fixedToFloat_arrL32( inv_spectrum_fx[ch][k], inv_spectrum[ch][k], q_spec, length ); + } + if ( mdst_spectrum[ch][0] ) + { + fixedToFloat_arrL32( inv_mdst_spectrum_fx[ch][k], inv_mdst_spectrum[ch][k], q_spec, length ); + fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_spec, length ); + } + } + + fixedToFloat_arrL( powerSpecMsInv_fx[ch][0], powerSpecMsInv[ch][0], q_powSpec[ch], L_FRAME48k ); + fixedToFloat_arrL( powerSpec_fx[ch], powerSpec[ch], q_powSpec[ch], sts[ch]->hTcxEnc->L_frameTCX ); + } +#endif // 1 + + if ( sts[0]->igf ) + { + if ( hMCT->currBlockDataCnt > 0 ) + { + mctStereoIGF_enc( hMCT, sts, orig_spectrum, powerSpec, powerSpecMsInv, inv_spectrum, sp_aud_decision0 ); + } + else + { + for ( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + + /* update the pointer to the buffer of indices of the second channel */ + if ( ch > 0 ) + { + st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; + } + if ( + sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + nSubframes = ( st->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; + L_subframeTCX = st->hTcxEnc->L_frameTCX / nSubframes; + + if ( st->igf ) + { + for ( n = 0; n < nSubframes; n++ ) + { + ProcessIGF( st, st->hTcxEnc->spectrum[n], orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); + } + } + } + } + + /*write IGF data to bitstream*/ + for ( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + if ( + sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + enc_prm_igf_mdct( st, hBstr ); + } + } + + /* correct side bits per channel*/ + for ( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + + if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + + st->side_bits_frame_channel -= NBBITS_MCT_RATIO; /* Subtract estimated stereo bits */ + total_side_bits += st->side_bits_frame_channel; + } + + /*--------------------------------------------------------------* + * Bitrate distribution among channels and MCT bitstream writing + *---------------------------------------------------------------*/ +#if 1 // Float to fixed conversion, to be removed + FOR( Word16 pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) + { + IF( hMCT->hBlockData[pair]->hStereoMdct->hItd ) + { + hMCT->hBlockData[pair]->hStereoMdct->hItd->itd_fx[1] = float_to_fix( hMCT->hBlockData[pair]->hStereoMdct->hItd->itd[1], Q23 ); + } + } +#endif + write_mct_bitstream_fx( sts, hMCT, nChannels ); + + FindChannelRatio( sts, chBitRatios, nChannels ); + + nAvailBits = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - NBITS_BWIDTH - hMCT->nBitsMCT - lfe_bits ); + + + /* subtract IVAS format signaling bits */ + if ( ivas_format == MC_FORMAT ) + { + nAvailBits -= IVAS_FORMAT_SIGNALING_NBITS; + nAvailBits -= MC_LS_SETUP_BITS; + } + else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) + { + nAvailBits -= IVAS_FORMAT_SIGNALING_NBITS_EXTENDED; + nAvailBits -= SBA_ORDER_BITS + SBA_PLANAR_BITS; + if ( ivas_format == SBA_ISM_FORMAT && nChannels > 4 ) + { + nAvailBits -= IVAS_COMBINED_FORMAT_SIGNALLING_BITS; + } + } + + for ( cpe_id = 0, i = 0; cpe_id < nCPE; cpe_id++ ) + { + if ( hCPE[cpe_id]->hMetaData != NULL ) + { + nAvailBits -= hCPE[cpe_id]->hMetaData->nb_bits_tot; + } + } + + /*substract bits needed for the bitrate ratios */ + for ( ch = 0; ch < nChannels; ch++ ) + { + if ( + sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + nAvailBits -= NBBITS_MCT_RATIO; + } + nAvailBits -= total_side_bits + hMCT->nchan_out_woLFE; /* if MC 1 extra bit that was initially send to signal LFE_off */ + + + if ( hMCT->hbr_mct ) + { + assert( ivas_total_brate >= IVAS_256k ); + AdjustChannelRatios( chBitRatios, nChannels, ivas_total_brate, nAvailBits, sba_order ); + } + + for ( ch = 0; ch < nChannels; ch++ ) + { + if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + + push_next_indice( hBstr, chBitRatios[ch], NBBITS_MCT_RATIO ); + } + + /*distribute bits amongst channels*/ + splitAvailableBitsMCT( (void **) sts, nAvailBits, chBitRatios, ENC, nChannels ); + + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE[cpe_id]->hCoreCoder[ch]; + if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + st->total_brate = ( st->bits_frame_channel + st->side_bits_frame_channel ) * FRAMES_PER_SEC; + } + } + + + pop_wmops(); + + return; +} +#endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index e0e9d5cbc4d63290e13ad47e798f5f536c0571ab..0fac502c14803c5a9660fef328973a53b77c5eef 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -40,6 +40,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif @@ -79,6 +80,14 @@ static void set_mct_enc_params( { set_f( hMCT->lastxCorrMatrix[n], 0, MCT_MAX_CHANNELS ); } +#ifdef IVAS_FLOAT_FIXED + FOR( n = 0; n < MCT_MAX_CHANNELS; n++ ) + { + set32_fx( hMCT->lastxCorrMatrix_fx[n], 0, MCT_MAX_CHANNELS ); + } + hMCT->lastxCorrMatrix_e = 0; + move16(); +#endif } hMCT->hbr_mct = 0; @@ -157,7 +166,7 @@ static void map_input_to_cpe_channels( * * Multi-Channel Coding Tool (MCT) encoding routine *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_mct_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ @@ -169,6 +178,9 @@ ivas_error ivas_mct_enc( MCT_ENC_HANDLE hMCT; CPE_ENC_HANDLE hCPE; float mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; +#ifdef IVAS_FLOAT_FIXED + Word32 orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; +#endif // IVAS_FLOAT_FIXED float orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; int16_t switch_bw; IVAS_FORMAT ivas_format; @@ -196,6 +208,9 @@ ivas_error ivas_mct_enc( { hCPE = st_ivas->hCPE[cpe_id]; hMCT->p_mdst_spectrum_long[cpe_id][n] = mdst_spectrum_long[cpe_id][n]; +#ifdef IVAS_FLOAT_FIXED + hMCT->p_orig_spectrum_long_fx[cpe_id][n] = orig_spectrum_long_fx[cpe_id][n]; +#endif // IVAS_FLOAT_FIXED hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; hCPE->hCoreCoder[n]->input_bwidth = hCPE->hCoreCoder[n]->last_input_bwidth; /* updated in BWD */ hCPE->hCoreCoder[n]->bwidth = hCPE->hCoreCoder[n]->last_bwidth; /* updated in BWD */ @@ -224,11 +239,7 @@ ivas_error ivas_mct_enc( for ( n = 0; n < (int16_t) ( hMCT->nchan_out_woLFE * 0.5 ); n++ ) { -#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 0 ); -#else - initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 0 ); -#endif } } @@ -275,7 +286,209 @@ ivas_error ivas_mct_enc( pop_wmops(); return error; } +#else +ivas_error ivas_mct_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +) +{ + Word16 n, cpe_id; + MCT_ENC_HANDLE hMCT; + CPE_ENC_HANDLE hCPE; + float mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; + float orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; + Word32 mdst_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; + Word32 orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; + Word16 switch_bw; + IVAS_FORMAT ivas_format; + Word16 max_bwidth; + Word32 ivas_total_brate; + ivas_error error; + float *pdata[MAX_INPUT_CHANNELS]; + + error = IVAS_ERR_OK; + move32(); + + push_wmops( "ivas_mct_enc" ); + + /* Initialization */ + hMCT = st_ivas->hMCT; + hMCT->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; /* pointer to write MCT side bits */ + + ivas_format = st_ivas->hEncoderConfig->ivas_format; + max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + move16(); + move32(); + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; +#if 1 // float initialization to be removed + hMCT->p_mdst_spectrum_long[cpe_id][n] = mdst_spectrum_long[cpe_id][n]; + hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; +#endif + + hMCT->p_mdst_spectrum_long_fx[cpe_id][n] = mdst_spectrum_long_fx[cpe_id][n]; + hMCT->p_orig_spectrum_long_fx[cpe_id][n] = orig_spectrum_long_fx[cpe_id][n]; + + hCPE->hCoreCoder[n]->input_bwidth = hCPE->hCoreCoder[n]->last_input_bwidth; /* updated in BWD */ + hCPE->hCoreCoder[n]->bwidth = hCPE->hCoreCoder[n]->last_bwidth; /* updated in BWD */ + move16(); + move16(); + /* reset channel mode from previous state*/ + IF( ( hCPE->cpe_id * CPE_CHANNELS + n ) >= hMCT->nchan_out_woLFE ) + { + hCPE->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move32(); + } + ELSE + { + hCPE->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); + } + } + } + + /* reconfiguration in case of bitrate switching */ + IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + Word32 cp_bitrate; + // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, hMCT->nchan_out_woLFE ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) + + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, st_ivas->nchan_transport ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) + } + + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + FOR( n = 0; n < shr( hMCT->nchan_out_woLFE, 1 ); n++ ) + { + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); + } + } + ELSE + { + FOR( n = 0; n < shr( hMCT->nchan_out_woLFE, 1 ); n++ ) + { + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, NULL, 0 ); + } + } + } + + /* set coded audio band-width */ + switch_bw = set_bw_mct_fx( st_ivas->hCPE, st_ivas->nCPE ); + + /*for MC and MCT remove pointer to LFE input that has been processed separately */ + map_input_to_cpe_channels( st_ivas, pdata, data ); + + /* pre-processing */ + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + IF( ( error = ivas_cpe_enc( st_ivas, cpe_id, pdata[cpe_id * CPE_CHANNELS], pdata[cpe_id * CPE_CHANNELS + 1], input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#if 1 // Float to Fixed, to be removed + Word16 q_spec = Q31; + Word16 length, ch, nCPE; + nCPE = ( hMCT->nchan_out_woLFE % 2 ) == 0 ? ( hMCT->nchan_out_woLFE / 2 ) : ( hMCT->nchan_out_woLFE / 2 ) + 1; + + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) + { + q_spec = s_min( q_spec, Q_factor_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[k], length ) - 1 ); + } + if ( hMCT->p_mdst_spectrum_long[cpe_id][ch] ) + { + q_spec = s_min( q_spec, Q_factor_arrL( &hMCT->p_mdst_spectrum_long[cpe_id][ch][k * N_TCX10_MAX], length ) - 1 ); + } + } + } + } + + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + // if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + //{ + // continue; + // } + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) + { + floatToFixed_arrL32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[k], st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[k], q_spec, length ); + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[k] = sub( Q31, q_spec ); + } + if ( hMCT->p_mdst_spectrum_long[cpe_id][ch] ) + { + floatToFixed_arrL32( &hMCT->p_mdst_spectrum_long[cpe_id][ch][k * N_TCX10_MAX], &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], q_spec, length ); + } + } + } + } +#endif // 1 + + /* joint MCT encoding */ + ivas_mct_core_enc( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE, ivas_total_brate, switch_bw, ( ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) ? (int16_t) st_ivas->hLFE->lfe_bits : 0, st_ivas->hEncoderConfig->sba_order ); + /* Spectrum quantization and coding */ + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + + if ( cpe_id > 0 ) + { + hCPE->hCoreCoder[0]->hBstr->ind_list = st_ivas->hCPE[cpe_id - 1]->hCoreCoder[1]->hBstr->ind_list + st_ivas->hCPE[cpe_id - 1]->hCoreCoder[1]->hBstr->nb_ind_tot; + } + + ivas_mdct_quant_coder( hCPE, hMCT->tnsBits[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], 1 ); + + /* update input samples buffer (as done in ivas_cpe_enc() for other than MCT coding) */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( hCPE->hCoreCoder[n]->input, hCPE->hCoreCoder[n]->old_input_signal, input_frame ); + + /* common encoder updates */ + updt_enc_common( hCPE->hCoreCoder[n] ); + } + } + + pop_wmops(); + return error; +} +#endif /*------------------------------------------------------------------------- * create_mct_enc() diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index 554b16008683620b4664d46484a24b3b05739bf1..066f7a55770a385abc22d20b05252302d81a7cd7 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -35,7 +35,9 @@ #include #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "prot.h" +#include "prot_fx.h" #include "wmc_auto.h" #include @@ -44,8 +46,10 @@ * Local constants *---------------------------------------------------------------*/ -#define SPAR_CORR_THRES 0.9f -#define DEFAULT_CORR_THRES 0.3f +#define SPAR_CORR_THRES 0.9f +#define DEFAULT_CORR_THRES 0.3f +#define SPAR_CORR_THRES_Q31 1932735283 +#define DEFAULT_CORR_THRES_Q31 644245094 /*------------------------------------------------------------------------- * getChannelEnergies() @@ -83,6 +87,64 @@ void getChannelEnergies( return; } +#ifdef IVAS_FLOAT_FIXED +void getChannelEnergies_fx( + Encoder_State **sts, /* i/o: Encoder state structure */ + Word32 nrg[MCT_MAX_CHANNELS], /* o : buffer with energies for each channel */ + Word16 nrg_e[MCT_MAX_CHANNELS], /* o : exponents of energies for each channel */ + const Word16 nchan /* i : number of channels */ +) +{ + Word16 ch, n, gb, sum2_e; + Word32 sum2; + Word16 nSubframes, L_subframe; + Encoder_State *st; + + /* Calculate energies per channel */ + FOR( ch = 0; ch < nchan; ch++ ) + { + st = sts[ch]; + IF( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + L_subframe = st->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframe = shr( st->hTcxEnc->L_frameTCX, 1 ); + } + + gb = find_guarded_bits_fx( (Word32) L_subframe ); + + sum2_e = st->hTcxEnc->spectrum_e[0]; + move16(); + nrg[ch] = 0; + move32(); + FOR( n = 0; n < nSubframes; n++ ) + { + sum2 = sum2_32_exp_fx( st->hTcxEnc->spectrum_fx[n], L_subframe, &sum2_e, gb ); + + nrg[ch] = BASOP_Util_Add_Mant32Exp( nrg[ch], nrg_e[ch], sum2, sum2_e, &nrg_e[ch] ); + move32(); + + sum2_e = st->hTcxEnc->spectrum_e[0]; + move16(); + } + + nrg[ch] = Sqrt32( nrg[ch], &nrg_e[ch] ); + move32(); + } + } + + return; +} +#endif /*------------------------------------------------------------------------- @@ -90,7 +152,7 @@ void getChannelEnergies( * * find channel pair with highest cross-correlation *-------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void getNextBestCorrelation( float xCorrMatrix[][MCT_MAX_CHANNELS], /* i : cross-correlation matrix */ int16_t *_ch1, /* o : first channel of selected channel-pair */ @@ -143,6 +205,69 @@ static void getNextBestCorrelation( return; } +#else +static void getNextBestCorrelation_fx( + Word32 xCorrMatrix[][MCT_MAX_CHANNELS], /* i : cross-correlation matrix, Qx */ + Word16 *_ch1, /* o : first channel of selected channel-pair */ + Word16 *_ch2, /* o : second channel of selected channel-pair, Qx */ + Word32 *max_corr, /* o : normalized cross correlation value of selected channel pair */ + const Word16 sortInd, + const Word16 nChannels ) +{ + Word32 tmp_corrVals[( MCT_MAX_CHANNELS * ( MCT_MAX_CHANNELS - 1 ) ) / 2]; + Word16 tmp_org[( MCT_MAX_CHANNELS * ( MCT_MAX_CHANNELS - 1 ) ) / 2]; + Word16 i, tmp_idx; + Word16 ch1, ch2; + + set32_fx( tmp_corrVals, 0, ( MCT_MAX_CHANNELS * ( MCT_MAX_CHANNELS - 1 ) ) / 2 ); + + /* first sort correlation matrix */ + i = 0; + move16(); + FOR( ch1 = 0; ch1 < nChannels; ch1++ ) + { + FOR( ch2 = ch1 + 1; ch2 < nChannels; ch2++ ) + { + IF( L_abs( xCorrMatrix[ch1][ch2] ) > 0 ) + { + assert( i < ( MCT_MAX_CHANNELS * ( MCT_MAX_CHANNELS - 1 ) ) / 2 ); + tmp_corrVals[i] = L_abs( xCorrMatrix[ch1][ch2] ); + move32(); + i = add( i, 1 ); + } + } + } + + tmp_idx = sub( shr( imult1616( nChannels, sub( nChannels, 1 ) ), 1 ), 1 ); + + /* sort values */ + v_sort_ind_fixed( tmp_corrVals, tmp_org, add( tmp_idx, 1 ) ); + + /* get max, or 2nd max and so on depending on sortInd value */ + *max_corr = tmp_corrVals[sub( tmp_idx, sortInd )]; + move32(); + + /*find channel pair for this max_corr*/ + FOR( ch1 = 0; ch1 < nChannels; ch1++ ) + { + FOR( ch2 = ch1 + 1; ch2 < nChannels; ch2++ ) + { + IF( EQ_32( L_abs( xCorrMatrix[ch1][ch2] ), *max_corr ) ) + { + *_ch1 = ch1; + *_ch2 = ch2; + *max_corr = xCorrMatrix[ch1][ch2]; /* assign to max_corr its actual value */ + move16(); + move16(); + move32(); + BREAK; + } + } + } + + return; +} +#endif /*-----------------------------------------------------------------------* @@ -151,7 +276,7 @@ static void getNextBestCorrelation( * calculates the cross correlation matrix for all active * channels *-----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void getCorrelationMatrix( Encoder_State **sts, /* i : core coder handle */ MCT_ENC_HANDLE hMCT, /* i : MCT handle */ @@ -204,6 +329,124 @@ static void getCorrelationMatrix( return; } +#else +static void getCorrelationMatrix_fx( + Encoder_State **sts, /* i : core coder handle */ + MCT_ENC_HANDLE hMCT, /* i : MCT handle */ + Word32 xCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS], /* o : cross-correlation matrix, exponent: xCorrMatrix_e */ + Word16 *xCorrMatrix_e /* o : exponent of cross-correlation matrix */ +) +{ + Word16 ch1, ch2, n, nchan, res_q, s, max_e; + Word16 xCorrMatrix_exp[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; + Word32 L_tmp; + Word64 W_tmp; + + nchan = hMCT->nchan_out_woLFE; + move16(); + + /* correlation */ + FOR( ch1 = 0; ch1 < nchan; ch1++ ) + { + FOR( ch2 = ch1; ch2 < nchan; ch2++ ) + { + xCorrMatrix[ch1][ch2] = 0; + move32(); + xCorrMatrix_exp[ch1][ch2] = 0; + move16(); + + test(); + test(); + IF( EQ_16( sts[ch1]->core, sts[ch2]->core ) && NE_32( sts[ch1]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) && + NE_32( sts[ch2]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + Word16 nSubframes; + Word16 L_subframe; + IF( EQ_16( sts[ch1]->core, TCX_20 ) ) + { + nSubframes = 1; + move16(); + L_subframe = sts[ch1]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframe = shr( sts[ch1]->hTcxEnc->L_frameTCX, 1 ); + } + + FOR( n = 0; n < nSubframes; n++ ) + { + res_q = sub( 31, sts[0]->hTcxEnc->spectrum_e[0] ); + L_tmp = dotp_fixed_32( sts[ch1]->hTcxEnc->spectrum_fx[n], sts[ch2]->hTcxEnc->spectrum_fx[n], L_subframe, 1, &res_q ); + xCorrMatrix[ch1][ch2] = BASOP_Util_Add_Mant32Exp( xCorrMatrix[ch1][ch2], xCorrMatrix_exp[ch1][ch2], L_tmp, sub( 31, res_q ), &xCorrMatrix_exp[ch1][ch2] ); + move32(); + } + } + } + } + + /* normalize */ + FOR( ch1 = 0; ch1 < nchan; ch1++ ) + { + FOR( ch2 = ch1 + 1; ch2 < nchan; ch2++ ) + { + // tmp = sqrtf( xCorrMatrix[ch1][ch1] * xCorrMatrix[ch2][ch2] ); + W_tmp = W_mult0_32_32( xCorrMatrix[ch1][ch1], xCorrMatrix[ch2][ch2] ); + s = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, s ) ); + + s = sub( add( s, 30 ), add( xCorrMatrix_exp[ch1][ch1], xCorrMatrix_exp[ch2][ch2] ) ); // s = s + ( 31 - xCorrMatrix_exp[ch1][ch1] ) + ( 31 - xCorrMatrix_exp[ch2][ch2] ) - 32; + s = sub( 31, s ); + L_tmp = Sqrt32( L_tmp, &s ); + + IF( L_tmp > 0 ) + { + // xCorrMatrix[ch1][ch2] /= tmp; + xCorrMatrix[ch1][ch2] = L_deposit_h( BASOP_Util_Divide3232_Scale( xCorrMatrix[ch1][ch2], L_tmp, &res_q ) ); + xCorrMatrix_exp[ch1][ch2] = add( res_q, sub( xCorrMatrix_exp[ch1][ch2], s ) ); + move32(); + move16(); + } + ELSE + { + xCorrMatrix[ch1][ch2] = 0; + xCorrMatrix_exp[ch1][ch2] = 0; + move32(); + move16(); + } + } + } + + /* Aligning the variable exponents for each element to a common exponent */ + s = 31; + *xCorrMatrix_e = 0; + move16(); + move16(); + + FOR( ch1 = 0; ch1 < nchan - 1; ch1++ ) + { + s = s_min( s, getScaleFactor32( &xCorrMatrix[ch1][ch1 + 1], sub( nchan, add( ch1, 1 ) ) ) ); + maximum_s( &xCorrMatrix_exp[ch1][ch1 + 1], sub( nchan, add( ch1, 1 ) ), &max_e ); + *xCorrMatrix_e = s_max( *xCorrMatrix_e, max_e ); + move16(); + } + + FOR( ch1 = 0; ch1 < nchan; ch1++ ) + { + FOR( ch2 = ch1 + 1; ch2 < nchan; ch2++ ) + { + xCorrMatrix[ch1][ch2] = L_shl_sat( xCorrMatrix[ch1][ch2], add( s, sub( xCorrMatrix_exp[ch1][ch2], *xCorrMatrix_e ) ) ); + move32(); + } + } + *xCorrMatrix_e = sub( *xCorrMatrix_e, s ); + move16(); + + return; +} +#endif /*-----------------------------------------------------------------* @@ -211,7 +454,7 @@ static void getCorrelationMatrix( * * searches for the best correlated channel pair *------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void getBestCorrelation( MCT_ENC_HANDLE hMCT, /* i : MCT handle */ int16_t *_ch1, /* o : first channel of selected channel-pair */ @@ -241,13 +484,50 @@ static void getBestCorrelation( return; } +#else +static void getBestCorrelation_fx( + MCT_ENC_HANDLE hMCT, /* i : MCT handle */ + Word16 *_ch1, /* o : first channel of selected channel-pair, Q0 */ + Word16 *_ch2, /* o : second channel of selected channel-pair, Q0 */ + Word32 *max_corr, /* o : normalized cross correlation value of selected channel pair, Qx */ + Word32 xCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS] ) /* i : cross-correlation matrix, Qx */ +{ + Word16 ch1, ch2; + + *_ch1 = -1; + *_ch2 = -1; + *max_corr = 0; + move16(); + move16(); + move32(); + + FOR( ch1 = 0; ch1 < ( hMCT->nchan_out_woLFE ); ch1++ ) + { + FOR( ch2 = ch1 + 1; ch2 < ( hMCT->nchan_out_woLFE ); ch2++ ) + { + IF( LT_32( L_abs( *max_corr ), L_abs( xCorrMatrix[ch1][ch2] ) ) ) + { + *max_corr = xCorrMatrix[ch1][ch2]; + move32(); + + *_ch1 = ch1; + *_ch2 = ch2; + move16(); + move16(); + } + } + } + + return; +} +#endif /*----------------------------------------------------------------------* * getBlockValues() * stereo processing for the channels of current block *----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void getBlockValues( Encoder_State **sts, /* i/o: core coder handle */ const int16_t ch1, /* i : first channel of channel-pair */ @@ -289,6 +569,56 @@ static void getBlockValues( return; } +#else +static void getBlockValues_fx( + Encoder_State **sts, /* i/o: core coder handle */ + const Word16 ch1, /* i : first channel of channel-pair */ + const Word16 ch2, /* i : second channel of channel-pair */ + MCT_BLOCK_DATA *hBlock, /* i : stereo block handle */ + Word32 *mdst_spectrum[MCT_MAX_CHANNELS][2], /* i/o: MDST spectrum, Q = q_spec */ + Word32 *inv_spectrum[MCT_MAX_CHANNELS][2], /* i/o: inverse spectrum, Q = q_spec */ + Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][2], /* i/o: invers MDST spectrum, Q = q_spec */ + Word16 q_spec /* i : common Q factor of the above spectrum buffers */ +) +{ + Word16 n; + Word32 *p_mdst_spectrum[2][2]; + Word32 *p_inv_spectrum[2][2]; + Word32 *p_inv_mdst_spectrum[2][2]; + Encoder_State *p_st[2]; + + /* init return values: */ + hBlock->isActive = 1; + move16(); + + /* map vectors to current block channels */ + FOR( n = 0; n < 2; n++ ) + { + p_mdst_spectrum[0][n] = mdst_spectrum[ch1][n]; + p_mdst_spectrum[1][n] = mdst_spectrum[ch2][n]; + p_inv_spectrum[0][n] = inv_spectrum[ch1][n]; + p_inv_spectrum[1][n] = inv_spectrum[ch2][n]; + p_inv_mdst_spectrum[0][n] = inv_mdst_spectrum[ch1][n]; + p_inv_mdst_spectrum[1][n] = inv_mdst_spectrum[ch2][n]; + } + p_st[0] = sts[ch1]; + p_st[1] = sts[ch2]; + + stereo_coder_tcx_fx( hBlock->hStereoMdct, p_st, hBlock->mask, p_mdst_spectrum, p_inv_spectrum, p_inv_mdst_spectrum, 1, q_spec ); + + test(); + test(); + test(); + test(); + if ( ( EQ_16( sts[ch1]->core, TCX_20_CORE ) && hBlock->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) || ( EQ_16( sts[ch1]->core, TCX_10_CORE ) && hBlock->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO && hBlock->hStereoMdct->mdct_stereo_mode[1] == SMDCT_DUAL_MONO ) ) + { + hBlock->isActive = 0; + move16(); + } + + return; +} +#endif /*-------------------------------------------------------------------* @@ -297,7 +627,7 @@ static void getBlockValues( * updates the cross correlation matrix with modified spectra after * stereo block processing *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void updateCorrelationMatrix( Encoder_State **sts, MCT_ENC_HANDLE hMCT, @@ -330,13 +660,64 @@ static void updateCorrelationMatrix( return; } +#else +static void updateCorrelationMatrix_fx( + Encoder_State **sts, + MCT_ENC_HANDLE hMCT, + const Word16 _ch1, + const Word16 _ch2, + Word32 xCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS] // Qx +) +{ + Word16 ch1, ch2, n; + + /* correlation: */ + FOR( ch1 = 0; ch1 < ( hMCT->nchan_out_woLFE ); ch1++ ) + { + FOR( ch2 = ch1; ch2 < ( hMCT->nchan_out_woLFE ); ch2++ ) + { + test(); + test(); + IF( EQ_16( sts[ch1]->core, sts[ch2]->core ) && NE_32( sts[ch1]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) && + NE_32( sts[ch2]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + Word16 nSubframes; + IF( EQ_16( sts[ch1]->core, TCX_20 ) ) + { + nSubframes = 1; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + } + + test(); + test(); + test(); + IF( EQ_16( ch1, _ch1 ) || EQ_16( ch2, _ch2 ) || EQ_16( ch1, _ch2 ) || EQ_16( ch2, _ch1 ) ) + { + FOR( n = 0; n < nSubframes; n++ ) + { + xCorrMatrix[ch1][ch2] = 0; /*disable combinations with channels already processed */ + move32(); + } + } + } + } + } + + return; +} +#endif /*----------------------------------------------------------* * channelPairToIndex() * get the index of each channel pair *----------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static int16_t channelPairToIndex( const int16_t chIdx1, const int16_t chIdx2, @@ -364,13 +745,43 @@ static int16_t channelPairToIndex( return -1; } +#else +static Word16 channelPairToIndex_fx( + const Word16 chIdx1, + const Word16 chIdx2, + const Word16 nChannels ) +{ + Word16 ch1, ch2; + Word16 pairIdx; + pairIdx = 0; + move16(); + + FOR( ch2 = 1; ch2 < nChannels; ch2++ ) + { + FOR( ch1 = 0; ch1 < ch2; ch1++ ) + { + test(); + IF( EQ_16( ch1, chIdx1 ) && EQ_16( ch2, chIdx2 ) ) + { + return pairIdx; + } + ELSE + { + pairIdx = add( pairIdx, 1 ); + } + } + } + + return -1; +} +#endif /*--------------------------------------------------------------------* * getGlobalILD() * get broadband ILD to mean energy and normalize channels with ratio *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void getGlobalILD( Encoder_State **sts, MCT_ENC_HANDLE hMCT, @@ -432,6 +843,123 @@ static void getGlobalILD( return; } +#else +static void getGlobalILD_fx( + Encoder_State **sts, + MCT_ENC_HANDLE hMCT, + Word32 *mdst_spectrum[MCT_MAX_CHANNELS][2], // Exponent is same as spectrum_fx i.e. spectrum_e + const Word16 nchan ) +{ + Word16 k, ch, nSubframes, L_subframe; + Word32 nrg[MCT_MAX_CHANNELS]; + Word16 nrg_e[MCT_MAX_CHANNELS]; + Word16 ratio_fx, qratio; + Word32 meanE = 0; + Word32 L_tmp; + Word16 cnt = 0, meanE_e = 0, L_tmp_e; + move32(); + move16(); + move16(); + + /*Initializations*/ + set16_fx( hMCT->lowE_ch, 0, nchan ); + + getChannelEnergies_fx( sts, nrg, nrg_e, nchan ); + + /*calculate total energy without LFE*/ + FOR( ch = 0; ch < nchan; ch++ ) + { + IF( NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + meanE = BASOP_Util_Add_Mant32Exp( meanE, meanE_e, nrg[ch], nrg_e[ch], &meanE_e ); + cnt = add( cnt, 1 ); + } + } + + /*calculate mean energy*/ + assert( cnt >= 2 ); + L_tmp = BASOP_Util_Divide3216_Scale( meanE, cnt, &L_tmp_e ); + L_tmp_e = add( L_tmp_e, sub( meanE_e, 15 ) ); + + // meanE = max( meanE / cnt, EPSILON ); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_tmp, L_tmp_e, EPSILON_FX_M, EPSILON_FX_E ), 1 ) ) + { + meanE = L_deposit_h( (Word16) L_tmp ); + meanE_e = L_tmp_e; + move32(); + move16(); + } + ELSE + { + meanE = EPSILON_FX_M; + meanE_e = EPSILON_FX_E; + move32(); + move16(); + } + + FOR( ch = 0; ch < nchan; ch++ ) + { + IF( NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + L_subframe = sts[ch]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframe = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); + } + + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrg[ch], nrg_e[ch], meanE, meanE_e ), 1 ) ) /*change it to meanE if final solution*/ + { + // ratio_fx = meanE / nrg[ch]; + ratio_fx = BASOP_Util_Divide3232_Scale( meanE, nrg[ch], &L_tmp_e ); + L_tmp_e = add( L_tmp_e, sub( meanE_e, nrg_e[ch] ) ); + ratio_fx = shl_sat( ratio_fx, L_tmp_e ); + + hMCT->mc_global_ild[ch] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, mult_r( SMDCT_ILD_RANGE, ratio_fx ) ) ); + move16(); + + qratio = div_l( L_shl( hMCT->mc_global_ild[ch], 11 ), SMDCT_ILD_RANGE / 2 ); // Q11 + } + ELSE + { + // ratio_fx = nrg[ch] / meanE; + ratio_fx = BASOP_Util_Divide3232_Scale( nrg[ch], meanE, &L_tmp_e ); + L_tmp_e = add( L_tmp_e, sub( nrg_e[ch], meanE_e ) ); + ratio_fx = shl_sat( ratio_fx, L_tmp_e ); + + hMCT->lowE_ch[ch] = 1; + move16(); + + hMCT->mc_global_ild[ch] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, mult_r( SMDCT_ILD_RANGE, ratio_fx ) ) ); + move16(); + + qratio = shl_sat( div_l( ( (Word32) SMDCT_ILD_RANGE << 11 ), hMCT->mc_global_ild[ch] ), 1 ); // Q11 + } + + FOR( k = 0; k < nSubframes; k++ ) + { + sts[ch]->hTcxEnc->spectrum_e[k] = add( sts[ch]->hTcxEnc->spectrum_e[k], 4 ); // Updating exponent of spectrum as q_ratio is in Q11 + } + + FOR( k = 0; k < nSubframes; k++ ) + { + v_multc_fixed( sts[ch]->hTcxEnc->spectrum_fx[k], L_deposit_h( qratio ), sts[ch]->hTcxEnc->spectrum_fx[k], L_subframe ); + v_multc_fixed( mdst_spectrum[ch][k], L_deposit_h( qratio ), mdst_spectrum[ch][k], L_subframe ); + } + } + } + + + return; +} +#endif /*--------------------------------------------------------------------* @@ -439,7 +967,7 @@ static void getGlobalILD( * * apply MCT algorithm to input channels *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void apply_MCT_enc( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ Encoder_State **sts, /* i/o: encoder state structure */ @@ -656,18 +1184,295 @@ void apply_MCT_enc( return; } +#else +void apply_MCT_enc_fx( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + Word32 *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ + Word32 *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ + Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + const Word16 nchan /* i : number of channels */ +) +{ + Word16 ch, k, ch1, ch2, nSubframes, L_subframeTCX; + Word32 max_corr; + Word16 forceKeepTree, pair, qratio; + Word32 sumCorrDiff, thr; + Word32 xCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; + Word16 currBlockDataCnt; + Word16 cpEle[MCT_MAX_CHANNELS]; + Word16 inactiveBlockDetected; + Word16 tmp_ch1, tmp_ch2, tmp; + Word32 tmp_max_corr, L_tmp; + Word16 count_active_ch = 0; + Word16 xCorrMatrix_e = 0, sumCorrDiff_e = 0, L_tmp_e; + move16(); + move16(); + move16(); + push_wmops( "mct_core_enc_mct" ); -/*--------------------------------------------------------------------* - * write_mct_bitstream() - * - * write mct metadata to bitstream - *--------------------------------------------------------------------*/ + forceKeepTree = 1; + inactiveBlockDetected = 0; + move16(); + move16(); + set16_fx( cpEle, 0, MCT_MAX_CHANNELS ); -void write_mct_bitstream( - Encoder_State **sts, /* i/o: encoder state structure */ - MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const int16_t nchan /* i : number of channels */ + /*Determine active channels*/ + FOR( ch = 0; ch < nchan; ch++ ) + { + IF( NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + count_active_ch = add( count_active_ch, 1 ); + } + ELSE + { + hMCT->mc_global_ild[ch] = 0; + move16(); + } + } + + /*there should be at least one cp*/ + IF( GE_16( count_active_ch, CPE_CHANNELS ) ) + { + /*Normalize energies with global ILD*/ + getGlobalILD_fx( sts, hMCT, mdst_spectrum, nchan ); + getCorrelationMatrix_fx( sts, hMCT, xCorrMatrix, &xCorrMatrix_e ); + + /*check if previous tree should be kept*/ + sumCorrDiff = 0; + move32(); + // thr = 0.15f * (float) ( count_active_ch ) * ( count_active_ch - 1 ) / 2.0f; + thr = Mpy_32_16_1( 161061274, imult1616( count_active_ch, sub( count_active_ch, 1 ) ) ); /* Q16 */ /* 161061274 = 0.15 / 2 in Q31 */ + + FOR( ch2 = 1; ch2 < nchan; ch2++ ) + { + FOR( ch1 = 0; ch1 < ch2; ch1++ ) + { + test(); + IF( NE_32( sts[ch1]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) && + NE_32( sts[ch2]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + L_tmp = L_abs( BASOP_Util_Add_Mant32Exp( hMCT->lastxCorrMatrix_fx[ch1][ch2], hMCT->lastxCorrMatrix_e, L_negate( xCorrMatrix[ch1][ch2] ), xCorrMatrix_e, &L_tmp_e ) ); + sumCorrDiff = BASOP_Util_Add_Mant32Exp( sumCorrDiff, sumCorrDiff_e, L_tmp, L_tmp_e, &sumCorrDiff_e ); + } + } + } + + if ( EQ_16( BASOP_Util_Cmp_Mant32Exp( sumCorrDiff, sumCorrDiff_e, thr, 15 ), 1 ) ) + { + forceKeepTree = 0; + move16(); + } + + /* check if keepTree is applied on unallowed blocks (e.g. channel pairs with different cores) */ + IF( forceKeepTree ) + { + IF( !hMCT->currBlockDataCnt ) + { + forceKeepTree = 0; + move16(); + } + ELSE + { + FOR( pair = 0; pair < hMCT->currBlockDataCnt; pair++ ) + { + if ( xCorrMatrix[hMCT->hBlockData[pair]->ch1][hMCT->hBlockData[pair]->ch2] == 0 ) + { + forceKeepTree = 0; + move16(); + } + } + } + } + + /*save initial correlation matrix for next frame*/ + FOR( ch1 = 0; ch1 < nchan; ch1++ ) + { + FOR( ch2 = ch1; ch2 < nchan; ch2++ ) + { + hMCT->lastxCorrMatrix_fx[ch1][ch2] = xCorrMatrix[ch1][ch2]; + move32(); + } + } + hMCT->lastxCorrMatrix_e = xCorrMatrix_e; + move16(); + move16(); + currBlockDataCnt = 0; + WHILE( LT_16( currBlockDataCnt, hMCT->nchan_out_woLFE ) ) + { + /* find best fitting channel pair: */ + ch1 = -1; + ch2 = -1; + max_corr = 0; + move16(); + move16(); + move32(); + + IF( !forceKeepTree ) + { + getNextBestCorrelation_fx( xCorrMatrix, &ch1, &ch2, &max_corr, inactiveBlockDetected, nchan ); + } + ELSE + { + getBestCorrelation_fx( hMCT, &tmp_ch1, &tmp_ch2, &tmp_max_corr, xCorrMatrix ); + + IF( EQ_16( currBlockDataCnt, hMCT->currBlockDataCnt ) ) + { + BREAK; + } + ELSE + { + ch1 = hMCT->hBlockData[currBlockDataCnt]->ch1; + ch2 = hMCT->hBlockData[currBlockDataCnt]->ch2; + move16(); + move16(); + + /*don't allow forcing of channel-pair if their correlation is under the threshold*/ + max_corr = xCorrMatrix[ch1][ch2]; + move32(); + + tmp = BASOP_Util_Cmp_Mant32Exp( L_abs( max_corr ), xCorrMatrix_e, DEFAULT_CORR_THRES_Q31 /* 0.3 in Q31 */, 0 ); + test(); + IF( EQ_16( tmp, -1 ) || tmp == 0 ) + { + ch1 = tmp_ch1; + ch2 = tmp_ch2; + max_corr = tmp_max_corr; + forceKeepTree = 0; + move16(); + move16(); + move32(); + move16(); + } + } + } + + test(); + test(); + test(); + IF( ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( max_corr ), xCorrMatrix_e, DEFAULT_CORR_THRES_Q31, 0 ), 1 ) && !hMCT->hbr_mct ) || ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( max_corr ), xCorrMatrix_e, SPAR_CORR_THRES_Q31, 0 ), 1 ) && hMCT->hbr_mct ) ) + { + IF( !forceKeepTree ) + { + /*save channel pair*/ + hMCT->hBlockData[currBlockDataCnt]->ch1 = ch1; + hMCT->hBlockData[currBlockDataCnt]->ch2 = ch2; + move16(); + move16(); + } + + /* calculate all related values: */ + assert( sts[ch1]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[ch2]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ); + + getBlockValues_fx( sts, ch1, ch2, hMCT->hBlockData[currBlockDataCnt], mdst_spectrum, inv_spectrum, inv_mdst_spectrum, sub( 31, sts[0]->hTcxEnc->spectrum_e[0] ) ); + + IF( hMCT->hBlockData[currBlockDataCnt]->isActive == 0 ) + { + inactiveBlockDetected = add( inactiveBlockDetected, 1 ); + IF( GT_16( inactiveBlockDetected, shr( hMCT->nchan_out_woLFE, 1 ) ) ) + { + BREAK; + } + forceKeepTree = 0; + move16(); + + CONTINUE; /* skip inactive blocks where stereo mode is dual-mono */ + } + + updateCorrelationMatrix_fx( sts, hMCT, ch1, ch2, xCorrMatrix ); + cpEle[ch1] = 1; + cpEle[ch2] = 1; + move16(); + move16(); + + currBlockDataCnt = add( currBlockDataCnt, 1 ); + } + ELSE + { + BREAK; + } + } + + /*save number of blocks for next frame*/ + hMCT->currBlockDataCnt = currBlockDataCnt; + move16(); + + FOR( ch = 0; ch < nchan; ch++ ) + { + IF( NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + test(); + IF( ( !cpEle[ch] ) || hMCT->currBlockDataCnt == 0 ) + { + IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) + { + nSubframes = 1; + move16(); + L_subframeTCX = sts[ch]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); + } + + IF( hMCT->lowE_ch[ch] ) + { + // qratio = (float) hMCT->mc_global_ild[ch] / SMDCT_ILD_RANGE; + qratio = div_l( L_shl( hMCT->mc_global_ild[ch], 11 ), SMDCT_ILD_RANGE / 2 ); // Q11 + } + ELSE + { + // qratio = (float) SMDCT_ILD_RANGE / hMCT->mc_global_ild[ch]; + qratio = shl_sat( div_l( ( (Word32) SMDCT_ILD_RANGE << 11 ), hMCT->mc_global_ild[ch] ), 1 ); // Q11 + } + + FOR( k = 0; k < nSubframes; k++ ) + { + v_multc_fixed( sts[ch]->hTcxEnc->spectrum_fx[k], L_deposit_h( qratio ), sts[ch]->hTcxEnc->spectrum_fx[k], L_subframeTCX ); + v_multc_fixed( mdst_spectrum[ch][k], L_deposit_h( qratio ), mdst_spectrum[ch][k], L_subframeTCX ); + set32_fx( inv_spectrum[ch][k], 0, L_subframeTCX ); + } + sts[ch]->hTcxEnc->spectrum_e[1] = add( sts[ch]->hTcxEnc->spectrum_e[0], 4 ); + sts[ch]->hTcxEnc->spectrum_e[0] = add( sts[ch]->hTcxEnc->spectrum_e[0], 4 ); + hMCT->mc_global_ild[ch] = 0; + move16(); + move16(); + move16(); + } + } + } + } + ELSE + { + hMCT->currBlockDataCnt = 0; + move16(); + FOR( ch = 0; ch < nchan; ch++ ) + { + hMCT->mc_global_ild[ch] = 0; + move16(); + } + } + + pop_wmops(); + + return; +} +#endif + +/*--------------------------------------------------------------------* + * write_mct_bitstream() + * + * write mct metadata to bitstream + *--------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED +void write_mct_bitstream( + Encoder_State **sts, /* i/o: encoder state structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const int16_t nchan /* i : number of channels */ ) { int16_t pair, ch; @@ -722,14 +1527,214 @@ void write_mct_bitstream( return; } +#else +void write_mct_bitstream_fx( + Encoder_State **sts, /* i/o: encoder state structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const Word16 nchan /* i : number of channels */ +) +{ + Word16 pair, ch; + Word16 channelPairIndex; + Word16 nbits_start; + MCT_BLOCK_DATA_HANDLE hBlock; + Encoder_State *p_st[2]; + BSTR_ENC_HANDLE hBstr = sts[0]->hBstr; + + nbits_start = hBstr->nb_bits_tot; + move16(); + + push_next_indice( hBstr, hMCT->currBlockDataCnt, MCT_NUM_BLOCK_DATA_BITS ); + + /* first write core info and overlap mode for all channels */ + FOR( ch = 0; ch < nchan; ch++ ) + { + test(); + IF( hMCT->currBlockDataCnt && NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + push_next_indice( hBstr, hMCT->mc_global_ild[ch], SMDCT_GLOBAL_ILD_BITS ); + } + } + + IF( hMCT->currBlockDataCnt ) + { + FOR( ch = 0; ch < nchan; ch++ ) + { + IF( NE_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + push_next_indice( hBstr, hMCT->lowE_ch[ch], 1 ); + } + } + } + + /* Do for each stereo block */ + FOR( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) + { + hBlock = hMCT->hBlockData[pair]; + + /*calculate channel pair index and write it to BS*/ + channelPairIndex = channelPairToIndex_fx( hBlock->ch1, hBlock->ch2, nchan ); + push_next_indice( hBstr, channelPairIndex, hMCT->bitsChannelPairIndex ); + + /*point to encoder states of actual channels to write block pair bits*/ + p_st[0] = sts[hBlock->ch1]; + p_st[1] = sts[hBlock->ch2]; + /*then business as usual for each block pair */ + write_stereo_to_bitstream( hMCT->hBlockData[pair]->hStereoMdct, p_st, hBlock->mask, 1, hBstr ); + } + + hMCT->nBitsMCT = sub( hBstr->nb_bits_tot, nbits_start ); + move16(); + + return; +} +#endif /*--------------------------------------------------------------------* * mctStereoIGF_enc() * * IGF analysis of channels after MCT processing *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void mctStereoIGF_enc_fx( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2], /* i : MDCT spectrum for ITF */ + Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate*/ + Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect.*/ + Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ +#endif // IVAS_FLOAT_FIXED + float *orig_spectrum[MCT_MAX_CHANNELS][2], /* i : MDCT spectrum for ITF */ + float powerSpec[MCT_MAX_CHANNELS][L_FRAME48k], /* i/o: MDCT^2 + MDST^2 spectrum,or estimate*/ + float *powerSpecMsInv[MCT_MAX_CHANNELS][NB_DIV], /* i : same as above but for inverse spect.*/ + float *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const Word16 sp_aud_decision0[MCT_MAX_CHANNELS] /* i : speech audio decision */ +) +{ +#ifdef IVAS_FLOAT_FIXED + Word32 *p_powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; + Word32 *p_inv_spectrum_fx[CPE_CHANNELS][NB_DIV]; + Word32 *p_orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; + Word32 *p_powerSpec_fx[NB_DIV]; +#endif // IVAS_FLOAT_FIXED + + UNUSED_PARAM( powerSpec_fx ); + int16_t b, nSubframes, L_subframeTCX; + int16_t p_ch[2], n, ch, ch1, ch2; + Encoder_State *p_st[NB_DIV]; + Encoder_State *st; + float *p_powerSpecMsInv[CPE_CHANNELS][NB_DIV]; + float *p_inv_spectrum[CPE_CHANNELS][NB_DIV]; + float *p_orig_spectrum[CPE_CHANNELS][NB_DIV]; + float *p_powerSpec[NB_DIV]; + int16_t singleChEle[MCT_MAX_CHANNELS]; + + L_subframeTCX = 0; /* to avoid compilation warning */ + set_s( singleChEle, 1, hMCT->nchan_out_woLFE ); + + for ( b = 0; b < hMCT->currBlockDataCnt; b++ ) + { + ch1 = hMCT->hBlockData[b]->ch1; + ch2 = hMCT->hBlockData[b]->ch2; + + p_ch[0] = ch1; + p_ch[1] = ch2; + + singleChEle[hMCT->hBlockData[b]->ch1] = 0; + singleChEle[hMCT->hBlockData[b]->ch2] = 0; + + /* point to encoder states of actual channels to write block pair bits */ + p_st[0] = sts[ch1]; + p_st[1] = sts[ch2]; + if ( ch1 > 0 ) + { + sts[ch1]->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; + } + + if ( ch2 > 0 ) + { + sts[ch2]->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; + } + +#if 1 + p_powerSpec_fx[0] = powerSpec_fx[ch1]; + p_powerSpec_fx[1] = powerSpec_fx[ch2]; +#endif + p_powerSpec[0] = powerSpec[ch1]; + p_powerSpec[1] = powerSpec[ch2]; + + /* Band-wise M/S for MDST */ + nSubframes = p_st[0]->hTcxEnc->tcxMode == TCX_20 ? 1 : NB_DIV; + for ( n = 0; n < nSubframes; n++ ) + { +#if 1 + p_orig_spectrum[0][n] = orig_spectrum[ch1][n]; + p_orig_spectrum[1][n] = orig_spectrum[ch2][n]; + p_powerSpecMsInv[0][n] = powerSpecMsInv[ch1][n]; + p_powerSpecMsInv[1][n] = powerSpecMsInv[ch2][n]; + p_inv_spectrum[0][n] = inv_spectrum[ch1][n]; + p_inv_spectrum[1][n] = inv_spectrum[ch2][n]; +#endif + p_orig_spectrum_fx[0][n] = orig_spectrum_fx[ch1][n]; + p_orig_spectrum_fx[1][n] = orig_spectrum_fx[ch2][n]; + p_powerSpecMsInv_fx[0][n] = powerSpecMsInv_fx[ch1][n]; + p_powerSpecMsInv_fx[1][n] = powerSpecMsInv_fx[ch2][n]; + p_inv_spectrum_fx[0][n] = inv_spectrum_fx[ch1][n]; + p_inv_spectrum_fx[1][n] = inv_spectrum_fx[ch2][n]; + if ( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n] != hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[n] || + hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n] == SMDCT_BW_MS ) + { + ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, p_powerSpec_fx, p_powerSpecMsInv_fx, p_inv_spectrum_fx, p_orig_spectrum, p_powerSpec, p_powerSpecMsInv, p_inv_spectrum, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); + } + else + { + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = p_st[ch]; + + L_subframeTCX = st->hTcxEnc->L_frameTCX / nSubframes; + + ProcessIGF( st, st->hTcxEnc->spectrum[n], (float *) orig_spectrum[p_ch[ch]][n], &powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch1], 0 ); + } + } + } + } + + /* channel elements that are coded separately detected */ + if ( sum_s( singleChEle, ( hMCT->nchan_out_woLFE ) ) != 0 ) + { + for ( ch = 0; ch < ( hMCT->nchan_out_woLFE ); ch++ ) + { + if ( singleChEle[ch] ) + { + st = sts[ch]; + + if ( + st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + + if ( ch > 0 ) + { + st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; + } + + nSubframes = st->hTcxEnc->tcxMode == TCX_20 ? 1 : NB_DIV; + for ( n = 0; n < nSubframes; n++ ) + { + ProcessIGF( st, st->hTcxEnc->spectrum[n], (float *) orig_spectrum[ch][n], &powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); + } + } + } + } + + return; +} +#endif void mctStereoIGF_enc( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ Encoder_State **sts, /* i/o: encoder state structure */ diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index f2e7125969483ac56a90450e56b8bdf533b43614..180594fa97281a6c14121f422a7ec608e1b06817 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -41,6 +41,11 @@ #include "rom_com.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#include "prot_fx.h" +#endif + /*--------------------------------------------------------------* * Local constants @@ -582,6 +587,10 @@ void ivas_mdct_core_whitening_enc( Encoder_State *st, **sts; float scf[CPE_CHANNELS][NB_DIV][M]; float scf_q[CPE_CHANNELS][NB_DIV][M]; +#ifdef IVAS_FLOAT_FIXED + Word32 scf_fx[CPE_CHANNELS][NB_DIV][M]; + Word32 scf_q_fx[CPE_CHANNELS][NB_DIV][M]; +#endif float chE[2], chE_tot; int8_t sns_low_br_mode; int16_t nbits_start_sns; @@ -599,7 +608,11 @@ void ivas_mdct_core_whitening_enc( for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef IVAS_FLOAT_FIXED + stereo_tcx_init_enc_fx( sts[ch] ); +#else stereo_tcx_init_enc( sts[ch] ); +#endif set_s( tnsSize[ch], 0, 2 ); set_s( tnsBits[ch], 0, 2 ); @@ -898,7 +911,20 @@ void ivas_mdct_core_whitening_enc( if ( sts[0]->hTcxEnc->tcxMode == TCX_20 && sts[1]->hTcxEnc->tcxMode == TCX_20 && sts[0]->mct_chan_mode == MCT_CHAN_MODE_REGULAR && sts[1]->mct_chan_mode == MCT_CHAN_MODE_REGULAR ) { +#ifdef IVAS_FLOAT_FIXED + /*=================flt-2-fix==============*/ + Word16 exp_snl = 0, exp_snr = 0; + f2me_buf( scf[0][0], scf_fx[0][0], &exp_snl, M ); + f2me_buf( scf[1][0], scf_fx[1][0], &exp_snr, M ); + /*=================flt-2-fix==============*/ + sns_avq_cod_stereo_fx( scf_fx[0][0], exp_snl, scf_fx[1][0], exp_snr, sts[0]->L_frame, scf_q_fx[0][0], scf_q_fx[1][0], param_lpc[0], param_lpc[1] ); + /*===============fix-2-flt==========================*/ + fixedToFloat_arrL( scf_q_fx[0][0], scf_q[0][0], Q16, M ); + fixedToFloat_arrL( scf_q_fx[1][0], scf_q[1][0], Q16, M ); + /*===============fix-2-flt==========================*/ +#else sns_avq_cod_stereo( scf[0][0], scf[1][0], sts[0]->L_frame, scf_q[0][0], scf_q[1][0], param_lpc[0], param_lpc[1] ); +#endif } else { @@ -910,7 +936,31 @@ void ivas_mdct_core_whitening_enc( continue; } st = sts[ch]; - +#ifdef IVAS_FLOAT_FIXED + Word16 exp_scf_1 = 0, exp_scf_0 = 0; + IF( st->hTcxEnc->tcxMode == TCX_20 ) + { + /*===============flt-2-fix==========================*/ + f2me_buf( scf[ch][0], scf_fx[ch][0], &exp_scf_0, M ); + /*===============flt-2-fix==========================*/ + sns_avq_cod_fx( scf_fx[ch][0], exp_scf_0, NULL, 0, scf_q_fx[ch][0], NULL, ¶m_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode ); + /*===============fix-2-flt==========================*/ + fixedToFloat_arrL( scf_q_fx[ch][0], scf_q[ch][0], Q16, M ); + /*===============fix-2-flt==========================*/ + } + ELSE + { + /*===============flt-2-fix==========================*/ + f2me_buf( scf[ch][1], scf_fx[ch][1], &exp_scf_1, M ); + f2me_buf( scf[ch][0], scf_fx[ch][0], &exp_scf_0, M ); + /*===============flt-2-fix==========================*/ + sns_avq_cod_fx( scf_fx[ch][1], exp_scf_1, scf_fx[ch][0], exp_scf_0, scf_q_fx[ch][1], scf_q_fx[ch][0], ¶m_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode ); + /*===============fix-2-flt==========================*/ + fixedToFloat_arrL( scf_q_fx[ch][0], scf_q[ch][0], Q16, M ); + fixedToFloat_arrL( scf_q_fx[ch][1], scf_q[ch][1], Q16, M ); + /*===============fix-2-flt==========================*/ + } +#else if ( st->hTcxEnc->tcxMode == TCX_20 ) { sns_avq_cod( scf[ch][0], NULL, scf_q[ch][0], NULL, ¶m_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode ); @@ -919,6 +969,7 @@ void ivas_mdct_core_whitening_enc( { sns_avq_cod( scf[ch][1], scf[ch][0], scf_q[ch][1], scf_q[ch][0], ¶m_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode ); } +#endif } } } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 075135e4184b26058096abb3c1885ab8fca78f2a..7d815d5d110aee4d3f6275b2a0f9fad014565a4c 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -38,8 +38,7 @@ #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" @@ -90,7 +89,11 @@ ivas_error ivas_omasa_enc_open( hOMasa->num_Cldfb_instances = numAnalysisChannels; for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -609,6 +612,78 @@ void ivas_omasa_enc( * * Set the importance of particular ISM streams in combined-format coding *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation Q8*/ + Word16 ism_imp[] /* o : ISM importance flags */ +) +{ + Encoder_State *st; + Word16 ch, ctype, active_flag; + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + st = hSCE[ch]->hCoreCoder[0]; + + active_flag = st->vad_flag; + move16(); + + IF( active_flag == 0 ) + { + if ( GT_32( st->lp_noise_fx, 3840 /*15 in Q8*/ ) || LT_32( L_sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /*30*/ ) ) + { + active_flag = 1; + move16(); + } + } + + Word32 quo, rem; + iDiv_and_mod_32( ism_total_brate, nchan_transport, &quo, &rem, 0 ); + + /* do not use the low-rate core-coder mode at highest bit-rates */ + if ( GT_32( quo, IVAS_48k ) ) + { + active_flag = 1; + move16(); + } + + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + st->low_rate_mode = 0; + IF( active_flag == 0 ) + { + ism_imp[ch] = ISM_INACTIVE_IMP; + move16(); + st->low_rate_mode = 1; + move16(); + } + ELSE IF( EQ_16( ctype, INACTIVE ) || EQ_16( ctype, UNVOICED ) ) + { + ism_imp[ch] = ISM_LOW_IMP; + move16(); + } + ELSE IF( EQ_16( ctype, VOICED ) ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + move16(); + } + ELSE /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + move16(); + } + + hIsmMeta[ch]->ism_metadata_flag = active_flag; /* flag is needed for the MD coding */ + move16(); + } + + return; +} +#endif void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ @@ -669,7 +744,6 @@ void ivas_set_ism_importance_interformat( return; } - /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() * diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 296dbce5c36a1e6996127c0d9b9a7c68fd373952..b170b0066565665698de119764afe6f344889653 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif @@ -170,7 +171,273 @@ void ivas_osba_enc_close( * * oSBA encoder reconfiguration *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_osba_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, nSCE_old, nCPE_old, nchan_transport_old; + ISM_MODE old_ism_mode; + Word32 ivas_total_brate; + ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + error = IVAS_ERR_OK; + move32(); + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + + IF( NE_32( ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + int16_t analysis_order_old; + int16_t spar_reconfig_flag; + int16_t nbands_old; + int16_t ndir_old; + + spar_reconfig_flag = 0; + move16(); + old_ism_mode = st_ivas->ism_mode; + move32(); + IF( GE_32( ivas_total_brate, IVAS_256k ) ) + { + st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); + } + ELSE + { + st_ivas->ism_mode = ISM_MODE_NONE; + move32(); + } + nchan_transport_old = st_ivas->nchan_transport; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + move16(); + move16(); + move16(); + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + move16(); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); + + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; + move16(); + ndir_old = st_ivas->hQMetaData->no_directions; + move16(); + + test(); + IF( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) || NE_32( old_ism_mode, st_ivas->ism_mode ) ) + { + Word16 i, n_old; + Word32 **old_mem_hp20_in_fx; + + n_old = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ) ); + n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); +#if 1 // To be removed + float **old_mem_hp20_in; + + if ( n > n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* create additional hp20 memories */ + for ( ; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } + else if ( n < n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* remove superfluous hp20 memories */ + for ( ; i < n_old; i++ ) + { + free( old_mem_hp20_in[i] ); + old_mem_hp20_in[i] = NULL; + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } +#endif + IF( GT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* create additional hp20 memories */ + FOR( ; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + ELSE IF( LT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* remove superfluous hp20 memories */ + FOR( ; i < n_old; i++ ) + { + free( old_mem_hp20_in_fx[i] ); + old_mem_hp20_in_fx[i] = NULL; + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + } + +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#else + ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#endif + + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + { + /* FB mixer handle */ + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + hDirAC->hFbMixer = NULL; + } + spar_reconfig_flag = 1; + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + { + int16_t dir, j, i; + IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; + for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + { + for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + q_direction[dir].band_data[j].energy_ratio_index[i] = 0; + q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + } + } + } + } + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( old_ism_mode == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + } + else if ( old_ism_mode == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan_transport_old += st_ivas->hEncoderConfig->nchan_ism; + } + else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + nchan_transport_old += st_ivas->hEncoderConfig->nchan_ism; + } + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#else ivas_error ivas_osba_enc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -208,13 +475,10 @@ ivas_error ivas_osba_enc_reconfig( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; -#ifndef IVAS_FLOAT_FIXED + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#else - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); - analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#endif + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; @@ -363,7 +627,7 @@ ivas_error ivas_osba_enc_reconfig( return error; } - +#endif /*--------------------------------------------------------------------------* * ivas_osba_enc() diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 37d72eda5c4227ac71717502154aecd87e815aff..819a42d3eb1ca4ba68519dcc899cd412b7d92c7f 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -42,8 +42,7 @@ #include "wmc_auto.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" diff --git a/lib_enc/ivas_rom_enc.c b/lib_enc/ivas_rom_enc.c index 565093d56a90a260295414ee36aa78ce7a0d0206..1afadbb2caad9907ce7083f6a8e1cd8d1aaf8258 100644 --- a/lib_enc/ivas_rom_enc.c +++ b/lib_enc/ivas_rom_enc.c @@ -722,6 +722,75 @@ const float ari_bit_estimate_s17_LC[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = { 1.2858f,2.9245f,5.1959f,6.8503f,2.9659f,3.2823f,5.0458f,6.4686f,5.1703f,5.0458f,6.3065f,7.6781f,6.8301f,6.5324f,7.6601f,8.7521f,4.3982f } }; +#ifdef IVAS_FLOAT_FIXED +const Word32 ari_bit_estimate_s17_LC_fx[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = // Q23 +{ + {83886080, 75881672, 61002796, 63255136, 77113120, 68724512, 57378916, 59202600, 63963136, 59104456, 60121992, 61117720, 66920960, 61587484, 62456544, 63393548, 1051931 }, + {9617539, 43694580, 72206624, 86402664, 16572534, 38999476, 65683640, 84666224, 30722438, 45647448, 68510600, 83886080, 42014344, 52961476, 74412824, 88424320, 32977296 }, + {16015530, 25555894, 41778624, 55004940, 25458586, 25380572, 38384592, 49867756, 40708236, 37617036, 46374740, 55574528, 53380068, 47898952, 54527628, 62716588, 26883810 }, + {20729090, 24146608, 39261204, 53876672, 24633986, 22665180, 34551836, 47295812, 39185704, 34411748, 42599028, 52902756, 53020196, 47149012, 52844876, 61468364, 30629324 }, + {19936366, 26554138, 39356832, 51112628, 24781626, 25550022, 36755524, 47112940, 35624740, 35102968, 45841228, 54935316, 45424312, 43887520, 53501704, 61952388, 26163230 }, + {31474896, 29648696, 39356832, 48656444, 30920410, 26409854, 34061104, 42327240, 41032876, 34942748, 40391988, 46968656, 50284672, 43667736, 47443452, 52786156, 15354508 }, + {27007124, 26188396, 38003748, 50051468, 27327568, 23485586, 33204628, 44083812, 39452464, 33841324, 40623512, 49204220, 51062296, 44572868, 49642944, 56482176, 21983186 }, + {32589742, 28184046, 37683304, 48452600, 28982640, 23729694, 31635118, 41501800, 37901408, 32003378, 38158100, 46685960, 48331804, 42327240, 47076868, 53380068, 21107416 }, + {4258477, 28757826, 59104456, 80595232, 26965180, 37290720, 61117720, 78978744, 53876672, 58165768, 75125016, 90848624, 72497704, 73740056, 86402664, 97962168, 63818012 }, + {8635233, 22469726, 47518108, 66920960, 23672652, 28382856, 48574236, 65189552, 48291540, 48864480, 62982508, 76688656, 65853088, 65029328, 75125016, 86402664, 50715848 }, + {36038300, 31635118, 39242748, 47518108, 32798618, 27027256, 33274252, 40771992, 40538788, 34049360, 38598500, 45021660, 48780596, 41825600, 45424312, 50570724, 14716974 }, + {12080434, 20354118, 46038360, 66374860, 21324680, 24359678, 45175172, 62982508, 47406540, 45488064, 57898172, 71371112, 67493064, 62982508, 71105200, 81185784, 49553184 }, + {15030708, 20736638, 38705876, 53876672, 24454470, 24260694, 38262120, 51418812, 43804472, 41054688, 51062296, 61952388, 58256364, 54797744, 62849128, 71921408, 37178312 }, + {37403964, 33390016, 40771992, 48093568, 35361340, 29546356, 35102968, 41254336, 43317932, 36526516, 40350884, 45361396, 50284672, 43239080, 46306792, 50618540, 11327137 }, + {17194968, 21221500, 35457808, 47295812, 27103592, 25865434, 36213620, 45841228, 43667736, 40412956, 48739492, 57128100, 55574528, 52387696, 59400572, 65853088, 29113502 }, + {21471482, 22235684, 39375288, 54593900, 23342140, 21510908, 35009856, 49075872, 40580732, 35610480, 44140016, 55144192, 55214656, 48906424, 55004940, 63674568, 32843078 }, + {43558684, 37952580, 43108216, 48615340, 38943272, 32362410, 36362100, 41411204, 44311144, 37162372, 40003592, 44140016, 49731864, 42205604, 44514148, 47937540, 9255151 }, + {117440512, 117440512, 28514556, 38314968, 117440512, 117440512, 31228272, 39568224, 30326496, 32182056, 38054920, 44691148, 40003592, 40751020, 45237248, 50570724, 10523509 }, + {22771716, 23176046, 39356832, 54729796, 23619804, 21598988, 35251448, 49075872, 39823240, 35333656, 44602228, 55357264, 54132528, 48291540, 54935316, 62849128, 28298130 }, + {34837052, 30657006, 38907204, 48093568, 31444698, 25984552, 32853984, 41098308, 39665532, 33332134, 38508744, 45456188, 48452600, 41662860, 45615572, 51214128, 16284805 }, + {22184512, 26574272, 40559760, 52387696, 26468574, 24628114, 35526592, 46273240, 39863504, 35049280, 42524372, 51418812, 51011964, 45175172, 50378624, 57635608, 21915238 }, + {4598131, 26208528, 62456544, 90848624, 25592804, 35865492, 65853088, 89573560, 59301588, 62982508, 82460856, 100663296, 84666224, 84666224, 97962168, 109051904, 80032352 }, + {46273240, 40902012, 45808512, 50426440, 41919552, 35361340, 38925656, 43030204, 47004728, 39665532, 42062160, 45456188, 51680536, 43859836, 45939372, 48615340, 7052806 }, + {18423900, 28789702, 43694580, 53380068, 27613620, 26883810, 38279736, 48015552, 41321444, 37004668, 43887520, 51522832, 50863484, 45424312, 51893608, 57045052, 19697290 }, + {117440512, 117440512, 39280496, 45051860, 117440512, 117440512, 39394580, 44168536, 40023728, 40206600, 43640056, 47480360, 46171736, 45456188, 48172420, 51470820, 4772195 }, + {34222164, 44111496, 59400572, 67889840, 33193722, 38071696, 51733384, 60664736, 41708996, 43056208, 53750004, 61707440, 47221992, 47004728, 56171796, 62849128, 5373071 }, + {5433133, 27810752, 53939588, 73740056, 25978680, 33625736, 55074568, 71643744, 49642944, 52220764, 67889840, 81806544, 66024216, 66736408, 78978744, 92274688, 55574528 }, + {9987477, 22437010, 48615340, 69164912, 22240716, 26003846, 46581100, 64257576, 47706852, 45808512, 57898172, 70590136, 67690192, 62716588, 70845152, 80032352, 50863484 }, + {30684690, 32469784, 43213076, 51418812, 33448736, 30093292, 37851076, 45113096, 43999088, 38123708, 42876692, 48015552, 51265300, 44631588, 48172420, 52056344, 10875830 }, + {14467832, 21260088, 43056208, 61117720, 22180318, 23276710, 40371016, 56095460, 43586368, 40454900, 51214128, 63532800, 61002796, 56019964, 62982508, 72797176, 41662860 }, + {14800021, 19242628, 44750708, 64870784, 20720700, 22442042, 42623356, 60554004, 46826048, 43531844, 55074568, 68300048, 66554376, 60776304, 68300048, 77553520, 46933424 }, + {15023158, 23893272, 42062160, 57378916, 23625676, 24059366, 38437440, 52331492, 41411204, 38020528, 47821776, 59007148, 56171796, 51112628, 58532352, 67493064, 34086268 }, + {19163774, 22665180, 36894776, 49117816, 25928348, 24032524, 35089548, 46443528, 41732484, 37258840, 45679328, 54327980, 53876672, 49642944, 56171796, 63963136, 29113502 }, + {22422750, 23110616, 36801664, 48864480, 26403144, 23583732, 34360576, 45144132, 41593236, 36709388, 44840464, 53380068, 54866528, 49247000, 54661848, 61233484, 24719550 }, + {52786156, 45939372, 49642944, 53440468, 47185920, 39943196, 42648520, 45873940, 51265300, 43749948, 45550980, 48054140, 55144192, 47295812, 48780596, 50764500, 4665324 }, + {25013152, 23957864, 37969356, 51839920, 25183440, 21892590, 33102286, 45550980, 38888748, 33757436, 41298796, 51470820, 52443900, 46071912, 51787072, 59602736, 28351818 }, + {28010400, 25815102, 37683304, 50051468, 26521424, 22399262, 32182056, 43749948, 38227724, 32437908, 39626944, 49290620, 50378624, 43722264, 49421484, 57045052, 25435098 }, + {63118404, 55429404, 54327980, 57549208, 56640720, 48822536, 48372068, 50962472, 56962844, 49822460, 51162960, 52844876, 60016296, 53020196, 53876672, 55429404, 2546613 }, + {24288376, 30110908, 42698852, 52165396, 29580748, 27722672, 37226964, 45679328, 41525288, 36111280, 42327240, 49204220, 50522068, 43776788, 48615340, 54067936, 15380513 }, + {31434630, 28298130, 38314968, 48739492, 29436464, 24498930, 32589742, 42182116, 39205000, 33011690, 38907204, 46826048, 49160600, 42401056, 46790816, 52961476, 19214106 }, + {3153193, 31766820, 62982508, 85505080, 29105114, 41990016, 66736408, 84666224, 56640720, 62849128, 80595232, 95755960, 75497472, 78010696, 92274688, 104144568, 68300048 }, + {28313230, 28063250, 39242748, 49777160, 28313230, 24805114, 34172672, 43640056, 39318244, 34098012, 40708236, 48697548, 49377864, 43265084, 48211848, 54593900, 18742666 }, + {40084124, 34889900, 41076496, 47821776, 35695204, 29411298, 34360576, 40517816, 41755136, 34903320, 38742788, 43804472, 48533968, 41142768, 44225580, 48412336, 12035136 }, + {6888557, 22805270, 47706852, 65853088, 26156518, 31920332, 51316472, 66374860, 52671232, 53079756, 66736408, 78978744, 70340992, 68724512, 78978744, 89573560, 51839920 }, + {6934359, 23031762, 55214656, 81185784, 23076222, 30317268, 56248972, 77553520, 54262548, 55285960, 70590136, 87367352, 79493808, 75881672, 84666224, 95755960, 66736408 }, + {10658565, 23201212, 47221992, 67299288, 22065394, 25833558, 45743920, 63393548, 44197060, 43722264, 57898172, 71643744, 61952388, 59202600, 69622088, 79493808, 44900024 }, + {9992510, 19614244, 42474876, 58720256, 25422516, 28283030, 45519944, 59400572, 50912980, 49075872, 60444952, 71643744, 68300048, 65351452, 74072248, 82460856, 45175172 }, + {14219529, 22078816, 44083812, 62585728, 21781020, 23573666, 42037832, 58256364, 42573864, 40538788, 53258432, 66198700, 59007148, 55285960, 64109096, 74412824, 37649752 }, + {17939038, 22324602, 41164576, 58076012, 22442042, 22171090, 37901408, 53139316, 40580732, 37371248, 48412336, 60335900, 56482176, 51733384, 59400572, 68510600, 33914304 }, + {12215491, 19329870, 37226964, 51893608, 27263814, 27497858, 41120956, 52786156, 47898952, 45550980, 55795148, 64257576, 63674568, 59501236, 67299288, 74412824, 38037304 }, + {20357474, 23951992, 40104256, 55214656, 23968770, 22699574, 36111280, 49822460, 39356832, 35639000, 44572868, 55285960, 53563780, 47860364, 54460520, 62456544, 28351818 }, + {25089488, 24195262, 37934964, 51367640, 25617132, 22588844, 33841324, 46139020, 39803944, 35143236, 42825520, 52557144, 53139316, 46968656, 52902756, 59705080, 24173452 }, + {15014769, 19723296, 34707028, 46409136, 28560694, 27271364, 37952580, 47745440, 46005644, 43291928, 51214128, 59007148, 59807420, 55795148, 61952388, 68510600, 31326418 }, + {19625988, 26674096, 40288808, 51733384, 27075910, 24902422, 35035860, 45615572, 40329912, 35049280, 42182116, 50522068, 52110872, 45582856, 50912980, 58165768, 24431820 }, + {26508002, 25118848, 36724488, 46512316, 29821502, 25716116, 33853904, 42085648, 43082212, 37550764, 43265084, 49959192, 53687932, 47480360, 51522832, 56640720, 18096744 }, + {17097660, 21086444, 42375892, 60888712, 21402694, 21901816, 39337540, 55720488, 42109972, 38961728, 50237696, 63118404, 59301588, 54327980, 61952388, 71643744, 38262120 }, + {29236816, 27179928, 37952580, 47976128, 29717482, 25555894, 33566176, 42351564, 41525288, 35624740, 40902012, 48331804, 51787072, 45424312, 49509564, 54797744, 17241106 }, + {1703306, 35808452, 78484656, 109051904, 34347996, 51575680, 85505080, 109051904, 74072248, 82460856, 104144568, 117440512, 104144568, 104144568, 117440512, 117440512, 109051904 }, + {117440512, 117440512, 22240716, 38455896, 117440512, 117440512, 26714362, 40559760, 21398500, 26298286, 36740424, 47706852, 36755524, 39491048, 47076868, 56019964, 20389350 }, + {25392316, 25195184, 39185704, 52500104, 25642296, 22694540, 33901720, 46071912, 39185704, 34049360, 41990016, 51470820, 51680536, 45615572, 51062296, 58347800, 23840424 }, + {9318905, 20827236, 51062296, 75125016, 21589760, 26707650, 51575680, 72206624, 51787072, 51316472, 66374860, 81806544, 75125016, 71921408, 81185784, 92274688, 60444952 }, + {20310498, 21762566, 40084124, 56404160, 22670214, 21554528, 36832700, 51575680, 41120956, 37258840, 47480360, 58720256, 57045052, 51627688, 58440076, 66736408, 31208978 }, + {7740001, 25753026, 52220764, 71921408, 23155914, 29666312, 51418812, 68942616, 45712040, 47258900, 62849128, 77113120, 61952388, 61002796, 73103360, 84666224, 47369632 }, + {10786072, 24532484, 43586368, 57464480, 24879772, 27533928, 42327240, 54262548, 43371620, 42327240, 52902756, 64408572, 57295032, 54797744, 64257576, 73417936, 36894776 }, +}; +#endif /*----------------------------------------------------------------------------------* * Stereo downmix to EVS ROM tables diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h index 3c87e361e888e7798669680730140faa68091f7d..bec7df35711e59daba6e246f1ef1c0f921bbfdaf 100644 --- a/lib_enc/ivas_rom_enc.h +++ b/lib_enc/ivas_rom_enc.h @@ -114,6 +114,7 @@ extern const Word32 win_mdct_8k_fx[STEREO_DFT_OVL_8k]; *----------------------------------------------------------------------------------*/ extern const float ari_bit_estimate_s17_LC[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; +extern const Word32 ari_bit_estimate_s17_LC_fx[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; /*----------------------------------------------------------------------------------* * ECLVQ Stereo ROM tables diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index cbd9c869defe943758ce9a33a9a289a67defd17c..21953637ef9b204fdf08e3e5e6f608c5c8f68213 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx.h" #endif @@ -87,7 +88,248 @@ void ivas_sba_getTCs( * * Reconfigure IVAS SBA encoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/* To be renamed as ivas_sba_enc_reconfigure_fx later */ +ivas_error ivas_sba_enc_reconfigure( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, nSCE_old, nCPE_old, nchan_transport_old; + Word32 ivas_total_brate; + ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + error = IVAS_ERR_OK; + move32(); + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + + IF( NE_32( ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + Word16 analysis_order_old; + Word16 spar_reconfig_flag; + Word16 nbands_old; + Word16 ndir_old; + + spar_reconfig_flag = 0; + nchan_transport_old = st_ivas->nchan_transport; + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + move16(); + move16(); + move16(); + move16(); + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + move16(); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); + + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; + move16(); + ndir_old = st_ivas->hQMetaData->no_directions; + move16(); + + IF( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) ) + { + Word16 i, n_old; + Word32 **old_mem_hp20_in_fx; + + n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ); + n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); + +#if 1 // To be removed + float **old_mem_hp20_in; + + if ( n > n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* create additional hp20 memories */ + for ( ; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } + else if ( n < n_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; + old_mem_hp20_in[i] = NULL; + } + /* remove superfluous hp20 memories */ + for ( ; i < n_old; i++ ) + { + free( old_mem_hp20_in[i] ); + old_mem_hp20_in[i] = NULL; + } + + free( old_mem_hp20_in ); + old_mem_hp20_in = NULL; + } +#endif + IF( GT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* create additional hp20 memories */ + FOR( ; i < n; i++ ) + { + IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 ); + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + ELSE IF( LT_16( n, n_old ) ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx; + st_ivas->mem_hp20_in_fx = NULL; + + IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + FOR( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i]; + old_mem_hp20_in_fx[i] = NULL; + } + /* remove superfluous hp20 memories */ + FOR( ; i < n_old; i++ ) + { + free( old_mem_hp20_in_fx[i] ); + old_mem_hp20_in_fx[i] = NULL; + } + + free( old_mem_hp20_in_fx ); + old_mem_hp20_in_fx = NULL; + } + } + +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#else + ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#endif + + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + { + /* FB mixer handle */ + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); + hDirAC->hFbMixer = NULL; + } + spar_reconfig_flag = 1; + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + { + int16_t dir, j, i; + IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; + for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + { + for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + q_direction[dir].band_data[j].energy_ratio_index[i] = 0; + q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + } + } + } + } + hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#else ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -114,13 +356,10 @@ ivas_error ivas_sba_enc_reconfigure( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; -#ifndef IVAS_FLOAT_FIXED + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#else - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); - analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); -#endif + nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; @@ -257,3 +496,4 @@ ivas_error ivas_sba_enc_reconfigure( return error; } +#endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 3e40937fb44f3d371aedf9c601c346f5a5444ee1..cbaf1faa3ce98f5d4c02bca15ac3760ded297b7c 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -37,7 +37,7 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot_fx_enc.h" #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -175,12 +175,19 @@ ivas_error ivas_sce_enc( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], + &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; @@ -543,7 +550,7 @@ ivas_error create_evs_sce_enc( { return error; } - st_fx->hBstr->ind_list_fx = ind_list; + st_fx->hBstr->ind_list = ind_list; // st_fx->hBstr->ind_list_fx = st->hBstr->ind_list; reset_indices_enc_fx( st_fx->hBstr ); hSCE->hCoreCoder[0] = st_fx; diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index c592390522da2643700e475ace3a73f3e69a8eb8..1373e8a6238339c24c7b06f06faa6f1068f7a031 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -37,12 +37,13 @@ #include "cnst.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include "prot_fx.h" #include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" #include "wmc_auto.h" - - +#include "prot_fx_enc.h" /*------------------------------------------------------------------- * sns_1st_cod() * @@ -50,6 +51,126 @@ *-------------------------------------------------------------------*/ /* r : codebook index */ +#ifdef IVAS_FLOAT_FIXED +static Word16 sns_1st_cod_fx( + const Word32 *sns_fx, /* i : vector to quantize */ + Word16 exp_sns, + const Word16 L_frame, + const Word16 core, + Word32 *snsq_fx /* o : quantized sns Q16 */ +) +{ + Word16 index; + const Word16 split_len = M / 2; + move16(); + const Word16 *means; + const Word16 means_fix = 2; // Q15 + move16(); + /* remove means */ + means = NULL; + SWITCH( L_frame ) + { + case L_FRAME16k: + means = &sns_1st_means_16k[core - 1][0]; + break; + case L_FRAME25_6k: + means = &sns_1st_means_25k6[core - 1][0]; + break; + case L_FRAME32k: + means = &sns_1st_means_32k[core - 1][0]; + break; + default: + assert( !"illegal frame length in sns_1st_cod" ); + } + Word16 exp_snsq_buffer[M] = { 0 }, exp_snsq = 0; + move16(); + move16(); + FOR( Word16 i = 0; i < M; ++i ) + { + Word32 tmp = L_mult( means[i], means_fix ); // Q16 + exp_snsq_buffer[i] = 0; + move16(); + snsq_fx[i] = BASOP_Util_Add_Mant32Exp( sns_fx[i], exp_sns, L_negate( tmp ), 15, &exp_snsq_buffer[i] ); + move32(); + } + FOR( int i = 0; i < M; i++ ) + { + exp_snsq = s_max( exp_snsq_buffer[i], exp_snsq ); + } + FOR( int i = 0; i < M; i++ ) + { + snsq_fx[i] = L_shr( snsq_fx[i], exp_snsq - exp_snsq_buffer[i] ); + move32(); + } + + index = 0; + move16(); + FOR( Word16 split = 0; split < 2; ++split ) + { + const Word16 *cdbk_ptr; + Word16 j0, j1, index_split; + Word32 dist_min_fx; + const Word16 cdbk_fix = 8; // 1.f / powf( 2, SNS_CDBKS_BITS_4_FRAC ) in Q15 + move16(); + const Word16 *const cdbk = &sns_1st_cdbk[split][core - 1][0]; + + j0 = imult1616( split, split_len ); + j1 = add( j0, split_len ); + + cdbk_ptr = cdbk; + dist_min_fx = MAXVAL_WORD32; + Word16 exp_dist_min = 31; + index_split = 0; + FOR( Word16 i = 0; i < 32; ++i ) + { + Word32 dist_fx = 0; + move32(); + Word16 exp_dist = 0; + move16(); + FOR( Word16 j = j0; j < j1; ++j ) + { + Word32 tmp_fx; + Word16 exp_tmp = 0; + move16(); + Word32 tmp_1 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16 + tmp_fx = BASOP_Util_Add_Mant32Exp( snsq_fx[j], exp_snsq, L_negate( tmp_1 ), 15, &exp_tmp ); + Word32 tmp_2 = Mpy_32_32( tmp_fx, tmp_fx ); // exp_tmp*2 + dist_fx = BASOP_Util_Add_Mant32Exp( dist_fx, exp_dist, tmp_2, exp_tmp * 2, &exp_dist ); // exp_tmp*2 + } + + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( dist_fx, exp_dist, dist_min_fx, exp_dist_min ), -1 ) ) + { + dist_min_fx = dist_fx; + move32(); + exp_dist_min = exp_dist; + move16(); + index_split = i; + move16(); + } + } + + /* set quantized vector */ + cdbk_ptr = &cdbk[imult1616( index_split, split_len )]; + FOR( Word16 j = j0; j < j1; ++j ) + { + Word32 tmp_3 = L_mult( means[j], means_fix ); // Q16 + Word32 tmp_4 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16 + snsq_fx[j] = L_add( tmp_4, tmp_3 ); // Q16 + move32(); + } + + /* for second split shift by five bits to store both indices as one 10 bit value */ + IF( EQ_16( split, 1 ) ) + { + index_split = shl( index_split, 5 ); + } + + index = add( index, index_split ); + } + + return index; +} +#else static int16_t sns_1st_cod( const float *sns, /* i : vector to quantize */ const int16_t L_frame, @@ -61,7 +182,6 @@ static int16_t sns_1st_cod( const int16_t split_len = M / 2; const int16_t *means; const float means_fix2float = 1.f / powf( 2, SNS_MEANS_BITS_4_FRAC ); - /* remove means */ means = NULL; switch ( L_frame ) @@ -78,12 +198,10 @@ static int16_t sns_1st_cod( default: assert( !"illegal frame length in sns_1st_cod" ); } - for ( int16_t i = 0; i < M; ++i ) { snsq[i] = sns[i] - means[i] * means_fix2float; } - index = 0; for ( int16_t split = 0; split < 2; ++split ) { @@ -102,12 +220,10 @@ static int16_t sns_1st_cod( for ( int16_t i = 0; i < 32; ++i ) { float dist; - dist = 0.f; for ( int16_t j = j0; j < j1; ++j ) { float tmp; - tmp = snsq[j] - ( *cdbk_ptr++ ) * cdbk_fix2float; dist += tmp * tmp; } @@ -137,7 +253,7 @@ static int16_t sns_1st_cod( return index; } - +#endif /*------------------------------------------------------------------- * sns_2st_cod() @@ -146,6 +262,82 @@ static int16_t sns_1st_cod( *-------------------------------------------------------------------*/ /* r : number of allocated bits */ +#ifdef IVAS_FLOAT_FIXED +static Word16 sns_2st_cod_fx( + const Word32 *sns_fx, /* i : normalized vector to quantize */ + Word16 exp_sns, + Word32 *snsq_fx, /* i/o: i:1st stage o:1st+2nd stage Q16 */ + Word16 exp_snsq, + Word16 *indx /* o : index[] (4 bits per words) */ +) +{ + Word16 i, nbits; + + Word16 x_fx[M] = { 0 }; + move16(); + Word16 xq_fx[M]; + Word16 exp_x_buff[M] = { 0 }, exp_x = 0; + move16(); + move16(); + Word32 scale_fx = 858993472; // Q31 + move32(); + Word16 nq; + + FOR( i = 0; i < M; i++ ) + { + Word16 exp_tmp = 0; + move16(); + Word32 tmp = BASOP_Util_Add_Mant32Exp( sns_fx[i], exp_sns, L_negate( snsq_fx[i] ), exp_snsq, &exp_tmp ); + x_fx[i] = BASOP_Util_Divide3232_Scale( tmp, scale_fx, &exp_x_buff[i] ); + move16(); + exp_x_buff[i] = add( exp_x_buff[i], exp_tmp ); + move16(); + } + FOR( i = 0; i < M; i++ ) + { + exp_x = s_max( exp_x, exp_x_buff[i] ); + } + FOR( i = 0; i < M; i++ ) + { + x_fx[i] = shr( x_fx[i], sub( ( 15 - Q10 ), exp_x_buff[i] ) ); + move16(); + } + + /* quantize */ + AVQ_cod_lpc_fx( x_fx, xq_fx, indx, 2 ); + FOR( i = 0; i < M; i++ ) + { + Word32 tmp_1 = Mpy_32_16_1( scale_fx, xq_fx[i] ); // Q31 + Q10 - 15 + tmp_1 = L_shr( tmp_1, 10 ); // Q16 + snsq_fx[i] = L_add( snsq_fx[i], tmp_1 ); // Q16 + move32(); + } + + /* total number of bits using entropic code to index the quantizer number */ + nbits = 0; + move16(); + FOR( i = 0; i < 2; i++ ) + { + nq = indx[i]; + nbits = add( nbits, ( add( 2, ( shl( nq, 2 ) ) ) ) ); /* 2 bits to specify Q2,Q3,Q4,ext */ + + IF( GT_16( nq, 6 ) ) + { + nbits = add( nbits, sub( nq, 3 ) ); /* unary code (Q7=1110, ...) */ + } + ELSE IF( GT_16( nq, 4 ) ) + { + nbits = add( nbits, sub( nq, 4 ) ); /* Q5=0, Q6=10 */ + } + ELSE IF( nq == 0 ) + { + nbits = add( nbits, 3 ); /* Q0=110 */ + } + } + + return ( nbits ); +} +#else static int16_t sns_2st_cod( const float *sns, /* i : normalized vector to quantize */ float *snsq, /* i/o: i:1st stage o:1st+2nd stage */ @@ -194,14 +386,115 @@ static int16_t sns_2st_cod( return ( nbits ); } - +#endif /*------------------------------------------------------------------- * sns_avq_cod() * * Stereo noise-shaping AVQ encoder for 1 channel *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void sns_avq_cod_fx( + const Word32 *sns_fx, /* i : Input sns vectors */ + Word16 exp_sns, + const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ + Word16 exp_snsmid, + Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ + Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ + Word16 *index, /* o : Quantization indices */ + const Word16 core, /* i : core */ + const Word16 L_frame, + const Word16 low_brate_mode /* i : flag low bit operating mode */ +) +{ + Word16 i; + Word16 indxt[256], nbits, nbt, nit; + Word32 snsmid_q0_fx[M]; + + index[0] = sns_1st_cod_fx( sns_fx, exp_sns, L_frame, core, sns_q_fx ); + move16(); + nit = 1 + 2; + move16(); + IF( !low_brate_mode ) + { + nbt = sns_2st_cod_fx( sns_fx, exp_sns, sns_q_fx, 31 - Q16, &index[1] ); + nit = add( nit, add( index[1], index[2] ) ); + } + ELSE + { + index[1] = SNS_LOW_BR_MODE; + move16(); + index[2] = 0; + move16(); + } + + index += nit; + nit = 0; + move16(); + *index = 0; + move16(); + + IF( EQ_16( core, TCX_10_CORE ) ) + { + index++; + + index[0] = sns_1st_cod_fx( snsmid_fx, exp_snsmid, L_frame, core, snsmid_q_fx ); + move16(); + nit = 1 + 2; + move16(); + IF( !low_brate_mode ) + { + nbits = sns_2st_cod_fx( snsmid_fx, exp_snsmid, snsmid_q_fx, 31 - Q16, &index[1] ); + nit = add( nit, add( index[1], index[2] ) ); + } + ELSE + { + index[1] = SNS_LOW_BR_MODE; + move16(); + index[2] = 0; + move16(); + nbits = 0; + move16(); + } + + + nbt = add( 10, nbits ); + + IF( !low_brate_mode ) + { + FOR( i = 0; i < M; i++ ) + { + snsmid_q0_fx[i] = sns_q_fx[i]; + move32(); + } + nbits = sns_2st_cod_fx( snsmid_fx, exp_snsmid, snsmid_q0_fx, 31 - Q16, indxt ); + + IF( LT_16( nbits, nbt ) ) + { + nbt = nbits; + move16(); + nit = add( 2, add( indxt[0], indxt[1] ) ); + index[-1] = 1; + move16(); + + FOR( i = 0; i < M; i++ ) + { + snsmid_q_fx[i] = snsmid_q0_fx[i]; + move32(); + } + FOR( i = 0; i < nit; i++ ) + { + index[i] = indxt[i]; + move16(); + } + } + } + index += nit; + } + return; +} +#else void sns_avq_cod( const float *sns, /* i : Input sns vectors */ const float *snsmid, /* i : Input mid-sns vectors */ @@ -284,7 +577,7 @@ void sns_avq_cod( return; } - +#endif /*------------------------------------------------------------------- * sns_avq_cod_stereo() @@ -292,6 +585,141 @@ void sns_avq_cod( * Stereo noise-shaping AVQ encoder for 2 channels *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void sns_avq_cod_stereo_fx( + const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ + Word16 exp_snl, + const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ + Word16 exp_snr, + const Word16 L_frame, + Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ + Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ + Word16 *indexl, /* o : Quantization indices (left channel) */ + Word16 *indexr /* o : Quantization indices (right channel) */ +) +{ + Word16 i, flag_zero; + Word32 mid_fx[M], side_fx[M], mid_q_fx[M], side_q_fx[M], ener_side_fx; + Word16 exp_ener_side = 0, exp_side_buffer[M] = { 0 }, exp_side = MIN16B; + move16(); + move16(); + move16(); + + /* Compute side */ + ener_side_fx = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + side_fx[i] = BASOP_Util_Add_Mant32Exp( snsl_fx[i], exp_snl, L_negate( snsr_fx[i] ), exp_snr, &exp_side_buffer[i] ); + move32(); + Word32 tmp = Mpy_32_32( side_fx[i], side_fx[i] ); // exp_side[i] * 2 + ener_side_fx = BASOP_Util_Add_Mant32Exp( ener_side_fx, exp_ener_side, tmp, exp_side_buffer[i] * 2, &exp_ener_side ); + } + FOR( i = 0; i < M; i++ ) + { + exp_side = s_max( exp_side, exp_side_buffer[i] ); + } + FOR( i = 0; i < M; i++ ) + { + side_fx[i] = L_shr( side_fx[i], exp_side - exp_side_buffer[i] ); + move32(); + } + + Word16 flag = BASOP_Util_Cmp_Mant32Exp( ener_side_fx, exp_ener_side, 24576, 31 - Q11 ); + IF( EQ_16( flag, -1 ) ) + { + /* MS coding */ + *indexl++ = 2; + move16(); + *indexr++ = 3; + move16(); + + /* Compute mid */ + Word16 exp_mid_buffer[M] = { 0 }; + move16(); + FOR( i = 0; i < M; i++ ) + { + mid_fx[i] = BASOP_Util_Add_Mant32Exp( snsl_fx[i], exp_snl, snsr_fx[i], exp_snr, &exp_mid_buffer[i] ); + move32(); + mid_fx[i] = L_shr( mid_fx[i], 1 ); + move32(); + } + + /* Quantize mid */ + Word16 exp_mid = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + exp_mid = s_max( exp_mid, exp_mid_buffer[i] ); + } + FOR( i = 0; i < M; i++ ) + { + mid_fx[i] = L_shr( mid_fx[i], exp_mid - exp_mid_buffer[i] ); + move32(); + } + indexl[0] = sns_1st_cod_fx( mid_fx, exp_mid, L_frame, TCX_20_CORE, mid_q_fx ); + move16(); + sns_2st_cod_fx( mid_fx, exp_mid, mid_q_fx, ( 31 - Q16 ), &indexl[1] ); + + /* Quantize side */ + indexr[0] = -1; + move16(); + FOR( i = 0; i < M; i++ ) + { + side_q_fx[i] = 0; + move32(); + } + sns_2st_cod_fx( side_fx, exp_side, side_q_fx, 31 - Q16, &indexr[1] ); + + /* Detect zero side */ + flag_zero = 1; + move16(); + FOR( i = 0; i < M; i++ ) + { + if ( side_q_fx[i] != 0 ) + { + flag_zero = 0; + move16(); + break; + } + } + if ( flag_zero ) + { + indexr[0] = -2; + move16(); + } + + /* Go back to LR */ + FOR( i = 0; i < M; i++ ) + { + Word32 a = L_shr( side_q_fx[i], 1 ); + snsl_q_fx[i] = L_add( mid_q_fx[i], a ); + move32(); + snsr_q_fx[i] = L_sub( mid_q_fx[i], a ); + move32(); + } + } + ELSE + { + /* LR coding */ + *indexl++ = 0; + move16(); + *indexr++ = 1; + move16(); + + /* Quantize left */ + indexl[0] = sns_1st_cod_fx( snsl_fx, exp_snl, L_frame, TCX_20_CORE, snsl_q_fx ); + move16(); + sns_2st_cod_fx( snsl_fx, exp_snl, snsl_q_fx, ( 31 - Q16 ), &indexl[1] ); + + /* Quantize right */ + indexr[0] = sns_1st_cod_fx( snsr_fx, exp_snr, L_frame, TCX_20_CORE, snsr_q_fx ); + move16(); + sns_2st_cod_fx( snsr_fx, exp_snr, snsr_q_fx, ( 31 - Q16 ), &indexr[1] ); + } + return; +} +#else void sns_avq_cod_stereo( const float *snsl, /* i : Input sns vector (left channel) */ const float *snsr, /* i : Input sns vector (right channel) */ @@ -376,6 +804,7 @@ void sns_avq_cod_stereo( return; } +#endif int16_t quantize_sns( float sns_in[CPE_CHANNELS][NB_DIV][M], @@ -427,7 +856,19 @@ int16_t quantize_sns( if ( sns_stereo_mode[k] == SNS_STEREO_MODE_MS ) { +#ifndef IVAS_FLOAT_FIXED convertToMS( M, snsQ_out[0][k], snsQ_out[1][k], 0.5f ); +#else + Word32 snsQ_out_fx[2][2][M]; + Word16 q = s_min( Q_factor_arrL( snsQ_out[0][k], M ), Q_factor_arrL( snsQ_out[1][k], M ) ) - 1; + floatToFixed_arrL( snsQ_out[0][k], snsQ_out_fx[0][k], q, M ); + floatToFixed_arrL( snsQ_out[1][k], snsQ_out_fx[1][k], q, M ); + + convertToMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q30 ); + + fixedToFloat_arrL( snsQ_out_fx[0][k], snsQ_out[0][k], q, M ); + fixedToFloat_arrL( snsQ_out_fx[1][k], snsQ_out[1][k], q, M ); +#endif } } } @@ -486,7 +927,19 @@ int16_t quantize_sns( { if ( sns_stereo_mode[k] == SNS_STEREO_MODE_MS ) { +#ifndef IVAS_FLOAT_FIXED convertToMS( M, snsQ_out[0][k], snsQ_out[1][k], 1.f ); +#else + Word32 snsQ_out_fx[2][2][M]; + Word16 q = s_min( Q_factor_arrL( snsQ_out[0][k], M ), Q_factor_arrL( snsQ_out[0][k], M ) ) - 1; + floatToFixed_arrL( snsQ_out[0][k], snsQ_out_fx[0][k], q, M ); + floatToFixed_arrL( snsQ_out[1][k], snsQ_out_fx[1][k], q, M ); + + convertToMS_fx( M, snsQ_out_fx[0][k], snsQ_out_fx[1][k], ONE_IN_Q31 ); + + fixedToFloat_arrL( snsQ_out_fx[0][k], snsQ_out[0][k], q, M ); + fixedToFloat_arrL( snsQ_out_fx[1][k], snsQ_out[1][k], q, M ); +#endif } } } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 238a9ff7b1154f41fc3084ae4dcd60be426b8c8f..ead9c4d2598cb84ee2b32fd8ab5154ff17162e6e 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -31,21 +31,22 @@ *******************************************************************************************************/ #include +#include #include "options.h" #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#include "options.h" +#include "prot_fx.h" #endif #include "ivas_rom_com.h" #include "ivas_stat_com.h" #include "prot.h" #include "math.h" -#include #include "wmc_auto.h" #include "prot_fx_enc.h" +#ifdef DEBUGGING +#include "debug.h" +#endif /*-------------------------------------------------------------------* @@ -150,10 +151,17 @@ ivas_error ivas_spar_enc_open( } /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( !spar_reconfig_flag ) { @@ -208,7 +216,11 @@ ivas_error ivas_spar_enc_open( * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif if ( st_ivas->nchan_transport == 1 ) { @@ -344,10 +356,17 @@ ivas_error ivas_spar_enc_open_fx( } /* Covariance handle */ +#ifdef IVAS_FLOAT_FIXED + IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else IF( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) { return error; } +#endif IF( !spar_reconfig_flag ) { @@ -391,7 +410,11 @@ ivas_error ivas_spar_enc_open_fx( * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { @@ -494,7 +517,11 @@ void ivas_spar_enc_close( ivas_spar_md_enc_close( &( *hSpar )->hMdEnc ); /* Covar. State handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_covar_enc_close_fx( &( *hSpar )->hCovEnc, num_chans ); +#else ivas_spar_covar_enc_close( &( *hSpar )->hCovEnc, num_chans ); +#endif /* FB mixer handle */ ivas_FB_mixer_close( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); @@ -578,7 +605,6 @@ ivas_error ivas_spar_enc( /* write the number of objects in ISM_SBA format*/ push_indice( hMetaData, IND_ISM_NUM_OBJECTS, hEncoderConfig->nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); } - /* front VAD */ if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { @@ -952,12 +978,16 @@ static ivas_error ivas_spar_enc_process( #else ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame, transient_det ); #endif -#ifdef DUMPS_ENABLED - float a[2]; - a[0] = transient_det[0]; - a[1] = transient_det[1]; - dbgwrite_txt( a, 2, "fixed.txt", NULL ); + +#ifdef DEBUGGING + { + float a[2]; + a[0] = transient_det[0]; + a[1] = transient_det[1]; + dbgwrite_txt( a, 2, "fixed.txt", NULL ); + } #endif + if ( ivas_total_brate < IVAS_24k4 ) { transient_det[1] = 0; @@ -1271,12 +1301,16 @@ static ivas_error ivas_spar_enc_process( * Transient detector *-----------------------------------------------------------------------------------------*/ ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame, transient_det ); -#ifdef DUMPS_ENABLED - float a[2]; - a[0] = transient_det[0]; - a[1] = transient_det[1]; - dbgwrite_txt( a, 2, "fixed.txt", NULL ); + +#ifdef DEBUGGING + { + float a[2]; + a[0] = transient_det[0]; + a[1] = transient_det[1]; + dbgwrite_txt( a, 2, "fixed.txt", NULL ); + } #endif + if ( ivas_total_brate < IVAS_24k4 ) { transient_det[1] = 0; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 88dc5ffc83ce551a19da84bb2038a9936896a289..8b896e397a6d45f092ec17c7fe86dc26a9714ea6 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -688,7 +688,11 @@ ivas_error ivas_spar_md_enc_process( active_w = ( hMdEnc->spar_md_cfg.active_w == 1 ) || ( dyn_active_w_flag == 1 ); nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; +#ifdef IVAS_FLOAT_FIXED + bwidth = ivas_get_bw_idx_from_sample_rate_fx( hEncoderConfig->input_Fs ); +#else bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs ); +#endif bwidth = min( bwidth, hEncoderConfig->max_bwidth ); int16_t active_w_vlbr; active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3e9ec271f70fa50cc8a0616ea05c4c55c0bf13ba..668dc5a26f0d3e487dafd4346db956e46edaff07 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -152,7 +152,8 @@ typedef struct stereo_dft_enc_data_struct /*FFT*/ #ifdef IVAS_FLOAT_FIXED Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC]; - Word16 DFT_q_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 DFT_fx_e[CPE_CHANNELS]; + // Word16 DFT_q_fx[CLDFB_NO_CHANNELS_MAX]; #endif float DFT[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC]; int16_t dft_ovl; /* Overlap size */ @@ -212,8 +213,12 @@ typedef struct stereo_dft_enc_data_struct int16_t side_gain_index_ECprevious[STEREO_DFT_BAND_MAX]; int16_t side_gain_index_EC[STEREO_DFT_BAND_MAX]; int16_t side_gain_counter; - float side_gain_bitdiff_lp; +#ifdef IVAS_FLOAT_FIXED Word16 side_gain_bitdiff_lp_fx; + Word16 q_side_gain_bitdiff_lp; +#else + float side_gain_bitdiff_lp; +#endif /* Stereo CNG */ float sidSideGain[STEREO_DFT_ERB4_BANDS]; @@ -303,6 +308,12 @@ typedef struct stereo_dft_enc_data_struct /*misc*/ float icbweRefEner; float lbEner; +#ifdef IVAS_FLOAT_FIXED + Word32 icbweRefEner_fx; + Word16 icbweRefEner_fx_e; + Word32 lbEner_fx; + Word16 lbEner_fx_e; +#endif int16_t flip_sign; Word32 dmx_res_all_prev_fx; /* energy of the previous frame Q31*/ Word16 switch_fade_factor_fx; /* Adaptive fade factor for switch frame Q15*/ @@ -348,7 +359,7 @@ typedef struct stereo_dft_enc_data_struct const Word16 *dft_trigo_16k_fx; const Word16 *dft_trigo_32k_fx; - Word32 output_mem_res_8k_fx[STEREO_DFT_OVL_8k]; + Word32 output_mem_res_8k_fx[STEREO_DFT_OVL_8k]; // Q16 Word32 res_cod_NRG_M_fx[STEREO_DFT_BAND_MAX]; Word32 res_cod_NRG_S_fx[STEREO_DFT_BAND_MAX]; @@ -358,11 +369,11 @@ typedef struct stereo_dft_enc_data_struct Word32 past_nrgR_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; Word32 past_dot_prod_real_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; Word32 past_dot_prod_imag_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; - Word32 output_mem_dmx_fx[STEREO_DFT_OVL_MAX]; - Word32 output_mem_dmx_12k8_fx[STEREO_DFT_OVL_12k8]; - Word32 output_mem_dmx_16k_fx[STEREO_DFT_OVL_16k]; /*can hold 16, 12.8 or 32kHz signals*/ - Word32 output_mem_dmx_32k_fx[STEREO_DFT_OVL_32k]; /*can hold 16, 12.8 or 32kHz signals*/ - Word32 output_mem_dmx_16k_shb_fx[STEREO_DFT_OVL_16k]; + Word32 output_mem_dmx_fx[STEREO_DFT_OVL_MAX]; // Q16 + Word32 output_mem_dmx_12k8_fx[STEREO_DFT_OVL_12k8]; // Q16 + Word32 output_mem_dmx_16k_fx[STEREO_DFT_OVL_16k]; /*can hold 16, 12.8 or 32kHz signals*/ // Q16 + Word32 output_mem_dmx_32k_fx[STEREO_DFT_OVL_32k]; /*can hold 16, 12.8 or 32kHz signals*/ // Q16 + Word32 output_mem_dmx_16k_shb_fx[STEREO_DFT_OVL_16k]; // Q16 Word32 input_mem_itd_fx[CPE_CHANNELS][STEREO_DFT_OVL_MAX]; Word32 gipd_fx[STEREO_DFT_ENC_DFT_NB]; @@ -425,11 +436,12 @@ typedef struct stereo_td_enc_data_structure Word32 tdm_lt_corr_RM_fx; /* Long term right-mono correlation */ Word32 tdm_lt_corr_LM_fx; /* Long term left-mono correlation */ Word32 tdm_last_diff_lt_corr_fx; /* long term correlation difference mem */ - Word32 tdm_last_ratio_fx; /* Last TDM ratio */ - Word32 tdm_lt_rms_L_fx; /* Left channel long term rms */ - Word32 tdm_lt_rms_R_fx; /* Right channel long term rms */ - Word32 tdm_last_ener_lt_R_fx; /* Right channel long term energy */ - Word32 tdm_last_ener_lt_L_fx; /* Left channel long term energy */ + Word16 q_tdm_last_diff_lt_corr; + Word32 tdm_last_ratio_fx; /* Last TDM ratio */ + Word32 tdm_lt_rms_L_fx; /* Left channel long term rms */ + Word32 tdm_lt_rms_R_fx; /* Right channel long term rms */ + Word32 tdm_last_ener_lt_R_fx; /* Right channel long term energy */ + Word32 tdm_last_ener_lt_L_fx; /* Left channel long term energy */ Word16 tdm_last_ratio_idx; /* last TDM ratio index */ Word16 tdm_last_SM_flag; /* Flag to signal a SM encoding scheme -> better for some music item */ @@ -456,11 +468,12 @@ typedef struct stereo_td_enc_data_structure Word32 tdm_lt_corr_RM_SM_fx; /* Long term right-mono correlation in SM mode*/ Word32 tdm_lt_corr_LM_SM_fx; /* Long term left-mono correlation in SM mode*/ Word32 tdm_last_diff_lt_corr_SM_fx; /* long term correlation difference mem in SM mode*/ - Word32 tdm_last_ratio_SM_fx; /* Last TDM ratio in SM mode*/ - Word32 tdm_lt_rms_L_SM_fx; /* Left channel long term rms in SM mode*/ - Word32 tdm_lt_rms_R_SM_fx; /* Right channel long term rms in SM mode*/ - Word32 tdm_last_ener_lt_R_SM_fx; /* Right channel long term energy in SM mode*/ - Word32 tdm_last_ener_lt_L_SM_fx; /* Left channel long term energy in SM mode*/ + Word16 q_tdm_last_diff_lt_corr_SM; + Word32 tdm_last_ratio_SM_fx; /* Last TDM ratio in SM mode*/ + Word32 tdm_lt_rms_L_SM_fx; /* Left channel long term rms in SM mode*/ + Word32 tdm_lt_rms_R_SM_fx; /* Right channel long term rms in SM mode*/ + Word32 tdm_last_ener_lt_R_SM_fx; /* Right channel long term energy in SM mode*/ + Word32 tdm_last_ener_lt_L_SM_fx; /* Left channel long term energy in SM mode*/ Word16 tdm_last_ratio_idx_SM; /* last TDM ratio index in SM mode*/ Word16 tdm_last_SM_flag_noop; /* Flag to signal a SM encoding scheme -> better for some music item in SM mode*/ @@ -653,6 +666,7 @@ typedef struct ivas_stereo_classifier_data_structure float non_sta_ch1; float sp_div_ch1; float ps_diff_ch1, ps_diff_ch2; + Word32 ps_diff_ch1_fx, ps_diff_ch2_fx; float ps_sta_ch1, ps_sta_ch2; float prev_g_IPD; float prev_IPD; @@ -702,7 +716,6 @@ typedef struct ivas_stereo_classifier_data_structure Word32 nchar_ch1_fx, nchar_ch2_fx; Word32 non_sta_ch1_fx; Word32 sp_div_ch1_fx; - Word32 ps_diff_ch1_fx, ps_diff_ch2_fx; Word32 ps_sta_ch1_fx, ps_sta_ch2_fx; Word32 prev_g_IPD_fx; Word32 prev_IPD_fx; @@ -735,6 +748,11 @@ typedef struct ivas_stereo_classifier_data_structure typedef struct { +#ifdef IVAS_FLOAT_FIXED + Word32 long_term_energy_stereo_dmx_enc_fx[MAX_NUM_OBJECTS][PARAM_ISM_HYS_BUF_SIZE]; + Word16 long_term_energy_stereo_dmx_enc_e; + Word16 coh_fx[MAX_NUM_OBJECTS]; +#endif // IVAS_FLOAT_FIXED int16_t dtx_flag; int16_t sce_id_dtx; @@ -742,7 +760,6 @@ typedef struct float long_term_energy_stereo_dmx_enc[MAX_NUM_OBJECTS][PARAM_ISM_HYS_BUF_SIZE]; float coh[MAX_NUM_OBJECTS]; - } ISM_DTX_DATA, *ISM_DTX_HANDLE; /*----------------------------------------------------------------------------------* @@ -753,21 +770,28 @@ typedef struct front_vad_enc { int16_t ini_frame; /* initialization frames counter */ float lp_speech; /* long term speech average */ - Word16 lp_speech_fx; /* Q9 long term speech average */ + /* Q9 long term speech average */ float lp_noise; /* long term noise average */ - Word16 lp_noise_fx; /* long term noise average */ + /* long term noise average */ float mem_decim[2 * L_FILT_MAX]; /* decimation filter memory */ float buffer_12k8[3 * L_FRAME / 2]; /* 12k8 signal buffer */ - float mem_preemph; /* preemph filter memory */ - Word16 mem_preemph_fx; /* preemph filter memory */ - NOISE_EST_HANDLE hNoiseEst; /* Noise estimation handle */ - VAD_HANDLE hVAD; /* VAD handle */ + + float mem_preemph; /* preemph filter memory */ + Word16 mem_preemph_fx; /* preemph filter memory */ + NOISE_EST_HANDLE hNoiseEst; /* Noise estimation handle */ + VAD_HANDLE hVAD; /* VAD handle */ float *delay_buf; Word16 *delay_buf_fx; int16_t delay_samples; - int16_t rem_dtx_ho; /* Remaining hangover frames */ - Word32 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ - Word32 buffer_12k8_fx[3 * L_FRAME / 2]; /* 12k8 signal buffer */ + int16_t rem_dtx_ho; /* Remaining hangover frames */ + +#ifdef IVAS_FLOAT_FIXED + Word16 lp_speech_fx; + Word16 lp_noise_fx; + Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ + Word16 buffer_12k8_fx[3 * L_FRAME / 2]; +#endif + // Word32 buffer_12k8_fx[3 * L_FRAME / 2]; /* 12k8 signal buffer */ } FRONT_VAD_ENC, *FRONT_VAD_ENC_HANDLE; @@ -855,10 +879,11 @@ typedef struct ivas_enc_cov_handler_state_t ivas_cov_smooth_state_t *pCov_dtx_state; int16_t num_bins; int16_t prior_dtx_present; - float bb_var_lt[FOA_CHANNELS]; int16_t prior_var_flag; #ifdef IVAS_FLOAT_FIXED Word32 bb_var_lt_fx[FOA_CHANNELS]; +#else + float bb_var_lt[FOA_CHANNELS]; #endif } ivas_enc_cov_handler_state_t; @@ -1017,7 +1042,9 @@ typedef struct ivas_omasa_encoder_one_data_struct Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ #endif - float lp_noise_CPE; /* LP filtered total noise estimation */ + float lp_noise_CPE; /* LP filtered total noise estimation */ + Word32 lp_noise_CPE_fx; /* LP filtered total noise estimation */ /*Q8*/ + int16_t omasa_stereo_sw_cnt; } OMASA_ENCODER_DATA_STATE, *OMASA_ENCODER_DATA_HANDLE; @@ -1251,12 +1278,20 @@ typedef struct mct_enc_data_structure MCT_BLOCK_DATA_HANDLE hBlockData[MCT_MAX_BLOCKS]; float lastxCorrMatrix[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; +#ifdef IVAS_FLOAT_FIXED + Word32 lastxCorrMatrix_fx[MCT_MAX_CHANNELS][MCT_MAX_CHANNELS]; + Word16 lastxCorrMatrix_e; +#endif int16_t lowE_ch[MCT_MAX_CHANNELS]; uint16_t mc_global_ild[MCT_MAX_CHANNELS]; int16_t nBitsMCT; /* number of bits spent on mct side info */ /* pointers to local buffers */ float *p_mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; float *p_orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; +#ifdef IVAS_FLOAT_FIXED + Word32 *p_mdst_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS]; + Word32 *p_orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS]; +#endif int16_t tnsBits[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns bits in the frame */ int16_t tnsSize[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns parameters put into prm */ int16_t p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; @@ -1351,8 +1386,9 @@ typedef struct ivas_lfe_enc_data_structure const uint16_t *cum_freq_models[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; int16_t lfe_enc_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; int16_t lfe_bits; +#ifndef IVAS_FLOAT_FIXED float *old_wtda_audio; -#ifdef IVAS_FLOAT_FIXED +#else Word32 *old_wtda_audio_fx; Word16 q_old_wtda_audio; #endif // IVAS_FLOAT_FIXED @@ -1414,7 +1450,10 @@ typedef struct ENCODER_CONFIG_HANDLE hEncoderConfig; /* Encoder configuration structure */ float *p_data_f[MAX_INPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point input audio buffers */ - +#ifdef IVAS_FLOAT_FIXED + Word32 *p_data_fx[MAX_INPUT_CHANNELS+MAX_NUM_OBJECTS]; /* fixed-point input audio buffers */ + Word16 q_data_fx; /* Q-factor of fixed-point input audio buffers */ +#endif Indice *ind_list; /* List of indices */ Word16 ivas_max_num_indices; /* Maximum allowed number of indices in the list */ Indice *ind_list_metadata; /* List of indices for metadata */ @@ -1426,6 +1465,9 @@ typedef struct Word16 codec_mode; /* Mode1 or Mode2 of core codec */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ float **mem_hp20_in; /* input signals HP filter memories */ +#ifdef IVAS_FLOAT_FIXED + Word32 **mem_hp20_in_fx; /* input signals HP filter memories */ +#endif /* core-encoder modules */ Word16 nSCE; /* number of total SCEs */ diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index 0b7aac44cfb75a6ca6753d6e4d73178bdd2cd2cc..f98b453a0e11bcf87a3800cbcac8fef655265d66 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -47,6 +47,48 @@ static int16_t adapt_GR_sg( const int16_t *in, const int16_t len, const int16_t no_symb, int16_t *nbits, int16_t *in_enc, const int16_t *map0, const int16_t no_GR_ord ); +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * calculate_diff() + * + * calculate difference wrt previous frame and maps it to positive integer + *---------------------------------------------------------------------*/ + +static void calculate_diff( + const Word16 *in, /* i : current frame values */ + const Word16 *prev, /* i : previous frmae values */ + Word16 *in_diff, /* o : difference values */ + const Word16 len /* i : vector length */ +) +{ + Word16 i, tmp; + + FOR( i = 0; i < len; i++ ) + { + tmp = sub( in[i], prev[i] ); + IF( tmp > 0 ) + { + in_diff[i] = sub( imult1616( 2, tmp ), 1 ); + move16(); + } + ELSE + { + IF( tmp < 0 ) + { + in_diff[i] = imult1616( -2, tmp ); + move16(); + } + ELSE + { + in_diff[i] = 0; + move16(); + } + } + } + + return; +} +#else /*---------------------------------------------------------------------* * calculate_diff() * @@ -84,8 +126,54 @@ static void calculate_diff( return; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * calculate_bit_diff() + * + * estimates the GR number of bits for encoding differential values + * selects between GR order 0 or 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits */ +static Word16 calculate_bit_diff( + Word16 *in_diff, /* i : values to be encoded */ + Word16 len, /* i : number of params */ + Word16 *flag_diff /* o : selected GR order */ +) +{ + Word16 i, nb, nb1; + + nb = 0; + move16(); + nb1 = 0; + move16(); + FOR( i = 0; i < len; i++ ) + { + nb = add( nb, in_diff[i] ); + nb1 = add( nb1, shr( in_diff[i], 1 ) ); + } + nb = add( nb, len ); + nb1 = add( nb1, imult1616( 2, len ) ); + IF( LT_16( nb1, nb ) ) + { + nb = add( nb1, 1 ); + *flag_diff = 1; /* GR order for differential coding */ + move16(); + } + ELSE + { + nb = add( nb, 1 ); + *flag_diff = 0; + move16(); + } + return nb; +} +#else /*---------------------------------------------------------------------* * calculate_bit_diff() * @@ -125,8 +213,76 @@ static int16_t calculate_bit_diff( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_ief_fx() + * + * adaptive GR coding considering also the differential case + *---------------------------------------------------------------------*/ + +/*! r: used GR order */ +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +) +{ + Word16 nb_diff, flag, flag_diff; + Word16 bitdiff; + Word32 L_tmp, L_tmp1; + Word16 exp_diff; + + flag = adapt_GR_sg( in, len, no_symb, nbits, in_enc, map0, no_GR_ord ); + + IF( try_diff ) /* inter-frame prediction allowed */ + { + calculate_diff( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + *nbits_diff = nb_diff; + move16(); + + bitdiff = sub( s_min( imult1616( 5, len ), *nbits ), add( nb_diff, 1 ) ); + L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_LP_FAC_Q31, bitdiff ); // (Q31, Q0) -> Q16 + L_tmp1 = Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_DFT_BITDIFF_LP_FAC_Q31 ), *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16 + *side_gain_bitdiff_lp = extract_h( BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q16, L_tmp1, sub( Q31, add( *q_side_gain_bitdiff_lp, Q16 ) ), &exp_diff ) ); + *q_side_gain_bitdiff_lp = sub( Q15, exp_diff ); + move16(); + + L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_ABS_SELECT_Q31, *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16 + L_tmp1 = Mpy_32_16_1( STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31, side_gain_counter ); // (Q31, Q0) -> Q16 + L_tmp = Mpy_32_32( L_tmp, L_tmp1 ); // (*q_side_gain_bitdiff_lp + Q16, Q16) -> *q_side_gain_bitdiff_lp + Q1 + IF( GT_32( L_shl( L_deposit_l( bitdiff ), add( *q_side_gain_bitdiff_lp, Q1 ) ), L_tmp ) ) + { + flag = add( no_GR_ord, flag_diff ); + *nbits = add( nb_diff, 1 ); + move16(); + } + } + ELSE + { + *nbits_diff = 100; + move16(); + flag_diff = -1; + move16(); + } + + return flag; +} +#else /*---------------------------------------------------------------------* * adapt_GR_ief() * @@ -176,8 +332,90 @@ int16_t adapt_GR_ief( return flag; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_rpg1_ief() + * + * use adaptive GR for RPG's considering also the differential case + *---------------------------------------------------------------------*/ + +/*! r: used GR order */ +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +) +{ + const Word16 *map0; + Word16 s, i, GR_ord, flag_diff, nb_diff; + map0 = &maps[8 * NO_SYMB_GR_PRED_G]; + IF( in[0] == 0 ) + { + s = 0; + move16(); + FOR( i = 0; i < len; i++ ) + { + s = add( s, in[i] ); + } + + IF( s == 0 ) + { + /* encode only the first zero with GR1 */ + *nbits = add( shr( map0[0], 1 ), 2 ); + move16(); + in_enc[0] = map0[0]; + move16(); + } + ELSE + { + *nbits = 1000; /* large number such that the plain coding will be selected */ + move16(); + } + GR_ord = 1; + move16(); + } + ELSE + { + GR_ord = adapt_GR_sg( in, len, no_symb, nbits, in_enc, maps, no_GR_ord ); + } + + IF( try_diff ) + { + calculate_diff( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + *nbits_diff = nb_diff; + move16(); + + IF( LT_16( add( nb_diff, 1 ), *nbits ) ) /* there is one more bit to signal differential coding */ + { + GR_ord = add( no_GR_ord, flag_diff ); + + *nbits = add( nb_diff, 1 ); + move16(); + } + } + ELSE + { + *nbits_diff = 100; + move16(); + } + + return GR_ord; +} +#else /*---------------------------------------------------------------------* * adapt_GR_rpg1_ief() * @@ -249,8 +487,137 @@ int16_t adapt_GR_rpg1_ief( return GR_ord; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_sg() + * + * adaptive GR coding + *---------------------------------------------------------------------*/ + +/*! r: GR order */ +static Word16 adapt_GR_sg( + const Word16 *in, /* i : data to be encoded */ + const Word16 len, /* i : number of params to be encoded */ + const Word16 no_symb, /* i : max number of symbols */ + Word16 *nbits, /* o : estimated number of bits */ + Word16 *in_enc, /* o : mapped symbols */ + const Word16 *map0, /* i : mapping */ + const Word16 no_GR_ord /* i : number of GR orders to be tested (2 or 3)*/ +) +{ + const Word16 *map; + Word16 nbits0, nbits1, nbits2, symb, map_symb, i, nb0, nb1, nb2; + + IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) ) + { + map = &map0[imult1616( 15, no_symb )]; + } + ELSE + { + map = &( map0[imult1616( 8, no_symb )] ); + } + + set_s( in_enc, 0, len ); + + nbits1 = 0; + move16(); + nbits0 = 0; + move16(); + nbits2 = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + symb = in[i]; + move16(); + map_symb = map[symb]; + move16(); + + IF( i == 0 ) + { + /* GR order is 1 for first band*/ + nb0 = add( shr( map_symb, 1 ), 1 ); + nb2 = sub( nb0, 2 ); + } + ELSE + { + nb0 = map_symb; + move16(); + nb2 = shr( map_symb, 2 ); + } + nb1 = shr( map_symb, 1 ); + + in_enc[i] = map_symb; + move16(); + nbits0 = add( nbits0, nb0 ); + nbits1 = add( nbits1, nb1 ); + nbits2 = add( nbits2, nb2 ); + + /* update counts */ + map = &( map0[imult1616( symb, no_symb )] ); + } + + IF( EQ_16( no_GR_ord, 2 ) ) + { + nbits0 = add( nbits0, add( len, 1 ) ); + nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) ); + IF( LE_16( nbits0, nbits1 ) ) + { + *nbits = nbits0; + move16(); + return 0; + } + ELSE + { + *nbits = nbits1; + move16(); + return 1; + } + } + ELSE + { + IF( EQ_16( no_GR_ord, 3 ) ) + { + nbits0 = add( nbits0, add( len, 2 ) ); + nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) ); + nbits2 = add( nbits2, add( imult1616( 3, len ), 2 ) ); + + test(); + IF( LE_16( nbits1, nbits2 ) && LE_16( nbits1, nbits0 ) ) + { + *nbits = nbits1; + move16(); + return 1; + } + + test(); + IF( LE_16( nbits0, nbits2 ) && LE_16( nbits0, nbits1 ) ) + { + *nbits = nbits0; + move16(); + return 0; + } + + test(); + IF( LE_16( nbits2, nbits0 ) && LE_16( nbits2, nbits1 ) ) + { + *nbits = nbits2; + move16(); + return 2; + } + } + ELSE + { + IVAS_ERROR( IVAS_ERR_INTERNAL, "Wrong number of GR orders!" ); + } + } + + return -1; +} +#else /*---------------------------------------------------------------------* * adapt_GR_sg() * @@ -362,8 +729,50 @@ static int16_t adapt_GR_sg( return -1; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR0() + * + * write data with GR order 0 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n, val; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = add( in[i], 1 ); + IF( LT_16( n, 16 ) ) + { + val = sub( shl( 1, in[i] ), 1 ); + val = shl( val, 1 ); + push_indice( hBstr, ind, val, n ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + push_indice( hBstr, ind, sub( shl( 1, sub( n, 15 ) ), 1 ), sub( n, 15 ) ); + push_indice( hBstr, ind, 0, 1 ); + } + nb = add( nb, n ); + } + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR0() * @@ -401,8 +810,53 @@ int16_t write_GR0( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR1() + * + * write data with GR order 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n, val; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = shr( in[i], 1 ); + IF( LT_16( n, 14 ) ) + { + val = sub( shl( 1, n ), 1 ); + val = add( shl( val, 2 ), s_and( in[i], 1 ) ); + push_indice( hBstr, ind, val, add( n, 2 ) ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + IF( GT_16( n, 14 ) ) + { + push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 1 ), 1 ); + } + nb = add( nb, add( n, 2 ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR1() * @@ -443,8 +897,56 @@ int16_t write_GR1( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR2() + * + * write data with GR order 2 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +static Word16 write_GR2( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = shr( in[i], 2 ); + IF( LT_16( n, 14 ) ) + { + IF( n > 0 ) + { + push_indice( hBstr, ind, sub( shl( 1, n ), 1 ), n ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 3 ), 2 ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + IF( GT_16( n, 14 ) ) + { + push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 3 ), 2 ); + } + nb = add( nb, add( n, 3 ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR2() * @@ -488,8 +990,44 @@ static int16_t write_GR2( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_bitstream_GR() + * + * generic GR encoder for GR order 0 or 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +) +{ + Word16 nb; + nb = 0; + move16(); + + push_indice( hBstr, ind, GR_ord, 1 ); + nb = add( nb, 1 ); + + IF( GR_ord == 0 ) + { + nb = add( nb, write_GR0( hBstr, ind, in, len ) ); + } + ELSE + { + nb = add( nb, write_GR1( hBstr, ind, in, len ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_bitstream_GR() * @@ -521,8 +1059,72 @@ int16_t write_bitstream_GR( return nb; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_bitstream_adapt_GR() + * + * write encoded data using adaptive GR + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +) +{ + Word16 nb; + + nb = 0; + /* first component first */ + nb = add( nb, write_GR1( hBstr, ind, in, 1 ) ); + + /* write the GR order */ + IF( EQ_16( no_GR_ord, 2 ) ) + { + push_indice( hBstr, ind, GR_ord, 1 ); + nb = add( nb, 1 ); + } + ELSE + { + IF( EQ_16( GR_ord, 1 ) ) + { + push_indice( hBstr, ind, 0, 1 ); /* GR order = 1*/ + nb = add( nb, 1 ); + } + ELSE + { + push_indice( hBstr, ind, 1, 1 ); + push_indice( hBstr, ind, shr( GR_ord, 1 ), 1 ); /* '10' for GR ord = 0; '11' for GR ord 2 */ + nb = add( nb, 2 ); + } + } + IF( GR_ord == 0 ) + { + nb = add( nb, write_GR0( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + ELSE + { + IF( EQ_16( GR_ord, 1 ) ) + { + nb = add( nb, write_GR1( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + ELSE + { + nb = add( nb, write_GR2( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + } + return nb; +} +#else /*---------------------------------------------------------------------* * write_bitstream_adapt_GR() * @@ -585,3 +1187,4 @@ int16_t write_bitstream_adapt_GR( return nb; } +#endif diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index a755906d86c55493453513eebe343b6a6354d59d..22d07cf28cd8e2d2479d7299b1381b6e31f953a4 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -41,7 +41,7 @@ #include "ivas_rom_enc.h" #include "ivas_cnst.h" #include "wmc_auto.h" -#include "prot_fx1.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* @@ -233,8 +233,15 @@ void stereo_classifier_init( hStereoClassif->nchar_ch2 = 0.0f; hStereoClassif->non_sta_ch1 = 0.0f; hStereoClassif->sp_div_ch1 = 0.0f; + +#ifdef IVAS_FLOAT_FIXED + hStereoClassif->ps_diff_ch1_fx = 0; + hStereoClassif->ps_diff_ch2_fx = 0; + hStereoClassif->ps_sta_ch1_fx = 0; + hStereoClassif->ps_sta_ch2_fx = 0; +#endif hStereoClassif->ps_diff_ch1 = 0.0f; - hStereoClassif->ps_diff_ch2 = 0.0f; + hStereoClassif->ps_sta_ch1 = 0.0f; hStereoClassif->ps_sta_ch2 = 0.0f; hStereoClassif->prev_g_IPD = 0.5f; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index f8fa5aea49ca73455aaf637fe091c778784431c1..55247933e347cf31aa3362ec7eb1c0744d7868e6 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -41,7 +41,7 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "prot_fx1.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index aebe83ca1ae26c70696ff753c455a2ac782b57d8..8fb7d28c8e57be01883dc9bd897db97dfb8d251f 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -40,7 +40,7 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_com_fx.h" @@ -367,6 +367,9 @@ static void stereo_dft_enc_open( hStereoDft->win_ana_energy = (float) hStereoDft->N - hStereoDft->dft_ovl; hStereoDft->win_ana_energy += 2 * sum_f( win, hStereoDft->dft_ovl ); hStereoDft->win_ana_energy = hStereoDft->win_ana_energy / hStereoDft->NFFT; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->win_ana_energy_fx = (Word16) ( hStereoDft->win_ana_energy * ( 1 << 15 ) ); +#endif set_f( hStereoDft->output_mem_dmx_32k, 0, STEREO_DFT_OVL_32k ); hStereoDft->dft_zp = (int16_t) ( STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000 ); @@ -418,6 +421,55 @@ static void stereo_dft_enc_open( set_zero( hStereoDft->output_mem_dmx_16k_shb, STEREO_DFT_OVL_16k ); set_zero( hStereoDft->output_mem_res_8k, STEREO_DFT_OVL_8k ); +#ifdef IVAS_FLOAT_FIXED + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; + + hStereoDft->win_ana_8k_fx = win_ana_8k_fx; + hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; + hStereoDft->win_ana_16k_fx = win_ana_16k_fx; + hStereoDft->win_ana_32k_fx = win_ana_32k_fx; + + hStereoDft->win_8k_fx = win_syn_8k_fx; + hStereoDft->win_12k8_fx = win_syn_12k8_fx; + hStereoDft->win_16k_fx = win_syn_16k_fx; + hStereoDft->win_32k_fx = win_syn_32k_fx; + + IF( EQ_32( input_Fs, 16000 ) ) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->win_ana_fx = win_ana_16k_fx; + hStereoDft->win_fx = win_syn_16k_fx; + } + ELSE IF( EQ_32( input_Fs, 32000 ) ) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->win_ana_fx = win_ana_32k_fx; + hStereoDft->win_fx = win_syn_32k_fx; + } + ELSE + { + assert( EQ_32( input_Fs, 48000 ) ); + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->win_ana_fx = win_ana_48k_fx; + hStereoDft->win_fx = win_syn_48k_fx; + } + + hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; + + /*I/O Buffers*/ + set_zero_fx( hStereoDft->output_mem_dmx_fx, STEREO_DFT_OVL_MAX ); + set_zero_fx( hStereoDft->output_mem_dmx_12k8_fx, STEREO_DFT_OVL_12k8 ); + set_zero_fx( hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k ); + set_zero_fx( hStereoDft->output_mem_dmx_16k_shb_fx, STEREO_DFT_OVL_16k ); + set_zero_fx( hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k ); +#endif + /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[max_bwidth] / L_FRAME48k; #ifndef IVAS_FLOAT_FIXED @@ -458,17 +510,15 @@ static void stereo_dft_enc_open_fx( Word16 win[STEREO_DFT_OVL_MAX]; /*Sizes*/ - /* input_Fs / 48000 */ - Word16 input_Fs_48k = extract_l( Mpy_32_32( input_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - - // input_Fs_48k = shr(input_Fs_48k, sub(15, div_e)); - hStereoDft->N = i_mult( STEREO_DFT_HOP_MAX_ENC, input_Fs_48k ); // e = div_e + hStereoDft->N = extract_l( Mpy_32_32( input_Fs, 42949673 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q31 */ ) ); // e = div_e assert( ( ( input_Fs / FRAMES_PER_SEC ) / hStereoDft->N ) == 1 ); /*Init. DFT sizes*/ - hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e - hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs_48k ); // e = div_e + // hStereoDft->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, input_Fs_48k ); // e = div_e + hStereoDft->NFFT = extract_l( Mpy_32_32( input_Fs, 85899346 ) ); // e = div_e + // hStereoDft->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, input_Fs ); // e = div_e + hStereoDft->dft_ovl = extract_l( Mpy_32_32( input_Fs, 18790482 ) ); // e = div_e mdct_window_sine_IVAS_updated( win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT ); // win_e = 15 FOR( Word16 i = 0; i < shr( STEREO_DFT_OVL_MAX, 1 ); i++ ) { @@ -575,7 +625,12 @@ void stereo_dft_enc_reset( set_s( hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set_s( hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX ); hStereoDft->side_gain_counter = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; + hStereoDft->q_side_gain_bitdiff_lp = Q10; +#else hStereoDft->side_gain_bitdiff_lp = STEREO_DFT_BITDIFF_INIT; +#endif set_zero( hStereoDft->gipd, STEREO_DFT_ENC_DFT_NB ); set_zero( hStereoDft->dot_prod_real_smooth, STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->dot_prod_img_smooth, STEREO_DFT_BAND_MAX ); @@ -1107,6 +1162,423 @@ void stereo_dft_enc_analyze( * Inverse DFT on a 20ms frame *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word32 stereo_dft_enc_synthesize_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ + // float *output, /* o : output synthesis */ + Word32 *output_fx, /* o : output synthesis Q16 */ + Word16 *output_start_index, + Word16 *output_end_index, + const Word16 chan, /* i : channel number */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word32 output_sampling_rate, /* i : output sampling rate */ + const Word16 L_frame, /* i : frame length at internal Fs */ + Word16 *nrg_out_fx_e ) +{ + Word16 i, j, sign; + // float *pDFT_in; + Word32 *pDFT_in_fx; + Word16 DFT_in_fx_e; + Word16 offset, NFFT, N, ovl, zp; + Word16 temp_exp; + // float fac; + Word32 fac_fx; + // float *mem; + Word32 *mem_fx; + // const float *trigo, *win, *win_ana; + const Word16 *trigo_fx; + const Word32 *win_fx, *win_ana_fx; + // float tmp[STEREO_DFT_N_MAX_ENC]; + Word32 tmp_fx[STEREO_DFT_N_MAX_ENC]; + // float nrg; + Word32 nrg_fx; + Word16 nrg_fx_e; + // float trigo_enc[STEREO_DFT_N_MAX_ENC / 2 + 1]; + Word16 trigo_enc_fx[STEREO_DFT_N_MAX_ENC / 2 + 1]; + Word16 trigo_step; + Word16 scal_fac; + + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + IF( L_frame > 0 ) + { + assert( ( output_sampling_rate == 16000 ) && "High-band generation only possible at 16kHz!" ); + } + nrg_fx = 0; + move32(); + nrg_fx_e = 0; + move16(); + + hStereoDft->icbweRefEner_fx = 0; + move32(); + hStereoDft->icbweRefEner_fx_e = 0; + move16(); + hStereoDft->lbEner_fx = 0; + move32(); + hStereoDft->lbEner_fx_e = 0; + move16(); + + IF( chan == 0 ) + { + pDFT_in_fx = hStereoDft->DFT_fx[0]; + DFT_in_fx_e = hStereoDft->DFT_fx_e[0]; + move16(); + } + ELSE + { + pDFT_in_fx = hStereoDft->DFT_fx[1]; + DFT_in_fx_e = hStereoDft->DFT_fx_e[1]; + move16(); + } + + IF( EQ_32( output_sampling_rate, input_Fs ) ) + { + assert( chan == 0 ); + + NFFT = hStereoDft->NFFT; + move16(); + fac_fx = MAX_32; + move32(); + N = hStereoDft->N; + move16(); + ovl = hStereoDft->dft_ovl; + move16(); + zp = hStereoDft->dft_zp; + move16(); + trigo_fx = hStereoDft->dft_trigo_fx; + trigo_step = hStereoDft->dft_trigo_step; + move16(); + IF( L_frame > 0 ) + { + mem_fx = hStereoDft->output_mem_dmx_16k_shb_fx; + } + ELSE + { + mem_fx = hStereoDft->output_mem_dmx_fx; + } + win_fx = hStereoDft->win_fx; + win_ana_fx = hStereoDft->win_ana_fx; + + push_wmops( "DFT_synth_fs" ); + } + ELSE IF( EQ_32( output_sampling_rate, INT_FS_12k8 ) ) + { + assert( chan == 0 ); + + NFFT = STEREO_DFT_N_12k8_ENC; + move16(); + N = STEREO_DFT_HOP_12k8_ENC; + move16(); + zp = STEREO_DFT_ZP_12k8_ENC; + move16(); + // fac = (float) ( NFFT ) / (float) ( hStereoDft->NFFT ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( NFFT, hStereoDft->NFFT, &temp_exp ); + fac_fx = L_shl( fac_fx, temp_exp ); + ovl = STEREO_DFT_OVL_12k8; + move16(); + trigo_fx = hStereoDft->dft_trigo_12k8_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP; + move16(); + mem_fx = hStereoDft->output_mem_dmx_12k8_fx; + win_fx = hStereoDft->win_12k8_fx; + win_ana_fx = hStereoDft->win_ana_12k8_fx; + + push_wmops( "DFT_synth_12k8" ); + } + ELSE IF( EQ_32( output_sampling_rate, 16000 ) ) + { + assert( chan == 0 ); + + NFFT = STEREO_DFT_N_16k_ENC; + move16(); + N = STEREO_DFT_HOP_16k_ENC; + move16(); + zp = STEREO_DFT_ZP_16k_ENC; + move16(); + // fac = (float) ( NFFT ) / (float) ( hStereoDft->NFFT ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( NFFT, hStereoDft->NFFT, &temp_exp ); + fac_fx = L_shl( fac_fx, temp_exp ); + ovl = STEREO_DFT_OVL_16k; + move16(); + trigo_fx = hStereoDft->dft_trigo_16k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + move16(); + IF( L_frame > 0 ) + { + mem_fx = hStereoDft->output_mem_dmx_16k_shb_fx; + + push_wmops( "DFT_synth_16k_shb" ); + } + ELSE + { + mem_fx = hStereoDft->output_mem_dmx_16k_fx; + + push_wmops( "DFT_synth_16k" ); + } + win_fx = hStereoDft->win_16k_fx; + win_ana_fx = hStereoDft->win_ana_16k_fx; + } + ELSE IF( EQ_32( output_sampling_rate, 32000 ) ) + { + assert( chan == 0 ); + + NFFT = STEREO_DFT_N_32k_ENC; + move16(); + N = STEREO_DFT_HOP_32k_ENC; + move16(); + zp = STEREO_DFT_ZP_32k_ENC; + move16(); + // fac = (float) ( NFFT ) / (float) ( hStereoDft->NFFT ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( NFFT, hStereoDft->NFFT, &temp_exp ); + fac_fx = L_shl( fac_fx, temp_exp ); + ovl = STEREO_DFT_OVL_32k; + move16(); + trigo_fx = hStereoDft->dft_trigo_32k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + move16(); + mem_fx = hStereoDft->output_mem_dmx_32k_fx; + win_fx = hStereoDft->win_32k_fx; + win_ana_fx = hStereoDft->win_ana_32k_fx; + + push_wmops( "DFT_synth_32k" ); + } + ELSE IF( EQ_32( output_sampling_rate, 8000 ) ) + { + assert( chan == 1 ); + + NFFT = STEREO_DFT_N_8k_ENC; + move16(); + N = STEREO_DFT_HOP_8k_ENC; + move16(); + zp = STEREO_DFT_ZP_8k_ENC; + move16(); + // fac = (float) ( NFFT ) / (float) ( hStereoDft->NFFT ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( NFFT, hStereoDft->NFFT, &temp_exp ); + fac_fx = L_shl( fac_fx, temp_exp ); + ovl = STEREO_DFT_OVL_8k; + move16(); + trigo_fx = hStereoDft->dft_trigo_8k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP; + move16(); + mem_fx = hStereoDft->output_mem_res_8k_fx; + win_fx = hStereoDft->win_8k_fx; + win_ana_fx = hStereoDft->win_ana_8k_fx; + + push_wmops( "DFT_synth_8k" ); + } + ELSE + { + assert( 0 && "DFT stereo: sampling rate not supported!" ); + NFFT = -1; /* to avoid compilation warning */ + move16(); + fac_fx = -1; /* to avoid compilation warning */ + move32(); + N = -1; /* to avoid compilation warning */ + move16(); + zp = -1; /* to avoid compilation warning */ + move16(); + win_fx = NULL; /* to avoid compilation warning */ + trigo_fx = NULL; /* to avoid compilation warning */ + trigo_step = -1; /* to avoid compilation warning */ + move16(); + ovl = -1; /* to avoid compilation warning */ + move16(); + mem_fx = NULL; /* to avoid compilation warning */ + win_ana_fx = NULL; /* to avoid compilation warning */ + } + + offset = 0; + move16(); + + FOR( i = 0; i < shr( NFFT, 2 ); i++ ) + { + trigo_enc_fx[i] = trigo_fx[imult1616( i, trigo_step )]; + move16(); + trigo_enc_fx[sub( shr( NFFT, 1 ), i )] = trigo_fx[imult1616( i, trigo_step )]; + move16(); + } + trigo_enc_fx[shr( NFFT, 2 )] = trigo_fx[imult1616( shr( NFFT, 2 ), trigo_step )]; + move16(); + + /*-----------------------------------------------------------------* + * Synthesizing & resampling + *-----------------------------------------------------------------*/ + + offset = negate( ovl ); + + test(); + IF( EQ_16( L_frame, L_FRAME ) || EQ_16( L_frame, L_FRAME16k ) ) + { + // for ( i = (int16_t) ( 200 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); i < (int16_t) ( 400 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); i++ ) + FOR( i = 320; i < 640; i++ ) + { + // hStereoDft->icbweRefEner += pDFT_in[2 * i] * pDFT_in[2 * i] + pDFT_in[2 * i + 1] * pDFT_in[2 * i + 1]; + hStereoDft->icbweRefEner_fx = BASOP_Util_Add_Mant32Exp( hStereoDft->icbweRefEner_fx, hStereoDft->icbweRefEner_fx_e, L_add( L_shr( Mpy_32_32( pDFT_in_fx[2 * i], pDFT_in_fx[2 * i] ), 1 ), L_shr( Mpy_32_32( pDFT_in_fx[2 * i + 1], pDFT_in_fx[2 * i + 1] ), 1 ) ), add( shl( DFT_in_fx_e, 1 ), 1 ), &hStereoDft->icbweRefEner_fx_e ); + move32(); + } + // for ( i = 0; i < (int16_t) ( 200 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); i++ ) + FOR( i = 0; i < 320; i++ ) + { + // hStereoDft->lbEner += pDFT_in[2 * i] * pDFT_in[2 * i] + pDFT_in[2 * i + 1] * pDFT_in[2 * i + 1]; + hStereoDft->lbEner_fx = BASOP_Util_Add_Mant32Exp( hStereoDft->lbEner_fx, hStereoDft->lbEner_fx_e, L_add( L_shr( Mpy_32_32( pDFT_in_fx[2 * i], pDFT_in_fx[2 * i] ), 1 ), L_shr( Mpy_32_32( pDFT_in_fx[2 * i + 1], pDFT_in_fx[2 * i + 1] ), 1 ) ), add( shl( DFT_in_fx_e, 1 ), 1 ), &hStereoDft->lbEner_fx_e ); + move32(); + } + hStereoDft->icbweRefEner_fx = Mpy_32_32( hStereoDft->icbweRefEner_fx, fac_fx ); + move32(); + hStereoDft->lbEner_fx = Mpy_32_32( hStereoDft->lbEner_fx, fac_fx ); + move32(); + } + + /*Flip?*/ + set32_fx( tmp_fx, 0, STEREO_DFT_N_MAX_ENC ); + IF( EQ_16( L_frame, L_FRAME ) ) + { + /* 6 to 14 kHz SHB target signal*/ + j = 2; + move16(); + sign = hStereoDft->flip_sign; + move16(); + + // for ( i = (int16_t) ( 350 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); i >= (int16_t) 150 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ); i-- ) + FOR( i = 560; i >= 240; i-- ) + { + /* alternate sign between frames for even starting index */ + tmp_fx[j++] = W_extract_l( W_mult0_32_32( sign, Mpy_32_32( pDFT_in_fx[2 * i], fac_fx ) ) ); + tmp_fx[j++] = W_extract_l( W_mult0_32_32( negate( sign ), Mpy_32_32( pDFT_in_fx[2 * i + 1], fac_fx ) ) ); + move32(); + move32(); + } + scal_fac = sub( L_norm_arr( tmp_fx, STEREO_DFT_N_MAX_ENC ), 1 ); + scale_sig32( tmp_fx, STEREO_DFT_N_MAX_ENC, scal_fac ); // Q16 + DFT_in_fx_e = sub( DFT_in_fx_e, scal_fac ); + + hStereoDft->flip_sign = negate( sign ); + move16(); + + // for ( i = 0; i <= (int16_t) 100 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ); i++ ) + FOR( i = 0; i <= 160; i++ ) + { + nrg_fx = BASOP_Util_Add_Mant32Exp( nrg_fx, nrg_fx_e, Mpy_32_32( tmp_fx[2 * i], tmp_fx[2 * i] ), shl( DFT_in_fx_e, 1 ), &nrg_fx_e ); + nrg_fx = BASOP_Util_Add_Mant32Exp( nrg_fx, nrg_fx_e, Mpy_32_32( tmp_fx[2 * i + 1], tmp_fx[2 * i + 1] ), shl( DFT_in_fx_e, 1 ), &nrg_fx_e ); + } + } + ELSE IF( EQ_16( L_frame, L_FRAME16k ) ) + { + /* 7.5 - 15.5 kHz SHB target signal*/ + j = 2; + move16(); + // for ( i = (int16_t) ( 400 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ) - 1; i >= (int16_t) 200 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ); i-- ) + FOR( i = 640 - 1; i >= 320; i-- ) + { + tmp_fx[j++] = Mpy_32_32( pDFT_in_fx[2 * i], fac_fx ); + tmp_fx[j++] = L_negate( Mpy_32_32( pDFT_in_fx[2 * i + 1], fac_fx ) ); + move32(); + move32(); + } + scal_fac = sub( L_norm_arr( tmp_fx, STEREO_DFT_N_MAX_ENC ), 1 ); + scale_sig32( tmp_fx, STEREO_DFT_N_MAX_ENC, scal_fac ); // Q16 + DFT_in_fx_e = sub( DFT_in_fx_e, scal_fac ); + + // for ( i = 0; i <= (int16_t) 100 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ); i++ ) + FOR( i = 0; i <= 160; i++ ) + { + nrg_fx = BASOP_Util_Add_Mant32Exp( nrg_fx, nrg_fx_e, Mpy_32_32( tmp_fx[2 * i], tmp_fx[2 * i] ), shl( DFT_in_fx_e, 1 ), &nrg_fx_e ); + nrg_fx = BASOP_Util_Add_Mant32Exp( nrg_fx, nrg_fx_e, Mpy_32_32( tmp_fx[2 * i + 1], tmp_fx[2 * i + 1] ), shl( DFT_in_fx_e, 1 ), &nrg_fx_e ); + } + } + ELSE IF( NE_32( fac_fx, MAX_32 ) ) + { + /*Copy and scale*/ + tmp_fx[0] = Mpy_32_32( pDFT_in_fx[0], fac_fx ); + move32(); + tmp_fx[1] = 0; + move32(); + FOR( i = 2; i < NFFT; i++ ) + { + tmp_fx[i] = Mpy_32_32( pDFT_in_fx[i], fac_fx ); + move32(); + } + + IF( LT_32( fac_fx, MAX_32 ) ) + { + tmp_fx[1] = 0; /*Nyquist is set to 0*/ + tmp_fx[0] = 0; /*DC is set to 0*/ + move32(); + move32(); + } + scal_fac = sub( L_norm_arr( tmp_fx, STEREO_DFT_N_MAX_ENC ), 1 ); + scale_sig32( tmp_fx, STEREO_DFT_N_MAX_ENC, scal_fac ); // Q16 + DFT_in_fx_e = sub( DFT_in_fx_e, scal_fac ); + } + ELSE + { + FOR( i = 0; i < NFFT; i++ ) + { + tmp_fx[i] = pDFT_in_fx[i]; + move32(); + } + scal_fac = sub( L_norm_arr( tmp_fx, STEREO_DFT_N_MAX_ENC ), 1 ); + scale_sig32( tmp_fx, STEREO_DFT_N_MAX_ENC, scal_fac ); // Q16 + DFT_in_fx_e = sub( DFT_in_fx_e, scal_fac ); + } + + /*Reconstruct */ + /*IFFT*/ + scal_fac = sub( 1, find_guarded_bits_fx( NFFT ) ); + scale_sig32( tmp_fx, NFFT, scal_fac ); // Q16 + rfft_fx( tmp_fx, trigo_enc_fx, NFFT, +1 ); + Scale_sig32( tmp_fx, NFFT, sub( sub( DFT_in_fx_e, scal_fac ), 15 ) ); // Q16 + + FOR( i = 0; i < ovl; i++ ) + { + // output[offset + i] = mem[i] + tmp[zp + i] * win[i]; + output_fx[offset + i] = L_add_sat( mem_fx[i], Mpy_32_32( tmp_fx[zp + i], win_fx[i] ) ); + move32(); + // mem[i] = tmp[zp + N + i] * win[ovl - 1 - i]; + mem_fx[i] = Mpy_32_32( tmp_fx[zp + N + i], win_fx[ovl - 1 - i] ); + move32(); + } + + /*Middle->Copy*/ + FOR( i = 0; i < N - ovl; i++ ) + { + // output_fx[offset + ovl + i] = tmp[zp + ovl + i]; + output_fx[offset + ovl + i] = tmp_fx[zp + ovl + i]; + move32(); + } + + /*-----------------------------------------------------------------* + * Lookahead: redress signal + *-----------------------------------------------------------------*/ + + FOR( i = 0; i < ovl; i++ ) + { + Word32 ifft_deviation = tmp_fx[zp + N + ovl]; + move32(); + // output[offset + N + i] = ( tmp[zp + N + i] - ifft_deviation ) / win_ana[ovl - 1 - i] + ifft_deviation; + Word16 L_temp_e; + Word32 L_temp = BASOP_Util_Divide3232_Scale_cadence( L_sub_sat( tmp_fx[zp + N + i], ifft_deviation ), win_ana_fx[ovl - 1 - i], &L_temp_e ); + L_temp = L_shl_sat( L_temp, L_temp_e ); + output_fx[offset + N + i] = L_add_sat( L_temp, ifft_deviation ); // Q16 + move32(); + } + + *output_start_index = offset; + move16(); + *output_end_index = add( add( offset, ovl ), N ); + move16(); + IF( nrg_out_fx_e ) + { + *nrg_out_fx_e = nrg_fx_e; + move16(); + } + pop_wmops(); + return ( nrg_fx ); +} +#endif float stereo_dft_enc_synthesize( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ float *output, /* o : output synthesis */ @@ -2963,9 +3435,15 @@ static void side_gain_mode_decision( try_diff = 0; } no_GR_ord = 3; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->side_gain_flag_2 = adapt_GR_ief_fx( hStereoDft->side_gain_index_EC, hStereoDft->side_gain_index_ECDiff, hStereoDft->side_gain_index_ECprevious, + hStereoDft->nbands, NO_SYMB_GR_SIDE_G, &n_bits, encoded_ind_GR, dft_maps_sg, no_GR_ord, &nb_diff, + hStereoDft->side_gain_counter, &hStereoDft->side_gain_bitdiff_lp_fx, &hStereoDft->q_side_gain_bitdiff_lp, try_diff ); +#else hStereoDft->side_gain_flag_2 = adapt_GR_ief( hStereoDft->side_gain_index_EC, hStereoDft->side_gain_index_ECDiff, hStereoDft->side_gain_index_ECprevious, hStereoDft->nbands, NO_SYMB_GR_SIDE_G, &n_bits, encoded_ind_GR, dft_maps_sg, no_GR_ord, &nb_diff, hStereoDft->side_gain_counter, &hStereoDft->side_gain_bitdiff_lp, try_diff ); +#endif for ( i = 0; i < hStereoDft->nbands; i++ ) diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index dc9fdc3019d0549ddf5e6b248d4eb91c66c7171b..aadfd8d58e7a2807b9ad94b13239672a19f27f6e 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -41,8 +41,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*--------------------------------------------------------------- * Local function prototypes diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index d762468aa0c5b295ccd859d929e8aeac8296ba26..f1f8371506d04da2ce573676af2d2340965030e5 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -40,7 +40,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" -#include "prot_fx1.h" +#include "prot_fx.h" /*-------------------------------------------------------------------* * ic_bwe_enc_reset() diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 73081c98aa59022e542a42109485aec16870437b..dd5f2d59fc115cb8bf78f7741acd19fc0d303723 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -36,6 +36,7 @@ #include #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" @@ -121,6 +122,22 @@ void stereo_mdct_core_enc( float pitch_buf[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ ) { +#ifdef IVAS_FLOAT_FIXED + Word32 *p_orig_spectrum_long_fx[CPE_CHANNELS], orig_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* MDCT output (L/R). */ + Word32 *orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; /* Pointers to MDCT output for a short block (L/R) */ + Word32 powerSpec_fx[CPE_CHANNELS][N_MAX]; + Word32 *p_powerSpec_fx[CPE_CHANNELS]; +#ifdef MSAN_FIX /*To be removed later*/ + Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX] = { 0 }; /* MS inv power spectrum, also inverse MDST spectrum */ +#else + Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX]; /* MS inv power spectrum, also inverse MDST spectrum */ +#endif // MSAN_FIX + Word32 *powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; + Word32 quantized_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ + Word32 *quantized_spectrum_fx[CPE_CHANNELS][NB_DIV]; + Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV]; + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV]; +#endif int16_t i, ch, nSubframes, L_subframeTCX; int16_t n, nAvailBits; int16_t tnsSize[CPE_CHANNELS][NB_DIV]; /* number of tns parameters put into prm */ @@ -155,6 +172,10 @@ void stereo_mdct_core_enc( for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef IVAS_FLOAT_FIXED + p_orig_spectrum_long_fx[ch] = orig_spectrum_long_fx[ch]; + UNUSED_PARAM( p_orig_spectrum_long_fx ); +#endif // IVAS_FLOAT_FIXED p_mdst_spectrum_long[ch] = mdst_spectrum_long[ch]; p_orig_spectrum_long[ch] = orig_spectrum_long[ch]; } @@ -213,6 +234,17 @@ void stereo_mdct_core_enc( for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef IVAS_FLOAT_FIXED + orig_spectrum_fx[ch][0] = orig_spectrum_long_fx[ch]; + orig_spectrum_fx[ch][1] = orig_spectrum_long_fx[ch] + N_TCX10_MAX; + inv_mdst_spectrum_fx[ch][0] = powerSpecMsInv_fx[ch][0] = powerSpecMsInv_long_fx[ch]; + inv_mdst_spectrum_fx[ch][1] = powerSpecMsInv_fx[ch][1] = powerSpecMsInv_long_fx[ch] + N_TCX10_MAX; + quantized_spectrum_fx[ch][0] = quantized_spectrum_long_fx[ch]; + quantized_spectrum_fx[ch][1] = quantized_spectrum_long_fx[ch] + N_TCX10_MAX; + inv_spectrum_fx[ch][0] = quantized_spectrum_fx[ch][0]; + inv_spectrum_fx[ch][1] = quantized_spectrum_fx[ch][1]; + UNUSED_PARAM( inv_mdst_spectrum_fx ); +#endif // IVAS_FLOAT_FIXED orig_spectrum[ch][0] = orig_spectrum_long[ch]; orig_spectrum[ch][1] = orig_spectrum_long[ch] + N_TCX10_MAX; quantized_spectrum[ch][0] = quantized_spectrum_long[ch]; @@ -258,7 +290,65 @@ void stereo_mdct_core_enc( if ( !hStereoMdct->isSBAStereoMode ) { +#ifndef IVAS_FLOAT_FIXED stereo_coder_tcx( hStereoMdct, sts, ms_mask, mdst_spectrum, inv_spectrum, inv_mdst_spectrum, 0 ); +#else +#if 1 + Word16 k; + Word16 q_spec = Q31; + Word16 length; + Word32 *mdst_spectrum_fx[2][2]; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + length = sts[ch]->hTcxEnc->L_frameTCX / ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + IF( sts[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + mdst_spectrum_fx[ch][k] = (Word32 *) malloc( sizeof( Word32 ) * length ); + q_spec = s_min( q_spec, Q_factor_arrL( sts[ch]->hTcxEnc->spectrum[k], length ) - 1 ); + q_spec = s_min( q_spec, Q_factor_arrL( mdst_spectrum[ch][k], length ) - 1 ); + } + } + + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + length = sts[ch]->hTcxEnc->L_frameTCX / ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + IF( sts[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + floatToFixed_arrL32( sts[ch]->hTcxEnc->spectrum[k], sts[ch]->hTcxEnc->spectrum_fx[k], q_spec, length ); + sts[ch]->hTcxEnc->spectrum_e[k] = sub( Q31, q_spec ); + floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_spec, length ); + } + } + +#endif + stereo_coder_tcx_fx( hStereoMdct, sts, ms_mask, mdst_spectrum_fx, inv_spectrum_fx, inv_mdst_spectrum_fx, 0, q_spec ); +#if 1 + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + length = sts[ch]->hTcxEnc->L_frameTCX / ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + IF( sts[ch]->last_core == ACELP_CORE ) + { + length += length / 4; + } + FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + { + fixedToFloat_arrL32( sts[ch]->hTcxEnc->spectrum_fx[k], sts[ch]->hTcxEnc->spectrum[k], q_spec, length ); + fixedToFloat_arrL32( inv_spectrum_fx[ch][k], inv_spectrum[ch][k], q_spec, length ); + fixedToFloat_arrL32( inv_mdst_spectrum_fx[ch][k], inv_mdst_spectrum[ch][k], q_spec, length ); + fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_spec, length ); + free( mdst_spectrum_fx[ch][k] ); + } + } +#endif +#endif } /*--------------------------------------------------------------* @@ -352,7 +442,13 @@ void stereo_mdct_core_enc( { p_powerSpec[0] = powerSpec[0]; p_powerSpec[1] = powerSpec[1]; +#ifdef IVAS_FLOAT_FIXED + p_powerSpec_fx[0] = powerSpec_fx[0]; + p_powerSpec_fx[1] = powerSpec_fx[1]; + ProcessStereoIGF_fx( hStereoMdct, sts, ms_mask, orig_spectrum_fx, p_powerSpec_fx, powerSpecMsInv_fx, inv_spectrum_fx, orig_spectrum, p_powerSpec, powerSpecMsInv, inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 ); +#else ProcessStereoIGF( hStereoMdct, sts, ms_mask, orig_spectrum, p_powerSpec, powerSpecMsInv, inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 ); +#endif // IVAS_FLOAT_FIXED } else { @@ -404,6 +500,10 @@ void stereo_mdct_core_enc( sts[0]->side_bits_frame_channel -= SMDCT_NBBITS_SPLIT_RATIO; if ( !hStereoMdct->isSBAStereoMode ) { +#ifdef IVAS_FLOAT_FIXED + IF( hStereoMdct->hItd ) + hStereoMdct->hItd->itd_fx[1] = float_to_fix( hStereoMdct->hItd->itd[1], Q23 ); +#endif stereo_bits = write_stereo_to_bitstream( hStereoMdct, sts, ms_mask, 0, hBstr ); } else @@ -415,7 +515,25 @@ void stereo_mdct_core_enc( * Split available bits between channels *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED FindSplitRatio( hCPE, sts ); +#else +#if 1 + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + L_subframeTCX = sts[ch]->hTcxEnc->L_frameTCX / ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + IF( sts[ch]->last_core == ACELP_CORE ) + { + L_subframeTCX += L_subframeTCX / 4; + } + FOR( n = 0; n <= ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ) - 1; n++ ) + { + f2me_buf( sts[ch]->hTcxEnc->spectrum[n], sts[ch]->hTcxEnc->spectrum_fx[n], &sts[ch]->hTcxEnc->spectrum_e[n], L_subframeTCX ); + } + } +#endif + FindSplitRatio_fx( hCPE, sts ); +#endif assert( hStereoMdct->split_ratio > 0 && hStereoMdct->split_ratio < SMDCT_BITRATE_RATIO_RANGE ); diff --git a/lib_enc/ivas_stereo_mdct_igf_enc.c b/lib_enc/ivas_stereo_mdct_igf_enc.c index d56e3d34dfcf8720f50316e651811acb8064e421..51862db720205e511b5cac1e7d3ecab845fe449c 100644 --- a/lib_enc/ivas_stereo_mdct_igf_enc.c +++ b/lib_enc/ivas_stereo_mdct_igf_enc.c @@ -35,21 +35,26 @@ #include "options.h" #include #include "prot.h" +#include "prot_fx.h" #include "cnst.h" #include "stat_enc.h" #include "ivas_stat_enc.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "wmc_auto.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define IGF_PATCH_MS 1 -#define IGF_PATCH_LR 0 -#define TARGET_COH_THRESHOLD 0.6f -#define SOURCE_COH_THRESHOLD 0.7f -#define PANNING_THRESHOLD 0.07f +#define IGF_PATCH_MS 1 +#define IGF_PATCH_LR 0 +#define TARGET_COH_THRESHOLD 0.6f +#define TARGET_COH_THRESHOLD_FX 19661 +#define SOURCE_COH_THRESHOLD 0.7f +#define SOURCE_COH_THRESHOLD_FX 22938 +#define PANNING_THRESHOLD 0.07f +#define PANNING_THRESHOLD_FX 2294 /*-------------------------------------------------------------------* @@ -58,6 +63,7 @@ * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static float calcCoh( const float *sig1, const float *sig2, @@ -94,6 +100,68 @@ static float calcCoh( return coh; } +#else +static Word16 calcCoh_fx( // Q15 + const Word32 *sig1_fx, // Q( q_sig ) + const Word32 *sig2_fx, // Q( q_sig ) + const Word16 q_sig, + const Word16 nSamples, + Word32 *corr, + Word16 *corr_e, + Word16 *predCoeff, + Word16 *predCoeff_e ) +{ + Word32 ener1_fx, ener2_fx, cEner_fx, cc_fx; + Word16 coh_fx, coh_e; + Word16 q_ener1, q_ener2, q_cEner, q_cc; + + coh_fx = 0; + move16(); + Word16 gB = find_guarded_bits_fx( nSamples ); + q_ener1 = shl( q_sig, 1 ); + q_ener2 = q_ener1; + move16(); + q_cc = q_ener1; + move16(); + ener1_fx = dotp_fixed_o( sig1_fx, sig1_fx, nSamples, gB, &q_ener1 ); + ener2_fx = dotp_fixed_o( sig2_fx, sig2_fx, nSamples, gB, &q_ener2 ); + cEner_fx = Mpy_32_32( ener1_fx, ener2_fx ); + q_cEner = sub( 62, add( q_ener1, q_ener2 ) ); + cEner_fx = Sqrt32( cEner_fx, &q_cEner ); + q_cEner = sub( Q31, q_cEner ); + cc_fx = dotp_fixed_o( sig1_fx, sig2_fx, nSamples, gB, &q_cc ); + + IF( corr != NULL ) + { + *corr = cc_fx; + *corr_e = sub( Q31, q_cc ); + move16(); + move32(); + } + + IF( cEner_fx > 0 ) + { + coh_fx = BASOP_Util_Divide3232_Scale( cc_fx, cEner_fx, &coh_e ); + coh_e = add( coh_e, sub( q_cEner, q_cc ) ); + coh_fx = shl_sat( coh_fx, coh_e ); // Q15 + } + + IF( predCoeff != NULL ) + { + *predCoeff = 0; + move32(); + IF( ener1_fx > 0 ) + { + *predCoeff = BASOP_Util_Divide3232_Scale( cc_fx, ener1_fx, predCoeff_e ); + move32(); + *predCoeff_e = add( *predCoeff_e, sub( q_ener1, q_cc ) ); + move16(); + } + } + + return coh_fx; +} +#endif /*-------------------------------------------------------------------* @@ -102,6 +170,7 @@ static float calcCoh( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void IGF_MsStereoDecision( STEREO_MDCT_BAND_PARAMETERS *sfbParam, H_IGF_GRID hGrid, @@ -226,6 +295,164 @@ static void IGF_MsStereoDecision( return; } +#else +static void IGF_MsStereoDecision_fx( + STEREO_MDCT_BAND_PARAMETERS *sfbParam, + H_IGF_GRID hGrid, + const Word32 *specL_fx, + const Word32 *specR_fx, + Word16 q_spec, + Word16 *igfStereoMode, /* output*/ + Word16 *msMask, /* output*/ + const Word16 mdct_stereo_mode ) +{ + Word16 sfb; + Word16 msMaskTrueSomewhere, msMaskFalseSomewhere; + Word16 numMsMaskTrue, numMsMaskFalse, numMsMaskThresh, numMsMaskMSForLR; + Word16 tile_idx; + Word16 strt_cpy; + Word16 thresh; + + thresh = TARGET_COH_THRESHOLD_FX; + move16(); + + if ( EQ_16( mdct_stereo_mode, SMDCT_MS_FULL ) ) + { + thresh = 13762; /* lower threshold if core is already MS */ + move16(); + } + + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) + { + strt_cpy = hGrid->sbWrap[tile_idx]; + move16(); + + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) + { + Word16 width = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); + Word32 cc_src_fx, cc_target_fx; + Word16 cc_src_e, cc_target_e; + Word16 pc_target_fx, pc_src_fx; + Word16 pc_target_e, pc_src_e; + Word16 tmp1, tmp1_e, tmp2, tmp2_e; + + Word16 coh_src = calcCoh_fx( &specL_fx[strt_cpy], &specR_fx[strt_cpy], q_spec, width, &cc_src_fx, &cc_src_e, &pc_src_fx, &pc_src_e ); + Word16 coh_target = calcCoh_fx( &specL_fx[hGrid->swb_offset[sfb]], &specR_fx[hGrid->swb_offset[sfb]], q_spec, width, &cc_target_fx, &cc_target_e, &pc_target_fx, &pc_target_e ); + tmp1_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, negate( pc_src_fx ), pc_src_e, &tmp1 ); + tmp2_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, -16384, 1, &tmp2 ); + + strt_cpy = add( strt_cpy, width ); + IF( GT_16( abs_s( coh_target ), thresh ) ) + { + /* target is very coherent */ + IF( GT_16( abs_s( coh_src ), SOURCE_COH_THRESHOLD_FX ) ) + { + test(); + IF( LT_16( abs_s( shl_sat( tmp1, tmp1_e ) ), PANNING_THRESHOLD_FX ) && GT_16( abs_s( shl_sat( tmp2, tmp2_e ) ), 2 * PANNING_THRESHOLD_FX ) ) /* same position but not close to the MID */ + { + /* same for the source, stereo pos are close, stay on LR */ + msMask[sfb] = IGF_PATCH_LR; + move16(); + } + ELSE + { + msMask[sfb] = IGF_PATCH_MS; + move16(); + } + } + ELSE + { + /* we need to get the coherent patch, do MS */ + msMask[sfb] = IGF_PATCH_MS; + move16(); + } + } + ELSE + { + /* target is not coherent, stick to LR patching */ + msMask[sfb] = IGF_PATCH_LR; + move16(); + } + } + } + + msMaskTrueSomewhere = 0; + move16(); + msMaskFalseSomewhere = 0; + move16(); + numMsMaskTrue = 0; + move16(); + numMsMaskFalse = 0; + move16(); + numMsMaskThresh = shr( sub( sfbParam->sfbCnt, sfbParam->nBandsStereoCore ), 2 ); + numMsMaskMSForLR = 0; + move16(); + + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) + { + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) + { + SWITCH( msMask[sfb] ) + { + case IGF_PATCH_LR: + msMask[sfb] = 0; + move16(); + numMsMaskFalse = add( numMsMaskFalse, 1 ); + msMaskFalseSomewhere = 1; + move16(); + break; + case IGF_PATCH_MS: + msMask[sfb] = 1; + move16(); + numMsMaskTrue = add( numMsMaskTrue, 1 ); + msMaskTrueSomewhere = 1; + move16(); + break; + default: + assert( 0 ); + break; + } + } + } + + IF( msMaskTrueSomewhere ) + { + IF( msMaskFalseSomewhere ) + { + *igfStereoMode = SMDCT_BW_MS; + move16(); + + test(); + IF( LE_16( numMsMaskFalse, numMsMaskThresh ) ) + { + *igfStereoMode = SMDCT_MS_FULL; + move16(); + set_s( &msMask[0], 1, sub( sfbParam->sfbCnt, sfbParam->nBandsStereoCore ) ); + } + ELSE IF( LE_16( numMsMaskTrue, numMsMaskThresh ) && !numMsMaskMSForLR ) + { + *igfStereoMode = SMDCT_DUAL_MONO; + move16(); + set_s( &msMask[0], 0, sub( sfbParam->sfbCnt, sfbParam->nBandsStereoCore ) ); + } + } + ELSE + { + *igfStereoMode = SMDCT_MS_FULL; + move16(); + set_s( &msMask[0], 1, sub( sfbParam->sfbCnt, sfbParam->nBandsStereoCore ) ); + } + } + ELSE + { + *igfStereoMode = SMDCT_DUAL_MONO; + move16(); + set_s( &msMask[0], 0, sub( sfbParam->sfbCnt, sfbParam->nBandsStereoCore ) ); + } + + return; +} +#endif /*-------------------------------------------------------------------* @@ -234,6 +461,7 @@ static void IGF_MsStereoDecision( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void IGFEncStereoEncoder( STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */ const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */ @@ -269,3 +497,43 @@ void IGFEncStereoEncoder( return; } +#else +void IGFEncStereoEncoder_fx( + STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */ + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */ + const Word32 *mdctSpectrumL_fx, /* i : left spectrum */ + const Word32 *mdctSpectrumR_fx, /* i : right spectrum */ + Word16 q_mdctSpectrum, + Word16 *msMask, /* i/o: MS mask */ + Word16 *igfStereoMode, /* o : IGF stereo mode */ + const Word16 mdct_stereo_mode, /* i : MDCT stereo mode */ + const Word16 isTCX20, /* i : flag for indicating TCX20 */ + const Word16 isTransition /* i : flag for transtition */ +) +{ + Word16 igfGridIdx; + H_IGF_GRID hGrid; + + IF( isTransition && isTCX20 ) + { + igfGridIdx = IGF_GRID_LB_TRAN; + move16(); + } + ELSE IF( isTCX20 ) + { + igfGridIdx = IGF_GRID_LB_NORM; + move16(); + } + ELSE + { + /* It is short block */ + igfGridIdx = IGF_GRID_LB_SHORT; + move16(); + } + + hGrid = &hIGFEnc->igfData.igfInfo.grid[igfGridIdx]; + IGF_MsStereoDecision_fx( sfbParam, hGrid, mdctSpectrumL_fx, mdctSpectrumR_fx, q_mdctSpectrum, igfStereoMode, msMask + sfbParam->nBandsStereoCore, mdct_stereo_mode ); + + return; +} +#endif diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 1c6aa5e8668ba512a53de31d1ed4becf76fa5222..5019512ebd2aae6c472f993f128f436cc85f47bc 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -37,8 +37,9 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" +#include "prot_fx.h" #include "prot.h" -#include "prot_fx1.h" +#include "prot_fx_enc.h" #include "ivas_rom_com.h" #include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" @@ -58,13 +59,29 @@ * Local function prototypes *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void convertToBwMS( const int16_t startLine, const int16_t stopLine, float x0[], float x1[], const float norm_fac ); +#else +static void convertToBwMS_fx( const Word16 startLine, const Word16 stopLine, Word32 x0[], Word32 x1[], const Word32 norm_fac ); +#endif +#ifndef IVAS_FLOAT_FIXED void convertToMS( const int16_t L_frame, float x0[], float x1[], const float norm_fac ); +#else +void convertToMS_fx( const Word16 L_frame, Word32 x0_fx[], Word32 x1_fx[], const Word32 norm_fac ); +#endif +#ifndef IVAS_FLOAT_FIXED static float GetChannelEnergyRatio( Encoder_State **st, const int16_t iFirstSubframe, const int16_t iLastSubframe, const uint8_t ratioInRmsDomain ); +#else +static Word16 GetChannelEnergyRatio_fx( Encoder_State **st, const Word16 iFirstSubframe, const Word16 iLastSubframe, const UWord8 ratioInRmsDomain ); +#endif +#ifndef IVAS_FLOAT_FIXED static void MsStereoDecision( STEREO_MDCT_BAND_PARAMETERS *sfbParam, float *specL, float *specR, float *specM, float *specS, int16_t *mdct_stereo_mode, int16_t *msMask, const int16_t nBitsAvailable ); +#else +static void MsStereoDecision_fx( STEREO_MDCT_BAND_PARAMETERS *sfbParam, Word32 *specL_fx, Word32 *specR_fx, Word32 *specM_fx, Word32 *specS_fx, Word16 q_spec, Word16 *mdct_stereo_mode, Word16 *msMask, const Word16 nBitsAvailable ); +#endif /*-------------------------------------------------------------------* @@ -74,6 +91,7 @@ static void MsStereoDecision( STEREO_MDCT_BAND_PARAMETERS *sfbParam, float *spec * MDCT-stereo *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void dft_ana_init( DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ const int32_t input_Fs /*i : Input sampling frequency */ @@ -108,20 +126,16 @@ static void dft_ana_init( return; } - -static void dft_ana_init_fx( +#else +static void dft_ana_init( DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ const Word32 input_Fs /*i : Input sampling frequency */ ) { - Word16 div1; - /* input_Fs / 48000 */ - div1 = extract_l( Mpy_32_32_r( input_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - - hDft_ana->N = i_mult( STEREO_DFT_HOP_MAX_ENC, div1 ); - hDft_ana->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, div1 ); - hDft_ana->dft_ovl = i_mult( STEREO_DFT_OVL_MAX, div1 ); - hDft_ana->dft_zp = i_mult( STEREO_DFT_ZP_MAX_ENC, div1 ); + hDft_ana->N = extract_l( Mpy_32_16_1( input_Fs, 656 ) ); + hDft_ana->NFFT = extract_l( Mpy_32_16_1( input_Fs, 1311 ) ); + hDft_ana->dft_ovl = extract_l( Mpy_32_16_1( input_Fs, 287 ) ); + hDft_ana->dft_zp = extract_l( Mpy_32_16_1( input_Fs, 185 ) ); hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; @@ -139,14 +153,34 @@ static void dft_ana_init_fx( } ELSE { - assert( EQ_32( input_Fs, 48000 ) ); + assert( input_Fs == 48000 ); hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; hDft_ana->win_ana_fx = win_ana_48k_fx; } +#if 1 // TODO: To be removed later + hDft_ana->dft_trigo_32k = dft_trigo_32k; + if ( input_Fs == 16000 ) + { + hDft_ana->dft_trigo = dft_trigo_32k; + hDft_ana->win_ana = win_ana_16k; + } + else if ( input_Fs == 32000 ) + { + hDft_ana->dft_trigo = dft_trigo_32k; + hDft_ana->win_ana = win_ana_32k; + } + else + { + hDft_ana->dft_trigo = dft_trigo_48k; + hDft_ana->win_ana = win_ana_48k; + } +#endif + return; } +#endif /*-------------------------------------------------------------------* * write_itd_data() @@ -154,6 +188,7 @@ static void dft_ana_init_fx( * Bitstream writing of ITDs *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void write_itd_data( ITD_DATA_HANDLE hItd, /* i : ITD data handle */ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ @@ -203,7 +238,58 @@ static void write_itd_data( } return; } +#else +static void write_itd_data_fx( + ITD_DATA_HANDLE hItd, /* i : ITD data handle */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +{ + Word16 k_offset; + Word16 itd; + k_offset = 1; + move16(); + + push_next_indice( hBstr, ( hItd->itd[k_offset] != 0 ), STEREO_DFT_ITD_MODE_NBITS ); + + IF( hItd->itd_fx[k_offset] != 0 ) + { + itd = hItd->itd_index[k_offset]; + IF( GT_16( itd, 255 ) ) + { + itd = sub( itd, 256 ); + + IF( LT_16( itd, 20 ) ) + { + push_next_indice( hBstr, 1, 1 ); /* use Huffman*/ + push_next_indice( hBstr, 1, 1 ); /* negative */ + push_next_indice( hBstr, dft_code_itd[itd], dft_len_itd[itd] ); + } + ELSE + { + push_next_indice( hBstr, 0, 1 ); /* don't use Huffman */ + push_next_indice( hBstr, 1, 1 ); /* negative */ + push_next_indice( hBstr, itd, STEREO_DFT_ITD_NBITS - 1 ); + } + } + ELSE + { + IF( LT_16( itd, 20 ) ) + { + push_next_indice( hBstr, 1, 1 ); /* use Huffman*/ + push_next_indice( hBstr, 0, 1 ); /* positive */ + push_next_indice( hBstr, dft_code_itd[itd], dft_len_itd[itd] ); + } + ELSE + { + /* don't use Huffman and positive*/ + push_next_indice( hBstr, itd, STEREO_DFT_ITD_NBITS + 1 ); + } + } + } + return; +} +#endif /*-------------------------------------------------------------------* * stereo_coder_tcx() @@ -211,6 +297,7 @@ static void write_itd_data( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_coder_tcx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: encoder state structure */ @@ -418,7 +505,333 @@ void stereo_coder_tcx( return; } +#else +void stereo_coder_tcx_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], + /* i/o: MDST spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], + /* i/o: inverse spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) + Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], + /* i/o: inverse MDST spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ + Word16 q_spec ) +{ + STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; + Word32 nrgRatio_fx[CPE_CHANNELS]; + Word16 nrgRatio_e[CPE_CHANNELS]; + Word16 nonQNrgRatio_fx[CPE_CHANNELS]; // Q15 + Word16 k; + Word16 nSubframes, L_frameTCX; + Word16 nAvailBitsMS[NB_DIV]; + Word16 tmp, e_tmp; + push_wmops( "stereo_coder_tcx" ); + + set16_fx( nAvailBitsMS, 0, NB_DIV ); + + nSubframes = ( sts[0]->core == TCX_20_CORE && sts[1]->core == TCX_20_CORE ) ? 1 : NB_DIV; + L_frameTCX = sts[0]->hTcxEnc->L_frameTCX / nSubframes; + + set16_fx( &ms_mask[0][0], 0, MAX_SFB ); + set16_fx( &ms_mask[1][0], 0, MAX_SFB ); + + IF( !mct_on ) + { + IF( EQ_16( sts[0]->core, sts[1]->core ) ) + { + FOR( k = 0; k < nSubframes; k++ ) + { + nonQNrgRatio_fx[k] = GetChannelEnergyRatio_fx( sts, k, k, 1 ); // Q15 + move16(); + + hStereoMdct->global_ild[k] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, round_fx( L_mult( SMDCT_ILD_RANGE, nonQNrgRatio_fx[k] ) ) ) ); + move16(); + nrgRatio_fx[k] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[k] ), hStereoMdct->global_ild[k], &nrgRatio_e[k] ) ); + move32(); + /*nonQNrgRatio[k] = max( 0.5f / SMDCT_ILD_RANGE, min( ( SMDCT_ILD_RANGE - 0.5f ) / SMDCT_ILD_RANGE, nonQNrgRatio[k] ) ); + nonQNrgRatio[k] = 1.0f / nonQNrgRatio[k] - 1.0f;*/ + // Not getting used further + } + } + ELSE + { + nonQNrgRatio_fx[0] = nonQNrgRatio_fx[1] = GetChannelEnergyRatio_fx( sts, 0, nSubframes - 1, 1 ); + move16(); + hStereoMdct->global_ild[0] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, round_fx( L_mult( SMDCT_ILD_RANGE, nonQNrgRatio_fx[0] ) ) ) ); + move16(); + nrgRatio_fx[0] = nrgRatio_fx[1] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[0] ), hStereoMdct->global_ild[0], &nrgRatio_e[0] ) ); /* nrgRatio = nrg[1]/nrg[0] */ + move32(); + nrgRatio_e[1] = nrgRatio_e[0]; + move16(); + /*nonQNrgRatio[0] = nonQNrgRatio[1] = max( 0.5f / SMDCT_ILD_RANGE, min( ( SMDCT_ILD_RANGE - 0.5f ) / SMDCT_ILD_RANGE, nonQNrgRatio[0] ) ); + nonQNrgRatio[0] = nonQNrgRatio[1] = 1.0f / nonQNrgRatio[0] - 1.0f;*/ + // Not getting used further + } + + FOR( k = 0; k < nSubframes; k++ ) + { + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[k], nrgRatio_e[k], ONE_IN_Q27, 4 ), 1 ) && LT_16( k, ( EQ_16( sts[1]->core, TCX_20_CORE ) ? 1 : NB_DIV ) ) ) + { + L_frameTCX = add( sts[1]->hTcxEnc->L_frameTCX, ( ( sts[1]->last_core == 0 ) ? shr( sts[1]->hTcxEnc->L_frameTCX, 2 ) : 0 ) ); + L_frameTCX = idiv1616( L_frameTCX, ( sts[1]->core == TCX_20_CORE ) ? 1 : NB_DIV ); + + e_tmp = nrgRatio_e[k]; + tmp = Inv16( extract_h( nrgRatio_fx[k] ), &e_tmp ); + tmp = shl( tmp, e_tmp ); + + v_multc_fixed_16( sts[1]->hTcxEnc->spectrum_fx[k], tmp, sts[1]->hTcxEnc->spectrum_fx[k], L_frameTCX ); + v_multc_fixed_16( mdst_spectrum_fx[1][k], tmp, mdst_spectrum_fx[1][k], L_frameTCX ); + } + ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[k], nrgRatio_e[k], ONE_IN_Q27, 4 ), -1 ) && LT_16( k, EQ_16( sts[0]->core, TCX_20_CORE ) ? 1 : NB_DIV ) ) + { + L_frameTCX = add( sts[0]->hTcxEnc->L_frameTCX, EQ_16( sts[0]->last_core, 0 ) ? shr( sts[0]->hTcxEnc->L_frameTCX, 2 ) : 0 ); + L_frameTCX = idiv1616( L_frameTCX, ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV ); + + /* This operation is resulting in some high MLDs in fixed point. */ + v_multc_fixed_16( sts[0]->hTcxEnc->spectrum_fx[k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), sts[0]->hTcxEnc->spectrum_fx[k], L_frameTCX ); + v_multc_fixed_16( mdst_spectrum_fx[0][k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), mdst_spectrum_fx[0][k], L_frameTCX ); + } + } + } + + IF( + ( NE_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) ) || NE_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) || ( NE_16( sts[0]->last_core, sts[1]->last_core ) && ( EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) ) || EQ_16( sts[0]->last_core, ACELP_CORE ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ) + { + hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; + move16(); + hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + move16(); + + + IF( sts[0]->igf ) + { + hStereoMdct->IGFStereoMode[0] = SMDCT_DUAL_MONO; + move16(); + hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; + move16(); + } + hStereoMdct->sw_uncorr = 1; + move16(); + + pop_wmops(); + return; + } + ELSE /* decide based on signal */ + { + FOR( k = 0; k < nSubframes; k++ ) + { + IF( EQ_16( sts[0]->core, TCX_20_CORE ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20; + } + ELSE + { + sfbConf = &hStereoMdct->stbParamsTCX10; + } + IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; + } + + IF( LT_32( sts[0]->element_brate, IVAS_80k ) && EQ_16( sts[0]->core, sts[1]->core ) && !mct_on ) /* band-wise HF ILD alignment to increase channel compaction */ + { + Word16 sfb = 1; + move16(); + + test(); + WHILE( LT_16( sfb, sfbConf->nBandsStereoCore ) && LT_16( sub( sfbConf->sfbOffset[sfb + 1], sfbConf->sfbOffset[sfb] ), 12 ) ) + { + test(); + sfb = add( sfb, 1 ); /* find start offset */ + } + + FOR( sfb--; sfb < sfbConf->nBandsStereoCore; sfb++ ) /* start one SFB early for the fade-in */ + { + const Word16 startLine = sfbConf->sfbOffset[sfb]; + move16(); + const Word16 endLine = sfbConf->sfbOffset[sfb + 1]; + move16(); + const Word16 sfbWidth = sub( endLine, startLine ); + + nrgRatio_e[0] = nrgRatio_e[1] = sub( Q31, q_spec ); + move16(); + move16(); + + nrgRatio_fx[0] = sum2_32_fx( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[0] ); + move32(); + nrgRatio_fx[1] = sum2_32_fx( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[1] ); + move32(); + + test(); + IF( !sts[0]->hTcxEnc->fUseTns[k] && !sts[1]->hTcxEnc->fUseTns[k] ) /* no TNS in either ch */ + { + Word32 tmp_fx; + Word16 tmp_e; + tmp_e = sub( Q31, q_spec ); + tmp_fx = sum2_32_fx( &mdst_spectrum_fx[0][k][startLine], sfbWidth, &tmp_e ); + nrgRatio_fx[0] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], tmp_fx, tmp_e, &nrgRatio_e[0] ); + tmp_e = sub( Q31, q_spec ); + tmp_fx = sum2_32_fx( &mdst_spectrum_fx[1][k][startLine], sfbWidth, &tmp_e ); + nrgRatio_fx[1] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[1], nrgRatio_e[1], tmp_fx, tmp_e, &nrgRatio_e[1] ); + } + IF( ( nrgRatio_fx[0] > 0 ) && ( nrgRatio_fx[1] > 0 ) && BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], nrgRatio_fx[1], nrgRatio_e[1] ) ) + { + Word16 fTemp_e, tmp_e; + Word32 fTemp_fx = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], nrgRatio_fx[1], nrgRatio_e[1], &fTemp_e ); + fTemp_e = sub( fTemp_e, 1 ); + nrgRatio_fx[0] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[0], &tmp_e ); + move32(); + nrgRatio_e[0] = add( tmp_e, sub( fTemp_e, nrgRatio_e[0] ) ); + move16(); + nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); + move32(); + + nrgRatio_fx[1] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[1], &tmp_e ); + move32(); + nrgRatio_e[1] = add( tmp_e, sub( fTemp_e, nrgRatio_e[1] ) ); + move16(); + nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); + move32(); + + nrgRatio_fx[0] = L_max( ONE_IN_Q27, L_shl_sat( nrgRatio_fx[0], sub( nrgRatio_e[0], 2 ) ) ); // max( 0.25f, min( 4.f, nrgRatio[0] ) ); + move32(); + nrgRatio_fx[1] = L_max( ONE_IN_Q27, L_shl_sat( nrgRatio_fx[1], sub( nrgRatio_e[1], 2 ) ) ); // Q29 + move32(); + nrgRatio_e[0] = Q2; + move16(); + nrgRatio_e[1] = Q2; + move16(); + + IF( ( LT_16( sfbWidth, 12 ) && LT_16( add( sfb, 1 ), sfbConf->nBandsStereoCore ) ) || GT_32( sts[0]->element_brate, IVAS_48k ) ) /* attenuate ILD alignment in the first SFB or at 64k */ + { + nrgRatio_fx[0] = BASOP_Util_fPow( nrgRatio_fx[0], nrgRatio_e[0], ONE_IN_Q29, 0, &nrgRatio_e[0] ); + move32(); + nrgRatio_fx[1] = BASOP_Util_fPow( nrgRatio_fx[1], nrgRatio_e[1], ONE_IN_Q29, 0, &nrgRatio_e[1] ); + move32(); + } + ELSE + { + nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); + move32(); + nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); + move32(); + } + + nrgRatio_fx[0] = L_shl( nrgRatio_fx[0], sub( nrgRatio_e[0], 1 ) ); // Q30 + move32(); + nrgRatio_fx[1] = L_shl( nrgRatio_fx[1], sub( nrgRatio_e[1], 1 ) ); // Q30 + move32(); + + + v_multc_fixed( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[0], &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); + v_multc_fixed( &mdst_spectrum_fx[0][k][startLine], nrgRatio_fx[0], &mdst_spectrum_fx[0][k][startLine], sfbWidth ); + scale_sig32( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + scale_sig32( &mdst_spectrum_fx[0][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + + v_multc_fixed( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[1], &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); + v_multc_fixed( &mdst_spectrum_fx[1][k][startLine], nrgRatio_fx[1], &mdst_spectrum_fx[1][k][startLine], sfbWidth ); + scale_sig32( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + scale_sig32( &mdst_spectrum_fx[1][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + } + } + } + + /* set mask to zero */ + set16_fx( &ms_mask[k][0], 0, MAX_SFB ); + IF( mct_on ) + { + nAvailBitsMS[k] = shl( sts[0]->bits_frame_channel, 1 ); + move16(); + } + ELSE + { + nAvailBitsMS[k] = sts[0]->bits_frame_nominal; + move16(); + } + + nAvailBitsMS[k] = sub( nAvailBitsMS[k], add( sts[0]->side_bits_frame_channel, sts[1]->side_bits_frame_channel ) ); + move16(); + + IF( EQ_16( nSubframes, 2 ) ) + { + nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX10 ); + move16(); + } + ELSE + { + nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX20 ); + move16(); + } + + nAvailBitsMS[k] = idiv1616( nAvailBitsMS[k], nSubframes ); + move16(); + + MsStereoDecision_fx( sfbConf, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], inv_spectrum_fx[0][k], inv_spectrum_fx[1][k], q_spec, &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); + + IF( sts[0]->igf ) + { + IGFEncStereoEncoder_fx( sfbConf, sts[0]->hIGFEnc, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], q_spec, &ms_mask[k][0], + &hStereoMdct->IGFStereoMode[k], hStereoMdct->mdct_stereo_mode[k], (Word16) EQ_16( sts[0]->core, TCX_20_CORE ), (Word16) EQ_16( sts[0]->last_core, ACELP_CORE ) ); + } + ELSE + { + hStereoMdct->IGFStereoMode[k] = hStereoMdct->mdct_stereo_mode[k]; + move16(); + } + + + IF( NE_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_DUAL_MONO ) || NE_16( hStereoMdct->IGFStereoMode[k], SMDCT_DUAL_MONO ) ) + { + + ms_inv_mask_processing_fx( hStereoMdct, sts, ms_mask, k, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], inv_spectrum_fx[0][k], inv_spectrum_fx[1][k], sfbConf->sfbCnt ); + + ms_processing_fx( hStereoMdct, sts, ms_mask, k, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], sfbConf->sfbCnt ); + + IF( !sts[0]->hTcxEnc->fUseTns[k] && !sts[1]->hTcxEnc->fUseTns[k] ) + { + sts[0]->hTcxEnc->tns_ms_flag[k] = 1; + move16(); + sts[1]->hTcxEnc->tns_ms_flag[k] = 1; + move16(); + ms_inv_mask_processing_fx( hStereoMdct, sts, ms_mask, k, mdst_spectrum_fx[0][k], mdst_spectrum_fx[1][k], inv_mdst_spectrum_fx[0][k], inv_mdst_spectrum_fx[1][k], -1 ); + + ms_processing_fx( hStereoMdct, sts, ms_mask, k, mdst_spectrum_fx[0][k], mdst_spectrum_fx[1][k], sfbConf->sfbCnt ); + } + } + } /* for k */ + } + /* for bitrate switching determine correlation depending on m/s decision */ + { + Word16 ms_bands[2]; + Word16 sw_uncorr[2], sw_uncorr_mean; + FOR( k = 0; k < nSubframes; k++ ) + { + sfbConf = EQ_16( sts[0]->core, TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + ms_bands[k] = sum_s( ms_mask[k], sfbConf->nBandsStereoCore ); + move16(); + sw_uncorr[k] = sub( 32767, div_s( ms_bands[k], sfbConf->nBandsStereoCore ) ); + move16(); + } + IF( EQ_16( sts[0]->core, TCX_20_CORE ) ) + { + sw_uncorr_mean = sw_uncorr[0]; + move16(); + } + ELSE + { + sw_uncorr_mean = add( shr( sw_uncorr[0], 1 ), shr( sw_uncorr[1], 1 ) ); + } + hStereoMdct->sw_uncorr = extract_l( GT_16( sw_uncorr_mean, 19661 ) ); + move16(); + } + + pop_wmops(); + return; +} +#endif /*-------------------------------------------------------------------* * ms_processing() @@ -426,6 +839,7 @@ void stereo_coder_tcx( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ms_processing( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ @@ -462,7 +876,47 @@ void ms_processing( return; } +#else +void ms_processing_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const int16_t iSubframe, /* i : subframe number */ + Word32 x_0_fx[], + /* i/o: spectrum 1 */ // Q( q_x ) + Word32 x_1_fx[], + /* i/o: spectrum 1 */ // Q( q_x ) + Word16 maxSfb /* i : number of stereo frequency bands*/ +) +{ + Word16 sfb; + STEREO_MDCT_BAND_PARAMETERS *sfbConf; + + sfbConf = EQ_16( sts[0]->core, TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + + IF( sts[0]->last_core == ACELP_CORE ) + { + assert( EQ_16( sts[1]->last_core, ACELP_CORE ) ); + sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; + } + if ( EQ_16( maxSfb, -1 ) ) + { + maxSfb = sfbConf->sfbCnt; + move16(); + } + + FOR( sfb = 0; sfb < maxSfb; sfb++ ) + { + IF( NE_16( ms_mask[iSubframe][sfb], 0 ) ) + { + convertToBwMS_fx( sfbConf->sfbOffset[sfb], sfbConf->sfbOffset[sfb + 1], x_0_fx, x_1_fx, SQRT2_OVER_2_FIXED ); + } + } + + return; +} +#endif /*-------------------------------------------------------------------* * ms_inv_mask_processing() @@ -470,6 +924,7 @@ void ms_processing( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ms_inv_mask_processing( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ @@ -521,6 +976,64 @@ void ms_inv_mask_processing( return; } +#else +void ms_inv_mask_processing_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const Word16 iSubframe, /* i : subframe number */ + const Word32 x_0_fx[], + /* i : spectrum 1 */ // Q( q_x ) + const Word32 x_1_fx[], + /* i : spectrum 2 */ // Q( q_x ) + Word32 x_inv_0_fx[], + /* o : inverse spectrum 1 */ // Q( q_x ) + Word32 x_inv_1_fx[], + /* o : inverse spectrum 2 */ // Q( q_x ) + Word16 maxSfb /* i : number of stereo frequency bands*/ +) +{ + Word16 sfb; + STEREO_MDCT_BAND_PARAMETERS *sfbConf; + Word16 nSubframes, L_subframeTCX; + + nSubframes = ( sts[0]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; + L_subframeTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); + sfbConf = ( sts[0]->core == TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + + IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + { + assert( EQ_16( sts[1]->last_core, ACELP_CORE ) ); + sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; + } + + IF( EQ_16( maxSfb, -1 ) ) + { + maxSfb = sfbConf->sfbCnt; + move16(); + } + + FOR( sfb = 0; sfb < maxSfb; sfb++ ) + { + Copy32( &x_0_fx[sfbConf->sfbOffset[sfb]], &x_inv_0_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + Copy32( &x_1_fx[sfbConf->sfbOffset[sfb]], &x_inv_1_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + + IF( EQ_16( ms_mask[iSubframe][sfb], 0 ) ) + { + convertToBwMS_fx( sfbConf->sfbOffset[sfb], sfbConf->sfbOffset[sfb + 1], x_inv_0_fx, x_inv_1_fx, SQRT2_OVER_2_FIXED ); + } + } + + /* set rest of inverse spectrum to zero */ + IF( GT_16( L_subframeTCX, sfbConf->sfbOffset[maxSfb] ) ) + { + set_zero_fx( &x_inv_0_fx[sfbConf->sfbOffset[maxSfb]], sub( L_subframeTCX, sfbConf->sfbOffset[maxSfb] ) ); + set_zero_fx( &x_inv_1_fx[sfbConf->sfbOffset[maxSfb]], sub( L_subframeTCX, sfbConf->sfbOffset[maxSfb] ) ); + } + + return; +} +#endif /*-------------------------------------------------------------------* @@ -529,6 +1042,7 @@ void ms_inv_mask_processing( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t write_stereo_to_bitstream( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ @@ -639,6 +1153,137 @@ int16_t write_stereo_to_bitstream( return ( hBstr->nb_bits_tot - start_bits ); } +#else +Word16 write_stereo_to_bitstream( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0)*/ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +{ + Word16 i, k, nSubframes; + UWord16 mdct_stereo_mode, stereo_mode_bits; + STEREO_MDCT_BAND_PARAMETERS *sfbConf; + Word16 start_bits = hBstr->nb_bits_tot; + move16(); + + if ( !mct_on ) + { + assert( ( EQ_16( sts[0]->hTcxEnc->transform_type[0], sts[1]->hTcxEnc->transform_type[0] ) && EQ_16( sts[0]->hTcxEnc->transform_type[1], sts[1]->hTcxEnc->transform_type[1] ) ) || ( EQ_16( hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO ) && EQ_16( hStereoMdct->mdct_stereo_mode[1], SMDCT_DUAL_MONO ) ) ); + } + + nSubframes = ( EQ_16( sts[0]->core, TCX_10_CORE ) || NE_16( sts[0]->core, sts[1]->core ) ) ? NB_DIV : 1; + move16(); + sfbConf = EQ_16( sts[0]->core, TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + move16(); + + IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + { + assert( EQ_16( sts[1]->ini_frame, 0 ) || EQ_16( sts[1]->last_core, ACELP_CORE ) ); + sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; + } + + IF( hStereoMdct->hItd != NULL ) + { + write_itd_data_fx( hStereoMdct->hItd, hBstr ); + } + + FOR( k = 0; k < nSubframes; k++ ) + { + mdct_stereo_mode = 0; + move16(); + stereo_mode_bits = 1; + move16(); + + SWITCH( hStereoMdct->mdct_stereo_mode[k] ) + { + case SMDCT_DUAL_MONO: + mdct_stereo_mode = 0; + move16(); + stereo_mode_bits = 1; + move16(); + BREAK; + case SMDCT_MS_FULL: + mdct_stereo_mode = 2; + move16(); + stereo_mode_bits = 2; + move16(); + BREAK; + case SMDCT_BW_MS: + mdct_stereo_mode = 3; + move16(); + stereo_mode_bits = 2; + move16(); + BREAK; + default: + assert( !"Not supported MDCT stereo mode\n" ); + } + + push_next_indice( hBstr, mdct_stereo_mode, stereo_mode_bits ); + + IF( !mct_on ) + { + IF( EQ_16( sts[0]->core, sts[1]->core ) || ( k == 0 ) ) + { + push_next_indice( hBstr, hStereoMdct->global_ild[k], SMDCT_GLOBAL_ILD_BITS ); + } + } + + IF( EQ_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_BW_MS ) ) + { + FOR( i = 0; i < sfbConf->nBandsStereoCore; i++ ) + { + push_next_indice( hBstr, ms_mask[k][i] ? 1 : 0, 1 ); + } + } + + IF( sts[0]->igf ) + { + mdct_stereo_mode = 0; + move16(); + stereo_mode_bits = 1; + move16(); + SWITCH( hStereoMdct->IGFStereoMode[k] ) + { + case SMDCT_DUAL_MONO: + mdct_stereo_mode = 0; + move16(); + stereo_mode_bits = 1; + move16(); + BREAK; + case SMDCT_MS_FULL: + mdct_stereo_mode = 2; + move16(); + stereo_mode_bits = 2; + move16(); + BREAK; + case SMDCT_BW_MS: + mdct_stereo_mode = 3; + move16(); + stereo_mode_bits = 2; + move16(); + BREAK; + default: + assert( !"Not supported MDCT stereo mode\n" ); + } + + push_next_indice( hBstr, mdct_stereo_mode, stereo_mode_bits ); + + + IF( EQ_16( hStereoMdct->IGFStereoMode[k], SMDCT_BW_MS ) ) + { + FOR( i = sfbConf->nBandsStereoCore; i < sfbConf->sfbCnt; i++ ) + { + push_next_indice( hBstr, ms_mask[k][i] ? 1 : 0, 1 ); + } + } + } + } + + return sub( hBstr->nb_bits_tot, start_bits ); +} +#endif /*-------------------------------------------------------------------* * Band-wise M/S stereo processing @@ -646,6 +1291,7 @@ int16_t write_stereo_to_bitstream( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void convertToBwMS( const int16_t startLine, /* i : start line of sfb */ const int16_t stopLine, /* i : stop line of sfb */ @@ -666,6 +1312,33 @@ static void convertToBwMS( return; } +#else +static void convertToBwMS_fx( + const Word16 startLine, /* i : start line of sfb */ + const Word16 stopLine, /* i : stop line of sfb */ + Word32 x0[], + /* i/o: mid/left channel coefficients */ /* Q_x */ + Word32 x1[], + /* i/o: side/right channel coefficients */ /* Q_x */ + const Word32 norm_fac /* i : normalization factor */ /* Q31 */ +) +{ + Word16 j; + Word32 tmpValue_fx; + + FOR( j = startLine; j < stopLine; j++ ) + { + tmpValue_fx = x0[j]; + move32(); + x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); + move32(); + x1[j] = Mpy_32_32( L_sub( tmpValue_fx, x1[j] ), norm_fac ); + move32(); + } + + return; +} +#endif /*-------------------------------------------------------------------* * convertToMS() @@ -673,6 +1346,7 @@ static void convertToBwMS( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void convertToMS( const int16_t L_frame, /* i : frame length */ float x0[], /* i/o: mid/left channel coefficients */ @@ -684,6 +1358,21 @@ void convertToMS( return; } +#else +void convertToMS_fx( + const Word16 L_frame, /* i : frame length */ + Word32 x0[], + /* i/o: mid/left channel coefficients */ // Q(q_x) + Word32 x1[], + /* i/o: side/right channel coefficients */ // Q(q_x) + const Word32 norm_fac /* i : normalization factor */ // Q31 +) +{ + convertToBwMS_fx( 0, L_frame, x0, x1, norm_fac ); + + return; +} +#endif /*-------------------------------------------------------------------* * SQ_gain_estimate_stereo() @@ -692,6 +1381,7 @@ void convertToMS( *-------------------------------------------------------------------*/ /*! r: SQ gain */ +#ifndef IVAS_FLOAT_FIXED static float SQ_gain_estimate_stereo( float xL[], /* i : L vector to quantize */ float xR[], /* i : R vector to quantize */ @@ -761,6 +1451,104 @@ static float SQ_gain_estimate_stereo( /* return gain */ return powf( 10.0f, 0.45f + 0.5f * offset ); } +#else +static Word32 SQ_gain_estimate_stereo_fx( // e_res + Word32 xL_fx[], + /* i : L vector to quantize */ // e_xL + Word16 e_xL, + Word32 xR_fx[], + /* i : R vector to quantize */ // e_xR + Word16 e_xR, + const Word16 nbitsSQ, /* i : number of bits targeted */ + const Word16 lg, /* i : vector size (2048 max) */ + Word16 *e_res ) +{ + Word16 i, q, iter, e_ener, e_tmp; + Word32 ener_fx, tmp_32, target_fx, fac_fx, offset_fx; + Word32 en_fx[N_MAX / 2]; // Q(26) + Word16 lg2, lg_4, lg2_4; + + lg_4 = shr( lg, 2 ); + lg2_4 = shl( lg_4, 1 ); + lg2 = shl( lg2_4, 2 ); + i = 0; + move16(); + + set32_fx( en_fx, 21474836 /* 0.01 in Q31 */, N_MAX / 2 ); + + /* energy of quadruples with 9dB offset */ + /* ignore that we may take no all lines into account, max. 3 lines at the upper end of the spectrum can be missed (if lg is not a multiple of 4, happens also in SQGain()*/ + + FOR( q = 0; q < lg_4; q++ ) + { + ener_fx = BASOP_Util_Add_Mant32Exp( 21474836, 0, Mpy_32_32( xL_fx[i], xL_fx[i] ), e_xL * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 1], xL_fx[i + 1] ), e_xL * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 2], xL_fx[i + 2] ), e_xL * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 3], xL_fx[i + 3] ), e_xL * 2, &e_ener ); + en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ + move32(); + en_fx[q] = Mpy_32_16_1( L_add( e_ener * ONE_IN_Q25, en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) + move32(); + i = add( i, 4 ); + } + i = 0; + FOR( ; q < lg2_4; q++ ) + { + ener_fx = BASOP_Util_Add_Mant32Exp( 21474836, 0, Mpy_32_32( xR_fx[i], xR_fx[i] ), e_xR * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 1], xR_fx[i + 1] ), e_xR * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 2], xR_fx[i + 2] ), e_xR * 2, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 3], xR_fx[i + 3] ), e_xR * 2, &e_ener ); + en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ + move32(); + en_fx[q] = Mpy_32_16_1( L_add( e_ener * ONE_IN_Q25, en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) + move32(); + i = add( i, 4 ); + } + + /* SQ scale: 4 bits / 6 dB per quadruple */ + target_fx = L_mult( 19660 /* 0.15 in Q17 */, sub( nbitsSQ, shr( lg2, 4 ) ) ); // Q(18) + fac_fx = 429496729; /* 12.8 in Q25 */ + move32(); + offset_fx = fac_fx; + move32(); + + /* find offset (0 to 128 dB with step of 0.125dB) */ + FOR( iter = 0; iter < 10; iter++ ) + { + fac_fx = L_shr( fac_fx, 1 ); + offset_fx = L_sub( offset_fx, fac_fx ); + ener_fx = 0; + move32(); + e_ener = 0; + move16(); + + FOR( i = 0; i < lg2_4; i++ ) + { + tmp_32 = L_sub( en_fx[i], offset_fx ); + e_tmp = 6; + move16(); + + /* avoid SV with 1 bin of amp < 0.5f */ + IF( GT_32( tmp_32, 10066329 ) ) + { + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, tmp_32, e_tmp, &e_ener ); + + /* if ener is above target -> break and increase offset */ + IF( L_shl_sat( ener_fx, sub( e_ener, Q13 ) ) > target_fx ) + { + offset_fx = L_add( offset_fx, fac_fx ); + BREAK; + } + } + } + } + + /* return gain */ + tmp_32 = L_add( 12539858, Mpy_32_16_1( offset_fx, 13606 ) ); // Q23 + + return BASOP_util_Pow2( tmp_32, Q8, e_res ); +} +#endif /*-------------------------------------------------------------------* * QuantSpecEstimateBits() @@ -768,6 +1556,7 @@ static float SQ_gain_estimate_stereo( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t QuantSpecEstimateBits( float *spec, float G, @@ -791,6 +1580,35 @@ static int16_t QuantSpecEstimateBits( return sqBits; } +#else +static Word16 QuantSpecEstimateBits_fx( + Word32 *spec_fx, + Word16 spec_e, + Word16 G_fx, + Word16 G_e, + const Word16 length, + const Word16 nBitsAvailable, + Word16 sqQ[] ) +{ + Word16 stop, sqBits, nEncoded; + Word16 lastnz; + + tcx_scalar_quantization_ivas_fx( spec_fx, spec_e, sqQ, length, G_fx, G_e, 16384, NULL, 1 ); + + stop = 0; + move16(); + + sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, length, &lastnz, &nEncoded, nBitsAvailable, &stop, 0, NULL ); + + if ( stop != 0 ) + { + sqBits = stop; + move16(); + } + + return sqBits; +} +#endif /*-------------------------------------------------------------------* * context_update() @@ -798,6 +1616,7 @@ static int16_t QuantSpecEstimateBits( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void context_update( HANDLE_RC_CONTEXT_MEM ctxSrc, HANDLE_RC_CONTEXT_MEM ctxTarget, @@ -813,6 +1632,24 @@ static void context_update( return; } +#else +static void context_update( + HANDLE_RC_CONTEXT_MEM ctxSrc, + HANDLE_RC_CONTEXT_MEM ctxTarget, + const Word16 endLine ) +{ + Word16 last_nz; + + /* check if last_nz of target is smaller than endLine, save and update */ + last_nz = s_max( ctxTarget->lastnz, endLine ); + + mvc2c( (UWord8 *) ctxSrc, (UWord8 *) ctxTarget, sizeof( RC_CONTEXT_MEM ) ); + ctxTarget->lastnz = last_nz; + move16(); + + return; +} +#endif /*-------------------------------------------------------------------* * GetChannelEnergyRatio() @@ -820,6 +1657,7 @@ static void context_update( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static float GetChannelEnergyRatio( Encoder_State **sts, /* i/o: Encoder state structure */ const int16_t iFirstSubframe, @@ -858,6 +1696,75 @@ static float GetChannelEnergyRatio( return ( nrg[0] + nrg[1] ) > 0 ? nrg[0] / ( nrg[0] + nrg[1] ) : -1.0f; } +#else +static Word16 GetChannelEnergyRatio_fx( // Q15 + Encoder_State **sts, /* i/o: Encoder state structure */ + const Word16 iFirstSubframe, + const Word16 iLastSubframe, + const UWord8 ratioInRmsDomain ) +{ + Word16 ch, n, i; + Word32 nrg_fx[2]; + Word16 nrg_e[2]; + + /* Calculate energies per channel */ + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + const Encoder_State *st = sts[ch]; + + Word16 nSubframes = NB_DIV; + move16(); + + if ( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + } + + Word16 L_subframeTCX = shr( st->hTcxEnc->L_frameTCX, sub( nSubframes, 1 ) ); + + if ( st->last_core == ACELP_CORE ) + { + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + } + assert( iFirstSubframe >= 0 && ( iFirstSubframe <= iLastSubframe ) ); + + nrg_fx[ch] = 0; + move32(); + nrg_e[ch] = 0; + move16(); + + FOR( n = iFirstSubframe; n <= s_min( nSubframes - 1, iLastSubframe ); n++ ) + { + FOR( i = 0; i < L_subframeTCX; i++ ) + { + nrg_fx[ch] = BASOP_Util_Add_Mant32Exp( nrg_fx[ch], nrg_e[ch], Mpy_32_32( st->hTcxEnc->spectrum_fx[n][i], st->hTcxEnc->spectrum_fx[n][i] ), shl( st->hTcxEnc->spectrum_e[n], 1 ), &nrg_e[ch] ); + move32(); + } + } + IF( ratioInRmsDomain && nrg_fx[ch] ) + { + nrg_fx[ch] = Sqrt32( nrg_fx[ch], &nrg_e[ch] ); + move32(); + } + } + + IF( L_add_sat( nrg_fx[0], nrg_fx[1] ) ) + { + nrg_fx[1] = BASOP_Util_Add_Mant32Exp( nrg_fx[0], nrg_e[0], nrg_fx[1], nrg_e[1], &nrg_e[1] ); + move32(); + + IF( NE_16( nrg_e[1], nrg_e[0] ) ) + { + nrg_fx[0] = L_shr( nrg_fx[0], sub( nrg_e[1], nrg_e[0] ) ); + move32(); + } + return divide3232( nrg_fx[0], nrg_fx[1] ); + } + + return MIN_16; +} +#endif /*-------------------------------------------------------------------* * FindSplitRatio() @@ -865,6 +1772,7 @@ static float GetChannelEnergyRatio( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void FindSplitRatio( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ Encoder_State **sts /* i/o: Encoder state structure */ @@ -875,7 +1783,6 @@ void FindSplitRatio( /* Calculate split ratio and quantize it */ hCPE->hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels */ - ratio_float = GetChannelEnergyRatio( sts, 0, 1, highRateMdctStereo ); if ( ratio_float >= 0 ) @@ -896,6 +1803,45 @@ void FindSplitRatio( return; } +#else +void FindSplitRatio_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + Encoder_State **sts /* i/o: Encoder state structure */ +) +{ + const UWord8 highRateMdctStereo = ( LT_32( sts[0]->element_brate, IVAS_80k ) && EQ_16( sts[0]->core, sts[1]->core ) && EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && sts[0]->hTcxEnc->enc_ste_pre_corr_past ? 0 : 1 ); + move16(); + Word16 ratio_fx; + + /* Calculate split ratio and quantize it */ + hCPE->hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels */ + move16(); + + ratio_fx = GetChannelEnergyRatio_fx( sts, 0, 1, highRateMdctStereo ); // Q15 + + IF( ratio_fx >= 0 ) + { + hCPE->hStereoMdct->split_ratio = round_fx( L_mult( SMDCT_BITRATE_RATIO_RANGE, ratio_fx ) ); + move16(); + /* Tuning to get closer to the optimal split ratio */ + IF( LT_32( L_mult0( 9, ratio_fx ), 8 * ONE_IN_Q15 ) && GT_16( hCPE->hStereoMdct->split_ratio, SMDCT_EQUAL_RATIO_RANGE + ( SMDCT_BITRATE_RATIO_RANGE >> 4 ) ) ) + { + hCPE->hStereoMdct->split_ratio = sub( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); + move16(); + } + IF( GT_32( L_mult0( 9, ratio_fx ), 1 * ONE_IN_Q15 ) && LT_16( hCPE->hStereoMdct->split_ratio, SMDCT_EQUAL_RATIO_RANGE - ( SMDCT_BITRATE_RATIO_RANGE >> 4 ) ) ) + { + hCPE->hStereoMdct->split_ratio = add( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); + move16(); + } + + hCPE->hStereoMdct->split_ratio = s_min( SMDCT_BITRATE_RATIO_RANGE - 1, s_max( 1, hCPE->hStereoMdct->split_ratio ) ); + move16(); + } + + return; +} +#endif /*-------------------------------------------------------------------* * MsStereoDecision() @@ -903,6 +1849,7 @@ void FindSplitRatio( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void MsStereoDecision( STEREO_MDCT_BAND_PARAMETERS *sfbParam, float *specL, @@ -1023,6 +1970,153 @@ static void MsStereoDecision( return; } +#else +static void MsStereoDecision_fx( + STEREO_MDCT_BAND_PARAMETERS *sfbParam, + Word32 *specL_fx, /* Q( q_spec ) */ + Word32 *specR_fx, /* Q( q_spec ) */ + Word32 *specM_fx, + /* scratch buffer for M, use buffer for inverse MS mask spectrum */ /* Q( q_spec ) */ + Word32 *specS_fx, + /* scratch buffer for M, use buffer for inverse MS mask spectrum */ /* Q( q_spec ) */ + Word16 q_spec, + Word16 *mdct_stereo_mode, /* output */ + Word16 *msMask, /* output */ + const Word16 nBitsAvailable ) +{ + Word16 length = sfbParam->sfbOffset[sfbParam->nBandsStereoCore]; + + Word16 bitsL, bitsR, bitsM, bitsS; + Word16 bitsBW, bitsLR, bitsMS; + Word16 sfb, i; + Word16 nMSOn; /* Number of MS active bands */ + Word16 quantSpecL[N_MAX]; + Word16 quantSpecR[N_MAX]; + Word16 quantSpecM[N_MAX]; + Word16 quantSpecS[N_MAX]; + RC_CONTEXT_MEM ctxMem[4]; + HANDLE_RC_CONTEXT_MEM ctxL, ctxR, ctxM, ctxS; + + set16_fx( quantSpecL, 0, N_MAX ); + set16_fx( quantSpecR, 0, N_MAX ); + set16_fx( quantSpecM, 0, N_MAX ); + set16_fx( quantSpecS, 0, N_MAX ); + + assert( GT_16( nBitsAvailable, 0 ) ); + + ctxL = &ctxMem[0]; + ctxR = &ctxMem[1]; + ctxM = &ctxMem[2]; + ctxS = &ctxMem[3]; + Word16 specL_e, specR_e, specM_e, specS_e, G_fx, G_e; + Word16 e_GLR; + Word32 GLR_fx; + + specL_e = sub( Q31, q_spec ); + specR_e = sub( Q31, q_spec ); + specM_e = sub( Q31, q_spec ); + specS_e = sub( Q31, q_spec ); + + GLR_fx = SQ_gain_estimate_stereo_fx( specL_fx, specL_e, specR_fx, specR_e, nBitsAvailable, length, &e_GLR ); + + FOR( i = 0; i < length; i++ ) + { + specM_fx[i] = Mpy_32_32( L_add( specL_fx[i], specR_fx[i] ), SQRT2_OVER_2_FIXED ); // Q( q_spec ) + move32(); + specS_fx[i] = Mpy_32_32( L_sub( specL_fx[i], specR_fx[i] ), SQRT2_OVER_2_FIXED ); // Q( q_spec ) + move32(); + } + + G_fx = extract_h( GLR_fx ); /* seems to be favourable to underestimate a bit */ + G_e = sub( e_GLR, 1 ); + + /* do the full spectrum estimates already here, as side effect we get the quantized spectra... */ + bitsLR = add( QuantSpecEstimateBits_fx( specL_fx, specL_e, G_fx, G_e, length, nBitsAvailable, quantSpecL ), QuantSpecEstimateBits_fx( specR_fx, specR_e, G_fx, G_e, length, nBitsAvailable, quantSpecR ) ); + bitsMS = add( QuantSpecEstimateBits_fx( specM_fx, specM_e, G_fx, G_e, length, nBitsAvailable, quantSpecM ), QuantSpecEstimateBits_fx( specS_fx, specS_e, G_fx, G_e, length, nBitsAvailable, quantSpecS ) ); + + /* clean-up MS scratch buffers */ + set32_fx( specM_fx, 0, length ); + set32_fx( specS_fx, 0, length ); + + nMSOn = 0; + move16(); + bitsBW = 0; + move16(); + + RCcontextMapping_encode2_estimate_bandWise_start( quantSpecL, length, nBitsAvailable, ctxL ); + RCcontextMapping_encode2_estimate_bandWise_start( quantSpecR, length, nBitsAvailable, ctxR ); + + bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecM, length, nBitsAvailable, ctxM ) ); + bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecS, length, nBitsAvailable, ctxS ) ); + + /*find_max_lastnz(ctxL,ctxR,ctxM,ctxS);*/ + + FOR( sfb = 0; sfb < sfbParam->nBandsStereoCore; sfb++ ) + { + const Word16 startline = sfbParam->sfbOffset[sfb]; + move16(); + const Word16 endline = sfbParam->sfbOffset[sfb + 1]; + move16(); + + bitsL = RCcontextMapping_encode2_estimate_bandWise( quantSpecL, startline, endline, ctxL ); + bitsR = RCcontextMapping_encode2_estimate_bandWise( quantSpecR, startline, endline, ctxR ); + bitsM = RCcontextMapping_encode2_estimate_bandWise( quantSpecM, startline, endline, ctxM ); + bitsS = RCcontextMapping_encode2_estimate_bandWise( quantSpecS, startline, endline, ctxS ); + + IF( LE_16( add( bitsM, bitsS ), add( bitsL, bitsR ) ) ) + { + msMask[sfb] = 1; + move16(); + nMSOn = add( nMSOn, 1 ); + context_update( ctxM, ctxL, endline ); + context_update( ctxS, ctxR, endline ); + bitsBW = add( bitsBW, add( bitsM, bitsS ) ); + } + ELSE + { + msMask[sfb] = 0; + move16(); + + context_update( ctxL, ctxM, endline ); + context_update( ctxR, ctxS, endline ); + bitsBW = add( bitsBW, add( bitsL, bitsR ) ); + } + } + + bitsBW = add( bitsBW, sfbParam->nBandsStereoCore ); /* Signaling bits */ + + IF( LT_16( bitsLR, bitsBW ) ) + { + nMSOn = 0; + move16(); + set16_fx( msMask, 0, sfbParam->sfbCnt ); + bitsBW = bitsLR; + move16(); + } + + IF( LT_16( bitsMS, bitsBW ) ) + { + nMSOn = sfbParam->nBandsStereoCore; + move16(); + set16_fx( msMask, 1, sfbParam->sfbCnt ); + } + + *mdct_stereo_mode = SMDCT_BW_MS; + move16(); + IF( EQ_16( nMSOn, sfbParam->nBandsStereoCore ) ) + { + *mdct_stereo_mode = SMDCT_MS_FULL; + move16(); + } + ELSE IF( nMSOn == 0 ) + { + *mdct_stereo_mode = SMDCT_DUAL_MONO; + move16(); + } + + return; +} +#endif /*-----------------------------------------------------------------------* @@ -1161,6 +2255,7 @@ void initMdctStereoEncData_fx( * initialize encoder mdct ITD handling structures *-----------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error initMdctItdHandling( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const int32_t input_Fs /* i : input sampling rate */ @@ -1190,8 +2285,8 @@ ivas_error initMdctItdHandling( return IVAS_ERR_OK; } - -ivas_error initMdctItdHandling_fx( +#else +ivas_error initMdctItdHandling( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const Word32 input_Fs /* i : input sampling rate */ ) @@ -1214,18 +2309,23 @@ ivas_error initMdctItdHandling_fx( /*Initialize ITD parameters*/ stereo_enc_itd_init_fx( hStereoMdct->hItd ); +#if 1 // TODO: To be removed later + stereo_enc_itd_init( hStereoMdct->hItd ); +#endif /*Initialize DFT analysis parameters*/ - dft_ana_init_fx( hStereoMdct->hDft_ana, input_Fs ); + dft_ana_init( hStereoMdct->hDft_ana, input_Fs ); return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- * stereo_mdct_enc_destroy() * * destroy MDCT stereo handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_mdct_enc_destroy( STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ ) @@ -1247,3 +2347,26 @@ void stereo_mdct_enc_destroy( return; } +#else +void stereo_mdct_enc_destroy( + STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ +) +{ + IF( ( *hStereoMdct )->hDft_ana != NULL ) + { + free( ( *hStereoMdct )->hDft_ana ); + ( *hStereoMdct )->hDft_ana = NULL; + } + + IF( ( *hStereoMdct )->hItd != NULL ) + { + free( ( *hStereoMdct )->hItd ); + ( *hStereoMdct )->hItd = NULL; + } + + free( *hStereoMdct ); + *hStereoMdct = NULL; + + return; +} +#endif diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 03cf7bfe2d347287134e606deec6eb34cacc9d8a..165db27f982f92be65fef4a7adb4799a2ffdad4b 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -403,7 +403,11 @@ ivas_error stereo_memory_enc( /* allocate CLDFB for primary channel */ if ( st->cldfbAnaEnc == NULL ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -419,7 +423,11 @@ ivas_error stereo_memory_enc( if ( st->cldfbSynTd == NULL ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -503,8 +511,18 @@ ivas_error stereo_memory_enc( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } + +#ifdef IVAS_FLOAT_FIXED + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#endif // IVAS_FLOAT_FIXED + st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef IVAS_FLOAT_FIXED + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); st->hTcxEnc->tfm_mem = 0.75f; @@ -553,7 +571,12 @@ ivas_error stereo_memory_enc( for ( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif + { return error; } diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index fc2ace3e5dc99b44d23f89a0c4351f3d7f14e397..73b03eb183aa3bc3dd031fd570d50bf29c007289 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -41,17 +41,40 @@ #include "ivas_cnst.h" #include "rom_enc.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#include "prot_fx.h" +#include "ivas_rom_com_fx.h" +#endif /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +#define RMS_MIN_FX_Q20 ( 1572864000 ) /* 1500 in Q20 */ /* Minimum energy for ratio index*/ +#define RMS_MIN2_FX_Q21 ( 2097152000 ) /* 1000 in Q21 */ /* Minimum energy for LR encoding*/ +#define CORR_THRES_FX_Q15 ( 31130 ) /* 0.95f in Q15 */ /* Maximal open loop correlation */ +#define DT_ENER_THR_FX_Q23 ( 1677721600 ) /* 200 in Q24 */ /* Energy variation threshold */ +#endif + #define RMS_MIN 1500 /* Minimum energy for ratio index*/ #define RMS_MIN2 1000 /* Minimum energy for LR encoding*/ #define CORR_THRES 0.95f /* Maximal open loop correlation */ #define DT_ENER_THR 200 /* Energy variation threshold */ +#ifdef IVAS_FLOAT_FIXED +#define ALP_REF_FX_Q31 ( 1717986918 ) /* 0.8f in Q31 */ /* smoothing factor */ +#define BET_REF_FX_Q31 ( ONE_IN_Q31 - ALP_REF_FX_Q31 ) + +#define ALP1_FX_Q31 ( 1073741824 ) /* 0.5f in Q31 */ /* smoothing factor in case of correlation are going in different directions */ +#define BET1_FX_Q31 ( ONE_IN_Q31 - ALP1_FX_Q31 ) /* increase the update rate */ + +#define ALP2_FX_Q31 ( 429496729 ) /* 0.2f in Q31 */ /* smoothing factor in case of correlation are going in different directions in SM mode*/ +#define BET2_FX_Q31 ( ONE_IN_Q31 - ALP2_FX_Q31 ) /* increase the update rate in SM mode*/ +#endif + #define ALP_REF 0.8f /* smoothing factor */ #define BET_REF ( 1.0f - ALP_REF ) @@ -62,11 +85,25 @@ #define BET2 ( 1.0f - ALP2 ) /* increase the update rate in SM mode*/ #define RATIO_MAX 1.5f /* Maximum correlation ratio */ +#ifdef IVAS_FLOAT_FIXED +#define RATIO_MAX_FX_Q30 ( 1610612736 ) /* 0.15f in Q30 */ /* Maximum correlation ratio */ +#define RATIO_MAX_FX_Q24 ( 2516582 ) /* 0.15f in Q24 */ /* Maximum correlation ratio */ +#define RATIO_MAX_FX_Q23 ( 1258291 ) /* 0.15f in Q23 */ /* Maximum correlation ratio */ +#endif + #define LIMIT_ADAP_FAC 0.15f #define MIN_ADAP_FAC 0.1f #define M_ADAP 0.0009f #define B_ADAP 0.16f +#ifdef IVAS_FLOAT_FIXED +#define LIMIT_ADAP_FAC_FX_Q24 ( 2516582 ) /* 0.15f in Q24 */ +#define MIN_ADAP_FAC_FX_Q24 ( 1677722 ) /*0.1f in Q24*/ +#define M_ADAP_FX_Q31 ( 1932735 ) /* 0.0009f in Q31 */ +#define B_ADAP_FX_Q24 ( 2684355 ) /* 0.16f in Q24 */ +// #define B_ADAP_FX_Q31 ( 343597384 ) /* 0.16f in Q31 */ +#endif + #define PC_LIMIT 64 #define RATIO_PG_HR 0.94f #define RATIO_PG 0.92f @@ -81,29 +118,61 @@ #define IVAS_BRATE_OMASA_STEREO_SW_THR 15000 +#ifdef IVAS_FLOAT_FIXED +// #define ONE_BY_100_Q15 ( 328 ) +#define ONE_BY_100_Q31 ( 21474896 ) +#define TEN_IN_Q27 ( 1342177280 ) /* 10.0f in Q27 */ +#define TEN_IN_Q24 ( 167772160 ) /* 10.0f in Q24 */ +#endif /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 stereo_tdm_ener_analysis_SM_fx( CPE_ENC_HANDLE hCPE, Encoder_State **sts, const Word16 input_frame, Word16 *tdm_SM_flag ); + +static void Get_corr_n_fx( const Word16 L[], const Word16 R[], Word32 *ic_Lm, Word16 *q_ic_Lm, Word32 *ic_Rm, Word16 *q_ic_Rm, const Word16 len, Word32 *es_em, const Word16 tdm_SM_calc_flag ); +#else static int16_t stereo_tdm_ener_analysis_SM( CPE_ENC_HANDLE hCPE, Encoder_State **sts, const int16_t input_frame, int16_t *tdm_SM_flag ); +#endif static void Get_corr_n( const float L[], const float R[], float *ic_Lm, float *ic_Rm, const int16_t len, float *es_em, const int16_t tdm_SM_calc_flag ); + +#ifdef IVAS_FLOAT_FIXED +static Word16 stereo_smooth_LR_transition_fx( Word16 *tdm_prev_stable_idx, Word16 *tdm_ratio_transition_mov_flag, Word16 tdm_last_ratio_idx, Word16 *tdm_prev_desired_idx, Word16 *tdm_ratio_transition_cnt, const Word16 tdm_SM_flag, Word16 desired_idx ); + +static Word16 limit_idx_Dwnmix_fx( const Word16 idx_in, const Word16 unclr_decision, const Word16 inst_idx, const Word16 previous_idx, const Word16 tdm_last_LRTD_PriCh_cnt, const Word16 tdm_last_LRTD_frame_cnt ); +#else static int16_t stereo_smooth_LR_transition( int16_t *tdm_prev_stable_idx, int16_t *tdm_ratio_transition_mov_flag, int16_t tdm_last_ratio_idx, int16_t *tdm_prev_desired_idx, int16_t *tdm_ratio_transition_cnt, const int16_t tdm_SM_flag, int16_t desired_idx ); static int16_t limit_idx_Dwnmix( const int16_t idx_in, const int16_t unclr_decision, const int16_t inst_idx, const int16_t previous_idx, const int16_t tdm_last_LRTD_PriCh_cnt, const int16_t tdm_last_LRTD_frame_cnt ); +#endif static int16_t limit_idx_NoDwnmix( const int16_t idx_in, const int16_t side_can_change, const float d_lt_corr_raw ); +#ifdef IVAS_FLOAT_FIXED +static void Get_LR_rms_fx( const Word16 *Left_in, const Word16 *Right_in, const Word16 input_frame, Word32 *rms_L, Word16 *q_rms_L, Word32 *rms_R, Word16 *q_rms_R ); +#else +#endif static void Get_LR_rms( const float *Left_in, const float *Right_in, const int16_t input_frame, float *rms_L, float *rms_R ); +#ifdef IVAS_FLOAT_FIXED +static Word16 Get_dt_lt_ener_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono, const Word16 input_frame, const Word16 tdm_last_SM_flag, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, Word32 *tdm_lt_rms_L, Word32 *tdm_lt_rms_R, Word32 *tdm_last_ener_lt_L, Word32 *tdm_last_ener_lt_R, Word32 *tdm_LT_es_em, Word16 *tdm_hyst_cnt, Word16 *tdm_NOOP_SM_flag_loc, Word32 *ener_R_dt, Word32 *ener_L_dt, Word32 *corr_LM, Word16 *q_corr_LM, Word32 *corr_RM, Word16 *q_corr_RM ); +#else +#endif static int16_t Get_dt_lt_ener( CPE_ENC_HANDLE hCPE, const int16_t IsSideMono, const int16_t input_frame, const int16_t tdm_last_SM_flag, const float rms_L, const float rms_R, float *tdm_lt_rms_L, float *tdm_lt_rms_R, float *tdm_last_ener_lt_L, float *tdm_last_ener_lt_R, float *tdm_LT_es_em, int16_t *tdm_hyst_cnt, int16_t *tdm_NOOP_SM_flag_loc, float *ener_R_dt, float *ener_L_dt, float *corr_LM, float *corr_RM ); static void NOOP_decision( CPE_ENC_HANDLE hCPE, const int16_t tdm_NOOP_flag_loc, const int16_t tmp_SM_flag, const float rms_L, const float rms_R, int16_t *tdm_SM_flag_loc ); +#ifdef IVAS_FLOAT_FIXED +static Word32 Comp_diff_lt_corr_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, const Word32 ener_L_dt, const Word32 ener_R_dt, Word32 corr_LM, Word16 q_corr_LM, Word32 corr_RM, Word16 q_corr_RM, const Word32 tdm_lt_rms_L, const Word32 tdm_lt_rms_R, Word32 *tdm_lt_corr_LM, Word32 *tdm_lt_corr_RM, Word32 *tdm_last_diff_lt_corr, Word16 *q_tdm_last_diff_lt_corr, Word32 *inst_ratio_L_out, Word32 *diff_lt_corr, Word16 *q_d_lt_corr_raw ); +#else +#endif static float Comp_diff_lt_corr( CPE_ENC_HANDLE hCPE, const int16_t IsSideMono, const float rms_L, const float rms_R, const float ener_L_dt, const float ener_R_dt, float corr_LM, float corr_RM, const float tdm_lt_rms_L, const float tdm_lt_rms_R, float *tdm_lt_corr_LM, float *tdm_lt_corr_RM, float *tdm_last_diff_lt_corr, float *inst_ratio_L_out, float *diff_lt_corr ); + /*-------------------------------------------------------------------* * Function stereo_tdm_ener_analysis() * @@ -371,7 +440,11 @@ int16_t stereo_tdm_ener_analysis( } } +#ifdef IVAS_FLOAT_FIXED + idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx, &hStereoTD->tdm_ratio_transition_mov_flag, hStereoTD->tdm_last_ratio_idx, &hStereoTD->tdm_prev_desired_idx, &hStereoTD->tdm_ratio_transition_cnt, tdm_SM_flag_loc, desired_idx ); +#else idx = stereo_smooth_LR_transition( &hStereoTD->tdm_prev_stable_idx, &hStereoTD->tdm_ratio_transition_mov_flag, hStereoTD->tdm_last_ratio_idx, &hStereoTD->tdm_prev_desired_idx, &hStereoTD->tdm_ratio_transition_cnt, tdm_SM_flag_loc, desired_idx ); +#endif /* Change the switching level in case of dual mono (in case the scenario still accept left right switching */ /* This logic is needed in case the content is exactly the same in the 2 channel and it is expected to get back to LRTD, to prevent the secondary channel to be completely empty */ @@ -458,7 +531,11 @@ int16_t stereo_tdm_ener_analysis( } else { +#ifdef IVAS_FLOAT_FIXED + idx = limit_idx_Dwnmix_fx( idx, ( hCPE->hStereoClassif->unclr_decision || ( sts[0]->flag_noisy_speech_snr == 1 && hCPE->hStereoClassif->xtalk_wscore > 0.1f ) ), desired_idx, hStereoTD->tdm_last_ratio_idx, hStereoTD->tdm_last_LRTD_PriCh_cnt, hStereoTD->tdm_last_LRTD_frame_cnt ); +#else idx = limit_idx_Dwnmix( idx, ( hCPE->hStereoClassif->unclr_decision || ( sts[0]->flag_noisy_speech_snr == 1 && hCPE->hStereoClassif->xtalk_wscore > 0.1f ) ), desired_idx, hStereoTD->tdm_last_ratio_idx, hStereoTD->tdm_last_LRTD_PriCh_cnt, hStereoTD->tdm_last_LRTD_frame_cnt ); +#endif } if ( abs( hStereoTD->tdm_last_ratio_idx - idx ) > LRTD_STEREO_MID_IS_PRIM ) @@ -502,6 +579,12 @@ int16_t stereo_tdm_ener_analysis( hStereoTD->tdm_last_diff_lt_corr_SM = 0; hStereoTD->tdm_last_ener_lt_R_SM = 0; hStereoTD->tdm_last_ener_lt_L_SM = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoTD->tdm_lt_corr_RM_SM_fx = 167772 /*0.01f Q24*/; + hStereoTD->tdm_lt_corr_LM_SM_fx = 167772 /*0.01f Q24*/; + hStereoTD->tdm_last_ener_lt_R_SM_fx = 0; + hStereoTD->tdm_last_ener_lt_L_SM_fx = 0; +#endif hStereoTD->tdm_noop_mov_flag = 0; hStereoTD->tdm_noop_cnt = 0; @@ -512,7 +595,39 @@ int16_t stereo_tdm_ener_analysis( hStereoTD->tdm_hyst_cnt_SM = 0; } +#ifdef IVAS_FLOAT_FIXED + hStereoTD->tdm_lt_rms_L_SM_fx = floatToFixed_32( hStereoTD->tdm_lt_rms_L_SM, Q24 ); + hStereoTD->tdm_lt_rms_R_SM_fx = floatToFixed_32( hStereoTD->tdm_lt_rms_R_SM, Q24 ); + hStereoTD->tdm_LT_es_em_SM_fx = floatToFixed_32( hStereoTD->tdm_LT_es_em_SM, Q21 ); + sts[0]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[0]->hNoiseEst->Etot_last, Q8 ); + sts[1]->hNoiseEst->Etot_last_fx = float_to_fix16( sts[1]->hNoiseEst->Etot_last, Q8 ); + sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); + sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); + hStereoTD->q_tdm_last_diff_lt_corr_SM = Q31; + hStereoTD->tdm_last_diff_lt_corr_SM_fx = floatToFixed_32( hStereoTD->tdm_last_diff_lt_corr_SM, hStereoTD->q_tdm_last_diff_lt_corr_SM ); +#endif + +#ifdef IVAS_FLOAT_FIXED + *tdm_ratio_idx_SM = stereo_tdm_ener_analysis_SM_fx( hCPE, sts, input_frame, &tdm_NOOP_flag ); +#else *tdm_ratio_idx_SM = stereo_tdm_ener_analysis_SM( hCPE, sts, input_frame, &tdm_NOOP_flag ); +#endif + +#ifdef IVAS_FLOAT_FIXED + hStereoTD->tdm_lt_rms_L_SM = fixedToFloat_32( hStereoTD->tdm_lt_rms_L_SM_fx, Q24 ); + hStereoTD->tdm_lt_rms_R_SM = fixedToFloat_32( hStereoTD->tdm_lt_rms_R_SM_fx, Q24 ); + hStereoTD->tdm_last_ener_lt_L_SM = fixedToFloat_32( hStereoTD->tdm_last_ener_lt_L_SM_fx, Q24 ); + hStereoTD->tdm_last_ener_lt_R_SM = fixedToFloat_32( hStereoTD->tdm_last_ener_lt_R_SM_fx, Q24 ); + hStereoTD->tdm_LT_es_em_SM = fixedToFloat_32( hStereoTD->tdm_LT_es_em_SM_fx, Q21 ); + sts[0]->hNoiseEst->Etot_last = fix16_to_float( sts[0]->hNoiseEst->Etot_last_fx, Q8 ); + sts[1]->hNoiseEst->Etot_last = fix16_to_float( sts[1]->hNoiseEst->Etot_last_fx, Q8 ); + hCPE->hStereoClassif->xtalk_fv[E_diff_corrLM_corrRM] = fixedToFloat( hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM], Q21 ); + hCPE->hStereoClassif->xtalk_fv[E_tdm_LT_es_em] = fixedToFloat( hCPE->hStereoClassif->xtalk_fv_fx[E_tdm_LT_es_em], Q21 ); + + hStereoTD->tdm_lt_corr_LM_SM = fixedToFloat_32( hStereoTD->tdm_lt_corr_LM_SM_fx, Q24 ); + hStereoTD->tdm_lt_corr_RM_SM = fixedToFloat_32( hStereoTD->tdm_lt_corr_RM_SM_fx, Q24 ); + hStereoTD->tdm_last_diff_lt_corr_SM = fixedToFloat_32( hStereoTD->tdm_last_diff_lt_corr_SM_fx, hStereoTD->q_tdm_last_diff_lt_corr_SM ); +#endif } else { @@ -536,6 +651,117 @@ int16_t stereo_tdm_ener_analysis( return ( idx ); } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function Get_LR_rms_fx() + * + * Get current frame left and right rms values + *-------------------------------------------------------------------*/ + +static void Get_LR_rms_fx( + const Word16 *Left_in, + const Word16 *Right_in, + const Word16 input_frame, + Word32 *rms_L, + Word16 *q_rms_L, + Word32 *rms_R, + Word16 *q_rms_R ) +{ + Word32 ener_l, ener_r; + Word32 ener_l_tmp, ener_r_tmp; +#ifdef FIX_818_COMPLEXITY_IMPROV + Word16 guard_bits; + Word64 W_ener_l_tmp, W_ener_r_tmp; +#else + Word64 ener_l_tmp_64bit, ener_r_tmp_64bit; + Word16 q_shift; +#endif + Word16 i; + Word16 exp_out_l, exp_out_r, exp_diff; + +#ifdef FIX_818_COMPLEXITY_IMPROV + W_ener_l_tmp = 0; + move64(); + W_ener_r_tmp = 0; + move64(); +#else + ener_l_tmp_64bit = 0; + move64(); + ener_r_tmp_64bit = 0; + move64(); +#endif + ener_l = ONE_BY_100_Q31; + move32(); + ener_r = ONE_BY_100_Q31; + move32(); + +#ifdef FIX_818_COMPLEXITY_IMPROV + guard_bits = sub( 32, find_guarded_bits_fx( input_frame ) ); + FOR( i = 0; i < input_frame; i++ ) + { + W_ener_l_tmp = W_mac0_16_16( W_ener_l_tmp, Left_in[i], Left_in[i] ); // Q0 + W_ener_r_tmp = W_mac0_16_16( W_ener_r_tmp, Right_in[i], Right_in[i] ); // Q0 + } + /* Scaling back to the original proposal */ + ener_l_tmp = W_extract_h( W_shl( W_ener_l_tmp, guard_bits ) ); // guard_bits - 32 + ener_r_tmp = W_extract_h( W_shl( W_ener_r_tmp, guard_bits ) ); // guard_bits - 32 +#else + FOR( i = 0; i < input_frame; i++ ) + { + ener_l_tmp_64bit = W_add( ener_l_tmp_64bit, W_deposit32_l( L_mult0( Left_in[i], Left_in[i] ) ) ); // Q0 + ener_r_tmp_64bit = W_add( ener_r_tmp_64bit, W_deposit32_l( L_mult0( Right_in[i], Right_in[i] ) ) ); // Q0 + } + + q_shift = 31; + move16(); + IF( ener_l_tmp_64bit != 0 ) + { + q_shift = s_min( q_shift, W_norm( ener_l_tmp_64bit ) ); + } + IF( ener_r_tmp_64bit != 0 ) + { + q_shift = s_min( q_shift, W_norm( ener_r_tmp_64bit ) ); + } + ener_l_tmp = W_extract_l( W_shl_nosat( ener_l_tmp_64bit, sub( q_shift, 32 ) ) ); // (q_shift - 32) + ener_r_tmp = W_extract_l( W_shl_nosat( ener_r_tmp_64bit, sub( q_shift, 32 ) ) ); // (q_shift - 32) + /* perform rounding towards lower value for negative results */ + IF( ener_l_tmp < 0 ) + { + ener_l_tmp = L_add( ener_l_tmp, 1 ); + } + IF( ener_r_tmp < 0 ) + { + ener_r_tmp = L_add( ener_r_tmp, 1 ); + } +#endif + +#ifdef FIX_818_COMPLEXITY_IMPROV + ener_l = BASOP_Util_Add_Mant32Exp( ener_l, 0, ener_l_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_l ); + ener_r = BASOP_Util_Add_Mant32Exp( ener_r, 0, ener_r_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_r ); +#else + ener_l = BASOP_Util_Add_Mant32Exp( ener_l, 0, ener_l_tmp, sub( Q31, sub( q_shift, 32 ) ), &exp_out_l ); + ener_r = BASOP_Util_Add_Mant32Exp( ener_r, 0, ener_r_tmp, sub( Q31, sub( q_shift, 32 ) ), &exp_out_r ); +#endif + + ener_l_tmp = BASOP_Util_Divide3232_Scale( ener_l, input_frame, &exp_diff ); + exp_out_l = sub( add( exp_diff, exp_out_l ), Q15 ); + ener_r_tmp = BASOP_Util_Divide3232_Scale( ener_r, input_frame, &exp_diff ); + exp_out_r = sub( add( exp_diff, exp_out_r ), Q15 ); + + *rms_L = Sqrt32( ener_l_tmp, &exp_out_l ); // Q31 - exp_out_l + move32(); + *q_rms_L = sub( Q31, exp_out_l ); + move16(); + *rms_R = Sqrt32( ener_r_tmp, &exp_out_r ); // Q31 - exp_out_r + move32(); + *q_rms_R = sub( Q31, exp_out_r ); + move16(); + + return; +} +#endif + + /*-------------------------------------------------------------------* * Function Get_LR_rms() * @@ -567,6 +793,181 @@ static void Get_LR_rms( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function Get_dt_lt_ener_fx() + * + * Compute the gain of L&R channel compared to mono + * - estimate the long term evolution of the L to Mono gain + * - estimate the long term evolution of the R to Mono gain + * - estimate the long term difference between the long term + * - evolution of the L and R to Mono gain + *-------------------------------------------------------------------*/ + +static Word16 Get_dt_lt_ener_fx( + CPE_ENC_HANDLE hCPE, + const Word16 IsSideMono, + const Word16 input_frame, + const Word16 tdm_last_SM_flag, + const Word32 rms_L, + const Word16 q_rms_L, + const Word32 rms_R, + const Word16 q_rms_R, + Word32 *tdm_lt_rms_L, + Word32 *tdm_lt_rms_R, + Word32 *tdm_last_ener_lt_L, + Word32 *tdm_last_ener_lt_R, + Word32 *tdm_LT_es_em, + Word16 *tdm_hyst_cnt, + Word16 *tdm_NOOP_SM_flag_loc, + Word32 *ener_R_dt, + Word32 *ener_L_dt, + Word32 *corr_LM, + Word16 *q_corr_LM, + Word32 *corr_RM, + Word16 *q_corr_RM ) +{ + Encoder_State **sts; + Word16 Left_in_fx[L_FRAME48k], Right_in_fx[L_FRAME48k]; + Word16 q_Left_in, q_Right_in; + Word32 es_em_fx; + Word16 tmp_SM_flag, tdm_SM_flag_loc; + Word32 L_tmp, L_tmp1; + Word16 exp_diff; + + sts = hCPE->hCoreCoder; +#if 0 + Left_in_fx = sts[0]->input_fx; /* Left channel */ + Right_in_fx = sts[1]->input_fx; /* Right channel */ +#else + /* This part has f2f conversions as sts[0]->input_fx and sts[1]->input_fx are in Q0. Precision loss is observed in later functions.*/ + q_Left_in = Q_factor_arr( sts[0]->input, input_frame ); + q_Right_in = Q_factor_arr( sts[1]->input, input_frame ); + q_Left_in = s_min( q_Left_in, q_Right_in ); + q_Left_in = sub( q_Left_in, Q1 ); + floatToFixed_arr16( sts[0]->input, Left_in_fx, q_Left_in, input_frame ); + floatToFixed_arr16( sts[1]->input, Right_in_fx, q_Left_in, input_frame ); +#endif + + tdm_SM_flag_loc = tdm_last_SM_flag; + move16(); + + test(); + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && IsSideMono == 0 ) /* last coding mode not TD and normal mono/side case, quick update of lt energy */ + { + *tdm_lt_rms_L = L_shl( Mpy_32_32( 1932735282 /* 0.9f in Q31 */, rms_L ), sub( Q24, q_rms_L ) ); // (Q31, q_rms_L) -> q_rms_L -> Q24 + move32(); + *tdm_lt_rms_R = L_shl( Mpy_32_32( 1932735282 /* 0.9f in Q31 */, rms_R ), sub( Q24, q_rms_R ) ); // (Q31, q_rms_R) -> q_rms_R -> Q24 + move32(); + L_tmp = Mpy_32_16_1( 1932735282 /* 0.9f in Q31 */, sts[0]->hNoiseEst->Etot_last_fx ); //(Q31, Q8) -> Q24 + sts[1]->hNoiseEst->Etot_last_fx = extract_h( L_tmp ); // (Q24 >> Q16) -> Q8 + sts[1]->hVAD->hangover_cnt = 0; + move16(); + } + ELSE + { + L_tmp = Mpy_32_32( 1288490188 /* 0.6f in Q31 */, *tdm_lt_rms_L ); // Q24 + L_tmp1 = Mpy_32_32( 858993459 /* 0.4f in Q31 */, rms_L ); // q_rms_L + *tdm_lt_rms_L = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_rms_L ), &exp_diff ); //(Q31 - exp_diff) + move32(); + *tdm_lt_rms_L = L_shl( *tdm_lt_rms_L, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + L_tmp = Mpy_32_32( 1288490188 /* 0.6f in Q31 */, *tdm_lt_rms_R ); // Q24 + L_tmp1 = Mpy_32_32( 858993459 /* 0.4f in Q31 */, rms_R ); // q_rms_L + *tdm_lt_rms_R = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_rms_R ), &exp_diff ); //(Q31 - exp_diff) + move32(); + *tdm_lt_rms_R = L_shl( *tdm_lt_rms_R, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + } + + /*----------------------------------------------------------------* + * Compute the 1st order energy difference difference + *----------------------------------------------------------------*/ + + *ener_R_dt = L_sub( *tdm_lt_rms_R, *tdm_last_ener_lt_R ); // Q24 + move32(); + *tdm_last_ener_lt_R = *tdm_lt_rms_R; // Q24 + move32(); + + *ener_L_dt = L_sub( *tdm_lt_rms_L, *tdm_last_ener_lt_L ); // Q24 + move32(); + *tdm_last_ener_lt_L = *tdm_lt_rms_L; // Q24 + move32(); + + /*----------------------------------------------------------------* + * Compute the gain of L&R channel compared to mono + * - estimate the long term evolution of the L to Mono gain + * - estimate the long term evolution of the R to Mono gain + * - estimate the long term difference between the long term + * - evolution of the L and R to Mono gain + *----------------------------------------------------------------*/ + + Get_corr_n_fx( Left_in_fx, Right_in_fx, corr_LM, q_corr_LM, corr_RM, q_corr_RM, input_frame, &es_em_fx, IsSideMono ); + + hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM] = BASOP_Util_Add_Mant32Exp( *corr_LM, sub( Q31, *q_corr_LM ), L_negate( *corr_RM ), sub( Q31, *q_corr_RM ), &exp_diff ); + move32(); + hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM] = L_shl( hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM], sub( Q21, sub( Q31, exp_diff ) ) ); + move32(); + + IF( sts[0]->hVAD->hangover_cnt != 0 ) + { + *tdm_LT_es_em = Mpy_32_32( 1932735282 /* 0.9f in Q31 */, *tdm_LT_es_em ); // Q21 + move32(); + } + ELSE + { + *tdm_LT_es_em = L_add( Mpy_32_32( 1932735282 /* 0.9f in Q31 */, *tdm_LT_es_em ), Mpy_32_32( 214748365 /* 0.1f in Q31 */, es_em_fx ) ); // Q21 + move32(); + } + + hCPE->hStereoClassif->xtalk_fv_fx[E_tdm_LT_es_em] = *tdm_LT_es_em; // Q21 + move32(); + + tmp_SM_flag = 0; + move16(); + if ( LT_16( s_min( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 27853 /* 0.85f in Q15 */ ) && LT_16( s_max( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 30147 /* 0.92f in Q15 */ ) && + ( GT_32( *tdm_LT_es_em, ONE_IN_Q22 /* 2.0f in Q21 */ ) || GT_32( es_em_fx, 5242880 /* 2.5f in Q21 */ ) ) && ( LE_16( sts[0]->hVAD->hangover_cnt, 1 ) && LE_16( sts[1]->hVAD->hangover_cnt, 3 ) && sts[0]->tdm_LRTD_flag == 0 ) ) + { + tmp_SM_flag = 1; + move16(); + } + if ( IsSideMono == 0 ) + { + *tdm_NOOP_SM_flag_loc = tdm_SM_flag_loc; + move16(); + } + + IF( NE_16( tmp_SM_flag, tdm_SM_flag_loc ) ) + { + IF( GE_16( *tdm_hyst_cnt, 2 ) && EQ_16( tmp_SM_flag, 1 ) && ( GT_16( sts[0]->tdm_pc, PC_LIMIT ) || GT_16( sts[1]->tdm_pc, PC_LIMIT ) ) ) + { + tdm_hyst_cnt++; + *tdm_NOOP_SM_flag_loc = tmp_SM_flag; + move16(); + *tdm_hyst_cnt = 0; + move16(); + } + ELSE IF( GE_16( *tdm_hyst_cnt, 20 ) && tmp_SM_flag == 0 && + ( GT_16( sts[0]->tdm_pc, PC_LIMIT ) || GT_16( sts[1]->tdm_pc, PC_LIMIT ) ) && ( LE_32( *tdm_LT_es_em, ONE_IN_Q20 /* 0.5f in Q21 */ ) || LT_32( es_em_fx, -20971520 /* -10.0f in Q21 */ ) ) ) + { + tdm_hyst_cnt++; + *tdm_NOOP_SM_flag_loc = tmp_SM_flag; + move16(); + *tdm_hyst_cnt = 0; + move16(); + } + } + ELSE + { + *tdm_hyst_cnt = 0; + move16(); + } + + return tmp_SM_flag; +} +#endif + + /*-------------------------------------------------------------------* * Function Get_dt_lt_ener() * @@ -802,6 +1203,220 @@ static void NOOP_decision( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function Comp_diff_lt_corr_fx() + * + * Adjust stereo downmixing adaptation rate factor + * in function of the signal energy. + *-------------------------------------------------------------------*/ + +static Word32 Comp_diff_lt_corr_fx( + CPE_ENC_HANDLE hCPE, + const Word16 IsSideMono, + const Word32 rms_L, + const Word16 q_rms_L, + const Word32 rms_R, + const Word16 q_rms_R, + const Word32 ener_L_dt, + const Word32 ener_R_dt, + Word32 corr_LM, + Word16 q_corr_LM, + Word32 corr_RM, + Word16 q_corr_RM, + const Word32 tdm_lt_rms_L, + const Word32 tdm_lt_rms_R, + Word32 *tdm_lt_corr_LM, + Word32 *tdm_lt_corr_RM, + Word32 *tdm_last_diff_lt_corr, + Word16 *q_tdm_last_diff_lt_corr, + Word32 *inst_ratio_L_out, + Word32 *diff_lt_corr, + Word16 *q_d_lt_corr_raw ) +{ + Encoder_State **sts; + Word32 adaprate_fx; + Word32 adaprate_tmp_fx; + Word32 madaprate_fx; + Word32 d_lt_corr_raw_fx; + Word32 L_tmp, L_tmp1; + Word16 q_tmp, q_tmp1; + Word16 exp_diff; + Word32 inst_ratio_L_fx; + Word16 angle; + Word32 diff_lt_corr_LM_tmp_fx, diff_lt_corr_RM_tmp_fx; + Word16 q_diff_lt_corr_LM_tmp, q_diff_lt_corr_RM_tmp; + Word32 diff_lt_corr_tmp_fx; + Word16 q_diff_lt_corr_tmp; + Word32 d_lt_corr_fx; + Word16 q_d_lt_corr; + Word16 d_lt_corr_shift, shift, q_com; + + sts = hCPE->hCoreCoder; + + /*----------------------------------------------------------------* + * Adjust stereo downmixing adaptation rate factor + * in function of the signal energy. If signal energy is low, + * adaptation rate factor is lower. This prevent stereo image + * move on speech offset + *----------------------------------------------------------------*/ + + IF( IsSideMono == 0 && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) && ( GT_32( tdm_lt_rms_R, L_shl( tdm_lt_rms_L, Q1 ) ) || GT_32( tdm_lt_rms_L, L_shl( tdm_lt_rms_R, Q1 ) ) ) ) + { + adaprate_fx = L_add( Mpy_32_32( M_ADAP_FX_Q31, L_max( tdm_lt_rms_R, tdm_lt_rms_L ) ), B_ADAP_FX_Q24 ); // Q24 + } + ELSE + { + adaprate_fx = L_add( Mpy_32_32( M_ADAP_FX_Q31, L_min( tdm_lt_rms_R, tdm_lt_rms_L ) ), B_ADAP_FX_Q24 ); // Q24 + } + + adaprate_fx = check_bounds_l( adaprate_fx, MIN_ADAP_FAC_FX_Q24, ONE_IN_Q24 ); // Q24 + + /*----------------------------------------------------------------* + * In case of unvoiced content (expect when it is part of an onset), + * the adaptation rate is minimal. + *----------------------------------------------------------------*/ + + IF( GT_16( sts[0]->ini_frame, 2 ) && + ( ( LE_16( sts[0]->last_clas, VOICED_TRANSITION ) && sts[0]->hVAD->hangover_cnt == 0 ) || + ( LE_16( sts[1]->last_clas, VOICED_TRANSITION ) && sts[1]->hVAD->hangover_cnt == 0 ) ) ) + { + adaprate_fx = L_min( adaprate_fx, LIMIT_ADAP_FAC_FX_Q24 ); + } + + d_lt_corr_raw_fx = 0; + move32(); + IF( IsSideMono == 0 ) + { + if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) || ( ( LT_32( tdm_lt_rms_R, ONE_IN_Q24 ) || LT_32( tdm_lt_rms_L, ONE_IN_Q24 ) ) && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) && LT_32( L_max( tdm_lt_rms_R, tdm_lt_rms_L ), TEN_IN_Q24 ) ) ) + { + adaprate_fx = 16441672; /* 0.98f in Q24 */ /* speed up the adaptation of the long term values to the current values after coming from DFT */ + move32(); + } + adaprate_tmp_fx = L_max( adaprate_fx, 13421773 /* 0.8f in Q24 */ ); // Q24 + madaprate_fx = L_sub( ONE_IN_Q24, adaprate_tmp_fx ); /* madaprate has temporary value, will updated few lines below */ // Q24 + + L_tmp = Mpy_32_32( adaprate_tmp_fx, corr_LM ); // (Q24, q_corr_LM) -> q_corr_LM - Q7 + L_tmp1 = Mpy_32_32( madaprate_fx, *tdm_lt_corr_LM ); // (Q24, Q24) -> Q17 + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, sub( q_corr_LM, Q7 ) ), L_tmp1, Q31 - Q17, &exp_diff ); // Q31 - exp_diff + q_tmp = sub( Q31, exp_diff ); + + L_tmp = Mpy_32_32( adaprate_tmp_fx, corr_RM ); // (Q24, q_corr_RM) -> q_corr_RM - Q7 + L_tmp1 = Mpy_32_32( madaprate_fx, *tdm_lt_corr_RM ); // (Q24, Q24) -> Q17 + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, sub( q_corr_RM, Q7 ) ), L_tmp1, Q31 - Q17, &exp_diff ); // Q31 - exp_diff + q_tmp1 = sub( Q31, exp_diff ); + + d_lt_corr_raw_fx = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_tmp ), L_tmp1, sub( Q31, q_tmp1 ), &exp_diff ); // Q31 - exp_diff + *q_d_lt_corr_raw = sub( Q31, exp_diff ); + move16(); + q_com = s_min( *q_d_lt_corr_raw, Q30 ); + + inst_ratio_L_fx = 0; + move32(); + inst_ratio_L_fx = L_max( L_shl( d_lt_corr_raw_fx, sub( q_com, *q_d_lt_corr_raw ) ), L_negate( L_shl( RATIO_MAX_FX_Q30, sub( q_com, Q30 ) ) ) ); // q_com + inst_ratio_L_fx = L_min( inst_ratio_L_fx, L_shl( RATIO_MAX_FX_Q30, sub( q_com, Q30 ) ) ); // q_com + inst_ratio_L_fx = L_add( Mpy_32_32( 1432371593 /* 0.667f in Q31 */, inst_ratio_L_fx ), L_shl( 1, q_com ) ); // q_com + angle = extract_l( L_shl( Mpy_32_16_1( inst_ratio_L_fx, EVS_PI_FX ), sub( Q13, sub( q_com, Q2 ) ) ) ); // (q_com, Q13) -> q_com - Q2 >> Q1 -> q_com - Q3 -> Q13 + *inst_ratio_L_out = L_shl( L_shr( L_sub( ONE_IN_Q14, L_deposit_l( getCosWord16( angle ) ) ), Q1 ), Q24 - Q14 ); // Q14 << Q10 -> Q24 + } + madaprate_fx = L_sub( ONE_IN_Q24, adaprate_fx ); // Q24 + corr_RM = BASOP_Util_Add_Mant32Exp( Mpy_32_32( adaprate_fx, corr_RM ), sub( Q31, sub( q_corr_RM, Q7 ) ), Mpy_32_32( madaprate_fx, *tdm_lt_corr_RM ), Q31 - Q17, &exp_diff ); // Q31 - exp_diff + q_corr_RM = sub( Q31, exp_diff ); + corr_LM = BASOP_Util_Add_Mant32Exp( Mpy_32_32( adaprate_fx, corr_LM ), sub( Q31, sub( q_corr_LM, Q7 ) ), Mpy_32_32( madaprate_fx, *tdm_lt_corr_LM ), Q31 - Q17, &exp_diff ); // Q31 - exp_diff + q_corr_LM = sub( Q31, exp_diff ); + + L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_LM ); // Q24 + L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_LM ); // q_corr_LM + diff_lt_corr_LM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_corr_LM ), L_tmp1, Q31 - Q24, &exp_diff ); + q_diff_lt_corr_LM_tmp = sub( Q31, exp_diff ); + L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_RM ); // Q24 + L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_RM ); // q_corr_RM + diff_lt_corr_RM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_corr_RM ), L_tmp1, Q31 - Q24, &exp_diff ); + q_diff_lt_corr_RM_tmp = sub( Q31, exp_diff ); + diff_lt_corr_tmp_fx = BASOP_Util_Add_Mant32Exp( diff_lt_corr_LM_tmp_fx, sub( Q31, q_diff_lt_corr_LM_tmp ), L_negate( diff_lt_corr_RM_tmp_fx ), sub( Q31, q_diff_lt_corr_RM_tmp ), &exp_diff ); // (Q31 - exp_diff) + q_diff_lt_corr_tmp = sub( Q31, exp_diff ); + + d_lt_corr_fx = BASOP_Util_Add_Mant32Exp( diff_lt_corr_tmp_fx, sub( Q31, q_diff_lt_corr_tmp ), L_negate( *tdm_last_diff_lt_corr ), sub( Q31, *q_tdm_last_diff_lt_corr ), &exp_diff ); // (Q31 - exp_diff) + q_d_lt_corr = sub( Q31, exp_diff ); + IF( GT_16( q_d_lt_corr, Q31 ) ) + { + d_lt_corr_shift = sub( Q31, q_d_lt_corr ); + shift = 0; + move16(); + } + ELSE + { + d_lt_corr_shift = 0; + move16(); + shift = sub( q_d_lt_corr, Q31 ); + } + *tdm_last_diff_lt_corr = diff_lt_corr_tmp_fx; + move32(); + *q_tdm_last_diff_lt_corr = q_diff_lt_corr_tmp; + move16(); + + /*----------------------------------------------------------------* + * Correct the estimation depending of channels energies evolution + *----------------------------------------------------------------*/ + + IF( EQ_16( IsSideMono, 1 ) && + ( ( LT_32( L_shl( rms_L, sub( Q21, q_rms_L ) ), RMS_MIN2_FX_Q21 ) && + LT_32( L_shl( rms_R, sub( Q21, q_rms_R ) ), RMS_MIN2_FX_Q21 ) ) && + ( LT_32( tdm_lt_rms_L, L_shl( Mpy_32_32( 1717986918 /* 0.8f in Q31 */, rms_L ), sub( Q24, q_rms_L ) ) ) && + LT_32( tdm_lt_rms_R, L_shl( Mpy_32_32( 1717986918 /* 0.8f in Q31 */, rms_R ), sub( Q24, q_rms_R ) ) ) ) && + ( GT_32( tdm_lt_rms_L, L_shl( tdm_lt_rms_R, Q1 ) ) || + LT_32( tdm_lt_rms_L, L_shr( tdm_lt_rms_R, Q1 ) ) ) ) ) + { + L_tmp = Mpy_32_32( ALP2_FX_Q31, *tdm_lt_corr_LM ); // Q24 + L_tmp1 = Mpy_32_32( BET2_FX_Q31, corr_LM ); // q_corr_LM + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_LM ), &exp_diff ); // (Q31 - exp_diff) + *tdm_lt_corr_LM = L_shl( L_tmp, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + L_tmp = Mpy_32_32( ALP2_FX_Q31, *tdm_lt_corr_RM ); // Q24 + L_tmp1 = Mpy_32_32( BET2_FX_Q31, corr_RM ); // q_corr_RM + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_RM ), &exp_diff ); // (Q31 - exp_diff) + *tdm_lt_corr_RM = L_shl( L_tmp, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + + *tdm_lt_corr_LM = L_shl( Mpy_32_32( *tdm_lt_corr_LM, 1342177280 /* 2.5f in Q29 */ ), Q24 - Q22 ); // ((Q24, Q29) -> Q22 << 2) -> Q24 + move32(); + *tdm_lt_corr_RM = L_shl( Mpy_32_32( *tdm_lt_corr_RM, 1342177280 /* 2.5f in Q29 */ ), Q24 - Q22 ); // ((Q24, Q29) -> Q22 << 2) -> Q24 + move32(); + } + ELSE IF( ( !( ( GT_32( L_shr( ener_R_dt, Q1 ), DT_ENER_THR_FX_Q23 ) && LT_32( L_shr( ener_L_dt, Q1 ), DT_ENER_THR_FX_Q23 ) ) || + ( LT_32( L_shr( ener_R_dt, Q1 ), DT_ENER_THR_FX_Q23 ) && GT_32( L_shr( ener_L_dt, Q1 ), DT_ENER_THR_FX_Q23 ) ) ) /* Energy are going in the same direction */ + && ( LT_32( L_abs( L_shl( d_lt_corr_fx, d_lt_corr_shift ) ), L_shl( 665719931 /* 0.31f in Q31 */, shift ) ) /* small difference regarding the difference gain evolution */ + || GT_32( L_shr( tdm_lt_rms_L, Q24 - Q20 ), RMS_MIN2_FX_Q21 ) || GT_32( L_shr( tdm_lt_rms_R, Q24 - Q20 ), RMS_MIN2_FX_Q21 ) ) ) /* Energy of at least one of the channel is not low */ + ) + { + /* Use estimated results */ + *tdm_lt_corr_LM = L_shl( diff_lt_corr_LM_tmp_fx, sub( Q24, q_diff_lt_corr_LM_tmp ) ); + move32(); + *tdm_lt_corr_RM = L_shl( diff_lt_corr_RM_tmp_fx, sub( Q24, q_diff_lt_corr_RM_tmp ) ); + move32(); + } + ELSE + { + L_tmp = Mpy_32_32( ALP1_FX_Q31, *tdm_lt_corr_LM ); // Q24 + L_tmp1 = Mpy_32_32( BET1_FX_Q31, corr_LM ); // q_corr_LM + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_LM ), &exp_diff ); // (Q31 - exp_diff) + *tdm_lt_corr_LM = L_shl( L_tmp, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + L_tmp = Mpy_32_32( ALP1_FX_Q31, *tdm_lt_corr_RM ); // Q24 + L_tmp1 = Mpy_32_32( BET1_FX_Q31, corr_RM ); // q_corr_RM + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_RM ), &exp_diff ); // (Q31 - exp_diff) + *tdm_lt_corr_RM = L_shl( L_tmp, sub( Q24, sub( Q31, exp_diff ) ) ); // Q24 + move32(); + } + + *diff_lt_corr = L_sub( *tdm_lt_corr_LM, *tdm_lt_corr_RM ); /* update the difference */ // Q24 + move32(); + + return d_lt_corr_raw_fx; +} +#endif + + /*-------------------------------------------------------------------* * Function Comp_diff_lt_corr() * @@ -925,6 +1540,63 @@ static float Comp_diff_lt_corr( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function limit_idx_Dnwmix_fx() + * + * + *-------------------------------------------------------------------*/ + +static Word16 limit_idx_Dwnmix_fx( + const Word16 idx_in, + const Word16 unclr_decision, + const Word16 inst_idx, + const Word16 previous_idx, + const Word16 tdm_last_LRTD_PriCh_cnt, + const Word16 tdm_last_LRTD_frame_cnt ) +{ + Word16 idx; + + idx = idx_in; + move16(); + idx = check_bounds_s_fx( idx, 1, 29 ); + + IF( EQ_16( unclr_decision, 1 ) && GT_16( tdm_last_LRTD_frame_cnt, 1 ) ) + { + IF( tdm_last_LRTD_PriCh_cnt > 0 ) + { + IF( LE_16( idx, LRTD_STEREO_MID_IS_PRIM ) && LT_16( inst_idx, LRTD_STEREO_MID_IS_PRIM + 2 ) ) + { + idx = s_min( 1, idx ); + } + ELSE IF( GE_16( idx, LRTD_STEREO_MID_IS_PRIM ) && GT_16( inst_idx, LRTD_STEREO_MID_IS_PRIM - 2 ) ) + { + idx = s_max( 29, idx ); + } + ELSE IF( LT_16( inst_idx, LRTD_STEREO_MID_IS_PRIM - 4 ) ) + { + idx = s_min( 1, idx ); + } + ELSE IF( GT_16( inst_idx, LRTD_STEREO_MID_IS_PRIM + 4 ) ) + { + idx = s_max( 29, idx ); + } + ELSE + { + idx = previous_idx; + move16(); + } + } + ELSE + { + idx = previous_idx; + move16(); + } + } + + return idx; +} +#else /*-------------------------------------------------------------------* * Function limit_idx_Dnwmix() * @@ -977,6 +1649,7 @@ static int16_t limit_idx_Dwnmix( return idx; } +#endif /*-------------------------------------------------------------------* @@ -1017,6 +1690,194 @@ static int16_t limit_idx_NoDwnmix( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function stereo_tdm_ener_analysis_SM_fx() + * + * + *-------------------------------------------------------------------*/ + +static Word16 stereo_tdm_ener_analysis_SM_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + Encoder_State **sts, /* i/o: Encoder static variables structure */ + const Word16 input_frame, /* i : Number of samples */ + Word16 *tdm_SM_flag /* i/o: channel combination scheme flag */ +) +{ + Word32 rms_R_fx, rms_L_fx; + Word16 q_rms_R, q_rms_L; + Word32 corr_RM_fx, corr_LM_fx; + Word16 q_corr_LM, q_corr_RM; + Word32 diff_lt_corr_fx; + Word32 ratio_L_fx; + Word32 dist_fx; + Word16 i, side_can_change; + Word16 idx, tdm_SM_flag_loc; + Word32 es_em_fx; + Word32 ener_R_dt_fx, ener_L_dt_fx; + Word16 desired_idx; + STEREO_TD_ENC_DATA_HANDLE hStereoTD; + Word16 angle; + + hStereoTD = hCPE->hStereoTD; + desired_idx = 0; + move16(); + es_em_fx = 20972; /* 0.01f in Q21 */ + move32(); + + /*----------------------------------------------------------------* + * set SM flag + *----------------------------------------------------------------*/ + + /* Simple logic to set SM flag, should be done in the frequency domain for low SM correlation signal, especially for music item such as Music_1_org_s */ + tdm_SM_flag_loc = hStereoTD->tdm_last_SM_flag_noop; + move16(); + + /*----------------------------------------------------------------* + * Compute L and R energy and Long term RMS of each channel + *----------------------------------------------------------------*/ + + Get_LR_rms_fx( sts[0]->input_fx, sts[1]->input_fx, input_frame, &rms_L_fx, &q_rms_L, &rms_R_fx, &q_rms_R ); + + /*----------------------------------------------------------------* + * Compute the 1st order energy difference difference + * Compute the gain of L&R channel compared to mono + * - estimate the long term evolution of the L to Mono gain + * - estimate the long term evolution of the R to Mono gain + * - estimate the long term difference between the long term + * - evolution of the L and R to Mono gain + *----------------------------------------------------------------*/ + + Get_dt_lt_ener_fx( hCPE, 1, input_frame, hStereoTD->tdm_last_SM_flag_noop, rms_L_fx, q_rms_L, rms_R_fx, q_rms_R, + &hStereoTD->tdm_lt_rms_L_SM_fx, &hStereoTD->tdm_lt_rms_R_SM_fx, &hStereoTD->tdm_last_ener_lt_L_SM_fx, &hStereoTD->tdm_last_ener_lt_R_SM_fx, &hStereoTD->tdm_LT_es_em_SM_fx, &hStereoTD->tdm_hyst_cnt_SM, &tdm_SM_flag_loc, + &ener_R_dt_fx, &ener_L_dt_fx, &corr_LM_fx, &q_corr_LM, &corr_RM_fx, &q_corr_RM ); + + hStereoTD->tdm_SM_reset_flag = 0; + move16(); + + /*----------------------------------------------------------------* + * Adjust stereo downmixing adaptation rate factor + * in function of the signal energy. If signal energy is low, + * adaptation rate factor is lower. This prevent stereo image + * move on speech offset + *----------------------------------------------------------------*/ + + Comp_diff_lt_corr_fx( hCPE, 1, rms_L_fx, q_rms_L, rms_R_fx, q_rms_R, ener_L_dt_fx, ener_R_dt_fx, corr_LM_fx, q_corr_LM, corr_RM_fx, q_corr_RM, hStereoTD->tdm_lt_rms_L_SM_fx, hStereoTD->tdm_lt_rms_R_SM_fx, &hStereoTD->tdm_lt_corr_LM_SM_fx, + &hStereoTD->tdm_lt_corr_RM_SM_fx, &hStereoTD->tdm_last_diff_lt_corr_SM_fx, &hStereoTD->q_tdm_last_diff_lt_corr_SM, NULL, &diff_lt_corr_fx, NULL ); + + side_can_change = 0; + move16(); + + /*----------------------------------------------------------------* + * When the energies of channels are low enough, compute the ratio + * of L and R needed to create new mono/side signals + *----------------------------------------------------------------*/ + + IF( ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q20 - Q24 ), RMS_MIN_FX_Q20 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q19 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN_FX_Q20 ) ) || + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q20 - Q24 ), RMS_MIN_FX_Q20 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q19 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN_FX_Q20 ) ) ) + { + if ( ( LT_16( sts[0]->old_corr_fx, CORR_THRES_FX_Q15 ) && LT_16( sts[1]->old_corr_fx, CORR_THRES_FX_Q15 ) ) || + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) ) ) + { + side_can_change = 1; + move16(); + } + } + + IF( ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q20 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN2_FX_Q21 ) ) || + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q20 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN2_FX_Q21 ) ) ) + { + IF( ( ( NE_16( hStereoTD->tdm_last_SM_flag_noop, tdm_SM_flag_loc ) ) && hStereoTD->tdm_noop_cnt == 0 ) || + EQ_16( hStereoTD->tdm_noop_mov_flag, 1 ) || NE_16( hStereoTD->tdm_prev_desired_idx_SM, hStereoTD->tdm_prev_stable_idx_SM ) ) + { + hStereoTD->tdm_noop_mov_flag = 1; + move16(); + if ( hStereoTD->tdm_last_ratio_idx_SM != 0 && NE_16( hStereoTD->tdm_last_ratio_idx_SM, ( TDM_NQ - 1 ) ) ) + { + side_can_change = 1; + move16(); + } + } + } + + if ( side_can_change == 0 && EQ_16( tdm_SM_flag_loc, 1 ) && GT_32( es_em_fx, 31457280 /* 15.0f in Q21 */ ) ) + { + side_can_change = 1; + move16(); + } + + IF( side_can_change ) + { + ratio_L_fx = L_max( diff_lt_corr_fx, -RATIO_MAX_FX_Q24 ); // Q24 + ratio_L_fx = L_min( ratio_L_fx, RATIO_MAX_FX_Q24 ); // Q24 + + IF( GT_32( ratio_L_fx, RATIO_MAX_FX_Q23 ) ) + { + ratio_L_fx = L_add( Mpy_32_32( 1159641170 /* 1.08f in Q30 */, ratio_L_fx ), 3187671 /* 0.38f in Q23 */ ); // (Q30, Q24) -> Q23 + } + ELSE IF( LT_32( ratio_L_fx, -RATIO_MAX_FX_Q23 ) ) + { + ratio_L_fx = L_add( Mpy_32_32( 687194767 /* 0.64f in Q30 */, ratio_L_fx ), 10737418 /* 1.28f in Q23 */ ); // (Q30, Q24) -> Q23 + } + ELSE + { + ratio_L_fx = L_add( Mpy_32_32( 279172874 /* 0.26f in Q30 */, ratio_L_fx ), 8346665 /* 0.995f in Q23 */ ); // (Q30, Q24) -> Q23 + } + + angle = extract_l( L_shl( Mpy_32_16_1( ratio_L_fx, EVS_PI_FX ), Q13 - Q21 - Q1 ) ); // (Q23, Q13) -> Q21 >> Q1 -> Q22 -> Q13 + ratio_L_fx = L_shl( L_shr( L_sub( ONE_IN_Q14, L_deposit_l( getCosWord16( angle ) ) ), Q1 ), Q24 - Q14 ); // Q14 << Q10 -> Q24 + + dist_fx = L_abs( L_sub( ratio_L_fx, tdm_ratio_tabl_fx_Q24[0] ) ); // Q24 + + desired_idx = 0; + move16(); + FOR( i = 1; i < TDM_NQ; i++ ) + { + IF( LE_32( L_abs( L_sub( ratio_L_fx, tdm_ratio_tabl_fx_Q24[i] ) ), dist_fx ) ) + { + dist_fx = L_abs( L_sub( ratio_L_fx, tdm_ratio_tabl_fx_Q24[i] ) ); // Q24 + desired_idx = i; + move16(); + } + } + + idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx_SM, &hStereoTD->tdm_noop_mov_flag, hStereoTD->tdm_last_ratio_idx_SM, &hStereoTD->tdm_prev_desired_idx_SM, &hStereoTD->tdm_noop_cnt, tdm_SM_flag_loc, desired_idx ); + + idx = extract_l( L_add( Mpy_32_32( 1717986918 /* 0.8f in Q31 */, idx ), Mpy_32_32( 429496729 /* 0.2f in Q31 */, hStereoTD->tdm_last_ratio_idx_SM ) ) ); // (Q31, Q0) -> Q0 + + ratio_L_fx = tdm_ratio_tabl_fx_Q24[idx]; + move32(); + } + else + { + ratio_L_fx = hStereoTD->tdm_last_ratio_SM_fx; + move32(); + idx = hStereoTD->tdm_last_ratio_idx_SM; + move16(); + } + + IF( ( EQ_16( hStereoTD->tdm_noop_mov_flag, 1 ) && GE_16( hStereoTD->tdm_noop_cnt, 31 ) ) || ( ( EQ_16( hStereoTD->tdm_last_SM_flag_noop, tdm_SM_flag_loc ) ) && ( EQ_16( idx, hStereoTD->tdm_prev_stable_idx_SM ) ) ) ) + { + hStereoTD->tdm_noop_cnt = 0; + move16(); + hStereoTD->tdm_noop_mov_flag = 0; + move16(); + } + + if ( hStereoTD->tdm_noop_mov_flag == 0 || tdm_SM_flag_loc == 0 ) + { + hStereoTD->tdm_prev_stable_idx_SM = idx; + move16(); + } + + hStereoTD->tdm_last_SM_flag_noop = tdm_SM_flag_loc; + move16(); + *tdm_SM_flag = tdm_SM_flag_loc; + move16(); + + return ( idx ); +} +#else /*-------------------------------------------------------------------* * Function stereo_tdm_ener_analysis_SM() * @@ -1172,6 +2033,7 @@ static int16_t stereo_tdm_ener_analysis_SM( return ( idx ); } +#endif /*-------------------------------------------------------------------* @@ -1328,6 +2190,161 @@ void tdm_ol_pitch_comparison( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function Get_corr_n_fx() + * + * + *-------------------------------------------------------------------*/ + +static void Get_corr_n_fx( + const Word16 L[], /* i : Left signal */ + const Word16 R[], /* i : Right signal */ + Word32 *ic_Lm, /* o : Left signal */ + Word16 *q_ic_Lm, /* o : Q factor of Left signal */ + Word32 *ic_Rm, /* o : Right signal */ + Word16 *q_ic_Rm, /* o : Q factor of Right signal */ + const Word16 len, /* i : segment length */ + Word32 *es_em, /* o : return the difference between the side and mono energy */ + const Word16 tdm_SM_calc_flag /* i : Flag that indicates that it is for SM mode */ +) +{ + Word32 corrL, corrR, ener; + Word16 mono_i; + Word16 i; + Word32 ener_side; + Word16 side_i; + Word16 exp_diff; + Word32 L_tmp; + Word16 guard_bits; +#ifdef FIX_818_COMPLEXITY_IMPROV + Word64 W_corrL, W_corrR, W_ener, W_ener_side; +#endif + +#ifdef FIX_818_COMPLEXITY_IMPROV + W_corrL = 0; + move64(); + W_corrR = 0; + move64(); + W_ener = EPSILON_FX; + move64(); + W_ener_side = EPSILON_FX; + move64(); + guard_bits = sub( 32, find_guarded_bits_fx( len ) ); +#else + corrL = 0; + move32(); + corrR = 0; + move32(); + ener = EPSILON_FX; + move32(); + ener_side = EPSILON_FX; + move32(); + guard_bits = find_guarded_bits_fx( len ); +#endif + + /*----------------------------------------------------------------* + * Find the normalized correlation between: left/mono and right/mono based + *----------------------------------------------------------------*/ + + IF( tdm_SM_calc_flag ) + { +#ifdef FIX_818_COMPLEXITY_IMPROV + FOR( i = 0; i < len; i++ ) + { + mono_i = round_fx( L_msu( L_mult( L[i], ONE_IN_Q14 ), R[i], ONE_IN_Q14 ) ); // q_in + W_corrL = W_mac0_16_16( W_corrL, abs_s( L[i] ), abs_s( mono_i ) ); // (q_in + q_in ) + W_corrR = W_mac0_16_16( W_corrR, abs_s( R[i] ), abs_s( mono_i ) ); // (q_in + q_in ) + W_ener = W_mac0_16_16( W_ener, mono_i, mono_i ); // (q_in + q_in ) + side_i = round_fx( L_mac( L_mult( L[i], ONE_IN_Q14 ), R[i], ONE_IN_Q14 ) ); // q_in + W_ener_side = W_mac0_16_16( W_ener_side, side_i, side_i ); // (q_in + q_in ) + } + /* Scaling back to the original proposal */ + corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); + corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); + ener = W_extract_h( W_shl( W_ener, guard_bits ) ); + ener_side = W_extract_h( W_shl( W_ener_side, guard_bits ) ); +#else + FOR( i = 0; i < len; i++ ) + { + mono_i = sub( shr( L[i], Q1 ), shr( R[i], Q1 ) ); // q_in + corrL = L_add( corrL, L_shr( L_mult0( abs_s( L[i] ), abs_s( mono_i ) ), guard_bits ) ); // (q_in + q_in - guard_bits) + corrR = L_add( corrR, L_shr( L_mult0( abs_s( R[i] ), abs_s( mono_i ) ), guard_bits ) ); // (q_in + q_in - guard_bits) + ener = L_add( ener, L_shr( L_mult0( mono_i, mono_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + side_i = add( shr( L[i], Q1 ), shr( R[i], Q1 ) ); // q_in + ener_side = L_add( ener_side, L_shr( L_mult0( side_i, side_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + } +#endif + } + ELSE + { +#ifdef FIX_818_COMPLEXITY_IMPROV + FOR( i = 0; i < len; i++ ) + { + mono_i = round_fx( L_mac( L_mult( L[i], ONE_IN_Q14 ), R[i], ONE_IN_Q14 ) ); // q_in + W_corrL = W_mac0_16_16( W_corrL, L[i], mono_i ); // (q_in + q_in ) + W_corrR = W_mac0_16_16( W_corrR, R[i], mono_i ); // (q_in + q_in ) + W_ener = W_mac0_16_16( W_ener, mono_i, mono_i ); // (q_in + q_in ) + side_i = round_fx( L_msu( L_mult( L[i], ONE_IN_Q14 ), R[i], ONE_IN_Q14 ) ); // q_in + W_ener_side = W_mac0_16_16( W_ener_side, side_i, side_i ); // (q_in + q_in ) + } + /* Scaling back to the original proposal */ + corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); + corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); + ener = W_extract_h( W_shl( W_ener, guard_bits ) ); + ener_side = W_extract_h( W_shl( W_ener_side, guard_bits ) ); +#else + FOR( i = 0; i < len; i++ ) + { + mono_i = add( shr( L[i], Q1 ), shr( R[i], Q1 ) ); // q_in + corrL = L_add( corrL, L_shr( L_mult0( L[i], mono_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + corrR = L_add( corrR, L_shr( L_mult0( R[i], mono_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + ener = L_add( ener, L_shr( L_mult0( mono_i, mono_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + side_i = sub( shr( L[i], Q1 ), shr( R[i], Q1 ) ); // q_in + ener_side = L_add( ener_side, L_shr( L_mult0( side_i, side_i ), guard_bits ) ); // (q_in + q_in - guard_bits) + } +#endif + } + + *ic_Lm = BASOP_Util_Divide3232_Scale_cadence( corrL, ener, &exp_diff ); // (Q31 - exp_diff) + move32(); + IF( *ic_Lm == 0 ) + { + *q_ic_Lm = Q31; + move16(); + } + ELSE + { + *q_ic_Lm = sub( Q31, exp_diff ); + move16(); + } + *ic_Rm = BASOP_Util_Divide3232_Scale_cadence( corrR, ener, &exp_diff ); // (Q31 - exp_diff) + move16(); + IF( *ic_Rm == 0 ) + { + *q_ic_Rm = Q31; + move16(); + } + ELSE + { + *q_ic_Rm = sub( Q31, exp_diff ); + move16(); + } + + /* *es_em = 10 * ( log10f( sqrtf( ener_side / len ) ) - log10f( sqrtf( ener / len ) ) ); + is simplified to + *es_em = 10 * ( log10f( sqrtf( ener_side / ener ) ) ); */ + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ener_side, ener, &exp_diff ); // (Q31 - exp_diff) + L_tmp = Sqrt32( L_tmp, &exp_diff ); + L_tmp = BASOP_Util_Log2( L_tmp ); + *es_em = Mpy_32_32( Mpy_32_32( L_add( L_tmp, L_shl( exp_diff, Q25 ) ), LOG10_2_Q31 ), TEN_IN_Q27 ); // (Q25, Q27) -> Q21 + move32(); + + return; +} +#endif + + /*-------------------------------------------------------------------* * Function Get_corr_n() * @@ -1391,6 +2408,77 @@ static void Get_corr_n( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * Function stereo_smooth_LR_transition_fx() + * + *-------------------------------------------------------------------*/ + +/*! r: smoothed position */ +static Word16 stereo_smooth_LR_transition_fx( + Word16 *tdm_prev_stable_idx, /* i/o: Previous Transmitted ratio index */ + Word16 *tdm_ratio_transition_mov_flag, /* i/o: Flag that indicates that L-R energy is changing */ + Word16 tdm_last_ratio_idx, /* i : last TDM ratio index */ + Word16 *tdm_prev_desired_idx, /* i/o: Previous Transmitted ratio index */ + Word16 *tdm_ratio_transition_cnt, /* i/o: Counter */ + const Word16 tdm_SM_flag, /* i : channel combination scheme flag for current frame */ + Word16 desired_idx /* i : desired final position */ +) +{ + Word16 idx; + + if ( EQ_16( tdm_SM_flag, 1 ) ) + { + desired_idx = 15; + move16(); + } + + if ( NE_16( desired_idx, *tdm_prev_stable_idx ) ) + { + *tdm_ratio_transition_mov_flag = 1; + move16(); + } + + IF( EQ_16( *tdm_ratio_transition_mov_flag, 1 ) ) + { + IF( NE_16( desired_idx, *tdm_prev_desired_idx ) ) + { + *tdm_prev_stable_idx = tdm_last_ratio_idx; + move16(); + *tdm_ratio_transition_cnt = 0; + move16(); + } + + *tdm_ratio_transition_cnt = add( *tdm_ratio_transition_cnt, 4 ); + move16(); + IF( LT_16( desired_idx, sub( *tdm_prev_stable_idx, 2 ) ) ) + { + idx = sub( *tdm_prev_stable_idx, *tdm_ratio_transition_cnt ); + idx = s_max( desired_idx, idx ); + } + ELSE IF( GT_16( desired_idx, add( *tdm_prev_stable_idx, 2 ) ) ) + { + idx = add( *tdm_prev_stable_idx, *tdm_ratio_transition_cnt ); + idx = s_min( desired_idx, idx ); + } + ELSE + { + idx = desired_idx; + move16(); + } + } + ELSE + { + idx = desired_idx; + move16(); + } + + *tdm_prev_desired_idx = desired_idx; + move16(); + + return idx; +} +#else /*-------------------------------------------------------------------* * Function stereo_smooth_LR_transition() * @@ -1452,3 +2540,4 @@ static int16_t stereo_smooth_LR_transition( return idx; } +#endif diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 8a388ca920991cf55d3188f64af13c4f499bd53f..ce1a4ff8fece90c83ac9f45e1d047471f246f231 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -142,6 +142,7 @@ void stereo_td_init_enc_fx( hStereoTD->tdm_lt_rms_L_fx = 671088640; // Q24 hStereoTD->tdm_lt_rms_R_fx = 671088640; // Q24 hStereoTD->tdm_last_diff_lt_corr_fx = 0; + hStereoTD->q_tdm_last_diff_lt_corr = Q31; hStereoTD->tdm_last_ener_lt_R_fx = 0; hStereoTD->tdm_last_ener_lt_L_fx = 0; @@ -165,6 +166,7 @@ void stereo_td_init_enc_fx( hStereoTD->tdm_lt_rms_L_SM_fx = 671088640; // Q24 hStereoTD->tdm_lt_rms_R_SM_fx = 671088640; // Q24 hStereoTD->tdm_last_diff_lt_corr_SM_fx = 0; + hStereoTD->q_tdm_last_diff_lt_corr_SM = Q31; hStereoTD->tdm_last_ener_lt_R_SM_fx = 0; hStereoTD->tdm_last_ener_lt_L_SM_fx = 0; hStereoTD->tdm_noop_mov_flag = 0; @@ -311,7 +313,11 @@ ivas_error stereo_set_tdm( /* allocate CLDFB ana for secondary channel */ if ( st->cldfbAnaEnc == NULL ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -324,8 +330,11 @@ ivas_error stereo_set_tdm( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - +#ifdef IVAS_FLOAT_FIXED + if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 836abd67d692b4ef6d2f48dcb2d0c368a1027049..76ca272563883c67527e209332787b1bbea15eb1 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -40,6 +40,10 @@ #include "basop_proto_func.h" #include "wmc_auto.h" #include "ivas_prot.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "prot_fx_enc.h" +#endif /*-------------------------------------------------------------------* * stereo_tcx_init_enc() @@ -47,6 +51,104 @@ * Initialize stereo TCX encoder *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void stereo_tcx_init_enc_fx( + Encoder_State *st /* i/o: encoder state structure */ +) +{ + Word16 prev_IsTNSAllowed; + Word32 total_brate; + assert( st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA ); + + /* Get the raw coder type from signal analysis*/ + st->coder_type = st->coder_type_raw; + move16(); + IF( !st->localVAD ) + { + st->coder_type = INACTIVE; + move16(); + } + ELSE IF( GT_16( st->coder_type, GENERIC ) ) + { + st->coder_type = GENERIC; + move16(); + } + + if ( st->tcxonly ) + { + st->coder_type = GENERIC; + move16(); + } + + st->hTcxCfg->coder_type = st->coder_type; + move16(); + test(); + test(); + IF( !st->tcxonly && !st->localVAD && EQ_16( st->hTcxCfg->coder_type, GENERIC ) ) + { + st->hTcxCfg->coder_type = UNVOICED; + move16(); + } + + /*sampling rate*/ + total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); + move32(); + st->fscale = sr2fscale_fx( st->sr_core ); + move16(); + + /*frame size*/ + st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + st->hTcxEnc->L_frameTCX = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); + + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, INT_FS_16k ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) + { + st->nb_subfr = NB_SUBFR16k; + move16(); + } + ELSE + { + st->nb_subfr = NB_SUBFR; + move16(); + } + + /*TCX tools*/ + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_mode ); + move16(); + st->hTcxCfg->resq = getResq( total_brate ); + move16(); + st->hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_mode, st->element_mode ); + move16(); + st->igf = getIgfPresent_fx( st->element_mode, total_brate, st->bwidth, st->rf_mode ); + move16(); + prev_IsTNSAllowed = st->hTcxCfg->fIsTNSAllowed; + move16(); + IF( NE_16( st->element_mode, EVS_MONO ) ) + { + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); + move16(); + } + test(); + test(); + IF( !prev_IsTNSAllowed && st->hTcxCfg->fIsTNSAllowed && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) /* may happen in unified stereo when switching stereo technologies */ + { + InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); + + SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, 0 ); + } + st->core_brate = st->total_brate; + move32(); + + return; +} +#endif + void stereo_tcx_init_enc( Encoder_State *st /* i/o: encoder state structure */ ) @@ -133,6 +235,129 @@ void stereo_tcx_core_enc( const int16_t vad_hover_flag /* i : VAD hangover flag */ ) { +#ifdef IVAS_FLOAT_FIXED + TCX_ENC_HANDLE hTcxEnc; + Word16 i, n; + + /*size and windowing*/ + const float *p_new_samples; + Word16 n_subframes; + Word16 last_core_orig; + + /*Bits*/ + Word16 nbits_start, total_nbbits, nbits_header; + Word16 target_bits[2], bitsAvailable; + Word16 nbits_lpc[2]; + Word16 tnsSize[2]; /* number of tns parameters put into prm */ + Word16 tnsBits[2]; /* number of tns bits in the frame */ + Word16 ltpBits; + + /*Parameters*/ + Word16 param_lpc[NPRM_LPC_NEW]; + Word16 param_core[2 * NPRM_DIV]; + Word16 bits_param_lpc[10], no_param_lpc; + + /*LPC*/ + float lsf_q[M], lsp_q[M], lsp[M], lsf[M]; + float lspmid_q[M]; + float A_q[M + 1]; + float gainlpc[2][FDNS_NPTS]; + float lsp_tcx_q[M], lsf_tcx_q[M]; + int16_t tcx_lpc_cdk; + Word16 A_q_ind[M + 1]; /*for LPC-based AC*/ + Word16 lspq_ind[M]; /*for LPC-based AC*/ + + /*TCX-LTP*/ + Word16 T_op[3]; + + /*HM*/ + Word16 indexBuffer[2 * ( ( N_MAX / 2 ) + 1 )]; + + CONTEXT_HM_CONFIG hm_cfg[2]; + + /* bitstream */ + BSTR_ENC_HANDLE hBstr = st->hBstr; + + + push_wmops( "stereo_tcx_core_enc" ); + + /*Sanity check*/ + assert( st->mdct_sw == MODE1 && "MDCT switching should be in TCX MODE 1\n" ); + assert( st->rf_mode == 0 && "Channel aware not supported! " ); + + no_param_lpc = 0; + move16(); + n_subframes = 1; + move16(); + + hTcxEnc = st->hTcxEnc; + + /*--------------------------------------------------------------* + * Configuration of TCX + *---------------------------------------------------------------*/ + + stereo_tcx_init_enc_fx( st ); + + /*--------------------------------------------------------------* + * Initialization + *---------------------------------------------------------------*/ + + /* Subtract the bits of common header */ + st->bits_frame_core = extract_l( L_sub( Mpy_32_32( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), hBstr->nb_bits_tot ) ); + + /*Get Bits of TCX header*/ + nbits_header = 3; /* Coder types (2) + last_core for bfi (1) */ + move16(); + + IF( st->tcxonly ) + { + /* TCX20/10 flag */ + nbits_header = add( nbits_header, 1 ); + } + + /* bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ + IF( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) || EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, MIN_OVERLAP ) ) + { + nbits_header = add( nbits_header, 2 ); + } + ELSE + { + nbits_header = add( nbits_header, 1 ); + } + + hm_cfg[0].indexBuffer = &indexBuffer[0]; + hm_cfg[1].indexBuffer = &indexBuffer[N_MAX / 2 + 1]; + + set16_fx( tnsSize, 0, 2 ); + set16_fx( tnsBits, 0, 2 ); + set16_fx( nbits_lpc, 0, 2 ); + ltpBits = 0; + move16(); + + FOR( i = 0; i < 3; i++ ) + { + T_op[i] = st->pitch[i]; + move16(); + + /* check minimum pitch for quantization */ + IF( LT_16( T_op[i], PIT_MIN_SHORTER ) ) + { + T_op[i] = shl( T_op[i], 1 ); + } + + /* convert pitch values to core sampling-rate */ + IF( NE_16( st->L_frame, L_FRAME ) ) + { + Word16 s; + Word16 fac = BASOP_Util_Divide1616_Scale( st->L_frame, L_FRAME, &s ); // exp: s + Word32 mul = L_mult0( T_op[i], fac ); // exp: 15 + s + 1 = 16 + s + Word32 half = L_shr( ONE_IN_Q14 /*0.5 in Q15*/, s ); // exp: 16 + s + Word32 sum = L_add( mul, half ); // exp: 16 + s + T_op[i] = extract_l( L_shr( sum, sub( 15, s ) ) ); // exp: 31 (Q0) + // T_op[i] = (int16_t)(T_op[i] * (float)st->L_frame / (float)L_FRAME + 0.5f); + } + } +#else TCX_ENC_HANDLE hTcxEnc; int16_t i, n; @@ -169,6 +394,7 @@ void stereo_tcx_core_enc( /*HM*/ int16_t indexBuffer[2 * ( ( N_MAX / 2 ) + 1 )]; + CONTEXT_HM_CONFIG hm_cfg[2]; /* bitstream */ @@ -235,6 +461,7 @@ void stereo_tcx_core_enc( T_op[i] = (int16_t) ( T_op[i] * (float) st->L_frame / (float) L_FRAME + 0.5f ); } } +#endif if ( st->L_frame == L_FRAME ) { @@ -327,7 +554,11 @@ void stereo_tcx_core_enc( /* Get the envelope */ if ( st->enableTcxLpc ) { +#ifdef IVAS_FLOAT_FIXED + tcx_lpc_cdk = tcxlpc_get_cdk( st->hTcxCfg->coder_type ); +#else tcx_lpc_cdk = tcxlpc_get_cdk_float( st->hTcxCfg->coder_type ); +#endif /* Get the envelope corresponding to the current frame */ E_LPC_int_lpc_tcx_float( st->lspold_enc, lsp_new, A_q ); diff --git a/lib_enc/lead_indexing_fx.c b/lib_enc/lead_indexing_fx.c index b3ceeda43ec7348fab0c2fcca88a7d1a9fcd3089..ff29330140ca4071d8d975ac14ce545a57050c97 100644 --- a/lib_enc/lead_indexing_fx.c +++ b/lib_enc/lead_indexing_fx.c @@ -7,8 +7,7 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 292956a0aab3b158469596d4014927b6c7f603e3..faf701d12902e5f877854a930750bc0221349737 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -34,7 +34,7 @@ #include "ivas_prot.h" #include "ivas_prot_fx.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "prot_fx_enc.h" #include #include @@ -472,8 +472,24 @@ ivas_error IVAS_ENC_FeedObjectMetadata( { return IVAS_ERR_INVALID_INDEX; } - +#ifdef IVAS_FLOAT_FIXED + Word32 azimuth_fx = float_to_fix( metadata.azimuth, Q22 ); /* Q22 */ + Word32 elevation_fx = float_to_fix( metadata.elevation, Q22 ); /* Q22 */ + Word16 radius_fx = float_to_fix16( metadata.radius, Q9 ); /* Q9 */ + Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */ + Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ + error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); + + /*================fix-to-flt====================*/ + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->azimuth = fix_to_float( azimuth_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->elevation = fix_to_float( elevation_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->radius = fix_to_float( radius_fx, Q9 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->yaw = fix_to_float( yaw_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->pitch = fix_to_float( pitch_fx, Q22 ); + /*================fix-to-flt====================*/ +#else error = ivas_set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation, metadata.radius, metadata.yaw, metadata.pitch, metadata.non_diegetic_flag ); +#endif if ( error != IVAS_ERR_OK ) { @@ -1641,7 +1657,10 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( { if ( !( hIvasEnc->hCoreCoder == NULL && hEncoderConfig->ivas_format == MONO_FORMAT ) ) { - st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + if ( ( hEncoderConfig->element_mode_init != EVS_MONO ) ) + { + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + } st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; } @@ -1741,7 +1760,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return error; } - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * IVAS_ENC_EncodeFrameToCompact() * @@ -1768,7 +1787,7 @@ ivas_error IVAS_ENC_EncodeFrameToCompact( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_ENC_SetBandwidth() @@ -2634,17 +2653,17 @@ static ivas_error sanitizeBitrateISM_fx( return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } @@ -2781,7 +2800,6 @@ static ivas_error bandwidthApiToInternal( case IVAS_ENC_BANDWIDTH_UNDEFINED: default: return IVAS_ERR_INVALID_BANDWIDTH; - BREAK; } return IVAS_ERR_OK; @@ -2808,7 +2826,6 @@ static ivas_error fecIndicatorApiToInternal( BREAK; default: return IVAS_ERR_INTERNAL; - BREAK; } return IVAS_ERR_OK; diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index e7f141b5f33e59f6d88100f1677779ec71a322fa..cc6291cee38d879561b2e0febb1b3d32088be3c3 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -4,11 +4,9 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -17,6 +15,129 @@ * * Compute relative energy, long-term average total noise energy and total active speech energy *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_long_enr_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + Word16 high_lpn_flag, /* i : sp/mus LPN flag */ + FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ + const Word16 n_chan, /* i : number of channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover LR channels */ + const Word16 Etot_LR[] /* i : total channel energy LR channels */ + +) +{ + Word16 tmp; + Word16 alpha; + NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; + + /*-----------------------------------------------------------------* + * Compute long term estimate of total noise energy + * and total active speech energy + *-----------------------------------------------------------------*/ + Word16 n; + IF( hFrontVad != NULL ) + { + IF( LT_16( hFrontVad[0]->ini_frame, 4 ) ) + { + FOR( n = 0; n < n_chan; n++ ) + { + hFrontVad[n]->lp_noise_fx = hFrontVad[n]->hNoiseEst->totalNoise_fx; + tmp = add( hFrontVad[n]->lp_noise_fx, 2560 ); + + IF( LT_16( hFrontVad[n]->lp_speech_fx, tmp ) ) + { + hFrontVad[n]->lp_speech_fx = tmp; + move16(); + } + } + } + ELSE + { + Word16 smooth_prev, smooth_curr; + + IF( LT_16( hFrontVad[0]->ini_frame, 150 ) ) + { + smooth_prev = 31130; + smooth_curr = 1638; + } + ELSE + { + smooth_prev = 32113; + smooth_curr = 655; + } + + FOR( n = 0; n < n_chan; n++ ) + { + hFrontVad[n]->lp_noise_fx = add( mult_r( smooth_prev, hFrontVad[n]->lp_noise_fx ), mult_r( smooth_curr, hFrontVad[n]->hNoiseEst->totalNoise_fx ) ); + + IF( localVAD_HE_SAD_LR[n] && !high_lpn_flag ) + { + IF( LT_16( sub( hFrontVad[n]->lp_speech_fx, Etot_LR[n] ), 2560 ) ) + { + hFrontVad[n]->lp_speech_fx = add( mult_r( 32113, hFrontVad[n]->lp_speech_fx ), mult_r( 655, Etot_LR[n] ) ); + } + ELSE + { + hFrontVad[n]->lp_speech_fx = sub( hFrontVad[n]->lp_speech_fx, 13 ); + } + } + } + } + FOR( n = 0; n < n_chan; n++ ) + { + hFrontVad[n]->hNoiseEst->Etot_last_fx = Etot_LR[n]; + move16(); + } + } + ELSE + { + IF( LT_16( st_fx->ini_frame, 4 ) ) + { + st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; + move16(); + tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ + st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); + } + ELSE + { + /* if ( st->ini_frame < 150 ) { + st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; + } else { + st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; + } */ + alpha = 655; + move16(); /* 0.02 Q15 */ + if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ + { + alpha = 1638; + move16(); /* 0.05 Q15 */ + } + st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ + + test(); + IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) + { + IF( LT_16( sub( st_fx->lp_speech_fx, Etot ), 2560 ) ) /* 10.0 in Q8 */ + { + /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ + st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ + } + ELSE + { + st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + } + } + } + } + + /*-----------------------------------------------------------------* + * Initialize parameters for energy tracking and signal dynamics + *-----------------------------------------------------------------*/ + return; +} +#endif void long_enr_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index a8a6abc3334023f03e091666bcfc0959815be444..9562eabf87f50d1b8a651bfcb05fa8e6aecb7974 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index ea07e8a1ee55ffdd27c85fc672cc77b6ad1ca530..855f786671e3aaeef4b50ddd0f388672ec2b8787 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -40,9 +40,12 @@ #include "rom_enc.h" #include "rom_com.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "basop_proto_func.h" #include "ivas_prot.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif #include "ivas_rom_com.h" #include "wmc_auto.h" diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 3926f4a2bacb26dc1ac293bfef5cd21a34e91fb2..121de20db6518a1b5ad86526bf1e91aa3b28793c 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -8,9 +8,9 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "ivas_prot_fx.h" /* Function prototypes */ /*-----------------------------------------------------------------* @@ -29,8 +29,12 @@ static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); +static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq ); + static void lsf_mid_enc_fx( BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); +static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, int16_t nb_bits, const Word32 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); + /*===========================================================================*/ /* FUNCTION : lsf_enc_fx() */ /*---------------------------------------------------------------------------*/ @@ -336,7 +340,266 @@ void lsf_enc_fx( return; } +void lsf_enc_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 Q_new ) +{ + Word16 nBits = 0; + Word16 int_fs; + Word16 force_sf = 0; + Word16 fec_lsf[M], stab, i; + Word16 no_param_lpc; + + Word16 param_lpc[NPRM_LPC_NEW]; + Word32 L_tmp; + Word16 coder_type, ppp_mode, nelp_mode; + + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) ) + { + coder_type = INACTIVE; + move16(); + } + ELSE + { + coder_type = st->coder_type; + move16(); + } + + test(); + if ( EQ_16( coder_type, AUDIO ) && GSC_IVAS_mode > 0 ) + { + coder_type = GENERIC; + move16(); + } + + no_param_lpc = 0; + move16(); + + IF( st->Opt_SC_VBR ) + { + ppp_mode = st->hSC_VBR->ppp_mode; + nelp_mode = st->hSC_VBR->nelp_mode; + move16(); + move16(); + } + ELSE + { + ppp_mode = 0; + nelp_mode = 0; + move16(); + move16(); + } + + /* initialize */ +#if 0 + int_fs = INT_FS_16k_FX; + move16(); + if (EQ_16(L_frame, L_FRAME)) + { + int_fs = INT_FS_FX; + move16(); + } +#else + assert( st->sr_core <= 32000 ); + int_fs = extract_l( st->sr_core ); + move32(); +#endif + /* convert LSPs to LSFs */ + lsp2lsf_fx( lsp_new, lsf_new, M, int_fs ); + + /* check resonance for pitch clipping algorithm */ + gp_clip_test_lsf_fx( st->element_mode, lsf_new, st->clip_var_fx, 0 ); + + /* Find the number of bits for LSF quantization */ + nBits = 0; + move16(); + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + nBits = LSF_BITS_CNG; + move16(); + } + ELSE + { + test(); + IF( ( nelp_mode == 0 ) && ( ppp_mode == 0 ) ) + { + nBits = st->acelp_cfg.lsf_bits; + move16(); + } + ELSE IF( EQ_16( nelp_mode, 1 ) ) + { + nBits = 30; + move16(); + + if ( EQ_16( st->bwidth, NB ) ) + { + nBits = 32; + move16(); + } + } + ELSE IF( EQ_16( ppp_mode, 1 ) ) + { + nBits = 26; + move16(); + } + } + force_sf = 0; + move16(); + /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ + test(); + if ( LT_16( st->Nb_ACELP_frames, 3 ) && NE_32( st->core_brate, SID_2k40 ) ) + { + force_sf = 1; + move16(); + } + + /* in case of unstable filter in decoder FEC, choose safety-net to help FEC */ + IF( EQ_16( st->next_force_safety_net_fx, 1 ) ) + { + force_sf = 1; + move16(); + st->next_force_safety_net_fx = 0; + move16(); + } + + /*-------------------------------------------------------------------------------------* + * Frame end LSF quantization + *-------------------------------------------------------------------------------------*/ + lsf_end_enc_ivas_fx( st, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, + force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw, tdm_lsfQ_PCh ); + + /* convert quantized LSFs back to LSPs */ + lsf2lsp_fx( lsf_new, lsp_new, M, st->sr_core ); + + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* don't use old LSF values if this is the first ACELP frame after HQ frames */ + Copy( lsf_new, st->lsf_old_fx, M ); + } + /* set seed_acelp used in UC mode */ + + test(); + IF( EQ_16( coder_type, UNVOICED ) && GT_16( st->element_mode, EVS_MONO ) ) + { + st->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st->seed_acelp = add( i_mult( add( shr( st->seed_acelp, 1 ), param_lpc[i] ), 31821 ), 13849 ); + } + } + + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - enforce safety-net in the next frame in case of unstable filter + *-------------------------------------------------------------------------------------*/ + + IF( NE_16( st->last_L_frame, st->L_frame ) ) + { + /* FEC - in case of core switching, use old LSFs */ + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); + } + + FEC_lsf_estim_enc_fx( st, fec_lsf ); + + /* in case of FEC in decoder - calculate LSF stability */ + stab = lsf_stab_ivas_fx( lsf_new, fec_lsf, 0, st->L_frame ); + + test(); + test(); + test(); + /* If decoder FEC frame may be unstable force safety-net usage */ + IF( ( EQ_16( st->L_frame, L_FRAME16k ) ) && ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( coder_type, GENERIC ) ) ) + { + st->next_force_safety_net_fx = 1; + move16(); + } + ELSE IF( ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( st->clas, VOICED_CLAS ) || ( LT_16( st->clas, VOICED_CLAS ) && EQ_16( coder_type, AUDIO ) ) ) ) + { + st->next_force_safety_net_fx = 1; + move16(); + } + + + /* FEC - update adaptive LSF mean vector */ + FOR( i = 0; i < M; i++ ) + { + L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ + L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ + st->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ + } + + /* FEC - update LSF memories */ + Copy( st->lsfoldbfi0_fx, st->lsfoldbfi1_fx, M ); + Copy( lsf_new, st->lsfoldbfi0_fx, M ); + + + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF encoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + IF( st->rate_switching_reset ) + { + /*extrapolation in case of unstable LSF convert*/ + Copy( lsp_new, st->lsp_old_fx, M ); + Copy( lsf_new, st->lsf_old_fx, M ); + } + /* Mid-frame LSF encoding */ + lsf_mid_enc_ivas_fx( st->hBstr, st->acelp_cfg.mid_lsf_bits, st->sr_core, st->lsp_old_fx, lsp_new, lsp_mid, coder_type, st->bwidth, st->Bin_E_old_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); + + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ + Copy( lsp_mid, st->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, int_fs ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + test(); + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) + { + IF( EQ_16( st->active_cnt, 1 ) ) + { + Copy( lsp_mid, st->lsp_old_fx, M ); + lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, int_fs ); + Copy( lsp_new, lsp_mid, M ); + } + /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + } + ELSE + { + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); + } + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + IF( NE_32( st->core_brate, SID_2k40 ) ) + { + st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st->lsf_old_fx, 0, st->L_frame ); + } + return; +} /*-------------------------------------------------------------------* * lsfq_CNG_fx() * @@ -441,47 +704,136 @@ static void lsfq_CNG_fx( return; } -/*-------------------------------------------------------------------* - * qlsf_Mode_Select_fx() - * - * Mode selection for LSF quantizer - *-------------------------------------------------------------------*/ - - -static Word16 qlsf_Mode_Select_fx( - const Word16 *w, /* i : weighting vector Q8 */ - const Word16 *pred1, /* i : prediction vector x2.56 */ - const Word16 streaklimit, /* i : predictive streak limit Q15 */ - const Word32 op_loop_thr /* i : Open-loop Threshold */ +static void lsfq_CNG_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *lsf, /*x2.56 unquantized LSF vector */ + const Word16 *wghts, /*Q10 LSF weights */ + Word16 *qlsf /*x2.56 quantized LSF vecotor */ ) { - Word16 pred_pow2[M]; - Word32 temp32, En = 0; - Word16 safety_net; - Word16 i, cs, cl; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif + Word16 i, j, idx_cv, idx_lvq[3]; + Word32 min_dist, dist; + Word16 dd[M], ddq[M]; + const Word16 *p_cb; + Word16 first_cb, last_cb; + Word16 idx_lead_cng[2], idx_scale_cng[2]; + Word16 tmp; - /* calculate the prediction residual */ - cl = 0; + idx_cv = 0; move16(); - FOR( i = 0; i < M; i++ ) + + /* quantize first stage with 4 bits + The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF + coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 + the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains + either NB or WB LSF data. */ + IF( GT_16( lsf[M - 1], WB_LIMIT_LSF_FX ) ) /* 16kHz sampled LSF vector*/ { - cl = s_max( cl, abs_s( pred1[i] ) ); + p_cb = &CNG_SN1_fx[0]; + move16(); + first_cb = 0; + move16(); + last_cb = 6; + move16(); } - cs = norm_s( cl ); - En = 0; - move16(); - FOR( i = 0; i < M; i++ ) + ELSE /* 12.8kHz sampled LSF vector*/ { - pred_pow2[i] = shl( pred1[i], cs ); + p_cb = &CNG_SN1_fx[6 * M]; move16(); -#ifdef BASOP_NOGLOB - En = L_mac_o( En, mult( pred_pow2[i], shl_o( w[i], 2, &Overflow ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */ -#else /* BASOP_NOGLOB */ - En = L_mac( En, mult( pred_pow2[i], shl( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */ -#endif /* BASOP_NOGLOB */ + first_cb = 6; + move16(); + last_cb = M; + move16(); + } + + + min_dist = L_add( MAXINT32, 0 ); + FOR( i = first_cb; i < last_cb; i++ ) + { + tmp = sub( *p_cb, shl( lsf[0], 1 ) ); /*x2.56 */ + dist = Mult_32_16( L_mult0( wghts[0], *p_cb ), tmp ); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ + p_cb++; + FOR( j = 1; j < M; j++ ) + { + tmp = sub( *p_cb, lsf[j] ); + tmp = sub( tmp, lsf[j] ); + + dist = L_add( dist, Mult_32_16( L_mult0( wghts[j], *p_cb ), tmp ) ); + p_cb++; + } + IF( LT_32( dist, min_dist ) ) + { + min_dist = dist; + move16(); /*Q-4 */ + idx_cv = i; + move16(); + } + } + + /* calculate difference */ + FOR( i = 0; i < M; i++ ) + { + dd[i] = sub( lsf[i], CNG_SN1_fx[idx_cv * M + i] ); /*x2.56 */ + move16(); + } + + /* quantize the difference with LVQ */ + /* MSVQ_ROM to be updated */ + mslvq_cng_ivas_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); + + index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, 0 ); + Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); + + /* write the VQ index to the bitstream */ + push_indice_fx( hBstr, IND_ISF_0_0, idx_cv, 4 ); + + /* write the LVQ index to the bitstream */ + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[0], LEN_INDICE ); + push_indice_fx( hBstr, IND_ISF_0_1, idx_lvq[1], LSF_BITS_CNG - 4 - LEN_INDICE ); + + return; +} +/*-------------------------------------------------------------------* + * qlsf_Mode_Select_fx() + * + * Mode selection for LSF quantizer + *-------------------------------------------------------------------*/ + + +static Word16 qlsf_Mode_Select_fx( + const Word16 *w, /* i : weighting vector Q8 */ + const Word16 *pred1, /* i : prediction vector x2.56 */ + const Word16 streaklimit, /* i : predictive streak limit Q15 */ + const Word32 op_loop_thr /* i : Open-loop Threshold */ +) +{ + Word16 pred_pow2[M]; + Word32 temp32, En = 0; + Word16 safety_net; + Word16 i, cs, cl; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* calculate the prediction residual */ + cl = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + cl = s_max( cl, abs_s( pred1[i] ) ); + } + cs = norm_s( cl ); + En = 0; + move16(); + FOR( i = 0; i < M; i++ ) + { + pred_pow2[i] = shl( pred1[i], cs ); + move16(); +#ifdef BASOP_NOGLOB + En = L_mac_o( En, mult( pred_pow2[i], shl_o( w[i], 2, &Overflow ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */ +#else /* BASOP_NOGLOB */ + En = L_mac( En, mult( pred_pow2[i], shl( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */ +#endif /* BASOP_NOGLOB */ } cs = shl( cs, 1 ); @@ -543,11 +895,630 @@ static Word16 qlsf_Mode_Select_fx( /* _ (Word16*) qlsf : quantized LSFs in the cosine domain x2.56 */ /*------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void lsf_end_enc_fx( +/*------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*========================================================================*/ +void lsf_end_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16 *lpc_param, + Word16 *no_indices, + Word16 *bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +#endif +) +{ + Word16 i; + Word16 Idx0[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for safety-net quantizer */ + Word16 Idx1[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for predictive quantizer */ + Word16 indice[MAX_VQ_STAGES + 3]; /* Temp. array of indice for vector de-quantizer */ + Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ + Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; + const Word16 *Bit_alloc1 = NULL; + Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ + Word16 Tmp[M]; /* Temporary target vector (mean and prediction removed) */ + Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean) */ + Word16 pred1[M]; /* Prediction for the predictive quantizer */ + Word16 pred2[M]; /* Prediction for the predictive quantizer */ + Word16 wghts[M]; /* Weighting used for quantizer (currently GSM based) */ + Word16 stages0; /* Amount of stages used by safety-net quantizer */ + Word16 stages1; /* Amount of stages used by predictive quantizer */ + Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer */ + Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer */ + Word16 predmode; /* 0: safety-net only, 1: predictive only, 2: best of the two */ + Word16 safety_net, cumleft, num_bits; + Word16 *Idx, stages, *bits; + Word16 Tmp2[M], Tmp1[M]; + Word32 abs_threshold; /* Absolute threshold depending on signal bandwidth, that indicates + very good perceptual LSF quantization performance */ + Word16 lsfq[M * 2], resq[M * 2]; + Word16 coder_type; /* coder type (from LSF quantizer point of view) */ + Word16 nBits; /* Number of bits */ + Word16 TCQIdx0[M + 2]; /* Optimal codebook indices for VQ-TCQ quantizer */ + Word16 *TCQIdx; + Word16 tmp; + Word16 flag_1bit_gran; + BSTR_ENC_HANDLE hBstr = st->hBstr; +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + Word16 pred3[M]; + Word16 dummy, dummy_v[5]; +#endif + + flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + + nBits = nBits_in; + move16(); + /* Update LSF coder_type for LSF quantizer for some special cases */ + test(); + test(); + test(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ +#else + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) +#endif + { + IF( EQ_16( coder_type_raw, VOICED ) ) + { + coder_type = VOICED; + move16(); /* Reflect Inactive mode */ + if ( EQ_16( flag_1bit_gran, 1 ) ) + { + nBits = sub( nBits, 1 ); /* This is for real Generic*/ + } + } + ELSE + { + nBits = sub( nBits, 1 ); /* This is for real Generic*/ + coder_type = coder_type_org; + move16(); + } + } + ELSE + { + coder_type = coder_type_org; + move16(); + } + + /*----------------------------------------------------------------------------------- -* + * Calculate the number of stages and levels for each stage based on allowed bit budget + * Set absolute threshold for codebook-type decision logic depending on signal bandwidth + *------------------------------------------------------------------------------------ -*/ + IF( EQ_16( st->bwidth, NB ) ) + { + abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); + } + ELSE + { + abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); + } + /* Calculate LSF weighting coefficients */ + Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); + + /*--------------------------------------------------------------------------------* + * LSF quantization of SID frames + *--------------------------------------------------------------------------------*/ + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + sort_fx( qlsf, 0, M - 1 ); + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); + + return; + } + /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ + find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); + + /*----------------------------------------------------------------* + * Calculate number of stages and levels for each stage based on the allowed bit allocation + * (subtract one bit for LSF predictor selection) + *----------------------------------------------------------------*/ + lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + + + /*--------------------------------------------------------------------------------* + * LSF quantization of all other frames but SID frames + * Select safety-net or predictive mode + *--------------------------------------------------------------------------------*/ + + Err[0] = MAXINT32; + move32(); + Err[1] = MAXINT32; + move32(); + /* for mem_MA update */ + FOR( i = 0; i < M; i++ ) + { + pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + move16(); + } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + { + /* if secondary channel predmode is set to be > 2 */ + predmode += 3; + + tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + } +#endif + IF( predmode == 0 ) + { + /* Subtract only mean */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Vr_subt( lsf, pred0, Tmp, M ); + + /* LVQ quantization (safety-net only) */ + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + safety_net = 1; + move16(); + st->pstreaklen = 0; + move16(); /* predictive LSF quantizer streak is ended with safety-net */ + } + ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ + { + Vr_subt( lsf, pred1, Tmp1, M ); + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + + safety_net = 0; + move16(); + } + ELSE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) + { + if ( predmode == 2 ) +#endif + { + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + test(); + test(); + test(); + IF( ( ( GT_16( st->pstreaklen, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); + move16(); + } + + IF( st->pstreaklen == 0 ) + { + /* reset the consecutive AR-predictor multiplier */ + st->streaklimit_fx = 32767; /*1.0 in Q15 */ + move16(); + } + + /* VOICED_WB@16kHz */ + test(); + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) + { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); + Tmp2[i] = sub( Tmp[i], pred2[i] ); + pred2[i] = add( pred2[i], pred0[i] ); + } + + /* select safety_net or predictive */ + safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); + IF( EQ_16( force_sf, 1 ) ) + { + safety_net = 1; + move16(); + } + + IF( safety_net ) + { + /* Safety-net - BC-TCQ quantization : SN */ + Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); + st->pstreaklen = 0; + move16(); + } + ELSE + { + /* predictive - BC-TCQ quantization : AR */ + Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); + st->pstreaklen = add( st->pstreaklen, 1 ); + } + } + /* all other frames (not VOICED@16kHz) */ + ELSE + { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp2[i] = sub( lsf[i], pred2[i] ); + } + + /* safety-net */ + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + /* Predictive quantizer is calculated only if it can be selected */ + test(); + IF( !force_sf || GT_32( Err[0], abs_threshold ) ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + } + test(); + test(); + /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: + if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected + or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. + or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ + IF( force_sf || LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) || LT_32( Err[0], abs_threshold ) ) + { + safety_net = 1; + move16(); + st->pstreaklen = 0; + move16(); /* Reset the consecutive predictive frame counter */ + } + ELSE + { + safety_net = 0; + move16(); /* Increase the consecutive predictive frame counter by one */ + st->pstreaklen = add( st->pstreaklen, 1 ); + } + } + } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) + else /* of "if (predmode==2)" */ + { + mvr2r( ModeMeans[mode_lvq], pred0, M ); + + if ( predmode == 4 ) + { + mode_lvq_p = 9; /* force to Generic WB with AR*/ + } + + for ( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * ( st->mem_AR[i] - pred0[i] ); + Tmp[i] = lsf[i] - pred2[i]; + Tmp2[i] = lsf[i] - pred3[i]; + } + + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + if ( st->pstreaklen > ( STREAKLEN ) ) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + st->streaklimit *= STREAKMULT; + } + + if ( st->pstreaklen == 0 ) + { + /* reset the adaptive scaling factor */ + st->streaklimit = 1.0f; + } + + /* intra pred */ + /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ + + lsf_allocate( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); + + Err[0] = vq_lvq_lsf_enc( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); + + if ( force_sf ) + { + safety_net = 1; /* intra-frame prediction */ + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { /* try also the inter frame prediction */ + + /* AR inter-frame prediction */ + lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); + + + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); + + if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) + { + safety_net = 1; + st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { + safety_net = 0; + ( st->pstreaklen )++; /* Increase the consecutive predictive frame counter by one */ + } + } + } + } +#endif /*--------------------------------------------------------------------------* \ + * Write indices to array \ + *--------------------------------------------------------------------------*/ + + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) + { + /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ + test(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && ( st->idchan == 0 ) ) +#else + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) +#endif + { + /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ + push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); + } + + /* write predictor selection bit */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( GE( predmode, 2 ) ) +#else + IF( EQ_16( predmode, 2 ) ) +#endif + { + push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); + } + + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + TCQIdx = &TCQIdx0[1]; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; + FOR( i = 0; i < ( M / 2 ) + 3; i++ ) + { + push_indice_fx( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i] ); + } + } + ELSE + { + cumleft = nBits; + move16(); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( GE( predmode, 2 ) ) +#else + IF( EQ_16( predmode, 2 ) ) +#endif + { + /* subtract predictor selection bit */ + cumleft = sub( nBits, 1 ); + } + + IF( safety_net ) + { + stages = stages0; + move16(); + Idx = Idx0; + move16(); + bits = bits0; + move16(); + } + ELSE + { + stages = stages1; + move16(); + Idx = Idx1; + move16(); + bits = bits1; + move16(); + } + + tmp = sub( stages, 1 ); + FOR( i = 0; i < tmp; i++ ) + { + indice[i] = Idx[i]; + move16(); + num_bits = bits[i]; + move16(); + cumleft -= num_bits; + move16(); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); + } + + WHILE( cumleft > 0 ) + { + indice[i] = Idx[i]; + move16(); + + IF( GT_16( cumleft, LEN_INDICE ) ) + { + num_bits = LEN_INDICE; + move16(); + } + ELSE + { + num_bits = cumleft; + move16(); + } + + cumleft = sub( cumleft, num_bits ); + push_indice_fx( hBstr, IND_LSF, indice[i], num_bits ); + i = add( i, 1 ); + } + } + } + ELSE + { + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + /* Number of quantization indices */ + *no_indices = 10; + move16(); + FOR( i = 0; i < *no_indices; i++ ) + { + lpc_param[i] = TCQIdx0[i]; + move16(); + bits_param_lpc[i] = BC_TCVQ_BIT_ALLOC_40B[i]; + move16(); + } + } + ELSE + { + /* Number of quantization indices */ + + /* there are 31 bits */ + IF( EQ_16( safety_net, 1 ) ) + { + Idx = Idx0; + move16(); + *no_indices = add( stages0, 1 ); + FOR( i = 0; i < stages0; i++ ) + { + lpc_param[i] = Idx[i]; + move16(); + indice[i] = Idx[i]; + move16(); + bits_param_lpc[i] = bits0[i]; + move16(); + } + lpc_param[stages0] = Idx[stages0]; + move16(); + indice[stages0] = Idx[stages0]; + move16(); + tmp = sub( stages0, 1 ); + bits_param_lpc[tmp] = LEN_INDICE; + move16(); + bits_param_lpc[stages0] = sub( bits0[tmp], LEN_INDICE ); + } + ELSE + { + *no_indices = add( stages1, 1 ); + Idx = Idx1; + move16(); + FOR( i = 0; i < stages1; i++ ) + { + lpc_param[i] = ( Idx[i] ); + move16(); + indice[i] = Idx[i]; + move16(); + bits_param_lpc[i] = bits1[i]; + move16(); + } + lpc_param[stages1] = ( Idx[stages1] ); + move16(); + indice[stages1] = Idx[stages1]; + move16(); + tmp = sub( stages1, 1 ); + bits_param_lpc[tmp] = LEN_INDICE; + move16(); + bits_param_lpc[stages1] = sub( bits1[tmp], LEN_INDICE ); + } + IF( EQ_16( predmode, 2 ) ) + { + FOR( i = *no_indices; i > 0; i-- ) + { + tmp = sub( i, 1 ); + lpc_param[i] = lpc_param[tmp]; + move16(); + bits_param_lpc[i] = bits_param_lpc[tmp]; + move16(); + } + lpc_param[0] = safety_net; + move16(); /* put the safety net info on the last param */ + bits_param_lpc[0] = 1; + move16(); + *no_indices = add( *no_indices, 1 ); + } + } + } + + + /*--------------------------------------------------------------------------* + * De-quantize encoded LSF vector + *--------------------------------------------------------------------------*/ + + IF( safety_net ) + { + /* Safety-net */ + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCQ */ + Copy( lsfq, st->mem_MA_fx, M ); + Vr_add( lsfq, pred0, qlsf, M ); + } + ELSE + { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL + if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + { + /* intra mode*/ + vq_dec_lvq( 0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); + v_add( qlsf, pred3, qlsf, M ); + v_sub( qlsf, pred1, st->mem_MA, M ); + } + else +#endif + { + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + Vr_add( qlsf, pred0, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + } + } + } + ELSE + { + test(); + IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) + { + /* BC-TCVQ */ + Copy( lsfq, st->mem_MA_fx, M ); + Vr_add( lsfq, pred2, qlsf, M ); + } + ELSE + { + /* LVQ */ + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + IF( EQ_16( predmode, 1 ) ) + { + Copy( qlsf, st->mem_MA_fx, M ); + Vr_add( qlsf, pred1, qlsf, M ); + } + ELSE + { + Vr_add( qlsf, pred2, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + } + } + } + + /* Sort the quantized vector to ascending order */ + sort_fx( qlsf, 0, M - 1 ); + + /* Verify stability by adding minimum separation */ + reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); + + /* Update AR-predictor memories */ + Copy( qlsf, st->mem_AR_fx, M ); + return; +} + +void lsf_end_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ Word16 *qlsf, /* o : quantized LSF */ @@ -559,10 +1530,8 @@ void lsf_end_enc_fx( Word16 *no_indices, Word16 *bits_param_lpc, Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ -#endif ) { Word16 i; @@ -596,10 +1565,8 @@ void lsf_end_enc_fx( Word16 tmp; Word16 flag_1bit_gran; BSTR_ENC_HANDLE hBstr = st->hBstr; -#ifdef LSF_RE_USE_SECONDARY_CHANNEL Word16 pred3[M]; Word16 dummy, dummy_v[5]; -#endif flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); @@ -609,11 +1576,8 @@ void lsf_end_enc_fx( test(); test(); test(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL + IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ -#else - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) -#endif { IF( EQ_16( coder_type_raw, VOICED ) ) { @@ -657,7 +1621,7 @@ void lsf_end_enc_fx( *--------------------------------------------------------------------------------*/ IF( EQ_32( st->core_brate, SID_2k40 ) ) { - lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); + lsfq_CNG_ivas_fx( hBstr, lsf, wghts, qlsf ); sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); @@ -688,16 +1652,16 @@ void lsf_end_enc_fx( pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); move16(); } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + IF( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ predmode += 3; - tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } -#endif + IF( predmode == 0 ) { /* Subtract only mean */ @@ -705,42 +1669,49 @@ void lsf_end_enc_fx( Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, - st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); safety_net = 1; move16(); - st->pstreaklen_fx = 0; + st->pstreaklen = 0; move16(); /* predictive LSF quantizer streak is ended with safety-net */ } ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ { Vr_subt( lsf, pred1, Tmp1, M ); - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); safety_net = 0; move16(); } ELSE -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) { - if ( predmode == 2 ) -#endif + IF( EQ_16( predmode, 2 ) ) { + /* Subtract mean and AR prediction */ + Copy( ModeMeans_fx[mode_lvq], pred0, M ); + + /* subtract only mean */ + Vr_subt( lsf, pred0, Tmp, M ); + + FOR( i = 0; i < M; i++ ) + { + /* subtract mean and AR prediction */ + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp2[i] = sub( lsf[i], pred2[i] ); + } /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ test(); test(); test(); - IF( ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen_fx, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) + IF( ( ( GT_16( st->pstreaklen, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) { /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); move16(); } - IF( st->pstreaklen_fx == 0 ) + IF( st->pstreaklen == 0 ) { /* reset the consecutive AR-predictor multiplier */ st->streaklimit_fx = 32767; /*1.0 in Q15 */ @@ -751,19 +1722,6 @@ void lsf_end_enc_fx( test(); IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); - Tmp2[i] = sub( Tmp[i], pred2[i] ); - pred2[i] = add( pred2[i], pred0[i] ); - } - /* select safety_net or predictive */ safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); IF( EQ_16( force_sf, 1 ) ) @@ -776,39 +1734,27 @@ void lsf_end_enc_fx( { /* Safety-net - BC-TCQ quantization : SN */ Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); - st->pstreaklen_fx = 0; + st->pstreaklen = 0; move16(); } ELSE { /* predictive - BC-TCQ quantization : AR */ Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); - st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); + st->pstreaklen = add( st->pstreaklen, 1 ); } } /* all other frames (not VOICED@16kHz) */ ELSE { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); - Tmp2[i] = sub( lsf[i], pred2[i] ); - } - /* safety-net */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); /* Predictive quantizer is calculated only if it can be selected */ test(); IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); } test(); test(); @@ -820,77 +1766,71 @@ void lsf_end_enc_fx( { safety_net = 1; move16(); - st->pstreaklen_fx = 0; + st->pstreaklen = 0; move16(); /* Reset the consecutive predictive frame counter */ } ELSE { safety_net = 0; move16(); /* Increase the consecutive predictive frame counter by one */ - st->pstreaklen_fx = add( st->pstreaklen_fx, 1 ); + st->pstreaklen = add( st->pstreaklen, 1 ); } } } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - PMT( "LSF_RE_USE_SECONDARY_CHANNEL CODE IS MISSING " ) - else /* of "if (predmode==2)" */ + ELSE /* of "if (predmode==2)" */ { - mvr2r( ModeMeans[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); - if ( predmode == 4 ) + IF( EQ_16( predmode, 4 ) ) { mode_lvq_p = 9; /* force to Generic WB with AR*/ } - for ( i = 0; i < M; i++ ) + FOR( i = 0; i < M; i++ ) { /* subtract mean and AR prediction */ - pred2[i] = pred0[i] + Predictors[mode_lvq_p][i] * ( st->mem_AR[i] - pred0[i] ); - Tmp[i] = lsf[i] - pred2[i]; - Tmp2[i] = lsf[i] - pred3[i]; + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + Tmp[i] = sub( lsf[i], pred2[i] ); + Tmp2[i] = sub( lsf[i], pred3[i] ); } /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in - case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - if ( st->pstreaklen > ( STREAKLEN ) ) + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + IF( GT_16( st->pstreaklen, ( STREAKLEN ) ) ) { /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - st->streaklimit *= STREAKMULT; + st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); + move16(); } - if ( st->pstreaklen == 0 ) + IF( EQ_16( st->pstreaklen, 0 ) ) { /* reset the adaptive scaling factor */ - st->streaklimit = 1.0f; + st->streaklimit_fx = 32767; } /* intra pred */ /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ - lsf_allocate( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); - - Err[0] = vq_lvq_lsf_enc( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); - - if ( force_sf ) + lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); + Err[0] = vq_lvq_lsf_enc_ivas_fx( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); + IF( force_sf ) { safety_net = 1; /* intra-frame prediction */ st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ } - else + ELSE { /* try also the inter frame prediction */ /* AR inter-frame prediction */ - lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); - - - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); - - if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) + lsf_allocate_fx( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); + IF( LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) ) { safety_net = 1; st->pstreaklen = 0; /* Reset the consecutive predictive frame counter */ } - else + ELSE { safety_net = 0; ( st->pstreaklen )++; /* Increase the consecutive predictive frame counter by one */ @@ -898,30 +1838,22 @@ void lsf_end_enc_fx( } } } -#endif /*--------------------------------------------------------------------------* \ - * Write indices to array \ - *--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------* + * Write indices to array + *--------------------------------------------------------------------------*/ IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) { /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ test(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && ( st->idchan == 0 ) ) -#else - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) -#endif { /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ push_indice_fx( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); } /* write predictor selection bit */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF( GE( predmode, 2 ) ) -#else - IF( EQ_16( predmode, 2 ) ) -#endif + IF( GE_16( predmode, 2 ) ) { push_indice_fx( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); } @@ -941,11 +1873,7 @@ void lsf_end_enc_fx( { cumleft = nBits; move16(); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - IF( GE( predmode, 2 ) ) -#else - IF( EQ_16( predmode, 2 ) ) -#endif + IF( GE_16( predmode, 2 ) ) { /* subtract predictor selection bit */ cumleft = sub( nBits, 1 ); @@ -1108,20 +2036,16 @@ void lsf_end_enc_fx( } ELSE { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + IF( EQ_16( st->tdm_LRTD_flag, 0 ) && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ - vq_dec_lvq( 0, qlsf, &indice[0], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); - v_add( qlsf, pred3, qlsf, M ); - v_sub( qlsf, pred1, st->mem_MA, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages0, M, 9, levels0[stages0 - 1] ); + Vr_add( qlsf, pred3, qlsf, M ); } - else -#endif + ELSE { - vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -1139,9 +2063,7 @@ void lsf_end_enc_fx( ELSE { /* LVQ */ - vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); IF( EQ_16( predmode, 1 ) ) { Copy( qlsf, st->mem_MA_fx, M ); @@ -1166,7 +2088,6 @@ void lsf_end_enc_fx( return; } - /*-------------------------------------------------------------------* * first_VQstages() * @@ -1358,30 +2279,151 @@ static void first_VQstages( cs = add( cs, stagesVQ ); } - m = maxC; + m = maxC; + move16(); + } + + Copy( indices[1], indices_VQstage, maxC * stagesVQ ); + + return; +} + +/*--------------------------------------------------------------------------- + * vq_enc_lsf_lvq() + * + * Multi-stage VQ encoder for LSF quantization. Trained codebooks are used in initial stages + * and lattice-VQ quantization is applied on residual vector in other stages. + * + * Note: + * Compared to normal multistage VQ resulting LSF vector is reordered to ascending order before + * weighted error calculation (spectral distortion) at the final stage. + * + * Returns: + * Weighted error + *--------------------------------------------------------------------------*/ + +static Word32 vq_lvq_lsf_enc( + Word16 pred_flag, + Word16 mode, + Word16 u[], + Word16 *levels, + Word16 stages, + Word16 w[], + Word16 Idx[], + const Word16 *lsf, + const Word16 *pred, + Word32 p_offset_scale1[][MAX_NO_SCALES + 1], + Word32 p_offset_scale2[][MAX_NO_SCALES + 1], + Word16 p_no_scales[][2], + Word16 *resq, + Word16 *lsfq ) +{ + Word16 i; + const Word16 *const *cb, *cb_stage; + Word16 cand[LSFMBEST][M]; + Word16 maxC = LSFMBEST, stagesVQ; + Word16 mode_glb, j, indices_firstVQ[LSFMBEST * MAX_VQ_STAGES], c2; + Word32 e[LSFMBEST], L_tmp, L_ftmp; + Word16 quant[LSFMBEST][M], diff[M], dd[M]; + Word16 lat_cv[LSFMBEST][M]; + Word16 idx_lead[LSFMBEST][2], idx_scale[LSFMBEST][2]; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + stagesVQ = sub( stages, 1 ); + /* Codebook selection */ + IF( pred_flag == 0 ) /* safety net*/ + { + cb = &Quantizers_fx[CB_lsf[mode]]; + move16(); + mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( levels[stagesVQ], min_lat_bits_SN_fx[mode] )] ); + } + ELSE /* predictive */ + { + cb = &Quantizers_p_fx[CB_p_lsf[mode]]; + move16(); + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + } + IF( stagesVQ > 0 ) + { + /* first VQ stages */ + first_VQstages( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); + } + + + FOR( i = 0; i < maxC; i++ ) + { + Copy( pred, cand[i], M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[i * stagesVQ + j]; + move16(); + } + + FOR( j = 0; j < stagesVQ; j++ ) + { + cb_stage = cb[j]; + move16(); + Vr_add( cand[i], cb_stage + Idx[j] * M, cand[i], M ); + } + + /* LVQ quantization */ + Vr_subt( lsf, cand[i], dd, M ); + mslvq_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag, p_no_scales ); + Vr_add( cand[i], quant[i], cand[i], M ); + + /* arrange the LSF candidate vector prior to selection to an ascending order*/ + sort_fx( cand[i], 0, M - 1 ); + + /* calculate the spectral distortion using weighted MSE of sorted LSF vector*/ + Vr_subt( cand[i], lsf, diff, M ); + FOR( j = 0; j < M; j++ ) + { +#ifdef BASOP_NOGLOB + diff[j] = shl_o( diff[j], 4, &Overflow ); +#else /* BASOP_NOGLOB */ + diff[j] = shl( diff[j], 4 ); +#endif /* BASOP_NOGLOB */ + move16(); + } +#ifdef BASOP_NOGLOB + L_tmp = L_mult( mult( diff[0], shl_o( w[0], 1, &Overflow ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#else + L_tmp = L_mult( mult( diff[0], shl( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#endif + FOR( j = 1; j < M; j++ ) + { +#ifdef BASOP_NOGLOB + L_tmp = L_mac( L_tmp, mult( diff[j], shl_o( w[j], 1, &Overflow ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#else + L_tmp = L_mac( L_tmp, mult( diff[j], shl( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ +#endif + } + e[i] = L_tmp; + move32(); + } + + /* find the optimal candidate */ + c2 = minimum_32_fx( e, maxC, &L_ftmp ); + set16_fx( resq, 0, M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[c2 * stagesVQ + j]; + move16(); + cb_stage = cb[j]; move16(); + Vr_add( resq, cb_stage + Idx[j] * M, resq, M ); } + Vr_add( resq, quant[c2], resq, M ); /* quantized prediction residual */ + Copy( cand[c2], lsfq, M ); + index_lvq_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], + &p_offset_scale1[0][0], &p_offset_scale2[0][0], &p_no_scales[0][0] ); - Copy( indices[1], indices_VQstage, maxC * stagesVQ ); - - return; + return e[c2]; } -/*--------------------------------------------------------------------------- - * vq_enc_lsf_lvq() - * - * Multi-stage VQ encoder for LSF quantization. Trained codebooks are used in initial stages - * and lattice-VQ quantization is applied on residual vector in other stages. - * - * Note: - * Compared to normal multistage VQ resulting LSF vector is reordered to ascending order before - * weighted error calculation (spectral distortion) at the final stage. - * - * Returns: - * Weighted error - *--------------------------------------------------------------------------*/ - -static Word32 vq_lvq_lsf_enc( +static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], @@ -1391,9 +2433,6 @@ static Word32 vq_lvq_lsf_enc( Word16 Idx[], const Word16 *lsf, const Word16 *pred, - Word32 p_offset_scale1[][MAX_NO_SCALES + 1], - Word32 p_offset_scale2[][MAX_NO_SCALES + 1], - Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ) { @@ -1415,15 +2454,32 @@ static Word32 vq_lvq_lsf_enc( IF( pred_flag == 0 ) /* safety net*/ { cb = &Quantizers_fx[CB_lsf[mode]]; - move16(); - mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( levels[stagesVQ], min_lat_bits_SN_fx[mode] )] ); + IF( LT_16( mode, 6 ) ) + { + move16(); + mode_glb = add( offset_lvq_modes_SN[mode], offset_in_lvq_mode_SN[mode][sub( levels[stagesVQ], min_lat_bits_SN[mode] )] ); + } + ELSE + { + move16(); + mode_glb = add( offset_lvq_modes_SN[mode], levels[stagesVQ] - min_lat_bits_SN[mode] ); + } } ELSE /* predictive */ { cb = &Quantizers_p_fx[CB_p_lsf[mode]]; - move16(); - mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + IF( LT_16( mode, 6 ) || EQ_16( mode, 12 ) ) + { + move16(); + mode_glb = add( offset_lvq_modes_pred[mode], offset_in_lvq_mode_pred[mode][sub( levels[stagesVQ], min_lat_bits_pred_fx[mode] )] ); + } + ELSE + { + move16(); + mode_glb = sub( add( offset_lvq_modes_pred[mode], levels[stagesVQ] ), min_lat_bits_pred_fx[mode] ); + } } + IF( stagesVQ > 0 ) { /* first VQ stages */ @@ -1449,7 +2505,7 @@ static Word32 vq_lvq_lsf_enc( /* LVQ quantization */ Vr_subt( lsf, cand[i], dd, M ); - mslvq_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag, p_no_scales ); + mslvq_ivas_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag ); Vr_add( cand[i], quant[i], cand[i], M ); /* arrange the LSF candidate vector prior to selection to an ascending order*/ @@ -1496,12 +2552,10 @@ static Word32 vq_lvq_lsf_enc( } Vr_add( resq, quant[c2], resq, M ); /* quantized prediction residual */ Copy( cand[c2], lsfq, M ); - index_lvq_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], - &p_offset_scale1[0][0], &p_offset_scale2[0][0], &p_no_scales[0][0] ); + index_lvq_ivas_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], pred_flag ); return e[c2]; } - static void BcTcvq_1st_fx( Word16 x_fx[][2], /*x2.56*/ const Word16 CB_fx[][128][2], /*x2.56*/ @@ -2604,3 +3658,198 @@ static void lsf_mid_enc_fx( return; } + +static void lsf_mid_enc_ivas_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 nb_bits, /* i : number of bits */ + const Word32 int_fs, /* i : internal (ACELP) sampling frequency*/ + const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ + const Word16 qlsp1[], /* i : quantized LSPs from frame end */ + Word16 lsp[], /* i/o: mid-frame LSP */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + Word32 Bin_Ener[], /* i : per bin log energy spectrum */ + Word16 Q_ener, /* i : Q value of Bin_ener */ + Word16 ppp_mode, + Word16 nelp_mode ) +{ + Word16 lsf[M], qlsf[M], qlsf1[M], qlsf0[M], wghts[M]; + Word32 err, err_min; + Word16 j, k, idx, size = 0; +#if 0 + Word32 Bin_Ener_mid[L_FFT/2]; +#endif + Word32 L_tmp; + Word16 tmp, k1; + const Word16 *ratio = NULL; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /* convert LSPs to LSFs */ + lsp2lsf_fx( lsp, lsf, M, int_fs ); + lsp2lsf_fx( qlsp0, qlsf0, M, int_fs ); + lsp2lsf_fx( qlsp1, qlsf1, M, int_fs ); + + /* LSF weighting */ + Unified_weighting_fx( Bin_Ener, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); + move16(); + /* codebook selection, number of bits, size of the codebook */ + test(); + IF( ppp_mode == 0 && nelp_mode == 0 ) + { + /* codebook selection */ + IF( EQ_16( coder_type, VOICED ) ) + { + SWITCH( nb_bits ) + { + case 5: + { + ratio = tbl_mid_voi_wb_5b_fx; + move16(); + BREAK; + } + case 4: + { + ratio = tbl_mid_voi_wb_4b_fx; + move16(); + BREAK; + } + case 1: + { + ratio = tbl_mid_voi_wb_1b_fx; + move16(); + BREAK; + } + } + } + ELSE IF( EQ_16( coder_type, UNVOICED ) ) + { + ratio = tbl_mid_unv_wb_5b_fx; + } + ELSE + { + /* GENERIC, TRANSITION, AUDIO and INACTIVE */ + SWITCH( nb_bits ) + { + case 5: + { + ratio = tbl_mid_gen_wb_5b_fx; + move16(); + BREAK; + } + case 4: + { + ratio = tbl_mid_gen_wb_4b_fx; + move16(); + BREAK; + } + case 2: + { + ratio = tbl_mid_gen_wb_2b_fx; + move16(); + BREAK; + } + } + } + + size = (Word16) pow2[nb_bits]; + move16(); + } + ELSE IF( EQ_16( ppp_mode, 1 ) ) + { + ratio = tbl_mid_voi_wb_1b_fx; + move16(); + nb_bits = 1; + move16(); + size = 2; + move16(); + } + ELSE IF( EQ_16( nelp_mode, 1 ) ) + { + ratio = tbl_mid_unv_wb_4b_fx; + move16(); + nb_bits = 4; + move16(); + size = 16; + move16(); + } + + /* loop over codevectors */ + err_min = MAXINT32; + move16(); + idx = 0; + move16(); + k1 = 0; + move16(); + FOR( k = 0; k < size; k++ ) + { + err = L_deposit_l( 0 ); + + FOR( j = 0; j < M; j++ ) + { + /* qlsf[j] = (1.0f - ratio[k*M+j]) * qlsf0[j] + ratio[k*M+j] * qlsf1[j]; */ + L_tmp = L_mult( sub( 0x2000, ratio[k1 + j] ), qlsf0[j] ); + L_tmp = L_mac( L_tmp, ratio[k1 + j], qlsf1[j] ); + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); + + test(); + test(); + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) + { + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + move16(); + } + + tmp = sub( lsf[j], qlsf[j] ); + /* err += wghts[j] * ftemp * ftemp; */ + /* tmp is usually very small, we can have some extra precision with very rare saturation */ +#ifdef BASOP_NOGLOB + tmp = shl_o( tmp, 4, &Overflow ); + tmp = mult_ro( tmp, tmp, &Overflow ); + err = L_mac_o( err, tmp, shl_o( wghts[j], 2, &Overflow ), &Overflow ); +#else /* BASOP_NOGLOB */ + tmp = shl( tmp, 4 ); + tmp = mult_r( tmp, tmp ); + err = L_mac( err, tmp, shl( wghts[j], 2 ) ); +#endif + } + /* err = L_shl(err,Wscale); */ + err = Mult_32_16( err, LSF_1_OVER_256SQ ); + /* err = Mult_32_16(err,Wmult); */ + + IF( LT_32( err, err_min ) ) + { + err_min = L_add( err, 0 ); + idx = k; + move16(); + } + k1 += M; + move16(); + } + + /* calculate the quantized LSF vector */ + FOR( j = 0; j < M; j++ ) + { + /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ + L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); + L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); + qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); + + test(); + test(); + IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) + { + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + move16(); + } + } + + reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); + + /* convert LSFs back to LSPs */ + lsf2lsp_fx( qlsf, lsp, M, int_fs ); + push_indice_fx( hBstr, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); + + return; +} diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index bf58e50406522413a49ee7f45c9ea9a6f84a52d2..fdb1ab0fc1a1dca2f7340871ecfde7e7e9b78058 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -11,8 +11,7 @@ #include "rom_com.h" #include "rom_enc.h" #include "basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index 797b21829ad66b1f5aa000114013e9ab11c7cbd7..5006202735a83f73d36e283c25e466b855296137 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -9,8 +9,7 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index 63f9c78be3bb3abdec24b20256bb9648c6fea926..dc938766bd6c77053296139df471f7b27195394b 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index d2e0b980c484319e07e5ae952165e058fed4740f..bb9de2fb922fb6395e55364847e3d7d5a56139ca 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index b683155060e3766dd9b9f45ea8d47e3994233e0f..c5a3e6bb753118c84a3f4e8bddd2e8086ba15877 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -7,8 +7,9 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot.h" /* Function prototypes */ +#include "basop32.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -17,6 +18,7 @@ *-----------------------------------------------------------------*/ static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, Word16 no_scales, const Word16 *no_lead ); +static Word32 quantize_data_ivas_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, const Word16 *no_lead ); static Word32 q_data_fx( Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, Word16 *p_no_scales, const Word16 *p_no_lead ); static void prepare_data_fx( Word16 *xsort, Word16 *sign, Word16 *data, Word32 *w, const Word16 *w_in, const Word16 *sigma, const Word16 *inv_sigma, Word16 *p_sig ); static Word32 calculate_min_dist_fx( Word16 cv_pot[LATTICE_DIM], Word16 no_scales, const Word16 *scale, const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, Word16 sig, Word16 *indx ); @@ -86,6 +88,122 @@ Word32 mslvq_fx( return dist; } + +Word32 mslvq_ivas_fx( + Word16 *pTmp, /* i : M-dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization Q10*/ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ +) +{ + Word32 dist, L_tmp; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + Word16 tmp, tmp1, i; + + dist = L_deposit_l( 0 ); + move16(); + + IF( EQ_16( pred_flag, 0 ) ) + { + p_sigma = sigma_MSLVQ_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + p_scales = scales_ivas_fx[mode_glb]; + tmp = no_lead_idx[mode_glb][0]; + tmp1 = no_lead_idx[mode_glb][1]; + IF( LE_16( tmp, LIMIT_LEADER ) && ( LT_16( tmp, sub( tmp1, 2 ) ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = leaders_short[tmp][i]; + p_no_lead[i + MAX_NO_SCALES] = leaders_short[tmp1][i]; + } + } + ELSE + { + IF( GE_16( pred_flag, 5 ) ) + { + /* assert( pred_flag >= 12 && pred_flag <= 15 ); */ + /* pred_flag is here the number of bits for MSLVQ */ + + p_sigma = &sigma_BWE16_fx[mode_glb * LATTICE_DIM]; + + /* inverse sigma is precomputed to save complexity */ +#if 1 // Pointing to wrong table, due to warning + p_inv_sigma = &sigma_BWE16_fx[mode_glb * LATTICE_DIM]; +#endif + + IF( EQ_16( mode_glb, 0 ) ) + { + p_scales = &scales_BWE_fx[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = no_lead_BWE[add( i, i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 ) )]; + } + } + ELSE + { + p_scales = &scales_BWE_3b_fx[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = no_lead_BWE_3b[add( i, i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 ) )]; + } + } + } + ELSE + { + p_sigma = sigma_p_fx[mode]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_fx[mode]; + p_scales = scales_p_ivas_fx[mode_glb]; + + tmp = no_lead_p_idx[mode_glb][0]; + tmp1 = no_lead_p_idx[mode_glb][1]; + + IF( LE_16( tmp, LIMIT_LEADER ) && ( LT_16( tmp, sub( tmp1, 2 ) ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + + IF( EQ_16( tmp, LIMIT_LEADER ) && EQ_16( tmp1, 0 ) ) + { + tmp = add( tmp, DELTA_LEADER ); + tmp1 = add( tmp1, DELTA_LEADER ); + } + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = leaders_short[tmp][i]; + p_no_lead[i + MAX_NO_SCALES] = leaders_short[tmp1][i]; + } + } + } + + /* first subvector */ + dist = quantize_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + IF( LT_16( pred_flag, 5 ) ) + { + /* second subvector */ + L_tmp = quantize_data_ivas_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, + cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + } + + return dist; +} /*-----------------------------------------------------------------* * q_data() * @@ -121,6 +239,33 @@ static Word32 q_data_fx( return dist; } +static Word32 q_data_ivas_fx( + Word16 *pTmp1, /* i: M-dimensional input vector x2.56 */ + const Word16 *w1, /* i: M-dimensional weight vector Q8 */ + Word16 *quant, /* o: quantized vector x2.56 */ + Word16 *cv_out, /* o: non-scaled lattice codevector x2.56 */ + Word16 *idx_lead, /* o: leader indexes for each subvector */ + Word16 *idx_scale, /* o: scale indexes for each subvector */ + const Word16 *p_sigma, /* i: standard deviation x2.56 */ + const Word16 *p_inv_sigma, /* i: inverse standard deviation Q15 */ + const Word16 *p_scales, /* i: scale values Q11 */ + const Word16 *p_no_lead /* i: number of leaders for each truncation and each subvector */ +) +{ + Word32 dist, L_tmp; + /* first subvector */ + dist = quantize_data_ivas_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* second subvector */ + L_tmp = quantize_data_ivas_fx( pTmp1 + LATTICE_DIM, w1 + LATTICE_DIM, + quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + + return dist; +} /*-----------------------------------------------------------------* * mslvq_cng() * @@ -192,6 +337,82 @@ Word32 mslvq_cng_fx( return dist; } +Word32 mslvq_cng_ivas_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +) +{ + Word32 dist; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 no_scales[2]; + Word16 mode_glb, mode, i; + Word16 pTmp1[M], w1[M]; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + + dist = L_deposit_l( 0 ); + mode = add( LVQ_COD_MODES, idx_cv ); + move16(); + + /* for CNG there is only one bitrate but several lattice quantizer structures, + depending on the previous VQ stage */ + mode_glb = add( START_CNG, idx_cv ); + move16(); + + p_sigma = sigma_MSLVQ_fx[mode]; + move16(); + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + move16(); + p_scales = scales_fx[mode_glb]; + move16(); + + no_scales[0] = 0; + no_scales[1] = 0; + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[no_lead_idx[mode_glb][0]][i]; + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[no_lead_idx[mode_glb][1]][i]; + + IF( p_scales[i] > 0 ) + { + no_scales[0] += 1; + } + IF( p_scales[i + MAX_NO_SCALES] > 0 ) + { + no_scales[1] += 1; + } + } + + /* check if LSF component permutation is needed or not */ + IF( cng_sort[idx_cv] ) + { + FOR( i = 0; i < M; i++ ) + { + pTmp1[i] = pTmp[i]; + move16(); + w1[i] = w[i]; + move16(); + } + /* sorting the quantizer input and the corresponding weights according to the specified permutations */ + permute_fx( pTmp1, perm_MSLVQ[idx_cv] ); + permute_fx( w1, perm_MSLVQ[idx_cv] ); + + dist = q_data_ivas_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* permute back */ + permute_fx( quant, perm_MSLVQ[idx_cv] ); + } + ELSE + { + dist = q_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + } + + return dist; +} /*-----------------------------------------------------------------* * prepare_data_fx() * @@ -546,6 +767,107 @@ static Word32 quantize_data_fx( return min_dist; } +static Word32 quantize_data_ivas_fx( + Word16 *data, /* i : residual LSF data to quantize x2.56*/ + const Word16 *w_in, /* i : weights Q10*/ + Word16 *qin, /* o : quantized output (scaled) x2.56*/ + Word16 *cv_out, /* o : codevectors Q1*/ + Word16 *idx_lead, /* o : leader indexes for each subvector */ + Word16 *idx_scale, /* o : scale indexes for each subvector */ + const Word16 *sigma, /* i : standard deviation x2.56 */ + const Word16 *inv_sigma, /* i : inverse of standard deviation Q15 */ + const Word16 *scale, /* i : scales for each truncation Q11*/ + const Word16 *no_leaders /* i : number of leader vectors for each truncation of each subvector */ +) +{ + Word16 j; + Word32 w[LATTICE_DIM]; + Word32 min_dist = 0; + Word16 best_idx = 0, best_scale = -1; + Word16 s; + Word16 indx[LATTICE_DIM]; + Word16 sig, sign[LATTICE_DIM]; + Word16 cv_pot[LATTICE_DIM]; + Word16 id[8]; + Word16 smallest; + Word32 L_tmp; + + IF( scale[0] > 0 ) + { + prepare_data_fx( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); + move16(); + /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ + sort_desc_ind_fx( cv_pot, LATTICE_DIM, indx ); + smallest = indx[LATTICE_DIM - 1]; + move16(); + + min_dist = calculate_min_dist_fx( cv_pot, MAX_NO_SCALES, scale, w, &best_scale, &best_idx, no_leaders, sig, indx ); + + IF( GT_16( best_scale, -1 ) ) + { + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + id[indx[j]] = j; + } + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + cv_out[j] = i_mult2( sign[j], pl_HQ_fx[best_idx * LATTICE_DIM + id[j]] ); + move16(); + } + IF( pl_par[best_idx] ) + { + IF( NE_16( sig, pl_par[best_idx] ) ) + { + cv_out[smallest] = negate( cv_out[smallest] ); + } + } + s = scale[best_scale]; + move16(); /*Q11 */ + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + /*qin[j] = s * cv_out[j] * sigma[j]; */ + L_tmp = L_mult( cv_out[j], s ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = Mult_32_16( L_tmp, shl( sigma[j], 2 ) ); /* Q13 + Q2 +x2.56 -Q15 */ + + qin[j] = extract_l( L_tmp ); /*x2.56 */ + } + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); + } + ELSE + { + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + qin[j] = 0; + move16(); + } + + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); + } + } + ELSE + { + *idx_lead = 0; + move16(); + *idx_scale = -1; + move16(); + + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + cv_out[j] = 0; + move16(); + qin[j] = 0; + move16(); + } + } + + return min_dist; +} /*-----------------------------------------------------------------* * sort_desc_ind() * @@ -655,7 +977,52 @@ void index_lvq_fx( return; } +void index_lvq_ivas_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i :scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ) +{ + Word32 index1, index2; + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + Word64 idx64; + Word64 index2_64; + + index1 = 0; + move16(); + + create_offset( offset_scale1, offset_scale2, mode, prediction_flag ); + + /* for first subvector */ + IF( GT_16( idx_scale[0], -1 ) ) + { + index1 = L_add( encode_comb_fx( quant, idx_lead[0] ), L_add( table_no_cv_fx[idx_lead[0]], offset_scale1[idx_scale[0]] ) ); + } + + /* for second subvector */ + index2 = L_deposit_l( 0 ); + + IF( GT_16( idx_scale[1], -1 ) ) + { + index2 = L_add( encode_comb_fx( &quant[LATTICE_DIM], idx_lead[1] ), L_add( table_no_cv_fx[idx_lead[1]], offset_scale2[idx_scale[1]] ) ); + } + idx64 = W_mult0_32_32( index1, offset_scale2[MAX_NO_SCALES] ); + index2_64 = W_deposit32_l( index2 ); + idx64 = W_add_nosat( idx64, index2_64 ); + + /* convert to 3 short */ + index[0] = ( ( idx64 ) & ( 0x7fff ) ); + move16(); + index[1] = ( idx64 >> 15 ) & ( 0x7fff ); + move16(); + index[2] = ( idx64 >> 30 ) & ( 0x7fff ); + move16(); + + return; +} /*-----------------------------------------------------------------* * encode_comb() * diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index cc3aef87c51249cf037214583eb0a9f37426ac12..2611fec4b542579be041c8e16f7afe2a64afe93d 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index a0b228c1e5adad47f5c643f2bd70a8982d3d0b1c..576a9ea208e4f0276e6bfe0dd3e33334567305cc 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -32,10 +32,9 @@ #include #include "control.h" -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "prot_fx1.h" -#include "prot_fx2.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index da9e0f0d345bfbeccfade271404a4a45394a68f7..dbb29cc6c27df3c6cee8a3a85e790040fc03315d 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -8,8 +8,7 @@ #include "cnst.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" @@ -348,7 +347,7 @@ void noise_est_pre_fx( test(); test(); test(); - IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_16( sub_sat( hNoiseEst->Etot_last_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_16( sub_sat( hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_l_fx ), HE_LT_THR2_FX ) ) ) { /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ hNoiseEst->Etot_l_lp_fx = mac_r( L_mult( 983, hNoiseEst->Etot_l_fx ), 31785, hNoiseEst->Etot_l_lp_fx ); @@ -361,13 +360,116 @@ void noise_est_pre_fx( } } /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) ); + hNoiseEst->sign_dyn_lp_fx = round_fx( L_mac( L_mult( 3277, sub_sat( hNoiseEst->Etot_h_fx, hNoiseEst->Etot_l_fx ) ), 29491, hNoiseEst->sign_dyn_lp_fx ) ); } return; } +void noise_est_pre_32fx( + const Word32 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const int16_t idchan, /* i : channel ID */ + const int16_t element_mode, /* i : element mode */ + const int16_t last_element_mode /* i : last element mode */ +) +{ + Word32 tmp; + + IF( LE_16( ini_frame_fx, 1 ) || ( EQ_16( idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) + { + hNoiseEst->Etot_h_32fx = Etot; + move16(); + hNoiseEst->Etot_l_32fx = Etot; + move16(); + hNoiseEst->Etot_l_lp_32fx = Etot; + move16(); + hNoiseEst->Etot_last_32fx = Etot; + move16(); + hNoiseEst->Etot_v_h2_32fx = 0; + move16(); + hNoiseEst->Etot_lp_32fx = Etot; + move16(); + hNoiseEst->sign_dyn_lp_32fx = 0; + move16(); + } + ELSE + { + /* *Etot_lp = 0.20f*Etot + 0.80f* *Etot_lp; */ + hNoiseEst->Etot_lp_32fx = L_add( Mpy_32_32( 429496730, Etot ), Mpy_32_32( 1717986918, hNoiseEst->Etot_lp_32fx ) ); + move16(); + + hNoiseEst->Etot_h_32fx = L_sub( hNoiseEst->Etot_h_32fx, 671089 ); + move16(); /* 10=0.04 in Q8 */ + hNoiseEst->Etot_h_32fx = L_max( hNoiseEst->Etot_h_32fx, Etot ); + move16(); + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); + move16(); /* 20 = .08 in Q8 */ + + + /* Could even be higher but it also delays first entry to DTX */ + IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) + { + test(); + IF( ( LT_16( ini_frame_fx, s_min( HE_LT_CNT_INIT_FX, MAX_FRAME_COUNTER - 1 ) ) ) && ( LT_32( L_sub( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_lp_32fx ), (Word32) 3 * 16777216 ) ) /* 3.0 Q8 */ + ) + { + /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ + tmp = Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 214748365 ); /* factor in Q15 3277 .1*32768 */ + tmp = L_min( 33554432, tmp ); /* 2.0 in Q8 is 512*/ + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, tmp ); + move16(); /* Q8 */ + } + + /* Avoids large steps in short active segments */ + test(); + IF( ( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) /* 30.0f*Q8 */ + && ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_SHORT_FX ) ) ) + { + /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, Mpy_32_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 42949673 ) ); + move16(); /* 0.02 = 655 Q8*/ + } + ELSE IF( GT_32( L_sub( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 167772160 ) ) /* 10.0 in Q8*/ + { + hNoiseEst->Etot_l_32fx = L_add( hNoiseEst->Etot_l_32fx, 1342177 ); + move16(); /* 0.08 is 20 in Q8*/ + } + } + + hNoiseEst->Etot_l_32fx = L_min( hNoiseEst->Etot_l_32fx, Etot ); + + IF( LT_16( ini_frame_fx, 100 ) && LT_32( hNoiseEst->Etot_l_32fx, hNoiseEst->Etot_l_lp_32fx ) ) + { + /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 214748364, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 1932735283, hNoiseEst->Etot_l_lp_32fx ) ); + move16(); + } + ELSE + { + test(); + test(); + test(); + test(); + IF( ( ( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) ) && ( GT_32( L_sub_sat( hNoiseEst->Etot_last_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) || ( ( sub( hNoiseEst->harm_cor_cnt, HE_LT_CNT_FX ) > 0 ) && ( LT_16( ini_frame_fx, HE_LT_CNT_INIT_FX ) ) ) || ( GT_32( L_sub_sat( hNoiseEst->Etot_l_lp_32fx, hNoiseEst->Etot_l_32fx ), 503316480 ) ) ) + { + /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 64424509, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2083059139, hNoiseEst->Etot_l_lp_32fx ) ); + move16(); + } + ELSE + { + /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ + hNoiseEst->Etot_l_lp_32fx = L_add( Mpy_32_32( 42949673, hNoiseEst->Etot_l_32fx ), Mpy_32_32( 2104533975, hNoiseEst->Etot_l_lp_32fx ) ); + } + } + /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ + hNoiseEst->sign_dyn_lp_32fx = L_add( Mpy_32_32( 214748365, L_sub_sat( hNoiseEst->Etot_h_32fx, hNoiseEst->Etot_l_32fx ) ), Mpy_32_32( 1932735283, hNoiseEst->sign_dyn_lp_32fx ) ); + } + return; +} /*==================================================================================*/ /* FUNCTION : noise_est_down_fx() */ /*----------------------------------------------------------------------------------*/ @@ -698,8 +800,8 @@ void noise_est_fx( *-----------------------------------------------------------------*/ /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */ - wtmp = abs_s( sub( st_fx->pitch_fx[0], old_pitch1 ) ); - wtmp1 = abs_s( sub( st_fx->pitch_fx[1], st_fx->pitch_fx[0] ) ); + wtmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); + wtmp1 = abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ); pc = add( wtmp, wtmp1 ); @@ -1904,3 +2006,1371 @@ void noise_est_fx( return; } +#ifdef IVAS_FLOAT_FIXED + +/*-----------------------------------------------------------------* + * noise_est_fx() + * + * Noise energy estimation (noise energy is updated in case of noise-only frame) + *-----------------------------------------------------------------*/ +void noise_est_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16 *cor_map_sum, /* o : Q8 */ + Word16 *sp_div, /* o : Q_sp_div */ + Word16 *Q_sp_div, /* o : Q factor for sp_div */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16 *bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16 *sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ + const Word16 ini_frame /* i : Frame number (init) */ +) +{ + Word16 alpha, alpha2, alpha2m1, alpham1; + Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp; + Word16 wtmp1, wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp; + Word16 i, tmp_pc, pc, th_eps; + Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden; + Word16 e_ener, f_ener; + Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2; + Word16 spec_div, noise_char; + Word16 log_enr16; + Word16 updt_step; /* Q15 */ + Word16 aE_bgd, sd1_bgd, bg_bgd2; + Word16 tn_ini; + Word16 epsP_0_2, epsP_0_2_ad, epsP_0_2_ad_lp_max; + Word16 epsP_2_16, epsP_2_16_dlp, epsP_2_16_dlp_max; + Word16 PAU, BG_1, NEW_POS_BG; + + Word16 haco_ev_max; + Word16 Etot_l_lp_thr; + Word16 comb_ahc_epsP, comb_hcm_epsP; + + Word16 enr_bgd, cns_bgd, lp_bgd, ns_mask; + Word16 lt_haco_mask, bg_haco_mask; + Word16 SD_1, SD_1_inv, bg_bgd3, PD_1, PD_2, PD_3, PD_4, PD_5; + + Word16 non_staB; /* Q8 */ + Word32 L_tmp_enr, L_tmp_ave_enr, L_tmp_ave_enr2; + Word16 tmp_Q; + Word16 tmp, tmp2; /* general temp registers */ + Word16 tmp_enr, tmp_floor; /* constants in Q8 */ + Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */ + /* for DTX operation */ + Word16 vad_2nd_stage_fx; + + Word16 lim_Etot_fx; /* Q8 */ + Word16 lim_Etot_sq_fx; /* Q2 */ + Word16 st_E_var_est_fx; /* Q2 */ + NOISE_EST_HANDLE hNoiseEst; + SP_MUS_CLAS_HANDLE hSpMusClas; + hSpMusClas = st_fx->hSpMusClas; + /* Check if LR-VAD */ + IF( hFrontVad != NULL ) + { + hNoiseEst = hFrontVad->hNoiseEst; + } + ELSE + { + hNoiseEst = st_fx->hNoiseEst; + } + + GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + vad_bwidth_fx = st_fx->input_bwidth; + move16(); + + /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ + + IF( hFrontVad == NULL ) + { + if ( hSpMusClas != NULL ) + { + Ltmp = L_shr( lf_E[0], 3 ); + FOR( i = 1; i < 8; i++ ) + { + Ltmp = L_add( Ltmp, L_shr( lf_E[i], 3 ) ); + } + IF( LT_32( Ltmp, L_shl( 1, add( Q_new, Q_SCALE - 2 ) ) ) ) + { + hSpMusClas->ener_RAT_fx = 0; + // PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") + } + ELSE + { + Ltmp = L_max( Ltmp, (Word32) 1L ); /* make sure log2_norm_lc does not cause table reading out of bounds */ + e_ener = norm_l( Ltmp ); + f_ener = Log2_norm_lc( L_shl( Ltmp, e_ener ) ); + e_ener = sub( 30, e_ener ); + e_ener = sub( e_ener, sub( add( Q_new, QSCALE ), 2 ) ); + Ltmp = Mpy_32_16( e_ener, f_ener, LG10 ); + wtmp = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ + + /* st_fx->ener_RAT /= (Etot + 0.01f); */ + wtmp1 = add( Etot, 3 ); /*3 is 0.01 in Q8 */ + /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ + hSpMusClas->ener_RAT_fx = 0; + move16(); + IF( wtmp > 0 ) + { + hSpMusClas->ener_RAT_fx = 32767; + move16(); /*Q15*/ + if ( GE_16( wtmp1, wtmp ) ) + { + hSpMusClas->ener_RAT_fx = div_s( wtmp, wtmp1 ); /*Q15*/ /* wtmp1 gte than wtmp */ + } + } + } + } + } + /*-----------------------------------------------------------------* + * Set the threshold for eps & non_sta based on input sampling rate + * The reason is that in case of 8kHz sampling input, there is nothing + * between 4kHz-6.4kHz. In noisy conditions, this makes a fast + * transition even in noise-only parts, hence producing a "higher + * order" spectral envelope => the epsP ratio is much less effective. + *-----------------------------------------------------------------*/ + + IF( NE_16( vad_bwidth_fx, NB ) ) /* WB input */ + { + th_eps = TH_EPS16_FX; + move16(); /*Q11*/ + th_sta = TH_STA16_FX; + move16(); /*Q10 */ + cor_min = COR_MIN16_FX; + move16(); /*Q15*/ + cor_max = COR_MAX16_FX; + move16(); /*Q15*/ + } + ELSE /* NB input */ + { + th_eps = TH_EPS8_FX; + move16(); /* Q11 */ + th_sta = TH_STA8_FX; + move16(); /* Q10 */ + cor_min = COR_MIN8_FX; + move16(); + cor_max = COR_MAX8_FX; + move16(); + } + + + /*-----------------------------------------------------------------* + * Estimation of pitch stationarity + *-----------------------------------------------------------------*/ + + /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */ + wtmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); + wtmp1 = abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ); + pc = add( wtmp, wtmp1 ); + + + Ltmp = L_deposit_h( corr_shift ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 ); +#ifdef BASOP_NOGLOB + Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow ); + wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow ); +#else /* BASOP_NOGLOB */ + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 10923 ); + wtmp = mac_r( Ltmp, st_fx->voicing_fx[2], 10923 ); +#endif /* BASOP_NOGLOB */ + + tmp_pc = pc; + move16(); + if ( LT_16( wtmp, cor_min ) ) + { + tmp_pc = TH_PC_FX; + move16(); /* low correlation -> probably inactive signal */ + } + + move16(); /* Update */ + + /*-----------------------------------------------------------------* + * Multi-harmonic analysis + *-----------------------------------------------------------------*/ + IF( hFrontVad == NULL ) + { + IF( st_fx->hSpMusClas != NULL ) + { + i = 0; + move16(); + *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); + } + } + /*-----------------------------------------------------------------* + * Detection of frames with non-stationary spectral content + *-----------------------------------------------------------------*/ + + /* weighted sum of spectral changes per critical bands */ + Lsum_num = L_deposit_l( 0 ); + Lsum_den = L_deposit_l( 0 ); + + /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */ + tmpExp = 0; + move16(); + ExpLmax = sub( 30, norm_l( fr_bands[10] ) ); + ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[10] ) ); + tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); + FOR( i = 11; i <= st_fx->max_band; i++ ) + { + ExpLmax = sub( 30, norm_l( fr_bands[i] ) ); + ExpLmax2 = sub( 30, norm_l( hNoiseEst->fr_bands2_fx[i] ) ); + tmpExp = s_max( tmpExp, sub( shl( s_max( ExpLmax, ExpLmax2 ), 1 ), s_min( ExpLmax, ExpLmax2 ) ) ); + } + tmpExp = sub( tmpExp, 30 - 4 - 4 ); /* 4bits for internal summation and 4 bits for comparaison */ + + pt1 = fr_bands + 10; + pt2 = hNoiseEst->fr_bands2_fx + 10; + FOR( i = 10; i <= st_fx->max_band; i++ ) + { + Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */ +#ifdef BASOP_NOGLOB + Lsum_den = L_add_o( Lsum_den, Lnum, &Overflow ); +#else /* BASOP_NOGLOB */ + Lsum_den = L_add( Lsum_den, Lnum ); +#endif /* BASOP_NOGLOB */ + Ltmpden = L_min( *pt1, *pt2 ); + if ( Ltmpden == 0 ) + { + Ltmpden = L_add( Ltmpden, 1 ); + } + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + num = mult_r( num, num ); + ExpDen = norm_l( Ltmpden ); + den = extract_h( L_shl( Ltmpden, ExpDen ) ); + num = div_s( num, den ); + Ltmp = L_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) ); + Lsum_num = L_add( Lsum_num, Ltmp ); + + pt1++; + pt2++; + } + Lsum_den = L_shr( Lsum_den, tmpExp ); + + + /* calculation of spectral diversity */ + /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ + spec_div = 0; + move16(); + if ( GT_32( Mult_32_16( Lsum_num, 6554 ), Lsum_den ) ) /* Qx+Q15+1-16 ==> Qx */ + { + spec_div = 1; + move16(); + } + + /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */ + ExpNum = sub( norm_l( Lsum_num ), 1 ); + num = extract_h( L_shl( Lsum_num, ExpNum ) ); + + Lsum_den = L_add( Lsum_den, 1 ); + + ExpDen = norm_l( Lsum_den ); + den = extract_h( L_shl( Lsum_den, ExpDen ) ); + + *sp_div = div_s( num, den ); + move16(); + + *Q_sp_div = add( 15, sub( ExpNum, ExpDen ) ); + move16(); + + /*-----------------------------------------------------------------* + * Detection of frames with high energy content in high frequencies + *-----------------------------------------------------------------*/ + + /* calculation of energy in first 10 critical bands */ + Ltmp = sum32_fx( &fr_bands[st_fx->min_band], sub( 10, st_fx->min_band ) ); + + /* calculation of energy in the rest of bands */ + Ltmp2 = sum32_fx( &fr_bands[10], sub( st_fx->max_band, 9 ) ); + +#ifdef BASOP_NOGLOB + wtmp = shl_o( 1, sub( add( Q_new, QSCALE ), 1 ), &Overflow ); +#else /* BASOP_NOGLOB */ + wtmp = shl( 1, sub( add( Q_new, QSCALE ), 1 ) ); +#endif /* BASOP_NOGLOB */ + test(); + IF( L_msu( Ltmp, 100, wtmp ) < 0 || L_msu( Ltmp2, 100, wtmp ) < 0 ) + { + noise_chartmp = 0; + move16(); + } + ELSE + { + /* ftemp2 /= ftemp */ + ExpNum = sub( norm_l( Ltmp2 ), 1 ); + num = extract_h( L_shl( Ltmp2, ExpNum ) ); + + ExpDen = norm_l( Ltmp ); + den = extract_h( L_shl( Ltmp, ExpDen ) ); + num = div_s( num, den ); +#ifdef BASOP_NOGLOB + noise_chartmp = extract_h( L_shr_o( num, add( sub( ExpNum, ExpDen ), 4 - 16 ), &Overflow ) ); /* Q11 */ +#else /* BASOP_NOGLOB */ + noise_chartmp = extract_h( L_shr( num, add( sub( ExpNum, ExpDen ), 4 - 16 ) ) ); /* Q11 */ +#endif /* BASOP_NOGLOB */ + } + + noise_chartmp = s_min( noise_chartmp, (Word16) 10 << 11 ); /* Q11 */ + + /* update LT value of the final parameter */ + /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ + hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp ); + + + nchar_thr = THR_NCHAR_WB_FX; + move16(); /* 1.0 Q11 */ + if ( EQ_16( vad_bwidth_fx, NB ) ) + { + nchar_thr = THR_NCHAR_NB_FX; + move16(); /* 1.0 Q11 */ + } + + noise_char = 0; + move16(); + if ( GT_16( hNoiseEst->noise_char_fx, nchar_thr ) ) + { + noise_char = 1; + move16(); + } + + /* save the 2 last spectra per crit. bands for the future */ + Copy32( hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, NB_BANDS ); + Copy32( fr_bands + NB_BANDS, hNoiseEst->fr_bands1_fx, NB_BANDS ); + + /*-----------------------------------------------------------------* + * Non-stationarity estimation for each band + * Handicap high E frames in average computing + *-----------------------------------------------------------------*/ + + /* set averaging factor */ + /* ftemp = relE; */ + /* if( ftemp < 0.0f ) { ftemp = 0.0f; } */ + tmp = s_max( relE, 0 ); /* Q8 */ + + /* alpha = 0.064f * ftemp + 0.75f; */ + Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */ + Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */ +#ifdef BASOP_NOGLOB + alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ +#else /* BASOP_NOGLOB */ + alpha = round_fx( L_shl( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ +#endif /* BASOP_NOGLOB */ + + /*if( alpha > 0.999f { alpha = 0.999f;} */ + alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ + alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ + /*--------------------------------------------------------------* + * during significant attacks, replace the LT energy by the + * current energy this will cause non_sta2 failures to occur in + * different frames than non_sta failures + *--------------------------------------------------------------*/ + + alpha2 = alpha; + move16(); + alpha2m1 = alpham1; + move16(); + IF( spec_div > 0 ) + { + alpha2 = 0; + move16(); + alpha2m1 = 32767; + move16(); + } + Lnon_sta2 = L_deposit_l( 1 << 10 ); + + non_sta = L_deposit_l( 1 << 10 ); + *non_staX = 0; + move16(); + non_staB = 0; + move16(); + + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) + { + /* + 1.0f added to reduce sensitivity to non stationarity in low energies */ + /* tmp_enr = enr[i] + 1.0f; */ + tmp_Q = add( Q_new, Q_SCALE ); + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ +#ifdef BASOP_NOGLOB + L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ +#else /* BASOP_NOGLOB */ + L_tmp_enr = L_add( enr[i], Ltmp ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */ +#endif /* BASOP_NOGLOB */ + + IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */ + { + /* if( enr[i] > st_ave_enr2[i] ) */ + /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */ + Lnum = L_max( L_tmp_enr, L_tmp_ave_enr ); + + /* else */ + /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */ + Lden = L_min( L_tmp_enr, L_tmp_ave_enr ); + + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + Lnum = L_shl( Lnum, ExpNum ); + ExpDen = norm_l( Lden ); + den = extract_h( L_shl( Lden, ExpDen ) ); + num = div_s( num, den ); + Ltmp = Mult_32_16( non_sta, num ); +#ifdef BASOP_NOGLOB + non_sta = L_shr_o( Ltmp, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ +#else /* BASOP_NOGLOB */ + non_sta = L_shr( Ltmp, sub( ExpNum, ExpDen ) ); /* Q10 */ +#endif /* BASOP_NOGLOB */ + } + + /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ + Ltmp = Mult_32_16( hNoiseEst->ave_enr_fx[i], alpha ); + Ltmp = L_add( Ltmp, Mult_32_16( enr[i], alpham1 ) ); + hNoiseEst->ave_enr_fx[i] = L_max( Le_min_scaled, Ltmp ); + move32(); + + /* calculation of another non-stationarity measure (following attacks) */ + /*if( non_sta2 <= th_sta ){ + tmp_ave2 = st->ave_enr2[i] + 1.0f; + if( tmp_enr > tmp_ave2 ){ + non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 ); + } else { + non_sta2 = non_sta2 * (tmp_ave2 / tmp_enr ); + } + } */ + + /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ + /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ +#ifdef BASOP_NOGLOB + L_tmp_ave_enr2 = L_add_o( hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ +#else + L_tmp_ave_enr2 = L_add( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */ +#endif + IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */ + { + Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 ); + Lden = L_min( L_tmp_enr, L_tmp_ave_enr2 ); + + ExpNum = sub( norm_l( Lnum ), 1 ); + num = extract_h( L_shl( Lnum, ExpNum ) ); + Lnum = L_shl( Lnum, ExpNum ); + ExpDen = norm_l( Lden ); + den = extract_h( L_shl( Lden, ExpDen ) ); + num = div_s( num, den ); + Ltmp1 = Mult_32_16( Lnon_sta2, num ); +#ifdef BASOP_NOGLOB + Lnon_sta2 = L_shr_o( Ltmp1, sub( ExpNum, ExpDen ), &Overflow ); /* Q10 */ +#else /* BASOP_NOGLOB */ + Lnon_sta2 = L_shr( Ltmp1, sub( ExpNum, ExpDen ) ); /* Q10 */ +#endif /* BASOP_NOGLOB */ + } + + /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] + + (1.0f - alpha2) * (enr[i]) */ + Ltmp1 = Mult_32_16( hNoiseEst->ave_enr2_fx[i], alpha2 ); + Ltmp1 = L_add( Ltmp1, Mult_32_16( enr[i], alpha2m1 ) ); + hNoiseEst->ave_enr2_fx[i] = L_max( Le_min_scaled, Ltmp1 ); + move32(); + + /* calculation of non-stationarity measure for speech/music classification */ + IF( hFrontVad == NULL ) + { + test(); + test(); + IF( GE_16( i, START_BAND_SPMUS ) && LT_16( i, NB_BANDS_SPMUS + START_BAND_SPMUS ) && st_fx->hSpMusClas != NULL ) + { + /* log_enr = (float)ln_fx(enr[i]); */ + log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q ); + wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) ); +#ifdef BASOP_NOGLOB + *non_staX = add_o( *non_staX, wtmp, &Overflow ); +#else /* BASOP_NOGLOB */ + *non_staX = add( *non_staX, wtmp ); +#endif /* BASOP_NOGLOB */ + move16(); /* Q8 */ + hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16; + move16(); + } + } + IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) + { + IF( GE_16( ini_frame, 100 ) ) + { + /* calculate non-stationarity feature relative background */ + tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ + tmp_floor = LN_E_MIN_PLUS_ONE_FX; + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q ); +#ifdef BASOP_NOGLOB + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#else /* BASOP_NOGLOB */ + non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#endif /* BASOP_NOGLOB */ + } + ELSE /*ini_frame < 100*/ + { + /* calculate non-stationarity feature relative background */ + tmp_enr = noise_est_ln_q8_fx( enr[i], 1, tmp_Q ); /* 1.0f added */ + tmp_floor = LN_E_MIN_PLUS_ONE_FX; + move16(); /* non dynamic init constant in Q8 */ + tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q ); +#ifdef BASOP_NOGLOB + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#else /* BASOP_NOGLOB */ + non_staB = add( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#endif /* BASOP_NOGLOB */ + } + } + + } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ + + IF( LT_16( Etot, -1280 ) ) + { + non_sta = L_deposit_l( 1024 ); /* 1.0 in Q10 */ + Lnon_sta2 = L_deposit_l( 1024 ); /* 1.0 in Q10 */ + } + + lim_Etot_fx = s_max( 5120, Etot ); /* 20.0f Q8 */ + lim_Etot_sq_fx = extract_h( L_shl_r( L_mult( lim_Etot_fx, lim_Etot_fx ), 1 ) ); /* Q2 */ + + if ( st_fx->ini_frame < 150 ) + { + /* Allow use of quicker filter during init - if needed */ + /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); + move16(); + /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); + move16(); + } + else + { + /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ + hNoiseEst->Etot_st_est_fx = mac_r( L_mult( 8192, lim_Etot_fx ), 24576, hNoiseEst->Etot_st_est_fx ); + move16(); + /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ + hNoiseEst->Etot_sq_st_est_fx = mac_r( L_mult( 8192, lim_Etot_sq_fx ), 24576, hNoiseEst->Etot_sq_st_est_fx ); + move16(); + } + + st_E_var_est_fx = sub( hNoiseEst->Etot_sq_st_est_fx, extract_h( L_shl_r( L_mult( hNoiseEst->Etot_st_est_fx, hNoiseEst->Etot_st_est_fx ), 1 ) ) ); + + + /*-----------------------------------------------------------------* + * Count frames since last correlation or harmonic event + *-----------------------------------------------------------------*/ + + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); + + test(); + test(); + *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); + if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) ) + { + *st_harm_cor_cnt = 0; + move16(); + } + + IF( ( GT_16( *st_harm_cor_cnt, 1 ) ) && ( ( LT_16( Etot, 3840 ) ) || /* 15 in Q8 */ + ( GT_16( st_fx->ini_frame, 10 ) && + GT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) ) /* 7 in Q8 */ + ) + { + *st_harm_cor_cnt = 1; + } + + if ( GT_16( *st_harm_cor_cnt, 1 ) && + GT_16( Etot, 7680 ) && /* 30.0f in Q8 */ + GT_16( st_E_var_est_fx, 32 ) /* 8.0f in Q2 */ + ) + { + + /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */ + *st_harm_cor_cnt = s_max( 1, shr( add( *st_harm_cor_cnt, 2 ), 1 ) ); + } + + + /*-----------------------------------------------------------------* + * Energy based pause length counter + *-----------------------------------------------------------------*/ + test(); + IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) ) + { + /* Possible speech burst */ + *bg_cnt = -1; + move16(); + } + ELSE + { + test(); + if ( EQ_16( *bg_cnt, -1 ) && ( LT_16( sub( Etot, Etot_l_lp ), 1280 ) ) /*5 in Q8*/ ) + { + /* Possible start of speech pause */ + *bg_cnt = 0; + move16(); + } + } + if ( *bg_cnt >= 0 ) + { + *bg_cnt = add( *bg_cnt, 1 ); + move16(); + } + + /*-----------------------------------------------------------------* + * Linear predition efficiency 0 to 2 order + *-----------------------------------------------------------------*/ + + /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */ + Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0], + epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ +#ifdef BASOP_NOGLOB + epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#else /* BASOP_NOGLOB */ + epsP_0_2 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#endif /* BASOP_NOGLOB */ + BASOP_SATURATE_WARNING_ON_EVS + + epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ + + + /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ + alpha = 4915; + move16(); /*0.15 in Q15 */ + hNoiseEst->epsP_0_2_lp_fx = noise_est_AR1_Qx( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx, alpha ); + + /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */ + epsP_0_2_ad = abs_s( sub( epsP_0_2, hNoiseEst->epsP_0_2_lp_fx ) ); /* Q12 */ + + /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) { + st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp; + } else { + st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp; + } */ + alpha = 6554; + move16(); /* 0.2 Q15 */ + if ( LT_16( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ) ) + { + alpha = shr( alpha, 1 ); /* 0.1 Q15 */ + } + hNoiseEst->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx, alpha ); + + /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ + epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */ + + + /*-----------------------------------------------------------------* + * Linear predition efficiency 2 to 16 order + *-----------------------------------------------------------------*/ + + /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ + Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2], + epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ +#ifdef BASOP_NOGLOB + epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , + NB saturation in Q12 sets max value to 7,999 */ +#else /* BASOP_NOGLOB */ + epsP_2_16 = round_fx( L_shl( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 , + NB saturation in Q12 sets max value to 7,999 */ +#endif /* BASOP_NOGLOB */ + BASOP_SATURATE_WARNING_ON_EVS + + epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ + + + /* if (epsP_2_16 > st->epsP_2_16_lp){ + st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; + } else { + st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp; + } + + st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; */ + + alpha = 983; + move16(); /* 0.03 Q15 */ + if ( GT_16( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx ) ) + { + alpha = 6554; + move16(); /* 0.2 Q15 */ + } + hNoiseEst->epsP_2_16_lp_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp_fx, alpha ); + + hNoiseEst->epsP_2_16_lp2_fx = noise_est_AR1_Qx( epsP_2_16, hNoiseEst->epsP_2_16_lp2_fx, 655 ); /* 0.02 */ + + epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx ); + + + /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { + st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; + } else { + st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2; + }*/ + alpha = 1638; + move16(); /* 0.05 Q15 */ + if ( LT_16( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ) ) + { + alpha = 655; + move16(); /* 0.02 Q15 */ + } + hNoiseEst->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx, alpha ); + + /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */ + epsP_2_16_dlp_max = s_max( epsP_2_16_dlp, hNoiseEst->epsP_2_16_dlp_lp2_fx ); + + /*-----------------------------------------------------------------* + * long term extensions of frame features + *-----------------------------------------------------------------*/ + + tmp = sub( Etot, hNoiseEst->totalNoise_fx ); /* Q8 */ + /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */ + tmp2 = 0; + move16(); + if ( LT_16( tmp, 2560 ) ) /*10 in Q8 */ + { + tmp2 = 32767; + move16(); + } + hNoiseEst->lt_tn_track_fx = noise_est_AR1_Qx( tmp2, hNoiseEst->lt_tn_track_fx, 983 ); /*0.03 in Q15 ,Q15 state*/ + + /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */ + hNoiseEst->lt_tn_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_tn_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ + + /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/ + tmp = sub( Etot, hNoiseEst->Etot_l_lp_fx ); /* Q8 */ + hNoiseEst->lt_Ellp_dist_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_Ellp_dist_fx, 983 ); /*0.03 in Q15 ,Q8 state*/ + + + /* if (st->harm_cor_cnt == 0) { + st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev; + } else { + st->lt_haco_ev = 0.99f*st->lt_haco_ev; + } */ + IF( *st_harm_cor_cnt == 0 ) + { + hNoiseEst->lt_haco_ev_fx = noise_est_AR1_Qx( (Word16) 32767, hNoiseEst->lt_haco_ev_fx, 983 ); /*.03 in Q15 , Q15 state */ + } + ELSE + { + hNoiseEst->lt_haco_ev_fx = mult_r( 32440, hNoiseEst->lt_haco_ev_fx ); /*.99 in Q15 , Q15 state */ + } + + + /* if (st->lt_tn_track < 0.05f) { + st->low_tn_track_cnt++; + } else { + st->low_tn_track_cnt=0; + }*/ + tmp = 0; + move16(); + move16(); + if ( LT_16( hNoiseEst->lt_tn_track_fx, 1638 ) ) /* 0.05 in Q15*/ + { + tmp = add( hNoiseEst->low_tn_track_cnt, 1 ); + } + hNoiseEst->low_tn_track_cnt = tmp; + move16(); + + + /* update of the long-term non-stationarity measure (between 0 and 1) */ + /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) { + st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1; + } else { + st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; + }*/ + Ltmp = L_mult( M_GAMMA_FX, hNoiseEst->act_pred_fx ); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ + tmp = round_fx( Ltmp ); /* Q15 */ + test(); + if ( ( GT_32( non_sta, th_sta ) ) /* float th_sta NB 5e10 , WB 3.5e10*/ + || ( *loc_harm > 0 ) ) + { + tmp = mac_r( Ltmp, ( -32768 + M_GAMMA_FX ), -32768 ); /* (-0.01)*(-1.0) */ + } + hNoiseEst->act_pred_fx = tmp; + move16(); + + + /*-----------------------------------------------------------------* + * Background noise adaptation enable flag + *-----------------------------------------------------------------*/ + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); + Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); +#ifdef BASOP_NOGLOB + cor_tmp = mac_ro( Ltmp, corr_shift, MAX_16, &Overflow ); +#else /* BASOP_NOGLOB */ + cor_tmp = mac_r( Ltmp, corr_shift, MAX_16 ); +#endif + + LepsP = eps_quota_fx( epsP_h[2], epsP_l[2], + epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */ + /* note this epsP2/eps16 is not limited to 8 as, epsP_2_16 is !! */ + + vad_2nd_stage_fx = 0; + move16(); /* background noise present - decrement counter */ + /* + if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) + && ( ( non_sta > th_sta ) || + ( tmp_pc < TH_PC ) || + ( noise_char > 0) ) + ) + || + ( (st->ini_frame > 150) && (Etot - Etot_l_lp) > 10 ) || + ( 0.5f * (voicing[0]+voicing[1]) > cor_max ) || + ( epsP[2] / epsP[16] > th_eps ) || + ( *loc_harm > 0) || + ((st->act_pred > 0.8f) && (non_sta2 > th_sta)) + ) */ + + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); /* Q15 + Q15(.5)) + 1 -> Q31 */ + cor_tmp = mac_r( Ltmp, st_fx->voicing_fx[1], 16384 ); /* Q31 -16 -> Q15 */ + if ( Etot < 0 ) + { + cor_tmp = 0; + move16(); + } + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + + if ( ( ( LT_16( *st_harm_cor_cnt, ( 3 * HC_CNT_SLOW_FX ) ) ) && ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || ( GT_16( noise_char, 0 ) ) ) ) || + ( ( GT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( sub( Etot, Etot_l_lp ), 2560 ) ) ) || + ( GT_16( cor_tmp, cor_max ) ) || /* Q15 */ + ( GT_32( LepsP, th_eps ) ) || /* Q11 */ + ( GT_16( *loc_harm, 0 ) ) || + ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) /*act_pred in Q15 , th_sta in Q10 */ + ) + { + vad_2nd_stage_fx = 1; + move16(); /* active signal present - increment counter */ + } + + tmp = 2; + move16(); /* Signal present */ + if ( vad_2nd_stage_fx == 0 ) + { + tmp = -1; + move16(); /* Background present */ + } + hNoiseEst->aEn = add( hNoiseEst->aEn, tmp ); + + + hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 ); + hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 ); + /*-----------------------------------------------------------------* + * Stereo classifier - save raw aEn + *-----------------------------------------------------------------*/ + + if ( hStereoClassif != NULL ) + { + /* + if ( ( non_sta > th_sta ) || + ( tmp_pc < TH_PC ) || + ( 0.5f * ( st->voicing[0] + st->voicing[1] ) > cor_max ) || + ( epsP[2] / epsP[16] > th_eps ) || + ( ( hNoiseEst->act_pred > 0.8f ) && ( non_sta2 > th_sta ) ) )*/ + if ( ( GT_32( non_sta, th_sta ) ) || ( LT_16( tmp_pc, TH_PC_FX ) ) || + ( GT_16( cor_tmp, cor_max ) ) || + ( GT_32( LepsP, th_eps ) ) || + ( ( GT_16( hNoiseEst->act_pred_fx, 26214 ) ) && ( GT_32( Lnon_sta2, th_sta ) ) ) ) /*act_pred in Q15 , th_sta in Q10 */ + { + /* active signal present - increment counter */ + hStereoClassif->aEn_raw[st_fx->idchan] = hStereoClassif->aEn_raw[st_fx->idchan] + 2; + } + else + { + /* background noise present - decrement counter */ + hStereoClassif->aEn_raw[st_fx->idchan] = hStereoClassif->aEn_raw[st_fx->idchan] - 1; + } + + if ( hStereoClassif->aEn_raw[st_fx->idchan] > 6 ) + { + hStereoClassif->aEn_raw[st_fx->idchan] = 6; + } + else if ( hStereoClassif->aEn_raw[st_fx->idchan] < 0 ) + { + hStereoClassif->aEn_raw[st_fx->idchan] = 0; + } + } + + + /* Additional NNE detectors */ + + /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ + /* Q15 Q15 Q12 */ + comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */ + + + /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ + /* Q15 Q12 Q12 */ + comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ + + /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */ + tmp = 0; + move16(); + if ( *st_harm_cor_cnt == 0 ) + { + tmp = (Word16) 32767; + move16(); + } + haco_ev_max = s_max( tmp, hNoiseEst->lt_haco_ev_fx ); /* Q15 */ + + /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */ + tmp = 12288; + move16(); /* 1.5 Q13 */ + if ( LT_16( hNoiseEst->Etot_lp_fx, 12800 ) ) /* 50.0 in Q8 */ + { + tmp = shl( tmp, 1 ); /*1.5 + 1.5 Q13 */ + } + Ltmp = L_deposit_h( hNoiseEst->Etot_l_lp_fx ); + Etot_l_lp_thr = round_fx( L_add( Ltmp, L_shl( L_mult( tmp, Etot_v_h2 ), 2 ) ) ); /* Q13+Q8+1 +2 = Q24 -> Q8*/ + + /* enr_bgd = Etot < Etot_l_lp_thr; */ + enr_bgd = 0; + move16(); + if ( LT_16( Etot, Etot_l_lp_thr ) ) /* Q8 */ + { + enr_bgd = 1; + move16(); /* Q0 */ + } + + /* cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); */ + cns_bgd = 0; + move16(); + test(); + if ( ( GT_16( epsP_0_2, 32563 ) ) /* 7.95 in Q12 */ + && ( LT_32( non_sta, 1024000L ) ) ) /* 1e3f in Q10 ? */ + { + cns_bgd = 1; + move16(); /* Q0 */ + } + + /*lp_bgd = epsP_2_16_dlp_max < 0.10f; */ + lp_bgd = 0; + move16(); + if ( LT_16( epsP_2_16_dlp_max, 410 ) ) /*0.10 Q12 */ + { + lp_bgd = 1; + move16(); /* Q0 */ + } + + + /* ns_mask = non_sta < 1e5f; */ + ns_mask = 0; + move16(); + if ( LT_32( non_sta, (Word32) 102400000L ) ) /* (1e5f in Q10)*/ + { + ns_mask = 1; + move16(); /* Q0 */ + } + + + /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ + lt_haco_mask = 0; + move16(); + if ( LT_16( hNoiseEst->lt_haco_ev_fx, 16384 ) ) /* ( .5 in Q15)*/ + { + lt_haco_mask = 1; + move16(); /* Q0 */ + } + + /* bg_haco_mask = haco_ev_max < 0.4f; */ + bg_haco_mask = 0; + move16(); + if ( LT_16( haco_ev_max, 13107 ) ) /* ( 0.4 in Q15)*/ + { + bg_haco_mask = 1; + move16(); /* Q0 */ + } + + + /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ + SD_1 = 0; + move16(); + test(); + if ( ( GT_16( epsP_0_2_ad, 2048 ) ) /* 0.5 in Q12 */ + && ( GT_16( epsP_0_2, 32563 ) ) ) /* 7.95 in Q12 */ + { + SD_1 = 1; + move16(); /* Q0 */ + } + SD_1_inv = sub( 1, SD_1 ); /* Q0 */ + + /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */ + /* NB only lowest bit position is used, result is always 0 or 1 */ + + /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */ + tmp = s_and( s_and( s_and( s_or( cns_bgd, lp_bgd ), ns_mask ), lt_haco_mask ), SD_1_inv ); + bg_bgd3 = s_or( enr_bgd, tmp ); + + /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */ + PD_1 = 0; + move16(); + if ( ( LT_16( epsP_2_16_dlp_max, 410 ) ) ) /* 0.10 in Q12 */ + { + PD_1 = 1; + move16(); /* Q0 */ + } + + /*PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; */ + PD_2 = 0; + move16(); + if ( ( LT_16( epsP_0_2_ad_lp_max, 410 ) ) ) /* 0.10 in Q12 */ + { + PD_2 = 1; + move16(); /* Q0 */ + } + + /*PD_3 = (comb_ahc_epsP < 0.85f ); */ + PD_3 = 0; + move16(); + if ( ( LT_16( comb_ahc_epsP, 3482 ) ) ) /* 0.85 in Q12 */ + { + PD_3 = 1; + move16(); /* Q0 */ + } + + /* PD_4 = comb_ahc_epsP < 0.15f; */ + PD_4 = 0; + move16(); + if ( ( LT_16( comb_ahc_epsP, 614 ) ) ) /* 0.15 in Q12 */ + { + PD_4 = 1; + move16(); /* Q0 */ + } + + /*PD_5 = comb_hcm_epsP < 0.30f; */ + PD_5 = 0; + move16(); + if ( ( LT_16( comb_hcm_epsP, 1229 ) ) ) /* 0.30 in Q12 */ + { + PD_5 = 1; + move16(); /* Q0 */ + } + + /* BG_1 = ( (SD_1==0) || (Etot < Etot_l_lp_thr) ) + && bg_haco_mask && (st->act_pred < 0.85f) && (st->Etot_lp < 50.0f); */ + BG_1 = 0; + move16(); + test(); + test(); + test(); + test(); + if ( ( ( SD_1 == 0 ) || ( LT_16( Etot, Etot_l_lp_thr ) ) ) && ( bg_haco_mask != 0 ) && ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85f in Q15 */ + && ( LT_16( hNoiseEst->Etot_lp_fx, 50 * 256 ) ) ) /* 50.0 in Q8 */ + { + BG_1 = 1; + move16(); + } + + /* PAU = (st->aEn==0) + || ( (Etot < 55.0f) && (SD_1==0) + && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */ + PAU = 0; + move16(); /*Q0*/ + if ( hNoiseEst->aEn == 0 ) + { + PAU = 1; + move16(); /*Q0*/ + } + tmp = 0; + move16(); /*Q0*/ + if ( LT_16( Etot, 55 * 256 ) ) /*55.0 in Q8 */ + { + tmp = 1; + move16(); /*Q0*/ + } + tmp = s_and( tmp, SD_1_inv ); + PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) ); + + + /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ + NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 ); + + /* Original silence detector works in most cases */ + /* aE_bgd = (st->aEn == 0);*/ + aE_bgd = 0; + move16(); + if ( hNoiseEst->aEn == 0 ) + { + aE_bgd = 1; + move16(); + } + + + /* When the signal dynamics is high and the energy is close to the background estimate */ + /* sd1_bgd = (st->sign_dyn_lp > 15) + && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 + && st->harm_cor_cnt > 20; */ + sd1_bgd = 0; + move16(); + test(); + test(); + if ( ( GT_16( hNoiseEst->sign_dyn_lp_fx, 15 * 256 ) ) /* 15 in Q8 */ + && ( LT_16( sub( Etot, hNoiseEst->Etot_l_lp_fx ), shl( Etot_v_h2, 1 ) ) ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ + && ( GT_16( *st_harm_cor_cnt, 20 ) ) ) + { + sd1_bgd = 1; + move16(); + } + + /* tn_ini = st->ini_frame < 150 && st->harm_cor_cnt > 5 && + ( (st->act_pred < 0.59f && st->lt_haco_ev <0.23f ) || + st->act_pred < 0.38f || + st->lt_haco_ev < 0.15f || + non_staB < 50.0f || + aE_bgd );*/ + + tmp = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + if ( ( ( LT_16( hNoiseEst->act_pred_fx, 19333 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 7537 ) ) ) /* .59 in Q15 .23 in Q15 */ + || ( LT_16( hNoiseEst->act_pred_fx, 12452 ) ) /* .38 in Q15 */ + || ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) || ( GT_16( st_fx->element_mode, EVS_MONO ) && LT_16( hNoiseEst->lt_haco_ev_fx, 2621 ) ) ) /* .15 in Q15 || 0.08 */ + || ( LT_16( non_staB, 50 * 256 ) ) /* 50.0 in Q8 */ + || aE_bgd != 0 || ( ( LT_16( Etot, 10752 ) ) /* 42 in Q8 */ + && ( GT_16( hNoiseEst->harm_cor_cnt, 10 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 11469 ) ) /* 0.35 in Q15 */ + && ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* 0.80 in Q15 */ + ) ) + { + tmp = 1; + move16(); + } + + tn_ini = 0; + move16(); + test(); + test(); + if ( ( LT_16( st_fx->ini_frame, HE_LT_CNT_INIT_FX ) ) && ( GT_16( hNoiseEst->harm_cor_cnt, 5 ) ) /* > 5 Q0 */ + && ( LT_16( sub( Etot, hNoiseEst->Etot_lp_fx ), 1792 ) ) /* 7 in Q8 */ + && ( NE_16( tmp, 0 ) ) ) + { + tn_ini = 1; + move16(); + } + + /* Energy close to the background estimate serves as a mask for other background detectors */ + /* bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini ; */ + bg_bgd2 = 0; + move16(); + test(); + if ( ( LT_16( Etot, Etot_l_lp_thr ) ) || ( tn_ini != 0 ) ) + { + bg_bgd2 = 1; + move16(); /* Q0 */ + } + + updt_step = 0; + move16(); /* Q15 */ + /*if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) ) + || tn_ini ) */ + tmp = 0; + move16(); + if ( GT_16( hNoiseEst->lt_tn_track_fx, 29491 ) ) /* .90 in Q15 */ + { + tmp = 1; + move16(); + } + + IF( s_or( s_and( bg_bgd2, s_or( aE_bgd, s_or( sd1_bgd, s_or( tmp, NEW_POS_BG ) ) ) ), tn_ini ) ) + { + /*if( ( ( st->act_pred < 0.85f ) + && (aE_bgd !=0) + && ( st->lt_Ellp_dist < 10 || sd1_bgd ) + && (st->lt_tn_dist<40) + && ( ( Etot - st->totalNoise ) < 10.0f ) + ) + || ( (st->first_noise_updt == 0) && (st->harm_cor_cnt > 80) && (aE_bgd!=0) && (st->lt_aEn_zero > 0.5f) ) + || ( (tn_ini!=0) && ( aE_bgd != 0) || (non_staB < 10.0) || (st->harm_cor_cnt > 80) ) + )*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); /* for the ELSE IF below*/ + test(); + test(); + test(); + test(); + test(); + test(); /* for the ELSE IF below*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( LT_16( hNoiseEst->act_pred_fx, 27853 ) ) /* 0.85 in Q15 */ + && ( NE_16( aE_bgd, 0 ) ) && ( ( LT_16( hNoiseEst->lt_Ellp_dist_fx, 10 * 256 ) ) || ( NE_16( sd1_bgd, 0 ) ) ) /* 10.0 in Q8*/ + && ( LT_16( hNoiseEst->lt_tn_dist_fx, 40 * 256 ) ) /* 40.0 in Q8*/ + && ( LT_16( sub( Etot, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8*/ + ) || + ( ( hNoiseEst->first_noise_updt == 0 ) && ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) /*.5 in Q15*/ + ) || + ( ( tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 10 * 256 ) ) || ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) ) /* 10.0 in Q8*/ + ) ) + + { + updt_step = 32767; + move16(); + hNoiseEst->first_noise_updt = 1; + FOR( i = 0; i < NB_BANDS; i++ ) + { + hNoiseEst->bckr_fx[i] = tmpN[i]; + move32(); + } + } + /* else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f ) + || ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f ) + || ( st->harm_cor_cnt > 80 && st->totalNoise > 5.0f && Etot < max(1.0f,Etot_l_lp + 1.5f* st->Etot_v_h2) ) + || + ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) + || tn_ini + ) */ + ELSE IF( ( ( LT_16( hNoiseEst->act_pred_fx, 26214 ) ) /* .8 in Q15*/ + && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 3277 ) ) ) /* .10 in q15*/ + || ( ( LT_16( hNoiseEst->act_pred_fx, 22938 ) ) /* 0.70 in Q15 */ + && ( ( aE_bgd != 0 ) || ( LT_16( non_staB, 17 * 256 ) ) ) /* 17.0 in Q8 */ + && ( PAU != 0 ) && ( LT_16( hNoiseEst->lt_haco_ev_fx, 4915 ) ) /* 0.15 in Q15 */ + ) || + ( ( GT_16( hNoiseEst->harm_cor_cnt, 80 ) ) && ( GT_16( hNoiseEst->totalNoise_fx, 5 * 256 ) ) /* 5.0 in Q8 */ + && ( LT_16( Etot, s_max( (Word16) 1 * 256, add( Etot_l_lp, add( hNoiseEst->Etot_v_h2_fx, shr( hNoiseEst->Etot_v_h2_fx, 1 ) ) ) ) ) ) /* 1.5= 1.0+.5 */ + ) || + ( ( GT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( GT_16( hNoiseEst->first_noise_updt, 30 ) ) && ( aE_bgd != 0 ) && ( GT_16( hNoiseEst->lt_aEn_zero_fx, 16384 ) ) ) /*.5 in Q15*/ + || ( tn_ini != 0 ) ) + + { + updt_step = 3277; + move16(); /* 0.1 in Q15 */ + /* if ( !aE_bgd && st->harm_cor_cnt < 50 + && ( (st->act_pred > 0.6f) + || ( (tn_ini==0) && (Etot_l_lp - st->totalNoise < 10.0f) && non_staB > 8.0f ) + ) + ) + */ + test(); + test(); + test(); + test(); + test(); + IF( ( aE_bgd == 0 ) && ( LT_16( hNoiseEst->harm_cor_cnt, 50 ) ) && ( ( GT_16( hNoiseEst->act_pred_fx, 19661 ) ) /* 0.6 in Q15*/ + || ( ( tn_ini == 0 ) && ( LT_16( sub( Etot_l_lp, hNoiseEst->totalNoise_fx ), 10 * 256 ) ) /* 10.0 in Q8 */ + && ( GT_16( non_staB, 8 * 256 ) ) /* 8.0 in in Q8*/ + ) ) ) + { + updt_step = 328; + move16(); /* 0.01 Q15 */ + } + /* + IF (updt_step > 0 ) + { + */ + hNoiseEst->first_noise_updt = 1; + move16(); + FOR( i = 0; i < NB_BANDS; i++ ) + { + /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ + /* 32 bit state update */ + Ltmp = L_sub( tmpN[i], hNoiseEst->bckr_fx[i] ); /*Q_new+Q_SCALE*/ + Ltmp = Mult_32_16( Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ + hNoiseEst->bckr_fx[i] = L_add( Ltmp, hNoiseEst->bckr_fx[i] ); + move32(); + } + /* + } */ + } + /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ + ELSE IF( ( aE_bgd != 0 ) || ( GT_16( hNoiseEst->harm_cor_cnt, 100 ) ) ) + { + hNoiseEst->first_noise_updt = add( hNoiseEst->first_noise_updt, 1 ); + } + } + ELSE + { + /* If in music lower bckr to drop further */ + test(); + test(); + IF( ( GT_16( hNoiseEst->low_tn_track_cnt, 300 ) ) && ( GT_16( hNoiseEst->lt_haco_ev_fx, 29491 ) ) /*.9 in Q15 */ + && ( hNoiseEst->totalNoise_fx > 0 ) ) + { + updt_step = -655; + move16(); /* for debug purposes */ + FOR( i = 0; i < NB_BANDS; i++ ) + { + IF( GT_32( hNoiseEst->bckr_fx[i], L_shl( Le_min_scaled, 1L ) ) ) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ + { + /* st->bckr[i] = 0.98f*st->bckr[i]; */ + hNoiseEst->bckr_fx[i] = Mult_32_16( hNoiseEst->bckr_fx[i], 32113 ); /* .98 in Q15 */ + move32(); /* move to array */ + } + } + } + /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/ + /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ + tmp = 0; + move16(); + if ( hNoiseEst->aEn == 0 ) + { + tmp = 32767; + move16(); + } + hNoiseEst->lt_aEn_zero_fx = noise_est_AR1_Qx( tmp, hNoiseEst->lt_aEn_zero_fx, 6554 ); /* alpha=0.2 , Q15 */ + } + + return; +} + +#endif diff --git a/lib_enc/noise_adjust_fx.c b/lib_enc/noise_adjust_fx.c index 1e149ad14bf0da6fb8a8e3a1350cb9cdb1c89b4c..1a2e204aea8c14b96a983c05f1eb02cd3a29c09f 100644 --- a/lib_enc/noise_adjust_fx.c +++ b/lib_enc/noise_adjust_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------* diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index 816f8531d657d9ef21e43263241a30bb8d435270..f6f5eedee7a031fce359b4471da4a17cf0aa892c 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ //#include "basop_mpy.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 5b3848706aa58a3244beede7c4dd90877d81ea8c..5a1fe61d1eb9c8bc37f9608ec35906f144f99d81 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -10,8 +10,7 @@ #include "rom_enc.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------------- diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 86343944b3329b42a453d1b6423017462d6e22f0..6bcf678a1dab815e60eeb7d424324c04c11cde48 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -10,8 +10,7 @@ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_basop_util.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #define inv_T0_res InvIntTable diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index cdbdea7919af4bcf80dfb46ed89e6813e36e4d63..f5352b75b887d73e9dc5f08da662dc7c6366d897 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -9,8 +9,7 @@ #include "rom_com.h" /* Encoder static table prototypes */ #include "rom_dec.h" //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index deb99d727ed7100969df6ebec7d16e99934737bb..0a7d20c6a2bcdcfde02050f231380c69b7f103b2 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -5,13 +5,12 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* @@ -47,101 +46,1242 @@ /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ +static Word32 Dot_product12_o_ivas( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Flag *Overflow_out /* o : propagating the Overflow flag to upper level, set to NULL to ignore internal overflows */ +); +static Word32 Dot_product12_ivas( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ +); +static Word32 Dot_product12_OL_ivas( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); +static Word32 Dot_product12_OL_back_ivas( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); + static void LP_Decim2_Copy( const Word16 x[], Word16 y[], Word16 l, Word16 mem[] ); -static void pitch_neighbour_fx( Word16 sect0, Word16 pitch_tmp[], Word16 pitch[3][2 * NSECT], Word16 corr_tmp[], Word16 corr[3][2 * NSECT], Word16 thres1[2 * NHFR], Word16 ind_tmp[2 * NHFR] ); +static void pitch_neighbour_fx( Word16 sect0, Word16 pitch_tmp[], Word16 pitch[3][2 * NSECT], Word16 corr_tmp[], Word16 corr[3][2 * NSECT], Word16 thres1[2 * NHFR], Word16 ind_tmp[2 * NHFR] ); + +static void find_mult_fx( Word16 *fac, Word16 pitch0, Word16 pitch1, Word16 pit_max0, Word16 *corr, Word16 *old_pitch, Word16 *old_corr, Word16 delta, Word16 step ); + +static Word16 pitch_coherence_fx( Word16 pitch0, Word16 pitch1, Word16 fac_max, Word16 diff_max ); + +static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); + +static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); +#ifdef BASOP_NOGLOB +static Word32 Dot_product12_o_ivas( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp, /* (o) : exponent of result (0..+30) */ + Flag *Overflow_out /* o : propagating the Overflow flag to upper level, set to NULL to ignore internal overflows */ +) +#else /* BASOP_NOGLOB */ +Word32 Dot_product12_ivas( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ +) +#endif /* BASOP_NOGLOB */ +{ + Word16 i, sft; + Word32 L_sum; +#ifdef BASOP_NOGLOB + Flag Overflow_ignored = 0; +#endif /* BASOP_NOGLOB */ + +#ifdef BASOP_NOGLOB + L_sum = L_mac_o( 0, x[0], y[0], &Overflow_ignored ); +#else + L_sum = L_mac( 1, x[0], y[0] ); +#endif + FOR( i = 1; i < lg; i++ ) + { +#ifdef BASOP_NOGLOB + L_sum = L_mac_o( L_sum, x[i], y[i], Overflow_out ? Overflow_out : &Overflow_ignored ); +#else /* BASOP_NOGLOB */ + L_sum = L_mac( L_sum, x[i], y[i] ); +#endif /* BASOP_NOGLOB */ + } + + /* Normalize acc in Q31 */ + + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); + + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ + + return L_sum; +} + +static Word32 Dot_product12_ivas( /* (o) Q31: normalized result (1 < val <= -1) */ + const Word16 x[], /* (i) 12bits: x vector */ + const Word16 y[], /* (i) 12bits: y vector */ + const Word16 lg, /* (i) : vector length */ + Word16 *exp /* (o) : exponent of result (0..+30) */ +) +{ + /* Ignore internal overflows */ + return Dot_product12_o_ivas( x, y, lg, exp, NULL ); +} +/*---------------------------------------------------------------------* + * Dot_product12_OL_back() + * + * two different length dot products of x and y, computed backward + *---------------------------------------------------------------------*/ +static Word32 Dot_product12_OL_back_ivas( /* o : Q31: normalized result (1 < val <= -1) */ + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ +) +{ + Word16 i, sft; + Word32 L_sum, L_sum2; + Flag Overflow_ignored = 0; + + L_sum = L_mac( 0, x[0], y[0] ); + IF( LE_16( lg, lg2 ) ) + { + FOR( i = 1; i < lg; i++ ) + { + L_sum = L_mac_o( L_sum, x[-i], y[-i], &Overflow_ignored ); + } + /* sets to 'L_sum' in 1 clock */ + L_sum2 = L_sum; + move32(); + FOR( ; i < lg2; i++ ) + { + L_sum2 = L_mac_o( L_sum2, x[-i], y[-i], &Overflow_ignored ); + } + } + ELSE + { + FOR( i = 1; i < lg2; i++ ) + { + L_sum = L_mac_o( L_sum, x[-i], y[-i], &Overflow_ignored ); + } + /* sets to 'L_sum' in 1 clock */ + L_sum2 = L_sum; + move32(); + FOR( ; i < lg; i++ ) + { + L_sum = L_mac_o( L_sum, x[-i], y[-i], &Overflow_ignored ); + } + } + + /* Q31 */ + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ + + sft = norm_l( L_sum2 ); + L_sum2 = L_shl( L_sum2, sft ); + *exp2 = sub( 30, sft ); + move16(); /* exponent = 0..30 */ + + *sum1 = extract_h( L_shr( L_sum2, 1 ) ); + + return L_sum; +} +/*---------------------------------------------------------------------* + * Dot_product12_OL + * + * two different length dot products of x and y + *---------------------------------------------------------------------*/ +static Word32 Dot_product12_OL_ivas( /* o : Q31: normalized result (1 < val <= -1) */ + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ +) +{ + Word16 i, sft; + Word32 L_sum, L_sum2; + Flag Overflow_ignored = 0; + L_sum = L_mac( 0, x[0], y[0] ); + IF( LE_16( lg, lg2 ) ) + { + FOR( i = 1; i < lg; i++ ) + { + L_sum = L_mac_o( L_sum, x[i], y[i], &Overflow_ignored ); + } + /* sets to 'L_sum' in 1 clock */ + L_sum2 = L_sum; + move32(); + FOR( ; i < lg2; i++ ) + { + L_sum2 = L_mac_o( L_sum2, x[i], y[i], &Overflow_ignored ); + } + } + ELSE + { + FOR( i = 1; i < lg2; i++ ) + { + L_sum = L_mac_o( L_sum, x[i], y[i], &Overflow_ignored ); + } + /* sets to 'L_sum' in 1 clock */ + L_sum2 = L_sum; + move32(); + FOR( ; i < lg; i++ ) + { + L_sum = L_mac_o( L_sum, x[i], y[i], &Overflow_ignored ); + } + } + + /* Q31 */ + sft = norm_l( L_sum ); + L_sum = L_shl( L_sum, sft ); + *exp = sub( 30, sft ); + move16(); /* exponent = 0..30 */ + + sft = norm_l( L_sum2 ); + L_sum2 = L_shl( L_sum2, sft ); + *exp2 = sub( 30, sft ); + move16(); /* exponent = 0..30 */ + + *sum1 = extract_h( L_shr( L_sum2, 1 ) ); + + return L_sum; +} +/*-----------------------------------------------------------------* + * pitch_ol_init() + * + * Open loop pitch variable initialization + *-----------------------------------------------------------------*/ +void pitch_ol_init_fx( + Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ + Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + Word16 *delta_pit, /* o : pitch evolution extrapolation */ + Word16 *old_corr /* o : correlation */ +) +{ + *old_thres = 0; + move16(); + *old_pitch = 0; + move16(); + *delta_pit = 0; + move16(); + *old_corr = 0; + move16(); +} + + +/*==================================================================================*/ +/* FUNCTION : pitch_ol_fx() */ +/*----------------------------------------------------------------------------------*/ +/* PURPOSE : + * Compute the open loop pitch lag. + * + * The pitch lag search is divided into two sets. + * Each set is divided into three sections. + * Each section cannot have a pitch multiple. + * We find a maximum for each section. + * We compare the maxima of each section. + * + * 1st set 2nd set + * 1st section: lag delay = 115 down to 62 and 115 down to 78 + * 2nd section: lag delay = 61 down to 32 and 77 down to 41 + * 3rd section: lag delay = 31 down to 17 and 40 down to 22 + * 4th section: lag delay = 16 down to 10 and 21 down to 12 + * + * As there is a margin between section overlaps, especially for + * longer delays, this section selection is more robust for not + * to find multiples in the same section when pitch evolves rapidly. + * + * For each section, the length of the vectors to correlate is + * greater/equal to the longest pitch delay. */ +/*----------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ +/* _ (Word16[]) old_corr_fx : correlation Q15 */ +/* _ (Word16[]) corr_shift_fx : normalized correlation correction Q15 */ +/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ +/* to past frame pitch Q15 */ +/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ +/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ +/* _ (Word16[]) wsp_fx : weighted speech for current frame & look-ahead qwsp */ +/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ +/* _ (Word16[]) relE_fx : relative frame energy Q8 */ +/* _ (Word16[]) L_look : look-ahead Q0 */ +/* _ (Word16[]) Opt_SC_VBR : SC-VBR flag Q0 */ +/* _ (Word16*) qwsp : wsp & filter memory Qformat */ +/*----------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) pitch : open loop pitch lag for each half-frame Q0 */ +/* _ (Word16[]) T_op : open loop pitch lag for each half-frm for quant Q0 */ +/* _ (Word16[]) voicing_fx : max normalized correlation for each half-frame QIn */ +/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ +/* _ (Word16[]) old_corr_fx : correlation Q15 */ +/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ +/* to past frame pitch Q15 */ +/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ +/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ +/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ +/*----------------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*==================================================================================*/ + +void pitch_ol_fx( + Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ + Word16 corr_shift, /* i : normalized correlation correction Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ + Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class, /* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ +) +{ + Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; + Word16 tmp_mem[3]; + + Word16 scale1[2 * DELTA_COH - 1]; + Word16 scaled_buf[2 * LEN_X + 3 * ( DELTA_COH - 1 )]; + Word16 scaled_buf_exp[2 * LEN_X + 3 * ( DELTA_COH - 1 )], exp_sect[8], exp_sect1[8], exp_sect0; + Word16 cor_buf[2 * LEN_X]; + Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; + Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; + Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; + Word16 thres1[6]; + Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; + Word16 ind_corX, ind1_corX; + + Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; + Word16 len_temp; + Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; + + Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; + Word32 enr, enr2, Ltmp; + Word16 fac, tmp16, tmp16_2; + Word16 qCorX, qScaledX; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; + const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; + + Word16 pit_min_coding; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + /*--------------------------------------------------------------* + * Initialization + *--------------------------------------------------------------*/ + len = len_12k8; + len1 = len1_12k8; + sublen = sublen_12k8; + sublen1 = sublen1_12k8; + pit_max = pit_max_12k8; + sec_length = sec_length_12k8; + sec_length1 = sec_length1_12k8; + + test(); + if ( ( LT_16( last_class, VOICED_TRANSITION ) ) && ( NE_16( bwidth, NB ) ) ) + { + /*reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings*/ + *old_thres = 0; + move16(); + } + + pit_min_coding = PIT_MIN_EXTEND; + move16(); + test(); + test(); + test(); + test(); + IF( ( ( NE_16( bwidth, NB ) ) && ( GT_16( *old_pitch, PIT_MIN ) ) ) || + ( ( EQ_16( bwidth, NB ) ) && ( ( GT_16( *old_pitch, PIT_MIN2_1 ) ) || ( LT_16( *old_thres, 3277 ) ) ) ) ) /* 0.1 inQ15*/ + { + pit_min = PIT_MIN / OPL_DECIM; + move16(); + pit_min1 = PIT_MIN_1 / OPL_DECIM; + move16(); + subsect0 = 2; + move16(); + sect0 = 1; + move16(); + } + ELSE + { + pit_min = PIT_MIN2 / OPL_DECIM; + move16(); + pit_min1 = PIT_MIN2_1 / OPL_DECIM; + move16(); + subsect0 = 0; + move16(); + sect0 = 0; + move16(); + } + + len_x = ( PIT_MAX / OPL_DECIM - pit_min + 1 ); + move16(); + len_x1 = ( PIT_MAX / OPL_DECIM - pit_min1 + 1 ); + move16(); + + /*--------------------------------------------------------------* + * Find decimated weighted speech + * Update wsp buffer with the memory + * decimation of wsp[] to search pitch in LF and to reduce complexity + * Extend the decimation of wsp to the end of the speech buffer + * Update wsp memory + *--------------------------------------------------------------*/ + Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + + LP_Decim2_Copy( wsp, wsp2, L_FRAME, mem_decim2 ); + + /* Avoid uninitialized memory access */ + set16_fx( wsp2 + L_FRAME / 2, 0, sizeof( old_wsp2 ) / sizeof( Word16 ) - ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ) - L_FRAME / 2 ); + tmp_mem[0] = mem_decim2[0]; + move16(); + tmp_mem[1] = mem_decim2[1]; + move16(); + tmp_mem[2] = mem_decim2[2]; + move16(); + + LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[shr( L_FRAME, 1 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ + + Copy( &old_wsp2[shr( L_FRAME, 1 )], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + + /*-----------------------------------------------------------------* + * Attenuate the correlation correction factor due to noise. + * Reset correlation buffer outside the useful range. + * Find the scaling functions for immediate neigbours and + * further ones. + *-----------------------------------------------------------------*/ + + corr_shift = shr( corr_shift, 1 ); + + set16_fx( scaled_buf, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + ( DELTA_COH - 1 ) + len_x, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + 2 * ( DELTA_COH - 1 ) + len_x + len_x1, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3 * ( DELTA_COH - 1 ) ); + + pt1 = scale1 + DELTA_COH - 1; + pt2 = pt1; + tmp16 = mult( negate( *old_thres ), MAX_16 / DELTA_COH ); + k = *old_thres; + move16(); + FOR( i = 0; i < DELTA_COH; i++ ) + { + /* + * *pt1 = ( -(*old_thres)/DELTA_COH * i + *old_thres+1.0f ); + * To keep Q15 values, the following code does not add 1 to the result. + * A scaling factor must be applied accordingly (see next use of scale1) + */ + *pt1 = k; + move16(); + k = add( k, tmp16 ); + *pt2-- = *pt1++; + move16(); + } + + /*-----------------------------------------------------------------------------* + * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames + *-----------------------------------------------------------------------------*/ + old_tmp = add( *old_pitch, *delta_pit ); + old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); + old_tmp = s_max( old_tmp, pit_min ); + old_tmp1 = add( old_tmp, *delta_pit ); + old_tmp1 = s_min( old_tmp1, PIT_MAX / OPL_DECIM ); + old_tmp1 = s_max( old_tmp1, pit_min ); + + /*-----------------------------------------------------------------* + * Loop for all three half-frames (current frame + look-ahead) + *-----------------------------------------------------------------*/ + pt_cor0 = scaled_buf + DELTA_COH - 1; + + pt_cor2 = pt_cor0 - pit_min + old_tmp; + pt_cor4 = pt_cor0 - pit_min1 + old_tmp + ( DELTA_COH - 1 ) + len_x; + + FOR( i = 0; i < NHFR; i++ ) /* i = 0, 1, 2 */ + { + pt1 = wsp2 + i * 2 * ( L_SUBFR / OPL_DECIM ); /* *pt1 -> Q12 */ + pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ + pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ + + enr = L_deposit_l( 1 ); + + pt_cor1 = pt_cor0; + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + + pt_exp1 = scaled_buf_exp + DELTA_COH - 1; + pt_exp2 = pt_exp1; + pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; + pt_exp4 = pt_exp3; + + IF( LT_16( i, NHFR - 1 ) ) /* First two half-frames (current frame) */ + { + pt3 = pt1; + pt5 = pt1; + + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + { + /*-----------------------------------------------------------------* + * Find fixed vector energy + *-----------------------------------------------------------------*/ + + /* 1st set */ + k = (Word16) ( pt1 - pt3 ); + move16(); + + FOR( k = add( k, len[j] ); k > 0; k-- ) + { + enr = L_mac0( enr, *pt3, *pt3 ); + pt3++; + } + /* keep Q15 normalized result */ + cnt = norm_l( enr ); + enr0[j] = extract_h( L_shl( enr, cnt ) ); + enr0_exp[j] = sub( 30, cnt ); + move16(); + + /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ + pt5 = pt3; + enr2 = enr; /* sets to 'enr' in 1 clock */ + move32(); + + /* 2nd set */ + k = (Word16) ( pt1 - pt5 ); + move16(); + + FOR( k = add( k, len1[j] ); k > 0; k-- ) + { + enr2 = L_mac0( enr2, *pt5, *pt5 ); + pt5++; + } + cnt = norm_l( enr2 ); + enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); + enr0_1_exp[j] = sub( 30, cnt ); + move16(); + } + + /*----------------------------------------------------------* + * Find correlation for the non-overlapping pitch lag values + *----------------------------------------------------------*/ + exp_sect[subsect0] = 0; + move16(); + pt_cor5 = pt_cor1; + pt_cor6 = pt_cor3; + + tmp16 = exp_sect[subsect0]; + move16(); + + k = (Word16) ( pt2 - pt1 + pit_max[subsect0] ); + + IF( k >= 0 ) + { + len_temp = sublen[0]; + move16(); + + FOR( ; k >= 0; k-- ) + { + /* Keep Q15 normalized result */ + /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ + /* Update exponent to reflect shr by 1 */ + *pt_cor1 = extract_h( L_shr( Dot_product12( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); + + /* save the biggest exponent */ + tmp16 = s_max( tmp16, *pt_exp1 ); + + pt_cor1++; + pt_exp1++; + } + } + exp_sect[subsect0] = tmp16; + move16(); + + /*----------------------------------------------------------* + * For each subsection, find the correlation + *----------------------------------------------------------*/ + FOR( j = subsect0; j < NSUBSECT; j++ ) + { + len_temp = sublen[j]; + move16(); + + k = (Word16) ( pt2 - pt1 ); + move16(); + k = add( k, pit_max[j + 1] ); + exp_sect[j + 1] = 0; + move16(); + exp_sect1[j] = 0; + move16(); + + IF( k >= 0 ) + { + ind = exp_sect[j + 1]; + move16(); + ind1 = exp_sect1[j]; + move16(); + + FOR( ; k >= 0; k-- ) + { + /* Keep Q15 normalized result */ + /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ + /* Update exponent to reflect shr by 1 (done in Dot_product12_OL() for pt_cor3/pt_exp3) */ + *pt_cor1 = extract_h( L_shr( Dot_product12_OL( pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); + /* The line above replaces: + * *pt_cor1 = shr(extract_h(Dot_product12(pt1, pt2, Sublen[j], pt_exp1)),1); move16(); + * *pt_cor3 = shr(extract_h(Dot_product12(pt1, pt2--, Sublen1[j+i*7], pt_exp3)),1); move16(); + */ + + /* save the biggest exponent */ + ind = s_max( ind, *pt_exp1 ); + ind1 = s_max( ind1, *pt_exp3 ); + + pt_cor1++; + pt_exp1++; + pt_cor3++; + pt_exp3++; + } + exp_sect[j + 1] = ind; + move16(); + exp_sect1[j] = ind1; + move16(); + } /* IF (k >= 0) */ + } /* FOR (j = subsect0; ... */ + } + ELSE /* 3rd half-frame (look-ahead) */ + { + pt6 = pt1 + L_LOOK_12k8 / OPL_DECIM - 1; + pt3 = pt6; + pt5 = pt6; + + /*-----------------------------------------------------------------* + * For each section in both sets, find fixed vector energy + *-----------------------------------------------------------------*/ + + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + { + /* 1st set */ + k = (Word16) ( pt3 - pt6 ); + move16(); + + FOR( k = add( k, len[j] ); k > 0; k-- ) + { + enr = L_mac0( enr, *pt3, *pt3 ); + pt3--; + } + + cnt = norm_l( enr ); + enr0[j] = extract_h( L_shl( enr, cnt ) ); /*qwsp+cnt-16*/ + enr0_exp[j] = sub( 30, cnt ); + move16(); + + /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ + pt5 = pt3; + enr2 = enr; + move16(); + + /* 2nd set */ + k = (Word16) ( pt5 - pt6 ); + move16(); + + FOR( k = add( k, len1[j] ); k > 0; k-- ) + { + enr2 = L_mac0( enr2, *pt5, *pt5 ); + pt5--; + } + + cnt = norm_l( enr2 ); + enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); /*qwsp+cnt-16*/ + enr0_1_exp[j] = sub( 30, cnt ); + move16(); + } + + /* Set pointers */ + IF( sect0 != 0 ) + { + pt2 = pt6 - add( pit_max[1], 1 ); + k = sub( pit_max[2], pit_max[1] ); + move16(); + } + ELSE + { + pt2 = pt6 - pit_min; + k = 2; + move16(); + } + + /*-----------------------------------------------------------------* + * Find correlation for the non-overlapping pitch lag values + *-----------------------------------------------------------------*/ + exp_sect[subsect0] = 0; + move16(); + pt_cor5 = pt_cor1; + pt_cor6 = pt_cor3; + + tmp16 = exp_sect[subsect0]; + move16(); + + IF( k > 0 ) + { + len_temp = sublen[0]; + move16(); + + FOR( ; k > 0; k-- ) + { + /* Following lines are equivalent of Dot_product12() but with a backward incrementing */ + Ltmp = L_deposit_l( 1 ); + FOR( m = 0; m < len_temp; m++ ) + { + Ltmp = L_mac( Ltmp, pt6[-m], pt2[-m] ); + } + + /* Normalize acc in Q31 */ + tmp16_2 = norm_l( Ltmp ); + Ltmp = L_shl( Ltmp, tmp16_2 ); + *pt_exp1 = sub( 30, tmp16_2 ); + move16(); /* exponent = 0..30 */ + + /* Save result */ + *pt_cor1 = extract_h( L_shr( Ltmp, 1 ) ); + + /* Save the biggest exponent */ + tmp16 = s_max( tmp16, *pt_exp1 ); + + pt_cor1++; + pt_exp1++; + pt2--; + } + exp_sect[subsect0] = tmp16; + move16(); + } + + /*-----------------------------------------------------------------* + * For each subsection, find the correlation (overlapping pitch lag values) + *-----------------------------------------------------------------*/ + + FOR( j = subsect0; j < NSUBSECT; j++ ) + { + exp_sect[j + 1] = 0; + move16(); + exp_sect1[j] = 0; + move16(); + + ind = exp_sect[j + 1]; + move16(); + ind1 = exp_sect1[j]; + move16(); + + k = sub( pit_max[j + 1], pit_max[j] ); + + FOR( ; k > 0; k-- ) + { + *pt_cor1 = extract_h( L_shr( Dot_product12_OL_back( pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); + + /* Save the biggest exponent */ + ind = s_max( ind, *pt_exp1 ); + ind1 = s_max( ind1, *pt_exp3 ); + + pt_cor1++; + pt_exp1++; + pt_cor3++; + pt_exp3++; + } + exp_sect[j + 1] = ind; + move16(); + exp_sect1[j] = ind1; + move16(); + } + } /* 3rd half-frame (look-ahead) */ + + /* Scale all values in each section to the same exponent for upcoming Find_max() */ + offset = 0; + move16(); + offset1 = 0; + move16(); + exp_sect1[7] = 0; /* padding */ + move16(); + FOR( j = sect0; j < NSECT; j++ ) + { + exp_sect0 = s_max( exp_sect[j * 2], exp_sect[j * 2 + 1] ); + + /* scaling of exp for track 1 */ + offset = add( offset, sec_length[j] ); + k = (Word16) ( pt_cor0 - pt_cor5 ); + move16(); + FOR( k = add( k, offset ); k > 0; k-- ) + { + cnt = sub( exp_sect0, *pt_exp2 ); + tmp16 = s_min( 15, cnt ); + if ( cnt > 0 ) + { + tmp16 = shr( *pt_cor5, tmp16 ); + } + if ( cnt > 0 ) + { + *pt_cor5 = tmp16; + move16(); + } + *pt_exp2 = s_max( *pt_exp2, exp_sect0 ); + move16(); + pt_cor5++; + pt_exp2++; + } + + exp_sect0 = s_max( exp_sect1[j * 2], exp_sect1[j * 2 + 1] ); + + /* scaling of exp for track 2 */ + offset1 = add( offset1, sec_length1[j] ); + k = (Word16) ( pt_cor0 - pt_cor6 + ( DELTA_COH - 1 ) ); + move16(); + k = add( k, len_x ); + FOR( k = add( k, offset1 ); k > 0; k-- ) + { + cnt = sub( exp_sect0, *pt_exp4 ); + tmp16 = s_min( 15, cnt ); + if ( cnt > 0 ) + { + tmp16 = shr( *pt_cor6, tmp16 ); + } + if ( cnt > 0 ) + { + *pt_cor6 = tmp16; + move16(); + } + *pt_exp4 = s_max( *pt_exp4, exp_sect0 ); + move16(); + pt_cor6++; + pt_exp4++; + } + } /* FOR (j = sect0; ... */ + + Copy( pt_cor0, cor_buf, len_x ); /* Save unscaled correlation vector */ + Copy( pt_cor0 + ( DELTA_COH - 1 ) + len_x, cor_buf + len_x, len_x1 ); + + /*-----------------------------------------------------------------* + * Scale correlation function in the neighbourhood of + * the extrapolated pitch + *-----------------------------------------------------------------*/ + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); + pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); + pt2 = scale1; + + FOR( k = 0; k < 2 * DELTA_COH - 1; k++ ) + { + /* all Q15 here */ + *pt_cor1 = add( *pt_cor1, mult( *pt_cor1, *pt2 ) ); + move16(); + *pt_cor3 = add( *pt_cor3, mult( *pt_cor3, *pt2++ ) ); + move16(); + + pt_cor1++; + pt_cor3++; + } + + /* Update for next half-frame & look-ahead */ + pt_cor2 = pt_cor0 - pit_min + old_tmp1; + pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; + + /*-----------------------------------------------------------------* + * For each section, find maximum correlation and compute + * normalized correlation + *-----------------------------------------------------------------*/ + + pt_cor1 = pt_cor0; + pt_exp1 = scaled_buf_exp + DELTA_COH - 1; + offset = 0; + move16(); + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; + offset1 = 0; + move16(); + + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + { + /* 1st set */ + offset_la = 0; + move16(); + if ( EQ_16( i, 2 ) ) + { + offset_la = sub( L_LOOK_12k8 / OPL_DECIM, len[j] ); + } + + /* 2nd set */ + offset_la1 = 0; + move16(); + if ( EQ_16( i, 2 ) ) + { + offset_la1 = sub( L_LOOK_12k8 / OPL_DECIM, len1[j] ); + } + + /* 1st set of candidates */ + ind = add( maximum_fx( pt_cor1, sec_length[j], &ftmp ), offset ); + pitchX[i][j] = add( ind, pit_min ); + move16(); + pt2 = pt1 - pitchX[i][j] + /*-*/ offset_la; /* selected moving vector */ + + enr1_exp = 0; + move16(); +#ifdef BASOP_NOGLOB + enr1 = add_o( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1, &Overflow ); +#else + enr1 = add( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1 ); +#endif + + enr2 = L_mult( enr0[j], enr1 ); + enr2_exp = norm_l( enr2 ); + enr2 = L_shl( enr2, enr2_exp ); + enr2_exp = sub( 31, add( sub( 28, add( enr0_exp[j], enr1_exp ) ), add( enr2_exp, 1 ) ) ); + + enr2 = Isqrt_lc( enr2, &enr2_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ + enr1_exp = norm_l( enr2 ); + enr1 = extract_h( L_shl( enr2, enr1_exp ) ); /*31-enr2_exp+enr1_exp-16*/ + enr1_exp = sub( enr2_exp, enr1_exp ); /*15-enr1_exp*/ + + Ltmp = L_mult0( cor_buf[ind], enr1 ); + qCorX = add( sub( 15, enr1_exp ), sub( 14, pt_exp1[ind] ) ); +#ifdef BASOP_NOGLOB + corX[i][j] = extract_h( L_shr_o( Ltmp, sub( qCorX, 31 ), &Overflow ) ); +#else /* BASOP_NOGLOB */ + corX[i][j] = extract_h( L_shr( Ltmp, sub( qCorX, 31 ) ) ); +#endif /* BASOP_NOGLOB */ + qCorX = 31; + move16(); + + Ltmp = L_mult0( pt_cor0[ind], enr1 ); + qScaledX = add( sub( 15, enr1_exp ), sub( 14, pt_exp1[ind] ) ); + scaledX[i][j] = round_fx( L_shl( Ltmp, sub( 16 + 12, qScaledX ) ) ); + qScaledX = 12; + move16(); + + pt_cor1 += sec_length[j]; + move16(); + offset = add( offset, sec_length[j] ); + + /* 2nd set of candidates */ + ind1 = add( maximum_fx( pt_cor3, sec_length1[j], &ftmp ), offset1 ); + pitchX[i][j + NSECT] = add( ind1, pit_min1 ); + move16(); + pt4 = pt1 - pitchX[i][j + NSECT] + /*-*/ offset_la1; + move16(); /* selected moving vector */ + enr1_exp = 0; + move16(); +#ifdef BASOP_NOGLOB + enr1 = add_o( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1, &Overflow ); +#else + enr1 = add( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1 ); +#endif + + enr2 = L_mult( enr0_1[j], enr1 ); + enr2_exp = norm_l( enr2 ); + enr2 = L_shl( enr2, enr2_exp ); + + enr2_exp = sub( 31, add( sub( 28, add( enr0_1_exp[j], enr1_exp ) ), add( enr2_exp, 1 ) ) ); + enr2 = Isqrt_lc( enr2, &enr2_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ + enr1_exp = norm_l( enr2 ); + enr1 = extract_h( L_shl( enr2, enr1_exp ) ); /*31-enr2_exp+enr1_exp-16*/ + enr1_exp = sub( enr2_exp, enr1_exp ); /*15-enr1_exp*/ + + Ltmp = L_mult0( cor_buf[ind1 + len_x], enr1 ); + + qCorX = add( sub( 15, enr1_exp ), sub( 14, pt_exp3[ind1] ) ); +#ifdef BASOP_NOGLOB + corX[i][j + NSECT] = extract_h( L_shr_o( Ltmp, qCorX - 31, &Overflow ) ); +#else /* BASOP_NOGLOB */ + corX[i][j + NSECT] = extract_h( L_shr( Ltmp, qCorX - 31 ) ); +#endif /* BASOP_NOGLOB */ + qCorX = 31; + move16(); + + Ltmp = L_mult0( pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x], enr1 ); + qScaledX = add( sub( 15, enr1_exp ), sub( 14, pt_exp3[ind1] ) ); + scaledX[i][j + NSECT] = round_fx( L_shl( Ltmp, sub( 16 + 12, qScaledX ) ) ); + /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ + qScaledX = 12; + move16(); + + pt_cor3 += sec_length1[j]; + move16(); + offset1 = add( offset1, sec_length1[j] ); + + } /* FOR j < NSECT */ + } /* FOR i < NHFR */ + + /*-----------------------------------------------------------------* + * Favor a smaller delay if it happens that it has its multiple + * in the longer-delay sections (harmonics check) + *-----------------------------------------------------------------*/ + + FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ + { + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + } + + fac = THRES0; + move16(); /* the look-ahead */ + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ + } + + /*-----------------------------------------------------------------* + * Do 1st estimate for pitch values + * Adjust the normalized correlation using estimated noise level + * Compute the maximum scaling for the neighbour correlation + * reinforcement + *-----------------------------------------------------------------*/ + add_sect0 = add( NSECT, sect0 ); + sub_sect0 = sub( NSECT, sect0 ); + FOR( i = 0; i < NHFR; i++ ) + { + /* 1st set of pitch candidates */ + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_tmp[i] = ind; + move16(); + pitch_tmp[i] = pitchX[i][ind]; + move16(); +#ifdef BASOP_NOGLOB + cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow ); +#else /* BASOP_NOGLOB */ + cor_tmp[i] = add( corX[i][ind], corr_shift ); +#endif /* BASOP_NOGLOB */ + move16(); + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i] = mult( THRES1, cor_tmp[i] ); + move16(); + + /* 2nd set of pitch candidates */ + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind_tmp[i + NHFR] = ind1; + move16(); + pitch_tmp[i + NHFR] = pitchX[i][ind1]; + move16(); +#ifdef BASOP_NOGLOB + cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow ); +#else /* BASOP_NOGLOB */ + cor_tmp[i + NHFR] = add( corX[i][ind1], corr_shift ); +#endif + move16(); + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); + move16(); + } + /*-----------------------------------------------------------------* + * Take into account previous and next pitch values of the present + * frame and look-ahead. Choose the pitch lags and normalize + * correlations for each half-frame & look-ahead + *-----------------------------------------------------------------*/ -static void find_mult_fx( Word16 *fac, Word16 pitch0, Word16 pitch1, Word16 pit_max0, Word16 *corr, Word16 *old_pitch, Word16 *old_corr, Word16 delta, Word16 step ); + pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); + FOR( i = 0; i < NHFR; i++ ) + { + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); -static Word16 pitch_coherence_fx( Word16 pitch0, Word16 pitch1, Word16 fac_max, Word16 diff_max ); + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); -static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); + if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) + { + ind = ind1; + move16(); + } + test(); + if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) + { + ind_corX = ind1_corX; + move16(); + } + test(); + test(); + test(); + IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) + { + pitch[i] = pitchX[i][ind_corX]; + move16(); + voicing[i] = corX[i][ind_corX]; + move16(); + } + ELSE + { + pitch[i] = pitchX[i][ind]; + move16(); + voicing[i] = corX[i][ind]; + move16(); + } + } -static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); + /*-----------------------------------------------------------------* + * Increase the threshold for correlation reinforcement with + * the past if correlation high and pitch stable + *-----------------------------------------------------------------*/ + /* all Q15 here */ + /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ + Ltmp = L_mult( voicing[0], 16384 ); + Ltmp = L_mac( Ltmp, voicing[1], 16384 ); + cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); -/*-----------------------------------------------------------------* - * pitch_ol_init() - * - * Open loop pitch variable initialization - *-----------------------------------------------------------------*/ -void pitch_ol_init_fx( - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ - Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ - Word16 *delta_pit, /* o : pitch evolution extrapolation */ - Word16 *old_corr /* o : correlation */ -) -{ - *old_thres = 0; + /* pitch unstable in present frame or from previous frame or normalized correlation too low */ + coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); move16(); - *old_pitch = 0; + coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); + move16(); + + test(); + test(); + test(); + IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) + { + /* Reset the threshold */ + *old_thres = 0; + move16(); + } + ELSE + { + /* The threshold increase is directly dependent on normalized correlation */ + /* *old_thres += (0.16f * cor_mean); */ + *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243, cor_mean ) ); + } + + *old_thres = s_min( *old_thres, THRES3 ); + move16(); + + IF( GT_16( voicing[1], voicing[0] ) ) + { + *old_corr = voicing[1]; + move16(); + } + ELSE + { + *old_corr = cor_mean; + move16(); + } + + /*-----------------------------------------------------------------* + * Extrapolate the pitch value for the next frame by estimating + * the pitch evolution. This value is added to the old_pitch + * in the next frame and is then used when the normalized + * correlation is reinforced by the past estimate + *-----------------------------------------------------------------*/ + tmp_buf[0] = *old_pitch; move16(); + FOR( i = 0; i < NHFR; i++ ) + { + tmp_buf[i + 1] = pitch[i]; + move16(); + } + *delta_pit = 0; move16(); - *old_corr = 0; + cnt = 0; move16(); -} + FOR( i = 0; i < NHFR; i++ ) + { + diff = sub( tmp_buf[i + 1], tmp_buf[i] ); + move16(); + coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); -/*==================================================================================*/ -/* FUNCTION : pitch_ol_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : - * Compute the open loop pitch lag. - * - * The pitch lag search is divided into two sets. - * Each set is divided into three sections. - * Each section cannot have a pitch multiple. - * We find a maximum for each section. - * We compare the maxima of each section. - * - * 1st set 2nd set - * 1st section: lag delay = 115 down to 62 and 115 down to 78 - * 2nd section: lag delay = 61 down to 32 and 77 down to 41 - * 3rd section: lag delay = 31 down to 17 and 40 down to 22 - * 4th section: lag delay = 16 down to 10 and 21 down to 12 - * - * As there is a margin between section overlaps, especially for - * longer delays, this section selection is more robust for not - * to find multiples in the same section when pitch evolves rapidly. - * - * For each section, the length of the vectors to correlate is - * greater/equal to the longest pitch delay. */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) corr_shift_fx : normalized correlation correction Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) wsp_fx : weighted speech for current frame & look-ahead qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/* _ (Word16[]) relE_fx : relative frame energy Q8 */ -/* _ (Word16[]) L_look : look-ahead Q0 */ -/* _ (Word16[]) Opt_SC_VBR : SC-VBR flag Q0 */ -/* _ (Word16*) qwsp : wsp & filter memory Qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch : open loop pitch lag for each half-frame Q0 */ -/* _ (Word16[]) T_op : open loop pitch lag for each half-frm for quant Q0 */ -/* _ (Word16[]) voicing_fx : max normalized correlation for each half-frame QIn */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/*----------------------------------------------------------------------------------*/ + if ( coh_flag != 0 ) + { + *delta_pit = add( *delta_pit, diff ); + move16(); + } + cnt = add( cnt, coh_flag ); + } + if ( EQ_16( cnt, 2 ) ) + { + /* *delta_pit /= 2; */ + *delta_pit = shr( *delta_pit, 1 ); + move16(); + } + IF( EQ_16( cnt, 3 ) ) + { + k = *delta_pit; + move16(); + /* *delta_pit /= 3; */ + if ( k < 0 ) + { + *delta_pit = mult( *delta_pit, -32768 ); + move16(); + } + tmp16 = mult( *delta_pit, 10923 ); + if ( k < 0 ) + { + tmp16 = mult( tmp16, -32768 ); + } + *delta_pit = tmp16; + move16(); + } -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ + /*--------------------------------------------------------------* + * Update old pitch, upsample pitch, + *--------------------------------------------------------------*/ -void pitch_ol_fx( + *old_pitch = pitch[1]; + move16(); + + FOR( i = 0; i < NHFR; i++ ) + { + /* compensate decimation */ + pitch[i] = i_mult2( pitch[i], OPL_DECIM ); + move16(); + } + + return; +} + +void pitch_ol_ivas_fx( Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ @@ -324,7 +1464,7 @@ void pitch_ol_fx( pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ - enr = L_deposit_l( 1 ); + enr = 0; pt_cor1 = pt_cor0; pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; @@ -348,10 +1488,10 @@ void pitch_ol_fx( /* 1st set */ k = (Word16) ( pt1 - pt3 ); move16(); - + Flag overflow = 0; FOR( k = add( k, len[j] ); k > 0; k-- ) { - enr = L_mac0( enr, *pt3, *pt3 ); + enr = L_mac0_o( enr, *pt3, *pt3, &overflow ); pt3++; } /* keep Q15 normalized result */ @@ -371,7 +1511,7 @@ void pitch_ol_fx( FOR( k = add( k, len1[j] ); k > 0; k-- ) { - enr2 = L_mac0( enr2, *pt5, *pt5 ); + enr2 = L_mac0_o( enr2, *pt5, *pt5, &overflow ); pt5++; } cnt = norm_l( enr2 ); @@ -403,7 +1543,7 @@ void pitch_ol_fx( /* Keep Q15 normalized result */ /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ /* Update exponent to reflect shr by 1 */ - *pt_cor1 = extract_h( L_shr( Dot_product12( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); + *pt_cor1 = extract_h( L_shr( Dot_product12_ivas( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); /* save the biggest exponent */ tmp16 = s_max( tmp16, *pt_exp1 ); @@ -443,7 +1583,7 @@ void pitch_ol_fx( /* Keep Q15 normalized result */ /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ /* Update exponent to reflect shr by 1 (done in Dot_product12_OL() for pt_cor3/pt_exp3) */ - *pt_cor1 = extract_h( L_shr( Dot_product12_OL( pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); + *pt_cor1 = extract_h( L_shr( Dot_product12_OL_ivas( pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); /* The line above replaces: * *pt_cor1 = shr(extract_h(Dot_product12(pt1, pt2, Sublen[j], pt_exp1)),1); move16(); * *pt_cor3 = shr(extract_h(Dot_product12(pt1, pt2--, Sublen1[j+i*7], pt_exp3)),1); move16(); @@ -474,7 +1614,7 @@ void pitch_ol_fx( /*-----------------------------------------------------------------* * For each section in both sets, find fixed vector energy *-----------------------------------------------------------------*/ - + Flag overflow = 0; FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /* 1st set */ @@ -483,7 +1623,7 @@ void pitch_ol_fx( FOR( k = add( k, len[j] ); k > 0; k-- ) { - enr = L_mac0( enr, *pt3, *pt3 ); + enr = L_mac0_o( enr, *pt3, *pt3, &overflow ); pt3--; } @@ -503,7 +1643,7 @@ void pitch_ol_fx( FOR( k = add( k, len1[j] ); k > 0; k-- ) { - enr2 = L_mac0( enr2, *pt5, *pt5 ); + enr2 = L_mac0_o( enr2, *pt5, *pt5, &overflow ); pt5--; } @@ -549,7 +1689,7 @@ void pitch_ol_fx( Ltmp = L_deposit_l( 1 ); FOR( m = 0; m < len_temp; m++ ) { - Ltmp = L_mac( Ltmp, pt6[-m], pt2[-m] ); + Ltmp = L_mac_o( Ltmp, pt6[-m], pt2[-m], &overflow ); } /* Normalize acc in Q31 */ @@ -592,7 +1732,7 @@ void pitch_ol_fx( FOR( ; k > 0; k-- ) { - *pt_cor1 = extract_h( L_shr( Dot_product12_OL_back( pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); + *pt_cor1 = extract_h( L_shr( Dot_product12_OL_back_ivas( pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3 ), 1 ) ); /* Save the biggest exponent */ ind = s_max( ind, *pt_exp1 ); @@ -1324,10 +2464,10 @@ static void LP_Decim2_Copy( move16(); FOR( i = 0; i < l; i += 2 ) { - L_tmp = L_mult( *p_x, H_fir[0] ); + L_tmp = L_mult( *p_x, h_fir_fx[0] ); FOR( k = 1; k < L_FIR_PO; k++ ) { - L_tmp = L_mac( L_tmp, p_x[k], H_fir[k] ); + L_tmp = L_mac( L_tmp, p_x[k], h_fir_fx[k] ); } p_x += 2; @@ -1462,7 +2602,6 @@ static Word32 Dot_product12_OL_back( /* o : Q31: normalized r return L_sum; } - void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, diff --git a/lib_enc/plc_enc_ext_fx.c b/lib_enc/plc_enc_ext_fx.c index 5c6af38f33a4f0c8fdc9965e8bfb6c3cdf9f3106..56598be2f5ab0342173145bfc314929340d29f4e 100644 --- a/lib_enc/plc_enc_ext_fx.c +++ b/lib_enc/plc_enc_ext_fx.c @@ -9,8 +9,7 @@ #include "stat_enc.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index 8353659eec7f735a3634cb9019bcdd34966b9ca6..3e5de17fa033d09164281b096fe1819354c3d15e 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -8,8 +8,7 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -201,7 +200,7 @@ ivas_error ppp_quarter_encoder_fx( push_indice_fx( hBstr, IND_GLOBAL_ALIGNMENT, shr( add( tmp_fx, 12 ), 2 ), 3 ); - count_free( PREVDTFS_FX ); + free( PREVDTFS_FX ); return error; } @@ -354,7 +353,7 @@ void set_ppp_mode_fx( test(); test(); if ( ( GT_16( st_fx->old_pitch_buf_fx[( 2 * NB_SUBFR ) - 1], PPP_LAG_THRLD_Q6 ) || - GT_16( st_fx->pitch_fx[1], PPP_LAG_THRLD ) || !st_fx->last_Opt_SC_VBR ) && + GT_16( st_fx->pitch[1], PPP_LAG_THRLD ) || !st_fx->last_Opt_SC_VBR ) && EQ_16( hSC_VBR->ppp_mode, 1 ) ) { hSC_VBR->ppp_mode = 0; diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index f76dd3e08e807d50489dd8a460e21d371af4de67..e55f488df2546d3ab7014e6c0fa8a394808b8edb 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" //#include "prot_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -211,8 +210,8 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + Word16 Q_new_inp, mem_decim_size; // TO be removed + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ), &Q_new_inp, &mem_decim_size ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -442,39 +441,39 @@ void pre_proc_fx( /* reset the OL pitch tracker memories during inactive frames */ pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); } - old_pitch1 = st->pitch_fx[1]; + old_pitch1 = st->pitch[1]; - pitch_ol_fx( st->pitch_fx, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, + pitch_ol_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, st->clas, st->bwidth, st->Opt_SC_VBR ); /* Updates for adaptive lag window memory */ - st->old_pitch_la = st->pitch_fx[2]; + st->old_pitch_la = st->pitch[2]; move16(); st->old_voicing_la = st->voicing_fx[2]; move16(); - /* Detection of very short stable st->pitch_fx period (MODE1 bit-rates) */ - StableHighPitchDetect_fx( &flag_spitch, st->pitch_fx, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, + /* Detection of very short stable st->pitch period (MODE1 bit-rates) */ + StableHighPitchDetect_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *Q_new, st->lgBin_E_fx ); /* 1/4 pitch precision improvement */ IF( LE_32( st->total_brate, ACELP_24k40 ) ) { /* 1/4 pitch precision improvement */ - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch_fx[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[2], &voicing_fr[2], 2 * L_SUBFR, wsp, 7 ); + pitch_ol2_fx( PIT_MIN_EXTEND, st->pitch[1], &pitch_fr[3], &voicing_fr[3], 3 * L_SUBFR, wsp, 7 ); } ELSE { - pitch_fr[0] = st->pitch_fx[0]; + pitch_fr[0] = st->pitch[0]; move16(); - pitch_fr[1] = st->pitch_fx[0]; + pitch_fr[1] = st->pitch[0]; move16(); - pitch_fr[2] = st->pitch_fx[1]; + pitch_fr[2] = st->pitch[1]; move16(); - pitch_fr[3] = st->pitch_fx[1]; + pitch_fr[3] = st->pitch[1]; move16(); voicing_fr[0] = st->voicing_fx[0]; @@ -511,7 +510,7 @@ void pre_proc_fx( * UC and VC frame selection *-----------------------------------------------------------------*/ - find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch_fx, st->voicing_fx, lf_E, corr_shift, st->input_bwidth, + find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch, st->voicing_fx, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, @@ -673,7 +672,7 @@ void pre_proc_fx( } st->sr_core = L_mult0( FRAMES_PER_SEC, st->L_frame ); - st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); + st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); move16(); st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 ); } @@ -830,7 +829,7 @@ void pre_proc_fx( Mpy_32_16_ss( st->sr_core, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->L_frame = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - st->encoderLookahead_enc = NS2SA_fx2( st->sr_core, ACELP_LOOK_NS ); + st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); move16(); st->encoderPastSamples_enc = shr( imult1616( st->L_frame, 9 ), 4 ); assert( st->L_frame == st->sr_core / 50 ); @@ -996,7 +995,7 @@ void pre_proc_fx( L_frame_tmp = L_FRAME16k; move16(); } - L_look = NS2SA_fx2( sr_core_tmp, ACELP_LOOK_NS ); + L_look = NS2SA_FX2( sr_core_tmp, ACELP_LOOK_NS ); move16(); /* lookahead at other sampling rate (16kHz, 25.5kHz, 32kHz) */ new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ @@ -1011,19 +1010,19 @@ void pre_proc_fx( IF( EQ_32( st->input_Fs, sr_core_tmp ) ) { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); Copy_Scale_sig( st->mem_decim16k_fx + delay, new_inp_16k, delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ Copy_Scale_sig( signal_in, new_inp_16k + delay, input_frame - delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ Copy( signal_in + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); /* memory still in Q0 */ } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0, &Q_new_inp, &mem_decim_size ); } ELSE /* keep memories up-to-date in case of bitrate switching */ { /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); Copy( st->mem_decim16k_fx + delay, new_inp_16k, delay ); Copy( signal_in, new_inp_16k + delay, sub( input_frame, delay ) ); Copy( signal_in + sub( input_frame, shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); @@ -1137,7 +1136,7 @@ void pre_proc_fx( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch_fx, st->voicing_fx, 16000, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); + analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input @@ -1216,7 +1215,7 @@ void pre_proc_fx( *-----------------------------------------------------------------*/ #ifndef FIX_I4_OL_PITCH - Copy( st->pitch_fx, pitch_orig, 3 ); + Copy( st->pitch, pitch_orig, 3 ); #endif IF( EQ_16( st->codec_mode, MODE2 ) ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 9ad6382745ba21cb90ad80d264c1e517a97ac47e..fec37122b0905511ec44ca975a29c780dd377ab2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -149,6 +149,14 @@ void dtx_fx( ); +void dtx_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 vad, /* i : vad flag for DTX */ + const Word16 speech[] /* i : Pointer to the speech frame */ + +); + Word16 dtx_hangover_addition_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ @@ -238,7 +246,19 @@ void long_enr_fx( const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ Word16 high_lpn_flag ); +#ifdef IVAS_FLOAT_FIXED +void ivas_long_enr_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + Word16 high_lpn_flag, /* i : sp/mus LPN flag */ + FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ + const Word16 n_chan, /* i : number of channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover LR channels */ + const Word16 Etot_LR[] /* i : total channel energy LR channels */ +); +#endif Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ Encoder_State *st_fx, /* i/o: Encoder state variable */ @@ -295,7 +315,38 @@ void noise_est_fx( #endif const Word16 ini_frame /* i : Frame number (init) */ ); - +#ifdef IVAS_FLOAT_FIXED +void noise_est_ivas_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ + const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ + const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ + const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ + const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ + const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ + Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ + Word16 *cor_map_sum, /* o : Q8 */ + Word16 *sp_div, /* o : Q_sp_div */ + Word16 *Q_sp_div, /* o : Q factor for sp_div */ + Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ + Word16 *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ + Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ + const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ + const Word16 Etot_v_h2, /* i : Energy variations Q8 */ + Word16 *bg_cnt, /* i : Background burst length timer Q0 */ + Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ + Word16 Q_new, /* i : SCaling of current frame */ + const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ + Word16 *sp_floor, /* o : noise floor estimate Q7 */ + Word16 S_map[], /* o : short-term correlation map Q7 */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + FRONT_VAD_ENC_HANDLE hFrontVad, /* i/o: front-VAD handle */ + const Word16 ini_frame /* i : Frame number (init) */ +); +#endif void noise_est_pre_fx( const Word16 Etot, /* i : Energy of current frame */ const Word16 ini_frame_fx, /* i : Frame number (init) */ @@ -306,6 +357,16 @@ void noise_est_pre_fx( ); +void noise_est_pre_32fx( + const Word32 Etot, /* i : Energy of current frame */ + const Word16 ini_frame_fx, /* i : Frame number (init) */ + NOISE_EST_HANDLE hNoiseEst, /* i/o: Noise estimation handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 element_mode, /* i : element mode */ + const Word16 last_element_mode /* i : last element mode */ + +); + void pitch_ol2_fx( const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ const Word16 pitch_ol, /* i : pitch to be improved */ @@ -319,6 +380,23 @@ void pitch_ol2_fx( const Word16 delta /* i : delta for pitch search (2 or 7) */ ); +void pitch_ol_ivas_fx( + Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ + Word16 corr_shift, /* i : normalized correlation correction Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ + Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class, /* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ +); + void pitch_ol_fx( Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ @@ -558,6 +636,22 @@ Word16 wb_vad_fx( Word16 lp_noise /* i : long term noise energy */ ); +Word16 wb_vad_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech, /* i : long term active speech energy average */ + Word16 lp_noise /* i : long term noise energy */ +); + Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center*/ Word32 snr_flux, /*(i) snr flux*/ Word32 lt_snr, /*(i) long time time domain snr*/ @@ -636,6 +730,21 @@ void lsf_end_enc_fx( #endif ); +void lsf_end_enc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ + Word16 *qlsf, /* o : quantized LSF */ + const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ + const Word16 coder_type_org, /* i : coding type */ + Word16 Q_ener, /* i : Q valuen for Bin_Ener */ + Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + Word16 *lpc_param, + Word16 *no_indices, + Word16 *bits_param_lpc, + Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ + , + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ +); void Mode2_abs_pit_enc_fx( Word16 T0, /* i : integer pitch lag */ Word16 T0_frac, /* i : pitch fraction */ @@ -1229,6 +1338,16 @@ void lsf_enc_fx( #endif const Word16 Q_new ); +void lsf_enc_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 Q_new ); void Es_pred_enc_fx( Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ Word16 *indice, /* o : indice of quantization */ @@ -1315,6 +1434,15 @@ void perform_noise_estimation_enc_fx( Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC st ); /* i/o: FD_CNG structure containing all buffers and variables */ +void perform_noise_estimation_enc_ivas_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *enerBuffer, + Word16 enerBuffer_exp, + HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ + const int32_t input_Fs, /* i : input sampling rate */ + CPE_ENC_HANDLE hCPE /* i : CPE encoder structure */ +); + /* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */ Word16 AdjustFirstSID_fx( Word16 npart, @@ -1988,7 +2116,35 @@ void qlpc_avq_fx( const Word32 sr_core /* i : internal sampling rate */ ); +/* ivas_tcx_core_enc.c */ +void stereo_tcx_init_enc_fx( + Encoder_State *st /* i/o: encoder state structure */ +); +void IGF_UpdateInfo( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +); +Word16 IGF_getCrest( /**< out: Q15| crest factor */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ +); +Word16 IGF_getSFM( /**< out: Q15| SFM value */ + Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ + const Word32 *energy, /**< in: Q31| energies */ + const Word16 *energy_exp, /**< in: | exponent of energies */ + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ +); /* IGFEnc.c */ +void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ +); void IGFEncApplyMono_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ Encoder_State *st, /**< in: | Encoder state */ @@ -2695,10 +2851,9 @@ void pre_proc_fx( Word16 lsp_new[M], /* o : LSPs at the end of the frame */ Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - + Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ @@ -3029,6 +3184,16 @@ Word32 mslvq_cng_fx( const Word16 *w, /* i : weights for LSF quantization Q10*/ Word16 *no_scales ); +Word32 mslvq_cng_ivas_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +); + void Unified_weighting_fx( const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, @@ -3061,6 +3226,18 @@ Word32 mslvq_fx( Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ Word16 no_scales[][2] ); +Word32 mslvq_ivas_fx( + Word16 *pTmp, /* i : M-dimensional i vector */ + Word16 *quant, /* o : quantized vector */ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + Word16 *w, /* i : weights for LSF quantization */ + Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + Word16 mode_glb, /* i : LVQ coding mode */ + Word16 pred_flag /* i : prediction flag (0: safety net, 1 - predictive )*/ +); + Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ @@ -3216,6 +3393,14 @@ void index_lvq_fx( Word32 *p_offset_scale2, Word16 *p_no_scales ); +void index_lvq_ivas_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i : scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ); + ivas_error init_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ ); diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 994a513a98825a8719377d9fac7196a5075f3b51..e87ae006fd211b0f990222f7add781d08b249916 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index d5bd9ee48e7fcb665a1bfa095ee92b6c23a9b987..1cee445e0e4646822e64ab085e3cbbd62ccb7007 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com_fx.h" #include "rom_com.h" diff --git a/lib_enc/q_gain2p_fx.c b/lib_enc/q_gain2p_fx.c index 6c0110bc7a47b2266562c3dbdfb16cc29c8298ee..8bfdcb588048b0467f18e9ff8289c76d904d4955 100644 --- a/lib_enc/q_gain2p_fx.c +++ b/lib_enc/q_gain2p_fx.c @@ -10,8 +10,7 @@ #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index 892a25eba219b1d4c4d230da8d8644174f41ce87..2740eac14660bf2caf842cda217788a461723c5c 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -9,8 +9,7 @@ #include "cnst.h" //#include "prot_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index 2576939280473d17e2f4c19a2643ce1df0c651b4..dab87e3b32c946701fff65c5e76c260a19cc3b8b 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -11,8 +11,7 @@ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" #include "rom_basop_util.h" diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index 81fb7695232db1a83fbc073ae525e79a49bc1b51..b05b2cf99fbe8ede4f1bdacde5e637bf19e2a3ac 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/re8_cod_fx.c b/lib_enc/re8_cod_fx.c index 0b14385fecf180e19568567834ad0aea5b01f3e7..e035baf57ccfbd988bbb2596722035453751371f 100644 --- a/lib_enc/re8_cod_fx.c +++ b/lib_enc/re8_cod_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*------------------------------------------------------------------------ diff --git a/lib_enc/reordernorm_fx.c b/lib_enc/reordernorm_fx.c index df30c30846dd8c80d96ddf034f87752de7b603e4..40f12ffb8bec38ed8ecbc01a358e73bd0db34972 100644 --- a/lib_enc/reordernorm_fx.c +++ b/lib_enc/reordernorm_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" #include "rom_com.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------*/ diff --git a/lib_enc/rom_enc.c b/lib_enc/rom_enc.c index 9b4d998d65e41f874714cdd66559ca2bddf4bf7b..49ea00a498f97a80d156fce03a163f6dae007ba0 100644 --- a/lib_enc/rom_enc.c +++ b/lib_enc/rom_enc.c @@ -231,7 +231,7 @@ const int16_t sublen1_12k8[7] = { 40, 40, 50, 50, 80, 80, 115 }; const int16_t sec_length_12k8[4] = { 7, 15, 30, 54 }; const int16_t sec_length1_12k8[4] = { 10, 19, 37, 38 }; const float h_fir[5] = {0.13f, 0.23f, 0.28f, 0.23f, 0.13f}; -const Word16 H_fir[] = { 4260, 7536, 9175, 7536, 4260 }; +const Word16 h_fir_fx[] = { 4260, 7536, 9175, 7536, 4260 }; const float W_HIST[DTX_HIST_SIZE] = { @@ -412,12 +412,24 @@ const float sm_means[N_SMC_FEATURES] = { 109.073304f, 0.727576f, 0.246557f, 0.291464f, 0.836498f, 1.021915f, 1.213649f, 64.230265f, 1.236224f, -2.347783f, 1.795570f, -0.039230f, -0.292081f, 0.611993f, 5.587905f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 sm_means_fx[N_SMC_FEATURES] = +{ +114371648, 762918, 258533, 305622, 877131, 1071555, 1272603, 67350312, +1296274, -2461829, 1882791, -41135, -306269, 641721, 5859343, +}; +#endif const float sm_scale[N_SMC_FEATURES] = { 44.621579f, 0.159182f, 0.063806f, 0.067614f, 0.112130f, 0.103447f, 0.091769f, 16.522003f, 0.115806f, 1.284023f, 3.337835f, 1.726416f, 1.422670f, 0.270914f, 0.422958f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 sm_scale_fx[N_SMC_FEATURES] = +{//Q20 +46789116, 166914, 66905, 70898, 117576, 108472, 96226, 17324576, +121431, 1346395, 3499973, 1810278, 1491777, 284073, 443503, +}; +#endif const float hout_intervals[N_SMC_FEATURES * 2] = { 18.000000f, 230.000000f, 0.000000f, 0.999769f, 0.119389f, 0.990880f, 0.255791f, 1.181627f, @@ -426,25 +438,51 @@ const float hout_intervals[N_SMC_FEATURES * 2] = -11.751500f, 10.883281f, 0.000793f, 1.994476f, 3.021017f, 10.545962f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 hout_intervals_fx[N_SMC_FEATURES * 2] = +{//Q20 +18874368, 241172480, 0, 1048333, 125188, 1039013, 268216, 1239025, +426065, 1451491, 608719, 1618445, 818630, 1973136, 0, 127492952, +0, 275457504, -8950052, -58, -15134888, 18681054, -11149023, 12630839, +-12322341, 11411947, 831, 2091359, 3167766, 11058243, +}; +#endif const float bcox_add_cnst[N_SMC_FEATURES] = { 0.000000f, 0.000000f, -0.878682f, -0.726044f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.778993f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 bcox_add_cnst_fx[N_SMC_FEATURES] = +{ + 0, 0, -1886955264, -1559167616, 0, 0, 0, 0, +-1672874752, 0, 0, 0, 0, 0, 0, +}; +#endif const float bcox_lmbd[N_SMC_FEATURES] = { 0.000000f, 0.000000f, -0.664282f, -0.422504f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.634475f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 bcox_lmbd_fx[N_SMC_FEATURES] = +{ +0, 0, -1426534784, -907320448, 0, 0, 0, 0, +-1362524672, 0, 0, 0, 0, 0, 0, +}; +#endif const float pca_mean_[N_SMC_FEATURES] = { 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.000000f, -0.000000f, 0.000000f, -0.000000f, -0.000000f, 0.000000f, 0.000000f, -0.000000f, 0.000000f, 0.000000f, 0.000000f }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 pca_mean_fx[N_SMC_FEATURES] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, +}; +#endif const float pca_components_[N_SMC_FEATURES * N_PCA_COEF] = { 0.025076f, -0.242897f, 0.309604f, 0.391805f, 0.384930f, 0.378366f, 0.352165f, -0.191363f, 0.158511f, 0.329501f, 0.145794f, 0.086507f, 0.009591f, 0.276506f, -0.007154f, @@ -460,7 +498,35 @@ const float pca_components_[N_SMC_FEATURES * N_PCA_COEF] = -0.025136f, -0.058113f, 0.137926f, 0.044374f, -0.239076f, 0.007627f, 0.343252f, 0.516920f, 0.447960f, -0.427809f, 0.100915f, 0.071696f, 0.016780f, 0.162128f, 0.327376f, -0.016076f, -0.042889f, -0.441975f, 0.409942f, -0.243623f, -0.482644f, 0.460423f, 0.052715f, -0.067754f, 0.305681f, 0.058106f, -0.008628f, 0.098064f, -0.032513f, -0.123637f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 pca_components_fx[N_SMC_FEATURES * N_PCA_COEF] = +{ + //Q31 +53850300, -521617344, 664869504, 841394816, 826630912, 812534784, 756268608, -410948928, +340399776, 707598016, 313090240, 185772368, 20596516, 593792128, -15363098, 552253312, +-333467712, 528749120, 182890448, 96868696, 32978906, -34922380, 862927680, -1019088384, +569624320, -298519552, 97158600, 415727072, -688403776, 1008881344, 39696236, 883947200, +-590381888, 251015072, 628265664, 568803968, 309151744, 270411136, -356222432, -344628160, +1206892288, -198603584, -495733728, -719314688, 159293888, -1166596864, 280759872, 331511360, +-81920056, 75333728, 215553664, 490723648, 432773792, -99411312, 345044800, -779497920, +-1242942080, -503838304, -167628272, -107908904, -391501312, 80378168, 131556992, 200443984, +127420944, -416188768, -172488032, 193806112, -74691632, 242253328, -305453792, 1222304768, +-1564175488, 12887049, 198238512, -1246255616, 574915712, 215371136, 530961024, 363511008, +-221427040, -658203712, 398349632, 82134808, 83833464, 233839488, 623672192, 1075657344, +30015378, -106077104, -140690240, 98930280, -510246400, -587343232, 286442112, 674346368, +982237568, -34930968, -186231936, -322264288, -911922496, 959551552, 488664192, -448772544, +-378040864, -1026978240, -1448578688, -578708160, -296335552, 35369056, 95511480, -66737348, +-386493376, -261140448, -263822656, 508893504, -20220706, -31720480, -254169728, 639462656, +-167057040, 899647488, -181004960, -47577500, -325298688, 48760764, 203744656, -1062381632, +244351424, 282318944, -274137024, 26607322, 168482976, 159102768, 1480558976, -177899696, +29734058, 1058730944, 682360768, -553178880, -241886112, 403883680, -807309952, -628843328, +-992895488, 53388592, 67669360, -22754736, -593890880, -267031008, -53979148, -124796720, +296193824, 95292440, -513411808, 16378858, 737128064, 1110077184, 961986752, -918712832, +216713312, 153965984, 36034776, 348167232, 703034624, -34522948, -92103424, -949134080, +880343744, -523176416, -1036470080, 988750848, 113204600, -145500608, 656444928, 124781688, +-18528488, 210590832, -69821136, -265508432, +}; +#endif const float means_speech[N_SMC_MIXTURES*N_PCA_COEF] = { 4.144528f, -0.445994f, -0.070302f, 0.359876f, -0.040196f, -0.118265f, 0.644765f, -0.174143f, -0.114585f, 0.658716f, 0.278107f, -0.260928f, @@ -470,7 +536,21 @@ const float means_speech[N_SMC_MIXTURES*N_PCA_COEF] = -0.413334f, -1.784803f, -0.187205f, -0.391714f, -0.243155f, -0.223117f, -0.018042f, 0.129642f, 0.137285f, -0.049526f, 0.029685f, -0.024247f, -0.694581f, -1.756488f, 0.597206f, 1.030080f, 0.297682f, 0.383268f, 0.135800f, -0.177134f, 0.096645f, -0.268388f, -0.151836f, -0.101950f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 means_speech_fx[N_SMC_MIXTURES*N_PCA_COEF] = +{ + //Q27 + 556269120, -59860300, -9435775, 48301740, -5395016, -15873260, 86538896, -23373078, +-15379338, 88411368, 37326888, -35021164, -4035256, -161975568, 85803920, -81899120, +-7169642, 64167884, -82728320, -29112898, 81431240, 15287399, -468956, 29038140, +-256403904, -208488720, 86349912, 56074020, 36843036, 19549348, 1753688, -32431970, +29630308, 14530545, -8338545, 4083037, 253332208, -116034448, -127942512, -33905276, +8696369, -14094204, -30782970, 37237904, 4475893, -12044833, -4461531, 2582617, +-55476752, -239552208, -25126230, -52574964, -32635712, -29946256, -2421556, 17400254, +18426080, -6647267, 3984253, -3254377, -93225080, -235751824, 80155632, 138254992, +39954200, 51441360, 18226768, -23774524, 12971472, -36022428, -20379082, -13683497, +}; +#endif const float log_det_chol_speech[N_SMC_MIXTURES] = { 6.500575f, 5.852711f, 5.579274f, 6.652653f, 4.752021f, 5.338445f, @@ -487,7 +567,69 @@ const float prec_chol_speech[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) }; #ifdef IVAS_FLOAT_FIXED -const Word32 prec_chol_speech_fx[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = { 232432352, -59879628, 304533312, -125429152, 99142344, 326068544, -56826444, 46350480, 37527544, 329625600, 31308164, -19632564, 32069984, 57804624, 403167520, 3554890, 64722740, -62716724, 56281252, -4959882, 478142080, -101929504, -14876156, 39897560, -40777760, -47372952, 187926288, 341264960, 21311090, -155172336, 108759040, -143880592, -20300968, -5616206, 73920144, 570679040, 218755296, -162775504, -64450816, -7369627, -36893500, -37446476, -80293072, 8201777, 597213568, -152507040, -256513440, -45927696, -77678512, -140313632, -170642272, -94367944, 112342656, 201967072, 756224576, -208080960, 225792336, 58484840, 66006132, -48434348, 7039720, -102562208, 39706704, -339747744, -90058216, 796577920, 202634944, 37851548, 10156524, 82895824, 73911016, -121567440, -148495536, -112251120, 27724282, 54130280, 84421344, 906663552, 209343680, 32186754, 306301216, -116259936, -36924908, 224391904, -24221736, 35642860, 46462152, 312121440, -39075344, -7622225, 60599840, 68880272, 244525904, -58326728, -36760892, 23687014, 173225968, 23444078, 473461088, -15582947, -34961840, 37741220, 31105764, -74304544, 12497281, 425261888, 33453500, 9509863, -120815016, 63221652, 7134209, 101693816, 61658284, 770215168, -17228724, -276690656, 128551864, -10146055, -15149155, 107287480, -8414646, -387697024, 649792832, 50705580, -73682312, -57487332, 8967623, -3074928, 20067160, 135318848, 273094432, -35929816, 819158720, -19654308, -23457232, 20863072, 11649830, -4230006, 119185344, 150983408, -51511960, -81179712, 365100416, 677546368, -1104880, 67182952, -148998320, -17748684, -31462514, 36981012, -243459152, -30465546, 39841460, -70792064, -7307618, 793560192, 196828960, -32199102, 232271296, -76255536, 20992994, 207772000, 19910932, 13635984, 32428882, 280196960, -25198842, -1165278, 42992624, -13211856, 237527792, -62810408, -99852624, 47340472, 231473232, -57426664, 489151424, 19632028, 2961111, -8761465, 94918512, -12379975, 80280456, 362603424, 142636400, 32065152, -350124672, 127381216, 47764332, 62010736, -35439924, 1157346560, -346969728, -366012832, 596499264, 170357456, 55534196, 444685088, 84101632, -1036655616, 1080018176, 147994640, -5793911, -7695776, 55731228, 16318191, 137087568, 107977896, 172195712, -159871568, 713860352, 105155024, -52278340, -47440328, 26797374, 11704323, 154628224, 63859720, 177926800, -3174517, 294978624, 586304384, -55530976, 100304664, -184816464, -121156736, -22429392, -187445792, -66290940, 399174784, -145260096, -435817856, -227558112, 632079616, 235678272, -8552354, 240827680, -37353868, -9822859, 337976896, -48387368, -7377143, 35740572, 353392864, 21862994, -32516660, 28525294, 31415538, 414974112, -20909780, 53856472, -18235358, 45784888, -63774628, 489165088, -36009004, -13625515, 11037798, -62288300, 22793928, 41337988, 507775744, 36684656, -117420112, 22649242, -64967556, -21585164, -59302760, 61845652, 551227904, 28334704, -96908688, -10986795, -3158680, -1148098, -1090116, -21733072, -98534064, 548509440, -12526541, -124452312, -39815688, 28119150, -82867096, -48626816, 41780368, 15056276, 114722336, 752520384, -72335840, 138609600, 457950, 58517588, -34335848, 7930120, 68274944, 71795744, -218303520, 30022896, 684244416, 29311810, 24879134, -5031822, -3604014, -107700064, 34280548, -161518960, -29972698, 45524776, -28767690, 70451960, 997068864, 181172464, -10389794, 282143392, -18262200, -9411616, 194651136, -34642400, 14696036, 32774090, 266709152, -12321724, -7934147, 42899744, 17961822, 326197120, -61064236, 2757905, -9434969, 114016616, -45294724, 423241632, 44844560, 7194607, -20771536, 17406428, -12688407, 27344446, 398144544, -20988432, 7578201, -36547220, 31998848, 1553972, 12336757, 23499376, 524998272, 38193264, -220705488, -3866007, -51896088, -8053332, 4608500, 2672543, 105980736, 617651200, 138849584, -138894416, -16658031, 14451491, -13349295, 42108932, 90309472, 45946488, 90752120, 714260864, -36247644, 218070784, 60232888, 133086544, 36377836, 146851648, 21597244, -80293880, -242705376, -25434260, 721932224, -73526080, 12684917, -26789322, -47208132, -29985852, -50325744, 4686614, 48175036, 81419696, -245451200, -121876408, 664714368, 166866720, 2983391, 263386720, -68162208, -7784091, 192441376, -145223, -15735686, -35828080, 344984128, 6308501, -28874260, 1040187, 139961712, 251922656, -73661104, -232072656, 127662000, 362434304, 189085392, 530900640, -2567048, -48370192, -40885672, 82937160, 128033784, 63094680, 384248448, 54663660, -320496640, -208546160, 766008512, 371514944, 699983808, 56493048, 1276140544, -85480856, -172129408, 182972048, 17228992, 16679505, 132060848, 21129896, -319555488, 617272960, 74918456, -142655184, 15233981, 243838976, 160190736, 297619744, 148904096, 314365024, -1673695, 579634560, 47073380, -135740560, 44690208, 97419520, 61031752, 157764080, 80927112, 97527968, 62705448, 190179008, 603058240, -73368240, 30219122, -3786282, -19939118, -20823612, -51310096, -75429024, 90901104, 18365818, -393250432, -234402672, 705817728 }; +const Word32 prec_chol_speech_fx[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = +{ + //Q28 + 232432352, -59879628, 304533312, -125429152, 99142344, 326068544, -56826444, 46350480, +37527544, 329625600, 31308164, -19632564, 32069984, 57804624, 403167520, 3554890, +64722740, -62716724, 56281252, -4959882, 478142080, -101929504, -14876156, 39897560, +-40777760, -47372952, 187926288, 341264960, 21311090, -155172336, 108759040, -143880592, +-20300968, -5616206, 73920144, 570679040, 218755296, -162775504, -64450816, -7369627, +-36893500, -37446476, -80293072, 8201777, 597213568, -152507040, -256513440, -45927696, +-77678512, -140313632, -170642272, -94367944, 112342656, 201967072, 756224576, -208080960, +225792336, 58484840, 66006132, -48434348, 7039720, -102562208, 39706704, -339747744, +-90058216, 796577920, 202634944, 37851548, 10156524, 82895824, 73911016, -121567440, +-148495536, -112251120, 27724282, 54130280, 84421344, 906663552, 209343680, 32186754, +306301216, -116259936, -36924908, 224391904, -24221736, 35642860, 46462152, 312121440, +-39075344, -7622225, 60599840, 68880272, 244525904, -58326728, -36760892, 23687014, +173225968, 23444078, 473461088, -15582947, -34961840, 37741220, 31105764, -74304544, +12497281, 425261888, 33453500, 9509863, -120815016, 63221652, 7134209, 101693816, +61658284, 770215168, -17228724, -276690656, 128551864, -10146055, -15149155, 107287480, +-8414646, -387697024, 649792832, 50705580, -73682312, -57487332, 8967623, -3074928, +20067160, 135318848, 273094432, -35929816, 819158720, -19654308, -23457232, 20863072, +11649830, -4230006, 119185344, 150983408, -51511960, -81179712, 365100416, 677546368, +-1104880, 67182952, -148998320, -17748684, -31462514, 36981012, -243459152, -30465546, +39841460, -70792064, -7307618, 793560192, 196828960, -32199102, 232271296, -76255536, +20992994, 207772000, 19910932, 13635984, 32428882, 280196960, -25198842, -1165278, +42992624, -13211856, 237527792, -62810408, -99852624, 47340472, 231473232, -57426664, +489151424, 19632028, 2961111, -8761465, 94918512, -12379975, 80280456, 362603424, +142636400, 32065152, -350124672, 127381216, 47764332, 62010736, -35439924, 1157346560, +-346969728, -366012832, 596499264, 170357456, 55534196, 444685088, 84101632, -1036655616, +1080018176, 147994640, -5793911, -7695776, 55731228, 16318191, 137087568, 107977896, +172195712, -159871568, 713860352, 105155024, -52278340, -47440328, 26797374, 11704323, +154628224, 63859720, 177926800, -3174517, 294978624, 586304384, -55530976, 100304664, +-184816464, -121156736, -22429392, -187445792, -66290940, 399174784, -145260096, -435817856, +-227558112, 632079616, 235678272, -8552354, 240827680, -37353868, -9822859, 337976896, +-48387368, -7377143, 35740572, 353392864, 21862994, -32516660, 28525294, 31415538, +414974112, -20909780, 53856472, -18235358, 45784888, -63774628, 489165088, -36009004, +-13625515, 11037798, -62288300, 22793928, 41337988, 507775744, 36684656, -117420112, +22649242, -64967556, -21585164, -59302760, 61845652, 551227904, 28334704, -96908688, +-10986795, -3158680, -1148098, -1090116, -21733072, -98534064, 548509440, -12526541, +-124452312, -39815688, 28119150, -82867096, -48626816, 41780368, 15056276, 114722336, +752520384, -72335840, 138609600, 457950, 58517588, -34335848, 7930120, 68274944, +71795744, -218303520, 30022896, 684244416, 29311810, 24879134, -5031822, -3604014, +-107700064, 34280548, -161518960, -29972698, 45524776, -28767690, 70451960, 997068864, +181172464, -10389794, 282143392, -18262200, -9411616, 194651136, -34642400, 14696036, +32774090, 266709152, -12321724, -7934147, 42899744, 17961822, 326197120, -61064236, +2757905, -9434969, 114016616, -45294724, 423241632, 44844560, 7194607, -20771536, +17406428, -12688407, 27344446, 398144544, -20988432, 7578201, -36547220, 31998848, +1553972, 12336757, 23499376, 524998272, 38193264, -220705488, -3866007, -51896088, +-8053332, 4608500, 2672543, 105980736, 617651200, 138849584, -138894416, -16658031, +14451491, -13349295, 42108932, 90309472, 45946488, 90752120, 714260864, -36247644, +218070784, 60232888, 133086544, 36377836, 146851648, 21597244, -80293880, -242705376, +-25434260, 721932224, -73526080, 12684917, -26789322, -47208132, -29985852, -50325744, +4686614, 48175036, 81419696, -245451200, -121876408, 664714368, 166866720, 2983391, +263386720, -68162208, -7784091, 192441376, -145223, -15735686, -35828080, 344984128, +6308501, -28874260, 1040187, 139961712, 251922656, -73661104, -232072656, 127662000, +362434304, 189085392, 530900640, -2567048, -48370192, -40885672, 82937160, 128033784, +63094680, 384248448, 54663660, -320496640, -208546160, 766008512, 371514944, 699983808, +56493048, 1276140544, -85480856, -172129408, 182972048, 17228992, 16679505, 132060848, +21129896, -319555488, 617272960, 74918456, -142655184, 15233981, 243838976, 160190736, +297619744, 148904096, 314365024, -1673695, 579634560, 47073380, -135740560, 44690208, +97419520, 61031752, 157764080, 80927112, 97527968, 62705448, 190179008, 603058240, +-73368240, 30219122, -3786282, -19939118, -20823612, -51310096, -75429024, 90901104, +18365818, -393250432, -234402672, 705817728, +}; #endif const float weights_speech[N_SMC_MIXTURES] = @@ -504,7 +646,21 @@ const float means_music[N_SMC_MIXTURES*N_PCA_COEF] = -0.944544f, 1.303678f, 0.326616f, 0.443005f, 0.339787f, 0.353776f, 0.811425f, -0.201050f, 0.056356f, 0.825931f, 0.425448f, -0.400853f, 2.416758f, 0.991434f, -0.249973f, -0.264729f, -0.003941f, -0.242565f, -0.114334f, 0.179267f, 0.085679f, -0.001649f, -0.267403f, 0.028878f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 means_music_fx[N_SMC_MIXTURES*N_PCA_COEF] = +{ + //Q27 + 88128840, 204692912, 12705453, 71462352, 12596468, 40563280, -1386066, -52265056, +-39146480, -6666997, 9846481, 10781844, -57806772, -1044348, 8851928, -134822384, +-26193530, -61436556, 53966400, 37307696, -3429397, 19347082, 13950591, -11268518, +-48344556, 197877728, -36032360, -8134399, -1136958, -20838778, -32593702, 16027207, +-26324122, -40342764, -3959959, 8085410, -332178944, 164642336, -341718, 34049964, +-15855543, 8985877, 22481872, 6408225, -40554556, 2538594, 4626216, 1585111, +-126774552, 174976704, 43837656, 59459124, 45605440, 47483012, 108907616, -26984474, +7563974, 110854584, 57102664, -53801580, 324371776, 133068016, -33550808, -35531324, +-528952, -32556524, -15345650, 24060810, 11499641, -221325, -35890224, 3875939, +}; +#endif const float log_det_chol_music[N_SMC_MIXTURES] = { 3.236255f, 3.517110f, 5.675361f, 2.875446f, -2.234983f, 7.961542f, @@ -523,7 +679,66 @@ const float prec_chol_music[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) #ifdef IVAS_FLOAT_FIXED const Word32 prec_chol_music_fx[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = { -232322304, 25836912, 235062480, -21970368, -88834688, 289087264, 38061464, 12829336, 25661356, 216226640, 3946806, 35926596, -49888460, 17696070, 235923888, -6313870, -29279598, 78824728, -1208764, 27664958, 273027328, -37742024, -71072048, 103689640, -10025259, -37697196, -61880548, 396421184, -26288422, 15300284, -459293, -23770764, 3474360, -25473720, 47310944, 332768160, 39007700, 9191767, -7766106, -35545148, 21523424, 6770747, -124619552, 1410091, 508736736, -25959320, -7817109, 19565456, 1404185, -51538532, -45457932, 165445904, -28407450, -81223736, 586521024, -46704816, -52083996, 9754944, -31150324, -39091720, -40270152, 66884720, 30225296, 100608000, 24531512, 657688896, 68076576, 48213692, -48020152, 49097380, -4268929, 59026004, -192775040, -50962204, -31122406, -117876448, -182476256, 625576192, 144678656, -9655086, 218327952, 6044361, -48620372, 254562448, -42861896, -13298292, 33123862, 287620000, -12122277, -30804848, 33071786, 16293764, 388198208, -19213268, 24338774, 14173929, -33506382, -87690080, 361291840, 34886676, 52138220, -48904644, -17044846, 2490812, 73471056, 354929120, 40659380, 38784092, 24256364, -112064552, -5929471, -94763888, -36720092, 322304000, -56521232, -65294776, 11020081, -15673409, 12677670, -51147960, -59997204, 68434128, 456261088, 44138304, 4000225, -77793136, 61852092, -3655554, -41457440, 71121976, -86157848, -69391640, 621925248, 56908, 50305072, -2964869, 102686760, -14214731, -68874360, 41617696, -34848560, -20007568, 56042344, 554498560, -36107792, -20590342, -25757992, -64163052, 53273432, 35053644, -77861048, -7609071, 98731368, 8330089, 81691888, 807686592, 206408080, 29242554, 246745872, -30320054, -141839152, 416885632, -31085094, 1968705, -7943542, 294907488, 972004, 26633630, -66413080, -21165868, 367168960, 11512928, -20904948, 56274004, -44399224, -4818953, 360435008, -49596404, 13496398, 7960453, 47073916, -4338185, -43219720, 462487456, 13815031, 2689991, 103510592, -71014872, -75477072, -97242624, -9769708, 371118464, -17768548, -22740510, -33236068, -8622415, 24936848, 18291192, -70021120, 2836020, 476147872, 63471028, 25856776, -21647440, 32818918, 34664144, 29404152, 114646368, -122478512, -68419632, 815255936, 35136860, -35646080, -34052916, 1725771, 2581812, -62708940, 215970288, -82662016, -34325112, 447461504, 753578304, -99274408, -3290213, 4633733, -15484968, -36483064, 40284916, -407272960, 58910844, 134671648, -601330048, -345841248, 981086208, 206335056, 1025423, 222901824, -58332100, -39948832, 262789184, -18609020, 1410628, -1774089, 212590416, 18125298, 28513752, -59463552, 4719095, 246369264, -81872, -23613194, 15571135, -16710912, 46739712, 268572096, 29908542, 37123820, 22983444, 55254756, 2779112, -57131120, 341562368, 5126580, 21001584, -6036039, -24000546, -46808700, -51209432, -9852655, 337137760, -8485513, -113351704, -16093779, -60946660, 8815152, -10634339, -80527416, 50575120, 478848064, 149115360, 27080038, 22408992, -24449906, 61073900, 40576168, 139484976, -77672608, -93439968, 705148288, 18536542, 21612006, -26196616, -17896592, 48906792, 10430328, 52505440, -55231936, -34737696, 181267760, 633243008, -77855408, -1544846, -16549583, -11117523, 31134218, 10136123, -124216360, 27077622, 80264352, -345837472, -203551920, 593004544, 99558952, 18271060, 165076528, -18376286, -30611842, 213814752, -21311628, -7249636, 15457856, 170620528, -4867540, -16669573, -49741896, 22724940, 143143472, -39989100, -10398384, 72010760, 44482440, 6079526, 200783008, -1092263, 15936208, 13659607, 18654116, -27689922, -23768886, 188797104, 12175964, -32829120, -61108256, 16816140, 3177470, 18617342, -5304821, 286432992, 28388660, -118288232, 51768048, -15788031, 7528809, 37260184, -33815620, -179149264, 306826016, -17569370, 22469390, -41274636, -16302085, -108179, -24384408, 16991428, -10070088, 94377344, 317392448, -28549990, -4354291, -2879238, 26857504, 15448729, 28430268, -357556, -21060910, -72179608, -65214248, 414794528, 6270384, -21697370, 62073552, -9898557, 21225192, 16768895, 1158030, 20269024, 9883257, 18578686, -97534416, 397891136, 324576576, 23795998, 325167936, -97054984, -170963328, 433155232, -19735912, 25351044, 93515664, 372817920, 21614692, -10068209, 19011672, 14128295, 503773088, -8658386, 33526246, -13009456, -61316296, -60996588, 463537312, -78218872, -20931524, 80347832, -46129292, 3235184, 61337772, 540847488, -10609643, -67685192, 110726408, -146586160, -74121744, -133886744, 76196480, 465427072, 12021882, -46549660, 25719874, -9411616, 1885759, 63607392, -72460128, -51621212, 528433184, -179129392, -56301116, -69872408, 23375360, -64939904, -75586056, 97111088, -49225964, 47048952, 831205824, -126763272, -4281814, -11618423, -14073534, -94524984, -89800784, 104806864, 30433332, -80776520, 390530912, 774659392, 128537096, 13576928, -10674873, 30707942, -18166370, 3521068, -300103584, -56028652, 119586656, -8497861, 3017751, 1177908480, + //Q28 +232322304, 25836912, 235062480, -21970368, -88834688, 289087264, 38061464, 12829336, +25661356, 216226640, 3946806, 35926596, -49888460, 17696070, 235923888, -6313870, +-29279598, 78824728, -1208764, 27664958, 273027328, -37742024, -71072048, 103689640, +-10025259, -37697196, -61880548, 396421184, -26288422, 15300284, -459293, -23770764, +3474360, -25473720, 47310944, 332768160, 39007700, 9191767, -7766106, -35545148, +21523424, 6770747, -124619552, 1410091, 508736736, -25959320, -7817109, 19565456, +1404185, -51538532, -45457932, 165445904, -28407450, -81223736, 586521024, -46704816, +-52083996, 9754944, -31150324, -39091720, -40270152, 66884720, 30225296, 100608000, +24531512, 657688896, 68076576, 48213692, -48020152, 49097380, -4268929, 59026004, +-192775040, -50962204, -31122406, -117876448, -182476256, 625576192, 144678656, -9655086, +218327952, 6044361, -48620372, 254562448, -42861896, -13298292, 33123862, 287620000, +-12122277, -30804848, 33071786, 16293764, 388198208, -19213268, 24338774, 14173929, +-33506382, -87690080, 361291840, 34886676, 52138220, -48904644, -17044846, 2490812, +73471056, 354929120, 40659380, 38784092, 24256364, -112064552, -5929471, -94763888, +-36720092, 322304000, -56521232, -65294776, 11020081, -15673409, 12677670, -51147960, +-59997204, 68434128, 456261088, 44138304, 4000225, -77793136, 61852092, -3655554, +-41457440, 71121976, -86157848, -69391640, 621925248, 56908, 50305072, -2964869, +102686760, -14214731, -68874360, 41617696, -34848560, -20007568, 56042344, 554498560, +-36107792, -20590342, -25757992, -64163052, 53273432, 35053644, -77861048, -7609071, +98731368, 8330089, 81691888, 807686592, 206408080, 29242554, 246745872, -30320054, +-141839152, 416885632, -31085094, 1968705, -7943542, 294907488, 972004, 26633630, +-66413080, -21165868, 367168960, 11512928, -20904948, 56274004, -44399224, -4818953, +360435008, -49596404, 13496398, 7960453, 47073916, -4338185, -43219720, 462487456, +13815031, 2689991, 103510592, -71014872, -75477072, -97242624, -9769708, 371118464, +-17768548, -22740510, -33236068, -8622415, 24936848, 18291192, -70021120, 2836020, +476147872, 63471028, 25856776, -21647440, 32818918, 34664144, 29404152, 114646368, +-122478512, -68419632, 815255936, 35136860, -35646080, -34052916, 1725771, 2581812, +-62708940, 215970288, -82662016, -34325112, 447461504, 753578304, -99274408, -3290213, +4633733, -15484968, -36483064, 40284916, -407272960, 58910844, 134671648, -601330048, +-345841248, 981086208, 206335056, 1025423, 222901824, -58332100, -39948832, 262789184, +-18609020, 1410628, -1774089, 212590416, 18125298, 28513752, -59463552, 4719095, +246369264, -81872, -23613194, 15571135, -16710912, 46739712, 268572096, 29908542, +37123820, 22983444, 55254756, 2779112, -57131120, 341562368, 5126580, 21001584, +-6036039, -24000546, -46808700, -51209432, -9852655, 337137760, -8485513, -113351704, +-16093779, -60946660, 8815152, -10634339, -80527416, 50575120, 478848064, 149115360, +27080038, 22408992, -24449906, 61073900, 40576168, 139484976, -77672608, -93439968, +705148288, 18536542, 21612006, -26196616, -17896592, 48906792, 10430328, 52505440, +-55231936, -34737696, 181267760, 633243008, -77855408, -1544846, -16549583, -11117523, +31134218, 10136123, -124216360, 27077622, 80264352, -345837472, -203551920, 593004544, +99558952, 18271060, 165076528, -18376286, -30611842, 213814752, -21311628, -7249636, +15457856, 170620528, -4867540, -16669573, -49741896, 22724940, 143143472, -39989100, +-10398384, 72010760, 44482440, 6079526, 200783008, -1092263, 15936208, 13659607, +18654116, -27689922, -23768886, 188797104, 12175964, -32829120, -61108256, 16816140, +3177470, 18617342, -5304821, 286432992, 28388660, -118288232, 51768048, -15788031, +7528809, 37260184, -33815620, -179149264, 306826016, -17569370, 22469390, -41274636, +-16302085, -108179, -24384408, 16991428, -10070088, 94377344, 317392448, -28549990, +-4354291, -2879238, 26857504, 15448729, 28430268, -357556, -21060910, -72179608, +-65214248, 414794528, 6270384, -21697370, 62073552, -9898557, 21225192, 16768895, +1158030, 20269024, 9883257, 18578686, -97534416, 397891136, 324576576, 23795998, +325167936, -97054984, -170963328, 433155232, -19735912, 25351044, 93515664, 372817920, +21614692, -10068209, 19011672, 14128295, 503773088, -8658386, 33526246, -13009456, +-61316296, -60996588, 463537312, -78218872, -20931524, 80347832, -46129292, 3235184, +61337772, 540847488, -10609643, -67685192, 110726408, -146586160, -74121744, -133886744, +76196480, 465427072, 12021882, -46549660, 25719874, -9411616, 1885759, 63607392, +-72460128, -51621212, 528433184, -179129392, -56301116, -69872408, 23375360, -64939904, +-75586056, 97111088, -49225964, 47048952, 831205824, -126763272, -4281814, -11618423, +-14073534, -94524984, -89800784, 104806864, 30433332, -80776520, 390530912, 774659392, +128537096, 13576928, -10674873, 30707942, -18166370, 3521068, -300103584, -56028652, +119586656, -8497861, 3017751, 1177908480, }; #endif @@ -541,7 +756,21 @@ const float means_noise[N_SMC_MIXTURES*N_PCA_COEF] = -1.990813f, -0.723883f, -1.196019f, -1.768941f, -0.344735f, -0.677093f, -0.256214f, 1.351858f, -0.353724f, 0.768104f, -0.384513f, -0.371595f, -2.101499f, -1.294068f, -0.188406f, -1.843713f, -0.786294f, -0.539876f, 0.241184f, 1.600162f, -0.300266f, 1.225627f, 0.080940f, -0.231195f, }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 means_noise_fx[N_SMC_MIXTURES*N_PCA_COEF] = +{ + //Q27 + 139344176, 85522728, -140739360, -127496240, -11822971, -83343840, -30885916, 128914920, +55142280, 43453528, -85148664, 1472368, -161889936, -113373848, -98158928, -153415568, +-42456556, -57162792, 60016264, 208695008, -13554783, 127521472, -30868064, -26999372, +178972768, 74413936, -168077904, -33409476, 6877316, -59676692, -21294850, 147021424, +33076482, 7783688, -105503456, 23490786, 165446160, 44187832, -118290112, -7072334, +20942126, -40746756, -14936017, 106057376, 17580778, 8650601, -64193252, 13850330, +-267202400, -97157928, -160526960, -237423248, -46269548, -90877888, -34388460, 181443312, +-47476032, 103093176, -51608460, -49874636, -282058432, -173686864, -25287426, -247458976, +-105534592, -72460928, 32371168, 214770112, -40301020, 164500864, 10863583, -31030468, +}; +#endif const float log_det_chol_noise[N_SMC_MIXTURES] = { 11.878154f, 13.025598f, 12.831137f, 7.099546f, 13.242941f, 11.898383f, @@ -559,7 +788,67 @@ const float prec_chol_noise[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) #ifdef IVAS_FLOAT_FIXED const Word32 prec_chol_noise_fx[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_COEF) / 2] = -{ 438274304, -101757704, 527959936, -92401656, -40066944, 569343040, -172637280, 92605400, 90126936, 502116576, -70281768, 15855140, 42644192, -75216424, 659778944, 21871852, 200184128, -66884720, -206631952, -271753600, 579995584, -41937404, 180430768, -70175472, 31213406, -61285692, -15286594, 914624320, 95589064, -197632384, 189309536, -378043296, -192572912, -278483808, 89525912, 667027200, 86715120, -398169504, -134308192, -24187914, -117845048, -77955000, 87847112, -65235184, 674295616, 118658400, 141179872, -385477600, 90381952, 47387716, -172783040, 213091584, -92059136, 180518816, 1113415808, 89164056, 159457376, -287768704, 140198736, 53548040, 12615661, 211052816, -195082784, -315002016, 199766976, 1060323264, -162984080, -169212048, 275297472, -209311472, -148597008, 90449592, -308289792, 131478344, 206830864, -316232544, -116264224, 1640643200, 575459840, -110880488, 540680576, -20299626, -120988960, 592097728, 75230912, 156925216, 72533680, 553807552, -272710816, -155779808, 38634840, -156862400, 752763072, -182010784, 94162056, -90105192, -416297760, -234046992, 690654080, 181351232, 128870224, -96438120, 75957304, 10280273, -216431728, 1041874240, -2115271, -161272000, 112353664, -387182976, 14206141, -50861004, -182521616, 664376128, -13428752, -358865984, -61852360, -3840774, -153737552, -335891136, 127812056, 72605352, 719982528, -11629161, -73992352, -370089824, -83219288, -95394448, -78352816, -28330678, -1691143, 79366160, 1178542208, -85602184, 94195616, -206783344, 134659312, -21508390, -89069568, 127365104, -119468808, -308679296, 307254432, 1144636160, 19030194, -8984535, -70737840, -155128048, 221865936, 50559280, 68931808, -94236416, 266750224, 260988512, 297829664, 1781693056, 421042624, -59415772, 527790560, -98705864, -94187288, 738609024, -33151778, 77225928, -97992632, 568460672, 43811888, 22125524, -44354932, -38434856, 696296640, 8982924, 76764488, 78076064, -148321856, -92465280, 669700032, 31240518, 1078842, -80158048, 17065784, 42776532, -97703528, 836559488, 101995008, -23285702, -44140184, -65183912, -32696244, -173090400, 116281136, 675435968, 24943022, -289375584, -28602066, -60206048, -67754184, -46702400, 88339696, -173576816, 792158656, 13933948, -103396240, -80619760, 4375229, 22152636, 20907632, 211938912, -232494096, 278967264, 1247803392, -70594232, 74254616, -54600844, 26415928, -10635144, 33370554, 298018912, -152319936, -244328336, 782944064, 1259614592, 20826564, 8513699, 101483096, -35796672, -149573040, -20171850, -532795264, 142151072, 163440688, -597162880, -376404768, 1708897920, 209270944, -23997324, 331448000, 6588480, -58776092, 382514624, -18828332, 39394512, -32496796, 381425568, 21953188, -17026056, -17383880, 29140548, 410380096, -22143510, 714575, 45383844, 30147180, -75072000, 468424448, 6863357, -2480612, -3718636, -18806856, 45715632, -12727867, 520436480, 52698712, 758061, -3390071, -57345060, -19137300, -94494648, 48669764, 553184256, 15456245, -55625196, 37220456, -21190832, 14073266, 37691024, -82113600, -125746712, 566309184, 24663312, -79263352, -81187768, 18228110, -23309324, -35227592, 45638592, -100310304, 111057384, 747604032, -38703024, -49378972, -1829387, -24915374, -44106092, 3890166, 95093528, 4453076, -105516344, 61340456, 779151360, 14067092, 24841018, 46075604, 14026826, -73798008, -27891786, -172234896, 22042846, 8342168, -136356624, -15677436, 917865664, 323919712, -183311616, 550143680, -136109392, -92123024, 508834976, -36581580, 25082610, 186993744, 612834112, 3323231, -41768288, 10869757, -32662958, 900676672, -132146208, 173920944, -285617472, -265424416, -17592454, 746075264, 174698064, 87668608, -12579422, 50304000, -52162648, -8793140, 1121056000, 147971552, -143892672, 40492148, -332957664, -99433056, -229635520, 90426776, 754189248, 91340536, -315738880, 3497714, 95215400, -131254200, -125219504, 210190864, -40012452, 774223424, 323906560, 82644032, -378786592, 18817058, 56163140, 78116600, -101264320, -171897472, 108985600, 1384031744, 217351648, 179599424, -252806064, 287773824, -31378494, -40052984, 121498448, -198681968, -319067488, 616561856, 1259752576, -10863851, -35322348, 214155392, -580386432, 360088192, 294499200, -423245408, 122124976, 92175096, -14300899, 19809194, 1852783360, 372837536, -142020880, 513938464, -66074584, -101171176, 458718880, -55148724, 84335712, 174501568, 494334368, -23007872, -3568849, -19046838, -125238024, 850134528, -69946760, 193497408, -212820192, -393971456, -100102000, 727705408, 162900592, 171089760, -145332032, -88654296, 45897900, 17440252, 800112128, 49616000, -91281208, 77360680, -280252256, -125265672, -100565856, -62217164, 572262784, 35549444, -258559712, -79083232, 11355357, -30667678, -250266672, -44622024, 54628764, 688208640, 147327840, -118213336, -250863936, -92370248, 8184597, -101297072, -22858352, -70537856, 128080216, 1281079808, 22687360, 96064192, -115392352, 184689760, 94979176, -117889608, 20655572, -206588192, -316042752, 525827200, 1154297216, -55784644, 65338264, -189560800, -157846496, 258337456, 90826744, -80055240, -94396936, 206332112, 185089200, 185797056, 1643156480, +{ + //Q28 + 438274304, -101757704, 527959936, -92401656, -40066944, 569343040, -172637280, 92605400, +90126936, 502116576, -70281768, 15855140, 42644192, -75216424, 659778944, 21871852, +200184128, -66884720, -206631952, -271753600, 579995584, -41937404, 180430768, -70175472, +31213406, -61285692, -15286594, 914624320, 95589064, -197632384, 189309536, -378043296, +-192572912, -278483808, 89525912, 667027200, 86715120, -398169504, -134308192, -24187914, +-117845048, -77955000, 87847112, -65235184, 674295616, 118658400, 141179872, -385477600, +90381952, 47387716, -172783040, 213091584, -92059136, 180518816, 1113415808, 89164056, +159457376, -287768704, 140198736, 53548040, 12615661, 211052816, -195082784, -315002016, +199766976, 1060323264, -162984080, -169212048, 275297472, -209311472, -148597008, 90449592, +-308289792, 131478344, 206830864, -316232544, -116264224, 1640643200, 575459840, -110880488, +540680576, -20299626, -120988960, 592097728, 75230912, 156925216, 72533680, 553807552, +-272710816, -155779808, 38634840, -156862400, 752763072, -182010784, 94162056, -90105192, +-416297760, -234046992, 690654080, 181351232, 128870224, -96438120, 75957304, 10280273, +-216431728, 1041874240, -2115271, -161272000, 112353664, -387182976, 14206141, -50861004, +-182521616, 664376128, -13428752, -358865984, -61852360, -3840774, -153737552, -335891136, +127812056, 72605352, 719982528, -11629161, -73992352, -370089824, -83219288, -95394448, +-78352816, -28330678, -1691143, 79366160, 1178542208, -85602184, 94195616, -206783344, +134659312, -21508390, -89069568, 127365104, -119468808, -308679296, 307254432, 1144636160, +19030194, -8984535, -70737840, -155128048, 221865936, 50559280, 68931808, -94236416, +266750224, 260988512, 297829664, 1781693056, 421042624, -59415772, 527790560, -98705864, +-94187288, 738609024, -33151778, 77225928, -97992632, 568460672, 43811888, 22125524, +-44354932, -38434856, 696296640, 8982924, 76764488, 78076064, -148321856, -92465280, +669700032, 31240518, 1078842, -80158048, 17065784, 42776532, -97703528, 836559488, +101995008, -23285702, -44140184, -65183912, -32696244, -173090400, 116281136, 675435968, +24943022, -289375584, -28602066, -60206048, -67754184, -46702400, 88339696, -173576816, +792158656, 13933948, -103396240, -80619760, 4375229, 22152636, 20907632, 211938912, +-232494096, 278967264, 1247803392, -70594232, 74254616, -54600844, 26415928, -10635144, +33370554, 298018912, -152319936, -244328336, 782944064, 1259614592, 20826564, 8513699, +101483096, -35796672, -149573040, -20171850, -532795264, 142151072, 163440688, -597162880, +-376404768, 1708897920, 209270944, -23997324, 331448000, 6588480, -58776092, 382514624, +-18828332, 39394512, -32496796, 381425568, 21953188, -17026056, -17383880, 29140548, +410380096, -22143510, 714575, 45383844, 30147180, -75072000, 468424448, 6863357, +-2480612, -3718636, -18806856, 45715632, -12727867, 520436480, 52698712, 758061, +-3390071, -57345060, -19137300, -94494648, 48669764, 553184256, 15456245, -55625196, +37220456, -21190832, 14073266, 37691024, -82113600, -125746712, 566309184, 24663312, +-79263352, -81187768, 18228110, -23309324, -35227592, 45638592, -100310304, 111057384, +747604032, -38703024, -49378972, -1829387, -24915374, -44106092, 3890166, 95093528, +4453076, -105516344, 61340456, 779151360, 14067092, 24841018, 46075604, 14026826, +-73798008, -27891786, -172234896, 22042846, 8342168, -136356624, -15677436, 917865664, +323919712, -183311616, 550143680, -136109392, -92123024, 508834976, -36581580, 25082610, +186993744, 612834112, 3323231, -41768288, 10869757, -32662958, 900676672, -132146208, +173920944, -285617472, -265424416, -17592454, 746075264, 174698064, 87668608, -12579422, +50304000, -52162648, -8793140, 1121056000, 147971552, -143892672, 40492148, -332957664, +-99433056, -229635520, 90426776, 754189248, 91340536, -315738880, 3497714, 95215400, +-131254200, -125219504, 210190864, -40012452, 774223424, 323906560, 82644032, -378786592, +18817058, 56163140, 78116600, -101264320, -171897472, 108985600, 1384031744, 217351648, +179599424, -252806064, 287773824, -31378494, -40052984, 121498448, -198681968, -319067488, +616561856, 1259752576, -10863851, -35322348, 214155392, -580386432, 360088192, 294499200, +-423245408, 122124976, 92175096, -14300899, 19809194, 1852783360, 372837536, -142020880, +513938464, -66074584, -101171176, 458718880, -55148724, 84335712, 174501568, 494334368, +-23007872, -3568849, -19046838, -125238024, 850134528, -69946760, 193497408, -212820192, +-393971456, -100102000, 727705408, 162900592, 171089760, -145332032, -88654296, 45897900, +17440252, 800112128, 49616000, -91281208, 77360680, -280252256, -125265672, -100565856, +-62217164, 572262784, 35549444, -258559712, -79083232, 11355357, -30667678, -250266672, +-44622024, 54628764, 688208640, 147327840, -118213336, -250863936, -92370248, 8184597, +-101297072, -22858352, -70537856, 128080216, 1281079808, 22687360, 96064192, -115392352, +184689760, 94979176, -117889608, 20655572, -206588192, -316042752, 525827200, 1154297216, +-55784644, 65338264, -189560800, -157846496, 258337456, 90826744, -80055240, -94396936, +206332112, 185089200, 185797056, 1643156480, }; #endif @@ -1178,7 +1467,42 @@ const float mel_fb[246] = 1.43369924f, 1.19031958f, 0.94874676f, 0.70895416f, 0.47091573f, 0.23460598f }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 mel_fb_fx[246] = +{ +1306887040, 840596608, 701826176, 1445657472, 297866656, 1849617024, 67613584, 2079870080, +2136398336, 43602444, 11085289, 2103881216, 216592064, 1930891520, 495221376, 1652262272, +868758208, 1278725376, 1328027264, 819456448, 1865122304, 325699488, 282361312, 1821784192, +998734592, 1148749056, 1731480576, 371805248, 416003072, 1775678336, 1210549888, 936933760, +2096551936, 879033408, 50931740, 1268450304, 1850000256, 711813440, 297483360, 1435670272, +1757021184, 688459456, 390462400, 1459024128, 1799094144, 792129792, 348389472, 1355353856, +1960859008, 1008777088, 81952272, 186624608, 1138706560, 2065531392, 1326562816, 446434464, +820920896, 1701049216, 1735416832, 897505024, 79218296, 412066848, 1249978624, 2068265344, +1427142016, 645470720, 720341696, 1502012928, 2028388992, 1280196608, 547690816, 119094688, +867287040, 1599792768, 1977710976, 1274684288, 585524928, 169772688, 872799360, 1561958656, +2057180032, 1394176384, 743519808, 104758968, 90303584, 753307264, 1403963776, 2042724736, +1624950272, 1008721792, 403173792, 522533408, 1138761856, 1744309888, 1955425920, 1370165248, +794546816, 228258160, 192057744, 777318400, 1352936832, 1919225472, 1818485248, 1269977216, +729947136, 198137088, 328998400, 877506496, 1417536512, 1949346560, 1821784192, 1305685504, +797099392, 295810368, 325699488, 841798208, 1350384256, 1851673344, 1949095552, 1461789952, +981187520, 507106368, 39371848, 198388080, 685693696, 1166296064, 1640377344, 2108111744, +1725299968, 1269762304, 820087488, 376126688, 422183712, 877721408, 1327396096, 1771356928, +2085220096, 1652262272, 1224604032, 802116992, 384677824, 62263592, 495221376, 922879680, +1345366656, 1762805888, 2119650816, 1711953664, 1308959104, 910559680, 516651968, 127135704, +27832838, 435529952, 838524608, 1236923904, 1630831744, 2020347904, 1889397760, 1508377088, +1131466752, 758579072, 389629024, 24534324, 258085904, 639106560, 1016016832, 1388904576, +1757854592, 2122949376, 1810698880, 1453078016, 1099080704, 748633920, 401667360, 58112508, +336784768, 694405568, 1048403008, 1398849664, 1745816320, 2089371136, 1865386624, 1528457728, +1194747136, 864193536, 536738048, 212323040, 282097056, 619025856, 952736576, 1283290112, +1610745600, 1935160576, 2038376192, 1719875840, 1404252672, 1091455232, 781433280, 474137984, +169521872, 109107440, 427607776, 743230976, 1056028416, 1366050432, 1673345664, 1977961728, +2015022208, 1715626752, 1418774912, 1124424064, 832532224, 543058752, 255963904, 132461384, +431856928, 728708736, 1023059648, 1314951424, 1604424960, 1891519744, 2118692480, 1836239488, +1556051584, 1278092800, 1002327744, 728722176, 457242624, 187856208, 28791110, 311244128, +591432000, 869390912, 1145155968, 1418761472, 1690241024, 1959627392, 2068014592, 1802719104, +1539422848, 1278095872, 1018709056, 761233728, 505641920, 251906256, +}; +#endif const float dct_mtx[NB_MEL_BANDS * NB_MEL_COEF] = { 2.23434405e-01f, 2.22056858e-01f, 2.19310256e-01f, 2.15211533e-01f, 2.09785960e-01f, 2.03066987e-01f, 1.95096038e-01f, 1.85922257e-01f, 1.75602204e-01f, 1.64199505e-01f, 1.51784461e-01f, 1.38433616e-01f, @@ -1246,7 +1570,76 @@ const float dct_mtx[NB_MEL_BANDS * NB_MEL_COEF] = 2.22056858e-01f, 1.38433616e-01f, -7.73941268e-02f, -2.19310256e-01f, -1.51784461e-01f, 6.06959298e-02f, 2.15211533e-01f, 1.64199505e-01f, -4.36235222e-02f, -2.09785960e-01f, -1.75602204e-01f, 2.62821611e-02f, 2.03066987e-01f, 1.85922257e-01f, -8.77876168e-03f, -1.95096038e-01f }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 dct_mtx_fx[NB_MEL_BANDS * NB_MEL_COEF] = +{ //Q31 + 479821728, 476863456, 470965184, 462163232, 450511904, 436083040, 418965536, 399264992, +377102848, 352615744, 325954656, 297283936, 266780352, 234631984, 201037040, 166202624, +130343520, 93680800, 56440512, 18852248, -18852248, -56440512, -93680800, -130343520, +-166202624, -201037040, -234631984, -266780352, -297283936, -325954656, -352615744, -377102848, +-399264992, -418965536, -436083040, -450511904, -462163232, -470965184, -476863456, -479821728, +478711680, 466924192, 443639520, 409430944, 365140832, 311859712, 250899600, 183761504, +112098584, 37675424, -37675424, -112098584, -183761504, -250899600, -311859712, -365140832, +-409430944, -443639520, -466924192, -478711680, -478711680, -466924192, -443639520, -409430944, +-365140832, -311859712, -250899600, -183761504, -112098584, -37675424, 37675424, 112098584, +183761504, 250899600, 311859712, 365140832, 409430944, 443639520, 466924192, 478711680, +476863456, 450511904, 399264992, 325954656, 234631984, 130343520, 18852248, -93680800, +-201037040, -297283936, -377102848, -436083040, -470965184, -479821728, -462163232, -418965536, +-352615744, -266780352, -166202624, -56440512, 56440512, 166202624, 266780352, 352615744, +418965536, 462163232, 479821728, 470965184, 436083040, 377102848, 297283936, 201037040, +93680800, -18852248, -130343520, -234631984, -325954656, -399264992, -450511904, -476863456, +474279968, 427854144, 339546976, 218002576, 75118568, -75118568, -218002576, -339546976, +-427854144, -474279968, -474279968, -427854144, -339546976, -218002576, -75118568, 75118568, +218002576, 339546976, 427854144, 474279968, 474279968, 427854144, 339546976, 218002576, +75118568, -75118568, -218002576, -339546976, -427854144, -474279968, -474279968, -427854144, +-339546976, -218002576, -75118568, 75118568, 218002576, 339546976, 427854144, 474279968, +470965184, 399264992, 266780352, 93680800, -93680800, -266780352, -399264992, -470965184, +-470965184, -399264992, -266780352, -93680800, 93680800, 266780352, 399264992, 470965184, +470965184, 399264992, 266780352, 93680800, -93680800, -266780352, -399264992, -470965184, +-470965184, -399264992, -266780352, -93680800, 93680800, 266780352, 399264992, 470965184, +470965184, 399264992, 266780352, 93680800, -93680800, -266780352, -399264992, -470965184, +466924192, 365140832, 183761504, -37675424, -250899600, -409430944, -478711680, -443639520, +-311859712, -112098584, 112098584, 311859712, 443639520, 478711680, 409430944, 250899600, +37675424, -183761504, -365140832, -466924192, -466924192, -365140832, -183761504, 37675424, +250899600, 409430944, 478711680, 443639520, 311859712, 112098584, -112098584, -311859712, +-443639520, -478711680, -409430944, -250899600, -37675424, 183761504, 365140832, 466924192, +462163232, 325954656, 93680800, -166202624, -377102848, -476863456, -436083040, -266780352, +-18852248, 234631984, 418965536, 479821728, 399264992, 201037040, -56440512, -297283936, +-450511904, -470965184, -352615744, -130343520, 130343520, 352615744, 470965184, 450511904, +297283936, 56440512, -201037040, -399264992, -479821728, -418965536, -234631984, 18852248, +266780352, 436083040, 476863456, 377102848, 166202624, -93680800, -325954656, -462163232, +456689664, 282249728, 0, -282249728, -456689664, -456689664, -282249728, 0, +282249728, 456689664, 456689664, 282249728, 0, -282249728, -456689664, -456689664, +-282249728, 0, 282249728, 456689664, 456689664, 282249728, 0, -282249728, +-456689664, -456689664, -282249728, 0, 282249728, 456689664, 456689664, 282249728, +0, -282249728, -456689664, -456689664, -282249728, 0, 282249728, 456689664, +450511904, 234631984, -93680800, -377102848, -479821728, -352615744, -56440512, 266780352, +462163232, 436083040, 201037040, -130343520, -399264992, -476863456, -325954656, -18852248, +297283936, 470965184, 418965536, 166202624, -166202624, -418965536, -470965184, -297283936, +18852248, 325954656, 476863456, 399264992, 130343520, -201037040, -436083040, -462163232, +-266780352, 56440512, 352615744, 479821728, 377102848, 93680800, -234631984, -450511904, +443639520, 183761504, -183761504, -443639520, -443639520, -183761504, 183761504, 443639520, +443639520, 183761504, -183761504, -443639520, -443639520, -183761504, 183761504, 443639520, +443639520, 183761504, -183761504, -443639520, -443639520, -183761504, 183761504, 443639520, +443639520, 183761504, -183761504, -443639520, -443639520, -183761504, 183761504, 443639520, +443639520, 183761504, -183761504, -443639520, -443639520, -183761504, 183761504, 443639520, +436083040, 130343520, -266780352, -476863456, -352615744, 18852248, 377102848, 470965184, +234631984, -166202624, -450511904, -418965536, -93680800, 297283936, 479821728, 325954656, +-56440512, -399264992, -462163232, -201037040, 201037040, 462163232, 399264992, 56440512, +-325954656, -479821728, -297283936, 93680800, 418965536, 450511904, 166202624, -234631984, +-470965184, -377102848, -18852248, 352615744, 476863456, 266780352, -130343520, -436083040, +427854144, 75118568, -339546976, -474279968, -218002576, 218002576, 474279968, 339546976, +-75118568, -427854144, -427854144, -75118568, 339546976, 474279968, 218002576, -218002576, +-474279968, -339546976, 75118568, 427854144, 427854144, 75118568, -339546976, -474279968, +-218002576, 218002576, 474279968, 339546976, -75118568, -427854144, -427854144, -75118568, +339546976, 474279968, 218002576, -218002576, -474279968, -339546976, 75118568, 427854144, +418965536, 18852248, -399264992, -436083040, -56440512, 377102848, 450511904, 93680800, +-352615744, -462163232, -130343520, 325954656, 470965184, 166202624, -297283936, -476863456, +-201037040, 266780352, 479821728, 234631984, -234631984, -479821728, -266780352, 201037040, +476863456, 297283936, -166202624, -470965184, -325954656, 130343520, 462163232, 352615744, +-93680800, -450511904, -377102848, 56440512, 436083040, 399264992, -18852248, -418965536, +}; +#endif const float SF[N_FEATURES*2] = { 0.0048f, -0.0952f, diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index 812db4821e8047a3c9fe7c84ae18a6f65df3ffb8..87537fc80ce0acc536f8161183045746086e4e4e 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -60,8 +60,8 @@ extern const Word16 W_HIST_S_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calcula extern const int16_t bwd_start_bin[]; extern const int16_t bwd_end_bin[]; -extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ -extern const Word16 H_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ +extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ +extern const Word16 h_fir_fx[]; /* 2nd order fir filter for wsp, decimation by 2 */ extern const float preemphCompensation[]; extern const Word16 preemphCompensation_fx[]; @@ -124,6 +124,23 @@ extern const float means_music[]; extern const float weights_noise[]; extern const float means_noise[]; extern const float prec_chol_speech[]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 pca_components_fx[]; +extern const Word32 pca_mean_fx[]; +extern const Word32 sm_means_fx[]; +extern const Word32 sm_scale_fx[]; +extern const Word32 bcox_lmbd_fx[N_SMC_FEATURES]; +extern const Word32 hout_intervals_fx[]; +extern const Word32 bcox_add_cnst_fx[N_SMC_FEATURES]; +extern const Word32 prec_chol_speech_fx[]; +extern const Word32 prec_chol_music_fx[]; +extern const Word32 prec_chol_noise_fx[]; +extern const Word32 means_speech_fx[]; +extern const Word32 means_music_fx[]; +extern const Word32 means_noise_fx[]; +extern const Word32 mel_fb_fx[]; +extern const Word32 dct_mtx_fx[]; +#endif extern const float log_det_chol_speech[]; extern const float prec_chol_music[]; extern const float log_det_chol_music[]; diff --git a/lib_enc/rst_enc_fx.c b/lib_enc/rst_enc_fx.c index 009ba531a12cd147b3f37b1ca81542a4fc872c25..85821ef0b028b6e360b6a57d40979f86ecd85985 100644 --- a/lib_enc/rst_enc_fx.c +++ b/lib_enc/rst_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index dd4f88b00d61b64c0ddd4d0cbf39fbfb6ab6e291..cfb3568bb669ed9fa5279c0f59236dfc84d98689 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index a145e42d6ae9dd9c67932c296e12c37e77c52b8a..f9efcacca33312130d2350aa325c9be8ab158818 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* diff --git a/lib_enc/setmodeindex_fx.c b/lib_enc/setmodeindex_fx.c index 7920db3e2aeb948044a8e97f187a4a210ce92939..dff13ec8964ba2be52e6649edb3e78c08ff5fdfa 100644 --- a/lib_enc/setmodeindex_fx.c +++ b/lib_enc/setmodeindex_fx.c @@ -8,8 +8,7 @@ #include "cnst.h" #include "rom_com_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*--------------------------------------------------------------------------- diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 62f7329399f07327f454fc9c9c435da1adb8fc84..27f0214653294501946f19597a4ab84d672b3834 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* @@ -115,7 +114,7 @@ Word16 signal_clas_fx( /* o : classification for current zc = extract_l( Ltmp ); /* compute pitch stability */ - pc = add( abs_s( sub( st->pitch_fx[1], st->pitch_fx[0] ) ), abs_s( sub( st->pitch_fx[2], st->pitch_fx[1] ) ) ); + pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) ); st->tdm_pc = pc; /*-----------------------------------------------------------------* diff --git a/lib_enc/spec_center_fx.c b/lib_enc/spec_center_fx.c index a3fb197cb19ea30367fb9997120a51a55a956dd5..920da568d721927e05f5e795583fbd17c7efefc4 100644 --- a/lib_enc/spec_center_fx.c +++ b/lib_enc/spec_center_fx.c @@ -8,8 +8,7 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index 918faa5e6889f8964655c2c7542701d619680184..271f7ba1b3ed974d0d1b8239c68c123e6386bf24 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -9,8 +9,7 @@ #include "basop_util.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index 3fe6fe53b64c399dfae134de51f73eb3d4449387..8df503bd1bbb93e2d4353a585b9e066c8e9e85d1 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -45,7 +45,7 @@ #include "rom_com.h" /* Common static table prototypes */ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif @@ -113,18 +113,31 @@ void speech_music_clas_init( int16_t i; set_f( hSpMusClas->FV_st, 0.0f, N_SMC_FEATURES ); - +#ifdef IVAS_FLOAT_FIXED + set_zero_fx( hSpMusClas->FV_st_fx, N_SMC_FEATURES ); +#endif hSpMusClas->inact_cnt = 0; set_s( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); set_f( hSpMusClas->past_dlp, 0, HANG_LEN - 1 ); set_f( hSpMusClas->past_dlp_mean_ST, 0, HANG_LEN - 1 ); hSpMusClas->dlp_mean_ST = 0.0f; +#ifdef IVAS_FLOAT_FIXED + hSpMusClas->dlp_mean_ST_fx = 0; + hSpMusClas->dlp_var_LT_fx = 0; +#ifdef MSAN_FIX + hSpMusClas->dlp_mean_LT_fx = 0; + set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); +#endif // MSAN_FIX +#endif hSpMusClas->dlp_mean_LT = 0.0f; hSpMusClas->dlp_var_LT = 0.0f; for ( i = 0; i < N_SMC_FEATURES; i++ ) { hSpMusClas->prev_FV[i] = 0.5f * hout_intervals[2 * i] + 0.5f * hout_intervals[2 * i + 1]; +#ifdef IVAS_FLOAT_FIXED + hSpMusClas->prev_FV_fx[i] = (Word32) ( hSpMusClas->prev_FV[i] * ONE_IN_Q20 ); +#endif } for ( i = 0; i < NB_BANDS_SPMUS; i++ ) @@ -1129,7 +1142,6 @@ static int16_t attack_det( * * 1st stage of the speech/music classification (based on the GMM model) *---------------------------------------------------------------------*/ - /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ #ifdef IVAS_FLOAT_FIXED @@ -1350,7 +1362,57 @@ int16_t ivas_smc_gmm( pt_mel_fb += len; } +#ifdef IVAS_FLOAT_FIXED + //////////////////// to be removed ////////////////////// + Word32 y_fx[NB_MEL_BANDS]; + Word32 x_fx[NB_MEL_BANDS]; + Word32 A_fx[NB_MEL_BANDS * NB_MEL_COEF]; + Word16 y_q_fx[NB_MEL_BANDS]; + Word16 x_q_fx[NB_MEL_BANDS]; + Word16 A_q_fx[NB_MEL_BANDS * NB_MEL_COEF]; + Word32 *pt_x_fx, *pt_A_fx; + const Float32 *pt_x, *pt_A; + Word16 *pt_x_q_fx, *pt_A_q_fx; + + pt_A_fx = A_fx; + pt_A_q_fx = A_q_fx; + pt_A = dct_mtx; + + FOR( i = 0; i < NB_MEL_COEF; i++ ) + { + pt_x = melS; + pt_x_fx = x_fx; + pt_x_q_fx = x_q_fx; + FOR( j = 0; j < NB_MEL_BANDS; j++ ) + { + IF( EQ_16( i, 0 ) ) + { + *pt_x_q_fx = sub( Q_factor_L( *pt_x ), 3 ); + *pt_x_fx++ = (Word32) ( *pt_x++ * ( W_shl( 1, *pt_x_q_fx++ ) ) ); + } + *pt_A_q_fx = sub( Q_factor_L( *pt_A ), 3 ); + *pt_A_fx++ = (Word32) ( *pt_A++ * ( W_shl( 1, *pt_A_q_fx++ ) ) ); + } + } + + v_mult_mat_fx( y_fx, y_q_fx, (const Word32 *) x_fx, x_q_fx, (const Word32 *) A_fx, A_q_fx, NB_MEL_BANDS, NB_MEL_COEF ); + + ////////////////////////////// to be removed //////////////////////// + FOR( i = 0; i < NB_MEL_COEF; i++ ) + { + IF( LT_16( y_q_fx[i], 0 ) ) + { + mfcc[i] = (Float32) y_fx[i] * W_shl( 1, -y_q_fx[i] ); + } + ELSE + { + mfcc[i] = (Float32) y_fx[i] / W_shl( 1, y_q_fx[i] ); + } + } + //////////////////////////////////////////////////////////////////// +#else v_mult_mat( mfcc, melS, dct_mtx, NB_MEL_BANDS, NB_MEL_COEF ); +#endif *pFV++ = mfcc[2]; *pFV++ = mfcc[6]; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index bba2c502a73df084323ef3ca645c61340d9359ec..677c94e04dea92b278d7b26780f1a15ccca60e56 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -6,15 +6,18 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_enc.h" #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ - +#ifdef IVAS_FLOAT_FIXED +#include +#include "ivas_prot.h" +#include "prot.h" +#endif /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -24,7 +27,8 @@ #define ATT_3LSUB_POS_16k 26 /* (short)((4.0f * ATT_NSEG / (float)NB_SUBFR16k) + 0.5f) */ #define LOG_PROB_CONST 11292 /*0.5f * N_FEATURES * LOG_PI2 in Q10 */ - +#define DLP_BIAS 0.138121f +#define DLP_BIAS_FX 72415 /*Q19*/ /*---------------------------------------------------------------------* * Local functions *---------------------------------------------------------------------*/ @@ -54,6 +58,31 @@ static Word16 attack_det_fx( const Word16 *inp, const Word16 Qx, const Word16 la static void order_spectrum_fx( Word16 *vec, Word16 len ); static void detect_sparseness_fx( Encoder_State *st_fx, const Word16 localVAD_HE_SAD, const Word16 voi_fv ); +// Q19 +Word32 log_weights_speech_compute[N_SMC_MIXTURES] = { + -3529378, + -3679759, + -3803054, + -3229859, + -4048972, + -3929047, +}; +Word32 log_weights_music_compute[N_SMC_MIXTURES] = { + -5058325, + -4983143, + -3436984, + -5133896, + -8505198, + -2561831, +}; +Word32 log_weights_noise_compute[N_SMC_MIXTURES] = { + -433769, + -105783, + 407264, + -3350157, + 103199, + -627672, +}; /*---------------------------------------------------------------------* * speech_music_clas_init_fx() * @@ -307,7 +336,7 @@ void speech_music_classif_fx( { sp_mus_classif_2nd_fx( st, Etot, attack_flag, inp, Q_inp - 1 ); - /* avoid switch to AUDIO/MUSIC class for very short stable high st->pitch_fx + /* avoid switch to AUDIO/MUSIC class for very short stable high st->pitch and/or stable pitch with high correlation at low bitrates*/ test(); test(); @@ -455,14 +484,14 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /* [0] OL pitch Q0 */ /*(float)(pitch[0] + pitch[1] + pitch[2]) / 3.0f;*/ - L_tmp = L_mult( st_fx->pitch_fx[0], 10923 ); - L_tmp = L_mac( L_tmp, st_fx->pitch_fx[1], 10923 ); - L_tmp = L_mac( L_tmp, st_fx->pitch_fx[2], 10923 ); + L_tmp = L_mult( st_fx->pitch[0], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->pitch[1], 10923 ); + L_tmp = L_mac( L_tmp, st_fx->pitch[2], 10923 ); test(); IF( EQ_16( st_fx->tc_cnt, 1 ) || EQ_16( st_fx->tc_cnt, 2 ) ) { - *pFV++ = st_fx->pitch_fx[2]; + *pFV++ = st_fx->pitch[2]; move16(); } ELSE @@ -1155,7 +1184,7 @@ static void sp_mus_classif_2nd_fx( st->sp_aud_decision2 = 0; move16(); } - ELSE IF( EQ_16( hSpMusClas->high_stable_cor, 1 ) && GE_16( st->pitch_fx[0], 130 ) ) + ELSE IF( EQ_16( hSpMusClas->high_stable_cor, 1 ) && GE_16( st->pitch[0], 130 ) ) { /* prevent GSC in highly correlated signal with low energy variation */ /* this is basically a patch against bassoon-type of music */ @@ -1469,322 +1498,447 @@ static Word16 attack_det_fx( /* o : attack flag return attack; } -#ifdef IVAS_CODE +#ifdef IVAS_FLOAT_FIXED /* -------------------------------------------------------------------- - * *ivas_smc_gmm() * *1st stage of the speech / music classification(based on the GMM model) * -------------------------------------------------------------------- - */ /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ -int16_t ivas_smc_gmm( +Word16 ivas_smc_gmm_fx( Encoder_State *st, /* i/o: state structure */ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - const int16_t localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const float Etot, /* i : total frame energy */ - const float lsp_new[M], /* i : LSPs in current frame */ - const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ - const float epsP[M + 1], /* i : LP prediciton error */ - const float PS[], /* i : energy spectrum */ - const float non_sta, /* i : unbound non-stationarity */ - const float relE, /* i : relative frame energy */ - int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ -) + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 Etot_fx, /* i : total frame energy */ + Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ + Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ + Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ + Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ + const Word16 non_sta_fx, /* i : unbound non-stationarity */ + const Word16 relE_fx, /* i : relative frame energy */ + Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ + const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + , + Word16 Qfact_PS, + Word16 Q_esp, + Word16 Qfact_PS_past ) { - int16_t i, m, dec; - int16_t flag_odv; - float lps, lpm, lpn; - float ps[N_SMC_MIXTURES], pm[N_SMC_MIXTURES], pn[N_SMC_MIXTURES]; - float fvm[N_PCA_COEF], lprob; - float dlp, ftmp, sum_PS, ps_diff, ps_sta, wrelE, wdrop, wght; - float wrise; - float dlp_mean2var; - float FV[N_SMC_FEATURES], *pFV, PS_norm[128], dPS[128]; - const float *pODV; - float *pFV_st, smc_st_mean_fact; - int16_t relE_attack_flag; - int16_t j, len; - const float *pt_mel_fb; - float melS[NB_MEL_BANDS], mfcc[NB_MEL_BANDS]; - int16_t odv_cnt; - int16_t i_out[N_SMC_FEATURES], *p_out; - + Word16 i, m, dec; + Word16 flag_odv; + Word32 lps_fx, lpm_fx, lpn_fx; + Word32 ps_fx[N_SMC_MIXTURES], pm_fx[N_SMC_MIXTURES], pn_fx[N_SMC_MIXTURES]; + Word32 lprob_fx; + Word16 lprob_exp = 0; + Word32 fvm_fx[N_PCA_COEF]; + Word16 fvm_exp = 0; + Word32 sum_PS_fx, ps_diff_fx, ps_sta_fx; + Word32 dlp_fx, wrelE_fx, wdrop_fx, wght_fx; + Word32 wrise_fx; + Word16 dlp_mean2var_fx; + Word16 dlp_mean2var_q; + Word32 FV_fx[N_SMC_FEATURES], *pFV_fx; + Word32 dPS_fx[128]; + Word32 PS_norm_fx[128]; + const Word32 *pODV_fx; + Word32 *pFV_st_fx; + Word16 relE_attack_flag, smc_st_mean_fact_fx; + Word16 j, len; + const Word32 *pt_mel_fb_fx; + Word32 melS_fx[NB_MEL_BANDS], mfcc_fx[NB_MEL_BANDS]; + Word16 odv_cnt; + Word16 i_out[N_SMC_FEATURES], *p_out; + Word16 temp_exp; + Word16 Qfact_FV; + Word32 temp32, temp32_log; + Word32 temp32_log1, temp32_log2; + Word16 temp16; + Word16 dotp_exp = 0; /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - + Word32 temp_sqrt, temp_acos; /*------------------------------------------------------------------* * State machine (sp_mus_state: -8 = INACTIVE, -7:-1 = UNSTABLE, 0:7 = ENTRY, 8 = STABLE ) *------------------------------------------------------------------*/ - if ( localVAD_HE_SAD ) + IF( localVAD_HE_SAD ) { - if ( relE < -20 ) + test(); + IF( LT_16( relE_fx, -10240 ) ) { - if ( hSpMusClas->sp_mus_state > 0 ) + IF( hSpMusClas->sp_mus_state > 0 ) { - if ( hSpMusClas->sp_mus_state < HANG_LEN ) + if ( LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ hSpMusClas->inact_cnt = 0; + move16(); } /* energy is too low -> we are going to instable state */ hSpMusClas->sp_mus_state = 0; + move16(); } - else if ( hSpMusClas->sp_mus_state > -HANG_LEN ) + ELSE IF( GT_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { /* energy is still too low -> we are still in instable state */ - hSpMusClas->sp_mus_state--; + hSpMusClas->sp_mus_state = sub( hSpMusClas->sp_mus_state, 1 ); } } - else if ( hSpMusClas->sp_mus_state <= 0 ) + ELSE IF( hSpMusClas->sp_mus_state <= 0 ) { - if ( hSpMusClas->inact_cnt == 0 ) + IF( hSpMusClas->inact_cnt == 0 ) { hSpMusClas->sp_mus_state = 1; + move16(); } - else + ELSE { hSpMusClas->sp_mus_state = HANG_LEN; + move16(); } hSpMusClas->inact_cnt = 12; + move16(); } - else if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + ELSE IF( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { /* we are inside an entry period -> increment the counter of entry frames */ - hSpMusClas->sp_mus_state++; + hSpMusClas->sp_mus_state = add( hSpMusClas->sp_mus_state, 1 ); } - if ( hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) + IF( hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) { - hSpMusClas->inact_cnt--; + hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); } } - else + ELSE { - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + test(); + test(); + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { hSpMusClas->inact_cnt = 0; + move16(); } - else if ( hSpMusClas->inact_cnt > 0 ) + ELSE IF( hSpMusClas->inact_cnt > 0 ) { - hSpMusClas->inact_cnt--; + hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); } - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { hSpMusClas->sp_mus_state = -HANG_LEN; + move16(); } - else if ( hSpMusClas->sp_mus_state > 0 ) + ELSE IF( hSpMusClas->sp_mus_state > 0 ) { hSpMusClas->sp_mus_state = -1; + move16(); } - else if ( hSpMusClas->sp_mus_state > -HANG_LEN ) + ELSE IF( GT_16( hSpMusClas->sp_mus_state, -HANG_LEN ) ) { /* we are in inactive state */ - hSpMusClas->sp_mus_state--; + hSpMusClas->sp_mus_state = sub( hSpMusClas->sp_mus_state, 1 ); } } /* detect attacks based on relE */ - if ( relE > hSpMusClas->prev_relE ) + IF( GT_16( relE_fx, hSpMusClas->prev_relE_fx ) ) { - hSpMusClas->relE_attack_sum += relE - hSpMusClas->prev_relE; + hSpMusClas->relE_attack_sum_fx = add_sat( sub_sat( relE_fx, hSpMusClas->prev_relE_fx ), hSpMusClas->relE_attack_sum_fx ); } - else + ELSE { - hSpMusClas->relE_attack_sum = 0; + hSpMusClas->relE_attack_sum_fx = 0; + move16(); } - hSpMusClas->prev_relE = relE; - + hSpMusClas->prev_relE_fx = relE_fx; + move16(); + test(); + test(); + test(); /* update counter from last VAD 0->1 change */ - if ( hSpMusClas->prev_vad == 0 && localVAD_HE_SAD == 1 ) + IF( hSpMusClas->prev_vad == 0 && EQ_16( localVAD_HE_SAD, 1 ) ) { hSpMusClas->vad_0_1_cnt = 1; + move16(); } - else if ( localVAD_HE_SAD == 1 && hSpMusClas->vad_0_1_cnt > 0 && hSpMusClas->vad_0_1_cnt < 50 ) + ELSE IF( EQ_16( localVAD_HE_SAD, 1 ) && hSpMusClas->vad_0_1_cnt > 0 && LT_16( hSpMusClas->vad_0_1_cnt, 50 ) ) { - hSpMusClas->vad_0_1_cnt++; + hSpMusClas->vad_0_1_cnt = add( hSpMusClas->vad_0_1_cnt, 1 ); } - else + ELSE { hSpMusClas->vad_0_1_cnt = 0; + move16(); } hSpMusClas->prev_vad = localVAD_HE_SAD; - - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && hSpMusClas->relE_attack_sum > 5.0f ) + move16(); + test(); + test(); + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) && GT_16( hSpMusClas->relE_attack_sum_fx, 2560 ) ) { - hSpMusClas->relE_attack_cnt++; + hSpMusClas->relE_attack_cnt = add( hSpMusClas->relE_attack_cnt, 1 ); /* set flag only in the first X frames in a series */ - if ( hSpMusClas->relE_attack_cnt > 0 && hSpMusClas->relE_attack_cnt < 3 ) + IF( hSpMusClas->relE_attack_cnt > 0 && LT_16( hSpMusClas->relE_attack_cnt, 3 ) ) { relE_attack_flag = 1; } - else + ELSE { relE_attack_flag = 0; } + move16(); } - else + ELSE { hSpMusClas->relE_attack_cnt = 0; relE_attack_flag = 0; + move16(); + move16(); } - hSpMusClas->prev_Etot = Etot; + hSpMusClas->prev_Etot_fx = Etot_fx; /*------------------------------------------------------------------* * Preparation of the feature vector *------------------------------------------------------------------*/ - pFV = FV; - + pFV_fx = FV_fx; + test(); + test(); /* [0] OL pitch */ - if ( relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2 ) + IF( relE_attack_flag || EQ_16( st->tc_cnt, 1 ) || EQ_16( st->tc_cnt, 2 ) ) { - *pFV++ = (float) st->pitch[2]; + *pFV_fx++ = L_shl( st->pitch[2], Q20 ); } - else + ELSE { - *pFV++ = (float) ( st->pitch[0] + st->pitch[1] + st->pitch[2] ) / 3.0f; + // *pFV_fx++ = (float) ( st->pitch[0] + st->pitch[1] + st->pitch[2] ) / 3.0f; + *pFV_fx++ = Mpy_32_32( L_shl( add( add( st->pitch[0], st->pitch[1] ), st->pitch[2] ), Q20 ), 715827883 ); } - + test(); + test(); /* [1] voicing */ - if ( relE_attack_flag || st->tc_cnt == 1 || st->tc_cnt == 2 ) + IF( relE_attack_flag || EQ_16( st->tc_cnt, 1 ) || EQ_16( st->tc_cnt, 2 ) ) { - *pFV++ = st->voicing[2]; + *pFV_fx++ = st->voicing_fx[2]; } - else + ELSE { - *pFV++ = ( st->voicing[0] + st->voicing[1] + st->voicing[2] ) / 3.0f; + // *pFV++ = ( st->voicing[0] + st->voicing[1] + st->voicing[2] ) / 3.0f; + *pFV_fx++ = Mpy_32_32( L_shl( L_add( L_add( st->voicing_fx[0], st->voicing_fx[1] ), st->voicing_fx[2] ), Q5 ), 715827883 ); } + temp_exp = 1; + move16(); + temp16 = lsp_new_fx[2]; + move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 + temp_sqrt = Sqrt32( temp32, &temp_exp ); + temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); + *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + temp_exp = 1; + move16(); + temp16 = lsp_new_fx[3]; + move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 + temp_sqrt = Sqrt32( temp32, &temp_exp ); + temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); + *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + temp_exp = 1; + move16(); + temp16 = lsp_new_fx[4]; + move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 + temp_sqrt = Sqrt32( temp32, &temp_exp ); + temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); + *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + temp_exp = 1; + move16(); + temp16 = lsp_new_fx[5]; + move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 + temp_sqrt = Sqrt32( temp32, &temp_exp ); + temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); + *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + temp_exp = 1; + move16(); + temp16 = lsp_new_fx[6]; + move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 + temp_sqrt = Sqrt32( temp32, &temp_exp ); + temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); + *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + // temf = acosf( lsp_new[2] ); /* [2,3,4,5,6] LSFs */ - *pFV++ = acosf( lsp_new[2] ); - *pFV++ = acosf( lsp_new[3] ); - *pFV++ = acosf( lsp_new[4] ); - *pFV++ = acosf( lsp_new[5] ); - *pFV++ = acosf( lsp_new[6] ); + /* *pFV++ = acosf( lsp_new[2] ); + *pFV++ = acosf( lsp_new[3] ); + *pFV++ = acosf( lsp_new[4] ); + *pFV++ = acosf( lsp_new[5] ); + *pFV++ = acosf( lsp_new[6] );*/ /* [7] cor_map_sum */ - *pFV++ = cor_map_sum; + *pFV_fx++ = L_shl( cor_map_sum_fx, Q12 ); /* [8] non_sta */ - *pFV++ = non_sta; + *pFV_fx++ = L_shl( non_sta_fx, Q12 ); /* [9] epsP */ - *pFV++ = logf( epsP[14] + 1e-5f ) - logf( epsP[0] + 1e-5f ); + temp32 = epsP_fx[14]; + move32(); + temp32_log = L_add( BASOP_Util_Log2( temp32 ), L_shl( sub( Q31, Q_esp ), Q25 ) ); + temp32_log1 = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ + + temp32 = epsP_fx[0]; + move32(); + temp32_log = L_add( BASOP_Util_Log2( temp32 ), L_shl( sub( Q31, Q_esp ), Q25 ) ); + temp32_log2 = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ + + *pFV_fx++ = L_shr( L_add( temp32_log1, temp32_log2 ), Q5 ); + //*pFV++ = logf( epsP[14] + 1e-5f ) - logf( epsP[0] + 1e-5f ); /* [10,11,12] MFCCs */ - set_zero( melS, NB_MEL_BANDS ); - pt_mel_fb = mel_fb; - for ( i = 0; i < NB_MEL_BANDS; i++ ) + set_zero_fx( melS_fx, NB_MEL_BANDS ); + + pt_mel_fb_fx = mel_fb_fx; + move32(); + + FOR( i = 0; i < NB_MEL_BANDS; i++ ) { j = mel_fb_start[i]; + move16(); len = mel_fb_len[i]; - melS[i] = logf( dotp( &PS[j], pt_mel_fb, len ) + 1e-5f ); - pt_mel_fb += len; + move16(); + temp32 = dotp_me_fx( &PS_fx[j], pt_mel_fb_fx, len, 31 - Qfact_PS, Q1, &dotp_exp ); + temp32_log = L_add( BASOP_Util_Log2( temp32 ), L_shl( dotp_exp, Q25 ) ); + temp32_log = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ + melS_fx[i] = temp32_log; + move32(); + // melS[i] = logf( dotp( &PS[j], pt_mel_fb, len ) + 1e-5f ); + pt_mel_fb_fx += len; } - v_mult_mat( mfcc, melS, dct_mtx, NB_MEL_BANDS, NB_MEL_COEF ); - - *pFV++ = mfcc[2]; - *pFV++ = mfcc[6]; - *pFV++ = mfcc[12]; + Word16 guard_bits = find_guarded_bits_fx( NB_MEL_BANDS ); + v_mult_mat_fixed( mfcc_fx, melS_fx, dct_mtx_fx, NB_MEL_BANDS, NB_MEL_COEF, guard_bits ); // Q19 + *pFV_fx++ = L_shl( mfcc_fx[2], 1 ); // Q20 + *pFV_fx++ = L_shl( mfcc_fx[6], 1 ); + *pFV_fx++ = L_shl( mfcc_fx[12], 1 ); + /* *pFV++ = mfcc[2]; + *pFV++ = mfcc[6]; + *pFV++ = mfcc[12];*/ /* calculation of differential normalized power spectrum */ - sum_PS = 1e-5f; - for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + sum_PS_fx = 1; + move32(); + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - sum_PS += PS[i]; + sum_PS_fx = L_add( L_shr( PS_fx[i], Q7 ), sum_PS_fx ); // Qfact_PS - Q7 } - for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + temp_exp = 0; + move16(); + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - PS_norm[i] = PS[i] / sum_PS; - dPS[i] = fabsf( PS_norm[i] - hSpMusClas->past_PS[i - LOWEST_FBIN] ); + temp32 = BASOP_Util_Divide3232_Scale( PS_fx[i], sum_PS_fx, &temp_exp ); + PS_norm_fx[i] = L_shl( temp32, sub( Qfact_PS_past, add( sub( 15, temp_exp ), 7 ) ) ); // Qfact_PS_past + move32(); + dPS_fx[i] = L_abs( L_sub( PS_norm_fx[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ); + move32(); } /* [13] ps_diff (spectral difference) */ - ps_diff = 0; - for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + ps_diff_fx = 0; + move32(); + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - ps_diff += dPS[i]; + ps_diff_fx = L_add( L_shr( dPS_fx[i], Q7 ), ps_diff_fx ); // Qfact_PS_past-7 } - *pFV++ = ps_diff; + *pFV_fx++ = L_shr( ps_diff_fx, sub( sub( Qfact_PS_past, Q7 ), Q20 ) ); /// ps_diff; /* [14] ps_sta (spectral stationarity) */ - ps_sta = 0; - for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + ps_sta_fx = 0; + move32(); + Word16 ps_sta_exp = 0; + move16(); + FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { - if ( PS_norm[i] > hSpMusClas->past_PS[i - LOWEST_FBIN] ) + IF( GT_32( PS_norm_fx[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ) { - ps_sta += PS_norm[i] / ( dPS[i] + 1e-5f ); + temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( PS_norm_fx[i], ( dPS_fx[i] + 1 ), &temp_exp ) ); // 31-temp_exp + ps_sta_fx = BASOP_Util_Add_Mant32Exp( temp32, temp_exp, ps_sta_fx, ps_sta_exp, &ps_sta_exp ); } - else + ELSE { - ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / ( dPS[i] + 1e-5f ); + // ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / ( dPS[i] + 1e-5f ); + temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( hSpMusClas->past_PS_fx[i - LOWEST_FBIN], ( dPS_fx[i] + 1 ), &temp_exp ) ); // 31-temp_exp + move32(); + ps_sta_fx = BASOP_Util_Add_Mant32Exp( temp32, temp_exp, ps_sta_fx, ps_sta_exp, &ps_sta_exp ); } } - - *pFV++ = logf( ps_sta + 1e-5f ); - mvr2r( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS, HIGHEST_FBIN - LOWEST_FBIN ); + temp32_log = L_add( BASOP_Util_Log2( ps_sta_fx ), L_shl( ps_sta_exp, Q25 ) ); + temp32_log = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ + *pFV_fx++ = L_shr( temp32_log, Q5 ); // logf( ps_sta + 1e-5f ); + MVR2R_WORD32( &PS_norm_fx[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN - LOWEST_FBIN ); /* save ps_diff and ps_sta features for XTALK and UNCLR classifier */ - if ( hStereoClassif != NULL ) + IF( hStereoClassif != NULL ) { - if ( st->idchan == 0 ) + IF( st->idchan == 0 ) { - hStereoClassif->ps_diff_ch1 = ps_diff; - hStereoClassif->ps_sta_ch1 = logf( ps_sta + 1e-5f ); + hStereoClassif->ps_diff_ch1_fx = ps_diff_fx; // Qfact_PS_past - 7 + hStereoClassif->ps_sta_ch1_fx = temp32_log; // logf( ps_sta + 1e-5f );Q25 } - else + ELSE { - hStereoClassif->ps_diff_ch2 = ps_diff; - hStereoClassif->ps_sta_ch2 = logf( ps_sta + 1e-5f ); + hStereoClassif->ps_diff_ch2_fx = ps_diff_fx; + hStereoClassif->ps_sta_ch2_fx = temp32_log; // logf( ps_sta + 1e-5f );Q25 } + move32(); + move32(); } /*------------------------------------------------------------------* * Outlier detection based on feature histograms *------------------------------------------------------------------*/ - flag_odv = 0; - if ( localVAD_HE_SAD ) + move16(); + IF( localVAD_HE_SAD ) { - pFV = FV; - pODV = hout_intervals; + pFV_fx = FV_fx; + pODV_fx = hout_intervals_fx; p_out = i_out; odv_cnt = 0; - for ( i = 0; i < N_SMC_FEATURES; i++ ) + move16(); + FOR( i = 0; i < N_SMC_FEATURES; i++ ) { - if ( *pFV < pODV[0] || *pFV > pODV[1] ) + IF( LT_32( *pFV_fx, pODV_fx[0] ) || GT_32( *pFV_fx, pODV_fx[1] ) ) { *p_out++ = i; - odv_cnt++; + odv_cnt = add( odv_cnt, 1 ); } - pFV++; - pODV += 2; + pFV_fx++; + pODV_fx += 2; } /* set outlier flag */ - if ( odv_cnt >= 2 ) + IF( GE_16( odv_cnt, 2 ) ) { flag_odv = 1; - + move16(); /* replace outlying features with values from the previous frame */ - for ( i = 0; i < odv_cnt; i++ ) + FOR( i = 0; i < odv_cnt; i++ ) { - FV[i_out[i]] = hSpMusClas->prev_FV[i_out[i]]; + FV_fx[i_out[i]] = hSpMusClas->prev_FV_fx[i_out[i]]; + move32(); } } } @@ -1792,54 +1946,70 @@ int16_t ivas_smc_gmm( /*------------------------------------------------------------------* * Adaptive short-term mean filter on feature vector *------------------------------------------------------------------*/ - - pFV = FV; - pFV_st = hSpMusClas->FV_st; - smc_st_mean_fact = SMC_ST_MEAN_FACT; - for ( i = 0; i < N_SMC_FEATURES; i++ ) + Qfact_FV = 20; + move16(); + pFV_fx = FV_fx; + pFV_st_fx = hSpMusClas->FV_st_fx; + smc_st_mean_fact_fx = SMC_ST_MEAN_RSHIFT_FACT_FX; + move16(); + FOR( i = 0; i < N_SMC_FEATURES; i++ ) { - *pFV_st = smc_st_mean_fact * ( *pFV_st ) + ( 1 - smc_st_mean_fact ) * ( *pFV ); - - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && ( relE_attack_flag || flag_odv ) ) + //*pFV_st = smc_st_mean_fact * ( *pFV_st ) + ( 1 - smc_st_mean_fact ) * ( *pFV ); + *pFV_st_fx = L_add( L_shr( *pFV_st_fx, smc_st_mean_fact_fx ), L_shr( *pFV_fx, 1 ) ); + test(); + test(); + test(); + test(); + test(); + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) && ( relE_attack_flag || flag_odv ) ) { /* strong attack or outlier frame during entry state -> features cannot be trusted but there is also no useful past info -> */ /* -> do whatever you want because dlp will be reset to 0 anyway */ - pFV++; - pFV_st++; + pFV_fx++; + pFV_st_fx++; } - else if ( hSpMusClas->sp_mus_state == HANG_LEN && ( st->tc_cnt == 1 || st->tc_cnt == 2 ) ) + ELSE IF( hSpMusClas->sp_mus_state == HANG_LEN && ( EQ_16( st->tc_cnt, 1 ) || EQ_16( st->tc_cnt, 2 ) ) ) { /* energy attack in stable state -> use current features intead of the long-term average */ - pFV++; - pFV_st++; + pFV_fx++; + pFV_st_fx++; } - else + ELSE { - *pFV++ = *pFV_st++; + *pFV_fx++ = *pFV_st_fx++; } } /* update */ - mvr2r( FV, hSpMusClas->prev_FV, N_SMC_FEATURES ); - + MVR2R_WORD32( FV_fx, hSpMusClas->prev_FV_fx, N_SMC_FEATURES ); /*------------------------------------------------------------------* * Non-linear power transformation (boxcox) on certain features *------------------------------------------------------------------*/ - - pFV = FV; - for ( i = 0; i < N_SMC_FEATURES; i++ ) + pFV_fx = FV_fx; + FOR( i = 0; i < N_SMC_FEATURES; i++ ) { - if ( bcox_lmbd[i] != 0 ) + IF( bcox_lmbd_fx[i] != 0 ) { - *pFV -= bcox_add_cnst[i]; - if ( *pFV < 1 ) + *pFV_fx = L_sub( *pFV_fx, L_shr( bcox_add_cnst_fx[i], sub( 31, Qfact_FV ) ) ); + IF( LT_32( *pFV_fx, L_shl( 1, Qfact_FV ) ) ) { - *pFV = 1; + *pFV_fx = L_shl( 1, Qfact_FV ); } - *pFV = ( powf( *pFV, bcox_lmbd[i] ) - 1 ) / bcox_lmbd[i]; + Word16 pow_e = 0; + move32(); + temp32_log = L_add( BASOP_Util_Log2( *pFV_fx ), L_shl( sub( 31, Qfact_FV ), Q25 ) ); // Q25 + temp32 = Mpy_32_32( temp32_log, bcox_lmbd_fx[i] ); // Q25 + Word32 pow_temp = BASOP_util_Pow2( temp32, sub( 31, Q25 ), &pow_e ); + temp32 = L_sub( pow_temp, L_shl( 1, 31 - pow_e ) ); + temp_exp = 0; + move32(); + temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, bcox_lmbd_fx[i], &temp_exp ) ); + *pFV_fx = L_shl( temp32, sub( Qfact_FV, sub( 31, add( temp_exp, pow_e ) ) ) ); + // float temp = powf( *pFV, bcox_lmbd[i] ); + // *pFV = ( powf( *pFV, bcox_lmbd[i] ) - 1 ) / bcox_lmbd[i]; } - pFV++; + pFV_fx++; } /*------------------------------------------------------------------* @@ -1847,302 +2017,375 @@ int16_t ivas_smc_gmm( * PCA *------------------------------------------------------------------*/ - pFV = FV; - for ( i = 0; i < N_SMC_FEATURES; i++ ) + pFV_fx = FV_fx; + FOR( i = 0; i < N_SMC_FEATURES; i++ ) { /* Standard scaler - mean and variance normalization */ - *pFV = ( *pFV - sm_means[i] ) / sm_scale[i]; - pFV++; - + // *pFV = ( *pFV - sm_means[i] ) / sm_scale[i]; + temp32 = L_sub( *pFV_fx, sm_means_fx[i] ); + temp_exp = 0; + temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, sm_scale_fx[i], &temp_exp ) ); + *pFV_fx = L_shl( temp32, Qfact_FV - ( 31 - temp_exp ) ); + pFV_fx++; /* MinMax sclaer - mean and variance normalization */ /**pFV = *pFV * sm_scale[i] + sm_min[i];*/ - /*pFV++;*/ } /* PCA */ - v_sub( FV, pca_mean_, FV, N_SMC_FEATURES ); - v_mult_mat( FV, FV, pca_components_, N_SMC_FEATURES, N_PCA_COEF ); - + v_sub_fixed( FV_fx, pca_mean_fx, FV_fx, N_SMC_FEATURES, 0 ); + v_mult_mat_fixed( FV_fx, FV_fx, pca_components_fx, N_SMC_FEATURES, N_PCA_COEF, 0 ); /*------------------------------------------------------------------* * Calculation of posterior probability * Log-probability *------------------------------------------------------------------*/ /* run loop for all mixtures (for each mixture, calculate the probability of speech, music and noise) */ - lps = lpm = lpn = 0; - for ( m = 0; m < N_SMC_MIXTURES; m++ ) + lps_fx = lpm_fx = lpn_fx = 0; + move32(); + move32(); + move32(); + FOR( m = 0; m < N_SMC_MIXTURES; m++ ) { - v_sub( FV, &means_speech[m * N_PCA_COEF], fvm, N_PCA_COEF ); - lprob = dot_product_cholesky( fvm, &prec_chol_speech[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); - ps[m] = logf( weights_speech[m] ) + log_det_chol_speech[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; - - v_sub( FV, &means_music[m * N_PCA_COEF], fvm, N_PCA_COEF ); - lprob = dot_product_cholesky( fvm, &prec_chol_music[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); - pm[m] = logf( weights_music[m] ) + log_det_chol_music[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; + v_sub32_fx( FV_fx, &means_speech_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); + fvm_exp = sub( 31, Qfact_FV ); + lprob_exp = 0; + move16(); + lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_speech_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); + ps_fx[m] = L_sub( log_weights_speech_compute[m], L_shr( L_shl_sat( lprob_fx, sub( Q19, sub( Q31, lprob_exp ) ) ), 1 ) ); + move32(); + v_sub32_fx( FV_fx, &means_music_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); + lprob_exp = 0; + move16(); + lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_music_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); + pm_fx[m] = L_sub( log_weights_music_compute[m], L_shr( L_shl_sat( lprob_fx, sub( Q19, sub( Q31, lprob_exp ) ) ), 1 ) ); + move32(); + v_sub32_fx( FV_fx, &means_noise_fx[m * N_PCA_COEF], fvm_fx, N_PCA_COEF ); - v_sub( FV, &means_noise[m * N_PCA_COEF], fvm, N_PCA_COEF ); - lprob = dot_product_cholesky( fvm, &prec_chol_noise[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF ); - pn[m] = logf( weights_noise[m] ) + log_det_chol_noise[m] - 0.5f * N_PCA_COEF * logf( PI2 ) - 0.5f * lprob; + lprob_exp = 0; + move16(); + lprob_fx = dot_product_cholesky_fixed( fvm_fx, &prec_chol_noise_fx[m * ( N_PCA_COEF * N_PCA_COEF + N_PCA_COEF ) / 2], N_PCA_COEF, fvm_exp, 31 - 28, &lprob_exp ); + pn_fx[m] = L_sub( log_weights_music_compute[m], L_shr( L_shl_sat( lprob_fx, sub( Q19, sub( Q31, lprob_exp ) ) ), 1 ) ); + move32(); } - lps = logsumexp( ps, N_SMC_MIXTURES ); - lpm = logsumexp( pm, N_SMC_MIXTURES ); - lpn = logsumexp( pn, N_SMC_MIXTURES ); - + lps_fx = logsumexp_fx( ps_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); + lpm_fx = logsumexp_fx( pm_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); + lpn_fx = logsumexp_fx( pn_fx, sub( 31, Q19 ), N_SMC_MIXTURES ); *high_lpn_flag = 0; - if ( lpn > lps && lpn > lpm ) + move16(); + if ( GT_32( lpn_fx, lps_fx ) && GT_32( lpn_fx, lpm_fx ) ) { *high_lpn_flag = 1; + move32(); } - hSpMusClas->lpm = lpm; - hSpMusClas->lps = lps; - hSpMusClas->lpn = lpn; + hSpMusClas->lpm_fx = extract_l( L_shr( lpm_fx, 11 ) ); // Q8 + hSpMusClas->lps_fx = extract_l( L_shr( lps_fx, 11 ) ); // Q8 + hSpMusClas->lpn_fx = extract_l( L_shr( lpn_fx, 11 ) ); // Q8 /* determine HQ Generic speech class */ - if ( st->hHQ_core != NULL ) + IF( st->hHQ_core != NULL ) { - if ( lps > lpm + 0.5f ) + IF( GT_32( lps_fx, L_add( lpm_fx, ONE_IN_Q18 ) ) ) { st->hHQ_core->hq_generic_speech_class = 1; } - else + ELSE { st->hHQ_core->hq_generic_speech_class = 0; } + move16(); } /*------------------------------------------------------------------* * Decision without hangover * Weighted decision *------------------------------------------------------------------*/ - + test(); + test(); + test(); + test(); + test(); /* decision without hangover (0 - speech/noise, 1 - music) */ - if ( !localVAD_HE_SAD || Etot < 10 || ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN && ( relE_attack_flag || flag_odv ) ) ) + IF( !localVAD_HE_SAD || LT_16( Etot_fx, 2560 ) || ( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) && ( relE_attack_flag || flag_odv ) ) ) { - dlp = 0; + dlp_fx = 0; + move32(); } - else + ELSE { - dlp = lpm - lps + DLP_BIAS; + dlp_fx = L_add( L_sub( lpm_fx, lps_fx ), DLP_BIAS_FX ); - if ( dlp > 30.0f ) + IF( GT_32( dlp_fx, 15728640 ) ) /*30.0f in Q19*/ { - dlp = 30.0f; + dlp_fx = 15728640; } - else if ( dlp < -30.0f ) + ELSE IF( LT_32( dlp_fx, -15728640 ) ) { - dlp = -30.0f; + dlp_fx = -15728640; } + move32(); } - dec = dlp > 0; - + dec = (Word16) GT_32( dlp_fx, 0 ); /* calculate weight based on relE (higher relE -> lower weight, lower relE -> higher weight) */ - wrelE = lin_interp( relE, 15.0f, 0.9f, -15.0f, 0.99f, 1 ); + Word16 Qio = Q25; + move16(); + wrelE_fx = lin_interp32_fx( L_deposit_h( relE_fx ), 503316480, 30198989, -503316480, 33218888, 1, &Qio ); // Q25 + wrelE_fx = L_shr( wrelE_fx, sub( Qio, 25 ) ); /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ - hSpMusClas->dlp_mean_ST = 0.8f * hSpMusClas->dlp_mean_ST + 0.2f * dlp; - hSpMusClas->lt_dec_thres = hSpMusClas->dlp_mean_ST; - - if ( dlp < 0 && dlp < hSpMusClas->dlp_mean_ST ) + // hSpMusClas->dlp_mean_ST = 0.8f * hSpMusClas->dlp_mean_ST + 0.2f * dlp; + hSpMusClas->dlp_mean_ST_fx = L_add( Mpy_32_32( 419430, hSpMusClas->dlp_mean_ST_fx ), Mpy_32_32( 104858, dlp_fx ) ); + hSpMusClas->lt_dec_thres_fx = extract_l( L_shr( hSpMusClas->dlp_mean_ST_fx, 10 ) ); + test(); + IF( dlp_fx < 0 && LT_32( dlp_fx, hSpMusClas->dlp_mean_ST_fx ) ) { - if ( hSpMusClas->dlp_mean_ST > 0 ) + IF( hSpMusClas->dlp_mean_ST_fx > 0 ) { - hSpMusClas->wdrop = -dlp; + hSpMusClas->wdrop_fx = -extract_l( L_shr( dlp_fx, 10 ) ); // Q9 } - else if ( hSpMusClas->wdrop > 0 ) + ELSE IF( hSpMusClas->wdrop_fx > 0 ) { - hSpMusClas->wdrop += hSpMusClas->dlp_mean_ST - dlp; + hSpMusClas->wdrop_fx = extract_l( L_shr( L_sub( hSpMusClas->dlp_mean_ST_fx, dlp_fx ), 10 ) ); } } - else + ELSE { - hSpMusClas->wdrop = 0; + hSpMusClas->wdrop_fx = 0; + move16(); } - - wdrop = lin_interp( hSpMusClas->wdrop, 15.0f, 0.7f, 0.0f, 1.0f, 1 ); - + Qio = Q25; + move16(); + wdrop_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wdrop_fx ), 503316480, 23488102, 0, ONE_IN_Q25, 1, &Qio ); + wdrop_fx = L_shr( wdrop_fx, sub( Qio, 25 ) ); + test(); + test(); /* calculate weight based on rises of dlp (close to 1 during sudden rise of dlp, close to 0 otherwise) */ - if ( hSpMusClas->sp_mus_state == HANG_LEN && hSpMusClas->dlp_mean_ST > 0 && hSpMusClas->dlp_mean_ST > hSpMusClas->past_dlp_mean_ST[0] ) + IF( EQ_16( hSpMusClas->sp_mus_state, HANG_LEN ) && hSpMusClas->dlp_mean_ST_fx > 0 && hSpMusClas->dlp_mean_ST_fx > hSpMusClas->past_dlp_mean_ST_fx[0] ) { - if ( hSpMusClas->past_dlp_mean_ST[0] < 0 ) + IF( hSpMusClas->past_dlp_mean_ST_fx[0] < 0 ) { - hSpMusClas->wrise = hSpMusClas->dlp_mean_ST; + hSpMusClas->wrise_fx = extract_l( L_shr( hSpMusClas->dlp_mean_ST_fx, 10 ) ); } - else if ( hSpMusClas->wrise > 0 ) + ELSE IF( hSpMusClas->wrise_fx > 0 ) { - hSpMusClas->wrise += hSpMusClas->dlp_mean_ST - hSpMusClas->past_dlp_mean_ST[0]; + hSpMusClas->wrise_fx = add( hSpMusClas->wrise_fx, extract_l( L_shr( L_sub( hSpMusClas->dlp_mean_ST_fx, hSpMusClas->past_dlp_mean_ST_fx[0] ), 10 ) ) ); } } - else + ELSE { - hSpMusClas->wrise = 0; + hSpMusClas->wrise_fx = 0; + move16(); } - wrise = lin_interp( hSpMusClas->wrise, 5.0f, 0.95f, 0.0f, 1.0f, 1 ); + Qio = Q25; + move16(); + wrise_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wrise_fx ), 167772160, 31876710, 0, ONE_IN_Q25, 1, &Qio ); + wrise_fx = L_shr( wrise_fx, sub( Qio, 25 ) ); /* combine weights into one */ - wght = wrelE * wdrop * wrise; - + // wght = wrelE * wdrop * wrise; + wght_fx = Mpy_32_32( Mpy_32_32( wrelE_fx, wdrop_fx ), wrise_fx ); // Q13 + test(); /* ratio of delta means vs. delta variances */ - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + if ( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { - hSpMusClas->dlp_mean_LT = dlp; - hSpMusClas->dlp_var_LT = 0; + + hSpMusClas->dlp_mean_LT_fx = dlp_fx; + hSpMusClas->dlp_var_LT_fx = 0; + move32(); + move32(); } - hSpMusClas->dlp_mean_LT = 0.9f * hSpMusClas->dlp_mean_LT + 0.1f * dlp; - ftmp = dlp - hSpMusClas->dlp_mean_LT; - hSpMusClas->dlp_var_LT = 0.9f * hSpMusClas->dlp_var_LT + 0.1f * ( ftmp * ftmp ); + hSpMusClas->dlp_mean_LT_fx = L_add( Mpy_32_32( 1932735283, hSpMusClas->dlp_mean_LT_fx ), Mpy_32_32( 214748365, dlp_fx ) ); // Q19 - if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + temp32 = L_sub( dlp_fx, hSpMusClas->dlp_mean_LT_fx ); + hSpMusClas->dlp_var_LT_fx = L_add( Mpy_32_32( 1932735283, hSpMusClas->dlp_var_LT_fx ), Mpy_32_32( 214748365, temp32 ) ); + + test(); + IF( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) { - dlp_mean2var = 0; + dlp_mean2var_fx = 0; + dlp_mean2var_q = 0; + move16(); + move16(); } - else + ELSE { - dlp_mean2var = fabsf( hSpMusClas->dlp_mean_LT ) / ( sqrtf( fabsf( hSpMusClas->dlp_var_LT ) ) + 1.0f ); + temp_exp = sub( Q31, Q19 ); + Word16 div_e = 0; + move16(); + temp32 = Sqrt32( L_abs( hSpMusClas->dlp_var_LT_fx ), &temp_exp ); + temp_sqrt = L_add( Sqrt32( L_abs( hSpMusClas->dlp_var_LT_fx ), &temp_exp ), 1 ); + dlp_mean2var_fx = BASOP_Util_Divide3232_Scale( L_abs( hSpMusClas->dlp_mean_LT_fx ), temp_sqrt, &div_e ); + dlp_mean2var_q = sub( add( Q3, temp_exp ), div_e ); // 15-div_e+Q19 -(31-temp_exp) } - if ( dlp_mean2var > 15.0f ) + if ( GT_32( L_deposit_l( dlp_mean2var_fx ), L_shl( 15, dlp_mean2var_q ) ) ) { /* decrease the weight little bit when the classifier indicates "strong speech" or "strong music" */ - wght *= 0.9f; + // wght *= 0.9f; + wght_fx = Mpy_32_32( wght_fx, 1932735283 ); // Q13 } - if ( wght > 1.0f ) + IF( GT_32( wght_fx, ONE_IN_Q13 ) ) { - wght = 1.0f; + wght_fx = ONE_IN_Q13; } - else if ( wght < 0.01f ) + ELSE IF( LT_32( wght_fx, 82 ) ) { - wght = 0.01f; + wght_fx = 82; } - - if ( Etot < 10 ) + move32(); + if ( LT_16( Etot_fx, 256 ) ) { /* silence */ - wght = 0.92f; + wght_fx = 7537; + move32(); } /* calculate weighted decision */ - hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + ( 1 - wght ) * dlp; + // hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + ( 1 - wght ) * dlp; + + hSpMusClas->wdlp_0_95_sp_fx = (Word16) L_add( L_shl( Mpy_32_16_1( wght_fx, hSpMusClas->wdlp_0_95_sp_fx ), Q2 ), L_shl( Mpy_32_32( L_sub( ONE_IN_Q13, wght_fx ), dlp_fx ), Q5 ) ); // Q8 /* xtalk classifier: apply long hysteresis to prevent LRTD on music */ - hSpMusClas->wdlp_xtalk = 0.995f * hSpMusClas->wdlp_xtalk + 0.005f * dlp; + + hSpMusClas->wdlp_xtalk_fx = L_add( Mpy_32_32( 2136746229, hSpMusClas->wdlp_xtalk_fx ), Mpy_32_32( 10737418, dlp_fx ) ); /*------------------------------------------------------------------* * Final speech/music decision *------------------------------------------------------------------*/ - if ( flag_spitch ) + IF( flag_spitch ) { hSpMusClas->flag_spitch_cnt = 5; + move16(); } - else if ( hSpMusClas->flag_spitch_cnt > 0 ) + ELSE IF( hSpMusClas->flag_spitch_cnt > 0 ) { - hSpMusClas->flag_spitch_cnt--; + hSpMusClas->flag_spitch_cnt = sub( hSpMusClas->flag_spitch_cnt, 1 ); } - - if ( Etot < 10 ) + test(); + IF( Etot_fx < 2560 ) { /* silence */ dec = 0; + move16(); } - else if ( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + ELSE IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { + temp32 = L_mult( w_spmus_fx[hSpMusClas->sp_mus_state - 1][0], (Word16) L_shr( dlp_fx, 10 ) ); /*Q25 */ + temp32 = L_add( temp32, Dot_product( &w_spmus_fx[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp_fx, sub( HANG_LEN, 1 ) ) ); + move16(); /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ - ftmp = w_spmus[hSpMusClas->sp_mus_state - 1][0] * dlp; - ftmp += dotp( &w_spmus[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp, HANG_LEN - 1 ); - if ( ftmp > 2.0f ) + IF( GT_32( temp32, L_shl( 2, 25 ) ) ) { - if ( dlp > 2.0f ) + IF( GT_32( dlp_fx, L_shl( 2, 19 ) ) ) { dec = 2; } - else + ELSE { dec = 1; } } - else + ELSE { dec = 0; } + move16(); } - else + ELSE { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); /* stable active state */ - if ( hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 && - ( ( hSpMusClas->flag_spitch_cnt > 0 && hSpMusClas->wdlp_0_95_sp > 3.4f ) || ( hSpMusClas->flag_spitch_cnt == 0 && hSpMusClas->wdlp_0_95_sp > 2.1f ) ) ) + IF( hSpMusClas->past_dec[0] == 0 && hSpMusClas->past_dec[1] == 0 && hSpMusClas->past_dec[2] == 0 && + ( ( hSpMusClas->flag_spitch_cnt > 0 && GT_16( hSpMusClas->wdlp_0_95_sp_fx, 870 ) ) || ( hSpMusClas->flag_spitch_cnt == 0 && GT_16( hSpMusClas->wdlp_0_95_sp_fx, 538 ) ) ) ) { /* switching from speech to unclear */ dec = 1; } - else if ( hSpMusClas->past_dec[0] == 0 && hSpMusClas->vad_0_1_cnt < 50 && hSpMusClas->relE_attack_sum == 0.0f && hSpMusClas->wdlp_0_95_sp > 1.0f ) + ELSE IF( hSpMusClas->past_dec[0] == 0 && LT_16( hSpMusClas->vad_0_1_cnt, 50 ) && hSpMusClas->relE_attack_sum_fx == 0 && GT_16( hSpMusClas->wdlp_0_95_sp_fx, 256 ) ) { /* switch from speech to unclear also during slowly rising weak music onsets */ dec = 1; } - else if ( hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp > 2.5f ) + ELSE IF( EQ_16( hSpMusClas->past_dec[0], 1 ) && GT_16( hSpMusClas->wdlp_0_95_sp_fx, 640 ) ) { /* switching from unclear to music */ dec = 2; } - else if ( hSpMusClas->past_dec[0] == 2 && hSpMusClas->past_dec[1] == 2 && hSpMusClas->past_dec[2] == 2 && hSpMusClas->wdlp_0_95_sp < -1.0f ) + ELSE IF( EQ_16( hSpMusClas->past_dec[0], 2 ) && EQ_16( hSpMusClas->past_dec[1], 2 ) && EQ_16( hSpMusClas->past_dec[2], 2 ) && LT_16( hSpMusClas->wdlp_0_95_sp_fx, -256 ) ) { /* switching from music to unclear */ dec = 1; } - else if ( hSpMusClas->past_dec[0] == 1 && hSpMusClas->wdlp_0_95_sp < -2.5f ) + ELSE IF( EQ_16( hSpMusClas->past_dec[0], 1 ) && LT_16( hSpMusClas->wdlp_0_95_sp_fx, -640 ) ) { /* switching from unclear to speech */ dec = 0; } - else + ELSE { dec = hSpMusClas->past_dec[0]; } + move16(); } /*------------------------------------------------------------------* * raw S/M decision based on smoothed GMM score *------------------------------------------------------------------*/ - - if ( dec == 0 || st->hSpMusClas->wdlp_0_95_sp <= 0 ) + test(); + IF( dec == 0 || st->hSpMusClas->wdlp_0_95_sp_fx <= 0 ) { st->sp_aud_decision0 = 0; st->sp_aud_decision1 = 0; } - else + ELSE { st->sp_aud_decision0 = 1; st->sp_aud_decision1 = 1; } - + move16(); + move16(); /*------------------------------------------------------------------* * Updates *------------------------------------------------------------------*/ /* update buffer of past non-binary decisions */ - mvr2r( &hSpMusClas->past_dlp[0], &hSpMusClas->past_dlp[1], HANG_LEN - 2 ); - hSpMusClas->past_dlp[0] = dlp; - + MVR2R_WORD16( &hSpMusClas->past_dlp_fx[0], &hSpMusClas->past_dlp_fx[1], HANG_LEN - 2 ); + hSpMusClas->past_dlp_fx[0] = extract_l( L_shr( dlp_fx, 10 ) ); + move16(); mvr2r( &hSpMusClas->past_dlp_mean_ST[0], &hSpMusClas->past_dlp_mean_ST[1], HANG_LEN - 2 ); - hSpMusClas->past_dlp_mean_ST[0] = hSpMusClas->dlp_mean_ST; - + hSpMusClas->past_dlp_mean_ST_fx[0] = hSpMusClas->dlp_mean_ST_fx; + move32(); /* update buffer of past binary decisions */ mvs2s( &hSpMusClas->past_dec[0], &hSpMusClas->past_dec[1], HANG_LEN - 2 ); hSpMusClas->past_dec[0] = dec; - + move16(); #ifdef DEBUG_MODE_INFO dbgwrite( &st->hSpMusClas->wdlp_0_95_sp, sizeof( float ), 1, 1, "res/wdlp_0_95_sp.x" ); #endif return dec; } - +#endif +#ifdef IVAS_CODE /*---------------------------------------------------------------------* * ivas_smc_mode_selection() * @@ -3497,15 +3740,15 @@ static void tonal_context_improv_fx( } /* Pitch difference w.r.t to past 3 frames */ - lt_pitch_diff = abs_s( sub( hSpMusClas->lt_corr_pitch[0], st_fx->pitch_fx[0] ) ); - lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[1], st_fx->pitch_fx[0] ) ) ); - lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[2], st_fx->pitch_fx[0] ) ) ); + lt_pitch_diff = abs_s( sub( hSpMusClas->lt_corr_pitch[0], st_fx->pitch[0] ) ); + lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[1], st_fx->pitch[0] ) ) ); + lt_pitch_diff = add( lt_pitch_diff, abs_s( sub( hSpMusClas->lt_corr_pitch[2], st_fx->pitch[0] ) ) ); hSpMusClas->lt_corr_pitch[0] = hSpMusClas->lt_corr_pitch[1]; move16(); hSpMusClas->lt_corr_pitch[1] = hSpMusClas->lt_corr_pitch[2]; move16(); - hSpMusClas->lt_corr_pitch[2] = st_fx->pitch_fx[0]; + hSpMusClas->lt_corr_pitch[2] = st_fx->pitch[0]; move16(); hSpMusClas->lt_old_mode[0] = hSpMusClas->lt_old_mode[1]; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 6ab6aae6c6338a5cc39f16efa038e20ba41dd47e..9b95d11439a7634d8564681f78fce0730a139408 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -91,10 +91,10 @@ typedef struct bitstream_enc_data_structure Indice **ivas_ind_list_zero; /* beginning of the buffer of indices */ void *st_ivas; /* IVAS encoder structure */ - Word16 nb_bits_tot_fx; /* total number of bits already written */ - Indice *ind_list_fx; /* list of indices */ - Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ - Word16 last_ind_fx; /* last written indice */ + // Word16 nb_bits_tot_fx; /* total number of bits already written */ + // Indice *ind_list_fx; /* list of indices */ + Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ + Word16 last_ind_fx; /* last written indice */ } BSTR_ENC_DATA, *BSTR_ENC_HANDLE; @@ -117,6 +117,7 @@ typedef struct signal_buffers_enc_data_structure float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ // Fixed Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; + Word32 input_buff32[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; Word32 Bin_E_old_fx[L_FFT / 2]; /* per bin energy of old 2nd frames */ Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ @@ -431,6 +432,7 @@ typedef struct td_cng_enc_structure int16_t cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ int16_t cng_ener_seed1; float lp_sp_enr; + Word16 lp_sp_enr_fx; /*Q8*/ int16_t last_allow_cn_step; int16_t ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ @@ -442,6 +444,7 @@ typedef struct td_cng_enc_structure float ho_lsp_hist[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ float ho_env_hist[HO_HIST_SIZE * NUM_ENV_CNG]; + Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; @@ -614,6 +617,7 @@ typedef struct fd_cng_enc_structure typedef struct dtx_enc_structure { + int16_t cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or DTX, if enabled */ int16_t first_CNG; /* CNG and DTX - first CNG frame flag */ int16_t cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ @@ -628,6 +632,7 @@ typedef struct dtx_enc_structure float frame_ener; Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ + Word32 frame_ener_fx; int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ @@ -673,6 +678,19 @@ typedef struct igf_enc_private_data_struct IGF_INFO igfInfo; int16_t igfScfQuantized[IGF_MAX_SFB]; IGFSCFENC_INSTANCE hIGFSCFArithEnc; +#ifdef IVAS_FLOAT_FIXED + Word16 prevSFM_FIR_SFB_TB_fx[IGF_MAX_SFB]; + Word16 sfb_sb_e[IGF_MAX_SFB]; + Word16 sfb_tb_e[IGF_MAX_SFB]; + Word16 prevSFM_IIR_SFB_TB_fx[IGF_MAX_SFB]; + Word16 prevSFM_FIR_SFB_SB_fx[IGF_MAX_SFB]; + Word16 prevSFM_IIR_SFB_SB_fx[IGF_MAX_SFB]; + Word16 SFM_tb_fx[IGF_MAX_SFB]; + Word16 SFM_sb_fx[IGF_MAX_SFB]; + Word16 prevDampingFactor_IIR_fx[IGF_MAX_SFB]; + Word16 prevDampingFactor_IIR_e[IGF_MAX_SFB]; + Word16 igfPastSFM_fx[IGF_MAX_TILES][IGF_PAST_SFM_LEN]; /*2Q13*/ +#endif // IVAS_FLOAT_FIXED float prevSFM_FIR_SFB_TB[IGF_MAX_SFB]; float prevSFM_IIR_SFB_TB[IGF_MAX_SFB]; @@ -694,7 +712,7 @@ typedef struct igf_enc_private_data_struct float prevSFM_FIR_flt[IGF_MAX_TILES]; float prevSFM_IIR_flt[IGF_MAX_TILES]; Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ - Word16 prevSFM_IIR[IGF_MAX_TILES]; + Word16 prevSFM_IIR[IGF_MAX_TILES]; /* 2Q13 */ int16_t wasTransient; UWord8 igfBitstream[IGF_BITBUFSIZE / 8]; @@ -766,15 +784,23 @@ typedef struct noise_estimation_structure float Etot_l_lp; /* Noise estimator - Smoothed low energy */ float Etot_last; /* Noise estimator - Energy of last frame */ float Etot_lp; /* Noise estimator - Filtered input energy */ + float lt_tn_track; float lt_tn_dist; float lt_Ellp_dist; float lt_haco_ev; - Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ - Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ - Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ - Word16 Etot_last_fx; /*Q8*/ - Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ + Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ + Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ + Word16 Etot_last_fx; /*Q8*/ + Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ + + Word32 Etot_l_32fx; /* Q8 Noise estimator - Track energy from below */ + Word32 Etot_h_32fx; /* Q8 Noise estimator - Track energy from above */ + Word32 Etot_l_lp_32fx; /* Q8 Noise estimator - Smoothed low energy */ + Word32 Etot_last_32fx; /*Q8*/ + Word32 Etot_lp_32fx; /* Q8 Noise estimator - Filtered input energy */ + Word16 lt_tn_track_fx; /* Q15 */ Word16 lt_tn_dist_fx; /* Q8*/ Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ @@ -799,7 +825,11 @@ typedef struct noise_estimation_structure float Etot_st_est; /* Noise estimation - short term estimate of E{ Etot } */ float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ Word16 Etot_v_h2_fx; - Word16 sign_dyn_lp_fx; /*Q8*/ + Word16 sign_dyn_lp_fx; /*Q8*/ + + Word32 Etot_v_h2_32fx; + Word32 sign_dyn_lp_32fx; /*Q8*/ + Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ @@ -813,12 +843,14 @@ typedef struct noise_estimation_structure typedef struct sp_mus_clas_structure { - float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ + float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ + Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; float past_ps_diff; Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; Word16 past_ps_diff_fx; float prev_FV[N_SMC_FEATURES]; + Word32 prev_FV_fx[N_SMC_FEATURES]; float past_epsP; float past_epsP2; Word16 past_epsP2_fx; @@ -826,18 +858,24 @@ typedef struct sp_mus_clas_structure float wdrop; Word16 wdrop_fx; float wrise; + Word16 wrise_fx; float wdlp_0_95_sp; Word16 wdlp_0_95_sp_fx; float wdlp_xtalk; + Word32 wdlp_xtalk_fx; int16_t sp_mus_state; int16_t past_dec[HANG_LEN - 1]; /* Speech/music classifier - buffer of past binary decisions */ float past_dlp[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions */ Word16 past_dlp_fx[HANG_LEN - 1]; - float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ + float past_dlp_mean_ST[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ + Word32 past_dlp_mean_ST_fx[HANG_LEN - 1]; /* Speech/music classifier - buffer of past non-binary decisions (with ST smoothing) */ float dlp_mean_ST; + Word32 dlp_mean_ST_fx; int16_t flag_spitch_cnt; float dlp_mean_LT; + Word32 dlp_mean_LT_fx; float dlp_var_LT; + Word32 dlp_var_LT_fx; float last_lsp[M_LSP_SPMUS]; float last_cor_map_sum; float last_non_sta; @@ -862,6 +900,7 @@ typedef struct sp_mus_clas_structure float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ Word16 mold_corr_fx; + Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ @@ -869,10 +908,13 @@ typedef struct sp_mus_clas_structure int16_t relE_attack_cnt; float prev_relE; + Word16 prev_relE_fx; float prev_Etot; + Word16 prev_Etot_fx; int16_t prev_vad; int16_t vad_0_1_cnt; float relE_attack_sum; + Word16 relE_attack_sum_fx; /* speech/music classifier improvement parameters */ float old_Bin_E[3 * N_OLD_BIN_E]; @@ -966,6 +1008,7 @@ typedef struct sp_mus_clas_structure float lpm; Word16 lps_fx; Word16 lpm_fx; + Word16 lpn_fx; float lpn; @@ -994,6 +1037,7 @@ typedef struct lpd_state_structure float mem_syn2_flt[M]; /* ACELP synthesis memory (pe) after post-proc */ float mem_syn_r_flt[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ float mem_syn3_flt[M]; + Word16 mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ @@ -1051,8 +1095,8 @@ typedef struct gsc_enc_structure float mid_dyn; /* AC mode (GSC) - signal dynamic */ Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; - Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ + Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ int16_t noise_lev; /* AC mode (GSC) - noise level */ int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ @@ -1064,7 +1108,9 @@ typedef struct gsc_enc_structure Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ float lt_gpitch; + Word16 lt_gpitch_fx; /*Q15 */ + } GSC_ENC_DATA, *GSC_ENC_HANDLE; /*----------------------------------------------------------------------------------* @@ -1562,12 +1608,12 @@ typedef struct tcx_enc_structure int16_t noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ STnsData tnsData[2]; - int16_t fUseTns[2]; - Word8 fUseTns_fx[2]; + // int16_t fUseTns[2]; + Word8 fUseTns[2]; int16_t bTnsOnWhithenedSpectra[2]; - int16_t memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ - Word8 memQuantZeros_fx[L_FRAME_PLUS]; + // int16_t memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ + Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ float *speech_TCX_flt; float *new_speech_TCX_flt; @@ -1634,7 +1680,8 @@ typedef struct tcx_enc_structure Word16 tcx_target_bits_fac; int16_t tns_ms_flag[2]; - Word32 *spectrum_fx[2]; /* MDCT output for a short block */ + Word32 *spectrum_fx[2]; /* MDCT output for a short block */ + Word16 spectrum_e[2]; Word32 spectrum_long_fx[N_MAX]; /* MDCT output for a long block. Points to spectrum */ } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -1753,7 +1800,7 @@ typedef struct enc_core_structure int16_t pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ float voicing[3]; /* open-loop normalized correlation values for three half-frames */ - Word16 pitch_fx[3]; + // Word16 pitch_fx[3]; Word16 voicing_fx[3]; LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ @@ -1782,11 +1829,10 @@ typedef struct enc_core_structure float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ - - float clip_var[6]; /* pitch gain clipping memory */ - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 pstreaklen_fx; /* LSF quantizer */ + float clip_var[6]; /* pitch gain clipping memory */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + // Word16 pstreaklen_fx; /* LSF quantizer */ Word16 streaklimit_fx; /* LSF quantizer */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ @@ -1795,19 +1841,20 @@ typedef struct enc_core_structure Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ Word16 stab_fac_fx; /* LSF stability factor */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word16 mem_preemph_fx; /* preemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ - Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ - Word16 mem_wsp_fx; /* weighted signal vector memory */ - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 clip_var_fx[6]; - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 mem_preemph_fx; /* preemphasis filter memory */ + + Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ + /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ + Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ + Word16 mem_wsp_fx; /* weighted signal vector memory */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 clip_var_fx[6]; + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; @@ -1845,6 +1892,7 @@ typedef struct enc_core_structure int16_t old_pitch; /* previous pitch for open-loop pitch search */ int16_t delta_pit; /* open-loop pitch extrapolation correction */ float ee_old; /* previous frame low/high frequency energy ratio */ + Word32 ee_old_fx; int16_t min_band; /* minimum critical band of useful bandwidth */ int16_t max_band; /* maximum critical band of useful bandwidth */ @@ -1864,7 +1912,6 @@ typedef struct enc_core_structure Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ Word16 last_vad_spa_fx; - Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ @@ -1913,7 +1960,9 @@ typedef struct enc_core_structure float *old_input_signal; Word16 *input_buff_fx; + Word32 *input_buff32_fx; Word16 *input_fx; + Word32 *input32_fx; Word16 *old_input_signal_fx; Word16 Q_old_wtda; @@ -2145,6 +2194,7 @@ typedef struct enc_core_structure float preemph_fac_flt; /* Preemphasis factor */ float gamma_flt; + Word16 preemph_fac; /*Preemphasis factor*/ Word16 gamma; @@ -2178,6 +2228,7 @@ typedef struct enc_core_structure int16_t encoderLookahead_FB; /* pitch_ol for adaptive lag window */ + int16_t old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ @@ -2267,10 +2318,10 @@ typedef struct enc_core_structure float mem_preemph16k_DFT; float inp_16k_mem_stereo_sw[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; - Word32 mem_preemph_DFT_fx; - Word32 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; - Word32 mem_preemph16k_DFT_fx; - Word32 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; + Word16 mem_preemph_DFT_fx; + Word16 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; + Word16 mem_preemph16k_DFT_fx; + Word16 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; /* MCT Channel mode indication: LFE, ignore channel? */ MCT_CHAN_MODE mct_chan_mode; @@ -2314,6 +2365,7 @@ typedef struct enc_core_structure // // /*----------------------------------------------------------------------------------* // * Common parameters + // *----------------------------------------------------------------------------------*/ // /*----------------------------------------------------------------------------------* // * Stereo/IVAS parameters @@ -2548,6 +2600,7 @@ typedef struct enc_core_structure // /*----------------------------------------------------------------------------------* // * AMR-WB IO handle // *----------------------------------------------------------------------------------*/ +// HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; // // AMRWB_IO_ENC_HANDLE hAmrwb_IO; /* AMR-WB IO encoder handle */ // @@ -2850,6 +2903,10 @@ typedef struct context_rc_mem_struct int16_t rateFlag; int16_t lastnz; int16_t nt_half; +#ifdef IVAS_FLOAT_FIXED + Word32 bit_estimate_fx; + Word16 bit_estimate_e; +#endif } RC_CONTEXT_MEM, *HANDLE_RC_CONTEXT_MEM; diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index b72ddf02fc7ab041b69a14d46fa1de3a2decb1c2..809f4e5b36359234c5c2e6b69e177474a796050b 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -8,8 +8,7 @@ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*======================================================================*/ diff --git a/lib_enc/subband_fft_fx.c b/lib_enc/subband_fft_fx.c index cee91f7ab086b0faf126dcb9ff866b94f1c9f410..83a1b41dd1dc30fe79f5b36f00f8f584d2ead612 100644 --- a/lib_enc/subband_fft_fx.c +++ b/lib_enc/subband_fft_fx.c @@ -9,8 +9,7 @@ #include "vad_basop.h" //#include "prot_fx.h" #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* @@ -126,7 +125,7 @@ static void passf4_1_16( ch[i + 4] = C_multr( c2, wa1[i] ); ch[i + 8] = C_multr( c3, wa2[i] ); ch[i + 12] = C_multr( c4, wa3[i] ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 4; #endif } @@ -158,7 +157,7 @@ static void passf4_2_16( ch[k + 8] = C_sub( t2, t3 ); ch[k + 4] = C_add( t1, t4 ); ch[k + 12] = C_sub( t1, t4 ); -#if ( WMOPS ) +#ifdef WMOPS multiCounter[currCounter].CL_move += 4; #endif } diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 02e122321d1af0e926ac7440b242638705a54013..9cd165b8db21f58a9572f39abbd1b453ad002e4f 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -10,8 +10,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 006a6195b2543e296b5b816b14daa4a4cbc6f686..094ad37fa96e5d3e5371e3b7e55ff76d6cd87dc2 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 10df60015950a6a8b85db39512e3612c36e36d94..8cca1104c572060dae448b4996216403573ede4d 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -32,8 +32,7 @@ #include #include "options.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" #include "enh32.h" diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 91dc8beeac03e6398b7dfe321b1b3e868689827a..3336ee3362dfa27b9e8a1d2e4dbbea7af16ea496 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -44,6 +44,10 @@ #include "wmc_auto.h" #include "ivas_prot.h" #include "ivas_rom_enc.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* * Local constants @@ -270,6 +274,550 @@ void wb_pre_proc( * - Common SWB TBE and SWB BWE pre-processing *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*full implementation pending*/ +void swb_pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + float *new_swb_speech, /* o : original input signal at 32kHz */ + Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz */ + float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer */ + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +) +{ + int16_t Sample_Delay_SWB_BWE, inner_frame, delay; + TD_BWE_ENC_HANDLE hBWE_TD; + FD_BWE_ENC_HANDLE hBWE_FD; + int32_t inner_Fs, input_Fs; + float old_input[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; + Word32 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart + float spchTmp[L_FRAME32k], spchTmp2[L_FRAME32k]; + int16_t i, j, L_resamp; + int16_t startB, endB; + float *realBufferFlipped[CLDFB_NO_COL_MAX]; + float *imagBufferFlipped[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][20]; + float imagBufferTmp[CLDFB_NO_COL_MAX][20]; + int16_t ts, nB, uB; + float sign, lbEner, v, t, regression; + const float *thr, *regV; + int16_t Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k; + + lMemRecalc32k = NS2SA( 32000, L_MEM_RECALC_NS ); + + /* initialization */ + hBWE_TD = st->hBWE_TD; + hBWE_FD = st->hBWE_FD; + input_Fs = st->input_Fs; + + for ( j = 0; j < CLDFB_NO_COL_MAX; j++ ) + { + set_f( realBufferTmp[j], 0, 20 ); + set_f( imagBufferTmp[j], 0, 20 ); + realBufferFlipped[j] = realBufferTmp[j]; + imagBufferFlipped[j] = imagBufferTmp[j]; + } + + set_f( old_input, 0.0f, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); + + if ( input_Fs == 32000 ) + { + if ( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS ); + if ( st->L_frame == L_FRAME16k ) + { + Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS ); + } + + mvr2r( st->input - Sample_Delay_SWB_BWE, hBWE_FD->old_input, Sample_Delay_SWB_BWE ); + mvr2r( st->input - L_FRAME32k, hBWE_FD->old_fdbwe_speech, L_FRAME32k ); + + if ( st->element_mode == IVAS_CPE_TD && st->bwidth >= SWB ) + { + mvr2r( st->input - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->old_wtda_swb + L_FRAME32k - ( hCPE->hStereoTCA->lMemRecalc - Sample_Delay_SWB_BWE ), hCPE->hStereoTCA->lMemRecalc - Sample_Delay_SWB_BWE ); + } + else if ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB ) + { + mvr2r( st->input - hCPE->hStereoDft->dft_ovl, hBWE_FD->old_wtda_swb + L_FRAME32k - ( hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ), hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); + } + } + + mvr2r( st->input, new_swb_speech, L_FRAME32k ); + + if ( st->last_extl != SWB_BWE && st->last_extl != FB_BWE && st->extl != SWB_BWE_HIGHRATE ) + { + Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + if ( st->element_mode > EVS_MONO && st->L_frame == L_FRAME16k ) + { + Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + } + if ( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE -= NS2SA( 32000, DELAY_FIR_RESAMPL_NS ); + } + + mvr2r( hBWE_FD->old_fdbwe_speech, &old_input[Sample_Delay_SWB_BWE], L_FRAME32k ); + + set_f( old_input, 0, Sample_Delay_SWB_BWE ); + mvr2r( hBWE_FD->old_fdbwe_speech + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input, Sample_Delay_SWB_BWE ); + if ( st->extl != WB_BWE ) + { + mvr2r( old_input, hBWE_FD->old_wtda_swb, L_FRAME32k ); + } + } + + if ( st->extl != SWB_BWE && st->extl != FB_BWE ) + { + mvr2r( st->input, hBWE_FD->old_fdbwe_speech, L_FRAME32k ); + } + } + else /* 48 kHz */ + { + + Sample_Delay_SWB_BWE32k = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS ); + Sample_Delay_SWB_BWE = NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS ); + if ( st->L_frame == L_FRAME16k ) + { + Sample_Delay_SWB_BWE32k = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS ); + Sample_Delay_SWB_BWE = NS2SA( 48000, DELAY_FD_BWE_ENC_16k_NS ); + } + + dft_ovl32k = 0; + if ( st->element_mode == IVAS_CPE_DFT ) + { + dft_ovl32k = (int16_t) ( STEREO_DFT_OVL_MAX * 32000 / 48000 ); + } + + if ( st->codec_mode == MODE1 ) + { + if ( st->element_mode > EVS_MONO ) + { + + if ( st->element_mode == IVAS_CPE_TD ) + { + } + else if ( st->bwidth == FB ) + { + mvr2r( st->input - Sample_Delay_SWB_BWE, hBWE_FD->old_input, Sample_Delay_SWB_BWE ); + } + + mvr2r( st->input - L_FRAME48k, hBWE_FD->old_fdbwe_speech, L_FRAME48k ); + + if ( st->element_mode == IVAS_CPE_TD && st->bwidth >= SWB ) + { + if ( st->bwidth == SWB ) + { + /* buffers hBWE_FD->old_input[] and hBWE_FD->old_wtda_swb[] need to be at 32 kHz (inner) sampling rate */ + + decimate_2_over_3_allpass( st->input - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, spchTmp, hBWE_TD->dec_2_over_3_mem, hBWE_TD->dec_2_over_3_mem_lp ); + + mvr2r( spchTmp, hBWE_FD->old_wtda_swb + L_FRAME32k - ( lMemRecalc32k - Sample_Delay_SWB_BWE32k ), lMemRecalc32k - Sample_Delay_SWB_BWE32k ); + mvr2r( spchTmp + lMemRecalc32k - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input, Sample_Delay_SWB_BWE32k ); + } + else /* FB_BWE */ + { + mvr2r( st->input - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->old_wtda_swb + L_FRAME48k - ( hCPE->hStereoTCA->lMemRecalc - Sample_Delay_SWB_BWE ), hCPE->hStereoTCA->lMemRecalc - Sample_Delay_SWB_BWE ); + mvr2r( st->input - Sample_Delay_SWB_BWE, hBWE_FD->old_input, Sample_Delay_SWB_BWE ); + } + } + else if ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB ) + { + if ( st->bwidth == SWB ) + { + lerp_flt( st->input - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); + + mvr2r( spchTmp, hBWE_FD->old_wtda_swb + L_FRAME32k - ( dft_ovl32k - Sample_Delay_SWB_BWE32k ), dft_ovl32k - Sample_Delay_SWB_BWE32k ); + } + else + { + mvr2r( st->input - hCPE->hStereoDft->dft_ovl, hBWE_FD->old_wtda_swb + L_FRAME48k - ( hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ), hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ); + } + } + } + + if ( ( st->extl != SWB_BWE && st->extl != FB_BWE && st->core == ACELP_CORE ) || ( st->element_mode == IVAS_CPE_DFT && st->core != ACELP_CORE ) /*resampling not needed for MDCT cores*/ ) + { + /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ + mvr2r( st->input, hBWE_FD->old_fdbwe_speech, L_FRAME48k ); + } + else + { + if ( st->last_extl != SWB_BWE && st->last_extl != FB_BWE ) + { + /* resample 48 kHz to 32kHz */ + if ( st->last_bwidth == FB ) + { + inner_frame = L_FRAME48k; + inner_Fs = 48000; + mvr2r( hBWE_FD->old_fdbwe_speech, new_swb_speech, L_FRAME48k ); + } + else + { + inner_frame = L_FRAME32k; + inner_Fs = 32000; + + if ( st->element_mode != IVAS_CPE_DFT ) + { + decimate_2_over_3_allpass( hBWE_FD->old_fdbwe_speech, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem, hBWE_TD->dec_2_over_3_mem_lp ); + } + else + { + lerp_flt( hBWE_FD->old_fdbwe_speech, new_swb_speech, inner_frame, L_FRAME48k ); + } + + if ( st->element_mode == IVAS_CPE_DFT && st->idchan == 0 ) + { + for ( i = 0; i < STEREO_DFT_OVL_32k; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_32k[i] = new_swb_speech[inner_frame - STEREO_DFT_OVL_32k + i] * hCPE->hStereoDft->win_32k[STEREO_DFT_OVL_32k - 1 - i]; + } + } + } + + Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + if ( st->element_mode > EVS_MONO && st->L_frame == L_FRAME16k ) + { + Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + } + if ( st->element_mode > EVS_MONO ) + { + Sample_Delay_SWB_BWE -= NS2SA( inner_Fs, DELAY_FIR_RESAMPL_NS ); + } + + mvr2r( new_swb_speech, &old_input[Sample_Delay_SWB_BWE], inner_frame ); + set_f( old_input, 0, Sample_Delay_SWB_BWE ); + mvr2r( new_swb_speech + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input, Sample_Delay_SWB_BWE ); + mvr2r( old_input, hBWE_FD->old_wtda_swb, inner_frame ); + } + + /* resample 48 kHz to 32kHz */ + if ( st->bwidth == FB ) + { + mvr2r( st->input, new_swb_speech, L_FRAME48k ); + } + else + { + if ( st->element_mode == IVAS_CPE_TD ) + { + float dec_2_over_3_mem_tmp[L_FILT_2OVER3], dec_2_over_3_mem_lp_tmp[L_FILT_2OVER3_LP]; + + decimate_2_over_3_allpass( st->input, L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, new_swb_speech, hBWE_TD->dec_2_over_3_mem, hBWE_TD->dec_2_over_3_mem_lp ); + + mvr2r( hBWE_TD->dec_2_over_3_mem, dec_2_over_3_mem_tmp, L_FILT_2OVER3 ); + mvr2r( hBWE_TD->dec_2_over_3_mem_lp, dec_2_over_3_mem_lp_tmp, L_FILT_2OVER3_LP ); + + decimate_2_over_3_allpass( st->input + L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, new_swb_speech + L_FRAME32k - lMemRecalc32k, dec_2_over_3_mem_tmp, dec_2_over_3_mem_lp_tmp ); + } + else if ( st->element_mode != IVAS_CPE_DFT ) + { + decimate_2_over_3_allpass( st->input, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem, hBWE_TD->dec_2_over_3_mem_lp ); + } + else /* IVAS_CPE_DFT */ + { + /*flt2fix*/ + f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); + f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); + f2me( hCPE->hStereoDft->icbweRefEner, &hCPE->hStereoDft->icbweRefEner_fx, &hCPE->hStereoDft->icbweRefEner_fx_e ); + f2me( hCPE->hStereoDft->lbEner, &hCPE->hStereoDft->lbEner_fx, &hCPE->hStereoDft->lbEner_fx_e ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k, hCPE->hStereoDft->output_mem_dmx_16k_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb, hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_32k, hCPE->hStereoDft->output_mem_dmx_32k_fx, 16, STEREO_DFT_OVL_32k ); + /*flt2fix end*/ + + Word16 out_start_ind, out_end_ind; + stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); + + /*fix2flt*/ + hCPE->hStereoDft->icbweRefEner = me2f( hCPE->hStereoDft->icbweRefEner_fx, hCPE->hStereoDft->icbweRefEner_fx_e ); + hCPE->hStereoDft->lbEner = me2f( hCPE->hStereoDft->lbEner_fx, hCPE->hStereoDft->lbEner_fx_e ); + fixedToFloat_arrL( new_swb_speech_fx + out_start_ind, new_swb_speech + out_start_ind, 16, out_end_ind - out_start_ind ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_fx, hCPE->hStereoDft->output_mem_dmx_16k, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, hCPE->hStereoDft->output_mem_dmx_16k_shb, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_32k_fx, hCPE->hStereoDft->output_mem_dmx_32k, 16, STEREO_DFT_OVL_32k ); + /*fix2flt end*/ + + mvr2r( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input, Sample_Delay_SWB_BWE32k ); + } + } + } + } + else + { + /* resample 48 kHz to 32kHz */ + if ( st->bwidth == FB ) + { + mvr2r( st->input, new_swb_speech, L_FRAME48k ); + } + else + { + decimate_2_over_3_allpass( st->input, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem, hBWE_TD->dec_2_over_3_mem_lp ); + } + } + } + + if ( ( st->core == ACELP_CORE && st->extl != SWB_BWE_HIGHRATE && st->extl != FB_BWE_HIGHRATE ) || + ( ( st->total_brate == ACELP_9k60 || st->rf_mode ) && st->bwidth == SWB && st->element_mode == EVS_MONO ) ) + { + float CldfbHB = 0; + Word32 CldfbHB_fx = 0; // fixed counterpart + Word16 CldfbHB_fx_e = 0; // fixed counterpart + + if ( st->element_mode == IVAS_CPE_DFT ) + { + + /*flt2fix*/ + f2me_buf( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], &hCPE->hStereoDft->DFT_fx_e[0], STEREO_DFT_N_MAX_ENC ); + f2me_buf( hCPE->hStereoDft->DFT[1], hCPE->hStereoDft->DFT_fx[1], &hCPE->hStereoDft->DFT_fx_e[1], STEREO_DFT_N_MAX_ENC ); + f2me( hCPE->hStereoDft->icbweRefEner, &hCPE->hStereoDft->icbweRefEner_fx, &hCPE->hStereoDft->icbweRefEner_fx_e ); + f2me( hCPE->hStereoDft->lbEner, &hCPE->hStereoDft->lbEner_fx, &hCPE->hStereoDft->lbEner_fx_e ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_res_8k, hCPE->hStereoDft->output_mem_res_8k_fx, 16, STEREO_DFT_OVL_8k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_fx, 16, STEREO_DFT_OVL_MAX ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_12k8, hCPE->hStereoDft->output_mem_dmx_12k8_fx, 16, STEREO_DFT_OVL_12k8 ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k, hCPE->hStereoDft->output_mem_dmx_16k_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb, hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, 16, STEREO_DFT_OVL_16k ); + floatToFixed_arrL( hCPE->hStereoDft->output_mem_dmx_32k, hCPE->hStereoDft->output_mem_dmx_32k_fx, 16, STEREO_DFT_OVL_32k ); + /*flt2fix end*/ + + Word16 out_start_ind, out_end_ind; + CldfbHB_fx = stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_input_fx + STEREO_DFT_OVL_16k, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 16000, st->L_frame, &CldfbHB_fx_e ); + + /*fix2flt*/ + CldfbHB = me2f( CldfbHB_fx, CldfbHB_fx_e ); + hCPE->hStereoDft->icbweRefEner = me2f( hCPE->hStereoDft->icbweRefEner_fx, hCPE->hStereoDft->icbweRefEner_fx_e ); + hCPE->hStereoDft->lbEner = me2f( hCPE->hStereoDft->lbEner_fx, hCPE->hStereoDft->lbEner_fx_e ); + fixedToFloat_arrL( old_input_fx + STEREO_DFT_OVL_16k + out_start_ind, old_input + STEREO_DFT_OVL_16k + out_start_ind, 16, out_end_ind - out_start_ind ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_res_8k_fx, hCPE->hStereoDft->output_mem_res_8k, 16, STEREO_DFT_OVL_8k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_fx, hCPE->hStereoDft->output_mem_dmx, 16, STEREO_DFT_OVL_MAX ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_12k8_fx, hCPE->hStereoDft->output_mem_dmx_12k8, 16, STEREO_DFT_OVL_12k8 ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_fx, hCPE->hStereoDft->output_mem_dmx_16k, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_16k_shb_fx, hCPE->hStereoDft->output_mem_dmx_16k_shb, 16, STEREO_DFT_OVL_16k ); + fixedToFloat_arrL( hCPE->hStereoDft->output_mem_dmx_32k_fx, hCPE->hStereoDft->output_mem_dmx_32k, 16, STEREO_DFT_OVL_32k ); + /*fix2flt end*/ + + /* delay corresponding to CLDFB delay */ + mvr2r( old_input + STEREO_DFT_OVL_16k - 20, shb_speech, L_FRAME16k ); + mvr2r( old_input, hBWE_TD->old_speech_shb + L_LOOK_16k + L_SUBFR16k - ( STEREO_DFT_OVL_16k - 20 ), STEREO_DFT_OVL_16k - 20 ); + mvr2r( old_input, hCPE->hStereoICBWE->mem_shb_speech_ref, STEREO_DFT_OVL_16k - 20 ); + + if ( CldfbHB <= 0 ) + { + CldfbHB = 1.0f; + } + hBWE_TD->cldfbHBLT_flt = 0.9f * hBWE_TD->cldfbHBLT_flt + 0.1f * ( 0.221462f /*=1/log10(32768)*/ * ( log10f( CldfbHB ) - 1.0f ) ); + + lbEner = 0.05f * (float) sqrt( hCPE->hStereoDft->lbEner ); + hCPE->hStereoICBWE->icbweRefEner = 0.05f * (float) sqrt( hCPE->hStereoDft->icbweRefEner ); + lbEner = 0.05f * (float) sqrt( hCPE->hStereoDft->lbEner ); + thr = icbwe_thr_DFT; + regV = icbwe_regressionValuesDFT; + } + else + { + if ( st->L_frame == L_FRAME ) + { + startB = 34; + endB = 14; + for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + for ( nB = startB, uB = 0; nB > endB; nB--, uB++ ) + { + sign = ( ts % 2 ) ? 1.0f : -1.0f; + realBufferFlipped[ts][uB] = -sign * realBuffer[ts][nB]; + imagBufferFlipped[ts][uB] = sign * imagBuffer[ts][nB]; + } + } + } + else + { + startB = 39; + endB = 19; + for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + for ( nB = startB, uB = 0; nB > endB; nB--, uB++ ) + { + realBufferFlipped[ts][uB] = -realBuffer[ts][nB]; + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + } + } + } + + for ( nB = 0; nB < 10; nB++ ) + { + for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + CldfbHB += ( realBufferFlipped[ts][nB] * realBufferFlipped[ts][nB] + imagBufferFlipped[ts][nB] * imagBufferFlipped[ts][nB] ); + } + } + if ( CldfbHB <= 0 ) + { + CldfbHB = 1.0f; + } + hBWE_TD->cldfbHBLT_flt = 0.9f * hBWE_TD->cldfbHBLT_flt + 0.1f * ( 0.221462f /*=1/log10(32768)*/ * ( log10f( CldfbHB ) - 1.0f ) ); + + if ( st->element_mode >= IVAS_CPE_DFT && hCPE->hStereoICBWE != NULL ) + { + hCPE->hStereoICBWE->icbweRefEner = EPSILON; + for ( nB = 20; nB < 40; nB++ ) + { + for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + hCPE->hStereoICBWE->icbweRefEner += ( realBuffer[ts][nB] * realBuffer[ts][nB] + imagBuffer[ts][nB] * imagBuffer[ts][nB] ); + } + } + hCPE->hStereoICBWE->icbweRefEner = 0.05f * sqrtf( hCPE->hStereoICBWE->icbweRefEner ); + } + + lbEner = EPSILON; + for ( nB = 0; nB < 20; nB++ ) + { + for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + lbEner += ( realBuffer[ts][nB] * realBuffer[ts][nB] + imagBuffer[ts][nB] * imagBuffer[ts][nB] ); + } + } + lbEner = 0.05f * sqrtf( lbEner ); + thr = icbwe_thr_TDM; + regV = icbwe_regressionValuesTDM; + + cldfbSynthesis_ivas( realBufferFlipped, imagBufferFlipped, shb_speech, -1, st->cldfbSynTd ); + } + + if ( st->element_mode >= IVAS_CPE_DFT && hCPE->hStereoICBWE != NULL ) + { + hCPE->hStereoICBWE->MSFlag = 0; /* Init the multi-source flag */ + v = 0.3333f * sum_f( st->voicing, 3 ); + t = log10f( ( hCPE->hStereoICBWE->icbweRefEner + 1e-6f ) / ( lbEner + 1e-6f ) ); + + /* Three Level Decision Tree to calculate a regression value first */ + if ( t < thr[0] ) /* level 1 */ + { + if ( t < thr[1] ) /* level 2 */ + { + regression = ( v < thr[3] ) ? regV[0] : regV[1]; /* level 3 */ + } + else + { + regression = ( v < thr[4] ) ? regV[2] : regV[3]; /* level 3 */ + } + } + else + { + if ( t < thr[2] ) /* level 2 */ + { + regression = ( v < thr[5] ) ? regV[4] : regV[5]; /* level 3 */ + } + else + { + regression = ( v < thr[6] ) ? regV[6] : regV[7]; /* level 3 */ + } + } + + /* Convert the regression to a hard decision (classification) */ + if ( regression > 0.79f && !( st->bwidth < SWB || hCPE->hCoreCoder[0]->vad_flag == 0 ) ) + { + hCPE->hStereoICBWE->MSFlag = 1; + } + } + + if ( st->extl != WB_TBE && st->extl != SWB_TBE && st->extl != FB_TBE ) + { + /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ + delay = L_LOOK_16k + L_SUBFR16k; + mvr2r( shb_speech + L_FRAME16k - delay, hBWE_TD->old_speech_shb, delay ); + } + } + else + { + if ( ( st->bwidth == FB || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) ) + { + InitSWBencBufferStates( st->hBWE_TD, shb_speech ); + } + else + { + if ( st->element_mode == IVAS_CPE_DFT ) + { + if ( st->L_frame == L_FRAME ) + { + L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz SHB target. 20 ms is 560 samples in 28 kHz sample rate */ + } + else + { + L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz SHB target. 20 ms is 620 samples in 31 kHz sample rate */ + } + + /* Dirty downsampling to match Nyquist to upper frequency limit of target */ + lerp_flt( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) ); + + /* flip the spectrum */ + mvr2r( new_swb_speech, spchTmp, L_resamp ); + for ( i = 0; i < L_resamp; i = i + 2 ) + { + spchTmp[i] = -spchTmp[i]; + } + + /* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/ + lerp_flt( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); + mvr2r( spchTmp2, spchTmp, L_FRAME32k ); + } + else + { + /* flip the spectrum */ + mvr2r( new_swb_speech, spchTmp, L_FRAME32k ); + + for ( i = 0; i < L_FRAME32k; i = i + 2 ) + { + spchTmp[i] = -spchTmp[i]; + } + } + + Decimate_allpass_steep( spchTmp, hBWE_TD->state_ana_filt_shb, L_FRAME32k, shb_speech ); + + mvr2r( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); + + /*Compute the past overlap for potential next iDFTs SHB*/ + if ( st->element_mode == IVAS_CPE_DFT ) + { + for ( i = 0; i < STEREO_DFT_OVL_16k; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_16k_shb[i] = shb_speech[20 + i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i]; + } + } + } + + if ( st->element_mode != IVAS_CPE_DFT ) + { + /* Reset CLDFB synthesis buffer */ + set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length ); + } + else + { + hCPE->hStereoDft->flip_sign = -hCPE->hStereoDft->flip_sign; /* Make sure sign is updated even if DFT SHB target is not generated */ + } + } + + /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ + /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed; + only when n = 1 start, it will be 9.6875/2.3125 in that case this reset is needed for IO->BWE.*/ + if ( st->last_extl == -1 && st->element_mode == EVS_MONO ) + { + delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); + for ( i = 0; i < delay; i++ ) + { + shb_speech[i] = (float) i * ( 0.03f * shb_speech[2 * delay - 1 - i] ); + } + } + + return; +} +#endif void swb_pre_proc( Encoder_State *st, /* i/o: encoder state structure */ float *new_swb_speech, /* o : original input signal at 32kHz */ diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 1bcef70256c0e8f56de117edc150151e0a298dd7..dbd41484e6713567f3b4b55e0652eb40a0b88da8 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stl.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" @@ -76,7 +75,7 @@ void wb_pre_proc_fx( move16(); } - set16_fx( old_input, 0, NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k ); + set16_fx( old_input, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k ); max_wb = 1; move16(); @@ -154,7 +153,7 @@ void wb_pre_proc_fx( test(); IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && LE_32( st_fx->total_brate, ACELP_8k00 ) ) ) && !hSC_VBR->ppp_mode ) { - Sample_Delay_WB_BWE = NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); + Sample_Delay_WB_BWE = NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k ); Copy( hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); @@ -233,7 +232,7 @@ void swb_pre_proc_fx( imagBufferFlipped[j] = imagBufferTmp[j]; } - set16_fx( old_input_fx, 0, NS2SA_fx2( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); + set16_fx( old_input_fx, 0, NS2SA_FX2( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k ); IF( EQ_32( st_fx->input_Fs, 32000 ) ) { @@ -242,7 +241,7 @@ void swb_pre_proc_fx( test(); IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) ) { - Sample_Delay_SWB_BWE = NS2SA_fx2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_SWB_BWE = NS2SA_FX2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); @@ -291,7 +290,7 @@ void swb_pre_proc_fx( decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx ); } - Sample_Delay_SWB_BWE = NS2SA_fx2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); Copy( new_swb_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); Copy( new_swb_speech_fx + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 943fe458b7728b532aea57f89da8119b1c2bc509..608d96d19f29249204e40279c78dd15418fc1076 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -373,6 +373,15 @@ void wb_tbe_enc( prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD / 4 ); curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD / 4, L_SHB_LAHEAD / 4 ); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + if ( st->element_mode > EVS_MONO ) + { + /* prevent too low values of energy */ + prev_pow = max( 0.00001f, prev_pow ); + curr_pow = max( 0.00001f, curr_pow ); + } +#endif + if ( voice_factors[0] > 0.75f ) { curr_pow = (float) ( curr_pow * 0.25 ); @@ -1050,6 +1059,15 @@ void swb_tbe_enc( prev_pow = sum2_f( shaped_shb_excitation, L_SHB_LAHEAD + 10 ); curr_pow = sum2_f( shaped_shb_excitation + L_SHB_LAHEAD + 10, L_SHB_LAHEAD + 10 ); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + if ( st->element_mode > EVS_MONO ) + { + /* prevent too low values of energy */ + prev_pow = max( 0.00001f, prev_pow ); + curr_pow = max( 0.00001f, curr_pow ); + } +#endif + if ( voice_factors[0] > 0.75f ) { curr_pow = (float) ( curr_pow * 0.25 ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index b4e93c1d32596cd3f267bc3637ed692bb3c1c060..5eb1d275a4b05b4d40890ae75a8ad1c104d1cf3a 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -9,8 +9,7 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stl.h" @@ -844,7 +843,18 @@ void wb_tbe_enc_fx( } prev_pow = 0; - move16(); + move32(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#else + prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ @@ -872,6 +882,17 @@ void wb_tbe_enc_fx( curr_pow = 0; move16(); +#ifdef NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE + IF( st_fx->element_mode > EVS_MONO ) + { + tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); +#ifdef BASOP_NOGLOB + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ +#else + curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ +#endif + } +#endif FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index 6de4560d5f3e01fdf0e881afc5e2b05c01275244..29ea322b603be69b72ca8543d2d6b0ae7f0bb39e 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -8,8 +8,7 @@ //#include "prot_fx.h" #include "rom_com.h" #include "ivas_error.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ ivas_error tcq_core_LR_enc_fx( diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index f44fcd20373d2f3576f2f9b622b07d2f3c61f303..32e44d84ad3f7ece511bd302c3113f4fec47200d 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -10,8 +10,7 @@ #include "basop_util.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ static Word32 dot( const Word16 *X, const Word16 *Y, Word16 n ) diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index 6b95cae29ce39d13d1779517be9e93e8a8444291..50690669b1a794f2a3b8f9e989c64ff533dded9d 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -39,6 +39,8 @@ #include "options.h" #include #include "prot.h" +#include "prot_fx.h" +#include "prot_fx_enc.h" #include "rom_com.h" #include "cnst.h" #include "wmc_auto.h" @@ -55,7 +57,7 @@ void ComputeSpectrumNoiseMeasure( const int16_t L_frame, const int16_t startLine, const int16_t resetMemory, - int16_t *noiseFlags, + int8_t *noiseFlags, const int16_t lowpassLine ) { int16_t i, lastTone; @@ -565,12 +567,12 @@ float SQ_gain_estimate( *---------------------------------------------------------------------*/ void tcx_scalar_quantization( - float *x, /* i : input coefficients */ - int16_t *xq, /* o : quantized coefficients */ - const int16_t L_frame, /* i : frame length */ - const float gain, /* i : quantization gain */ - const float offset, /* i : rounding offset (deadzone) */ - int16_t *memQuantZeros, /* o : coefficients set to 0 */ + float *x, /* i : input coefficients */ + int16_t *xq, /* o : quantized coefficients */ + const int16_t L_frame, /* i : frame length */ + const float gain, /* i : quantization gain */ + const float offset, /* i : rounding offset (deadzone) */ + int8_t *memQuantZeros, /* o : coefficients set to 0 */ const int16_t tcxonly ) { int16_t i; @@ -614,6 +616,87 @@ void tcx_scalar_quantization( return; } +#ifdef IVAS_FLOAT_FIXED +void tcx_scalar_quantization_ivas_fx( + Word32 *x, + /* i: input coefficients */ // x_e + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, + /* i: quantization gain */ // gain_e + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ + const Word16 alfe_flag ) +{ + Word16 i, tmp16, s; + Word32 tmp32, offs32; + + + /* common exponent for x and gain for comparison */ + tmp16 = sub( gain_e, x_e ); + tmp32 = L_shl( L_deposit_h( gain ), s_max( -31, s_min( tmp16, 0 ) ) ); + tmp16 = negate( s_max( tmp16, 0 ) ); + + i = sub( L_frame, 1 ); + IF( memQuantZeros_fx != NULL ) + { + test(); + WHILE( ( memQuantZeros_fx[i] != 0 ) && ( LT_32( L_abs( L_shl( x[i], tmp16 ) ), tmp32 ) ) ) + { + test(); + xq[i] = 0; + move16(); + i = sub( i, 1 ); + } + } + + /* invert gain */ + gain = Inv16( gain, &gain_e ); + + s = sub( add( x_e, gain_e ), 15 ); + + /*It should almost never happen and if so the quantization will be discarded later on (saturation of gain Quantizer).*/ + IF( GT_16( s, 31 ) ) + { + /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ + gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ + gain_e = 2; + + s = sub( add( x_e, gain_e ), 15 ); + } + + /* substract 0x8000 to affect the mac_r in the following loop + so it acts like extract_h. the 0x4000 will be multiplied by 2 + by the mac_r to get to 0x8000 and disable the round. */ + offset = sub( offset, 0x4000 ); + + FOR( ; i >= 0; i-- ) + { + offs32 = Mpy_32_16_1( L_abs( x[i] ), gain ); /* multiply */ +#ifdef BASOP_NOGLOB + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat( offs32, offset, 1 ); /* add offset and truncate */ +#else + offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ +#endif + if ( x[i] < 0 ) + tmp16 = negate( tmp16 ); /* restore sign */ + + xq[i] = tmp16; + move16(); + } + + IF( alfe_flag == 0 ) + { + AdaptLowFreqEmph_fx( x, x_e, xq, gain, gain_e, + 0, NULL, NULL, + L_frame ); + } +} +#endif /*---------------------------------------------------------------------* * tcx_scalar_quantization_rateloop() @@ -627,7 +710,7 @@ int16_t tcx_scalar_quantization_rateloop( const int16_t L_frame, /* i : frame length */ float *gain, /* i/o: quantization gain */ float offset, /* i : rounding offset (deadzone) */ - int16_t *memQuantZeros, /* o : coefficients set to 0 */ + int8_t *memQuantZeros, /* o : coefficients set to 0 */ int16_t *lastnz_out, /* i/o: last nonzero coeff index */ const int16_t target, /* i : target number of bits */ int16_t *nEncoded, /* o : number of encoded coeff */ @@ -1500,6 +1583,176 @@ void ProcessIGF( * * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ProcessStereoIGF_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, + Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ + int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ +#if 1 + Word32 *pITFMDCTSpectrum_fx[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ + Word32 *pPowerSpectrum_fx[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ +#endif + float *pITFMDCTSpectrum[CPE_CHANNELS][NB_DIV], /* i : MDCT spectrum fir ITF */ + float *pPowerSpectrum[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ + float *pPowerSpectrumMsInv[CPE_CHANNELS][NB_DIV], /* i : inverse power spectrum */ + float *inv_spectrum[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ + const int16_t frameno, /* i : flag indicating index of current subfr. */ + const int16_t sp_aud_decision0, /* i : sp_aud_decision0 */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ +) +{ + UNUSED_PARAM( pITFMDCTSpectrum_fx ); + int16_t ch, igfGridIdx, isIndepFlag, bsBits, pBsStart, curr_order; + float predictionGain; + float A[ITF_MAX_FILTER_ORDER + 1]; + IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS]; + BSTR_ENC_HANDLE hBstr; + + hIGFEnc[0] = sts[0]->hIGFEnc; + hIGFEnc[1] = sts[1]->hIGFEnc; + + isIndepFlag = 1; + + if ( sts[0]->last_core == ACELP_CORE && sts[0]->core == TCX_20_CORE ) + { + igfGridIdx = IGF_GRID_LB_TRAN; + } + else if ( sts[0]->core == TCX_20_CORE ) + { + igfGridIdx = IGF_GRID_LB_NORM; + } + else + { + /* It is short block */ + igfGridIdx = IGF_GRID_LB_SHORT; + if ( frameno == 1 ) + { + isIndepFlag = 0; + } + } + + IGFSaveSpectrumForITF( hIGFEnc[0], igfGridIdx, pITFMDCTSpectrum[0][frameno] ); + + IGFSaveSpectrumForITF( hIGFEnc[1], igfGridIdx, pITFMDCTSpectrum[1][frameno] ); + +#if 1 /*************************************flt to fix conversion****************************************************/ + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 *swb_offset; + hPrivateData = &hIGFEnc[ch]->igfData; + hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; + swb_offset = hGrid->swb_offset; + sts[ch]->hTcxEnc->spectrum_e[frameno] = 31 - Q_factor_arrL( sts[ch]->hTcxEnc->spectrum[frameno], hGrid->infoGranuleLen ); + sts[ch]->hTcxEnc->spectrum_e[frameno] = s_max( sts[ch]->hTcxEnc->spectrum_e[frameno], 31 - Q_factor_arrL( &pPowerSpectrum[ch][0], hGrid->infoGranuleLen ) ); + sts[ch]->hTcxEnc->spectrum_e[frameno] = s_max( sts[ch]->hTcxEnc->spectrum_e[frameno], 31 - Q_factor_arrL( inv_spectrum[ch][frameno], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ) ); + sts[ch]->hTcxEnc->spectrum_e[frameno] = s_max( sts[ch]->hTcxEnc->spectrum_e[frameno], 31 - Q_factor_arrL( pPowerSpectrumMsInv[ch][0], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ) ); + floatToFixed_arr32( sts[ch]->hTcxEnc->spectrum[frameno], sts[ch]->hTcxEnc->spectrum_fx[frameno], 31 - sts[ch]->hTcxEnc->spectrum_e[frameno], hGrid->infoGranuleLen ); + floatToFixed_arr32( &pPowerSpectrum[ch][0], &pPowerSpectrum_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[frameno], hGrid->infoGranuleLen ); + floatToFixed_arr32( inv_spectrum[ch][frameno], inv_spectrum_fx[ch][frameno], 31 - sts[ch]->hTcxEnc->spectrum_e[frameno], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); + floatToFixed_arr32( pPowerSpectrumMsInv[ch][0], pPowerSpectrumMsInv_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[frameno], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); + float max_sb = 0; + float max_tb = 0; + Word16 max_sb_fx = 0; + Word16 max_tb_fx = 0; + for ( Word16 sfb = 0; sfb < 23; sfb++ ) + { + f2me_16( hPrivateData->prevDampingFactor_IIR[sfb], &hPrivateData->prevDampingFactor_IIR_fx[sfb], &hPrivateData->prevDampingFactor_IIR_e[sfb] ); + max_tb = max( fabsf( hPrivateData->prevSFM_FIR_SFB_TB[sfb] ), max_tb ); + max_tb = max( fabsf( hPrivateData->prevSFM_IIR_SFB_TB[sfb] ), max_tb ); + max_tb = max( fabsf( hPrivateData->SFM_tb[sfb] ), max_tb ); + max_sb = max( fabsf( hPrivateData->SFM_sb[sfb] ), max_sb ); + max_sb = max( fabsf( hPrivateData->prevSFM_FIR_SFB_SB[sfb] ), max_sb ); + max_sb = max( fabsf( hPrivateData->prevSFM_IIR_SFB_SB[sfb] ), max_sb ); + f2me_16( max_tb, &max_tb_fx, &hPrivateData->sfb_tb_e[sfb] ); + f2me_16( max_sb, &max_sb_fx, &hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_TB[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_TB[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_SB[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_SB[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); + hPrivateData->SFM_tb_fx[sfb] = float_to_fix16( hPrivateData->SFM_tb[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); + hPrivateData->SFM_sb_fx[sfb] = float_to_fix16( hPrivateData->SFM_sb[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); + } + for ( int i = 0; i < IGF_MAX_TILES; i++ ) + { + hPrivateData->prevSFM_FIR[i] = float_to_fix( hPrivateData->prevSFM_FIR_flt[i], 16 ); /*15Q16*/ + hPrivateData->prevSFM_IIR[i] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[i], 13 ); /*2Q13*/ + for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) + { + hPrivateData->igfPastSFM_fx[i][j] = float_to_fix16( hPrivateData->igfPastSFM[i][j], 13 ); + } + } + floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); + } +#endif /**********************************flt to fix ends here*******************************************************/ + IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, inv_spectrum_fx, frameno, sp_aud_decision0, element_brate, mct_on ); +#if 1 /*************************************fix to flt conversion****************************************************/ + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + hPrivateData = &hIGFEnc[ch]->igfData; + hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; + me2f_buf( sts[ch]->hTcxEnc->spectrum_fx[frameno], sts[ch]->hTcxEnc->spectrum_e[frameno], sts[ch]->hTcxEnc->spectrum[frameno], hGrid->infoGranuleLen ); + me2f_buf( &pPowerSpectrum_fx[ch][0], sts[ch]->hTcxEnc->spectrum_e[frameno], &pPowerSpectrum[ch][0], hGrid->infoGranuleLen ); + for ( Word16 sfb = 0; sfb < 23; sfb++ ) + { + hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); + hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); + hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); + } + for ( int i = 0; i < IGF_MAX_TILES; i++ ) + { + hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ + hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ + for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) + { + hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); + } + } + } +#endif /**********************************fix to flt ends here*******************************************************/ + + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + curr_order = 0; + + ITF_Detect( hIGFEnc[ch]->spec_be_igf_flt, hIGFEnc[ch]->infoStartLine, hIGFEnc[ch]->infoStopLine, 8 /*maxOrder*/, A, &predictionGain, &curr_order ); + + hIGFEnc[ch]->flatteningTrigger = hIGFEnc[ch]->tns_predictionGain_flt < 1.15 && predictionGain < 1.15; + + hIGFEnc[ch]->infoTotalBitsPerFrameWritten = 0; + + if ( sts[ch]->core == TCX_20_CORE ) + { + IGFEncWriteBitstream( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); + } + else + { + hBstr = sts[ch]->hBstr; + pBsStart = hBstr->nb_ind_tot; + if ( ch > 0 ) + { + hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; + } + IGFEncWriteBitstream( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); + + bsBits = hBstr->nb_ind_tot - pBsStart; + IGFEncConcatenateBitstream( hIGFEnc[ch], bsBits, hBstr ); + } + } + + return; +} +#endif void ProcessStereoIGF( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 5b461cd5690aa41307bc3e133c6816d618c2dc1b..dc6dc6b7ed762ae7c291b0caa7da5235eaf37761 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -13,8 +13,7 @@ #include "rom_basop_util.h" #include "basop_util.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #define inv_int InvIntTable @@ -295,7 +294,7 @@ void AnalyzePowerSpectrum_fx( L_frameTCX, divide3216( L_mult( hTcxEnc->nmStartLine, L_frame ), st->L_frame ), tmp8, - hTcxEnc->memQuantZeros_fx, + hTcxEnc->memQuantZeros, lowpassLine ); IF( LE_32( st->total_brate, ACELP_24k40 ) ) @@ -1977,7 +1976,7 @@ void ProcessIGF_fx( bsBits = sub( hBstr->next_ind_fx, bsStart ); IF( !isTCX20 ) { - IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx ); + IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot, hBstr->ind_list ); } #else PMT( "New bit stream implementation to be checked" ) diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index aa633912c45a6f753ea7704e99509e12a9574350..cfb48aaeca8a479efd03489958158bead7ccedbb 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -7,8 +7,7 @@ #include "basop_util.h" #include "cnst.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 4cb7cefdde89c4b15d0ffdc654953fbdfb1153ad..b371381d580c27ab670e4f1bcc535f4144e5b018 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -13,8 +13,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "prot.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #define HLM_MIN_NRG ( 32768.0f * 2 * NORM_MDCT_FACTOR / ( 640 * 640 ) ) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 179e1150601a31d7141b9a4adeedf034cfc4a4a2..182f2acc5f7ad770889d4e37311e690dfb80dd47 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -12,8 +12,7 @@ #include #include #include -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /* Exponent of attack threshold. Picked according to current threshold values. */ @@ -570,10 +569,12 @@ static void RunTransientDetector( TransientDetector *pTransientDetector ) assert( ( pTransientDetector->CheckSubblocksForAttack_fx != NULL ) ); +#define WMC_TOOL_SKIP pTransientDetector->CheckSubblocksForAttack_fx( pSubblockNrg, pAccSubblockNrg, NSUBBLOCKS + nDelay, nRelativeDelay, attackRatioThreshold, &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex ); +#undef WMC_TOOL_SKIP } static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ) diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index 7afc32659bc8848af2511ae85fb407935e48d0db..c888269476595e5dc3aee07bad15b4a99f25a7c0 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -41,7 +41,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------* * Local function prototypes diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index bc81a23c6be616ff792b21f617cd1062cb233bee..3a9fabba0a0884684d229fee08b50f2e690f41d6 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -8,8 +8,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-----------------------------------------------------------------* @@ -106,14 +105,14 @@ void transition_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/ ) { - Copy( st_fx->pitch_fx, T_op, 2 ); + Copy( st_fx->pitch, T_op, 2 ); } ELSE /* L_frame == L_FRAME16k */ { /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ - T_op[0] = add( st_fx->pitch_fx[0], mult_r( st_fx->pitch_fx[0], 8192 /*0.25f Q15*/ ) ); - T_op[1] = add( st_fx->pitch_fx[1], mult_r( st_fx->pitch_fx[1], 8192 /*0.25f Q15*/ ) ); + T_op[0] = add( st_fx->pitch[0], mult_r( st_fx->pitch[0], 8192 /*0.25f Q15*/ ) ); + T_op[1] = add( st_fx->pitch[1], mult_r( st_fx->pitch[1], 8192 /*0.25f Q15*/ ) ); } shift_wsp = add( Q_new, shift ); @@ -210,7 +209,7 @@ void transition_enc_fx( { /* this is called only to compute unused bits */ config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } @@ -319,7 +318,7 @@ void transition_enc_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, *tc_subfr, 2, NULL, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index 935165d374b9f7ed8819fe3f2278c2df889f14bc..c161ac2563bbe1c976a7deccb8c1219d1b99374e 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -8,8 +8,7 @@ #include "basop_util.h" #include "vad_basop.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* * bg_music_decision_fx() diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index daa7d5d018d74c9cacf157017e14e94902fe2992..6a3202a1595650cd87d2d6cc049bafe6db557b4e 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -7,8 +7,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -191,7 +190,7 @@ void updt_IO_switch_enc_fx( /* Perform preemphasis of the old input signal @16kHz */ st->mem_preemph16k_fx = 0; move16(); - preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) ); + PREEMPH_FX( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new ); /* reset TD BWE buffers */ set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index 19d9cbb70daf867245d3f2d281a2d913d7c6f4c4..d62daff20038c9207323d924910626d50d587404 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -5,8 +5,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" //#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*----------------------------------------------------------------------------------* diff --git a/lib_enc/vad_basop_fx.c b/lib_enc/vad_basop_fx.c index 32f46ce169eb891d4673fc0acabd48bf6c824d42..f8f528c0e512c75cb9568d47512aae54374ed686 100644 --- a/lib_enc/vad_basop_fx.c +++ b/lib_enc/vad_basop_fx.c @@ -5,8 +5,7 @@ #include #include "options.h" //#include "prot_fx.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "vad_basop.h" #include "basop_util.h" diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 58c70edaec628df4004187c36803a175164b4228..d0356f518e67567e254099f52c41e7fad7ee3de4 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -6,8 +6,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "rom_enc.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -1685,6 +1684,1242 @@ Word16 wb_vad_fx( } + if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ + { + hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); + } + + hVAD->vad_prim_reg = L_shl( L_and( hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1 ); + + IF( st_fx->localVAD != 0 ) + { + hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); + } + + return flag; +} + +Word16 wb_vad_ivas_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, + Word8 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average */ + Word16 lp_noise_fx /* i : long term noise energy */ +) +{ + Word16 i, flag = 0, hangover_short; + + Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, nc = 0, th_clean = 0; + Word16 lp_snr; /* Q8 */ + const Word32 *pt1; + const Word32 *pt2; + const Word32 *pt3; + + Word16 min_snr, sign_thr; + + Word32 L_snr, L_snr_sum; + Word32 ftmp, ftmp1, ftmp2; + Word16 m_noise_local, e_noise, e_num, m_num, snr, snr_tmp, shift_snr; + + Word16 snr_sumt; + Word32 L_vad_thr; + Word16 hangover_hd; + Word16 snr_idx; + Word16 delta1, delta2, delta3, delta4; + + Word16 flag_he1; + Word16 stmp; + Word32 L_msnr, L_mssnr = 0, L_mssnr_hov; + Word16 j, tmp, tmp1, tmp2; + Word32 L_tmp, L_tmp1, L_tmp2; + + Word32 L_snr18, L_snr19; /* Q4 */ + Word32 L_msnr18, L_msnr19; /* Q13 */ + Word16 nb_sig_snr; /* Q0 */ + + Word16 nv; + Word16 nv_ofs; /* Q8 */ + Word32 L_snr_sum_HE_SAD; /* Q4 */ + Word16 snr_sum_HE_SAD; /*Q8 log */ + Word16 sign_thr_HE_SAD, min_snr_HE_SAD; + + + Word16 thr1_ol; + Word32 L_snr_sum_ol; + Word16 snr_sum_ol; /* Q8 log */ + + Word32 L_snr_outlier; + Word16 snr_outlier_index; + Word32 L_accum_ener_L; + Word32 L_accum_ener_H; + Word16 vad_bwidth_fx; + Word16 last_7k2_coder_type; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + if ( hNoiseEst == NULL ) + { + hNoiseEst = st_fx->hNoiseEst; + move16(); + } + + if ( hVAD == NULL ) + { + move16(); + hVAD = st_fx->hVAD; + } + if ( LT_16( lp_speech_fx, -100 * 256 ) ) + { + lp_speech_fx = st_fx->lp_speech_fx; + move16(); + } + + if ( LT_16( lp_noise_fx, -100 * 256 ) ) + { + lp_noise_fx = st_fx->lp_noise_fx; + move16(); + } + + vad_bwidth_fx = st_fx->input_bwidth; + move16(); + + L_snr_outlier = L_deposit_l( 0 ); + snr_outlier_index = 0; + move16(); + L_accum_ener_L = L_deposit_l( 0 ); + L_accum_ener_H = L_deposit_l( 0 ); + + L_snr18 = L_deposit_l( 0 ); /* Q4*/ + L_snr19 = L_deposit_l( 0 ); /* Q4 */ + L_msnr18 = L_deposit_l( 8192 ); /* 1.0 Q13*/ + L_msnr19 = L_deposit_l( 8192 ); /* 1.0 Q13 */ + + + IF( EQ_16( vad_bwidth_fx, NB ) ) + { + st_fx->min_band = 1; + move16(); + st_fx->max_band = 16; + move16(); + } + ELSE + { + st_fx->min_band = 0; + move16(); + st_fx->max_band = 19; + move16(); + } + + IF( st_fx->Opt_SC_VBR ) + { + last_7k2_coder_type = st_fx->hSC_VBR->last_7k2_coder_type; + move16(); + } + ELSE + { + last_7k2_coder_type = -1; + move16(); + } + /*---------------------------------------------------------------------* + * set SNR thresholds depending on the input bandwitdh + *---------------------------------------------------------------------*/ + IF( EQ_16( st_fx->max_band, 19 ) ) + /* WB input */ /* or SWB input */ + { + nk = 3277; + move16(); /*0.1 Q15 */ + nc = 4122; + move16(); /*16.1 Q8 */ + nv = 525; + move16(); /* 2.05 Q8*/ + nv_ofs = 422; + move16(); /* 1.65 Q8*/ + th_clean = TH16_2_FX; + move16(); /* 35 Q8 */ + sign_thr = 21; + move16(); /*1.3 Q4 */ + tmp = sub( vad_bwidth_fx, WB ); + if ( tmp != 0 ) + { + sign_thr = 28; + move16(); /*1.75f; Q4 SWB */ + } + min_snr = 13; + move16(); /*0.8 Q4 WB */ + if ( tmp != 0 ) + { + min_snr = 4; + move16(); /*0.25f; Q4 SWB */ + } + + sign_thr_HE_SAD = 40; + move16(); /* 2.5f Q4 */ + ; + min_snr_HE_SAD = 3; + move16(); /* 0.2f Q4 */ + ; + } + ELSE /* NB input */ + { + move16(); + nk = 3277; + move16(); /* 0.1 Q15 */ + nc = 4096; + move16(); /* 16.0 Q8 */ + nv = 1024; + move16(); /* 4.0 Q8 */ + nv_ofs = 294; + move16(); /*1.15 Q8*/ + th_clean = TH8_1_FX; + move16(); /*20 Q8 */ + sign_thr = 28; + move16(); /* 1.75 * Q4 SIGN_THR */ + min_snr = 4; + move16(); /* .25 *Q4 MIN_SNR */ + sign_thr_HE_SAD = 42; + move16(); /* 2.65f Q4 */ + ; + min_snr_HE_SAD = 1; + move16(); /* 0.05f Q4 */ + ; + } + + hangover_short = 0; + move16(); + + IF( st_fx->Opt_SC_VBR != 0 ) + { + *noisy_speech_HO = 0; + move16(); + *clean_speech_HO = 0; + move16(); + *NB_speech_HO = 0; + move16(); + } + + /*---------------------------------------------------------------------* + * compute SNR for each band & total + *---------------------------------------------------------------------*/ + + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8 */ + + snr_idx = 2; + move16(); + if ( GT_16( lp_snr, 4608 ) ) /*18.0 Q8*/ + { + snr_idx = 1; + move16(); + } + if ( GT_16( lp_snr, 6144 ) ) /*24.0 Q8*/ + { + snr_idx = 0; + move16(); + } + + + IF( snr_idx == 0 ) + { + stmp = 6; + move16(); + delta1 = 0; + move16(); /*0.0f in Q13 */ + delta2 = 0; + move16(); /*0.0f in Q13 */ + delta3 = 0; + move16(); /*0.0f in Q13 */ + delta4 = 0; + move16(); + + + /*vad_thr = 2.4f*lp_snr - 42.2f; + vad_thr = min(vad_thr, 80 ); */ + + L_vad_thr = -345702; + move32(); /* -42.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); + } + ELSE IF( EQ_16( snr_idx, 1 ) ) + { + stmp = 6; + move16(); + delta1 = 819; + move16(); /*0.1f in Q13 */ + delta2 = 1638; + move16(); /*0.2f in Q13 */ + delta3 = 1638; + move16(); /*0.2f in Q13 */ + delta4 = 1638; + move16(); /*0.2f in Q13 */ + + /* vad_thr = 2.4f*lp_snr - 40.2f; + vad_thr = min(vad_thr, 80); + */ + L_vad_thr = -329318; + move32(); /* -40.2 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 77, lp_snr ); /* (2.4)Q5*(lp_snr)Q8 */ + L_vad_thr = L_min( L_vad_thr, 80 * ( 1 << 13 ) ); + } + ELSE + { + stmp = 9; + move16(); + delta1 = 1638; + move16(); /*0.2f in Q13 */ + delta2 = 3277; + move16(); /*0.4f in Q13 */ + delta3 = 2458; + move16(); /*0.3f in Q13 */ + delta4 = 3277; + move16(); /*0.4f in Q13 */ + /* vad_thr = 2.5f*lp_snr - 10.0f; + vad_thr = max(vad_thr, 1); + */ + L_vad_thr = -81920; + move32(); /* -10 Q13*/ + L_vad_thr = L_mac0( L_vad_thr, 80, lp_snr ); /* (2.5)Q5*(lp_snr)Q8 */ + L_vad_thr = L_max( L_vad_thr, 1 * ( 1 << 13 ) ); + } + + nb_sig_snr = 20; + move16(); + + pt1 = fr_bands; + pt2 = fr_bands + NB_BANDS; + pt3 = hNoiseEst->bckr_fx; + + L_snr_sum = L_deposit_l( 0 ); + L_snr_sum_HE_SAD = L_deposit_l( 0 ); + snr_sumt = 0; + move16(); + L_mssnr_hov = L_deposit_l( 0 ); + *snr_sum_he = 0; + move16(); + snr_sum_HE_SAD = 0; + move16(); + + + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) + { + ftmp = L_add( *pt1++, 0 ); + ftmp1 = L_add( *pt2++, 0 ); + ftmp2 = L_add( *pt3++, 0 ); + + /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ + L_tmp = Mult_32_16( hNoiseEst->enrO_fx[i], 13107 ); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ + L_tmp1 = Madd_32_16( L_tmp, ftmp, 26214 ); /* 26214 = .4 in Q16 */ + L_tmp1 = Madd_32_16( L_tmp1, ftmp1, 26214 ); /* L_tmp1 re_used a bit later for final snr[i]*/ + + L_tmp2 = Madd_32_16( L_tmp, ftmp, 19661 ); /* 19661 = 0.3 in Q16 */ + L_tmp2 = Msub_32_16( L_tmp2, ftmp1, -32768 ); /* -32768= -0.5 in Q16 */ + + IF( GT_32( ftmp, ftmp1 ) ) + { + /*snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / ftmp2 ;*/ + /*snr[i] = L_tmp1/(ftmp2) */ + IF( ftmp2 != 0 ) + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + e_noise = norm_l( ftmp2 ); + m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*L_snr in Q4*/ + } + } + ELSE + { + /*snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / ftmp2 ;*/ + /*snr[i] =L_tmp2/( ftmp2 ) */ + IF( ftmp2 != 0 ) + { + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); + + e_noise = norm_l( ftmp2 ); + m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp2 ); + m_num = extract_h( L_shl( L_tmp2, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*L_snr in Q4*/ + } + } + + if ( LT_32( L_snr, 2 * ( 1 << 4 ) ) ) + { + nb_sig_snr = sub( nb_sig_snr, 1 ); /* nb_sig_snr--; */ + } + L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ + + + /* snr[i] = (float)log10(snr[i]); */ + snr = vad_snr_log_fx( L_snr, ONE_LG10 ); + + /* snr_sumt += snr[i];*/ + snr_sumt = add( snr_sumt, shr( snr, 4 ) ); /*Q4 */ + + +#ifdef BASOP_NOGLOB + tmp = shl_o( snr, 5, &Overflow ); /* Q8 -> Q13 */ +#else /* BASOP_NOGLOB */ + tmp = shl( snr, 5 ); /* Q8 -> Q13 */ +#endif /* BASOP_NOGLOB */ + IF( LT_16( i, 2 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta1, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta1 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE IF( LT_16( i, 7 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta2, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta2 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE IF( LT_16( i, 18 ) ) + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta3 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { +#ifdef BASOP_NOGLOB + tmp = add_o( tmp, delta4, &Overflow ); /*Q13 */ +#else /* BASOP_NOGLOB */ + tmp = add( tmp, delta4 ); /*Q13 */ +#endif /* BASOP_NOGLOB */ + } + + tmp1 = tmp; + move16(); /* ftmp1 = ftmp; */ + sub( 0, 0 ); + if ( i < 7 ) + { +#ifdef BASOP_NOGLOB + tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#else /* BASOP_NOGLOB */ + tmp1 = add( tmp, 3277 ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#endif /* BASOP_NOGLOB */ + } + + tmp = s_min( tmp, 16384 ); /* Q13, ftmp = min(ftmp, 2.0f); */ + tmp1 = s_min( tmp1, 16384 ); /* Q13, ftmp1 = min(ftmp1, 2.0f); */ + + L_msnr = L_deposit_l( tmp ); /*msnr = 1*tmp;*/ + FOR( j = 1; j < stmp; j++ ) + { + /* Q13*Q13 +1 -16 +2 = Q13 */ + L_msnr = L_shl( Mult_32_16( L_msnr, tmp ), 2 ); /*Q13 , msnr *= ftmp;*/ + } + L_mssnr = L_add( L_mssnr, L_msnr ); /*Q13 mssnr += msnr;*/ + + if ( EQ_16( i, 18 ) ) + { + L_msnr18 = L_add( L_msnr, 0 ); /*Q13 msnr18 = msnr; */ + } + + if ( EQ_16( i, 19 ) ) + { + L_msnr19 = L_add( L_msnr, 0 ); /* Q13 , msnr19 = msnr; */ + } + + L_msnr = L_deposit_l( tmp1 ); /* Q13, msnr = 1*tmp1 ;*/ + + FOR( j = 1; j < stmp; j++ ) + { + L_msnr = L_shl( Mult_32_16( L_msnr, tmp1 ), 2 ); /*Q13 msnr *= ftmp1;*/ + } + L_mssnr_hov = L_add( L_mssnr_hov, L_msnr ); /*Q13 mssnr_hov += msnr; */ + + /* recompute after he1 modifications */ + /* snr[i] = fr_enr / st->bckr[i] = L_tmp1/st->bckr[i];*/ + IF( hNoiseEst->bckr_fx[i] != 0 ) + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + e_noise = norm_l( hNoiseEst->bckr_fx[i] ); + m_noise_local = extract_h( L_shl( hNoiseEst->bckr_fx[i], e_noise ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, m_noise_local ); +#ifdef BASOP_NOGLOB + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ +#else /* BASOP_NOGLOB */ + L_snr = L_shr( snr_tmp, shift_snr ); /* L_snr in Q4 */ +#endif /* BASOP_NOGLOB */ + } + ELSE + { + e_num = norm_l( L_tmp1 ); + m_num = extract_h( L_shl( L_tmp1, e_num ) ); + + /* if bckr[i] == 0; approx. L_snr */ + e_noise = add( 30 + 1, abs_s( Q_new ) ); + + m_num = shr( m_num, 1 ); + shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); + + snr_tmp = div_s( m_num, 32767 ); + L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /*L_snr in Q4*/ + } + + + /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ + sign_thr_snr_acc_fx( &L_snr_sum_HE_SAD, L_snr, sign_thr_HE_SAD, min_snr_HE_SAD ); + sign_thr_snr_acc_fx( &L_snr_sum, L_snr, sign_thr, min_snr ); + + L_snr = L_max( L_snr, 16 ); /*Q4, if( snr[i] < 1.0f ) { snr[i] = 1.0f;} */ + + /* float saves all snrs in an snr[] vector , + in fix we only save two bands */ + if ( EQ_16( i, 18 ) ) + { + L_snr18 = L_add( L_snr, 0 ); /*Q4 */ + } + if ( EQ_16( i, 19 ) ) + { + L_snr19 = L_add( L_snr, 0 ); /* Q4 */ + } + + /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ + IF( LT_16( i, 3 ) ) + { +#ifdef BASOP_NOGLOB + L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#else + L_accum_ener_L = L_add( L_accum_ener_L, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#endif + } + ELSE + { +#ifdef BASOP_NOGLOB + L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#else + L_accum_ener_H = L_add( L_accum_ener_H, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#endif + } + + /* Identify the outlier band */ + IF( GT_32( L_snr, L_snr_outlier ) ) + { + L_snr_outlier = L_add( L_snr, 0 ); /*Q4*/ + snr_outlier_index = i; + move16(); + } + } /* end of band loop */ + + test(); + test(); + test(); /* one additional test for ELSE IF */ + IF( ( EQ_16( st_fx->max_band, 19 ) ) && ( GT_32( L_snr18, 5 * ( 1 << 4 ) ) ) && ( GT_32( L_snr19, 5 * ( 1 << 4 ) ) ) ) + { + /* mssnr = (mssnr + 3*(msnr18 + msnr19)) * 0.77f; */ + /* mssnr = (mssnr*.77f + 2.31f*(msnr18 + msnr19)); */ + L_tmp1 = Mult_32_16( L_mssnr, 25231 ); /* Q13+Q15+1-16 --> Q13 */ + L_tmp = Mult_32_16( L_shl( L_add( L_msnr18, L_msnr19 ), 2 ), 18924 ); /* Q(13+2)+Q(15-2)+1-16 --> Q13 */ + L_tmp = L_add( L_tmp1, L_tmp ); + if ( GT_32( L_tmp, L_mssnr ) ) + { + L_mssnr = L_tmp; + } + } + ELSE IF( ( snr_idx != 0 ) && GT_16( nb_sig_snr, 13 ) ) + { + L_tmp = -126976; + move32(); /* -15.5 Q13 */ + L_tmp = L_mac0( L_tmp, 80, lp_snr ); /* 2.5f(Q5)*lp_snr(Q8) - 15.5f */ + if ( L_tmp > 0 ) /* 2.5f*lp_snr - 15.5f > 0 */ + { + L_mssnr = L_add( L_mssnr, L_tmp ); /* mssnr += 2.5f*lp_snr - 15.5f; */ + } + } + + + /* Separated SNR_SUM outlier modification */ + L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ + + test(); + test(); + test(); + IF( ( EQ_16( st_fx->max_band, 19 ) ) && LT_32( L_snr_outlier, MAX_SNR_OUTLIER_3_FX ) && GT_16( snr_outlier_index, 3 ) && LT_16( snr_outlier_index, MAX_SNR_OUTLIER_IND_FX ) ) + { + + test(); + test(); + IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ + || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) ) + + { + /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ + L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */ + } + ELSE IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_2_FX ) ) /* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ + || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) + { + /* L_snr_sum = SNR_OUTLIER_WGHT_2 * (snr_sum - snr_outlier); */ + + /* 1.01*x -> (1*x + 0.01*x) to not drop down to Q3 */ + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 6 ) ); /* Q4 */ + } + ELSE + { + /* L_snr_sum = SNR_OUTLIER_WGHT_3 * (snr_sum - snr_outlier);*/ + /* 1.02*x -> (1*x + 0.02*x) to not drop down to Q3 */ + L_tmp = L_sub( L_snr_sum_ol, L_snr_outlier ); + L_tmp2 = Mult_32_16( L_tmp, 20972 ); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ + L_snr_sum_ol = L_add( L_tmp, L_shr( L_tmp2, 5 ) ); /* Q4 */ + } + } + /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ +#ifdef BASOP_NOGLOB + hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ +#else /* BASOP_NOGLOB */ + hVAD->L_snr_sum_vad_fx = L_shr( L_add( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ +#endif /* BASOP_NOGLOB */ + + /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ + snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); + snr_sum = snr_sum_ol; + move16(); /* note for NB no outlier modification */ + + /* snr_sum_HE_SAD = 10.0f * (float)log10( snr_sum_HE_SAD ); */ + snr_sum_HE_SAD = vad_snr_log_fx( L_snr_sum_HE_SAD, LG10 ); + + *snr_sum_he = snr_sum_HE_SAD; + move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ + + + /*---------------------------------------------------------------------* + * compute thr1 for SAD decision + *---------------------------------------------------------------------*/ + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ + + sub( 0, 0 ); + IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) + { + lp_snr = add( lp_snr, 1 << 8 ); /* lp_snr += 1; */ + + if ( GT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) + { + lp_snr = hNoiseEst->sign_dyn_lp_fx; + move16(); + } + } + + /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ + + L_tmp = L_shl( L_mult( sub( hNoiseEst->Etot_v_h2_fx, nv_ofs ), nv ), 7 ); /* Q8+Q8+1 +7 --> Q24 */ + L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ + thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ + + IF( st_fx->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) + { + /* lower threshold during warmup time */ + thr1 = sub( thr1, 2560 ); + L_vad_thr = 0; + } + + IF( GT_16( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) /* if (lp_snr > 20.0f )*/ + { + IF( st_fx->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100 ) + { + /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ + thr1 = add( thr1, mult( 9830, sub( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) ); /* Q15*Q8+1 -16 --> Q8 */ + + test(); + test(); + test(); + if ( EQ_16( st_fx->max_band, 16 ) && GT_16( lp_snr, 40 * 256 ) && GT_16( thr1, 6600 ) && LT_16( lp_speech_fx, 11520 ) ) + { + thr1 = 6600; + } + } + } + + + /*---------------------------------------------------------------------* + * WB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + IF( NE_16( vad_bwidth_fx, NB ) ) + { + + /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of + modyfying thr1 and snr_sum */ + + thr1_ol = thr1; + move16(); + hangover_short = 3; + move16(); + + IF( LT_16( lp_snr, th_clean ) ) + { + hangover_short = 4; + move16(); + + /* In this section the modified nk, and nc are used */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float + ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ + test(); + IF( ( snr_outlier_index <= 4 && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || + ( snr_outlier_index <= 4 && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) + + + { + thr1_ol = sub( thr1_ol, (Word16) ( 1 << 8 ) ); /*thr1_ol = thr1 - 1.0f ; */ + /*snr_sum_ol = 10.0f * (float)log10( hVAD->L_snr_sum_vad_fx );*/ + snr_sum_ol = vad_snr_log_fx( hVAD->L_snr_sum_vad_fx, LG10 ); /* snr in Q8 */ + } + ELSE IF( ( ( LE_16( st_fx->last_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR != 0 ) ) || + ( ( LE_16( last_7k2_coder_type, UNVOICED ) ) && ( LT_32( L_snr_outlier, MAX_SNR_OUTLIER_2_FX ) ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) + + { + /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ + L_tmp2 = Msub_32_16( (Word32) ( 1 << ( 24 - 16 ) ), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ + tmp2 = round_fx( L_shl( L_tmp2, 16 ) ); /* high word is in Q8 */ + thr1_ol = add( thr1_ol, tmp2 ); /* (Q8 , Q8) */ + } + ELSE + { + /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * L_snr_outlier)); */ + thr1_ol = thr1; + move16(); + L_tmp2 = Msub_32_16( (Word32) 614, L_snr_outlier, 20972 ); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ +#ifdef BASOP_NOGLOB + tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#else /* BASOP_NOGLOB */ + tmp2 = round_fx( L_shl( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#endif + if ( L_tmp2 > 0 ) + { + thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ + } + } + } + + /* apply outlier modification */ + snr_sum = snr_sum_ol; + move16(); /*NB s*/ + thr1 = thr1_ol; + move16(); + + /* DTX HANGOVER is in pre_proc_fx() */ + flag_he1 = 0; + move16(); + + IF( GT_32( L_mssnr, L_vad_thr ) ) + { + flag_he1 = 1; + move16(); /* he1 primary decision */ + hVAD->nb_active_frames_he1 = add( hVAD->nb_active_frames_he1, 1 ); /* Counter of consecutive active speech frames */ + + IF( GE_16( hVAD->nb_active_frames_he1, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames_he1 = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt_he1 = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + /* inside HO period */ + test(); + if ( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) + { + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + } + + if ( hVAD->soft_hangover > 0 ) + { + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + } + } + ELSE + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + hVAD->nb_active_frames_he1 = 0; + move16(); + } + + + IF( GT_16( hVAD->voiced_burst, 3 ) ) + { + IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ + { + hVAD->soft_hangover = hangover_sf_tbl[add( snr_idx, 3 )]; + move16(); + } + ELSE + { + hVAD->soft_hangover = hangover_sf_tbl[snr_idx]; + move16(); + } + } + + + hangover_hd = hangover_hd_tbl[snr_idx]; + move16(); + + IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) + { + hangover_hd = add( shr( hangover_hd, 1 ), 1 ); + move16(); + } + + /* VAD hangover for he1 */ + test(); + IF( flag_he1 == 0 && hVAD->soft_hangover > 0 ) + { + IF( GT_32( L_mssnr_hov, L_vad_thr ) ) + { + flag_he1 = 1; + move16(); + hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + } + ELSE + { + hVAD->soft_hangover = 0; + move16(); + } + + if ( hVAD->soft_hangover < 0 ) + { + hVAD->soft_hangover = 0; + move16(); + } + } + + test(); + test(); + IF( ( flag_he1 == 0 ) && ( LT_16( hVAD->hangover_cnt_he1, hangover_hd ) ) && ( hVAD->soft_hangover == 0 ) ) + { + flag_he1 = 1; + move16(); + hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + } + + + /* Calculate background stationarity */ + test(); + IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) + { + IF( GT_16( snr_sumt, hVAD->bcg_flux_fx ) ) + { + IF( hVAD->bcg_flux_init-- > 0 ) + { + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 800 ) ) ) + { + /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), add( hVAD->bcg_flux_fx, 800 ), 3277 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), snr_sumt, 3277 ); /*Q4 */ + } + } + ELSE + { + IF( GT_16( snr_sumt, add( hVAD->bcg_flux_fx, 160 ) ) ) + { + /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), add( hVAD->bcg_flux_fx, 160 ), 328 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), snr_sumt, 328 ); /*Q4 */ + } + } + } + ELSE + { + IF( hVAD->bcg_flux_init-- > 0 ) + { + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 480 ) ) ) + { + /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), sub( hVAD->bcg_flux_fx, 480 ), 1638 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31131 ), snr_sumt, 1638 ); /*Q4 */ + } + } + ELSE + { + IF( LT_16( snr_sumt, sub( hVAD->bcg_flux_fx, 160 ) ) ) + { + /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), sub( hVAD->bcg_flux_fx, 160 ), 26 ); /*Q4 */ + } + ELSE + { + /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ + hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), snr_sumt, 26 ); /*Q4 */ + } + } + } + + hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); + } + + flag = 0; + move16(); + st_fx->localVAD = 0; + move16(); + /* if ( snr_sum > thr1 && flag_he1 == 1 ) */ /* Speech present */ + test(); + + IF( ( GT_16( snr_sum, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ + { + flag = 1; + move16(); + st_fx->localVAD = 1; + move16(); + + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + /* inside HO period */ + test(); + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + } + } + ELSE + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + hVAD->nb_active_frames = 0; + move16(); + + if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) ) /* inside HO period */ + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + } + + + IF( LE_16( hVAD->hangover_cnt, hangover_short ) ) /* "hard" hangover */ + { + test(); + test(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + { + *noisy_speech_HO = 1; + move16(); + } + test(); + test(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + { + *clean_speech_HO = 1; + move16(); + } + flag = 1; + move16(); /*HO*/ + } + } + + + /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ + + *localVAD_HE_SAD = 0; + move16(); + + test(); + IF( ( GT_16( snr_sum_HE_SAD, thr1 ) ) && ( EQ_16( flag_he1, 1 ) ) ) /* Speech present */ + { + + *localVAD_HE_SAD = 1; + move16(); + } + } /* end of WB SWB */ + + /*---------------------------------------------------------------------* + * NB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + ELSE /* NB input */ + { + /* Add localVAD_HE_SAD also for NB operation for use with speech music classifier */ + *localVAD_HE_SAD = 0; + move16(); + if ( GT_16( snr_sum_HE_SAD, thr1 ) ) + { + *localVAD_HE_SAD = 1; + move16(); + } + + st_fx->localVAD = 0; + move16(); /* safety inits for fx */ + IF( GT_16( snr_sum, thr1 ) ) /* Speech present, possibly in hangover */ + { + hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) + { + hVAD->nb_active_frames = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt = 0; + move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + st_fx->localVAD = 1; + move16(); + } + ELSE + { + hVAD->nb_active_frames = 0; + move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ + /* st_fx->localVAD = 0; move16(); */ /* set above */ + } + + thr1_nb_mod = thr1; + move16(); /* thr1 may be adjusted after this point */ + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_NB_FX ) ) + { + hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + + IF( LT_16( lp_snr, 4864 ) ) + /*19.0f Q8*/ /* very low SNR */ + { + thr1_nb_mod = sub( thr1_nb_mod, 1331 ); /*thr1 -= 5.2f;*/ + } + ELSE IF( LT_16( lp_snr, 8960 ) ) /*35 in Q8 */ /* low SNR */ + { + thr1_nb_mod = sub( thr1_nb_mod, 512 ); /*thr1 -= 2.0f;*/ + } + } + + + thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ + + /* -dtx condition dependency in noisy speech */ + tmp = 333; + move16(); /* 1.3f; */ + if ( st_fx->Opt_DTX_ON == 0 ) + { + tmp = 282; + move16(); /* 1.10f; */ + } + if ( LT_16( lp_snr, th_clean ) ) + { + thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ + } + + + flag = 0; + move16(); + IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ + { + flag = 1; + move16(); + } + + + test(); + IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ + { + flag = 1; + move16(); + st_fx->localVAD = 0; + move16(); + + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + *NB_speech_HO = 1; + } + move16(); + } + thr1 = thr1_nb_mod; + move16(); /* needed for st_fx->vadnoise_fx update below */ + } /* end of NB */ + + + /* *flag_noisy_speech_snr is a Word8 parameter */ + *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ + move16(); + IF( vad_bwidth_fx != NB ) + { + if ( LT_16( lp_snr, TH16_2_NFLAG_FX ) ) /*now 27, original threshold: 35dB*/ + { + *flag_noisy_speech_snr = 1; + move16(); + } + } + ELSE + { + if ( LT_16( lp_snr, TH8_1_NFLAG_FX ) ) /* now 20.0 */ + { + *flag_noisy_speech_snr = 1; + move16(); + } + } + + if ( st_fx->hSC_VBR != NULL ) + { + /* SC-VBR */ + st_fx->hSC_VBR->vadsnr_fx = snr_sum; + move16(); /* for ppp, voiced_enc */ + st_fx->hSC_VBR->vadnoise_fx = thr1; + move16(); /* used in nb for find_uv */ + } + + /* Updates */ + hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ + + if ( st_fx->localVAD != 0 ) + { + hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ + } + + hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ + + if ( st_fx->localVAD != 0 ) + { + hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ + } + + tmp = hVAD->prim_act_slow_fx; + move16(); + if ( LE_16( hVAD->prim_act_quick_fx, hVAD->prim_act_slow_fx ) ) + { + tmp = hVAD->prim_act_quick_fx; + move16(); + } + /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ + hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); + + + hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) + { + hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ + } + + hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ + if ( *localVAD_HE_SAD != 0 ) + { + hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ + } + + tmp = hVAD->prim_act_slow_he_fx; + move16(); + if ( LE_16( hVAD->prim_act_quick_he_fx, hVAD->prim_act_slow_he_fx ) ) + { + tmp = hVAD->prim_act_quick_he_fx; + move16(); + } + hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); + + + if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ + { + hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); + } + + hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); + + + if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) + { + hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); + } + + hVAD->vad_flag_reg_L = L_shl( L_and( hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1 ); + + + IF( flag != 0 ) /* should not include the extra DTX hangover */ + { + hVAD->vad_flag_reg_L = L_or( hVAD->vad_flag_reg_L, 0x01L ); + hVAD->vad_flag_cnt_50 = add( hVAD->vad_flag_cnt_50, 1 ); + } + + if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index 3012600fad36092a8c2b82ed775825d7cf3b9e10..e0b607c5a68015d07f0af5774686659f67f828c4 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -7,8 +7,7 @@ #include "cnst.h" /* Common constants */ //#include "prot_fx.h" /* Function prototypes */ #include "ivas_stat_enc.h" /* Function prototypes */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* @@ -176,9 +175,9 @@ void vad_param_updt_fx( #endif /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ - pitch_tmp = abs_s( sub( st_fx->pitch_fx[0], old_pitch1 ) ); /*Q0 */ - pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch_fx[1], st_fx->pitch_fx[0] ) ) ); /*Q0 */ - pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch_fx[2], st_fx->pitch_fx[1] ) ) ); /*Q0 */ + pitch_tmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); /*Q0 */ + pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ) ); /*Q0 */ + pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[2], st_fx->pitch[1] ) ) ); /*Q0 */ /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index add2243400d60f09ac36ac0c22d3429fe8ea5598..cf235d96df85522ef26ea0524d55c1dd6ce9c644 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -12,8 +12,7 @@ #include "stat_enc.h" #include "rom_enc.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index 659eec5248eba3dcc2fa6b583c5bd8e9c78befd1..fe5766eea883fd5a3fd87d8ce8f7265d06b0c09b 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" /* Static table prototypes */ #include "stat_enc.h" /* Static table prototypes */ #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index 561446aa5a55c67b2ac35d825f35138b42b98dc6..cc9592739dae011a0653a3dab05f70514937327c 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -9,8 +9,7 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #define ISF_ONE 3 /*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index e0b2c427afaaa1e636da79b359e96119242c1ce0..0785e9e6e14a161fc9d2c4c60a3e2944714b4e4e 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -8,8 +8,7 @@ #include "options.h" //#include "prot_fx.h" #include "control.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index 2e9035743ef51c8625a990df63042eb62403cf7b..b9e0b9c425c7dcbf19ffd794b99f6686696ab86d 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -8,8 +8,7 @@ //#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" /* Common constants */ -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ @@ -206,12 +205,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } @@ -237,12 +236,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } @@ -268,12 +267,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } @@ -595,12 +594,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } } @@ -642,12 +641,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } } @@ -662,12 +661,12 @@ ivas_error ppp_voiced_encoder_fx( IF( hSC_VBR->bump_up == 1 ) { - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } @@ -676,12 +675,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } /* -----End Open-loop Bump-Up */ @@ -695,12 +694,12 @@ ivas_error ppp_voiced_encoder_fx( { if ( ( error = ppp_quarter_encoder_fx( &flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr ) ) != IVAS_ERR_OK ) { - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } } @@ -1173,12 +1172,12 @@ ivas_error ppp_voiced_encoder_fx( { hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } @@ -1193,12 +1192,12 @@ ivas_error ppp_voiced_encoder_fx( move16(); hSC_VBR->bump_up = 1; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } } @@ -1245,12 +1244,12 @@ ivas_error ppp_voiced_encoder_fx( hSC_VBR->dtfs_enc_Q = dtfs_temp_fx->Q; move16(); - count_free( CURRP_NQ_FX ); - count_free( TMPDTFS_FX ); - count_free( TMPDTFS2_FX ); - count_free( TMPDTFS3_FX ); - count_free( CURRP_Q_E_FX ); - count_free( dtfs_temp_fx ); + free( CURRP_NQ_FX ); + free( TMPDTFS_FX ); + free( TMPDTFS2_FX ); + free( TMPDTFS3_FX ); + free( CURRP_Q_E_FX ); + free( dtfs_temp_fx ); return error; } diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index a42994223bc0c098d89d8705ccdc0a2f6ce3e30b..378898522fefbf0ed6ee27e78f76e00a9e7db40a 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -9,8 +9,7 @@ #include "rom_com_fx.h" #include "rom_com.h" #include "stat_com.h" -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 2d737022cb55b4b94312c4223512b81b87d69d7e..95260d7b1bce7e1202e6fabdc2ce0727bba177db 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -42,14 +42,17 @@ #include "ivas_stat_rend.h" #include "lib_rend.h" #include "wmc_auto.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + #ifdef IVAS_FLOAT_FIXED #include "control.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#include "debug.h" +#include "prot_fx.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) #endif + #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_hrtf_init() @@ -3115,12 +3118,12 @@ static ivas_error ivas_rend_crendConvolver( hCrend = pCrend->hCrend; - IF( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) { return error; } @@ -3148,8 +3151,8 @@ static ivas_error ivas_rend_crendConvolver( IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { - set_val_Word32( &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse], 0, subframe_length ); - set_val_Word32( &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse], 0, subframe_length ); + set32_fx( &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse], 0, subframe_length ); + set32_fx( &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse], 0, subframe_length ); } i = 0; @@ -3179,18 +3182,18 @@ static ivas_error ivas_rend_crendConvolver( ivas_mdft_fx( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( pFreq_buf_re, subframe_length, "Fixed_pFreq_buf_re_mdft.txt", NULL ); - dbgwrite_txt( pFreq_buf_im, subframe_length, "Fixed_pFreq_buf_im_mdft.txt", NULL ); +#ifdef DEBUGGING + dbgwrite_txt( (const float *) pFreq_buf_re, subframe_length, "Fixed_pFreq_buf_re_mdft.txt", NULL ); + dbgwrite_txt( (const float *) pFreq_buf_im, subframe_length, "Fixed_pFreq_buf_im_mdft.txt", NULL ); #endif - i++; + i = add( i, 1 ); } } FOR( j = 0; j < nchan_out; j++ ) { - set_val_Word32( tmp_out_re, 0, subframe_length ); - set_val_Word32( tmp_out_im, 0, subframe_length ); + set32_fx( tmp_out_re, 0, subframe_length ); + set32_fx( tmp_out_im, 0, subframe_length ); i = 0; move16(); FOR( idx_in = 0; idx_in < nchan_in; idx_in++ ) @@ -3247,8 +3250,8 @@ static ivas_error ivas_rend_crendConvolver( ivas_imdft_fx( tmp_out_re, tmp_out_im, pOut, subframe_length ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); +#ifdef DEBUGGING + dbgwrite_txt( (const float *) pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); #endif pFreq_buf_re = &pcm_out[j][imult1616( i_ts, subframe_length )]; FOR( k = 0; k < subframe_length; k++ ) @@ -3591,7 +3594,7 @@ ivas_error ivas_rend_crendProcess( /* move to output */ FOR( i = 0; i < nchan_out; i++ ) { - mvr2r_Word32( pcm_tmp_fx[i], output_fx[i], imult1616( num_subframes, subframe_len ) ); + MVR2R_WORD32( pcm_tmp_fx[i], output_fx[i], imult1616( num_subframes, subframe_len ) ); } pop_wmops(); @@ -3891,7 +3894,7 @@ ivas_error ivas_rend_crendProcessSubframe( /* move to output */ FOR( ch = 0; ch < nchan_out; ch++ ) { - mvr2r_Word32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); + MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); } hTcBuffer->subframes_rendered = last_sf; diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index 534f59551a1a96ee86b222177d2055ecd97382d5..f32414199175d85bf62abee2ed5410c7c95823b7 100644 --- a/lib_rend/ivas_dirac_ana.c +++ b/lib_rend/ivas_dirac_ana.c @@ -39,8 +39,7 @@ #include "ivas_stat_rend.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 4c52699c932bf806ffbca7083b417264a09b82fa..d248df0d2116586d13242f0d2b6ad0b32a7d3274 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -35,8 +35,7 @@ #include #include #include "prot.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_cnst.h" @@ -179,9 +178,11 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); #endif - +#ifdef IVAS_FLOAT_FIXED +static void ivas_masa_ext_rend_parambin_internal_fx( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, Word32 *output_fx[], const Word16 subframe ); +#else static void ivas_masa_ext_rend_parambin_internal( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t subframe ); - +#endif #ifdef IVAS_FLOAT_FIXED static void formulate2x2MixingMatrix_fx( Word32 Ein1_fx, Word32 Ein2_fx, Word16 q_Ein, Word32 CinRe_fx, Word32 CinIm_fx, Word16 q_Cin, Word32 Eout1_fx, Word32 Eout2_fx, Word16 q_Eout, Word32 CoutRe_fx, Word32 CoutIm_fx, Word16 q_Cout, Word32 Q_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Mre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Mim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word16 *q_M, const Word16 regularizationFactor_fx ); @@ -579,12 +580,12 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( move16(); } - n_samples_granularity = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + n_samples_granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); test(); test(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - n_samples_granularity = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + n_samples_granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ } IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) @@ -886,7 +887,7 @@ void ivas_dirac_dec_binaural_render_fx( { output_fx_local[ch] = output_fx_local_buff[ch]; } - slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( (Word16) nSamplesAsked, (Word16) slot_size ) ); @@ -1420,8 +1421,8 @@ static void ivas_dirac_dec_binaural_internal_fx( ELSE IF( EQ_16( config_data.nchan_transport, 2 ) ) /* Stereo signal transmitted as mono with DFT stereo */ { /* At mono input duplicate the channel to dual-mono */ - mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); - mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); q_cldfb[1][slot] = q_cldfb[0][slot]; move16(); } @@ -1497,8 +1498,8 @@ static void ivas_dirac_dec_binaural_internal_fx( v_multc_fixed_16( Cldfb_RealBuffer_in_fx[0][slot], 23170, Cldfb_RealBuffer_in_fx[0][slot], nBins ); v_multc_fixed_16( Cldfb_ImagBuffer_in_fx[0][slot], 23170, Cldfb_ImagBuffer_in_fx[0][slot], nBins ); - mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); - mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); q_cldfb[1][slot] = q_cldfb[0][slot]; move16(); } @@ -7813,10 +7814,10 @@ static void ivas_masa_ext_rend_parambin_internal( return; } #else -static void ivas_masa_ext_rend_parambin_internal( +static void ivas_masa_ext_rend_parambin_internal_fx( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, - float *output_f[], + Word32 *output_fx[], /* Q11*/ const Word16 subframe ) { @@ -7829,21 +7830,20 @@ static void ivas_masa_ext_rend_parambin_internal( Word16 i, j; Word16 nchan_transport; Word16 q_mat; - -#if 1 hDiracDecBin = hMasaExtRend->hDiracDecBin; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - Word32 *output_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - FOR( ch = 0; ch < 2; ch++ ) - { - output_fx[ch] = output_fx_buff[ch]; - floatToFixed_arrL32( output_f[ch], output_fx[ch], Q11, L_FRAME48k ); - } -#endif Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + + FOR( i = 0; i < 6; i++ ) + { + FOR( j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) + { + set32_fx( Cldfb_RealBuffer_in_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_in_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } Word32 Rmat_fx[3][3]; hDiracDecBin = hMasaExtRend->hDiracDecBin; @@ -7864,8 +7864,16 @@ static void ivas_masa_ext_rend_parambin_internal( move16(); config_data.qualityBasedSmFactor_fx = ONE_IN_Q31; move32(); - config_data.processReverb = hMasaExtRend->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; - move16(); + IF( EQ_16( hMasaExtRend->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + config_data.processReverb = 1; + move16(); + } + ELSE + { + config_data.processReverb = 0; + move16(); + } config_data.ism_mode = ISM_MODE_NONE; move32(); @@ -7921,12 +7929,13 @@ static void ivas_masa_ext_rend_parambin_internal( v_multc_fixed( Cldfb_RealBuffer_in_fx[0][slot], 151800249 /* INV_SQRT_2 in Q31 */, Cldfb_RealBuffer_in_fx[0][slot], nBins ); v_multc_fixed( Cldfb_ImagBuffer_in_fx[0][slot], 151800249 /* INV_SQRT_2 in Q31 */, Cldfb_ImagBuffer_in_fx[0][slot], nBins ); - mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); - mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + Copy32( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); } } } Word16 q_inp = Q6; + move16(); IF( hCombinedOrientationData ) { FOR( i = 0; i < 3; i++ ) @@ -7983,20 +7992,15 @@ static void ivas_masa_ext_rend_parambin_internal( hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); -#if 1 Word16 q_out; q_inp = Q6; move16(); - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - output_fx[ch] = output_fx_buff[ch]; - } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; move16(); } -#endif // Float to fix ends q_mat = hDiracDecBin->q_processMtx; move16(); @@ -8043,20 +8047,18 @@ static void ivas_masa_ext_rend_parambin_internal( move16(); move16(); -#if 1 // Fix to float FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, nBins * hSpatParamRendCom->subframe_nbslots[subframe] ); + scale_sig32( output_fx[ch], nBins * hSpatParamRendCom->subframe_nbslots[subframe], sub( Q11, q_out ) ); scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } -#endif return; } #endif - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_rend_parambin_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ @@ -8096,3 +8098,46 @@ void ivas_masa_ext_rend_parambin_render( return; } +#else +void ivas_masa_ext_rend_parambin_render_fx( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output Q11*/ + const Word16 num_subframes ) /* i : number of subframes to render */ +{ + Word16 subframe; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + Word32 *p_output[BINAURAL_CHANNELS]; + Word16 ch; + + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + p_output[ch] = output_f[ch]; + } + + hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; + move16(); + FOR( subframe = 0; subframe < num_subframes; subframe++ ) + { + Word16 n_samples_sf = i_mult( hSpatParamRendCom->slot_size, CLDFB_SLOTS_PER_SUBFRAME ); + hSpatParamRendCom->slots_rendered = 0; + move16(); + + ivas_masa_ext_rend_parambin_internal_fx( hMasaExtRend, hCombinedOrientationData, p_output, hSpatParamRendCom->dirac_read_idx ); + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + p_output[ch] += n_samples_sf; + } + + ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_sf ); + + hSpatParamRendCom->dirac_read_idx = ( add( hSpatParamRendCom->dirac_read_idx, 1 ) ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); + } + + return; +} +#endif diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index de0253bb51f2cadfc24fe48c2b572380d34a5cd3..99c17d529c222248241500363d4af9d7cbc69eb8 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -41,8 +41,7 @@ #include "ivas_cnst.h" #include "ivas_rom_rend.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*------------------------------------------------------------------------- * Local constants @@ -1125,8 +1124,14 @@ void ivas_dirac_dec_decorr_process_fx( set32_fx( &h_freq_domain_decorr_ap_state->decorr_buffer_fx[imult1616( imult1616( imult1616( 2, sub( decorr_buffer_len, 1 ) ), max_band_decorr ), num_channels )], 0, imult1616( imult1616( 2, max_band_decorr ), num_channels ) ); Word16 decorr_buff_tot_len = imult1616( imult1616( shl( decorr_buffer_len, 1 ), max_band_decorr ), num_channels ); - - guarded_bits = s_max( find_guarded_bits_fx( 2 ), 3 ); + guarded_bits = 0; + FOR( Word16 i = 0; i < decorr_buff_tot_len; i++ ) + { + IF( h_freq_domain_decorr_ap_state->decorr_buffer_fx[i] != 0 ) + { + guarded_bits = s_max( find_guarded_bits_fx( 2 ), 3 ); + } + } q_shift = sub( getScaleFactor32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len ), guarded_bits ); Scale_sig32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len, q_shift ); q_decorr_buf = add( q_decorr_buf, q_shift ); diff --git a/lib_rend/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c index 7e2a595911bd537136a7d16f2294d31ddc9a2d3f..c7e4a6ff6e09dccbc7564e9cc9809faf930016be 100644 --- a/lib_rend/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -41,8 +41,7 @@ #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #ifdef IVAS_FLOAT_FIXED static Word16 BASOP_Util_Cmp_Mant32Exp_sat( Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e ); diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 01305155498381e01b44b527ab617175c24c9e55..36b13ed584b0e4f8347a262ce83f476594b130e7 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -44,8 +44,7 @@ #include "ivas_rom_dec.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" /* Function prototypes */ -#include "prot_fx2.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" @@ -2124,9 +2123,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g1 = L_add( POINT_3679_Q31, - Mpy_32_32( onset_filter[l], - POINT_1175_Q31 - POINT_3679_Q31 ) ); // Q31, (Q31, Q31) -> Q31 + g1 = Madd_32_32( POINT_3679_Q31, onset_filter[l], POINT_1175_Q31 - POINT_3679_Q31 ); // Q31, (Q31, Q31) -> Q31 g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_dir ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q g2 = L_max( g2, Mpy_32_32( 2126008812 /* 0.99f in Q31 */, L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q @@ -2142,9 +2139,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g1 = L_add( POINT_3679_Q31, - Mpy_32_32( onset_filter[l], - POINT_1175_Q31 - POINT_3679_Q31 ) ); // Q31, (Q31, Q31) -> Q31 + g1 = Madd_32_32( POINT_3679_Q31, onset_filter[l], POINT_1175_Q31 - POINT_3679_Q31 ); // Q31, (Q31, Q31) -> Q31 g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_dir ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q g2 = L_max( g2, Mpy_32_32( 1825361101 /* 0.85f in Q31 */, L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q @@ -2160,9 +2155,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g1 = L_add( POINT_3679_Q31, - Mpy_32_32( onset_filter[l], - POINT_1175_Q31 - POINT_3679_Q31 ) ); // Q31, (Q31, Q31) -> Q31 + g1 = Madd_32_32( POINT_3679_Q31, onset_filter[l], POINT_1175_Q31 - POINT_3679_Q31 ); // Q31, (Q31, Q31) -> Q31 g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_dir ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q g2 = L_max( g2, W_extract_h( W_shl( W_mult_32_32( -DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ), Q5 ) ) ); // p_gains_dir_q @@ -2192,9 +2185,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g1 = L_add( POINT_3679_Q31, - Mpy_32_32( onset_filter[l], - POINT_1175_Q31 - POINT_3679_Q31 ) ); // Q31, (Q31, Q31) -> Q31 + g1 = Madd_32_32( POINT_3679_Q31, onset_filter[l], POINT_1175_Q31 - POINT_3679_Q31 ); // Q31, (Q31, Q31) -> Q31 g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_dir ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ) ); // (p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q g2 = L_max( g2, W_extract_h( W_shl( W_mult_32_32( -DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ), Q5 ) ) ); // p_gains_dir_q @@ -2251,8 +2242,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( shl( i_mult( ch_idx, num_freq_bands ), Q1 ); FOR( l = 0; l < num_freq_bands; l++ ) { - g = L_add( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), - Mpy_32_32( g2, ( *( p_gains_dir_prev++ ) ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) + g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); @@ -2278,31 +2268,25 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( shl( i_mult( proto_direct_index[1], num_freq_bands ), Q1 ); FOR( l = 0; l < num_freq_bands; l++ ) { - gs1 = L_add( Mpy_32_32( g1, ( *( p_gains_dir ) ) ), - Mpy_32_32( g2, ( *( p_gains_dir_prev ) ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - gs2 = L_add( Mpy_32_32( g1, ( *( p_gains_dir + imult1616( num_freq_bands, num_channels_dir ) ) ) ), - Mpy_32_32( g2, ( *( p_gains_dir_prev + imult1616( num_freq_bands, num_channels_dir ) ) ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) + gs1 = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir ) ) ), g2, ( *( p_gains_dir_prev ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) + gs2 = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir + imult1616( num_freq_bands, num_channels_dir ) ) ) ), g2, ( *( p_gains_dir_prev + imult1616( num_freq_bands, num_channels_dir ) ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) p_gains_dir++; p_gains_dir_prev++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = - L_add( - Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), - Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), /* s1 */ - Mpy_32_32( gs2, ( L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), - Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ) ); /* s2 */ + Madd_32_32( + Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), /* s1 */ + gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); /* s2 */ move32(); p_proto++; p_proto2++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = - L_add( - Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), - Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), - Mpy_32_32( gs2, ( L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), - Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ) ); + Madd_32_32( + Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), + gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); move32(); p_proto++; p_proto2++; @@ -2334,8 +2318,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g = L_add( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), - Mpy_32_32( g2, ( *( p_gains_dir_prev++ ) ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) + g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); @@ -2383,19 +2366,18 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( ch_idx_diff = add( ch_idx_diff, 1 ); FOR( l = 0; l < num_freq_bands_diff; l++ ) { - g = L_add( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), - Mpy_32_32( g2, ( *( p_gains_diff_prev++ ) ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q + g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), g2, ( *( p_gains_diff_prev++ ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - L_add( output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], - Mpy_32_32( g, ( *( p_proto++ ) ) ) ); + Madd_32_32( output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + g, ( *( p_proto++ ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - L_add( output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], - Mpy_32_32( g, ( *( p_proto++ ) ) ) ); + Madd_32_32( output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + g, ( *( p_proto++ ) ) ); move32(); } } @@ -2436,9 +2418,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( move32(); FOR( i = 1; i < num_channels_dir; i++ ) { - p_real[l] = L_add( p_real[l], Mpy_32_32( *( p_out_real++ ), hoa_decoder[i] ) ); // (q, Q29) -> q - Q2 + p_real[l] = Madd_32_32( p_real[l], *( p_out_real++ ), hoa_decoder[i] ); // (q, Q29) -> q - Q2 move32(); - p_imag[l] = L_add( p_imag[l], Mpy_32_32( *( p_out_imag++ ), hoa_decoder[i] ) ); // (q, Q29) -> q - Q2 + p_imag[l] = Madd_32_32( p_imag[l], *( p_out_imag++ ), hoa_decoder[i] ); // (q, Q29) -> q - Q2 move32(); } } diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index e96aec922f7a9a475bb57d6f4b5ae8f9f7d7e61b..a96e1cf5f9fefbe24ca6b48bc0b147722fef7559 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -41,8 +41,7 @@ #include "ivas_cnst.h" #include "ivas_rom_rend.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_binaural_crend_head.h" @@ -1472,6 +1471,7 @@ ivas_error ivas_dirac_alloc_mem_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx = hDirAC_mem->direct_power_factor_fx; hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx = hDirAC_mem->diffuse_power_factor_fx; + hDirACRend->h_output_synthesis_psd_state.diff_dir_power_factor_len = size_pf; set_zero_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, size_pf ); set_zero_fx( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, size_pf ); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; @@ -4278,7 +4278,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); #ifdef MSAN_FIX Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, - sub( 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE, diffuse_start ), sub( diff_e, new_diff_e ) ); + i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); #else Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, sub( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_len, diffuse_start ), sub( diff_e, new_diff_e ) ); diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index fb6abd9411b8e1a9017498d645c508ccd4866b9b..5229164dd2813f48856912851b47f0d643f6ff1a 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -36,7 +36,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 07f2ca72d95853a3c92305fb9976d2343a2eec51..94f291ea182b0a4cb4d693c82d8fecc97c3a89d2 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -796,11 +796,11 @@ void limiter_process_fx( /* Update gain */ IF( LT_32( frame_gain, gain ) ) { - gain = L_add( Mpy_32_32( attack_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); /* Q30 */ + gain = Madd_32_32( frame_gain, attack_constant, L_sub( gain, frame_gain ) ); /* Q30 */ } ELSE { - gain = L_add( Mpy_32_32( release_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); /* Q30 */ + gain = Madd_32_32( frame_gain, release_constant, L_sub( gain, frame_gain ) ); /* Q30 */ } FOR( c = 0; c < num_channels; c++ ) diff --git a/lib_rend/ivas_masa_merge.c b/lib_rend/ivas_masa_merge.c index f1e93e22486542a627b737e070603bf3c597be42..734751f2db23870f3cba463d2555d92c330a44b9 100644 --- a/lib_rend/ivas_masa_merge.c +++ b/lib_rend/ivas_masa_merge.c @@ -39,9 +39,9 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*---------------------------------------------------------------------* @@ -822,7 +822,7 @@ void masaPrerendClose_fx( FOR( i = 0; i < ( *hMasaPrerendPtr )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); + deleteCldfb_ivas_fx( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); } free( ( *hMasaPrerendPtr )->hMasaOut ); diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index b0c4e82a0918a267761096addd99eebb42b31cd1..08c01b3b743a2f0431d6d613684ee153cf01db48 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -43,10 +43,9 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_rom_com_fx.h" -#endif // IVAS_FLOAT_FIXED +#endif /*------------------------------------------------------------------------- * Local constants @@ -253,7 +252,7 @@ ivas_error ivas_mcmasa_ana_open( move16(); FOR( i = 0; i < hMcMasa->num_Cldfb_instances; i++ ) { - IF( NE_32( ( error = openCldfb_ivas( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -664,7 +663,7 @@ void ivas_mcmasa_ana_close( FOR( i = 0; i < ( *hMcMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_ivas_fx( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); } /* intensity 3-dim */ diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index b2ebebb87b8c8dd787ee9de5f8d4db77a03f7b7d..0a12e65b3c982c1e3a9f8ec93088613808da408c 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -41,8 +41,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #include "ivas_rom_com_fx.h" #define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index c2fe6a26264b311296c35d9203ddab89d9bb48f0..8568da9eb6b18b2f74b126746df731bbf216d70b 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -39,8 +39,7 @@ #include "ivas_rom_rend.h" #include "ivas_cnst.h" #include "wmc_auto.h" -#include "prot_fx2.h" -#include "prot_fx1.h" +#include "prot_fx.h" /*---------------------------------------------------------------------* * Local function prototypes diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 06a645622c6d0c8b7e187dc3fd9a6a3fdcbe4846..67a70fcb12706074d4104b9d6c0172e2893b20a7 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -39,10 +39,9 @@ #include "wmc_auto.h" #include "ivas_rom_rend.h" #include "ivas_prot_fx.h" - #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif #define IVAS_FLOAT_FIXED_TO_BE_REMOVED diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index 6bb4b0c4409eb87b912ce00b1fee1833e8a30af8..cbd860f49c1a95a2954975cf26cd5c5b387b8c53 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -38,7 +38,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif @@ -286,6 +286,7 @@ void TDREND_Apply_ITD_fx( * The sinc resampling reads SFX_SPAT_BIN_SINC_M (5) samples outside of * the target frame. *---------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED static void sincResample( const float *input, /*i : Input signal */ @@ -350,7 +351,6 @@ static void sincResample( return; } - #else static void sincResample_fx( const Word32 *input_fx, /*i : Input signal Qx */ @@ -366,7 +366,7 @@ static void sincResample_fx( Word16 t_step_e; Word32 t_frac_fx; Word16 t_frac_e; - Word32 tmp_fx; + Word64 tmp64_fx; const Word32 *p_mid_fx; const Word32 *p_forward_fx; const Word32 *p_backward_fx; @@ -413,20 +413,20 @@ static void sincResample_fx( p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); - tmp_fx = Mpy_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ + tmp64_fx = W_mult_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ FOR( j = 0; j < SFX_SPAT_BIN_SINC_M - 1; j++ ) { - tmp_fx = L_add( tmp_fx, L_add( Mpy_32_32( *p_forward_fx, *p_sinc_forward_fx ), Mpy_32_32( *p_backward_fx, *p_sinc_backward_fx ) ) ); + tmp64_fx = W_add( tmp64_fx, W_mac_32_32( W_mult_32_32( *p_forward_fx, *p_sinc_forward_fx ), *p_backward_fx, *p_sinc_backward_fx ) ); p_sinc_forward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; p_sinc_backward_fx += SFX_SPAT_BIN_NUM_SUBSAMPLES; p_forward_fx++; p_backward_fx--; } - tmp_fx = L_add( tmp_fx, Mpy_32_32( *p_forward_fx, *p_sinc_forward_fx ) ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ + tmp64_fx = W_mac_32_32( tmp64_fx, *p_forward_fx, *p_sinc_forward_fx ); /* Integer index always rounded down --> 4 steps backward, 5 steps forward */ - output_fx[i] = tmp_fx; + output_fx[i] = W_extract_h( tmp64_fx ); move32(); /* Advance fractional time */ @@ -445,6 +445,7 @@ static void sincResample_fx( * --------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void TDREND_firfilt( float *signal, /* i/o: Input signal / Filtered signal */ float *filter, /* i/o: FIR filter */ @@ -497,8 +498,7 @@ void TDREND_firfilt( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void TDREND_firfilt_fx( Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ Word32 *filter_fx, /* i/o: FIR filter Qy */ @@ -521,6 +521,7 @@ void TDREND_firfilt_fx( Word32 tmp_fx; Word16 step_fx, gain_tmp_fx, gain_delta_fx; Word16 tmp_e; + Word64 tmp64_fx; gain_delta_fx = sub( Gain_fx, prevGain_fx ); // Q14 step_fx = BASOP_Util_Divide1616_Scale( gain_delta_fx, subframe_length, &tmp_e ); @@ -537,8 +538,8 @@ void TDREND_firfilt_fx( /* Convolution */ FOR( i = 0; i < subframe_length; i++ ) { - tmp_fx = 0; - move32(); + tmp64_fx = 0; + move64(); tmp_e = 0; move16(); p_tmp_fx = p_signal_fx + i; @@ -547,12 +548,14 @@ void TDREND_firfilt_fx( FOR( j = 0; j < filterlength; j++ ) { - tmp_fx = L_add( tmp_fx, Mpy_32_32( *p_filter_fx, *p_tmp_fx ) ); + tmp64_fx = W_mac_32_32( tmp64_fx, *p_filter_fx, *p_tmp_fx ); p_filter_fx++; p_tmp_fx--; } - tmp_fx = L_shl( tmp_fx, filter_e ); // This is done to keep the output Q same as input Q for signal + // This is done to keep the output Q same as input Q for signal + tmp64_fx = W_shl( tmp64_fx, filter_e ); + tmp_fx = W_extract_h( tmp64_fx ); /* Apply linear gain interpolation in case of abrupt gain changes */ gain_tmp_fx = add( gain_tmp_fx, step_fx ); diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 15159cacfc42f3033e1178aa8abc26da784588ff..743b98a1d7a7d1b9ea0d4ad65b5a72a38e6d6e21 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -38,9 +38,8 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#include "prot_fx2.h" -#include "prot_fx1.h" -#endif // IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*---------------------------------------------------------------------* diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index 714fdb2992193fda93c3c96d7d496c623541f99d..f24edf8bd86261e22dc081914ece1c143845c61f 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -36,8 +36,7 @@ #include "prot.h" #include "ivas_prot_rend.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index f5aa073180e9396a61f51b0c13ea5b539f1003b2..f231cc0a708414864a60c60590b122f703b7840f 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -41,7 +41,7 @@ #include "ivas_stat_rend.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" #define IVAS_FLOAT_FIXED_TO_BE_REMOVED @@ -146,7 +146,7 @@ ivas_error ivas_omasa_ana_open( hOMasa->num_Cldfb_instances = numAnalysisChannels; FOR( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { - IF( NE_32( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -379,7 +379,7 @@ void ivas_omasa_ana_close( FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_ivas_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -1087,8 +1087,8 @@ static void ivas_omasa_dmx_fx( { set_zero_fx( data_out_f_fx[i], input_frame ); } - set_s( data_e, 0, 4 ); - set_s( in_e, 0, 960 ); + set16_fx( data_e, 0, 4 ); + set16_fx( in_e, 0, 960 ); FOR( i = 0; i < nchan_ism; i++ ) { diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index edea2f0494d63d93a834577aadeb06f50174a1d0..6f308742c4ac7f605cdf6f61b5b5cd637bdb21bb 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -40,8 +40,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #endif /*------------------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 4868919f86e14af7fd593d2275ded2012a92c11d..78ee3d424d5081124f52cf4a45546e0e25a8924c 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -357,12 +357,20 @@ void ivas_dirac_dec_binaural_render_fx( Word32 *output_f[] /* o : rendered time signal */ ); #endif +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_rend_parambin_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t num_subframes /* i : number of subframes to render */ ); +#else +void ivas_masa_ext_rend_parambin_render_fx( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output Q11*/ + const Word16 num_subframes ); /* i : number of subframes to render */ +#endif #ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1640,6 +1648,7 @@ void TDREND_Apply_ITD_fx( ); #endif +#ifndef IVAS_FLOAT_FIXED void TDREND_firfilt( float *signal, /* i/o: Input signal / Filtered signal */ float *filter, /* i/o: FIR filter */ @@ -1651,7 +1660,7 @@ void TDREND_firfilt( const float Gain, /* i : Gain */ const float prevGain /* i : Previous gain */ ); -#ifdef IVAS_FLOAT_FIXED +#else void TDREND_firfilt_fx( Word32 *signal_fx, /* i/o: Input signal / Filtered signal Qx */ Word32 *filter_fx, /* i/o: FIR filter Qy */ diff --git a/lib_rend/ivas_reflections.c b/lib_rend/ivas_reflections.c index ea4b114184d01da34f44d23d3d3611333b590693..c684c29c4eb8e200fc79849185398d392461e0bb 100644 --- a/lib_rend/ivas_reflections.c +++ b/lib_rend/ivas_reflections.c @@ -43,8 +43,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 65525868cda2a86d8b92cb0e44390c5a6f28f5da..c7161061b9496018382d84ff361dec075a1e6173 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -37,7 +37,7 @@ #include "ivas_rom_rend.h" #include "ivas_rom_TdBinauralRenderer.h" #include "wmc_auto.h" -#include "prot_fx1.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 127dd83268ce80e5a91a1c1e71e948b7991173b5..f1a8205a75fbd47a1abd7945978aefbfc5415381 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -40,8 +40,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define float_to_fixQ31( n ) ( round( n * 0x7fffffff ) ) @@ -1923,12 +1922,12 @@ static void clear_buffers_fx( FOR( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) { delay_line = &( hReverb->delay_line[branch_idx] ); - set_val_Word32( delay_line->pBuffer_fx, 0, delay_line->MaxDelay ); + set32_fx( delay_line->pBuffer_fx, 0, delay_line->MaxDelay ); delay_line->BufferPos = 0; move16(); iirFilter = &( hReverb->t60[branch_idx] ); - set_val_Word32( iirFilter->pBuffer_fx, 0, iirFilter->MaxTaps ); + set32_fx( iirFilter->pBuffer_fx, 0, iirFilter->MaxTaps ); } ivas_reverb_t2f_f2t_ClearHistory( &hReverb->fft_filter_ols ); @@ -3103,7 +3102,9 @@ static void reverb_block_fx( FOR( ns = 0; ns < inner_bsize; ns++ ) { pO0[ns] = L_add( imult3216( pOutput_i_fx[ns], mixer_0_i ), pO0[ns] ); /* mixer ch 0 */ + move32(); pO1[ns] = L_add( imult3216( pOutput_i_fx[ns], mixer_1_i ), pO1[ns] ); /* mixer ch 1 */ + move32(); } } @@ -3114,15 +3115,18 @@ static void reverb_block_fx( FOR( ns = 0; ns < inner_bsize; ns++ ) { pFeedback_input_fx[ns] = L_shr( pIn[ns], 3 ); // to make the Qfactor similar to pOutput + move32(); } FOR( j = 0; j < nr_branches; j++ ) { Word32 gain_matrix_j_i = hReverb->gain_matrix_fx[j][i]; + move32(); Word32 *pOutput = &ppOutput_fx[j][0]; FOR( ns = 0; ns < inner_bsize; ns++ ) { pFeedback_input_fx[ns] = ( L_add( Mpy_32_32( gain_matrix_j_i, pOutput[ns] ), pFeedback_input_fx[ns] ) ); + move32(); } } @@ -3300,7 +3304,6 @@ static ivas_error downmix_input_block_fx( } default: return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported input format for reverb" ); - BREAK; } return IVAS_ERR_OK; @@ -3564,8 +3567,8 @@ ivas_error ivas_reverb_process_fx( } ELSE { - mvr2r_Word32( tmp1_fx, &pcm_out_fx[0][i_mult( i_ts, hReverb->full_block_size )], hReverb->full_block_size ); - mvr2r_Word32( tmp2_fx, &pcm_out_fx[1][i_mult( i_ts, hReverb->full_block_size )], hReverb->full_block_size ); + MVR2R_WORD32( tmp1_fx, &pcm_out_fx[0][i_mult( i_ts, hReverb->full_block_size )], hReverb->full_block_size ); + MVR2R_WORD32( tmp2_fx, &pcm_out_fx[1][i_mult( i_ts, hReverb->full_block_size )], hReverb->full_block_size ); } return IVAS_ERR_OK; diff --git a/lib_rend/ivas_reverb_delay_line.c b/lib_rend/ivas_reverb_delay_line.c index d24bbe1ec3233e9fbbdd526863dd555d5176e831..425afce0feea602de534eb94ef16e5cdd09d6e36 100644 --- a/lib_rend/ivas_reverb_delay_line.c +++ b/lib_rend/ivas_reverb_delay_line.c @@ -37,8 +37,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) @@ -72,7 +71,7 @@ void ivas_rev_delay_line_init( pDelay->pBuffer_fx = memory_buffer; move32(); - set_val_Word32( pDelay->pBuffer_fx, 0, pDelay->MaxDelay ); + set32_fx( pDelay->pBuffer_fx, 0, pDelay->MaxDelay ); pDelay->BufferPos = 0; move16(); pDelay->Gain_fx = ONE_IN_Q14; diff --git a/lib_rend/ivas_reverb_fft_filter.c b/lib_rend/ivas_reverb_fft_filter.c index 62ab464da4838c13afa711e1ec6da6b571ffd2d4..1889974cd8925f868db96dbb3275c9322f2399a6 100644 --- a/lib_rend/ivas_reverb_fft_filter.c +++ b/lib_rend/ivas_reverb_fft_filter.c @@ -37,8 +37,7 @@ #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index b293d6e22b8e4d898d7bacf8a6406b42cba932f7..ba6c43a09a761863e73f990617103479cbae5dc6 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -33,7 +33,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_rend.h" #include #include diff --git a/lib_rend/ivas_reverb_iir_filter.c b/lib_rend/ivas_reverb_iir_filter.c index 1f1508b5e84674aced11df0a0d58a35fa33b934f..4129a61e62987fbdc6b5afcb620f94532729c62f 100644 --- a/lib_rend/ivas_reverb_iir_filter.c +++ b/lib_rend/ivas_reverb_iir_filter.c @@ -36,8 +36,7 @@ #include "ivas_prot_rend.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) @@ -70,7 +69,7 @@ void ivas_reverb_iir_filt_init( move32(); } - set_val_Word32( iirFilter->pBuffer_fx, 0, iirFilter->MaxTaps ); + set32_fx( iirFilter->pBuffer_fx, 0, iirFilter->MaxTaps ); return; } diff --git a/lib_rend/ivas_reverb_utils.c b/lib_rend/ivas_reverb_utils.c index 7f4af770372e983224af0e798dbaadbd4668593b..c382c034a43dde17bbb5c2419a1289fb615dfc3d 100644 --- a/lib_rend/ivas_reverb_utils.c +++ b/lib_rend/ivas_reverb_utils.c @@ -37,7 +37,7 @@ #include "ivas_rom_rend.h" #include #include "wmc_auto.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------------------------* * Local constants diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 5290f0abb38914574207467677248cee7e2eab60..40cec01981ce99f119681f532ef0e8952ec505e3 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -30,10 +30,10 @@ *******************************************************************************************************/ -#include "basop_util.h" -#include "ivas_cnst.h" #include #include +#include "basop_util.h" +#include "ivas_cnst.h" #include "options.h" #include #include "cnst.h" @@ -42,8 +42,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #include "debug.h" #include "ivas_rom_binaural_crend_head.h" @@ -961,8 +960,8 @@ void rotateFrame_shd( /* initialize rotation matrices with zeros */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - set_val_Word16( SHrotmat_prev[i], 0, HEADROT_SHMAT_DIM ); - set_val_Word16( SHrotmat[i], 0, HEADROT_SHMAT_DIM ); + set16_fx( SHrotmat_prev[i], 0, HEADROT_SHMAT_DIM ); + set16_fx( SHrotmat[i], 0, HEADROT_SHMAT_DIM ); } /* calculate ambisonics rotation matrices for the previous and current frames */ @@ -1026,7 +1025,7 @@ void rotateFrame_shd( /* move Rmat to Rmat_prev */ FOR( i = 0; i < 3; i++ ) { - mvr2r_Word32( + MVR2R_WORD32( hCombinedOrientationData->Rmat_fx[subframe_idx][i], hCombinedOrientationData->Rmat_prev_fx[i], 3 ); @@ -1162,14 +1161,17 @@ void rotateFrame_sd( Word16 azimuth, elevation; Word32 azimuth_fx, elevation_fx; Word32 tmp = Q31_BY_SUB_FRAME_240; // Q31 - move32(); Word32 out_temp; Word32 tmp_gains_fx[MAX_CICP_CHANNELS - 1]; Word32 gains_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; Word32 gains_prev_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; Word32 output_tmp_fx[MAX_CICP_CHANNELS][L_FRAME48k]; Word32 cross_fade_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + push_wmops( "rotateFrame_sd" ); + + move32(); + nchan = add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); index_lfe = hTransSetup.index_lfe[0]; move16(); @@ -1205,9 +1207,9 @@ void rotateFrame_sd( FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { /* zero output and gain buffers */ - set_val_Word32( &output_tmp_fx[ch_in][offset], 0, subframe_len ); - set_val_Word32( gains_prev_fx[ch_in], 0, nchan ); - set_val_Word32( gains_fx[ch_in], 0, nchan ); + set32_fx( &output_tmp_fx[ch_in][offset], 0, subframe_len ); + set32_fx( gains_prev_fx[ch_in], 0, nchan ); + set32_fx( gains_fx[ch_in], 0, nchan ); /* set gains to passthrough by default */ gains_prev_fx[ch_in][ch_in] = ONE_IN_Q30; move32(); @@ -1324,7 +1326,7 @@ void rotateFrame_sd( /* move Rmat to Rmat_prev */ FOR( i = 0; i < 3; i++ ) { - mvr2r_Word32( + MVR2R_WORD32( hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], hCombinedOrientationData->Rmat_prev_fx[i], 3 ); @@ -1332,7 +1334,7 @@ void rotateFrame_sd( /* copy to output */ FOR( ch_out = 0; ch_out < nchan; ch_out++ ) { - mvr2r_Word32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); + MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); } pop_wmops(); @@ -1515,9 +1517,10 @@ void rotateFrame_shd_cldfb( /* calculate Ambisonics rotation matrix from the quaternion */ SHrotmatgen_fx( SHrotmat, Rmat, shd_rot_max_order ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( SHrotmat, HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM, "Fixed_SHrotmat.txt", NULL ); +#ifdef DEBUGGING + dbgwrite_txt( (const float *) SHrotmat[0], HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM, "Fixed_SHrotmat.txt", NULL ); #endif + /* rotation by mtx multiplication */ FOR( i = 0; i < numTimeSlots; i++ ) { @@ -1852,7 +1855,7 @@ void rotateFrame_sd_cldfb_fixed( } ELSE { - set_l( gains_fx[n], 0, nInChannels ); + set32_fx( gains_fx[n], 0, nInChannels ); gains_fx[n][n] = 0x7fffffff; // Q31 move32(); } @@ -1861,8 +1864,8 @@ void rotateFrame_sd_cldfb_fixed( /* Apply panning gains by mtx multiplication*/ FOR( n = 0; n < nInChannels; n++ ) { - set_l( realRot_fx[n], 0, shl( nb_band, 2 ) ); - set_l( imagRot_fx[n], 0, shl( nb_band, 2 ) ); + set32_fx( realRot_fx[n], 0, shl( nb_band, 2 ) ); + set32_fx( imagRot_fx[n], 0, shl( nb_band, 2 ) ); FOR( m = 0; m < nInChannels; m++ ) { g1_fx = gains_fx[m][n]; @@ -3544,7 +3547,7 @@ void SHrotmatgen_fx( #ifdef MSAN_FIX FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - set_s( R_lm1[i], 0, HEADROT_SHMAT_DIM ); + set16_fx( R_lm1[i], 0, HEADROT_SHMAT_DIM ); } #endif Word16 R_l[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; @@ -3585,7 +3588,7 @@ void SHrotmatgen_fx( move16(); FOR( l = 2; l <= order; l++ ) { - set_val_Word16( &R_l[0][0], 0, HEADROT_SHMAT_DIM2 ); + set16_fx( &R_l[0][0], 0, HEADROT_SHMAT_DIM2 ); FOR( m = -l; m <= l; m++ ) { d = 0; diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index c2aeaef5d038b8b674d78bd6260ef2c2b4468244..9c95a2d8cfd8db7982bec7209dd36664df56179b 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -33,8 +33,7 @@ #include #include "options.h" #include "prot.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" diff --git a/lib_rend/ivas_shoebox.c b/lib_rend/ivas_shoebox.c index f09cbeac273aa7fa91e4dd65c41cb80e61989bd4..5464c488239791b55dc84254f1ecac6dbcdcb8d2 100644 --- a/lib_rend/ivas_shoebox.c +++ b/lib_rend/ivas_shoebox.c @@ -37,6 +37,7 @@ #include "ivas_stat_rend.h" #include "ivas_cnst.h" #include "prot.h" +#include "prot_fx.h" #include "wmc_auto.h" #include "ivas_rom_com.h" #ifdef IVAS_FLOAT_FIXED @@ -200,8 +201,8 @@ void ivas_shoebox_init( /* Positions */ - set_l( &obj->src_pos_fx[0], 0, 75U ); - set_l( &obj->src_dist_fx[0], 0, 25U ); + set32_fx( &obj->src_pos_fx[0], 0, 75U ); + set32_fx( &obj->src_dist_fx[0], 0, 25U ); FOR( i = 0; i < 3; i++ ) { @@ -905,7 +906,7 @@ void ivas_shoebox_set_scene( } move16(); - set_l( &obj->src_pos_fx[0], 0, 75U ); + set32_fx( &obj->src_pos_fx[0], 0, 75U ); obj->list_pos_fx[0] = list_pos_fx[0]; obj->list_pos_fx[1] = list_pos_fx[1]; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index b8ac1194b19db82e8675e78180893fbe52b959ec..869fd98bd13b768813871890d665c38634b3b5ce 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -451,6 +451,7 @@ typedef struct dirac_output_synthesis_state_structure Word16 direct_power_factor_q; Word16 diffuse_power_factor_q; + Word16 diff_dir_power_factor_len; Word32 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ Word16 proto_power_smooth_q; diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index 2e14388f82ec9d1c0af40b9054be643dbf4ed0b6..880844a9f3bb36756781629267e279d2a1f78872 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -31,22 +31,19 @@ *******************************************************************************************************/ #include +#include #include "options.h" #include "prot.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" -#endif -#include "ivas_prot.h" -#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif +#include "ivas_prot.h" #include "ivas_prot_rend.h" #include "math.h" -#include #include "wmc_auto.h" -#ifdef DUMPS_ENABLED -#include +#ifdef DEBUGGING +#include "debug.h" #endif /*------------------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index bc8090c7a71161984abb0d3f17774527db58d9e4..c6524aeed35ec344c1a99dc53fc6df24e28ce31b 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -35,13 +35,11 @@ #include #include #include "prot.h" -#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 2ce92589289cd2d1bb515560d8d700615f5bbce2..e0bc60311cc89460f7eceb792915c4f69eec5a05 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -47,8 +47,7 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #include "ivas_prot_fx.h" -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "debug.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) @@ -131,8 +130,11 @@ typedef struct AUDIO_CONFIG inConfig; IVAS_REND_InputId id; IVAS_REND_AudioBuffer inputBuffer; - float gain; /* Linear, not in dB */ +#ifndef IVAS_FLOAT_FIXED + float gain; /* Linear, not in dB */ +#else Word32 gain_fx; /* Linear, not in dB */ +#endif rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ } input_base; @@ -385,8 +387,6 @@ static void freeMasaExtRenderer( MASA_EXT_REND_HANDLE *hMasaExtRendOut ); #ifdef IVAS_FLOAT_FIXED // TOBE REMOVED static void intermidiate_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - float *output_f_flt[], /* i/o: input/output signals in time domain */ Word16 to_fix ); #endif /*-------------------------------------------------------------------* @@ -573,7 +573,7 @@ static void copyBufferTo2dArray_fx( return; } -#endif +#else static void copyBufferTo2dArray( const IVAS_REND_AudioBuffer buffer, float array[][L_FRAME48k] ) @@ -594,6 +594,7 @@ static void copyBufferTo2dArray( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void accumulate2dArrayToBuffer_fx( Word32 array[][L_FRAME48k], @@ -615,7 +616,7 @@ static void accumulate2dArrayToBuffer_fx( return; } -#endif +#else static void accumulate2dArrayToBuffer( float array[][L_FRAME48k], IVAS_REND_AudioBuffer *buffer ) @@ -634,6 +635,7 @@ static void accumulate2dArrayToBuffer( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * limitRendererOutput() @@ -1164,19 +1166,19 @@ static LSSETUP_CUSTOM_STRUCT defaultCustomLs( set_zero( ls.ls_azimuth, MAX_OUTPUT_CHANNELS ); #endif - set_val_Word32( ls.ls_azimuth_fx, 0, MAX_OUTPUT_CHANNELS ); + set32_fx( ls.ls_azimuth_fx, 0, MAX_OUTPUT_CHANNELS ); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED set_zero( ls.ls_elevation, MAX_OUTPUT_CHANNELS ); #endif - set_val_Word32( ls.ls_elevation_fx, 0, MAX_OUTPUT_CHANNELS ); + set32_fx( ls.ls_elevation_fx, 0, MAX_OUTPUT_CHANNELS ); ls.num_lfe = 0; move16(); - set_s( ls.lfe_idx, 0, MAX_OUTPUT_CHANNELS ); + set16_fx( ls.lfe_idx, 0, MAX_OUTPUT_CHANNELS ); ls.separate_ch_found = 0; move16(); - set_val_Word16( ls.separate_ch_gains_fx, 0, MAX_OUTPUT_CHANNELS ); + set16_fx( ls.separate_ch_gains_fx, 0, MAX_OUTPUT_CHANNELS ); return ls; } @@ -2088,7 +2090,7 @@ static void initRotGains_fx( /* Set gains to passthrough */ FOR( i = 0; i < MAX_INPUT_CHANNELS; i++ ) { - set_val_Word16( rot_gains[i], 0, MAX_INPUT_CHANNELS ); + set16_fx( rot_gains[i], 0, MAX_INPUT_CHANNELS ); rot_gains[i][i] = ONE_IN_Q14; move16(); } @@ -2104,7 +2106,7 @@ static void initRotGainsWord32_fx( /* Set gains to passthrough */ FOR( i = 0; i < MAX_INPUT_CHANNELS; i++ ) { - set_val_Word32( rot_gains[i], 0, MAX_INPUT_CHANNELS ); + set32_fx( rot_gains[i], 0, MAX_INPUT_CHANNELS ); rot_gains[i][i] = ONE_IN_Q30; move16(); } @@ -2152,12 +2154,12 @@ static void initRendInputBase_fx( inputBase->inputBuffer.data_fx = dataBuf; IF( inputBase->inputBuffer.data_fx != NULL ) { - set_val_Word32( inputBase->inputBuffer.data_fx, 0, dataBufSize ); + set32_fx( inputBase->inputBuffer.data_fx, 0, dataBufSize ); } return; } -#endif +#else static void initRendInputBase( input_base *inputBase, const AUDIO_CONFIG inConfig, @@ -2182,7 +2184,7 @@ static void initRendInputBase( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static IVAS_ISM_METADATA defaultObjectPosition( @@ -2724,7 +2726,7 @@ static void setZeroPanMatrix_fx( FOR( i = 0; i < MAX_INPUT_CHANNELS; ++i ) { - set_val_Word32( panMatrix[i], 0, MAX_OUTPUT_CHANNELS ); + set32_fx( panMatrix[i], 0, MAX_OUTPUT_CHANNELS ); } return; @@ -4119,7 +4121,7 @@ static ivas_error initMcBinauralRendering( move16(); test(); - IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && inputMc->hReverb == NULL ) + IF( ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) && NE_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */ } @@ -4376,7 +4378,7 @@ static lfe_routing defaultLfeRouting( FOR( i = 0; i < RENDERER_MAX_INPUT_LFE_CHANNELS; ++i ) { - set_val_Word32( routing.lfePanMtx_fx[i], 0, IVAS_MAX_OUTPUT_CHANNELS ); + set32_fx( routing.lfePanMtx_fx[i], 0, IVAS_MAX_OUTPUT_CHANNELS ); } routing.pan_lfe = false; move16(); @@ -4528,7 +4530,7 @@ static ivas_error setRendInputActiveMc( initRotGains( inputMc->rot_gains_prev ); initRotGainsWord32_fx( inputMc->rot_gains_prev_fx ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); - set_val_Word32( inputMc->lfeDelayBuffer_fx, 0, MAX_BIN_DELAY_SAMPLES ); + set32_fx( inputMc->lfeDelayBuffer_fx, 0, MAX_BIN_DELAY_SAMPLES ); inputMc->binauralDelaySmp = 0; move16(); @@ -5339,7 +5341,7 @@ static void clearInputMasa( freeMasaExtRenderer( &inputMasa->hMasaExtRend ); - initRendInputBase( &inputMasa->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); + initRendInputBase_fx( &inputMasa->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); return; } @@ -5501,7 +5503,7 @@ ivas_error IVAS_REND_Open( FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + initRendInputBase_fx( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); hIvasRend->inputsMasa[i].metadataHasBeenFed = false; hIvasRend->inputsMasa[i].bufferData = NULL; @@ -5684,7 +5686,7 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( customLs.num_lfe = rendCustomLsLayout.num_lfe; move16(); - mvs2s( rendCustomLsLayout.lfe_idx, customLs.lfe_idx, rendCustomLsLayout.num_lfe ); + Copy( rendCustomLsLayout.lfe_idx, customLs.lfe_idx, rendCustomLsLayout.num_lfe ); return customLs; } @@ -7352,7 +7354,7 @@ ivas_error IVAS_REND_FeedInputAudio_fx( inputBase->inputBuffer.config = inputAudio.config; - mvr2r_Word32( inputAudio.data_fx, inputBase->inputBuffer.data_fx, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); + MVR2R_WORD32( inputAudio.data_fx, inputBase->inputBuffer.data_fx, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); inputBase->numNewSamplesPerChannel = inputAudio.config.numSamplesPerChannel; move32(); @@ -7428,8 +7430,7 @@ ivas_error IVAS_REND_FeedInputAudio( inputBase->inputBuffer.config = inputAudio.config; #ifdef IVAS_FLOAT_FIXED - mvr2r_Word32( inputAudio.data_fx, inputBase->inputBuffer.data_fx, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); - + MVR2R_WORD32( inputAudio.data_fx, inputBase->inputBuffer.data_fx, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); #endif mvr2r( inputAudio.data, inputBase->inputBuffer.data, inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels ); @@ -8757,7 +8758,7 @@ static ivas_error rotateFrameMc_fx( /* initialize gains to passthrough */ FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { - set_val_Word32( gains[ch_in], 0, nchan ); + set32_fx( gains[ch_in], 0, nchan ); gains[ch_in][ch_in] = ONE_IN_Q30; move32(); } @@ -8784,7 +8785,7 @@ static ivas_error rotateFrameMc_fx( ELSE { /* Set to identity */ - set_val_Word32( Rmat_fx[i], 0, 3 ); + set32_fx( Rmat_fx[i], 0, 3 ); Rmat_fx[i][i] = ONE_IN_Q30; move32(); } @@ -8871,7 +8872,7 @@ static ivas_error rotateFrameMc_fx( /* move gains to gains_prev */ FOR( i = 0; i < nchan; i++ ) { - mvr2r_Word32( gains[i], gains_prev[i], nchan ); + MVR2R_WORD32( gains[i], gains_prev[i], nchan ); } } @@ -9072,7 +9073,7 @@ static ivas_error rotateFrameSba_fx( /* initialize rotation matrices with zeros */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - set_val_Word16( gains[i], 0, HEADROT_SHMAT_DIM ); + set16_fx( gains[i], 0, HEADROT_SHMAT_DIM ); } FOR( i = 0; i < 3; i++ ) @@ -9088,7 +9089,7 @@ static ivas_error rotateFrameSba_fx( ELSE { /* Set to identity */ - set_val_Word32( Rmat[i], 0, 3 ); + set32_fx( Rmat[i], 0, 3 ); Rmat[i][i] = ONE_IN_Q30; move32(); } @@ -9096,9 +9097,9 @@ static ivas_error rotateFrameSba_fx( /* calculate ambisonics rotation matrices for the previous and current frames */ SHrotmatgen_fx( gains, Rmat, shd_rot_max_order ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( gains, HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM, "Fixed_code_gains.txt", NULL ); - dbgwrite_txt( Rmat, 3 * 3, "Fixed_code_Rmat.txt", NULL ); +#ifdef DEBUGGING + dbgwrite_txt( (const float *) ( gains[0] ), HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM, "Fixed_code_gains.txt", NULL ); + dbgwrite_txt( (const float *) ( Rmat[0] ), 3 * 3, "Fixed_code_Rmat.txt", NULL ); #endif FOR( i = 0; i < subframe_len; i++ ) { @@ -10506,7 +10507,7 @@ static ivas_error renderLfeToBinaural_fx( v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); // Qinp-1 /* Save remaining LFE samples of current frame for next frame */ - mvr2r_Word32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); + MVR2R_WORD32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); r_shift = sub( sub( in_q, 1 ), out_q ); IF( r_shift != 0 ) @@ -10663,7 +10664,7 @@ static ivas_error renderMcToBinaural( { tmpRotBuffer = mcInput->base.inputBuffer; tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); - set_val_Word32( tmpRotBuffer.data_fx, 0, imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) ); + set32_fx( tmpRotBuffer.data_fx, 0, imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) ); IF( NE_32( ( error = rotateFrameMc_fx( mcInput->base.inputBuffer, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, mcInput->base.ctx.pCombinedOrientationData, mcInput->rot_gains_prev_fx, mcInput->efapInWrapper.hEfap, tmpRotBuffer ) ), IVAS_ERR_OK ) ) { @@ -10875,7 +10876,7 @@ static ivas_error renderMcToBinauralRoom( { tmpRotBuffer = mcInput->base.inputBuffer; tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); - set_val_Word32( tmpRotBuffer.data_fx, 0, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); + set32_fx( tmpRotBuffer.data_fx, 0, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); IF( NE_32( ( error = rotateFrameMc_fx( mcInput->base.inputBuffer, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, mcInput->base.ctx.pCombinedOrientationData, mcInput->rot_gains_prev_fx, @@ -11061,7 +11062,7 @@ static ivas_error renderMcCustomLsToBinauralRoom( { tmpRotBuffer = mcInput->base.inputBuffer; tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); - set_val_Word32( tmpRotBuffer.data_fx, 0, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); + set32_fx( tmpRotBuffer.data_fx, 0, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); IF( NE_32( ( error = rotateFrameMc_fx( mcInput->base.inputBuffer, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, mcInput->base.ctx.pCombinedOrientationData, mcInput->rot_gains_prev_fx, @@ -11084,7 +11085,7 @@ static ivas_error renderMcCustomLsToBinauralRoom( tmpMcBuffer.config.numChannels = tmp; move16(); tmpMcBuffer.data_fx = malloc( imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) * sizeof( Word32 ) ); - set_val_Word32( tmpMcBuffer.data_fx, 0, imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) ); + set32_fx( tmpMcBuffer.data_fx, 0, imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) ); IF( combinedOrientationEnabled ) { @@ -11629,7 +11630,7 @@ static ivas_error renderSbaToBinaural( tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); /* copy input for in-place rotation */ - mvr2r_Word32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); IF( NE_16( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, sbaInput->rot_gains_prev_fx, tmpRotBuffer ) ), @@ -11799,7 +11800,7 @@ static ivas_error renderSbaToBinauralRoom( tmpRotBuffer.data_fx = malloc( imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) * sizeof( Word32 ) ); /* copy input for in-place rotation */ - mvr2r_Word32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); IF( NE_32( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, @@ -11822,7 +11823,7 @@ static ivas_error renderSbaToBinauralRoom( tmpMcBuffer.config.numChannels = tmp; move16(); tmpMcBuffer.data_fx = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( Word32 ) ); - set_val_Word32( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); + set32_fx( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); IF( combinedOrientationEnabled ) { @@ -12363,7 +12364,7 @@ static void renderMasaToMasa( test(); IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 1 ) && EQ_16( outAudio.config.numChannels, 2 ) ) { - mvr2r_Word32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); + MVR2R_WORD32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); } ELSE IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 2 ) && EQ_16( outAudio.config.numChannels, 1 ) ) { @@ -12588,14 +12589,11 @@ static ivas_error renderInputMasa( IVAS_REND_AudioBuffer outAudio ) { IVAS_REND_AudioBuffer inAudio; - int16_t ch; - int16_t maxBin; - float *tmpBuffer[MAX_OUTPUT_CHANNELS]; - float tmpBuffer_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED + Word16 ch; + Word16 maxBin; Word32 *tmpBuffer_fx[MAX_OUTPUT_CHANNELS]; Word32 tmpBuffer_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#endif + IF( !masaInput->metadataHasBeenFed ) { return IVAS_ERR_MISSING_METADATA; @@ -12609,70 +12607,56 @@ static ivas_error renderInputMasa( masaInput->base.numNewSamplesPerChannel = 0; move32(); -#ifdef IVAS_FLOAT_FIXED - masaInput->base.gain = fix_to_float( masaInput->base.gain_fx, Q30 ); *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. -#endif // IVAS_FLOAT_FIXED - - /* Apply input gain to new audio */ - v_multc( inAudio.data, masaInput->base.gain, inAudio.data, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); - maxBin = (Word16) ( *masaInput->base.ctx.pOutSampleRate * INV_CLDFB_BANDWIDTH ); + maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( masaInput->base.ctx.pCombinedOrientationData ) ); - if ( EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) + IF( EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) { /* MASA prerendering path for MASA -> MASA */ renderMasaToMasa( masaInput, outAudio ); -#ifdef IVAS_FLOAT_FIXED - for ( Word16 i = 0; i < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; i++ ) - { - outAudio.data[i] = (float) outAudio.data_fx[i] / ( 1 << *outAudio.pq_fact ); - } -#endif } - else + ELSE { /* MASA external renderer -> other formats */ - int16_t num_subframes; - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) - { - tmpBuffer[ch] = tmpBuffer_buff[ch]; - } -#ifdef IVAS_FLOAT_FIXED - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + Word16 num_subframes, exp; + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { tmpBuffer_fx[ch] = tmpBuffer_buff_fx[ch]; } copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); -#endif - copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer_buff ); - num_subframes = (int16_t) ( masaInput->base.inputBuffer.config.numSamplesPerChannel / ( *masaInput->base.ctx.pOutSampleRate / ( IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) ); + num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); + num_subframes = shr( num_subframes, sub( 15, exp ) ); - switch ( masaInput->hMasaExtRend->renderer_type ) + SWITCH( masaInput->hMasaExtRend->renderer_type ) { case RENDERER_DIRAC: -#ifdef IVAS_FLOAT_FIXED + copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); -#else - copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); -#endif -#ifdef IVAS_FLOAT_FIXED #if 1 // TOBE REMOVED - intermidiate_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 1 ); + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 1 ); #endif FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; } + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + { + Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); + + *outAudio.pq_fact = Q11; + move16(); + FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); @@ -12680,29 +12664,29 @@ static ivas_error renderInputMasa( } #if 1 // TOBE REMOVED - intermidiate_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 0 ); -#endif -#else - ivas_masa_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer, num_subframes ); + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 0 ); #endif - break; + BREAK; case RENDERER_STEREO_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: -#ifdef IVAS_FLOAT_FIXED + copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); -#else - copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); -#endif - ivas_masa_ext_rend_parambin_render( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer, num_subframes ); - break; + + Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + + ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); + *outAudio.pq_fact = Q11; + move16(); + BREAK; case RENDERER_DISABLE: - break; /* This happens for 1TC MASA to MONO where we just copy input transport to output */ + BREAK; /* This happens for 1TC MASA to MONO where we just copy input transport to output */ default: return ( IVAS_ERROR( IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED, "Wrong output config for MASA input in external renderer\n" ) ); } - accumulate2dArrayToBuffer( tmpBuffer_buff, &outAudio ); + accumulate2dArrayToBuffer_fx( tmpBuffer_buff_fx, &outAudio ); } return IVAS_ERR_OK; @@ -12781,23 +12765,43 @@ static ivas_error renderInputMasa( return IVAS_ERR_OK; } #endif - +#ifdef IVAS_FLOAT_FIXED static ivas_error renderActiveInputsMasa( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int16_t i; + Word16 i; input_masa *pCurrentInput; ivas_error error; -#ifdef IVAS_FLOAT_FIXED - if ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) + + FOR( ( i = 0, pCurrentInput = hIvasRend->inputsMasa ); i < RENDERER_MAX_MASA_INPUTS; ( ++i, ++pCurrentInput ) ) { - for ( i = 0; i < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; i++ ) + IF( EQ_16( pCurrentInput->base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + /* Skip inactive inputs */ + CONTINUE; + } + + *outAudio.pq_fact = Q8; + move16(); + + IF( NE_32( ( error = renderInputMasa( pCurrentInput, hIvasRend->outputConfig, outAudio ) ), IVAS_ERR_OK ) ) { - outAudio.data[i] = (float) outAudio.data_fx[i] / ( 1 << *outAudio.pq_fact ); + return error; } } -#endif + + return IVAS_ERR_OK; +} +#else +static ivas_error renderActiveInputsMasa( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_AudioBuffer outAudio ) +{ + int16_t i; + input_masa *pCurrentInput; + ivas_error error; + for ( i = 0, pCurrentInput = hIvasRend->inputsMasa; i < RENDERER_MAX_MASA_INPUTS; ++i, ++pCurrentInput ) { if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) @@ -12806,27 +12810,15 @@ static ivas_error renderActiveInputsMasa( continue; } -#ifdef IVAS_FLOAT_FIXED - *outAudio.pq_fact = Q8; -#endif // IVAS_FLOAT_FIXED if ( ( error = renderInputMasa( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( getAudioConfigType( hIvasRend->outputConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) - { - for ( Word16 k = 0; k < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; k++ ) - { - outAudio.data_fx[k] = (Word32) outAudio.data[k] * ( 1 << *outAudio.pq_fact ); - } - } -#endif } return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_REND_GetMasaMetadata( ) @@ -13289,7 +13281,7 @@ static ivas_error getSamplesInternal( /* Clear original output buffer */ set_zero( outAudio.data, imult1616( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ) ); - set_val_Word32( outAudio.data_fx, 0, imult1616( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ) ); + set32_fx( outAudio.data_fx, 0, imult1616( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ) ); IF( NE_32( ( error = renderActiveInputsIsm( hIvasRend, outAudio ) ), IVAS_ERR_OK ) ) { @@ -13310,18 +13302,10 @@ static ivas_error getSamplesInternal( test(); test(); - IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsIsm[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - } - ELSE - { - floatToFixed_arrL( outAudio.data, outAudio.data_fx, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - fixedToFloat_arrL( outAudio.data_fx, outAudio.data, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); - } + + Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); + limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); + /* update global cominbed orientation start index */ ivas_combined_orientation_update_start_index( hIvasRend->hCombinedOrientationData, outAudio.config.numSamplesPerChannel ); @@ -13564,8 +13548,8 @@ void IVAS_REND_Close( closeHeadRotation( hIvasRend ); - ivas_external_orientation_close_fx( &hIvasRend->hExternalOrientationData ); - ivas_combined_orientation_close_fx( &hIvasRend->hCombinedOrientationData ); + ivas_external_orientation_close( &hIvasRend->hExternalOrientationData ); + ivas_combined_orientation_close( &hIvasRend->hCombinedOrientationData ); free( hIvasRend ); *phIvasRend = NULL; @@ -14804,7 +14788,7 @@ static ivas_error initMasaExtRenderer( { for ( i = 0; i < hMasaExtRend->nchan_input; i++ ) { - if ( ( error = openCldfb( &( hMasaExtRend->cldfbAnaRend[i] ), CLDFB_ANALYSIS, *inputMasa->base.ctx.pOutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas( &( hMasaExtRend->cldfbAnaRend[i] ), CLDFB_ANALYSIS, *inputMasa->base.ctx.pOutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -14812,7 +14796,7 @@ static ivas_error initMasaExtRenderer( for ( i = 0; i < hMasaExtRend->nchan_output; i++ ) { - if ( ( error = openCldfb( &( hMasaExtRend->cldfbSynRend[i] ), CLDFB_SYNTHESIS, *inputMasa->base.ctx.pOutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb_ivas( &( hMasaExtRend->cldfbSynRend[i] ), CLDFB_SYNTHESIS, *inputMasa->base.ctx.pOutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -15052,7 +15036,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbAnaRend[i] != NULL ) { - deleteCldfb_ivas( &hMasaExtRend->cldfbAnaRend[i] ); + deleteCldfb_ivas_fx( &hMasaExtRend->cldfbAnaRend[i] ); } } @@ -15060,7 +15044,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbSynRend[i] != NULL ) { - deleteCldfb_ivas( &hMasaExtRend->cldfbSynRend[i] ); + deleteCldfb_ivas_fx( &hMasaExtRend->cldfbSynRend[i] ); } } @@ -15144,19 +15128,16 @@ static void freeMasaExtRenderer( #ifdef IVAS_FLOAT_FIXED static void intermidiate_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - Word32 *output_f[], /* i/o: input/output signals in time domain */ - float *output_f_flt[], /* i/o: input/output signals in time domain */ Word16 to_fix ) { SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; DIRAC_DEC_STACK_MEM DirAC_mem; - int16_t i, ch, q_cldfb; + Word16 ch; DIRAC_REND_HANDLE hDirACRend; - int16_t subframe_idx; - int16_t slot_idx; - int16_t nchan_transport; - int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; + Word16 subframe_idx; + Word16 slot_idx; + Word16 nchan_transport; Word16 tmp; hDirACRend = hMasaExtRend->hDirACRend; @@ -15170,120 +15151,118 @@ static void intermidiate_ext_dirac_render( DirAC_mem = hDirACRend->stack_mem; - if ( to_fix ) + IF( to_fix ) { DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; - q_cldfb = 11; - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - floatToFixed_arrL( output_f_flt[i], output_f[i], q_cldfb, L_FRAME48k ); - } - - for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + move16(); + move16(); + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - else - { - if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) - { - if ( masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( masa_band_mapping != NULL ) ) || - hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - } - else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - } + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); } + Word16 num_channels_dir = hDirACRend->num_outputs_dir; + move16(); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); } - if ( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) + + IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp; + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp ); + move16(); } scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + move16(); scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) + move16(); + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); + move16(); } - if ( hDirACRend->proto_signal_decorr_on == 1 ) + IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); - hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; + hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) { - Word16 shift; + Word16 shift, norm1, norm2; Word32 tmp1, tmp2; maximum_abs_32_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, &tmp2 ); maximum_abs_32_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, &tmp1 ); - shift = s_min( ( tmp1 == 0 ) ? 31 : norm_l( tmp1 ), ( tmp2 == 0 ) ? 31 : norm_l( tmp2 ) ); - Word16 hr_exp = 31 - shift; + IF( tmp1 == 0 ) + { + norm1 = 31; + move16(); + } + ELSE + { + norm1 = norm_l( tmp1 ); + } + + IF( tmp2 == 0 ) + { + norm2 = 31; + move16(); + } + ELSE + { + norm2 = norm_l( tmp2 ); + } + + shift = s_min( norm1, norm2 ); + + Word16 hr_exp = sub( 31, shift ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, ( 31 - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) - hr_exp ); - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hr_exp; + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = sub( 31, hr_exp ); } FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -15292,32 +15271,38 @@ static void intermidiate_ext_dirac_render( FOR( ch = 0; ch < nchan_transport; ch++ ) { hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; + move16(); } } - hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; + hDirACRend->proto_frame_dec_f_q = sub( 31, hDirACRend->proto_frame_dec_f_q ); + move16(); - if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, tmp ); + move16(); tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); + move16(); } tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, tmp ); + move16(); - if ( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp ); + move16(); } } - else + ELSE { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) { @@ -15326,17 +15311,15 @@ static void intermidiate_ext_dirac_render( { scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; + move16(); } } - for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) { scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; - } - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - fixedToFloat_arrL( output_f[i], output_f_flt[i], hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state, L_FRAME48k ); + move16(); } } } diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index a4994e544b0f554c5f8ee9b7de50208c5695186c..e8bbe3653bccd9541d4ad1225e01e6934a6d0f2a 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -34,7 +34,7 @@ #include #include "prot.h" #include "ivas_prot_rend.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot.h" /*---------------------------------------------------------------------* diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index 9127fe84758be7e3e33d6f8a737332781d7ae6a8..ae35e6d463de7d6f9a188dab4dcf9fe393721f09 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -35,7 +35,7 @@ #include #include #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif // IVAS_FLOAT_FIXED #define META_LINE_LENGTH 200 /* max number of characters at one line of metadata input/output file */ diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index f5a815377b6aabec172d38302acc3c465fa5e7e3..47ba31fb8775a2f2916fc321acccb7ccceac77cb 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -36,7 +36,7 @@ #include #include "prot.h" #ifdef IVAS_FLOAT_FIXED -#include "prot_fx2.h" +#include "prot_fx.h" #endif diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index 00c23a497da35bb2e23f94e9e01435d2910e859e..aa828b0eef5911f63a7d40075ce76e6049385f7e 100644 --- a/lib_util/vector3_pair_file_reader.c +++ b/lib_util/vector3_pair_file_reader.c @@ -38,8 +38,7 @@ #include "prot.h" #include "options.h" /* only included to get access to the feature-defines */ #ifdef IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" +#include "prot_fx.h" #include "ivas_prot_fx.h" #endif