From b2876d944cc18a6bed1dd3fa218124034c567b47 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 4 Jul 2024 11:56:48 +0530 Subject: [PATCH 1/2] BASOP and instrumentation changes for lib_com, lib_rend modules files --- lib_com/ari_hm_fx.c | 14 +- lib_com/arith_coder.c | 6 +- lib_com/arith_coder_fx.c | 3 + lib_com/basop_tcx_utils.c | 3 +- lib_com/bitalloc.c | 3 + lib_com/bitalloc_fx.c | 36 +- lib_com/ivas_cnst.h | 1 + lib_com/ivas_prot_fx.h | 18 + lib_com/lerp.c | 128 ++- lib_com/log2.c | 6 +- lib_com/logqnorm_fx.c | 9 +- lib_com/low_rate_band_att_fx.c | 10 +- lib_com/lpc_tools.c | 22 +- lib_com/lpc_tools_fx.c | 74 +- lib_com/lsf_dec_bfi_fx.c | 6 +- lib_com/lsf_msvq_ma_fx.c | 3 +- lib_com/lsf_tools.c | 150 +-- lib_com/prot.h | 11 - lib_com/tools.c | 108 +- lib_com/tools_fx.c | 201 +++- lib_com/trans_direct_fx.c | 34 +- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_init_dec.c | 8 +- lib_dec/ivas_ism_dec.c | 2 +- lib_dec/pit_dec.c | 2 + lib_rend/ivas_allrad_dec.c | 6 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 1071 ++++++++++-------- lib_rend/ivas_dirac_rend.c | 1171 +++++++++++--------- lib_rend/ivas_efap.c | 686 ++++++++---- lib_rend/ivas_hrtf.c | 4 +- lib_rend/ivas_limiter.c | 200 ++-- lib_rend/ivas_masa_merge.c | 255 +++-- lib_rend/ivas_prot_rend.h | 108 +- lib_rend/ivas_stat_rend.h | 48 +- lib_rend/lib_rend.c | 20 +- 35 files changed, 2647 insertions(+), 1782 deletions(-) diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index e7032468b..425823d27 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -35,7 +35,7 @@ void UnmapIndex( *FractionalResolution = kLtpHmFractionalResolution; move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][sub( Multiplier, 1 )] ), 8 ); move32(); } ELSE @@ -75,6 +75,7 @@ void UnmapIndex( } } *Lag = L_deposit_l( Lag16 ); + move32(); } } @@ -95,7 +96,7 @@ void ConfigureContextHm( Bandwidth = 0; move16(); - IF( GE_16( NumCoeffs, 256 ) ) + if ( GE_16( NumCoeffs, 256 ) ) { Bandwidth = 1; move16(); @@ -104,7 +105,7 @@ void ConfigureContextHm( SmallerLags = 0; move16(); test(); - IF( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) + if ( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) { SmallerLags = 1; move16(); @@ -134,6 +135,7 @@ void ConfigureContextHm( } } hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); + move16(); /* Set up and fill holeIndices */ hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; @@ -161,6 +163,7 @@ void ConfigureContextHm( } } hm_cfg->numHoleIndices = (Word16) ( tmp - hm_cfg->holeIndices ); + move16(); *tmp++ = NumCoeffs; move16(); /* Add extremal element signaling the end of the buffer */ } @@ -186,7 +189,7 @@ Word16 CountIndexBits( } -int tcx_hm_render( +Word32 tcx_hm_render( Word32 lag, /* i: pitch lag Q0 */ Word16 fract_res, /* i: fractional resolution of the lag Q0 */ Word16 p[] /* o: harmonic model Q13 */ @@ -231,6 +234,7 @@ int tcx_hm_render( FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); + move16(); } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) @@ -279,7 +283,7 @@ void tcx_hm_modify_envelope( l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); FOR( x = l1; x <= l2; ++x ) { - env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[add( sub( x, k ), kTcxHmParabolaHalfWidth )] ); move32(); } diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index 58729a004..08c972ea9 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -168,11 +168,11 @@ void powfp_odd2_evs( h = shl( 1, k ); /* highest bit of exp2 */ out2 = base; move16(); - out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ + out = mult_r( out, pows[add( k, 1 )] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */ /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */ if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[add( k, 1 )] ); } h = shr( h, 1 ); @@ -315,7 +315,7 @@ void tcx_arith_scale_envelope_flt( IF( tmp <= 0 ) { tmp = 0; - + move16(); FOR( k = 0; k < L_frame; k++ ) { s_env[k] = 0; diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 69d646406..54533aaca 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -196,6 +196,7 @@ void tcx_arith_scale_envelope( Word16 mean_e, tmp, tmp2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -264,6 +265,7 @@ void tcx_arith_scale_envelope( IF( tmp <= 0 ) { tmp = 0; + move16(); set16_fx( s_env, 0, L_frame ); } ELSE @@ -429,6 +431,7 @@ void tcx_arith_scale_envelope( L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); L_tmp = L_min( L_tmp, a ); s_env[k] = round_fx( L_tmp ); + move16(); } } diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index f189a5752..5730b2212 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -73,7 +73,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /* short-cut, to avoid calling of BASOP_getTables() */ ptwiddle = SineTable512_fx; step = 8; - + move16(); /*ODFT*/ assert( lpcOrder < FDNS_NPTS ); @@ -106,6 +106,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor j = FDNS_NPTS - 1; k = 0; move16(); + move16(); FOR( i = 0; i < FDNS_NPTS / 2; i++ ) { diff --git a/lib_com/bitalloc.c b/lib_com/bitalloc.c index 975740a9c..7e1c92f9c 100644 --- a/lib_com/bitalloc.c +++ b/lib_com/bitalloc.c @@ -849,6 +849,8 @@ int16_t BitAllocWB( factor_fx[0] = 16384; /*Q13 move16(); */ factor_fx[1] = 24576; /*Q13 move16(); */ + move16(); + move16(); { R_diff_32_fx[0] = L_sub( Ravg_sub_32_fx[0], Ravg_sub_32_fx[1] ); move32(); /*Q16 */ @@ -1013,6 +1015,7 @@ int16_t BitAllocWB( { L_tmp = L_add( L_tmp, Rsubband_buf[i] ); /*Q21 */ R[i] = extract_h( L_shr( Rsubband_buf[i], 5 ) ); /*Q0 */ + move16(); } t_fx = extract_h( L_shr( L_tmp, 5 ) ); /*Q0 */ diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index 8ae8a674f..78f6ac276 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -26,6 +26,7 @@ void bitalloc_fx( Word16 ii; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Word16 SFM_thr = SFM_G1G2; move16(); @@ -294,7 +295,7 @@ Word16 BitAllocF_fx( t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); + tmp = add( band_end_HQ[sub( num_env_bands, 1 )], shl( band_end_HQ[sub( num_env_bands, 1 )], 1 ) ); exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -318,6 +319,7 @@ Word16 BitAllocF_fx( ELSE { Rsubband_w32_fx[i] = L_deposit_l( 0 ); + move32(); } } } @@ -338,7 +340,7 @@ Word16 BitAllocF_fx( t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); + tmp = add( band_end_HQ[sub( N, 1 )], shl( band_end_HQ[sub( N, 1 )], 1 ) ); exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -346,7 +348,7 @@ Word16 BitAllocF_fx( exp1 = add( 29, sub( exp2, exp1 ) ); FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[sub( N, 1 )] ), L_tmp1 ); Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -361,6 +363,7 @@ Word16 BitAllocF_fx( ELSE { Rsubband_w32_fx[i] = L_deposit_l( 0 ); + move32(); } } } @@ -397,6 +400,7 @@ Word16 BitAllocF_fx( ELSE { Rsubband_w32_fx[i] = L_deposit_l( 0 ); + move32(); } } } @@ -416,6 +420,7 @@ Word16 BitAllocF_fx( IF( ( LT_32( Rsubband_w32_fx[i], L_shl( add( bs, LNb[i] ), 15 ) ) ) && ( EQ_16( low_rate, 1 ) ) ) { Rsubband_w32_fx[i] = L_deposit_l( 0 ); + move32(); } ELSE IF( LE_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { @@ -437,7 +442,7 @@ Word16 BitAllocF_fx( L_tmp1 = L_sub( t_fx, L_shl( B, 15 ) ); L_tmp2 = L_abs( L_tmp1 ); - if ( n > 0 ) + IF( n > 0 ) { exp1 = sub( norm_l( L_tmp2 ), 1 ); exp2 = norm_s( n ); @@ -486,6 +491,7 @@ Word16 BitAllocF_fx( { B = add( B, Nb[i] ); Rsubband_w32_fx[i] = L_deposit_l( 0 ); + move32(); IF( B >= 0 ) { BREAK; @@ -502,6 +508,7 @@ Word16 BitAllocF_fx( FOR( i = 0; i < N; i++ ) { Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); + move16(); tmp = add( tmp, Rsubband_fx[i] ); } @@ -609,6 +616,7 @@ static void Bit_group_fx( tmp = sub( fac_fx[1], tmp ); /*Q13 */ L_tmp = L_mult( y_index[i], tmp ); /*Q14 */ y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */ + move16(); } } ELSE @@ -620,6 +628,7 @@ static void Bit_group_fx( tmp = sub( fac_fx[0], tmp ); /*Q13 */ L_tmp = L_mult( y_index[i], tmp ); /*Q14 */ y_index[i] = extract_h( L_shl( L_tmp, 2 ) ); /*Q0 */ + move16(); } } @@ -653,6 +662,7 @@ static void Bit_group_fx( FOR( k = 0; k <= i; k++ ) { R_temp_fx[k] = L_deposit_h( 0 ); /*Q21 */ + move32(); } } ELSE @@ -676,8 +686,9 @@ static void Bit_group_fx( IF( LT_32( R_temp_fx[i], L_tmp ) ) { R_temp_fx[i] = L_deposit_h( 0 ); + move32(); norm_sum = sub( norm_sum, y_index[i] ); - i--; + i = sub( i, 1 ); } ELSE { @@ -701,15 +712,18 @@ static void Bit_group_fx( FOR( j = bit_band; j < band_num; j++ ) { R_temp_fx[j] = L_deposit_l( 0 ); + move32(); } norm_sum = 0; + move16(); FOR( k = 0; k < bit_band; k++ ) { norm_sum = add( norm_sum, y_index[k] ); } i = bit_band; + move16(); FOR( j = 0; j < bit_band; j++ ) { IF( norm_sum == 0 ) @@ -717,6 +731,7 @@ static void Bit_group_fx( FOR( k = 0; k < i; k++ ) { R_temp_fx[k] = L_deposit_l( 0 ); /*Q21 */ + move32(); } } ELSE @@ -735,6 +750,7 @@ static void Bit_group_fx( } } R_sum_fx = 0; + move32(); L_tmp = L_shl( L_deposit_l( thr ), 21 ); /*Q21 */ FOR( k = 0; k < i; k++ ) { @@ -744,8 +760,10 @@ static void Bit_group_fx( { norm_sum = sub( norm_sum, y_index[m] ); R_temp_fx[m] = L_deposit_l( 0 ); /*Q21 */ + move32(); } i = k; + move16(); BREAK; } ELSE @@ -759,6 +777,7 @@ static void Bit_group_fx( } R_sum_org_fx = R_sum_fx; + move32(); } } @@ -796,6 +815,7 @@ Word16 BitAllocWB_fx( /* o : t Word16 BANDS; Word16 tmp, exp; Word16 Rsum_sub_fx_tmp = 0; /* initialize just to avoid compiler warning */ + move16(); Word32 L_tmp, L_tmp1; Word32 Rsubband_buf[NB_SFM]; @@ -845,7 +865,7 @@ Word16 BitAllocWB_fx( /* o : t } } Ravg_sub_32_fx[1] = L_mult( Rsum_sub_fx[1], 4096 ); /*16 0+15+1 //q15 1/8 =4096 */ - + move32(); Rsum_sub_fx[2] = 0; move16(); FOR( j = SFM_G1G2; j < BANDS; j++ ) @@ -870,6 +890,8 @@ Word16 BitAllocWB_fx( /* o : t factor_fx[0] = 16384; /*Q13 move16(); */ factor_fx[1] = 24576; /*Q13 move16(); */ + move16(); + move16(); { R_diff_32_fx[0] = L_sub( Ravg_sub_32_fx[0], Ravg_sub_32_fx[1] ); move32(); /*Q16 */ @@ -1030,6 +1052,7 @@ Word16 BitAllocWB_fx( /* o : t FOR( i = 0; i < BANDS; i++ ) { Rsubband_fx[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + move16(); } /* Calcuate total used bits and initialize R to be used for Noise Filling */ @@ -1038,6 +1061,7 @@ Word16 BitAllocWB_fx( /* o : t { L_tmp = L_add( L_tmp, Rsubband_buf[i] ); /*Q21 */ R[i] = extract_h( L_shr( Rsubband_buf[i], 5 ) ); /*Q0 */ + move16(); } t_fx = extract_h( L_shr( L_tmp, 5 ) ); /*Q0 */ diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index c8fa4f9e8..62183974c 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -991,6 +991,7 @@ typedef enum #define DIRAC_DIFF_NUM_AMBI_COMP 4 #define DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS 8 #define DIRAC_GAIN_LIMIT 31.622776601683793f /* 30db gain limitiation */ +#define DIRAC_GAIN_LIMIT_Q26 ( 2122168614 ) /* 30db gain limitiation */ #define DIRAC_MAX_NUM_DECORR_FILTERS 22 #define DIRAC_MAX_DECORR_FILTER_LEN 20 #define DIRAC_DECORR_NUM_SPLIT_BANDS 3 diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a96ef417a..56709404a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2393,4 +2393,22 @@ Word16 ism_quant_meta_fx( const Word16 cbsize /* i : codebook size */ ); +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 */ + const Word32 sampling_rate /* i : sampling rate for processing */ +); + +void ivas_limiter_close_fx( + IVAS_LIMITER_HANDLE *phLimiter /* i/o: pointer to limiter handle, can be NULL */ +); + +void copy_masa_descriptive_meta_fx( + MASA_DECRIPTIVE_META *outMeta, /* o : metadata to be written */ + MASA_DECRIPTIVE_META *inMeta /* i : input metadata */ +); + +void efap_free_data_fx( + EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ +); #endif diff --git a/lib_com/lerp.c b/lib_com/lerp.c index ac11a17ce..eea745b81 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -213,8 +213,6 @@ void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOl BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); tmp2 = shr( tmp2, 3 ); /*Q12*/ tmp2 = shl( tmp2, tmpexp ); - test(); - test(); IF( GT_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) { Word16 tmpNewSize = shl( bufferOldSize, 1 ); @@ -223,16 +221,17 @@ void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOl BASOP_Util_Divide_MantExp( bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp ); tmp1 = shr( tmp1, 3 ); /*Q12*/ tmp1 = shl( tmp1, tmpexp ); - test(); - IF( LE_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) + if ( LE_16( tmp1, 16224 /*3,9609375 in Q12*/ ) ) { tmpNewSize = bufferNewSize; + move16(); } lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; + move16(); tmpNewSize = shl( tmpNewSize, 1 ); } } @@ -244,20 +243,22 @@ void lerp( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOl BASOP_Util_Divide_MantExp( bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp ); tmp2 = shr( tmp2, 3 ); /*Q12*/ tmp2 = shl( tmp2, tmpexp ); - test(); - IF( LE_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) + + if ( LE_16( tmp2, 16224 /*3,9609375 in Q12*/ ) ) { tmpNewSize = bufferNewSize; + move16(); } lerp_proc( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; + move16(); tmpNewSize = shr( tmpNewSize, 1 ); } } - else + ELSE { lerp_proc( f, f_out, bufferNewSize, bufferOldSize ); } @@ -283,7 +284,6 @@ static void lerp_proc( const Word16 *f, Word16 *f_out, Word16 bufferNewSize, Wor if ( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { ptr = buf; - move16(); } IF( EQ_16( bufferNewSize, bufferOldSize ) ) @@ -396,10 +396,9 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 test(); test(); test(); - IF( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) + if ( ( ( f <= f_out ) && ( f + bufferOldSize >= f_out ) ) || ( ( f_out <= f ) && ( f_out + bufferNewSize >= f ) ) ) { ptr = buf; - move16(); } IF( EQ_16( bufferNewSize, bufferOldSize ) ) @@ -408,7 +407,7 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 return; } - shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), 4 - shift_e + 16 ); + shift = L_shl( L_deposit_l( div_s( bufferOldSize, shl( bufferNewSize, 4 ) ) ), add( sub( 4, shift_e ), Q16 ) ); pos = L_sub( L_shr( shift, 1 ), 32768l /*1.0f Q15*/ ); @@ -426,16 +425,16 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 diff = shr( extract_l( pos ), 1 ); /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ - move16(); *ptr++ = L_add_sat( f[0], Mpy_32_16_1( L_sub( f[1], f[0] ), diff ) ); + move32(); } ELSE { idx = extract_h( pos ); diff = lshr( extract_l( pos ), 1 ); - move16(); - *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); + *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[add( idx, 1 )], f[idx] ), diff ) ); + move32(); } pos = L_add( pos, shift ); @@ -445,19 +444,19 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 FOR( i = 1; i < n; i++ ) { diff = lshr( extract_l( pos ), 1 ); - IF( LT_32( pos, 0 ) ) + if ( pos < 0 ) { diff = sub( 16384 /*0.5f Q15*/, diff ); } - move16(); *ptr++ = L_add_sat( f[idx], Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ) ); + move32(); pos = L_add( pos, shift ); idx = extract_h( pos ); } /* last point */ - IF( GT_32( pos, L_deposit_h( sub( bufferOldSize, 1 ) ) ) ) + if ( GT_32( pos, L_deposit_h( sub( bufferOldSize, 1 ) ) ) ) { idx = sub( bufferOldSize, 2 ); } @@ -466,8 +465,8 @@ static void lerp_proc32( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 /* diff = t - point;*/ diff = lshr( extract_l( L_shr( L_sub( pos, L_deposit_h( idx ) ), 1 ) ), 1 ); - move16(); - *ptr++ = L_add_sat( f[idx], L_shl_sat( Mpy_32_16_1( L_sub( f[idx + 1], f[idx] ), diff ), 1 ) ); + *ptr++ = L_add_sat( f[idx], L_shl_sat( Mpy_32_16_1( L_sub( f[add( idx, 1 )], f[idx] ), diff ), 1 ) ); + move32(); test(); test(); test(); @@ -489,50 +488,63 @@ static void L_lerp_proc_fx( const Word32 *f_fx, Word32 *f_out_fx, const Word16 b void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize, Word16 *q ) { Word16 tmpNewSize; - Word16 guard_bits = s_max( find_guarded_bits_fx( bufferNewSize / bufferOldSize ), find_guarded_bits_fx( bufferOldSize / bufferNewSize ) ) + 1; - IF( getScaleFactor32( f, bufferOldSize ) < guard_bits ) + Word16 tmp1, tmp2, tmp_e; + tmp1 = BASOP_Util_Divide1616_Scale( bufferNewSize, bufferOldSize, &tmp_e ); + tmp1 = shr( tmp1, sub( 15, tmp_e ) ); + + tmp2 = BASOP_Util_Divide1616_Scale( bufferOldSize, bufferNewSize, &tmp_e ); + tmp2 = shr( tmp2, sub( 15, tmp_e ) ); + Word16 guard_bits = add( s_max( tmp1, tmp2 ), 1 ); + IF( LT_16( getScaleFactor32( f, bufferOldSize ), guard_bits ) ) { - *q -= guard_bits; + *q = sub( *q, guard_bits ); FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) - f[ind] = L_shr( f[ind], guard_bits ); + { + f[ind] = L_shr( f[ind], guard_bits ); + move32(); + } #ifndef MSAN_FIX FOR( Word16 ind = 0; ind < bufferNewSize; ind++ ) f_out[ind] = L_shr( f_out[ind], guard_bits ); #endif } - IF( 128 * bufferNewSize > bufferOldSize * 507 ) + IF( GT_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = bufferOldSize * 2; - WHILE( bufferNewSize > bufferOldSize ) + tmpNewSize = shl( bufferOldSize, 1 ); + WHILE( GT_16( bufferNewSize, bufferOldSize ) ) { - IF( 128 * bufferNewSize <= 507 * bufferOldSize ) + if ( LE_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { tmpNewSize = bufferNewSize; + move16(); } L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize *= 2; + move16(); + tmpNewSize = shl( tmpNewSize, 1 ); } } - ELSE IF( 128 * bufferOldSize > bufferNewSize * 507 ) + ELSE IF( GT_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = bufferOldSize / 2; - WHILE( bufferNewSize < bufferOldSize ) + tmpNewSize = shr( bufferOldSize, 1 ); + WHILE( LT_16( bufferNewSize, bufferOldSize ) ) { - IF( 128 * bufferOldSize <= 507 * bufferNewSize ) + if ( LE_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { tmpNewSize = bufferNewSize; + move16(); } L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize /= 2; + move16(); + tmpNewSize = shr( tmpNewSize, 1 ); } } ELSE @@ -546,38 +558,42 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe { Word16 tmpNewSize; - IF( 128 * bufferNewSize > bufferOldSize * 507 ) + IF( GT_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { - tmpNewSize = bufferOldSize * 2; - WHILE( bufferNewSize > bufferOldSize ) + tmpNewSize = shl( bufferOldSize, 1 ); + WHILE( GT_16( bufferNewSize, bufferOldSize ) ) { - IF( 128 * bufferNewSize <= 507 * bufferOldSize ) + if ( LE_32( L_mult0( 128, bufferNewSize ), L_mult0( bufferOldSize, 507 ) ) ) { tmpNewSize = bufferNewSize; + move16(); } lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize *= 2; + move16(); + tmpNewSize = shl( tmpNewSize, 1 ); } } - ELSE IF( 128 * bufferOldSize > bufferNewSize * 507 ) + ELSE IF( GT_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { - tmpNewSize = bufferOldSize / 2; - WHILE( bufferNewSize < bufferOldSize ) + tmpNewSize = shr( bufferOldSize, 1 ); + WHILE( LT_16( bufferNewSize, bufferOldSize ) ) { - IF( 128 * bufferOldSize <= 507 * bufferNewSize ) + if ( LE_32( L_mult0( 128, bufferOldSize ), L_mult0( bufferNewSize, 507 ) ) ) { tmpNewSize = bufferNewSize; + move16(); } lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize /= 2; + move16(); + tmpNewSize = shr( tmpNewSize, 1 ); } } ELSE @@ -604,7 +620,7 @@ static void L_lerp_proc_fx( Word32 buf_fx[2 * L_FRAME_MAX]; Word16 tmp; - IF( bufferNewSize == bufferOldSize ) + IF( EQ_16( bufferNewSize, bufferOldSize ) ) { Copy32( f_fx, buf_fx, bufferNewSize ); Copy32( buf_fx, f_out_fx, bufferNewSize ); @@ -616,7 +632,7 @@ static void L_lerp_proc_fx( shift_fx = L_shl( L_deposit_l( tmp ), 4 - 15 + 21 ); // q =21 pos_fx = Mpy_32_32( L_sub( shift_fx, 1 << 21 ), 1073741824 ); - IF( shift_fx < L_shr( 644245094, 31 - 21 ) ) + IF( LT_32( shift_fx, L_shr( 644245094, 31 - 21 ) ) ) { pos_fx = L_sub( pos_fx, L_shr( 279172874, 31 - 21 ) ); } @@ -625,37 +641,41 @@ static void L_lerp_proc_fx( IF( pos_fx < 0 ) { buf_fx[0] = L_add( f_fx[0], L_shl( Mpy_32_32( pos_fx, L_sub( f_fx[1], f_fx[0] ) ), 31 - 21 ) ); + move32(); } ELSE { - idx = (Word16) L_shr( pos_fx, 21 ); + idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); - buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); + buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[add( idx, 1 )], f_fx[idx] ) ), 31 - 21 ) ); + move32(); } pos_fx = L_add( pos_fx, shift_fx ); FOR( i = 1; i < bufferNewSize - 1; i++ ) { - idx = (Word16) L_shr( pos_fx, 21 ); - diff_fx = pos_fx - L_shl( idx, 21 ); + idx = extract_l( L_shr( pos_fx, 21 ) ); + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); + move32(); pos_fx = L_add( pos_fx, shift_fx ); } /* last point */ - idx = (Word16) L_shr( pos_fx, 21 ); + idx = extract_l( L_shr( pos_fx, 21 ) ); - IF( pos_fx > L_shl( bufferOldSize - 1, 21 ) ) + if ( GT_32( pos_fx, L_shl( sub( bufferOldSize, 1 ), 21 ) ) ) { - idx = bufferOldSize - 2; + idx = sub( bufferOldSize, 2 ); } - diff_fx = pos_fx - L_shl( idx, 21 ); + diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); - buf_fx[bufferNewSize - 1] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); + buf_fx[sub( bufferNewSize, 1 )] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[add( idx, 1 )], f_fx[idx] ) ), 31 - 21 ) ); + move32(); Copy32( buf_fx, f_out_fx, bufferNewSize ); diff --git a/lib_com/log2.c b/lib_com/log2.c index 739dd8e5e..4e70862d1 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -87,7 +87,9 @@ Word32 log10_fx( Word32 Linput ) frac = extract_l( Ltemp2 ); p1 = log2_tab[sub( extract_h( Ltemp2 ), 0x20 )]; + move16(); p2 = log2_tab[sub( extract_h( Ltemp2 ), 0x1F )]; + move16(); Ltemp2 = L_mult( n1, 0x200 ); n1 = extract_l( Ltemp2 ); @@ -124,10 +126,10 @@ Word32 pow_10( Word32 x, Word16 *Q ) Word16 count = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); - ; xl = extract_l( x ); xh = extract_h( x ); @@ -193,7 +195,7 @@ Word32 pow_10( Word32 x, Word16 *Q ) #else L_tmp = L_shl( L_tmp, i ); #endif - IF( Overflow ) + if ( Overflow ) { count = add( count, 1 ); } diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 678517ae2..902a120b4 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -66,6 +66,7 @@ void logqnorm_fx( Word16 offset = add( 3, shl( qx, 1 ) ); /* 3 + 2*qx */ lsb = 0U; /* to avoid compilation warnings */ + move16(); L_temp1 = L_deposit_l( 1 ); FOR( i = 0; i < N; i++ ) @@ -79,6 +80,7 @@ void logqnorm_fx( FOR( i = 0; i < N; i++ ) { coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); + move16(); L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); } @@ -95,14 +97,14 @@ void logqnorm_fx( m = add( offset, m ); test(); - IF( m < 5 && hvq_flag ) + IF( LT_16( m, 5 ) && hvq_flag ) { m = shl( m, 1 ); IF( LT_32( L_temp1, 1276901417L /* 2^0.25 Q30 */ ) ) { m = add( m, 2 ); } - ELSE if ( LT_32( L_temp1, 1805811301L /* 2^0.75 Q30 */ ) ) + ELSE IF( LT_32( L_temp1, 1805811301L /* 2^0.75 Q30 */ ) ) { m = add( m, 1 ); } @@ -119,8 +121,10 @@ void logqnorm_fx( } } *k = s_max( m, 0 ); + move16(); i = sub( L, 1 ); *k = s_min( *k, i ); + move16(); return; } @@ -149,6 +153,7 @@ void logqnorm_2_fx( ELSE IF( GT_32( thren[sub( L, 2 )], temp ) ) { *ynrm = sub( L, 1 ); + move16(); } ELSE { diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 0df807523..a71311f38 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -46,6 +46,7 @@ void ivas_fine_gain_pred_fx( UWord16 lsb; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif FOR( band = 0; band < num_sfm; band++ ) @@ -53,7 +54,7 @@ void ivas_fine_gain_pred_fx( k = K[i_sort[band]]; move16(); - IF( GT_16( k, 0 ) ) + IF( k > 0 ) { /* bw, bw_idx only used if k>0 */ bw = sfm_size[i_sort[band]]; @@ -63,6 +64,7 @@ void ivas_fine_gain_pred_fx( move16(); /* bw_idx= 0: 8 */ xx = L_deposit_l( 0 ); shift = ivas_band_len_ener_shift[bw_idx]; + move16(); FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) { /*xx += xq[i] * xq[i]; */ @@ -70,7 +72,7 @@ void ivas_fine_gain_pred_fx( xx = L_mac0( xx, tmp, tmp ); /*30-2*shift */ } - IF( GT_32( xx, 0 ) ) + IF( xx > 0 ) { /* Normalize synthesis to RMS=1.0 */ /*gp = (float) sqrt(bw / xx); */ @@ -163,6 +165,7 @@ void fine_gain_pred_fx( UWord16 lsb; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( band = 0; band < num_sfm; band++ ) @@ -322,12 +325,14 @@ void fine_gain_dec_fx( FOR( band = 0; band < num_sfm; band++ ) { gbits = gain_bits[ord[band]]; + move16(); IF( gbits > 0 ) { IF( fg_pred[band] != 0 ) { idx = get_next_indice( st, gbits ); gain_dbq = finegain_fx[gbits - 1][idx]; + move16(); /* Update predicted gain with quantized correction */ L_tmp = L_mult0( gain_dbq, 21771 ); /* 21771=0.05*log2(10) */ /* 14+17=31 */ @@ -339,6 +344,7 @@ void fine_gain_dec_fx( L_tmp = L_mult0( fg_pred[band], tmp1 ); /*12+exp1 */ fg_pred[band] = round_fx_sat( L_shl_sat( L_tmp, sub( 16, exp1 ) ) ); /*12+exp1+16-exp1-16=12 */ + move16(); } } } diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index bcf0a5d9a..382ca06d8 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -207,12 +207,16 @@ Word16 lev_dur_fx( Word16 *rc_fx; /* reflection coefficients 0,...,m-1 */ Word32 at; Word32 s, err; - Word16 flag = 0; + Word16 flag = 0, tmp16; + move16(); rc_fx = &buf_fx[0]; rc_fx[0] = divide3232( L_negate( r_fx[1] ), r_fx[0] ); // Q(31) + move16(); a_fx[0] = L_shl( 1, q_a ); + move32(); a_fx[1] = L_shl( rc_fx[0], sub( q_a, 15 ) ); + move32(); err = L_add( r_fx[0], Mpy_32_16_1( r_fx[1], rc_fx[0] ) ); // Q(q_r) IF( epsP != NULL ) { @@ -225,36 +229,42 @@ Word16 lev_dur_fx( FOR( i = 2; i <= m; i++ ) { s = 0; // Q(q_a + q_r - 31) + move32(); FOR( j = 0; j < i; j++ ) { s = L_add( s, Mpy_32_32( r_fx[i - j], a_fx[j] ) ); } rc_fx[i - 1] = divide3232( L_negate( s ), L_shr( err, sub( 31, q_a ) ) ); + move16(); - IF( abs_s( rc_fx[i - 1] ) > 32749 ) // 32749 = 0.99945 in Q15 + if ( GT_16( abs_s( rc_fx[i - 1] ), 32749 ) ) // 32749 = 0.99945 in Q15 { flag = 1; /* Test for unstable filter. If unstable keep old A(z) */ + move16(); } - FOR( j = 1; j <= shr( i, 1 ); j++ ) + tmp16 = shr( i, 1 ); + FOR( j = 1; j <= tmp16; j++ ) { l = sub( i, j ); at = L_add( a_fx[j], Mpy_32_16_1( a_fx[l], rc_fx[i - 1] ) ); // Q(q_a) a_fx[l] = L_add( a_fx[l], Mpy_32_16_1( a_fx[j], rc_fx[i - 1] ) ); + move32(); a_fx[j] = at; move32(); } a_fx[i] = L_shl( rc_fx[i - 1], sub( q_a, 15 ) ); + move32(); err = L_add( err, L_shl( Mpy_32_16_1( s, rc_fx[i - 1] ), sub( 31, q_a ) ) ); // q_err - q_s - IF( LE_32( err, 0 ) ) + IF( err <= 0 ) { - err = L_shr( 327, 31 - q_r ); // 327 = 0.01 in Q15 + err = L_shr( 327, sub( 31, q_r ) ); // 327 = 0.01 in Q15 } - IF( epsP != NULL ) + if ( epsP != NULL ) { epsP[i] = err; move32(); diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index c5849e930..83b59079a 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -168,7 +168,7 @@ void autocorr_fx( void autocorr_fx_32( const Word16 x[], /* i : Input signal */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ + Word32 r[], /* o : Autocorrelations */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ @@ -179,27 +179,29 @@ void autocorr_fx_32( Word16 i, j, norm, shift, y[MAX_LEN_LP]; Word16 fact; Word32 L_sum, L_tmp; + Word16 tmp16; IF( EQ_16( rev_flag, 1 ) ) { /* Windowing of signal */ FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[len - i - 1] ); + y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); move16(); } } ELSE IF( EQ_16( sym_flag, 1 ) ) { /* symmetric window of even length */ - FOR( i = 0; i < len / 2; i++ ) + tmp16 = shr( len, 1 ); + FOR( i = 0; i < tmp16; i++ ) { y[i] = mult_r( x[i], wind[i] ); move16(); } FOR( ; i < len; i++ ) { - y[i] = mult_r( x[i], wind[len - i - 1] ); + y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); move16(); } } @@ -258,7 +260,8 @@ void autocorr_fx_32( FOR( i = 1; i <= m; i++ ) { L_sum = L_mult( y[0], y[i] ); - FOR( j = 1; j < len - i; j++ ) + tmp16 = sub( len, i ); + FOR( j = 1; j < tmp16; j++ ) { L_sum = L_mac( L_sum, y[j], y[j + i] ); } @@ -479,6 +482,7 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Wor flag = 1; move16(); /* Test for unstable filter. If unstable keep old A(z) */ } + test(); if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) ) { flag = 1; @@ -555,6 +559,7 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Wor #else A[i] = round_fx( L_shl( t0, k ) ); #endif + move16(); } BASOP_SATURATE_WARNING_ON_EVS @@ -563,11 +568,11 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Wor /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ IF( flag ) { - Copy( mem, A, order + 1 ); + Copy( mem, A, add( order, 1 ) ); } ELSE /* If stable LPC filter, store into memories */ { - Copy( A, mem, order + 1 ); + Copy( A, mem, add( order, 1 ) ); } } @@ -592,6 +597,7 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -693,6 +699,7 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], flag = 1; move16(); /* Test for unstable filter. If unstable keep old A(z) */ } + test(); if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) ) { flag = 1; @@ -767,8 +774,9 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], #ifdef BASOP_NOGLOB A[i] = L_shl_o( t0, k, &Overflow ); #else - A[i] = L_shl(t0, k)); + A[i] = L_shl(t0, k)); #endif + move16(); } BASOP_SATURATE_WARNING_ON_EVS @@ -777,11 +785,11 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ IF( flag ) { - Copy32( mem, A, order + 1 ); + Copy32( mem, A, add( order, 1 ) ); } ELSE /* If stable LPC filter, store into memories */ { - Copy32( A, mem, order + 1 ); + Copy32( A, mem, add( order, 1 ) ); } } @@ -821,15 +829,17 @@ void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ) } Atmp[m + 1] = L_negate( L_mult0( gamma, a[m] ) ); move32(); - Amax = L_max( Amax, L_abs( Atmp[m + 1] ) ); + Amax = L_max( Amax, L_abs( Atmp[add( m, 1 )] ) ); shift = norm_l( Amax ); ap[0] = shl( a[0], sub( shift, 1 ) ); move16(); FOR( i = 1; i <= m; i++ ) { ap[i] = round_fx( L_shl( Atmp[i], shift ) ); + move16(); } - ap[m + 1] = round_fx( L_shl( Atmp[m + 1], shift ) ); + ap[add( m, 1 )] = round_fx( L_shl( Atmp[add( m, 1 )], shift ) ); + move16(); } void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* input : LSPs from past frame Q15 */ @@ -844,6 +854,7 @@ void E_LPC_int_lpc_tcx( const Word16 lsp_old[], /* input : LSPs from past frame { /*lsp[i] = lsp_old[i]*0.125f + lsp_new[i]*0.875f;*/ lsp[i] = round_fx( L_mac( L_mult( lsp_old[i], 4096 ), lsp_new[i], 28672 ) ); + move16(); } E_LPC_f_lsp_a_conversion( lsp, a, M ); @@ -940,6 +951,7 @@ Word16 E_LPC_lsp_unweight( /* Approximate unweighting by 3-tap FIR */ lsp_uw[0] = add( lsp_w_orig[0], round_fx( L_shl( L_mac0( L_mult0( unw_coeffs[0][1], lsp_w_diff[0] ), unw_coeffs[0][2], lsp_w_diff[1] ), 2 ) ) ); + move16(); FOR( i = 1; i < lpcorder - 1; ++i ) { lsp_uw[i] = add( lsp_w_orig[i], round_fx( L_shl( L_mac0( L_mac0( L_mult0( unw_coeffs[i][0], lsp_w_diff[i - 1] ), unw_coeffs[i][1], lsp_w_diff[i] ), unw_coeffs[i][2], lsp_w_diff[i + 1] ), 2 ) ) ); @@ -1002,8 +1014,8 @@ Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 temp16 = negate( divide3232( g0[0], g1[0] ) ); reflCoeff[0] = temp16; move16(); - move32(); epsP[0] = r[0]; + move32(); FOR( i = 0; i < mM1; i++ ) @@ -1075,24 +1087,24 @@ static void spec2isf( Word16 tmp, i; Word16 specix, lsfix; - move16(); - move16(); specix = lsfix = 0; move16(); + move16(); s = spec_r[specix++]; + move16(); WHILE( LT_16( specix, speclen ) && LE_16( lsfix, 15 ) ) { - + test(); /*check for next zero crossing*/ /*for (; s*spec_r[specix] >= 0; specix++);*/ WHILE( mult( s, spec_r[specix] ) >= 0 ) specix = add( specix, 1 ); tmp = divide1616( spec_r[specix - 1], sub( spec_r[specix - 1], spec_r[specix] ) ); - move16(); /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ lsf[lsfix] = add( shl( sub( specix, 1 ), 7 ), shr( ( tmp ), 8 ) ); /*7Q8*/ + move16(); lsfix++; @@ -1103,9 +1115,9 @@ static void spec2isf( specix = add( specix, 1 ); tmp = divide1616( spec_i[specix - 1], sub( spec_i[specix - 1], spec_i[specix] ) ); - move16(); /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ lsf[lsfix] = add( shl( sub( specix, 1 ), 7 ), shr( ( tmp ), 8 ) ); /*7Q8*/ + move16(); lsfix++; @@ -1144,9 +1156,11 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o Word16 s[4]; Word32 L_tmp, L_tmp1, L_tmp3; Word16 lpc[19]; + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* half length FFT */ @@ -1194,8 +1208,11 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o move16(); } s[0] = shr( s[0], 1 ); + move16(); s[1] = shr( s[1], 1 ); + move16(); s[2] = shr( s[2], 1 ); + move16(); lpc[0] = mult_r( lpcCoeffs[0], s[0] ); move16(); L_tmp = L_mult( s[0], lpcCoeffs[1] ); @@ -1223,9 +1240,12 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o FOR( j = 0; j < 9; j++ ) { ptrReal[j * 8] = L_shl( L_deposit_h( lpc[2 * j] ), scale ); + move32(); ptrImag[j * 8] = L_shl( L_deposit_h( lpc[2 * j + 1] ), scale ); + move32(); } ptrReal[j * 8] = L_shl( L_deposit_h( lpc[2 * j] ), scale ); + move32(); ptrImag[j * 8] = 0; move16(); j++; @@ -1233,7 +1253,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o FOR( ; j < 16; j++ ) { ptrReal[j * 8] = L_deposit_h( 0 ); + move32(); ptrImag[j * 8] = L_deposit_h( 0 ); + move32(); } fft16( ptrReal, ptrImag, 8, 0 ); @@ -1246,7 +1268,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o ptwiddle = w_a[i - 1]; ptrReal[0] = L_shl( L_deposit_h( lpc[0] ), scale ); + move32(); ptrImag[0] = L_shl( L_deposit_h( lpc[1] ), scale ); + move32(); FOR( j = 1; j < 9; j++ ) { @@ -1266,7 +1290,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o FOR( ; j < 16; j++ ) { ptrReal[j * 8] = L_deposit_h( 0 ); + move32(); ptrImag[j * 8] = L_deposit_h( 0 ); + move32(); ptwiddle++; } @@ -1293,12 +1319,14 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o pwn15i = &tmpw15; RealOut[0] = round_fx( 2 * L_add( RealFFT[0], ImagFFT[0] ) ); + move16(); ImagOut[0] = 0; move16(); RealOut[128] = 0; move16(); ImagOut[128] = round_fx( L_sub( L_add( RealFFT[0], RealFFT[0] ), L_add( ImagFFT[0], ImagFFT[0] ) ) ); + move16(); ptwiddle += 8; FOR( i = 1; i <= N / 2 / 4; i++ ) @@ -1310,7 +1338,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im, &Overflow ); + move16(); tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re, &Overflow ); + move16(); #else /* BASOP_NOGLOB */ tmpw15.v.re = mac_r( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im ); tmpw15.v.im = msu_r( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re ); @@ -1323,7 +1353,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = msu_ro( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re, &Overflow ); + move16(); tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re, &Overflow ); + move16(); #else /* BASOP_NOGLOB */ tmpw15.v.re = msu_r( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); tmpw15.v.im = mac_r( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); @@ -1350,7 +1382,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im, &Overflow ); + move16(); tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re, &Overflow ); + move16(); #else /* BASOP_NOGLOB */ tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); tmpw15.v.im = msu_r( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); @@ -1363,7 +1397,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = msu_ro( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re, &Overflow ); + move16(); tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re, &Overflow ); + move16(); #else /* BASOP_NOGLOB */ tmpw15.v.re = msu_r( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); tmpw15.v.im = mac_r( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); @@ -1387,7 +1423,9 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs, Word16 *lsf, const Word16 *o BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); + move16(); tmpw15.v.im = msu_r_sat( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); + move16(); #else tmpw15.v.re = mac_r( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); tmpw15.v.im = msu_r( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 147c40846..4c10059d0 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -65,7 +65,7 @@ void lsf_dec_bfi( { pt_meansForFading = GEWB_Ave_fx; - if ( EQ_16( bwidth, NB ) ) + if ( bwidth == NB ) { pt_meansForFading = GENB_Ave_fx; } @@ -206,18 +206,22 @@ ELSE IF( tcxonly != 0 ) IF( EQ_16( L_frame, 320 ) ) { gap = 143; + move16(); } ELSE IF( EQ_16( L_frame, 512 ) ) { gap = 90; + move16(); } ELSE IF( EQ_16( L_frame, 640 ) ) { gap = 72; + move16(); } ELSE { gap = 48; + move16(); } reorder_lsf_fx( lsf, gap, M, INT_FS_FX ); } diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index 179e644b6..a423cb951 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -38,8 +38,8 @@ void midlsf_dec( Word16 j; Word32 L_tmp; Word16 bad_spacing = 0; - move16(); + /* Select codebook */ IF( EQ_16( coder_type, UNVOICED ) ) { @@ -54,6 +54,7 @@ void midlsf_dec( 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)*/ + move16(); } diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 127cee7e9..0b9223922 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -1616,37 +1616,6 @@ void lsp2lsf( return; } -#ifdef IVAS_FLOAT_FIXED -/*-----------------------------------------------------------------------* - * lsf2lsp_32_fx() - * - * Transformation of LSFs to LSPs - * - * LSP are line spectral pairs in cosine domain (-1 to 1). - * LSF are line spectral frequencies (0 to fs/2). - *-----------------------------------------------------------------------*/ - -void lsf2lsp_32_fx( - const Word32 lsf_fx[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ - Word16 lsf_q_fx, - Word16 lsp_fx[], /* o : isp[m] (range: -1<=val<1) */ - Word16 *lsp_q_fx, - const Word16 m, /* i : LPC order */ - const Word32 Fs /* i : sampling frequency */ -) -{ - Word16 i; - - /* convert LSFs to LSPs */ - FOR( i = 0; i < m; i++ ) - { - lsp_fx[i] = getCosWord16R2( div_l( L_shr( lsf_fx[i], lsf_q_fx - 13 ), div_l( Fs, shl( 2, 1 ) ) ) ); - } - *lsp_q_fx = 15; - return; -} -#endif - /*-----------------------------------------------------------------------* * lsf2lsp() * @@ -2101,7 +2070,6 @@ void dec_FDCNG_MSVQ_stage1( } #ifdef IVAS_FLOAT_FIXED - void dec_FDCNG_MSVQ_stage1_fx( Word16 j_full, /* i : index full range */ Word16 n, /* i : dimension to generate */ @@ -2111,7 +2079,7 @@ void dec_FDCNG_MSVQ_stage1_fx( Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ) { - Word16 col, segm_ind, j; + Word16 col, segm_ind, j, i; Word32 dct_vec[FDCNG_VQ_MAX_LEN]; const Word8 *cbpW8; const Word16 *dct_col_shift_tab; @@ -2121,15 +2089,16 @@ void dec_FDCNG_MSVQ_stage1_fx( assert( n >= FDCNG_VQ_DCT_MINTRUNC ); segm_ind = 0; - for ( col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++ ) + move16(); + FOR( col = 1; col <= FDCNG_VQ_DCT_NSEGM; col++ ) { - if ( j_full >= cdk1_ivas_cum_entries_per_segment[col] ) + if ( GE_16( j_full, cdk1_ivas_cum_entries_per_segment[col] ) ) { - segm_ind++; + segm_ind = add( segm_ind, 1 ); } } - j = j_full - cdk1_ivas_cum_entries_per_segment[segm_ind]; /* j is the local segment index */ + j = sub( j_full, cdk1_ivas_cum_entries_per_segment[segm_ind] ); /* j is the local segment index */ /* Word8 column variable Qx storage*/ @@ -2137,9 +2106,10 @@ void dec_FDCNG_MSVQ_stage1_fx( cbpW8 += j * cdk1_ivas_cols_per_segment[segm_ind]; /* adaptive ptr init */ dct_col_shift_tab = stage1_dct_col_syn_shift[segm_ind]; - for ( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) + FOR( col = 0; col < cdk1_ivas_cols_per_segment[segm_ind]; col++ ) { - dct_vec[col] = shl( (Word16) cbpW8[col], dct_col_shift_tab[col] ); + dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); + move32(); /* LOGIC( 1 ) , SHIFT( 1 ); in BASOP: s_and(for W8->W16), shl() */ @@ -2147,10 +2117,12 @@ void dec_FDCNG_MSVQ_stage1_fx( assert( j < cdk1_ivas_entries_per_segment[segm_ind] ); Word16 norm = 20; + move16(); - for ( int i = 0; i < cdk1_ivas_cols_per_segment[segm_ind]; i++ ) + FOR( i = 0; i < cdk1_ivas_cols_per_segment[segm_ind]; i++ ) { dct_vec_fx[i] = L_shl( dct_vec[i], norm ); + move32(); } dctT2_N_apply_matrix_fx( (const Word32 *) dct_vec_fx, idct_vec_fx, cdk1_ivas_cols_per_segment[segm_ind], n, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, idcttype ); @@ -2159,14 +2131,20 @@ void dec_FDCNG_MSVQ_stage1_fx( /*scale down to original fdcngvq domain and move to Q0 */ /* fdcng_dct_scaleF[1] --> Q15 conversion --> 860 */ // v_multc_att32( idct_vec_fx, 860, idct_vec_fx, n ); - for ( int i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) + { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ + move32(); + } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , not really relevant for BASOP loop */ /*add common mid fdcng vector, in fdcng bands domain */ - for ( int i = 0; i < n; i++ ) - uq[i] = L_add( idct_vec_fx[i], L_lshl( cdk1r_tr_midQ_truncQ_fx[i], norm - 10 ) ); // making the Q factors equal + FOR( i = 0; i < n; i++ ) + { + uq[i] = L_add( idct_vec_fx[i], L_lshl( cdk1r_tr_midQ_truncQ_fx[i], sub( norm, Q10 ) ) ); // making the Q factors equal + move32(); + } assert( uq_ind == NULL ); return; @@ -2255,7 +2233,6 @@ void msvq_dec_float( } #ifdef IVAS_FLOAT_FIXED - 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.) */ @@ -2270,20 +2247,24 @@ void msvq_dec_fx( Word16 *uq_ind, /* o : quantized vector (fixed point) */ Word16 exp ) { - Word16 i, n, maxn, start; + Word16 i, n, maxn, start, k; Word16 j, max_size = 0; + move16(); FOR( i = 0; i < stages; i++ ) { IF( dims ) { - IF( max_size < dims[i] ) - max_size = dims[i]; + if ( LT_16( max_size, dims[i] ) ) + { + max_size = dims[i]; + move16(); + } } - ELSE { max_size = N; + move16(); } } @@ -2302,36 +2283,44 @@ void msvq_dec_fx( IF( dims ) { n = dims[i]; + move16(); maxn = n; + move16(); } ELSE { n = N; + move16(); maxn = maxN; + move16(); } IF( offs ) { start = offs[i]; + move16(); } ELSE { start = 0; + move16(); } Word16 guard_bits = find_guarded_bits_fx( max_size ); - if ( i == 0 ) + IF( i == 0 ) { - FOR( Word16 k = 0; k < N; k++ ) + FOR( k = 0; k < N; k++ ) { uq[k] = L_shr( uq[k], guard_bits ); + move32(); } } + test(); IF( i == 0 && applyIDCT_flag != 0 ) { assert( start == 0 ); dec_FDCNG_MSVQ_stage1_fx( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */ - FOR( Word16 k = 0; k < N; k++ ) + FOR( k = 0; k < N; k++ ) { uq[k] = L_shr( uq[k], guard_bits ); move32(); @@ -2341,9 +2330,10 @@ void msvq_dec_fx( { // v_add( uq + start, cb[i] + Idx[i] * maxn, uq + start, n ); - FOR( Word16 k = 0; k < n; k++ ) + FOR( k = 0; k < n; k++ ) { - uq[start + k] = L_add( uq[start + k], L_lshl( cb[i][Idx[i] * maxn + k], 20 - exp - guard_bits ) ); + uq[add( start, k )] = L_add( uq[add( start, k )], L_lshl( cb[i][add( imult1616( Idx[i], maxn ), k )], sub( sub( 20, exp ), guard_bits ) ) ); + move32(); } } @@ -2352,8 +2342,8 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { + uq_ind[add( start, j )] = add( uq_ind[add( start, j )], (Word16) ( mult( cb[i][add( imult1616( Idx[i], maxn ), j )], 20971 ), sub( add( 13, exp ), 15 ) ) ); move16(); - uq_ind[start + j] = add( uq_ind[start + j], (Word16) ( mult( cb[i][Idx[i] * maxn + j], 20971 ), ( 13 + exp ) - 15 ) ); } } #undef WMC_TOOL_SKIP @@ -2726,42 +2716,54 @@ void dctT2_N_apply_matrix_fx( assert( dct_dim <= FDCNG_VQ_DCT_MAXTRUNC ); assert( fdcngvq_dim <= FDCNG_VQ_MAX_LEN ); - if ( ( dcttype & 1 ) == 0 ) /* even entries are DCTs */ + IF( L_and( dcttype, 1 ) == 0 ) /* even entries are DCTs */ { /* DCT_typeII 24,21 -> XX in worst case */ dim_in = fdcngvq_dim; + move16(); dim_out = dct_dim; + move16(); mat_step_col = matrix_row_dim; /* matrix maximum storage size dependent, width of first row in matrix */ + move16(); mat_step_row = 0; + move16(); mat_step_col_flag = 1; + move16(); assert( dcttype == DCT_T2_21_XX || dcttype == DCT_T2_24_XX ); } - else + ELSE { assert( ( dcttype & 1 ) != 0 ); /* idct */ dim_in = dct_dim; + move16(); dim_out = fdcngvq_dim; + move16(); mat_step_col = 1; + move16(); mat_step_row = matrix_row_dim; + move16(); mat_step_col_flag = 0; + move16(); assert( dcttype == IDCT_T2_XX_24 ); } pt_y = tmp_y; - for ( i = 0; i < dim_out; i++ ) + FOR( i = 0; i < dim_out; i++ ) { pt_x = input; *pt_y = 0; + move32(); /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag )] ); /* ptr indexing */ + pt_A = &( matrix[imult1616( i, add( mat_step_row, mat_step_col_flag ) )] ); /* ptr indexing */ PTR_INIT( 1 ); #undef WMC_TOOL_SKIP - for ( j = 0; j < dim_in; j++ ) + FOR( j = 0; j < dim_in; j++ ) { #define WMC_TOOL_SKIP - *pt_y += Mpy_32_32( ( *pt_x++ ), ( *pt_A ) ); + *pt_y = L_add( *pt_y, Mpy_32_32( ( *pt_x++ ), ( *pt_A ) ) ); + move32(); pt_A += mat_step_col; /* step +maxtrunc or +1 */ /* ptr indexing*/ MAC( 1 ); #undef WMC_TOOL_SKIP @@ -2916,7 +2918,7 @@ void create_IDCT_N_Matrix_fx( const Word16 alloc_size /* i : RAM buffer size in elements */ ) { - Word16 c, c1, r, r_flip, W16_val; + Word16 c, c1, r, r_flip, W16_val, tmp16; Word16 len; Word16 mat_cpy_size; const Word16 *absval_ptr; @@ -2927,20 +2929,23 @@ void create_IDCT_N_Matrix_fx( absval_ptr = unique_idctT2_24coeffsQ16; idx_ptr = idctT2_24_compressed_idx; len = FDCNG_VQ_MAX_LEN; + move16(); - IF( N == FDCNG_VQ_MAX_LEN_WB ) + IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { absval_ptr = unique_idctT2_21coeffsQ16; idx_ptr = idctT2_21_compressed_idx; len = N; + move16(); } assert( alloc_size >= ( n_cols * len ) ); /* enough space for the full expanded IDCT matrix */ assert( N <= len ); - mat_cpy_size = ( n_cols ) * ( len >> 1 ); /* NB integer division of "len" */ + // mat_cpy_size = ( n_cols ) * ( len >> 1 ); /* NB integer division of "len" */ + mat_cpy_size = imult1616( n_cols, shr( len, 1 ) ); /* NB integer division of "len" */ - IF( NE_16( ( len & 1 ), 0 ) ) + IF( s_and( len, 1 ) != 0 ) { /* odd sized DCT with a non-reflected center row */ mat_cpy_size = add( mat_cpy_size, n_cols ); } @@ -2949,13 +2954,15 @@ void create_IDCT_N_Matrix_fx( { idx = (Word16) ( idx_ptr[c] ); W16_val = absval_ptr[abs( idx )]; + move16(); IF( idx < 0 ) { - W16_val = -( W16_val ); + W16_val = negate( W16_val ); } /* (+1.52587890625e-05f) * 2 ^ 31 is equal to 32768 */ - inv_matrixFloatQ[c] = 32768 * ( W16_val ); /* scaling to 2 ^ 31*/ + inv_matrixFloatQ[c] = L_shl( W16_val, Q15 ); /* scaling to 2 ^ 31*/ + move32(); } /* for even number of coeffs DCT24, @@ -2967,13 +2974,14 @@ void create_IDCT_N_Matrix_fx( FOR( c = 0; c < ( n_cols ); c += 2 ) { - c1 = c + 1; - r_flip = len - 1; - FOR( r = 0; r < ( len / 2 ); r_flip-- ) + c1 = add( c, 1 ); + r_flip = sub( len, 1 ); + tmp16 = shr( len, 1 ); + FOR( r = 0; r < tmp16; r_flip-- ) { #define WMC_TOOL_SKIP - ptr[r_flip][c] = ptr[r][c]; /* flipped */ - ptr[r_flip][c1] = -( ptr[r][c1] ); /* flipped and sign swapped */ + ptr[r_flip][c] = ptr[r][c]; /* flipped */ + ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped */ MOVE( 2 ); MULT( 1 ); /* for negate */ #undef WMC_TOOL_SKIP diff --git a/lib_com/prot.h b/lib_com/prot.h index d33a84804..03ce573b9 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -931,17 +931,6 @@ void lsp2lsf( const int32_t Fs /* i : sampling frequency */ ); -#ifdef IVAS_FLOAT_FIXED -void lsf2lsp_32_fx( - const Word32 lsf_fx[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ - Word16 lsf_q_fx, - Word16 lsp_fx[], /* o : isp[m] (range: -1<=val<1) */ - Word16 *lsp_q_fx, - const Word16 m, /* i : LPC order */ - const Word32 Fs /* i : sampling frequency */ -); -#endif - void lsf2lsp( const float lsf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ float lsp[], /* o : isp[m] (range: -1<=val<1) */ diff --git a/lib_com/tools.c b/lib_com/tools.c index 6a6ea3d42..2132eb9f5 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -185,10 +185,11 @@ Word32 sum2_f_16_fx( const Word16 lvec /* i : length of input vector */ ) { - int16_t i; + Word16 i; Word32 tmp; tmp = 0; + move32(); FOR( i = 0; i < lvec; i++ ) { tmp = L_add( tmp, L_mult0( vec[i], vec[i] ) ); @@ -217,15 +218,17 @@ float sum2_f( #ifdef IVAS_FLOAT_FIXED Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ + const Word16 lvec, /* i : length of input vector */ Word16 gb ) { - int16_t i; + Word16 i; Word32 tmp; tmp = 0; Word32 var_a = 0; - for ( i = 0; i < lvec; i++ ) + move32(); + move32(); + FOR( i = 0; i < lvec; i++ ) { var_a = Mpy_32_32( vec[i], vec[i] ); // 2x-31 tmp = L_add( tmp, L_shr( var_a, gb ) ); // 2x-31-gb @@ -239,12 +242,15 @@ Word32 sum2_32_fx( const Word16 lvec, /* i : length of input vector */ Word16 *e ) { - int16_t i; + Word16 i; Word32 tmp; tmp = 0; Word32 var_a = 0; Word16 exp = 0, exp_tmp; + move32(); + move32(); + move16(); FOR( i = 0; i < lvec; i++ ) { exp_tmp = norm_l( vec[i] ); @@ -254,6 +260,7 @@ Word32 sum2_32_fx( tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, var_a, exp_tmp, &exp ); } *e = exp; + move16(); return tmp; } @@ -351,6 +358,7 @@ void set_zero_fx( FOR( i = 0; i < lvec; i++ ) { *vec++ = 0; + move32(); } return; @@ -516,7 +524,7 @@ uint32_t mvr2s( } #ifdef IVAS_FLOAT_FIXED -uint32_t mvl2s_r( +UWord32 mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q_x, Word16 y[], /* o : output vector */ @@ -525,7 +533,8 @@ uint32_t mvl2s_r( { Word16 i; Word32 temp; - uint32_t noClipping = 0; + UWord32 noClipping = 0; + move32(); IF( n <= 0 ) { @@ -537,21 +546,24 @@ uint32_t mvl2s_r( { FOR( i = 0; i < n; i++ ) { - temp = L_shr( x[i], q_x - 1 ); + temp = L_shr( x[i], sub( q_x, 1 ) ); temp = L_shr( L_add( temp, 1 ), 1 ); - IF( temp > MAX16B ) + IF( GT_32( temp, MAX16B ) ) { temp = MAX16B; - noClipping++; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); } - ELSE IF( temp < MIN16B ) + ELSE IF( LT_32( temp, MIN16B ) ) { temp = MIN16B; - noClipping++; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); } - y[i] = (Word16) temp; + y[i] = extract_l( temp ); + move16(); } } ELSE @@ -561,18 +573,21 @@ uint32_t mvl2s_r( temp = L_shr( x[i], q_x - 1 ); temp = L_shr( L_add( temp, 1 ), 1 ); - IF( temp > MAX16B ) + IF( GT_32( temp, MAX16B ) ) { temp = MAX16B; - noClipping++; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); } - ELSE IF( temp < MIN16B ) + ELSE IF( LT_32( temp, MIN16B ) ) { temp = MIN16B; - noClipping++; + move32(); + noClipping = L_add( (Word32) noClipping, 1 ); } - y[i] = (Word16) temp; + y[i] = extract_l( temp ); + move16(); } } @@ -710,7 +725,7 @@ Word16 maximum_s( } } - IF( max != NULL ) + if ( max != NULL ) { *max = tmp; move16(); @@ -761,19 +776,23 @@ Word16 maximum_l( ind = 0; tmp = vec[0]; - + move16(); + move32(); FOR( i = 1; i < lvec; i++ ) { IF( GT_32( vec[i], tmp ) ) { ind = i; tmp = vec[i]; + move16(); + move32(); } } IF( max_val != NULL ) { *max_val = tmp; + move32(); } return ind; @@ -883,7 +902,7 @@ Word16 minimum_s( } } - IF( min_val != NULL ) + if ( min_val != NULL ) { *min_val = tmp; move16(); @@ -939,19 +958,24 @@ Word16 minimum_l( ind = 0; tmp = vec[0]; + move16(); + move32(); - for ( i = 1; i < lvec; i++ ) + FOR( i = 1; i < lvec; i++ ) { - if ( LT_32( vec[i], tmp ) ) + IF( LT_32( vec[i], tmp ) ) { ind = i; tmp = vec[i]; + move16(); + move32(); } } if ( min_val != NULL ) { *min_val = tmp; + move32(); } return ind; @@ -1102,12 +1126,15 @@ 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 ); + move16(); + test(); WHILE( GT_64( suma, MAX_32 ) || GT_16( *res_q, 31 ) ) { suma = W_shr( suma, 1 ); *res_q = sub( *res_q, 1 ); + move16(); } - return (Word32) suma; + return W_extract_l( suma ); } /*---------------------------------------------------------------------* * inv_sqrt() @@ -1249,6 +1276,7 @@ void v_add_fixed( FOR( i = 0; i < N; i++ ) { y[i] = L_add( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) ); + move32(); } return; @@ -1266,15 +1294,17 @@ void v_add_fixed_me( ) { Word16 i; - Word16 x1_shift = s_max( x1_e, x2_e ) - x1_e; - Word16 x2_shift = s_max( x1_e, x2_e ) - x2_e; + 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 = s_max( x1_e, x2_e ) + hdrm; + *y_e = add( s_max( x1_e, x2_e ), hdrm ); + move16(); return; } @@ -1299,6 +1329,7 @@ void v_add_w64( FOR( i = 0; i < N; i++ ) { y[i] = W_add( W_shr( x1[i], hdrm ), W_shr( x2[i], hdrm ) ); + move64(); } return; @@ -1347,6 +1378,7 @@ void v_sub_fixed( FOR( i = 0; i < N; i++ ) { y[i] = L_sub( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) ); + move32(); } return; @@ -1370,6 +1402,7 @@ void v_mult_fixed( FOR( i = 0; i < N; i++ ) { y[i] = Mpy_32_32( x1[i], x2[i] ); + move32(); } return; @@ -1434,6 +1467,7 @@ void v_multc_fixed( FOR( i = 0; i < N; i++ ) { y[i] = Mpy_32_32( c, x[i] ); + move32(); } return; @@ -1451,6 +1485,7 @@ void v_multc_fixed_16( FOR( i = 0; i < N; i++ ) { y[i] = Mpy_32_16_1( x[i], c ); + move32(); } return; @@ -1468,6 +1503,7 @@ void v_multc_fixed_16_16( FOR( i = 0; i < N; i++ ) { y[i] = mult_r( x[i], c ); + move16(); } return; @@ -1838,8 +1874,10 @@ void sort_l( FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { x[j - 1] = x[j]; + move32(); } x[j - 1] = tempr; + move32(); } return; @@ -2235,7 +2273,14 @@ Word32 anint_fixed( Word32 x, Word16 exp ) { return 0; } - return GE_32( x, 0 ) ? L_add( x, L_shl( 1, exp - 1 ) ) : L_sub( x, L_shl( 1, exp - 1 ) ); + IF( GE_32( x, 0 ) ) + { + return L_add( x, L_shl( 1, exp - 1 ) ); + } + ELSE + { + return L_sub( x, L_shl( 1, exp - 1 ) ); + } } /*-------------------------------------------------------------------* @@ -2246,10 +2291,11 @@ Word32 anint_fixed( Word32 x, Word16 exp ) Word32 ceil_fixed( Word32 x, Word16 exp ) { Word32 step; - step = x / L_shl( 1, exp ); - IF( GT_32( x % L_shl( 1, exp ), 0 ) ) + // step = x / L_shl( 1, exp ); + step = L_shr( x, exp ); + if ( ( x % L_shl( 1, exp ) ) > 0 ) { - step++; + step = L_add( step, 1 ); } return L_shl( step, exp ); } diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 98568a301..6369b678f 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -308,6 +308,7 @@ Word16 usquant_fx( /* o: index of the winning codeword */ Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* idx = (short)( (x - qlow)/delta + 0.5f); */ @@ -351,6 +352,7 @@ Word32 Dot_product( /* o : Sum */ Word64 L64_sum; L64_sum = 1; + move64(); FOR( i = 0; i < lg; i++ ) { L64_sum = W_mac_16_16( L64_sum, x[i], y[i] ); @@ -398,6 +400,7 @@ Word32 sum2_fx( /* o : sum of all squared vector elements Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < lvec; i++ ) @@ -421,6 +424,7 @@ Word32 sum2_fx_mod( /* o : sum of all squared vector element Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_tmp = L_deposit_l( 0 ); @@ -526,6 +530,7 @@ void Copy_pword( y[i].v.im = x[i].v.im; y[i].v.re = x[i].v.re; move16(); + move16(); } } ELSE @@ -535,6 +540,7 @@ void Copy_pword( y[i].v.im = x[i].v.im; y[i].v.re = x[i].v.re; move16(); + move16(); } } } @@ -603,6 +609,7 @@ void set32_fx( FOR( i = 0; i < N; i++ ) { y[i] = L_deposit_l( tmp ); + move32(); } } ELSE @@ -632,6 +639,7 @@ void Copy_Scale_sig( Word16 tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif IF( exp0 == 0 ) { @@ -678,6 +686,7 @@ void Copy_Scale_sig_16_32( Word16 tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -686,6 +695,7 @@ void Copy_Scale_sig_16_32( FOR( i = 0; i < lg; i++ ) { y[i] = L_deposit_l( x[i] ); + move32(); } return; } @@ -699,6 +709,7 @@ void Copy_Scale_sig_16_32( #else y[i] = L_deposit_l( shl( x[i], exp0 ) ); #endif + move32(); } return; } @@ -725,6 +736,7 @@ void Copy_Scale_sig_16_32_no_sat( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -733,6 +745,7 @@ void Copy_Scale_sig_16_32_no_sat( FOR( i = 0; i < lg; i++ ) { y[i] = L_deposit_l( x[i] ); + move32(); } return; } @@ -746,6 +759,7 @@ void Copy_Scale_sig_16_32_no_sat( #else y[i] = L_deposit_l( shl( x[i], exp0 ) ); #endif + move32(); } return; } @@ -773,6 +787,7 @@ void Copy_Scale_sig_32_16( Word16 tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif tmp = add( 16, exp0 ); @@ -785,6 +800,7 @@ void Copy_Scale_sig_32_16( #else y[i] = round_fx( L_shl( x[i], tmp ) ); #endif + move16(); } } ELSE @@ -796,6 +812,7 @@ void Copy_Scale_sig_32_16( #else y[i] = round_fx( x[i] ); #endif + move16(); } } } @@ -814,6 +831,7 @@ void Scale_sig32( Word16 i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( i = 0; i < lg; i++ ) @@ -1177,7 +1195,6 @@ Word16 maximum_abs_32_fx( /* o : index of the maximum abs va ind = 0; move16(); tmp = L_abs( vec[0] ); - move16(); FOR( j = 1; j < lvec; j++ ) { @@ -1347,6 +1364,7 @@ void conv_fx( Word32 L_sum; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif y[0] = mult_r( x[0], h[0] ); move16(); @@ -1427,6 +1445,7 @@ Word16 var_fx( /* o: variance of vector Qx*/ Word32 L_tmp; L_tmp = x[0]; + move32(); FOR( i = 1; i < len; i++ ) { L_tmp = L_add( L_tmp, x[i] ); /*Qx */ @@ -1591,7 +1610,7 @@ Word16 vquant_fx( /* o: index of the winning codevector FOR( c = 0; c < cbsize; c++ ) { L_dist = 0; - move16(); + move32(); FOR( d = 0; d < dim; d++ ) { @@ -1655,6 +1674,7 @@ Word16 w_vquant_fx( Word32 dist, minDist; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -1874,12 +1894,16 @@ Word16 emaximum_32fx( /* o : return index with max energy va { W_tmp = W_mult0_32_32( vec[j], vec[j] ); W_tmp1 = W_sub( W_tmp, emax ); - IF( GT_64( W_tmp1, 0 ) ) + if ( W_tmp1 > 0 ) { ind = j; move16(); } - emax = GT_64( emax, W_tmp ) ? emax : W_tmp; + if ( LE_64( emax, W_tmp ) ) + { + emax = W_tmp; + move64(); + } } #ifdef BASOP_NOGLOB @@ -1887,7 +1911,7 @@ Word16 emaximum_32fx( /* o : return index with max energy va #else /* BASOP_NOGLOB */ *ener_max = L_shr( emax, add( Qvec, Qvec ) ); #endif /* BASOP_NOGLOB */ - move64(); + move32(); return ind; } @@ -1969,7 +1993,7 @@ Word16 Random( /* o : output random value */ ) { *seed = extract_l( L_mac0( 13849L, *seed, 31821 ) ); - + move16(); return *seed; } @@ -2205,6 +2229,7 @@ void pz_filter_sp_fx( Ltemp1 = L_add( L_shr( Lacc, s ), 0x08000 ); /* Ltemp1 in Qc+Qa+Qn=Q(Qn) */ #endif y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ + move16(); } } @@ -2217,9 +2242,10 @@ Word32 root_a_fx( Word16 exp, tmp; Word32 L_tmp; - if ( a <= 0 ) + IF( a <= 0 ) { *exp_out = 0; + move16(); return 0; } @@ -2249,9 +2275,10 @@ Word32 root_a_over_b_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif test(); - if ( ( a <= 0 ) || ( b <= 0 ) ) + IF( ( a <= 0 ) || ( b <= 0 ) ) { *exp_out = 0; move16(); @@ -2334,6 +2361,7 @@ void fir_fx( const Word16 x[], /* i : input vector Word32 s; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* prepare the input buffer (copy and update memory) */ Copy( mem, buf_in, K ); @@ -2365,6 +2393,7 @@ void fir_fx( const Word16 x[], /* i : input vector s = L_shl( s, shift ); y[i] = round_fx( s ); /*Qx */ #endif + move16(); } } @@ -2386,6 +2415,7 @@ void v_add_32( for ( i = 0; i < N; i++ ) { y[i] = L_add( x1[i], x2[i] ); + move32(); } return; @@ -2403,6 +2433,7 @@ void v_shr_32( for ( i = 0; i < N; i++ ) { y[i] = L_shr( x1[i], shift ); + move32(); } return; @@ -2424,9 +2455,10 @@ void v_sub_32( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { - y[i] = x1[i] - x2[i]; + y[i] = L_sub( x1[i], x2[i] ); + move32(); } return; @@ -2450,7 +2482,8 @@ void v_add_16( for ( i = 0; i < N; i++ ) { - y[i] = x1[i] + x2[i]; + y[i] = add_sat( x1[i], x2[i] ); + move16(); } return; @@ -2474,7 +2507,8 @@ void v_sub_16( for ( i = 0; i < N; i++ ) { - y[i] = x1[i] - x2[i]; + y[i] = sub_sat( x1[i], x2[i] ); + move16(); } return; @@ -2613,6 +2647,7 @@ void pz_filter_dp_fx( Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ #endif y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ + move16(); } } @@ -2639,6 +2674,7 @@ void Copy_Scale_sig32_16( #else *dst++ = round_fx( *src++ ); #endif + move16(); } return; } @@ -2654,6 +2690,7 @@ void Copy_Scale_sig32_16( *dst++ = round_fx( L_temp ); #endif + move16(); } } @@ -2745,6 +2782,7 @@ void v_L_mult_1616( for ( i = 0; i < N; i++ ) { y[i] = L_mult( x1[i], x2[i] ); + move32(); } return; @@ -2768,6 +2806,7 @@ void v_L_mult_3216( for ( i = 0; i < N; i++ ) { y[i] = Mpy_32_16_1( x1[i], x2[i] ); + move32(); } return; @@ -2792,6 +2831,7 @@ void add_vec_fx( Word16 i, Qyx1, Qyx2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Qyx1 = sub( Qx1, Qy ); Qyx2 = sub( Qx2, Qy ); @@ -2929,6 +2969,7 @@ Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) Word16 i, j; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Overflow = 0; @@ -3158,6 +3199,7 @@ Word16 find_rem( Word16 n, Word16 m, Word16 *r ) q1 = extract_l( Lacc ); Ltemp2 = L_shr( Lacc, q2 ); *r = extract_h( Ltemp2 ); + move16(); return ( q1 ); } @@ -3205,6 +3247,7 @@ Word32 find_remd( Word32 n, Word32 m, Word32 *r ) } } *r = L_shr( Lacc, q2 ); + move16(); return ( qo ); } @@ -3224,11 +3267,11 @@ Word16 rint_new_fx( { a = add( extract_h( x ), 1 ); - if ( s_and( a, 1 ) == 0 ) + IF( s_and( a, 1 ) == 0 ) { return a; } - if ( s_and( a, 1 ) != 0 ) + IF( s_and( a, 1 ) != 0 ) { return extract_h( x ); } @@ -3381,6 +3424,8 @@ void Acelp_dec_total_exc( L_tmp = L_add( L_tmp, L_shl( L_mult( gain_code16, code_fx[i] ), 6 ) ); /*Q16+Q_exc*/ exc_fx[i + i_subfr] = round_fx( L_tmp ); /*Q_exc*/ #endif + move16(); + move16(); } } @@ -3394,9 +3439,11 @@ UWord32 UL_inverse( const UWord32 UL_val, Word16 *exp ) UWord32 UL_tmp; *exp = norm_ul( UL_val ); + move16(); UL_tmp = UL_lshl( UL_val, *exp ); /* Q32 */ *exp = add( 32, sub( 31, *exp ) ); + move16(); return UL_div( 0x80000000, UL_tmp ); } @@ -3446,7 +3493,7 @@ Word16 ratio( const Word32 numer, const Word32 denom, Word16 *expo ) quotient = div_s( manNumer, manDenom ); /* in Q14 */ *expo = sub( expNumer, expDenom ); - + move16(); return quotient; /* Q14 */ } @@ -3494,7 +3541,7 @@ void hp400_12k8_fx( L_tmp3 = L_mult( mem[4], b_hp400_fx[2] ); mem[5] = signal[lg - 2]; - + move16(); FOR( i = 1; i < lg; i++ ) { /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ @@ -3520,6 +3567,7 @@ void hp400_12k8_fx( /* signal is divided by 16 to avoid overflow in energy computation */ *signal++ = round_fx( L_tmp ); + move16(); } /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ @@ -3541,6 +3589,7 @@ void hp400_12k8_fx( /* signal is divided by 16 to avoid overflow in energy computation */ *signal++ = round_fx( L_tmp ); + move16(); return; } @@ -3631,6 +3680,7 @@ Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy Word16 *pt1, *pt2; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -3675,7 +3725,7 @@ Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy ener = extract_h( L_tmp ); /*Q(qx+qy-shift+q-16) */ q = add( q, add( qx, qy ) ); *qo = sub( q, add( shift, 16 ) ); - + move16(); return ener; } @@ -3706,12 +3756,14 @@ void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Wo FOR( n = 0; n < size; n++ ) { L64_sum = 0; + move64(); FOR( i = 0; i < n; i++ ) { L64_sum = W_mac_16_16( L64_sum, x[i], h[n - i] ); } L_sum = W_sat_l( L64_sum ); y[n] = mac_r( L_sum, x[i], h[0] ); + move16(); } return; } @@ -3737,7 +3789,7 @@ void floating_point_add( accY = L_shr( my, 1 ); /* First, align the Q-points of the two operands. Then, add. */ align = sub( *ex, ey ); - test(); + IF( align < 0 ) { accX = L_add( accX, L_shl( accY, align ) ); @@ -3752,6 +3804,8 @@ void floating_point_add( expo = norm_l( accX ); *mx = L_shl( accX, expo ); *ex = sub( add( *ex, expo ), 1 ); /* Subtract 1 due to 1-bit down-shift above ensuring 1 bit headroom before addition. */ + move32(); + move16(); return; } /*-------------------------------------------------------------------* @@ -3770,8 +3824,8 @@ void delay_signal( Word16 tmp_buffer[L_FRAME48k]; Copy( mem, tmp_buffer, delay ); - Copy( x + len - delay, mem, delay ); - Copy( x, x + delay, len - delay ); + Copy( x + sub( len, delay ), mem, delay ); + Copy( x, x + delay, sub( len, delay ) ); Copy( tmp_buffer, x, delay ); return; @@ -3781,15 +3835,15 @@ void delay_signal_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 int16_t delay /* i : delay in samples */ + const Word16 delay /* i : delay in samples */ ) { Word32 tmp_buffer[L_FRAME48k]; Copy32( mem, tmp_buffer, delay ); - Copy32( x + len - delay, mem, delay ); - Copy32( x, x + delay, len - delay ); + Copy32( x + sub( len, delay ), mem, delay ); + Copy32( x, x + delay, sub( len, delay ) ); Copy32( tmp_buffer, x, delay ); return; @@ -3797,9 +3851,9 @@ void delay_signal_fx( #ifdef IVAS_FLOAT_FIXED void delay_signal_q_adj_fx( Word32 x[], /* i/o: signal to be delayed */ - const int16_t len, /* i : length of the input signal */ + const Word16 len, /* i : length of the input signal */ Word32 mem[], /* i/o: synchronization memory */ - const int16_t delay, /* i : delay in samples */ + const Word16 delay, /* i : delay in samples */ const Word16 q_x, const Word16 q_mem ) { @@ -3807,8 +3861,8 @@ void delay_signal_q_adj_fx( Word32 tmp_buffer[L_FRAME48k]; Copy32( mem, tmp_buffer, delay ); - Copy32( x + len - delay, mem, delay ); - Copy32( x, x + delay, len - delay ); + Copy32( x + sub( len, delay ), mem, delay ); + Copy32( x, x + delay, sub( len, delay ) ); IF( EQ_16( q_x, q_mem ) ) @@ -3828,55 +3882,66 @@ void v_add_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 int16_t N /* i : Vector length */ + const Word16 N /* i : Vector length */ ) { - int16_t i; + Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = L_add_sat( x1[i], x2[i] ); + move32(); } return; } Word16 floor_log_2( Word32 num ) { - return num < 2 ? 0 : num < 4 ? 1 - : num < 8 ? 2 - : num < 16 ? 3 - : num < 32 ? 4 - : num < 64 ? 5 - : num < 128 ? 6 - : num < 256 ? 7 - : num < 512 ? 8 - : num < 1024 ? 9 - : num < 2048 ? 10 - : num < 4096 ? 11 - : num < 8192 ? 12 - : num < 16384 ? 13 - : num < 32768 ? 14 - : num < 65536 ? 15 - : num < 131072 ? 16 - : num < 262144 ? 17 - : num < 524288 ? 18 - : num < 1048576 ? 19 - : num < 2097152 ? 20 - : 21; +#if 0 + return num < 2 ? 0 : num < 4 ? 1 + : num < 8 ? 2 + : num < 16 ? 3 + : num < 32 ? 4 + : num < 64 ? 5 + : num < 128 ? 6 + : num < 256 ? 7 + : num < 512 ? 8 + : num < 1024 ? 9 + : num < 2048 ? 10 + : num < 4096 ? 11 + : num < 8192 ? 12 + : num < 16384 ? 13 + : num < 32768 ? 14 + : num < 65536 ? 15 + : num < 131072 ? 16 + : num < 262144 ? 17 + : num < 524288 ? 18 + : num < 1048576 ? 19 + : num < 2097152 ? 20 + : 21; +#endif + + IF( EQ_32( num, 0 ) ) + { + return 0; + } + + return ( sub( 30, norm_l( num ) ) ); } void v_shr( const Word32 x[], /* i : Input vector */ const Word16 shift, /* i : Constant */ - Word32 y[], /* o : Output vector that contains x >> shift */ + Word32 y[], /* o : Output vector that contains x >> shift */ const Word16 N /* i : Vector length */ ) { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = L_shr( x[i], shift ); + move32(); } return; @@ -3891,9 +3956,10 @@ void v_shr_16( { Word16 i; - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { y[i] = shr( x[i], shift ); + move16(); } return; @@ -3915,8 +3981,8 @@ void delay_signal32( Word32 tmp_buffer[L_FRAME48k]; Copy32( mem, tmp_buffer, delay ); - Copy32( x + len - delay, mem, delay ); - Copy32( x, x + delay, len - delay ); + Copy32( x + sub( len, delay ), mem, delay ); + Copy32( x, x + delay, sub( len, delay ) ); Copy32( tmp_buffer, x, delay ); return; @@ -3939,7 +4005,7 @@ Word16 lin_interp_fx( const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ ) { - IF( EQ_16( sub( x2, x1 ), 0 ) ) + IF( sub( x2, x1 ) == 0 ) { return y1; } @@ -3947,11 +4013,25 @@ Word16 lin_interp_fx( { IF( GE_16( x, s_max( x1, x2 ) ) ) { - return GT_16( x1, x2 ) ? y1 : y2; + IF( GT_16( x1, x2 ) ) + { + return y1; + } + ELSE + { + return y2; + } } ELSE IF( LE_16( x, s_min( x1, x2 ) ) ) { - return LT_16( x1, x2 ) ? y1 : y2; + IF( LT_16( x1, x2 ) ) + { + return y1; + } + ELSE + { + return y2; + } } } @@ -3969,7 +4049,7 @@ Word32 sign_l( const Word32 x /* i : input value of x */ ) { - IF( LT_32( x, 0 ) ) + IF( x < 0 ) { return MIN_32; } @@ -3991,6 +4071,7 @@ void v_mult16_fixed( FOR( i = 0; i < N; i++ ) { y[i] = mult_r( x1[i], x2[i] ); + move16(); } return; diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index b088be832..32d94aa49 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -44,6 +44,7 @@ void direct_transform_fx( #ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING (void) ( element_mode ); #endif + move16(); segment_length = shr( L, 1 ); segment_length2 = shr( segment_length, 1 ); @@ -68,10 +69,8 @@ void direct_transform_fx( win_fx = wscw16q15_16_fx; } - sh_fx = &in32_fx[L - 1]; - add( 0, 0 ); - sl_fx = &in32_r16_fx[L - 1]; - add( 0, 0 ); + sh_fx = &in32_fx[sub( L, 1 )]; + sl_fx = &in32_r16_fx[sub( L, 1 )]; FOR( i = 0; i < segment_length; i++ ) { in32_r16_fx[i] = ( *sh_fx-- ); @@ -81,16 +80,13 @@ void direct_transform_fx( } iseg_fx = &in32_r16_fx[-segment_length4]; - add( 0, 0 ); oseg_fx = out32_fx; wh_fx = &win_fx[segment_length4]; - add( 0, 0 ); wl_fx = wh_fx - 1; shift = extract_l( L_mult0( 3, segment_length4 ) ); sh_fx = &iseg_fx[shift]; - add( 0, 0 ); sl_fx2 = sh_fx - 1; @@ -101,8 +97,7 @@ void direct_transform_fx( move32(); /*Q */ } - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add( 0, 0 ); + sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; FOR( i = segment_length4; i < segment_length2; i++ ) { @@ -116,17 +111,13 @@ void direct_transform_fx( Qmin = s_min( Qs[0], Qmin ); iseg_fx += segment_length2; - add( 0, 0 ); oseg_fx += segment_length2; - add( 0, 0 ); FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { wh_fx = &win_fx[segment_length4]; - add( 0, 0 ); wl_fx = wh_fx - 1; sh_fx = &iseg_fx[shift]; - add( 0, 0 ); sl_fx2 = sh_fx - 1; FOR( i = 0; i < segment_length4; i++ ) { @@ -136,10 +127,8 @@ void direct_transform_fx( } sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add( 0, 0 ); - wh_fx = &win_fx[segment_length2 - 1]; - add( 0, 0 ); + sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; + wh_fx = &win_fx[sub( segment_length2, 1 )]; wl_fx = win_fx; FOR( i = segment_length4; i < segment_length2; i++ ) @@ -155,13 +144,10 @@ void direct_transform_fx( Qmin = s_min( Qs[seg], Qmin ); iseg_fx += segment_length2; - add( 0, 0 ); oseg_fx += segment_length2; - add( 0, 0 ); } - sh_fx = &iseg_fx[shift - 1]; - add( 0, 0 ); + sh_fx = &iseg_fx[sub( shift, 1 )]; FOR( i = 0; i < segment_length4; i++ ) { dctin32_fx[i] = L_negate( *sh_fx-- ); @@ -170,10 +156,8 @@ void direct_transform_fx( sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add( 0, 0 ); - wh_fx = &win_fx[segment_length2 - 1]; - add( 0, 0 ); + sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; + wh_fx = &win_fx[sub( segment_length2, 1 )]; wl_fx = win_fx; FOR( i = segment_length4; i < segment_length2; i++ ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index f94faadc5..ae75fcf2f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1005,7 +1005,7 @@ static ivas_error ivas_dirac_rend_config_fx( { ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); } - IF( NE_32( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dirac_alloc_mem_fx( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5dafca0bc..d844c7435 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2290,7 +2290,7 @@ ivas_error ivas_init_decoder_fx( } ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ), - st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) @@ -3114,7 +3114,7 @@ ivas_error ivas_init_decoder_fx( * Allocate and initialize limiter struct *-----------------------------------------------------------------*/ - IF( NE_32( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_limiter_open_fx( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -4890,7 +4890,7 @@ void ivas_destroy_dec_fx( ivas_param_mc_dec_close_fx( &st_ivas->hParamMC ); /* EFAP handle */ - efap_free_data( &st_ivas->hEFAPdata ); + efap_free_data_fx( &st_ivas->hEFAPdata ); /* VBAP handle */ vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); @@ -4962,7 +4962,7 @@ void ivas_destroy_dec_fx( ivas_render_config_close( &( st_ivas->hRenderConfig ) ); /* Limiter struct */ - ivas_limiter_close( &( st_ivas->hLimiter ) ); + ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); IF( st_ivas->hDecoderConfig != NULL ) { diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index b806bc79c..5a62afa9e 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -175,7 +175,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( NE_16( st_ivas->ism_mode, last_ism_mode ) ) { /* EFAP handle */ - efap_free_data( &st_ivas->hEFAPdata ); + efap_free_data_fx( &st_ivas->hEFAPdata ); } /*-----------------------------------------------------------------* diff --git a/lib_dec/pit_dec.c b/lib_dec/pit_dec.c index 250571511..3574218f3 100644 --- a/lib_dec/pit_dec.c +++ b/lib_dec/pit_dec.c @@ -41,6 +41,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*----------------------------------------------------------* * pit_decode_flt() @@ -837,3 +838,4 @@ void Mode2_delta_pit_dec_flt( return; } +#endif diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 6ba37df9e..ca405c01d 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -292,7 +292,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( // printf( "\n%f", ((float)*p_dec_mtx)/ ONE_IN_Q25 ); p_dec_mtx++; } - p_dec_mtx += sub( SBA_NHARM_HOA3, num_harm ); + p_dec_mtx += sub( SBA_NHARM_HOA3 , num_harm ); } } @@ -310,11 +310,11 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( move32(); p_dec_mtx++; } - p_dec_mtx += sub( SBA_NHARM_HOA3, num_harm ); + p_dec_mtx += sub( SBA_NHARM_HOA3 , num_harm ); } /* free EFAP handle */ - efap_free_data( &hEFAP ); + efap_free_data_fx( &hEFAP ); } ELSE { diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index c5d73c231..013051554 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -62,7 +62,7 @@ #define DIRAC_ALPHA_MAX_FAST 0.12f #define DIRAC_ALPHA_MAX_FAST_Q15 3932 #define DIRECTION_SMOOTHNESS_ALPHA 0.01f -#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( Word32 )( 0.01f * ONE_IN_Q31 ) +#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) #ifdef IVAS_FLOAT_FIXED #define POINT_3679_Q31 790059234 @@ -83,8 +83,15 @@ static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, const Word1 static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, const Word32 *onset_filter, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); -#else +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ); + +static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); + +static void spreadCoherencePanningVbap_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response, const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata ); + +static void normalizePanningGains_fx( Word32 *direct_response_fx, Word16 *q_direct_res, const Word16 num_channels_dir ); +#else static void computeTargetPSDs_direct( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); static void computeTargetPSDs_direct_subframe( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); @@ -94,29 +101,17 @@ static void computeTargetPSDs_diffuse( const int16_t num_channels, const int16_t static void computeTargetPSDs_diffuse_subframe( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); -#endif -#ifndef IVAS_FLOAT_FIXED -static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, const float maxAlpha, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, const int32_t output_Fs ); -#endif - -#ifdef IVAS_FLOAT_FIXED -static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const int16_t averaging_length_ms, const Word16 maxAlpha_fx, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, Word16 *frequency_axis_fx, const int32_t output_Fs ); - -static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); -static void spreadCoherencePanningVbap_fx( const int16_t azimuth, const int16_t elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); +static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, const float maxAlpha, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, const int32_t output_Fs ); -static void normalizePanningGains_fx( Word32 *direct_response_fx, Word16 *q_direct_res, const Word16 num_channels_dir ); -#endif -#ifndef IVAS_FLOAT_FIXED static void spreadCoherencePanningHoa( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const int16_t ambisonics_order ); -#ifndef IVAS_FLOAT_FIXED + static void spreadCoherencePanningVbap( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); -#endif // !IVAS_FLOAT_FIXED static void normalizePanningGains( float *direct_response, const int16_t num_channels_dir ); #endif + /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_open() * @@ -124,23 +119,25 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -extern Word16 find_guarded_bits_fx( Word32 n ); - ivas_error ivas_dirac_dec_output_synthesis_open_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { - int16_t idx, ch_idx; - int16_t size; - uint16_t num_diffuse_responses; - Word16 tmp_fx; + Word16 idx, ch_idx; + Word16 size; + UWord16 num_diffuse_responses; + Word16 tmp_fx, tmp16; Word16 temp_alpha_synthesis_fx[CLDFB_NO_CHANNELS_MAX]; Word16 interpolator_tbl[JBM_CLDFB_SLOTS_IN_SUBFRAME] = { 8192, 16384, 24576, MAX16B }; /* idx / JBM_CLDFB_SLOTS_IN_SUBFRAME Q15 */ + move16(); + move16(); + move16(); + move16(); /* pointers to structs for allocation */ DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); @@ -157,10 +154,12 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( IF( hDirACRend->proto_signal_decorr_on ) { dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; + move16(); } ELSE { dirac_output_synthesis_params->max_band_decorr = 0; + move16(); } /*-----------------------------------------------------------------* @@ -169,7 +168,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( dirac_output_synthesis_state->diffuse_responses_square_fx = NULL; - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { IF( ( dirac_output_synthesis_state->diffuse_responses_square_fx = (Word32 *) malloc( 2 * sizeof( Word32 ) ) ) == NULL ) { @@ -187,21 +186,25 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( /* prototype power buffers */ dirac_output_synthesis_state->proto_power_smooth_prev_fx = NULL; - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { IF( ( dirac_output_synthesis_state->proto_power_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->proto_power_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir; + dirac_output_synthesis_state->proto_power_smooth_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); + move16(); } - IF( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) + test(); + test(); + IF( dirac_output_synthesis_params->max_band_decorr > 0 && ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { IF( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->proto_power_diff_smooth_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE; + dirac_output_synthesis_state->proto_power_diff_smooth_prev_len = imult1616( dirac_output_synthesis_params->max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ); + move16(); } ELSE { @@ -217,25 +220,27 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( /* target PSD buffers */ IF( hodirac_flag ) { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; + size = imult1616( imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), DIRAC_HO_NUMSECTORS ); } ELSE { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + size = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ); } IF( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx = (Word32 *) malloc( size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } dirac_output_synthesis_state->cy_cross_dir_smooth_prev_len = size; - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + move16(); + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = NULL; IF( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff; + dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = imult1616( dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ); + move16(); } ELSE { @@ -243,15 +248,17 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ); + move16(); - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { IF( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ); + move16(); } ELSE { @@ -259,7 +266,8 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff; + dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ); + move16(); } } @@ -269,21 +277,25 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } dirac_output_synthesis_state->gains_dir_prev_len = size; - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + move16(); + test(); + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->gains_diff_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff; + dirac_output_synthesis_state->gains_diff_prev_len = imult1616( dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ); + move16(); } - ELSE IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) + ELSE IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->gains_diff_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff; + dirac_output_synthesis_state->gains_diff_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ); + move16(); } ELSE { @@ -291,7 +303,8 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->gains_diff_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + dirac_output_synthesis_state->gains_diff_prev_len = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ); + move16(); } /*-----------------------------------------------------------------* @@ -299,7 +312,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( *-----------------------------------------------------------------*/ /* compute alpha */ - IF( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) + test(); + test(); + IF( !( EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX_Q15, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs ); @@ -323,6 +338,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } set32_fx( dirac_output_synthesis_state->reference_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands ); dirac_output_synthesis_state->reference_power_smooth_prev_q = Q31; + move16(); IF( ( dirac_output_synthesis_state->direction_smoothness_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -346,13 +362,15 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } /* prepare diffuse response function */ - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { num_diffuse_responses = 2; + move16(); } ELSE { num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); } IF( dirac_output_synthesis_state->diffuse_responses_square_fx != NULL ) @@ -369,47 +387,69 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { Word16 diff_compensation_order; Word32 diff_nrg_total_fx, diff_nrg_fx, diff_nrg_trans_fx, diff_nrg_decorr_fx; - diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ + /* compensate missing diffuseness modelling up order 2, except for HR*/ + IF( GE_16( nchan_transport, 3 ) ) + { + diff_compensation_order = 3; + move16(); + } + ELSE + { + diff_compensation_order = 2; + move16(); + } diff_compensation_order = s_min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order ); diff_nrg_total_fx = 0; + move32(); diff_nrg_trans_fx = 0; + move32(); diff_nrg_decorr_fx = 0; + move32(); - Word16 gaurd_bits = find_guarded_bits_fx( ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ) ); - FOR( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ ) + Word16 gaurd_bits = find_guarded_bits_fx( imult1616( add( diff_compensation_order, 1 ), add( diff_compensation_order, 1 ) ) ); + tmp16 = add( diff_compensation_order, 1 ); + tmp16 = imult1616( tmp16, tmp16 ); + FOR( ch_idx = 0; ch_idx < tmp16; ch_idx++ ) { diff_nrg_fx = L_shr( L_mult0( hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx] ), gaurd_bits ); // Q30 - gaurd_bits diff_nrg_total_fx = L_add( diff_nrg_total_fx, diff_nrg_fx ); /* is it a transport channel?*/ - IF( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) + test(); + if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { diff_nrg_trans_fx = L_add( diff_nrg_trans_fx, diff_nrg_fx ); } /* is it a decorrelated or transport channel?*/ - IF( ch_idx < hDirACRend->num_outputs_diff ) + if ( LT_16( ch_idx, hDirACRend->num_outputs_diff ) ) { diff_nrg_decorr_fx = L_add( diff_nrg_decorr_fx, diff_nrg_fx ); } } Word16 exp_1 = 0, exp_2 = 0, tmp; + move16(); + move16(); tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // (Q15 - exp_diff) dirac_output_synthesis_params->diffuse_compensation_factor_fx = L_shl( L_deposit_l( tmp ), add( Q12, exp_1 ) ); // Q27 + move32(); tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_diff) dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = L_shl( L_deposit_l( tmp ), add( Q14, exp_2 ) ); // Q29 + move32(); } ELSE { dirac_output_synthesis_params->diffuse_compensation_factor_fx = 0; + move32(); dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = 0; + move32(); } return IVAS_ERR_OK; @@ -778,63 +818,71 @@ void ivas_dirac_dec_output_synthesis_init_fx( /* initialize buffers */ IF( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx != NULL ) { - set32_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + set32_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx, 0, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev = 0; + move16(); IF( hodirac_flag ) { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; + size = imult1616( imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), DIRAC_HO_NUMSECTORS ); } ELSE { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + size = imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ); } set32_fx( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx, 0, size ); h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = 0; + move16(); - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); + set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, imult1616( h_dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ) ); } - ELSE IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + ELSE IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { - set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); + set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); } ELSE { - set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + set32_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = 0; + move16(); IF( h_dirac_output_synthesis_state->proto_power_smooth_prev_fx != NULL ) { - set32_fx( h_dirac_output_synthesis_state->proto_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir ); + set32_fx( h_dirac_output_synthesis_state->proto_power_smooth_prev_fx, 0, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ) ); h_dirac_output_synthesis_state->proto_power_smooth_prev_q = Q31; + move16(); } set32_fx( h_dirac_output_synthesis_state->gains_dir_prev_fx, 0, size ); h_dirac_output_synthesis_state->gains_dir_prev_q = 0; + move16(); - IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); + set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, imult1616( h_dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ) ); } ELSE { - set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + set32_fx( h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } h_dirac_output_synthesis_state->gains_diff_prev_q = 0; + move16(); IF( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx != NULL ) { - set32_fx( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE ); + set32_fx( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx, 0, imult1616( h_dirac_output_synthesis_params->max_band_decorr, nchan_out_woLFE ) ); } h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_q = Q31; + move16(); return; } #endif + /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_close() * @@ -1036,6 +1084,7 @@ void ivas_dirac_dec_output_synthesis_close_fx( * * *------------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_slot( const float *reference_power, /* i : Estimated power */ @@ -1293,7 +1342,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Word16 num_freq_bands_diff, num_channels_diff; Word16 ch_idx; Word32 aux_buf[CLDFB_NO_CHANNELS_MAX]; - Word16 diff_start_band; + Word16 diff_start_band, tmp16; DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; @@ -1308,9 +1357,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /* collect some often used parameters */ num_freq_bands = hSpatParamRendCom->num_freq_bands; + move16(); num_channels_dir = hDirACRend->num_outputs_dir; + move16(); num_channels_diff = hDirACRend->num_outputs_diff; + move16(); num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { @@ -1318,6 +1371,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( move16(); } + test(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) && hodirac_flag ) { ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, @@ -1337,8 +1391,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); h_dirac_output_synthesis_state->direct_responses_square_q = 31; + move16(); } Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); IF( hodirac_flag ) @@ -1346,14 +1401,16 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); } h_dirac_output_synthesis_state->direct_responses_q = 31; + move16(); } } - IF( EQ_16( dec_param_estim, FALSE ) && hodirac_flag ) + test(); + IF( dec_param_estim == FALSE && hodirac_flag ) { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], L_negate( MAX_32 ), aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); Copy32( hSpatParamRendCom->energy_ratio1_fx[md_idx], h_dirac_output_synthesis_state->direct_power_factor_fx, @@ -1362,7 +1419,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands ); - v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], L_negate( MAX_32 ), aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); Copy32( hSpatParamRendCom->energy_ratio2_fx[md_idx], &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], @@ -1372,7 +1429,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( num_freq_bands ); h_dirac_output_synthesis_state->diffuse_power_factor_q = 30; + move16(); h_dirac_output_synthesis_state->direct_power_factor_q = 30; + move16(); } ELSE { @@ -1404,8 +1463,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, num_channels_dir * num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); h_dirac_output_synthesis_state->direct_responses_square_q = 31; + move16(); } Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); IF( hodirac_flag ) @@ -1413,6 +1473,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); } h_dirac_output_synthesis_state->direct_responses_q = 31; + move16(); } IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -1439,7 +1500,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Word16 *Q_temp_cy_cross_dir_smooth_fx = (Word16 *) malloc( num_freq_bands * num_channels_dir * sizeof( Word16 ) ); - FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) + tmp16 = imult1616( num_freq_bands, num_channels_dir ); + FOR( Word16 kk = 0; kk < tmp16; kk++ ) { Q_temp_cy_cross_dir_smooth_fx[kk] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); @@ -1448,7 +1510,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( FOR( ch_idx = 0; ch_idx < s_min( 4, nchan_transport ); ch_idx++ ) { Word16 k; - IF( NE_16( ch_idx, 0 ) ) + IF( ch_idx != 0 ) { Word32 a, c; Word16 b, b_exp, sqr_exp, q_diff_aab, q_diff_c; @@ -1459,14 +1521,17 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( FOR( k = 0; k < num_freq_bands_diff; k++ ) { a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses - IF( EQ_32( reference_power[k + num_freq_bands], 0 ) ) + move32(); + IF( reference_power[add( k, num_freq_bands )] == 0 ) { b = 0; + move16(); b_exp = 0; + move16(); } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], L_add( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], EPSILON_FX ), &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[add( k, num_freq_bands )], L_add( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], EPSILON_FX ), &b_exp ); } c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ @@ -1474,66 +1539,80 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - q_diff_aab = ( h_dirac_output_synthesis_state->direct_responses_q + ( 31 - b_exp ) - 31 ) + ( h_dirac_output_synthesis_state->direct_responses_q ) - 31 + q_diffuseness - 31; + q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 31, b_exp ) ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); - IF( NE_32( mpy_diff_c, 0 ) && NE_32( mpy_diff_aab, 0 ) ) + test(); + IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); } ELSE { - IF( EQ_32( mpy_diff_c, 0 ) ) + IF( mpy_diff_c == 0 ) { sqr_inp = mpy_diff_aab; + move32(); sqr_exp = sub( 31, q_diff_aab ); } ELSE { sqr_inp = mpy_diff_c; + move32(); sqr_exp = sub( 31, q_diff_c ); } } sqr = Sqrt32( sqr_inp, &sqr_exp ); sqr = L_shr( sqr, 2 ); - IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); } ELSE { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } } FOR( ; k < num_freq_bands; k++ ) { a = h_dirac_output_synthesis_state->direct_responses_fx[add( i_mult( ch_idx, num_freq_bands ), k )]; // Q = h_dirac_output_synthesis_state->q_direct_responses - IF( EQ_32( reference_power[k + num_freq_bands], 0 ) ) + move32(); + IF( reference_power[k + num_freq_bands] == 0 ) { b = 0; + move16(); b_exp = 0; + move16(); } ELSE { - IF( EQ_32( reference_power[k + ( ch_idx + 1 ) * num_freq_bands], 0 ) ) + IF( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )] == 0 ) { b = MAXVAL_WORD16; + move16(); b_exp = 40; + move16(); } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )], &b_exp ); } } c = L_add( ONE_IN_Q29, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ @@ -1542,46 +1621,55 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( mpy_diff_aab = Mpy_32_32( L_sub( L_shl( 1, q_diffuseness ), diffuseness[k] ), mpy_a_a_b ); // Q = 2*(h_dirac_output_synthesis_state->q_direct_responses) - b_exp - 31 + q_diffuseness -31 mpy_diff_c = Mpy_32_32( diffuseness[k], c ); // Q = q_diffuseness - 2 - q_diff_aab = ( h_dirac_output_synthesis_state->direct_responses_q + ( 31 - b_exp ) - 31 ) + ( h_dirac_output_synthesis_state->direct_responses_q ) - 31 + q_diffuseness - 31; + q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 31, b_exp ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); - IF( NE_32( mpy_diff_c, 0 ) && NE_32( mpy_diff_aab, 0 ) ) + test(); + IF( mpy_diff_c != 0 && mpy_diff_aab != 0 ) { sqr_inp = BASOP_Util_Add_Mant32Exp( mpy_diff_c, sub( 31, q_diff_c ), mpy_diff_aab, sub( 31, q_diff_aab ), &sqr_exp ); } ELSE { - IF( EQ_32( mpy_diff_c, 0 ) ) + IF( mpy_diff_c == 0 ) { sqr_inp = mpy_diff_aab; + move32(); sqr_exp = sub( 31, q_diff_aab ); } ELSE { sqr_inp = mpy_diff_c; + move32(); sqr_exp = sub( 31, q_diff_c ); } } sqr = Sqrt32( sqr_inp, &sqr_exp ); sqr = L_shr( sqr, 2 ); - IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); } ELSE { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } } } @@ -1597,24 +1685,30 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); sqr = Sqrt32( sqr_inp, &sqr_exp ); sqr = L_shr( sqr, 2 ); - IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); } ELSE { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } } FOR( ; k < num_freq_bands; k++ ) @@ -1624,49 +1718,60 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); sqr = Sqrt32( sqr_inp, &sqr_exp ); sqr = L_shr( sqr, 2 ); - IF( NE_32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], 0 ) ) + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] != 0 ) { IF( LT_16( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } ELSE { sqr = L_shr( sqr, sub( sub( 31, sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; + move16(); } h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); } ELSE { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )], sqr ); + move32(); Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + move16(); } } } } Word16 temp = MAX_16; - FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) + move16(); + tmp16 = imult1616( num_freq_bands, num_channels_dir ); + FOR( Word16 kk = 0; kk < tmp16; kk++ ) { temp = s_min( Q_temp_cy_cross_dir_smooth_fx[kk], temp ); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp; move16(); - FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) + FOR( Word16 kk = 0; kk < tmp16; kk++ ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp, Q_temp_cy_cross_dir_smooth_fx[kk] ) ); + move32(); } free( Q_temp_cy_cross_dir_smooth_fx ); /*Directional gain (panning)*/ Word16 temp_q = sub( add( h_dirac_output_synthesis_state->direct_power_factor_q, h_dirac_output_synthesis_state->direct_responses_q ), 31 ); IF( LT_16( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ) { - FOR( Word16 kk = 0; kk < num_freq_bands * num_channels_dir; kk++ ) + FOR( Word16 kk = 0; kk < tmp16; kk++ ) { h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk] = L_shl( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[kk], sub( temp_q, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); + move32(); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp_q; + move16(); } FOR( ch_idx = s_min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { @@ -1681,8 +1786,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, 0 ); // Todo:Hdrm } @@ -1695,8 +1800,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( num_freq_bands_diff ); v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, 0 ); // Todo:Hdrm } @@ -1714,7 +1819,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); h_dirac_output_synthesis_state->diffuse_power_factor_q = 31; + move16(); h_dirac_output_synthesis_state->direct_power_factor_q = 31; + move16(); } } @@ -1748,13 +1855,15 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( return; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*------------------------------------------------------------------------- - * ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx() + * ivas_dirac_dec_output_synthesis_process_subframe_gain_shd() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -1820,30 +1929,30 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_multc_fixed( diffuseness, // Q30 - ONE_IN_Q31, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + v_multc_fixed( diffuseness, // Q30 + ONE_IN_Q31, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 - L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 + L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 num_freq_bands ); FOR( l = 0; l < num_freq_bands; l++ ) { - exp = sub( Q31, Q26 ); - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), + exp = Q31 - Q26; + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); } @@ -1855,36 +1964,36 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { aux_buf[l] = L_sub( ONE_IN_Q30, diffuseness[l] ); // Q30 move32(); - ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[num_freq_bands + l] ); // Q31 + ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[add( num_freq_bands, l )] ); // Q31 move32(); - ratio_float[l + num_freq_bands] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 + ratio_float[add( l, num_freq_bands )] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 move32(); } v_mult_fixed( aux_buf, ratio_float, ratio_float, num_freq_bands ); //(Q30, Q31) -> Q30 v_mult_fixed( aux_buf, &ratio_float[num_freq_bands], &ratio_float[num_freq_bands], num_freq_bands ); //(Q30, Q31) -> Q30 - v_mult_fixed( ratio_float, // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], //(Q30, Q31) -> Q30 + v_mult_fixed( ratio_float, // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], //(Q30, Q31) -> Q30 num_freq_bands ); - v_mult_fixed( &ratio_float[num_freq_bands], // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], //(Q30, Q31) -> Q30 + v_mult_fixed( &ratio_float[num_freq_bands], // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], //(Q30, Q31) -> Q30 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q30 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], num_freq_bands, sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], num_freq_bands, sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); } @@ -1897,17 +2006,17 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); } @@ -1922,34 +2031,34 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_decorr_fx, Q3 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 num_freq_bands_diff ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q31 - L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q26 num_freq_bands - num_freq_bands_diff ); FOR( l = 0; l < num_freq_bands; l++ ) { - exp = sub( Q31, Q26 ); - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), + exp = Q31 - Q26; + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); } @@ -1957,17 +2066,17 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Directional gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); } @@ -1980,17 +2089,17 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); } @@ -2017,12 +2126,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g1 = L_add( POINT_3679_Q31, Mpy_32_32( onset_filter[l], - L_sub( 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, (Word32) ( 0.99f * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - g2 = L_min( g2, (Word32) ( 2.0f * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - *( p_gains_dir++ ) = g2; // p_gains_dir_q + 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 + g2 = L_min( g2, Mpy_32_32( ONE_IN_Q31 /* 2.0f in Q30 */, L_shl( 1, add( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 1 ) ) ) ); // p_gains_dir_q + *( p_gains_dir++ ) = g2; // p_gains_dir_q move32(); } } @@ -2035,12 +2144,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g1 = L_add( POINT_3679_Q31, Mpy_32_32( onset_filter[l], - L_sub( 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, (Word32) ( 0.85f * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - g2 = L_min( g2, (Word32) ( 1.15f * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - *( p_gains_dir++ ) = g2; // p_gains_dir_q + 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 + g2 = L_min( g2, Mpy_32_32( 1234803098 /* 1.15f in Q30 */, L_shl( 1, add( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 1 ) ) ) ); // p_gains_dir_q + *( p_gains_dir++ ) = g2; // p_gains_dir_q move32(); } } @@ -2053,20 +2162,20 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g1 = L_add( POINT_3679_Q31, Mpy_32_32( onset_filter[l], - L_sub( 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, (Word32) ( -DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - *( p_gains_dir++ ) = g2; // p_gains_dir_q + 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 + g2 = L_min( 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 + *( p_gains_dir++ ) = g2; // p_gains_dir_q move32(); } } IF( hodirac_flag ) { - p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx + num_freq_bands * num_channels_dir; - p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx + num_freq_bands * num_channels_dir; + p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx + imult1616( num_freq_bands, num_channels_dir ); + p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx + imult1616( num_freq_bands, num_channels_dir ); /*Direct gains*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) @@ -2085,30 +2194,31 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g1 = L_add( POINT_3679_Q31, Mpy_32_32( onset_filter[l], - L_sub( 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, (Word32) ( -DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ) ); // p_gains_dir_q - *( p_gains_dir++ ) = g2; // p_gains_dir_q + 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 + g2 = L_min( 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 + *( p_gains_dir++ ) = g2; // p_gains_dir_q move32(); } } } /*Diffuse gains*/ - p_cy_auto_diff_smooth = h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx + nchan_transport_foa * num_freq_bands_diff; - p_gains_diff = h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx + nchan_transport_foa * num_freq_bands_diff; + p_cy_auto_diff_smooth = h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx + imult1616( nchan_transport_foa, num_freq_bands_diff ); + p_gains_diff = h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx + imult1616( nchan_transport_foa, num_freq_bands_diff ); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { FOR( l = 0; l < num_freq_bands_diff; l++ ) { - g1 = POINT_1175_Q31; // Q31 - g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_diff ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q - g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q - g2 = L_max( g2, 0 ); // p_gains_diff_q - g2 = L_min( g2, (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ) ); // p_gains_diff_q - *( p_gains_diff++ ) = g2; // p_gains_diff_q + g1 = POINT_1175_Q31; // Q31 + move32(); + g2 = Mpy_32_32( L_sub( ONE_IN_Q31, g1 ), *( p_gains_diff ) ); // (Q31, p_gains_dir_q) -> p_gains_dir_q + g2 = L_add_sat( g2, Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth++ ) ) ) ); // p_gains_diff_q, (Q31, p_gains_diff_q) -> p_gains_diff_q + g2 = L_max( g2, 0 ); // p_gains_diff_q + g2 = L_min( g2, W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ), Q5 ) ) ); // p_gains_diff_q + *( p_gains_diff++ ) = g2; // p_gains_diff_q move32(); } } @@ -2127,11 +2237,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev = h_dirac_output_synthesis_state.gains_dir_prev_fx; FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[ch_idx * num_freq_bands], + Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[imult1616( ch_idx, num_freq_bands )], num_freq_bands, sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); } h_dirac_output_synthesis_state.gains_dir_prev_q = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; + move16(); FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { @@ -2143,9 +2254,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( 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) - output_real[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) + 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(); - output_imag[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) + output_imag[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(); } } @@ -2155,7 +2266,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { IF( hodirac_flag ) { - IF( EQ_16( proto_direct_index[ch_idx], 0 ) ) + IF( proto_direct_index[ch_idx] == 0 ) { Word32 *p_proto2; Word32 gs1, gs2; @@ -2169,29 +2280,29 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { 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 + num_freq_bands * num_channels_dir ) ) ), - Mpy_32_32( g2, ( *( p_gains_dir_prev + num_freq_bands * num_channels_dir ) ) ) ); // (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) 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[l * num_channels_dir + ch_idx] = + output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_add( - Mpy_32_32( gs1, ( L_add( Mpy_32_32( (Word32) ( 1903158016 ), ( *p_proto ) ), - Mpy_32_32( (Word32) ( 1098788992 ), ( *p_proto2 ) ) ) ) ), /* s1 */ - Mpy_32_32( gs2, ( L_sub( Mpy_32_32( (Word32) ( 1903158016 ), ( *p_proto ) ), - Mpy_32_32( (Word32) ( 1098788992 ), ( *p_proto2 ) ) ) ) ) ); /* s2 */ + 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 */ 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[l * num_channels_dir + ch_idx] = + output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_add( - Mpy_32_32( gs1, ( L_add( Mpy_32_32( (Word32) ( 1903158016 ), ( *p_proto ) ), - Mpy_32_32( (Word32) ( 1098788992 ), ( *p_proto2 ) ) ) ) ), - Mpy_32_32( gs2, ( L_sub( Mpy_32_32( (Word32) ( 1903158016 ), ( *p_proto ) ), - Mpy_32_32( (Word32) ( 1098788992 ), ( *p_proto2 ) ) ) ) ) ); + 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 ) ) ) ) ) ); move32(); p_proto++; p_proto2++; @@ -2207,9 +2318,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2226,9 +2337,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( 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) - output_real[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) + 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(); - output_imag[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) + output_imag[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(); } } @@ -2239,9 +2350,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2253,17 +2364,18 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_diff_prev = h_dirac_output_synthesis_state.gains_diff_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[ch_idx * num_freq_bands_diff], + Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], num_freq_bands_diff, sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); } h_dirac_output_synthesis_state.gains_diff_prev_q = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; + move16(); ch_idx_diff = nchan_transport_foa; move16(); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - IF( EQ_16( proto_direct_index[ch_idx], 0 ) ) + IF( proto_direct_index[ch_idx] == 0 ) { p_proto = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + @@ -2275,14 +2387,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Mpy_32_32( 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[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = - L_add( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], + 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++ ) ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = - L_add( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], + 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++ ) ) ) ); move32(); } @@ -2301,6 +2413,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( * Copy output or HOA decoder *-----------------------------------------------------------------*/ + test(); IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { Word32 *p_real, *p_imag; @@ -2338,9 +2451,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[l * num_channels_dir + ch_idx], Q2 ); + RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); move32(); - ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[l * num_channels_dir + ch_idx], Q2 ); + ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); move32(); } } @@ -2354,42 +2467,34 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /* store estimates for next synthesis block */ IF( hodirac_flag ) { - mvl2l( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); } ELSE { - mvl2l( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, num_freq_bands * num_channels_dir ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); } *q_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); - mvl2l( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, num_freq_bands_diff * num_channels_diff ); + Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); *q_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); /* reset values */ IF( hodirac_flag ) { - set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); + set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); } ELSE { - set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, num_freq_bands * num_channels_dir ); + set_zero_fx( h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx, imult1616( num_freq_bands, num_channels_dir ) ); } - set_zero_fx( h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx, num_freq_bands_diff * num_channels_diff ); + set_zero_fx( h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); return; } #else - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_output_synthesis_process_subframe_gain_shd() - * - * - *------------------------------------------------------------------------*/ - void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -2830,13 +2935,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx() + * ivas_dirac_dec_output_synthesis_process_subframe_psd_ls() * * *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -2904,10 +3009,18 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( * compute target PSDs *-----------------------------------------------------------------*/ - IF( EQ_16( enc_param_start_band, 0 ) ) + IF( enc_param_start_band == 0 ) { - diff_start_band = EQ_16( h_dirac_output_synthesis_params->use_onset_filters, 1 ) ? h_dirac_output_synthesis_params->max_band_decorr : 0; - move16(); + IF( EQ_16( h_dirac_output_synthesis_params->use_onset_filters, 1 ) ) + { + diff_start_band = h_dirac_output_synthesis_params->max_band_decorr; + move16(); + } + ELSE + { + diff_start_band = 0; + move16(); + } IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { @@ -2932,7 +3045,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( &h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ); // Scale cy_auto_diff_smooth_fx if required - IF( NE_32( diff_start_band, 0 ) ) + IF( diff_start_band != 0 ) { q_com = s_min( *q_reference_power_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); @@ -2941,9 +3054,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( i_mult( num_freq_bands, nchan_target_psds ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); *q_reference_power_smooth = q_com; + move16(); h_dirac_output_synthesis_state->reference_power_smooth_prev_q = q_com; - move16(); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = q_com; move16(); } @@ -2971,29 +3085,30 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { - exp = sub( Q31, Q31 ); + exp = Q31 - Q31; + move16(); exp1 = 0; move16(); tmp32 = BASOP_Util_Divide3232_Scale_cadence( L_shl( p_cy_auto_dir_smooth[num_freq_bands], sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth ) ), ( L_add( Sqrt32( h_dirac_output_synthesis_state->direct_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) &exp1 ); target_power_y = L_shr( tmp32, 1 ); // Q31 + (q_com - (31 - exp)) - q_target_power_y = add( Q31 - exp1, sub( q_com, sub( Q31, exp ) ) ); + q_target_power_y = add( sub( Q31, exp1 ), sub( q_com, sub( Q31, exp ) ) ); q_target_power_y = sub( q_target_power_y, 1 ); - exp = sub( Q31, Q31 ); + exp = Q31 - Q31; + move16(); exp1 = 0; move16(); tmp32 = BASOP_Util_Divide3232_Scale_cadence( L_shl( p_cy_auto_diff_smooth[num_freq_bands], sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ), ( L_add( Sqrt32( h_dirac_output_synthesis_state->diffuse_power_factor_fx[0], &exp ), EPSILON_FX ) ), // (Q31 - exp) &exp1 ); target_power_y1 = L_shr( tmp32, 1 ); // Q31 + (q_com - (31 - exp)) - q_target_power_y1 = add( Q31 - exp1, sub( q_com, sub( Q31, exp ) ) ); + q_target_power_y1 = add( sub( Q31, exp1 ), sub( q_com, sub( Q31, exp ) ) ); q_target_power_y1 = sub( q_target_power_y1, 1 ); target_power_y = L_add( L_shl( target_power_y, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y ) ), L_shl( target_power_y1, sub( s_min( q_target_power_y1, q_target_power_y ), q_target_power_y1 ) ) ); - exp = s_min( q_target_power_y1 - 1, q_target_power_y - 1 ); - move16(); + exp = s_min( sub( q_target_power_y1, 1 ), sub( q_target_power_y, 1 ) ); } ELSE { @@ -3007,25 +3122,29 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( subtract_power_y = masa_stereo_type_detect->subtract_power_y_fx; // q_subtract_power_y move32(); - a = 858993; /* ( 0.0004f in Q31 ); Temporal smoothing coefficient */ + a = 858993; /* ( 0.0004f in Q31 ); Temporal smoothing coefficient */ + move32(); b = L_sub( ONE_IN_Q31, a ); /* Temporal smoothing coefficient */ q_com = s_min( exp, masa_stereo_type_detect->q_target_power_y_smooth ); target_power_y = L_shl( target_power_y, sub( q_com, exp ) ); masa_stereo_type_detect->target_power_y_smooth_fx = L_shl( masa_stereo_type_detect->target_power_y_smooth_fx, sub( q_com, masa_stereo_type_detect->q_target_power_y_smooth ) ); + move32(); masa_stereo_type_detect->target_power_y_smooth_fx = L_add( Mpy_32_32( a, target_power_y ), Mpy_32_32( b, masa_stereo_type_detect->target_power_y_smooth_fx ) ); //(Q31, q_com) -> q_com + move32(); masa_stereo_type_detect->q_target_power_y_smooth = q_com; move16(); masa_stereo_type_detect->subtract_power_y_smooth_fx = L_add( Mpy_32_32( a, subtract_power_y ), Mpy_32_32( b, masa_stereo_type_detect->subtract_power_y_smooth_fx ) ); //(Q31, q_subtract_power_y) -> q_subtract_power_y + move32(); exp = 0; move16(); - IF( NE_32( masa_stereo_type_detect->target_power_y_smooth_fx, 0 ) ) + IF( masa_stereo_type_detect->target_power_y_smooth_fx != 0 ) { subtract_target_ratio = L_sub( BASOP_Util_Log2( masa_stereo_type_detect->subtract_power_y_smooth_fx ), BASOP_Util_Log2( masa_stereo_type_detect->target_power_y_smooth_fx ) ); // Q25 @@ -3036,7 +3155,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { subtract_target_ratio = BASOP_Util_Log2( masa_stereo_type_detect->subtract_power_y_smooth_fx ); // Q25 exp = sub( 31, masa_stereo_type_detect->q_subtract_power_y ); - L_tmp = L_sub( Mpy_32_32( L_add( subtract_target_ratio, L_shl( exp, 25 ) ), LOG10_2_Q31 ), L_shl( -15, 25 ) /*log(EPSILON)*/ ); // Q25 + L_tmp = L_sub( Mpy_32_32( L_add( subtract_target_ratio, L_shl( exp, 25 ) ), LOG10_2_Q31 ), -503316480 /* L_shl( -15, 25 ) */ /*log(EPSILON)*/ ); // Q25 } subtract_target_ratio_db = Mpy_32_32( 1342177280 /* 10.0f * in Q27*/, L_tmp ); // (Q27, (Q25, Q31)) -> (Q27, Q25) -> Q21 @@ -3117,7 +3236,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - g1 = alpha[l]; // Q31 + g1 = alpha[l]; // Q31 + move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 *p_power_smooth_prev = L_add( EPSILON_FX, Mpy_32_32( g2, ( *p_power_smooth_prev ) ) ); //(Q31, q_proto_power_smooth) -> q_proto_power_smooth move32(); @@ -3172,11 +3292,11 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( FOR( l = 0; l < num_freq_bands; l++ ) { *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[add( i_mult( k, num_freq_bands ), l )] ) ); - p_power_smooth++; move32(); + p_power_smooth++; IF( EQ_32( *( p_power_smooth_prev ), EPSILON_FX ) ) { - q_tmp = add( sub( Q31, min_exp ), sub( Q31, 62 ) ); + q_tmp = add( sub( Q31, min_exp ), Q31 - 62 ); } ELSE { @@ -3187,7 +3307,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( // Update the Q-factor h_dirac_output_synthesis_state->proto_power_smooth_prev_q = h_dirac_output_synthesis_state->proto_power_smooth_q; + move16(); h_dirac_output_synthesis_state->proto_power_smooth_q = q_tmp; + move16(); /*Direct gains and diffuse gains on number of output channels*/ p_power_diff_smooth_prev = h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx; @@ -3202,6 +3324,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( scale_sig32( p_cy_auto_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth ) ); scale_sig32( p_cy_auto_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ) ); h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev = q_com; + move16(); + move16(); p_cy_cross_dir_smooth = h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx; p_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx; @@ -3209,6 +3333,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = q_com; + move16(); + move16(); p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx; p_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx; @@ -3216,6 +3342,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = q_com; + move16(); + move16(); FOR( k = 0; k < nchan_out_woLFE; k++ ) { @@ -3246,20 +3374,21 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_dir ) = L_shl_sat( *( p_gains_dir ), sub( h_dirac_output_synthesis_state->gains_dir_prev_q, sub( Q31, exp ) ) ); // gains_dir_prev_q move32(); - IF( LT_32( *( p_gains_dir ), 0 ) ) + IF( *( p_gains_dir ) < 0 ) { *( p_gains_dir ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_dir ), (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_dir_prev_q ) ) ) ) + ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_dir ) = (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_dir_prev_q ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); move32(); } - IF( LT_32( *( p_cy_cross_dir_smooth_prev++ ), 0 ) ) + IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + move32(); } p_gains_dir++; @@ -3267,8 +3396,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *p_power_diff_smooth_prev = L_add( L_add( Mpy_32_32( g1, ( *( p_power_smooth_diff++ ) ) ), Mpy_32_32( g2, ( *( p_power_diff_smooth_prev ) ) ) ), EPSILLON_FX ); // (Q31, q_power_diff_smooth_prev) -> q_power_diff_smooth_prev + move32(); *( p_cy_auto_diff_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_auto_diff_smooth++ ) ) ), Mpy_32_32( g2, ( *( p_cy_auto_diff_smooth_prev ) ) ) ); // (Q31, q_cy_auto_diff_smooth_prev) -> q_cy_auto_diff_smooth_prev + move32(); exp = 0; move16(); @@ -3280,14 +3411,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = L_shl_sat( *( p_gains_diff ), sub( h_dirac_output_synthesis_state->gains_diff_prev_q, sub( Q31, exp ) ) ); // gains_diff_prev_q move32(); - IF( LT_32( *( p_gains_diff ), 0 ) ) + IF( *( p_gains_diff ) < 0 ) { *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_diff_prev_q ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_diff ) = (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_diff_prev_q ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); move32(); } p_gains_diff++; @@ -3297,7 +3428,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( FOR( ; l < num_freq_bands; l++ ) { /*Direct*/ - g1 = alpha[l]; // Q31 + g1 = alpha[l]; // Q31 + move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 *( p_cy_auto_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_auto_dir_smooth++ ) ) ), Mpy_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); // (Q31, q_cy_auto_dir_smooth_prev) -> q_cy_auto_dir_smooth_prev @@ -3317,20 +3449,21 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_dir ) = L_shl_sat( *( p_gains_dir ), sub( h_dirac_output_synthesis_state->gains_dir_prev_q, sub( Q31, exp ) ) ); // gains_dir_prev_q move32(); - IF( LT_32( *( p_gains_dir ), 0 ) ) + IF( *( p_gains_dir ) < 0 ) { *( p_gains_dir ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_dir ), (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_dir_prev_q ) ) ) ) + ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_dir ) = (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_dir_prev_q ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); move32(); } - IF( LT_32( *( p_cy_cross_dir_smooth_prev++ ), 0 ) ) + IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + move32(); } p_gains_dir++; @@ -3351,14 +3484,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = L_shl_sat( *( p_gains_diff ), sub( h_dirac_output_synthesis_state->gains_diff_prev_q, sub( Q31, exp ) ) ); // gains_diff_prev_q move32(); - IF( LT_32( *( p_gains_diff ), 0 ) ) + IF( *( p_gains_diff ) < 0 ) { *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_diff_prev_q ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_diff ) = (Word32) ( DIRAC_GAIN_LIMIT * L_shl( 1U, h_dirac_output_synthesis_state->gains_diff_prev_q ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); move32(); } p_gains_diff++; @@ -3393,7 +3526,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } /*Diffuse stream*/ - IF( NE_16( h_dirac_output_synthesis_params->max_band_decorr, 0 ) ) + IF( h_dirac_output_synthesis_params->max_band_decorr != 0 ) { p_power_smooth_diff = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + shl( i_mult( buf_idx, i_mult( h_dirac_output_synthesis_params->max_band_decorr, nchan_out_woLFE ) ), Q1 ); @@ -3431,39 +3564,32 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } } *q_Cldfb = sub( sub( add( h_dirac_output_synthesis_state->proto_direct_buffer_f_q, h_dirac_output_synthesis_state->gains_dir_prev_q ), Q31 ), Q1 ); + move16(); /*-----------------------------------------------------------------* * update buffers *-----------------------------------------------------------------*/ /* store estimates for next synthesis block */ - mvl2l( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, num_freq_bands * nchan_out_woLFE ); - mvl2l( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, num_freq_bands * nchan_out_woLFE ); + Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /* reset values */ - set_zero_fx( h_dirac_output_synthesis_state->proto_power_smooth_fx, num_freq_bands * num_protos_dir ); + set_zero_fx( h_dirac_output_synthesis_state->proto_power_smooth_fx, imult1616( num_freq_bands, num_protos_dir ) ); IF( h_dirac_output_synthesis_state->proto_power_diff_smooth_fx != NULL ) { set_zero_fx( h_dirac_output_synthesis_state->proto_power_diff_smooth_fx, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE ); } - set_zero_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_freq_bands * nchan_out_woLFE ); - set_zero_fx( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_freq_bands * nchan_out_woLFE ); - set_zero_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_freq_bands * nchan_out_woLFE ); + set_zero_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); pop_wmops(); return; } #else - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_output_synthesis_process_subframe_psd_ls() - * - * - *------------------------------------------------------------------------*/ - void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -3818,13 +3944,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * ivas_dirac_dec_get_response_split_order_fx() + * ivas_dirac_dec_get_response_split_order() * * calculate reponse, 1 degree resolution *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_get_response_split_order_fx( const Word16 azimuth, const Word16 elevation, @@ -3848,7 +3975,16 @@ static void ivas_dirac_dec_get_response_split_order_fx( push_wmops( "ivas_dirac_dec_get_response_split_order" ); - tmp = idiv1616( add( azimuth, 180 ), 360 ); + /* Corner case for handling crash in idiv1616 when numerator is 0 */ + IF( EQ_16( azimuth, -180 ) ) + { + tmp = 0; + move16(); + } + ELSE + { + tmp = idiv1616( add( azimuth, 180 ), 360 ); + } index_azimuth = sub( add( azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (azimuth + 180) % 360 index_elevation = add( elevation, 90 ); @@ -3944,7 +4080,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( move16(); c = L_shl( Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ), 3 ); // Q29 - IF( EQ_16( sub( l, i_mult( idiv1616( l, 2 ), 2 ) ), 1 ) ) + IF( EQ_16( l % 2, 1 ) ) { c = L_shl( Mpy_32_16_1( c, e ), 1 ); // Q29 } @@ -3954,8 +4090,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( } /*Conversion spherical to cartesian coordinates*/ - w = -dirac_gains_trg_term_int[el][1]; // Q30 - move32(); + w = L_negate( dirac_gains_trg_term_int[el][1] ); // Q30 dv_0 = Mpy_32_32( w, cos_1 ); // Q28 dv_1 = Mpy_32_32( w, sin_1 ); // Q28 dv_2 = L_shr( Mpy_32_16_1( dirac_gains_trg_term_int[el][0], e ), 1 ); // Q28 @@ -4077,7 +4212,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( c = L_shl( Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ), 3 ); // Q29 - IF( EQ_16( sub( l, i_mult( idiv1616( l, 2 ), 2 ) ), 1 ) ) + IF( EQ_16( l % 2, 1 ) ) { c = L_shl( Mpy_32_16_1( c, e ), 1 ); // Q29 } @@ -4087,19 +4222,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( } *q_response = Q29; - move32(); + move16(); pop_wmops(); return; } #else -/*------------------------------------------------------------------------- - * ivas_dirac_dec_get_response_split_order() - * - * calculate reponse, 1 degree resolution - *------------------------------------------------------------------------*/ - static void ivas_dirac_dec_get_response_split_order( const int16_t azimuth, const int16_t elevation, @@ -4262,6 +4391,7 @@ static void ivas_dirac_dec_get_response_split_order( * * *------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_directional_responses_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ @@ -4319,7 +4449,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( azimuth2 = NULL; elevation2 = NULL; transport_signal_type = MASA_STEREO_NOT_DEFINED; - move16(); + move32(); IF( hDirACRend->masa_stereo_type_detect != NULL ) { @@ -4341,13 +4471,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } - codingBand = negate( 1 ); + codingBand = -1; assert( num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high" ); FOR( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { - IF( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) + if ( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) { codingBand = add( codingBand, 1 ); } @@ -4404,6 +4534,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( } } + test(); + test(); + test(); + test(); IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); @@ -4423,13 +4557,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( Q_direct_response_hoa = Q29; move16(); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); - move16(); } spreadCoherencePanningHoa_fx( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence_fx[md_idx][k], direct_response_hoa_fx, &Q_direct_response_hoa, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); - move16(); /* Synthesize the second direction and combine the gains */ IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { @@ -4439,22 +4571,20 @@ void ivas_dirac_dec_compute_directional_responses_fx( Q_direct_response_dir2 = Q29; move16(); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); - move16(); } spreadCoherencePanningHoa_fx( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2_fx[md_idx][k], direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); - move16(); /* Combine gains from the two directions */ totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); - IF( EQ_32( totalDirect_fx, 0 ) ) + IF( totalDirect_fx == 0 ) { totalDirect_fx = EPSILON_FIX; move32(); } - Word16 var_a = 0, var_b = 0, exp_1 = 0, exp_2 = 0; + Word16 var_a, var_b, exp_1, exp_2; var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); @@ -4463,11 +4593,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( directRatio_fx[1] = L_deposit_h( var_b ); move32(); - Word32 temp_a = 0; - Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_a = 0, final_exp = 0; + Word32 temp_a; + Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_a, final_exp; set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); - move16(); FOR( l = 0; l < num_channels_dir; l++ ) { @@ -4476,9 +4605,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_arr[l] = add( exp_1, sub( 31, Q_direct_response_hoa ) ); move16(); temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); - move32(); exp_temp_a = add( exp_2, sub( 31, Q_direct_response_dir2 ) ); - move16(); direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); move32(); exp_arr[l] = final_exp; @@ -4490,23 +4617,23 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); move32(); } exp_direct_response_hoa = max_exp; move16(); Q_direct_response_hoa = sub( 31, max_exp ); - move16(); } - IF( GT_16( hSpatParamRendCom->numIsmDirections, 0 ) ) + IF( hSpatParamRendCom->numIsmDirections > 0 ) { Word16 dir; Word32 direct_response_temp_fx[MAX_OUTPUT_CHANNELS]; Word32 direct_response_ism_fx[MAX_OUTPUT_CHANNELS]; - Word16 exp_direct_response_ism = 0, exp_direct_response_temp = 0; + Word16 exp_direct_response_ism = 0, exp_direct_response_temp; Word32 masaDirect_fx; Word32 ismDirect_fx; + move16(); set32_fx( direct_response_ism_fx, 0, num_channels_dir ); @@ -4525,6 +4652,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word32 temp_1 = 0; Word16 exp_temp = 0, exp_arr[MAX_OUTPUT_CHANNELS]; + move16(); + move16(); set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { @@ -4535,6 +4664,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } Word16 max_exp = MIN16B; + move16(); maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { @@ -4544,14 +4674,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_direct_response_ism = max_exp; move16(); } - Word16 exp_1 = 0, exp_2 = 0; + Word16 exp_1, exp_2; masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; move32(); - IF( EQ_32( masaDirect_fx, 0 ) ) + if ( masaDirect_fx == 0 ) { masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); } - IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) + if ( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); } @@ -4572,14 +4702,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( directRatio_fx[1] = L_deposit_h( var_b ); move32(); - Word32 temp_2 = 0, temp_3 = 0; - Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_3 = 0; + Word32 temp_2, temp_3; + Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_3; set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); move32(); - exp_arr[l] = exp_direct_response_hoa + exp_1; + exp_arr[l] = add( exp_direct_response_hoa, exp_1 ); move16(); temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, exp_2 + exp_direct_response_ism, &exp_temp_3 ); @@ -4595,7 +4725,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4604,27 +4734,29 @@ void ivas_dirac_dec_compute_directional_responses_fx( } /* Synthesize surrounding coherence */ - IF( surCohRatio_fx != NULL && GT_32( surCohRatio_fx[k], 0 ) ) + IF( surCohRatio_fx != NULL && surCohRatio_fx[k] > 0 ) { - Word32 var_a = 0, var_b = 0; - Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp = 0; + Word32 var_a, var_b; + Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp; set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); FOR( l = 1; l < num_channels_dir; l++ ) { exp = 0; + move16(); var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); var_b = Sqrt32( var_a, &exp ); direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); move32(); - exp_arr[l] = 31 - Q_direct_response_hoa + exp; + exp_arr[l] = add( sub( 31, Q_direct_response_hoa ), exp ); move16(); } Word16 max_exp = MIN_16; + move16(); maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4639,7 +4771,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); direct_response_fx = direct_response_hoa_fx; - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); @@ -4650,6 +4782,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( { direct_response_fx[0] = ONE_IN_Q29; move32(); + test(); IF( GE_16( k, dipole_freq_range[0] ) && LT_16( k, dipole_freq_range[1] ) ) { direct_response_fx[1] = ONE_IN_Q29; @@ -4669,7 +4802,6 @@ void ivas_dirac_dec_compute_directional_responses_fx( assert( 0 && "Not supported synthesis method!" ); } } - ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ { /* Synthesize the first direction */ @@ -4687,7 +4819,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( /* Combine gains from the two directions */ Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); - IF( EQ_32( test, 0 ) ) + IF( test == 0 ) { totalDirect_fx = L_add( test, EPSILON_FIX ); // Q30 } @@ -4696,12 +4828,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( totalDirect_fx = test; move32(); } - Word16 exp_1 = 0, exp_2 = 0; - move16(); - move16(); - Word16 var_1 = 0, var_2 = 0; - move16(); - move16(); + Word16 var_1, var_2, exp_1, exp_2; var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); @@ -4710,21 +4837,24 @@ void ivas_dirac_dec_compute_directional_responses_fx( directRatio_fx[1] = L_deposit_h( var_2 ); move32(); - Word32 var_a = 0; - Word16 exp_tmp = 0; + Word32 var_a; + Word16 exp_tmp; Word16 exp_max = MIN16B, exp_table[MAX_OUTPUT_CHANNELS]; + move16(); set16_fx( exp_table, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); Word32 temp = 0; + move32(); FOR( l = 0; l < num_channels_dir; l++ ) { temp = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); // exp_direct_response_ls + exp_1 var_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); // exp_direct_response_dir2 + exp_2 exp_tmp = 0; - direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, exp_direct_response_ls + exp_1, var_a, exp_direct_response_dir2 + exp_2, &exp_tmp ); + move16(); + direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); move32(); exp_table[l] = exp_tmp; move16(); @@ -4734,7 +4864,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], exp_max - exp_table[i] ); + direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); move32(); } Q_direct_response_ls = sub( 31, exp_max ); @@ -4745,13 +4875,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_direct_response_ls = sub( 31, Q_direct_response_ls ); } - IF( GT_16( hSpatParamRendCom->numIsmDirections, 0 ) ) + IF( hSpatParamRendCom->numIsmDirections > 0 ) { Word16 dir; Word32 direct_response_temp_fx[MAX_OUTPUT_CHANNELS]; set32_fx( direct_response_temp_fx, 0, MAX_OUTPUT_CHANNELS ); Word16 Q_direct_response_temp = Q31; + move16(); Word32 direct_response_ism_fx[MAX_OUTPUT_CHANNELS]; set32_fx( direct_response_ism_fx, 0, num_channels_dir ); Word32 masaDirect_fx; @@ -4769,17 +4900,17 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word32 tmp = 0; move32(); - Word16 Q_arr[MAX_OUTPUT_CHANNELS], exp_tmp = 0; - move16(); + Word16 Q_arr[MAX_OUTPUT_CHANNELS], exp_tmp; FOR( l = 0; l < num_channels_dir; l++ ) { tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, sub( 31, sub( 60, 31 ) ), &exp_tmp ); + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); move32(); Q_arr[l] = sub( 31, exp_tmp ); move16(); } Word16 Q_min = MAX16B; + move32(); minimum_fx( Q_arr, num_channels_dir, &Q_min ); FOR( i = 0; i < num_channels_dir; i++ ) { @@ -4791,11 +4922,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_ism_fx, &Q_direct_response_temp, num_channels_dir ); } - Word16 exp_1 = 0, exp_2 = 0; - move16(); + Word16 exp_1, exp_2; masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; move32(); - IF( EQ_32( masaDirect_fx, 0 ) ) + IF( masaDirect_fx == 0 ) { masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); } @@ -4812,8 +4942,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed - Word16 var_a = 0, var_b = 0; - move16(); + Word16 var_a, var_b; var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); directRatio_fx[0] = L_deposit_h( var_a ); @@ -4821,12 +4950,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( directRatio_fx[1] = L_deposit_h( var_b ); move32(); - Word32 temp_2 = 0, temp_3 = 0; - move16(); - move16(); - Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_3 = 0; - move16(); - // set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS); + Word32 temp_2, temp_3; + Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_3; set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { @@ -4844,10 +4969,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 max_exp = MIN16B; + move16(); maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], max_exp - exp_arr[l] ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); move16(); } Q_direct_response_ls = sub( 31, max_exp ); @@ -4859,7 +4985,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } /* Synthesize surrounding coherence */ - IF( surCohRatio_fx != NULL && GT_32( surCohRatio_fx[k], 0 ) ) + IF( surCohRatio_fx != NULL && surCohRatio_fx[k] > 0 ) { Word16 num_channels_surrCoh; @@ -4867,20 +4993,15 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); num_channels_surrCoh = sub( num_channels_surrCoh, hDirACRend->num_ele_spk_no_diffuse_rendering ); - Word32 temp = 0, final = 0; - move32(); - move32(); - Word16 exp_temp = 0, exp_temp_a = 0, temp_a = 0, final_exp = 0; - move16(); - move16(); - move16(); - move16(); + Word32 temp, final; + Word16 exp_temp, exp_temp_a, temp_a, final_exp; Word16 exp_arr[MAX_OUTPUT_CHANNELS], max_exp = MIN16B; move16(); set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { exp_temp = 0; + move16(); temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); temp = Sqrt32( temp, &exp_temp ); direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // exp_direct_response_ls + exp_temp @@ -4888,13 +5009,15 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_arr[l] = add( exp_direct_response_ls, exp_temp ); move16(); - IF( GT_16( hDirACRend->diffuse_response_function_fx[l], 0 ) ) + IF( hDirACRend->diffuse_response_function_fx[l] > 0 ) { exp_temp_a = 0; + move16(); temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); exp_temp_a = add( exp_temp_a, sub( exp_surCohRatio, 15 ) ); temp_a = Sqrt16( temp_a, &exp_temp_a ); final_exp = 0; + move16(); final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); direct_response_ls_fx[l] = final; move32(); @@ -4908,7 +5031,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], max_exp - exp_arr[l] ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); move32(); } @@ -5192,10 +5315,6 @@ void ivas_dirac_dec_compute_directional_responses( { int16_t dir; float direct_response_temp[MAX_OUTPUT_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED - Word32 direct_response_temp_fx[MAX_OUTPUT_CHANNELS]; - set32_fx( direct_response_temp_fx, 0, MAX_OUTPUT_CHANNELS ); -#endif float direct_response_ism[MAX_OUTPUT_CHANNELS]; float masaDirect; float ismDirect; @@ -5206,27 +5325,11 @@ void ivas_dirac_dec_compute_directional_responses( { if ( hMasaIsm->ism_is_edited[dir] ) { -#ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx( hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); - FOR( int i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_temp[i] = fix_to_float( direct_response_temp_fx[i], Q29 ); - } -#else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); -#endif } else { -#ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx( hVBAPdata, direct_response_temp_fx, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1 ); - FOR( int i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_temp[i] = fix_to_float( direct_response_temp_fx[i], Q29 ); - } -#else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], 1 ); -#endif } for ( l = 0; l < num_channels_dir; l++ ) @@ -5295,6 +5398,8 @@ void ivas_dirac_dec_compute_directional_responses( return; } #endif + + /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_gain_factors() * @@ -5317,7 +5422,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( FOR( i = 0; i < num_freq_bands; i++ ) { exp1 = 1; + move16(); exp2 = 1; + move16(); direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30, diffuseness_fx[i] ), &exp1 ); move32(); diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); @@ -5346,15 +5453,16 @@ void ivas_dirac_dec_compute_gain_factors_fx( FOR( i = 0; i < num_freq_bands; i++ ) { - direct_gain_factor[i] = L_shr( direct_gain_factor[i], max_exp_direct - exp_direct_gain_factor[i] ); - diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], max_exp_diffuse - exp_diffuse_gain_factor[i] ); + direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); + move32(); + diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); + move32(); } return; } -#endif - +#else void ivas_dirac_dec_compute_gain_factors( const int16_t num_freq_bands, const float *diffuseness, @@ -5377,6 +5485,7 @@ void ivas_dirac_dec_compute_gain_factors( return; } +#endif /*------------------------------------------------------------------------- @@ -5385,6 +5494,7 @@ void ivas_dirac_dec_compute_gain_factors( * *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_power_factors( const int16_t num_freq_bands, const float *diffuseness, @@ -5404,8 +5514,7 @@ void ivas_dirac_dec_compute_power_factors( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_compute_power_factors_fx( const Word16 num_freq_bands, const Word32 *diffuseness_fx, // Q3O @@ -5413,6 +5522,8 @@ void ivas_dirac_dec_compute_power_factors_fx( Word32 *direct_power_factor, Word32 *diffuse_power_factor ) { + Word16 i; + v_multc_fixed( diffuseness_fx, L_negate( ( ONE_IN_Q31 ) ), direct_power_factor, num_freq_bands ); // Q30 v_addc_fixed( direct_power_factor, ONE_IN_Q30, direct_power_factor, num_freq_bands ); // Q30 @@ -5424,14 +5535,18 @@ void ivas_dirac_dec_compute_power_factors_fx( v_mult_fixed( &diffuse_power_factor[max_band_decorr], &diffuse_power_factor[max_band_decorr], &diffuse_power_factor[max_band_decorr], num_freq_bands - max_band_decorr ); // Q29 - FOR( int i = 0; i < max_band_decorr; i++ ) + FOR( i = 0; i < max_band_decorr; i++ ) { - direct_power_factor[i] = L_shr( direct_power_factor[i], 1 ); // Q29 + direct_power_factor[i] = L_shr( direct_power_factor[i], 1 ); // Q29 + move32(); diffuse_power_factor[i] = L_shr( diffuse_power_factor[i], 1 ); // Q29 + move32(); } return; } #endif + + /*------------------------------------------------------------------------- * ivas_lfe_synth_with_filters() * @@ -5451,16 +5566,16 @@ void ivas_lfe_synth_with_filters_fx( Word16 i, j; Word32 lowPassSignal_fx[L_FRAME48k]; Word32 highPassSignal_fx[L_FRAME48k]; - int16_t slot_index; - int16_t subframe_index; - int16_t slotSize; + Word16 slot_index; + Word16 subframe_index; + Word16 slotSize; Word32 transportEne_fx, targetEneLfe_fx, targetEneTrans_fx; - int16_t mrange[2]; + Word16 mrange[2]; Word16 lfeGain_fx; Word16 lfeGain_fx_exp; Word16 transportGain_fx; Word16 transportGain_fx_exp; - int16_t delay; + Word16 delay; /* Delay the separated channel to sync the LFE synthesis with the DirAC rendering */ delay = hMasaLfeSynth->delayBuffer_syncDirAC_size; @@ -5481,16 +5596,20 @@ void ivas_lfe_synth_with_filters_fx( hMasaLfeSynth->lfeSynthRingBuffer_fx[hMasaLfeSynth->ringBufferLoPointer] = data_fx[separateChannelIndex][i]; // Q11 move32(); - hMasaLfeSynth->ringBufferLoPointer--; - IF( LT_16( hMasaLfeSynth->ringBufferLoPointer, 0 ) ) + hMasaLfeSynth->ringBufferLoPointer = sub( hMasaLfeSynth->ringBufferLoPointer, 1 ); + move16(); + IF( hMasaLfeSynth->ringBufferLoPointer < 0 ) { hMasaLfeSynth->ringBufferLoPointer = sub( hMasaLfeSynth->ringBufferSize, 1 ); + move16(); } - hMasaLfeSynth->ringBufferHiPointer--; - IF( LT_16( hMasaLfeSynth->ringBufferHiPointer, 0 ) ) + hMasaLfeSynth->ringBufferHiPointer = sub( hMasaLfeSynth->ringBufferHiPointer, 1 ); + move16(); + IF( hMasaLfeSynth->ringBufferHiPointer < 0 ) { hMasaLfeSynth->ringBufferHiPointer = sub( hMasaLfeSynth->ringBufferSize, 1 ); + move16(); } } @@ -5515,31 +5634,37 @@ void ivas_lfe_synth_with_filters_fx( } Word16 tmp_shift = W_norm( W_tmp ); - move16(); W_tmp = W_shl( W_tmp, tmp_shift ); - move64(); - Word16 tmp_q = Q22 + tmp_shift - 32; - move16(); + Word16 tmp_q = sub( add( Q22, tmp_shift ), 32 ); Word16 tmp_exp; transportEne_fx = W_extract_h( W_tmp ); /* Q22 + tmp_shift - 32 */ targetEneLfe_fx = W_extract_l( W_shr( W_mult0_32_32( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), Q14 ) ); /* Q22 + tmp_shift - 32 */ targetEneTrans_fx = W_extract_l( W_shr( W_mult0_32_32( transportEne_fx, s_max( sub( ONE_IN_Q14, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 168 ) ), Q14 ) ); /* Q22 + tmp_shift - 32 */ - hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); /* transportEneSmooth_q */ - hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); /* targetEneLfeSmooth_q */ + hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); /* transportEneSmooth_q */ + move32(); + hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); /* targetEneLfeSmooth_q */ + move32(); hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); /* targetEneTransSmooth_q */ + move32(); - hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, ( Q31 - hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, ( Q31 - tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( Q31, tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + move32(); hMasaLfeSynth->transportEneSmooth_q = sub( Q31, tmp_exp ); - hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, ( Q31 - hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, ( Q31 - tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + move16(); + hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( Q31, tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + move32(); hMasaLfeSynth->targetEneLfeSmooth_q = sub( Q31, tmp_exp ); - hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, ( Q31 - hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, ( Q31 - tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + move16(); + hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( Q31, tmp_q ), &tmp_exp ); /* Q31 - tmp_exp */ + move32(); hMasaLfeSynth->targetEneTransSmooth_q = sub( Q31, tmp_exp ); + move16(); - IF( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, ( Q31 - hMasaLfeSynth->targetEneLfeSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, ( Q31 - hMasaLfeSynth->transportEneSmooth_q ) ) == 1 ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneLfeSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { lfeGain_fx = MAX_16; move16(); @@ -5551,7 +5676,7 @@ void ivas_lfe_synth_with_filters_fx( lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 } - IF( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, ( Q31 - hMasaLfeSynth->targetEneTransSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, ( Q31 - hMasaLfeSynth->transportEneSmooth_q ) ) == 1 ) + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneTransSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { transportGain_fx = MAX_16; move16(); @@ -5564,6 +5689,7 @@ void ivas_lfe_synth_with_filters_fx( transportGain_fx = shl_r( transportGain_fx, transportGain_fx_exp ); // Q15 } j = 0; + move16(); FOR( i = mrange[0]; i < mrange[1]; i++ ) { Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 @@ -5574,7 +5700,7 @@ void ivas_lfe_synth_with_filters_fx( Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); move32(); - j++; + j = add( j, 1 ); } hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; @@ -5593,13 +5719,16 @@ void ivas_lfe_synth_with_filters_fx( L_shl_r( L_sub( Mpy_32_16_1( data_fx[lfeChannelIndex][i], lowpassCoef_fx ), Mpy_32_16_1( hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2], lowpassCoef_fx ) ), lowpassCoef_fx_exp ) ); + move32(); hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; move32(); - hMasaLfeSynth->ringBufferLoPointer2--; - IF( LT_16( hMasaLfeSynth->ringBufferLoPointer2, 0 ) ) + hMasaLfeSynth->ringBufferLoPointer2 = sub( hMasaLfeSynth->ringBufferLoPointer2, 1 ); + move16(); + IF( hMasaLfeSynth->ringBufferLoPointer2 < 0 ) { hMasaLfeSynth->ringBufferLoPointer2 = sub( hMasaLfeSynth->ringBufferSize2, 1 ); + move16(); } data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; @@ -5779,7 +5908,6 @@ static void computeTargetPSDs_direct_fx( return; } #else - static void computeTargetPSDs_direct( const int16_t num_channels, const int16_t num_freq_bands, @@ -5814,6 +5942,8 @@ static void computeTargetPSDs_direct( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_direct_subframe_fx( const Word16 num_channels, @@ -5853,8 +5983,6 @@ static void computeTargetPSDs_direct_subframe_fx( return; } #else - - static void computeTargetPSDs_direct_subframe( const int16_t num_channels, const int16_t num_freq_bands, @@ -5886,6 +6014,7 @@ static void computeTargetPSDs_direct_subframe( } #endif + #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, @@ -5914,10 +6043,10 @@ static void computeTargetPSDs_diffuse_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, num_freq_bands - start_band ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ - scale_sig32( aux_buffer_res, num_freq_bands - start_band, sub( common_q, *q_reference_power ) ); /* Q(common_q) */ - scale_sig32( &cy_auto_diff_smooth[cur_idx + start_band], num_freq_bands - start_band, sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ - v_add_fixed( &cy_auto_diff_smooth[cur_idx + start_band], aux_buffer_res, &cy_auto_diff_smooth[cur_idx + start_band], num_freq_bands - start_band, Q1 ); /* Q(common_q) - Q1 */ + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ + scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ + scale_sig32( &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ + v_add_fixed( &cy_auto_diff_smooth[add( cur_idx, start_band )], aux_buffer_res, &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ } /* Q adjustment */ @@ -5927,7 +6056,6 @@ static void computeTargetPSDs_diffuse_fx( return; } #else - static void computeTargetPSDs_diffuse( const int16_t num_channels, const int16_t num_freq_bands, @@ -5957,6 +6085,8 @@ static void computeTargetPSDs_diffuse( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, @@ -5980,7 +6110,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[cur_idx + start_band], num_freq_bands - start_band ); // (q_reference_power, Q31) -> q_reference_power + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power } *q_cy_auto_diff_smooth = *q_reference_power; @@ -5989,8 +6119,6 @@ static void computeTargetPSDs_diffuse_subframe_fx( return; } #else - - static void computeTargetPSDs_diffuse_subframe( const int16_t num_channels, const int16_t num_freq_bands, @@ -6018,6 +6146,7 @@ static void computeTargetPSDs_diffuse_subframe( } #endif + #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, @@ -6090,8 +6219,6 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( return; } #else - - static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, const int16_t num_freq_bands, @@ -6132,6 +6259,8 @@ static void computeTargetPSDs_diffuse_with_onsets( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs ) { @@ -6158,32 +6287,39 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) avg_length_f_ms_fx = tmp_2; + move16(); + move16(); Word32 tmp_3 = Mpy_32_16_1( output_Fs, avg_length_f_ms_fx ); // 0 - tmp_exp - 15 (Q-fac) - Word16 tmp_exp_3 = 0; + Word16 tmp_exp_3; Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); - Word16 tmp_exp_4 = tmp_exp_3 + ( 31 + tmp_exp + 15 ) - 31; - Word16 tmp_exp_5 = 0; + Word16 tmp_exp_4 = sub( add( tmp_exp_3, add( add( 31, tmp_exp ), 15 ) ), 31 ); + Word16 tmp_exp_5; Word16 tmp_5 = BASOP_Util_Divide1616_Scale( slot_size, tmp_4, &tmp_exp_5 ); - Word16 res_exp = tmp_exp_5 + 15 - tmp_exp_4; + Word16 res_exp = sub( add( tmp_exp_5, 15 ), tmp_exp_4 ); Word16 flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp_5 ), res_exp, 1, 31 ); - IF( flag == -1 ) + IF( EQ_16( flag, -1 ) ) { alpha_synthesis_fx[k] = shr( tmp_5, negate( res_exp ) ); // q15 + move16(); } ELSE { alpha_synthesis_fx[k] = MAX16B; + move16(); } Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( alpha_synthesis_fx[k] ), 0, L_deposit_h( maxAlpha_fx ), 0 ); - IF( flag2 == 0 || flag2 == 1 ) + test(); + IF( flag2 == 0 || EQ_16( flag2, 1 ) ) { alpha_synthesis_fx[k] = maxAlpha_fx; - *numAlphas = k + 1; - break; + move16(); + *numAlphas = add( k, 1 ); + move16(); + BREAK; } } } @@ -6191,7 +6327,6 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a return; } #else - static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, @@ -6234,6 +6369,8 @@ static void computeAlphaSynthesis( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningHoa_fx( const Word16 azimuth, @@ -6253,14 +6390,14 @@ static void spreadCoherencePanningHoa_fx( ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); - Word16 exp_Gain_side = 0, exp_Gain_center = 0; - IF( GT_32( spreadCoh_fx, 0 ) ) + Word16 exp_Gain_side, exp_Gain_center; + IF( spreadCoh_fx > 0 ) { - ivas_dirac_dec_get_response_fx( azimuth + 30, elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); - ivas_dirac_dec_get_response_fx( azimuth + 330, elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); - Word16 var_a, var_b, exp_a = 0; + Word16 var_a, var_b, exp_a; IF( LT_16( spreadCoh_fx, ONE_IN_Q14 ) ) { @@ -6271,49 +6408,58 @@ static void spreadCoherencePanningHoa_fx( gainCenter_fx = L_deposit_h( shr( var_a, 2 ) ); // Q11 + 16 = Q27 gainSide_fx = L_deposit_h( mult( spreadCoh_fx, ONE_BY_THREE_Q15 ) ); // Q14 + 16 (reduce Q by 1 to *2) = Q30 exp_Gain_side = 31 - Q30; + move16(); exp_Gain_center = 31 - Q27; + move16(); } ELSE { var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); exp_a = 15 - Q13; + move16(); var_a = Inv16( var_a, &exp_a ); gainSide_fx = L_deposit_h( var_a ); // Q14 + 16 = Q30 //exp_a exp_Gain_side = exp_a; + move16(); var_b = sub( 8192 /*2 in Q12*/, shr( spreadCoh_fx, 2 ) /*Q14*/ ); // exp => 3 gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // Q13 + 16 = Q29 // 3 + exp_a - exp_Gain_center = 3 + exp_a; + exp_Gain_center = add( 3, exp_a ); } Word32 mpy1, mpy2; - Word16 exp_arr[16], exp = 0; - set16_fx( exp_arr, 31 - *Q_direct_response, 16 ); + Word16 exp_arr[16], exp; + set16_fx( exp_arr, sub( 31, *Q_direct_response ), 16 ); FOR( i = 0; i < num_channels_dir; i++ ) { mpy1 = Mpy_32_32( L_add( direct_response_left_fx[i], direct_response_right_fx[i] ), gainSide_fx ); // 31 - Q_direct_response + exp_Gain_Side mpy2 = Mpy_32_32( direct_response_fx[i], gainCenter_fx ); // 31 - Q_direct_response + exp_Gain_Center exp = 0; - direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, 31 - *Q_direct_response + exp_Gain_side, mpy2, 31 - *Q_direct_response + exp_Gain_center, &exp ); + move16(); + direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, 31 - *Q_direct_response + exp_Gain_side, mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); + move32(); exp_arr[i] = exp; + move16(); } Word16 max_val = MIN_16; + move16(); FOR( i = 0; i < 16; i++ ) { - max_val = max( max_val, exp_arr[i] ); + max_val = s_max( max_val, exp_arr[i] ); } FOR( i = 0; i < 16; i++ ) { - direct_response_fx[i] = L_shr( direct_response_fx[i], max_val - exp_arr[i] ); + direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); + move32(); } - *Q_direct_response = 31 - max_val; + *Q_direct_response = sub( 31, max_val ); + move16(); } return; } #else - static void spreadCoherencePanningHoa( const int16_t azimuth, const int16_t elevation, @@ -6356,6 +6502,8 @@ static void spreadCoherencePanningHoa( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( const Word16 azimuth, @@ -6366,7 +6514,7 @@ static void spreadCoherencePanningVbap_fx( const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata ) { - int16_t i; + Word16 i; Word32 direct_response_left_fx[MAX_OUTPUT_CHANNELS]; Word32 direct_response_right_fx[MAX_OUTPUT_CHANNELS]; set32_fx( direct_response_left_fx, 0, MAX_OUTPUT_CHANNELS ); @@ -6382,6 +6530,7 @@ static void spreadCoherencePanningVbap_fx( Word16 var_temp = ISqrt16( num_channels_dir, &exp_tmp ); set32_fx( direct_response_fx, var_temp, num_channels_dir ); *Q_direct_response = sub( 31, exp_tmp ); + move16(); return; } @@ -6391,10 +6540,10 @@ static void spreadCoherencePanningVbap_fx( *Q_direct_response = Q29; move16(); - IF( GT_16( spreadCoh_fx, 0 ) ) + IF( spreadCoh_fx > 0 ) { - vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, azimuth + 30, elevation, 0 ); - vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, azimuth - 30, elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, add( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, sub( azimuth, 30 ), elevation, 0 ); Word32 var1 = 0; move32(); @@ -6436,7 +6585,6 @@ static void spreadCoherencePanningVbap_fx( return; } #else - static void spreadCoherencePanningVbap( const int16_t azimuth, const int16_t elevation, @@ -6485,26 +6633,29 @@ static void spreadCoherencePanningVbap( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void normalizePanningGains_fx( Word32 *direct_response_fx, Word16 *q_direct_res, - const int16_t num_channels_dir ) + const Word16 num_channels_dir ) { Word32 energySum_fx; Word16 exp_energySum = 0; Word32 normVal_fx; - int16_t i; + Word16 i; + move16(); Word16 gb = find_guarded_bits_fx( num_channels_dir ); energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); - if ( *q_direct_res > 31 ) + IF( GT_16( *q_direct_res, Q31 ) ) { - exp_energySum = ( 31 - *q_direct_res ) * 2 + gb; + exp_energySum = add( shl( sub( Q31, *q_direct_res ), 1 ), gb ); } - exp_energySum = 31 - ( ( 2 * ( *q_direct_res ) - 31 ) - gb ); + exp_energySum = sub( Q31, sub( sub( shl( *q_direct_res, 1 ), Q31 ), gb ) ); - IF( GT_32( energySum_fx, 0 ) ) + IF( energySum_fx > 0 ) { normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); } @@ -6517,14 +6668,14 @@ static void normalizePanningGains_fx( FOR( i = 0; i < num_channels_dir; i++ ) { direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); + move32(); } - Word16 exp = 31 - *q_direct_res + exp_energySum; - *q_direct_res = 31 - exp; + Word16 exp = add( sub( Q31, *q_direct_res ), exp_energySum ); + *q_direct_res = sub( Q31, exp ); return; } #else - static void normalizePanningGains( float *direct_response, const int16_t num_channels_dir ) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index eadb0f81d..e96aec922 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -46,7 +46,7 @@ #include "ivas_prot_fx.h" #include "ivas_rom_binaural_crend_head.h" -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED + /*------------------------------------------------------------------------- * ivas_dirac_allocate_parameters() * @@ -208,10 +208,12 @@ ivas_error ivas_dirac_allocate_parameters_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } + IF( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } + IF( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -338,8 +340,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( DIRAC_CONFIG_FLAG flag_config; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + flag_config = EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + move32(); error = IVAS_ERR_OK; + move32(); hSpatParamRendCom = NULL; @@ -347,7 +351,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( { hSpatParamRendCom = *hSpatParamRendCom_out; } - ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) ) + ELSE IF( flag_config == DIRAC_OPEN ) { /*-----------------------------------------------------------------* * prepare library opening @@ -375,6 +379,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->slots_rendered = 0; move16(); hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); move16(); @@ -390,8 +395,12 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( * set input parameters *-----------------------------------------------------------------*/ + test(); + test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && EQ_32( flag_config, DIRAC_RECONFIGURE ) ) { + test(); + test(); IF( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) { IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) ) @@ -405,7 +414,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( } } - IF( EQ_32( flag_config, DIRAC_OPEN ) ) + IF( flag_config == DIRAC_OPEN ) { hSpatParamRendCom->dirac_md_buffer_length = 0; move16(); @@ -413,6 +422,8 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( move16(); hSpatParamRendCom->dirac_read_idx = 0; move16(); + test(); + test(); IF( EQ_32( mc_mode, MC_MODE_MCMASA ) || EQ_16( masa_ext_rend_flag, 1 ) ) { hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; @@ -441,9 +452,9 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( } ELSE { - Word16 num_slots_in_subfr; + Word16 num_slots_in_subfr, tmp = 1; num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - hSpatParamRendCom->dirac_md_buffer_length = add( MAX_PARAM_SPATIAL_SUBFRAMES, DELAY_DIRAC_PARAM_DEC_SFR ); + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR; move16(); hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; move16(); @@ -451,9 +462,17 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( move16(); set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + + if ( EQ_16( num_slots_in_subfr, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + tmp = 2; + move16(); + } + FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) { - hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; + hSpatParamRendCom->render_to_md_map[map_idx] = add( hSpatParamRendCom->dirac_read_idx, shr( map_idx, tmp ) ); + move16(); } } @@ -462,6 +481,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( return error; } + test(); + test(); + test(); + test(); IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || ( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && hodirac_flag ) ) { IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) ) @@ -593,10 +616,12 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; } } + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) { return error; } + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && hodirac_flag ) ) { if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) @@ -617,6 +642,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config( } #endif + /*------------------------------------------------------------------------- * ivas_spat_hSpatParamRendCom_close() * @@ -658,6 +684,7 @@ void ivas_spat_hSpatParamRendCom_close_fx( } #endif + /*------------------------------------------------------------------------- * ivas_dirac_rend_close() * @@ -671,6 +698,7 @@ void ivas_dirac_rend_close_fx( Word16 i, j; DIRAC_REND_HANDLE hDirACRend; + test(); IF( hDirACRend_out == NULL || *hDirACRend_out == NULL ) { return; @@ -679,11 +707,7 @@ void ivas_dirac_rend_close_fx( hDirACRend = *hDirACRend_out; /* close Output synthesis sub-module */ -#ifdef IVAS_FLOAT_FIXED ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); -#else - ivas_dirac_dec_output_synthesis_close( hDirACRend ); -#endif /* close Decorrelator sub-module */ IF( hDirACRend->proto_signal_decorr_on ) @@ -693,31 +717,30 @@ void ivas_dirac_rend_close_fx( /* Params */ -#ifdef IVAS_FLOAT_FIXED /* free frequency axis buffer */ IF( hDirACRend->frequency_axis_fx != NULL ) { free( hDirACRend->frequency_axis_fx ); hDirACRend->frequency_axis_fx = NULL; } + IF( hDirACRend->diffuse_response_function_fx != NULL ) { free( hDirACRend->diffuse_response_function_fx ); hDirACRend->diffuse_response_function_fx = NULL; } + IF( hDirACRend->hoa_encoder_fx != NULL ) { free( hDirACRend->hoa_encoder_fx ); hDirACRend->hoa_encoder_fx = NULL; } -#endif -#ifdef IVAS_FLOAT_FIXED + IF( hDirACRend->hoa_encoder_fx != NULL ) { free( hDirACRend->hoa_encoder_fx ); hDirACRend->hoa_encoder_fx = NULL; } -#endif /* prototype indexing */ IF( hDirACRend->proto_index_dir != NULL ) @@ -764,6 +787,7 @@ void ivas_dirac_rend_close_fx( free( hDirACRend->masa_stereo_type_detect ); hDirACRend->masa_stereo_type_detect = NULL; } + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); free( *hDirACRend_out ); @@ -885,20 +909,21 @@ void ivas_dirac_deallocate_parameters_fx( Word16 i; Word16 md_buffer_length; - if ( hSpatParamRendCom == NULL ) + IF( hSpatParamRendCom == NULL ) { return; } md_buffer_length = hSpatParamRendCom->dirac_md_buffer_length; + move16(); - if ( params_flag == 1 ) + IF( EQ_16( params_flag, 1 ) ) { - if ( hSpatParamRendCom->azimuth != NULL ) + IF( hSpatParamRendCom->azimuth != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->azimuth[i] != NULL ) + IF( hSpatParamRendCom->azimuth[i] != NULL ) { free( hSpatParamRendCom->azimuth[i] ); hSpatParamRendCom->azimuth[i] = NULL; @@ -909,11 +934,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->azimuth = NULL; } - if ( hSpatParamRendCom->elevation != NULL ) + IF( hSpatParamRendCom->elevation != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->elevation[i] != NULL ) + IF( hSpatParamRendCom->elevation[i] != NULL ) { free( hSpatParamRendCom->elevation[i] ); hSpatParamRendCom->elevation[i] = NULL; @@ -924,11 +949,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->elevation = NULL; } - if ( hSpatParamRendCom->energy_ratio1_fx != NULL ) + IF( hSpatParamRendCom->energy_ratio1_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->energy_ratio1_fx[i] != NULL ) + IF( hSpatParamRendCom->energy_ratio1_fx[i] != NULL ) { free( hSpatParamRendCom->energy_ratio1_fx[i] ); hSpatParamRendCom->energy_ratio1_fx[i] = NULL; @@ -938,11 +963,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->energy_ratio1_fx = NULL; } - if ( hSpatParamRendCom->diffuseness_vector_fx != NULL ) + IF( hSpatParamRendCom->diffuseness_vector_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->diffuseness_vector_fx[i] != NULL ) + IF( hSpatParamRendCom->diffuseness_vector_fx[i] != NULL ) { free( hSpatParamRendCom->diffuseness_vector_fx[i] ); hSpatParamRendCom->diffuseness_vector_fx[i] = NULL; @@ -953,11 +978,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->diffuseness_vector_fx = NULL; } - if ( hSpatParamRendCom->spreadCoherence_fx != NULL ) + IF( hSpatParamRendCom->spreadCoherence_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->spreadCoherence_fx[i] != NULL ) + IF( hSpatParamRendCom->spreadCoherence_fx[i] != NULL ) { free( hSpatParamRendCom->spreadCoherence_fx[i] ); hSpatParamRendCom->spreadCoherence_fx[i] = NULL; @@ -967,11 +992,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->spreadCoherence_fx = NULL; } - if ( hSpatParamRendCom->surroundingCoherence_fx != NULL ) + IF( hSpatParamRendCom->surroundingCoherence_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->surroundingCoherence_fx[i] != NULL ) + IF( hSpatParamRendCom->surroundingCoherence_fx[i] != NULL ) { free( hSpatParamRendCom->surroundingCoherence_fx[i] ); hSpatParamRendCom->surroundingCoherence_fx[i] = NULL; @@ -981,13 +1006,13 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->surroundingCoherence_fx = NULL; } } - else if ( params_flag == 2 ) + ELSE IF( EQ_16( params_flag, 2 ) ) { - if ( hSpatParamRendCom->azimuth2 != NULL ) + IF( hSpatParamRendCom->azimuth2 != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->azimuth2[i] != NULL ) + IF( hSpatParamRendCom->azimuth2[i] != NULL ) { free( hSpatParamRendCom->azimuth2[i] ); hSpatParamRendCom->azimuth2[i] = NULL; @@ -997,11 +1022,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->azimuth2 = NULL; } - if ( hSpatParamRendCom->elevation2 != NULL ) + IF( hSpatParamRendCom->elevation2 != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->elevation2[i] != NULL ) + IF( hSpatParamRendCom->elevation2[i] != NULL ) { free( hSpatParamRendCom->elevation2[i] ); hSpatParamRendCom->elevation2[i] = NULL; @@ -1011,11 +1036,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->elevation2 = NULL; } - if ( hSpatParamRendCom->energy_ratio2_fx != NULL ) + IF( hSpatParamRendCom->energy_ratio2_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->energy_ratio2_fx[i] != NULL ) + IF( hSpatParamRendCom->energy_ratio2_fx[i] != NULL ) { free( hSpatParamRendCom->energy_ratio2_fx[i] ); hSpatParamRendCom->energy_ratio2_fx[i] = NULL; @@ -1025,11 +1050,11 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->energy_ratio2_fx = NULL; } - if ( hSpatParamRendCom->spreadCoherence2_fx != NULL ) + IF( hSpatParamRendCom->spreadCoherence2_fx != NULL ) { - for ( i = 0; i < md_buffer_length; i++ ) + FOR( i = 0; i < md_buffer_length; i++ ) { - if ( hSpatParamRendCom->spreadCoherence2_fx[i] != NULL ) + IF( hSpatParamRendCom->spreadCoherence2_fx[i] != NULL ) { free( hSpatParamRendCom->spreadCoherence2_fx[i] ); hSpatParamRendCom->spreadCoherence2_fx[i] = NULL; @@ -1217,240 +1242,163 @@ void ivas_dirac_deallocate_parameters( * Allocate stack memory for DirAC renderer *------------------------------------------------------------------------*/ -ivas_error ivas_dirac_alloc_mem( +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_alloc_mem_fx( DIRAC_REND_HANDLE hDirACRend, const RENDERER_TYPE renderer_type, - const int16_t num_freq_bands, + const Word16 num_freq_bands, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, - const int16_t hodirac_flag ) + const Word16 hodirac_flag ) { - int16_t num_freq_bands_diff, size; - int16_t size_ho; - int16_t size_pf; - int16_t num_outputs_dir, num_outputs_diff; - int16_t num_protos_dir; + Word16 num_freq_bands_diff, size; + Word16 size_ho; + Word16 size_pf; + Word16 num_outputs_dir, num_outputs_diff; + Word16 num_protos_dir; num_protos_dir = hDirACRend->num_protos_dir; + move16(); num_freq_bands_diff = hDirACRend->h_output_synthesis_psd_params.max_band_decorr; + move16(); num_outputs_dir = hDirACRend->num_outputs_dir; + move16(); num_outputs_diff = hDirACRend->num_outputs_diff; + move16(); - size = num_freq_bands * num_outputs_dir; - if ( hodirac_flag ) + size = imult1616( num_freq_bands, num_outputs_dir ); + IF( hodirac_flag ) { - size_ho = size * DIRAC_HO_NUMSECTORS; - size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS; + size_ho = imult1616( size, DIRAC_HO_NUMSECTORS ); + size_pf = imult1616( num_freq_bands, DIRAC_HO_NUMSECTORS ); } - else + ELSE { size_ho = size; + move16(); size_pf = num_freq_bands; + move16(); } /* PSD related buffers */ -#ifdef IVAS_FLOAT_FIXED hDirAC_mem->cy_auto_dir_smooth_fx = NULL; hDirAC_mem->proto_power_smooth_fx = NULL; hDirAC_mem->proto_power_diff_smooth_fx = NULL; hDirAC_mem->direct_responses_square_fx = NULL; -#else - hDirAC_mem->cy_auto_dir_smooth = NULL; - hDirAC_mem->direct_responses_square = NULL; -#endif -#ifdef IVAS_FLOAT_FIXED hDirAC_mem->frame_dec_f_fx = NULL; -#else - hDirAC_mem->proto_power_smooth = NULL; - hDirAC_mem->proto_power_diff_smooth = NULL; - hDirAC_mem->direct_responses_square = NULL; - hDirAC_mem->frame_dec_f = NULL; -#endif - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); -#else - if ( ( hDirAC_mem->cy_auto_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) + IF( ( hDirAC_mem->cy_auto_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->cy_auto_dir_smooth_fx, size ); hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len = size; -#endif - -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->proto_power_smooth, size ); + move16(); - if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->proto_power_diff_smooth, size ); -#else - if ( ( hDirAC_mem->proto_power_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) + IF( ( hDirAC_mem->proto_power_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->proto_power_smooth_fx, size ); hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len = size; - if ( ( hDirAC_mem->proto_power_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) + move16(); + + IF( ( hDirAC_mem->proto_power_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->proto_power_diff_smooth_fx, size ); hDirAC_mem->proto_power_diff_smooth_len = size; + move16(); hDirAC_mem->proto_power_diff_smooth_q = Q31; -#endif + move16(); -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->direct_responses_square, size ); -#else - if ( ( hDirAC_mem->direct_responses_square_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) + IF( ( hDirAC_mem->direct_responses_square_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set32_fx( hDirAC_mem->direct_responses_square_fx, 0, size ); -#endif - if ( hDirACRend->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + test(); + test(); + test(); + IF( hDirACRend->proto_signal_decorr_on && ( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else - if ( ( hDirAC_mem->frame_dec_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) + IF( ( hDirAC_mem->frame_dec_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } #ifdef MSAN_FIX set_zero_fx( hDirAC_mem->frame_dec_f_fx, 2 * num_outputs_diff * num_freq_bands ); #endif - hDirAC_mem->frame_dec_f_len = 2 * num_outputs_diff * num_freq_bands; -#endif + hDirAC_mem->frame_dec_f_len = imult1616( imult1616( 2, num_outputs_diff ), num_freq_bands ); } } -#ifndef IVAS_FLOAT_FIXED - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; - hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; - hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; -#else - hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx; - hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = Q31; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx = hDirAC_mem->proto_power_diff_smooth_fx; hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirAC_mem->proto_power_diff_smooth_q; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len = hDirAC_mem->proto_power_diff_smooth_len; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = Q31; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = Q31; + move16(); hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx = hDirAC_mem->cy_auto_dir_smooth_fx; hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = 0; move16(); -#endif + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx; + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; + move16(); + move16(); /* Target and smoothed nrg factors/gains */ -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#ifdef MSAN_FIX - set_zero( hDirAC_mem->cy_cross_dir_smooth, size_ho ); -#else - set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); -#endif -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->cy_cross_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) + IF( ( hDirAC_mem->cy_cross_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len = size_ho; + move16(); #ifdef MSAN_FIX set_zero_fx( hDirAC_mem->cy_cross_dir_smooth_fx, size_ho ); #else set_zero_fx( hDirAC_mem->cy_cross_dir_smooth_fx, size ); hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len = size_ho; -#endif #endif - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); -#else - if ( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) + IF( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, size ); hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = size; -#endif + move16(); } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); -#else - if ( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) + IF( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, num_outputs_diff * num_freq_bands_diff ); - hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = num_outputs_diff * num_freq_bands_diff; -#endif + set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, imult1616( num_outputs_diff, num_freq_bands_diff ) ); + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = imult1616( num_outputs_diff, num_freq_bands_diff ); } -#ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx = hDirAC_mem->cy_cross_dir_smooth_fx; - hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx = hDirAC_mem->cy_auto_diff_smooth_fx; hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = 31; move16(); + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx = hDirAC_mem->cy_auto_diff_smooth_fx; hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = 0; move16(); -#else - hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; - hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; -#endif - - /*Responses (gains/factors)*/ -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->direct_responses, size ); - - - hDirACRend->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; -#else /*Responses (gains/factors)*/ - if ( ( hDirAC_mem->direct_responses_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) + IF( ( hDirAC_mem->direct_responses_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } @@ -1459,100 +1407,59 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx = hDirAC_mem->direct_responses_fx; hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; -#endif + move16(); /* Prototypes */ -#ifndef IVAS_FLOAT_FIXED - hDirAC_mem->proto_direct_buffer_f = NULL; - hDirAC_mem->proto_diffuse_buffer_f = NULL; -#else hDirAC_mem->proto_direct_buffer_f_fx = NULL; hDirAC_mem->proto_diffuse_buffer_f_fx = NULL; -#endif - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else IF( ( hDirAC_mem->proto_direct_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len = imult1616( imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, num_protos_dir ), num_freq_bands ); - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len = 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands; -#endif - - if ( hDirACRend->proto_signal_decorr_on ) + IF( hDirACRend->proto_signal_decorr_on ) { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - hDirAC_mem->proto_diffuse_buffer_f_len = 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size; -#endif + hDirAC_mem->proto_diffuse_buffer_f_len = imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, size ); } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - hDirAC_mem->proto_diffuse_buffer_f_len = 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands; -#endif + hDirAC_mem->proto_diffuse_buffer_f_len = imult1616( imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, num_outputs_diff ), num_freq_bands ); } #ifdef MSAN_FIX set_zero_fx( hDirAC_mem->proto_diffuse_buffer_f_fx, hDirAC_mem->proto_diffuse_buffer_f_len ); #endif } } -#ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx = hDirAC_mem->proto_direct_buffer_f_fx; hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx = hDirAC_mem->proto_diffuse_buffer_f_fx; hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len = hDirAC_mem->proto_diffuse_buffer_f_len; + move16(); hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = Q31; -#else - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; -#endif - /* Gains/power factors*/ + move16(); -#ifdef IVAS_FLOAT_FIXED + /* Gains/power factors*/ hDirAC_mem->direct_power_factor_fx = NULL; hDirAC_mem->diffuse_power_factor_fx = NULL; -#else - hDirAC_mem->direct_power_factor = NULL; - hDirAC_mem->diffuse_power_factor = NULL; -#endif - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else IF( ( hDirAC_mem->direct_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1561,10 +1468,8 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } -#endif } -#ifdef IVAS_FLOAT_FIXED 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; set_zero_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, size_pf ); @@ -1573,107 +1478,267 @@ ivas_error ivas_dirac_alloc_mem( move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; move16(); -#else - hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; - set_zero( hDirACRend->h_output_synthesis_psd_state.direct_power_factor, size_pf ); - set_zero( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, size_pf ); -#endif -#ifndef IVAS_FLOAT_FIXED - hDirAC_mem->reference_power = NULL; - hDirAC_mem->onset_filter = NULL; -#endif -#ifdef IVAS_FLOAT_FIXED hDirAC_mem->reference_power_fx = NULL; hDirAC_mem->onset_filter_fx = NULL; -#endif - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#else - if ( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL ) + IF( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } - hDirAC_mem->reference_power_len = 2 * num_freq_bands; + hDirAC_mem->reference_power_len = imult1616( 2, num_freq_bands ); hDirAC_mem->reference_power_q = Q31; + move16(); hDirAC_mem->reference_power_smooth_q = Q31; -#endif - if ( hDirACRend->proto_signal_decorr_on ) + move16(); + IF( hDirACRend->proto_signal_decorr_on ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands ) ) == NULL ) + IF( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } #ifdef MSAN_FIX -#ifndef IVAS_FLOAT_FIXED - set_zero( hDirAC_mem->onset_filter, num_outputs_diff * num_freq_bands ); -#endif - set_zero_fx( hDirAC_mem->onset_filter_fx, num_outputs_diff * num_freq_bands ); -#endif + set_zero_fx( hDirAC_mem->onset_filter_fx, imult1616( num_outputs_diff, num_freq_bands ) ); #endif } } } - else + ELSE { - if ( num_protos_dir > 2 ) + IF( GT_16( num_protos_dir, 2 ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) + IF( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 5 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + + hDirAC_mem->reference_power_len = imult1616( 5, num_freq_bands ); + } + + IF( hDirACRend->proto_signal_decorr_on ) + { + IF( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } +#ifdef MSAN_FIX + set_zero_fx( hDirAC_mem->onset_filter_fx, imult1616( 2, num_freq_bands ) ); +#endif + } + } + + return IVAS_ERR_OK; +} #else - if ( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 5 * num_freq_bands ) ) == NULL ) +ivas_error ivas_dirac_alloc_mem( + DIRAC_REND_HANDLE hDirACRend, + const RENDERER_TYPE renderer_type, + const int16_t num_freq_bands, + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, + const int16_t hodirac_flag ) +{ + int16_t num_freq_bands_diff, size; + int16_t size_ho; + int16_t size_pf; + int16_t num_outputs_dir, num_outputs_diff; + int16_t num_protos_dir; + + num_protos_dir = hDirACRend->num_protos_dir; + + num_freq_bands_diff = hDirACRend->h_output_synthesis_psd_params.max_band_decorr; + + num_outputs_dir = hDirACRend->num_outputs_dir; + num_outputs_diff = hDirACRend->num_outputs_diff; + + size = num_freq_bands * num_outputs_dir; + if ( hodirac_flag ) + { + size_ho = size * DIRAC_HO_NUMSECTORS; + size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS; + } + else + { + size_ho = size; + size_pf = num_freq_bands; + } + + /* PSD related buffers */ + hDirAC_mem->cy_auto_dir_smooth = NULL; + hDirAC_mem->proto_power_smooth = NULL; + hDirAC_mem->proto_power_diff_smooth = NULL; + hDirAC_mem->direct_responses_square = NULL; + hDirAC_mem->frame_dec_f = NULL; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); + + if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_smooth, size ); + + if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_diff_smooth, size ); + + if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->direct_responses_square, size ); + if ( hDirACRend->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + } + } + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; + hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; + hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; - hDirAC_mem->reference_power_len = 5 * num_freq_bands; -#endif + /* Target and smoothed nrg factors/gains */ + if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); + + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); + } + else + { + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); + } + hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; + + /*Responses (gains/factors)*/ + if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->direct_responses, size ); + + + hDirACRend->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; + + /* Prototypes */ + hDirAC_mem->proto_direct_buffer_f = NULL; + hDirAC_mem->proto_diffuse_buffer_f = NULL; + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } if ( hDirACRend->proto_signal_decorr_on ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + { + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + else + { + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + } + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; + + /* Gains/power factors*/ + hDirAC_mem->direct_power_factor = NULL; + hDirAC_mem->diffuse_power_factor = NULL; + + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + + hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; + + hDirAC_mem->reference_power = NULL; + hDirAC_mem->onset_filter = NULL; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL ) + if ( hDirACRend->proto_signal_decorr_on ) + { + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + } + else + { + if ( num_protos_dir > 2 ) + { + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + + if ( hDirACRend->proto_signal_decorr_on ) + { + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } -#ifdef MSAN_FIX -#ifndef IVAS_FLOAT_FIXED - set_zero( hDirAC_mem->onset_filter, 2 * num_freq_bands ); -#endif - set_zero_fx( hDirAC_mem->onset_filter_fx, 2 * num_freq_bands ); -#endif -#endif } } return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -1698,10 +1763,6 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->proto_power_diff_smooth_fx ); } - /*IF( hDirAC_mem->direct_responses_square != NULL ) - { - free( hDirAC_mem->direct_responses_square ); - }*/ IF( hDirAC_mem->direct_responses_square_fx != NULL ) { free( hDirAC_mem->direct_responses_square_fx ); @@ -1710,12 +1771,6 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->frame_dec_f_fx ); } -#if 0 /* TODO: remove float free */ - IF (hDirAC_mem->frame_dec_f != NULL) - { - free( hDirAC_mem->frame_dec_f ); - } -#endif IF( hDirAC_mem->cy_cross_dir_smooth_fx != NULL ) { free( hDirAC_mem->cy_cross_dir_smooth_fx ); @@ -1724,42 +1779,18 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->cy_auto_diff_smooth_fx ); } -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF( hDirAC_mem->direct_responses != NULL ) - { - free( hDirAC_mem->direct_responses ); - } -#endif - if ( hDirAC_mem->direct_responses_fx != NULL ) + IF( hDirAC_mem->direct_responses_fx != NULL ) { free( hDirAC_mem->direct_responses_fx ); } - /*IF( hDirAC_mem->proto_direct_buffer_f != NULL ) - { - free( hDirAC_mem->proto_direct_buffer_f ); - }*/ IF( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) { free( hDirAC_mem->proto_direct_buffer_f_fx ); } - /*IF( hDirAC_mem->proto_diffuse_buffer_f != NULL ) - { - free( hDirAC_mem->proto_diffuse_buffer_f ); - }*/ IF( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) { free( hDirAC_mem->proto_diffuse_buffer_f_fx ); } -#ifndef IVAS_FLOAT_FIXED - IF( hDirAC_mem->direct_power_factor != NULL ) - { - free( hDirAC_mem->direct_power_factor ); - } - IF( hDirAC_mem->diffuse_power_factor != NULL ) - { - free( hDirAC_mem->diffuse_power_factor ); - } -#endif IF( hDirAC_mem->direct_power_factor_fx != NULL ) { free( hDirAC_mem->direct_power_factor_fx ); @@ -1856,21 +1887,20 @@ void compute_hoa_encoder_mtx_fx( const Word32 *azimuth, const Word32 *elevation, Word32 *response_fx, - const int16_t num_responses, - const int16_t ambisonics_order ) + const Word16 num_responses, + const Word16 ambisonics_order ) { Word16 k, num_sh; num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { - ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order, Q31 ); // Q29 + ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[imult1616( k, num_sh )], ambisonics_order, Q31 ); /* Q31 */ } return; } #else - void compute_hoa_encoder_mtx( const float *azimuth, const float *elevation, @@ -1890,11 +1920,14 @@ void compute_hoa_encoder_mtx( return; } #endif + + /*------------------------------------------------------------------------- * ivas_dirac_dec_get_frequency_axis() * * DirAC decoding initialization *------------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_get_frequency_axis( float *frequency_axis, @@ -1923,22 +1956,25 @@ void ivas_dirac_dec_get_frequency_axis_fx( /* calc cldfb frequency axis */ const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); - const_part = shr( const_part, ( -1 - scale ) ); - for ( k = 0; k < num_freq_bands; k++ ) + const_part = shr( const_part, sub( -1, scale ) ); + FOR( k = 0; k < num_freq_bands; k++ ) { /* frequency_axis[k] = ((float)k + 0.5f) * const_part; */ frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); + move16(); } return; } #endif + /*------------------------------------------------------------------------- * initDiffuseResponses() * * *-------------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED void initDiffuseResponses( float *diffuse_response_function, @@ -2061,66 +2097,99 @@ void initDiffuseResponses_fx( Word16 var1, exp_var1, res; - IF( output_config == IVAS_AUDIO_CONFIG_MONO ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { diffuse_response_function_fx[0] = MAX16B; + move16(); diffuse_response_function_fx[1] = 18918 /*inv_sqrt(3.0f) oin Q15*/; + move16(); } - ELSE IF( !( output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) + ELSE IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { /* set diffuse response function */ - IF( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_5_1_4 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + move16(); } - ELSE IF( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_7_1_4 ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); exp_var1 = 15; + move16(); var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); var1 = shr( var1, negate( exp_var1 ) ); // Q15 set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + move16(); } - ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5 ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && EQ_16( num_channels, 5 ) ) { Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); } - ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && EQ_16( num_channels, 7 ) ) { Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); } - ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) && EQ_16( num_channels, 9 ) ) { Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); } - ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) + IF( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) { /* Detect loudspeakers with elevation */ num_horizontal_speakers = 0; + move16(); FOR( i = 0; i < num_channels; i++ ) { IF( LE_32( abs( hOutSetup.ls_elevation_fx[i] ), 20971520 ) /*5 in Q22*/ ) { num_horizontal_speakers = add( num_horizontal_speakers, 1 ); diffuse_response_function_fx[i] = MAX16B; + move16(); } ELSE { *num_ele_spk_no_diffuse_rendering = add( *num_ele_spk_no_diffuse_rendering, 1 ); + move16(); diffuse_response_function_fx[i] = 0; + move16(); } } /* Diffuse only to horizontal plane IF enough loudspeakers */ IF( GT_16( num_horizontal_speakers, 2 ) ) { exp_var1 = 15; + move16(); Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); assert( 0 ); @@ -2128,20 +2197,26 @@ void initDiffuseResponses_fx( FOR( i = 0; i < num_channels; i++ ) { diffuse_response_function_fx[i] = shr( mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ), Q15 ); + move16(); } } ELSE { var1 = num_channels, exp_var1 = 15; + move16(); + move16(); res = ISqrt16( var1, &exp_var1 ); res = shr( res, negate( exp_var1 ) ); set16_fx( diffuse_response_function_fx, res, num_channels ); *num_ele_spk_no_diffuse_rendering = 0; + move16(); } } ELSE { var1 = num_channels, exp_var1 = 15; + move16(); + move16(); res = ISqrt16( var1, &exp_var1 ); res = shr( res, negate( exp_var1 ) ); set16_fx( diffuse_response_function_fx, res, num_channels ); @@ -2150,6 +2225,8 @@ void initDiffuseResponses_fx( ELSE { var1 = num_channels, exp_var1 = 15; + move16(); + move16(); res = ISqrt16( var1, &exp_var1 ); res = shr( res, negate( exp_var1 ) ); set16_fx( diffuse_response_function_fx, res, num_channels ); @@ -2158,6 +2235,7 @@ void initDiffuseResponses_fx( ELSE { idx = 0; + move16(); Word16 j; FOR( l = 0; l <= ambisonics_order; l++ ) { @@ -2165,6 +2243,8 @@ void initDiffuseResponses_fx( FOR( k = 0; k < j; k++ ) { var1 = j, exp_var1 = 15; + move16(); + move16(); res = ISqrt16( var1, &exp_var1 ); diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); idx = add( idx, 1 ); @@ -2176,13 +2256,14 @@ void initDiffuseResponses_fx( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * protoSignalComputation_shd_fx() + * protoSignalComputation_shd() * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -2225,9 +2306,9 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[i_mult( 2, l )] = RealBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = ImagBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[add( 2 * l, 1 )] = ImagBuffer_fx[0][0][l]; move32(); } *proto_direct_buffer_f_q = q_cldfb; @@ -2247,9 +2328,9 @@ void protoSignalComputation_shd_fx( re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); - p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; move32(); p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx move32(); @@ -2266,9 +2347,9 @@ void protoSignalComputation_shd_fx( re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); - p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; move32(); p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); move32(); @@ -2395,6 +2476,7 @@ void protoSignalComputation_shd_fx( *proto_direct_buffer_f_q = q_cldfb; move16(); *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + move16(); } /* Additional transport channels = planar SBA components of degree higher than 1*/ @@ -2431,12 +2513,6 @@ void protoSignalComputation_shd_fx( return; } #else -/*------------------------------------------------------------------------- - * protoSignalComputation_shd() - * - * - *-------------------------------------------------------------------------*/ - void protoSignalComputation_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -2593,13 +2669,14 @@ void protoSignalComputation_shd( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * protoSignalComputation1_fx() + * protoSignalComputation1() * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void protoSignalComputation1_fx( Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -2653,6 +2730,7 @@ void protoSignalComputation1_fx( reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); move32(); *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + move16(); IF( LT_16( *reference_power_q, *proto_power_smooth_q ) ) { @@ -2695,12 +2773,6 @@ void protoSignalComputation1_fx( return; } #else -/*------------------------------------------------------------------------- - * protoSignalComputation1() - * - * - *-------------------------------------------------------------------------*/ - void protoSignalComputation1( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -2734,13 +2806,15 @@ void protoSignalComputation1( return; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*------------------------------------------------------------------------- - * protoSignalComputation2_fx() + * protoSignalComputation2() * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void protoSignalComputation2_fx( Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -2821,6 +2895,7 @@ void protoSignalComputation2_fx( scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); } *q_proto_power_smooth = add( *q_proto_power_smooth, sub( q_shift, 1 ) ); + move16(); IF( isloudspeaker ) { @@ -2918,24 +2993,31 @@ void protoSignalComputation2_fx( p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); left_bb_power_fx = 0; + move32(); right_bb_power_fx = 0; + move32(); total_bb_power_fx = 0; + move32(); left_hi_power_fx = 0; + move32(); right_hi_power_fx = 0; + move32(); total_hi_power_fx = 0; + move32(); dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0]; + move16(); dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1]; + move16(); a_fx = 21474836; /*0.01 in Q31*/ /* Temporal smoothing coefficient */ move32(); b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient */ // a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */ - move32(); // b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */ - IF( GT_16( stereo_type_detect->interpolator, 0 ) ) + IF( stereo_type_detect->interpolator > 0 ) { IF( EQ_16( stereo_type_detect->type_change_direction, MASA_STEREO_SPACED_MICS ) ) { @@ -2954,9 +3036,7 @@ void protoSignalComputation2_fx( min_q_shift = sub( min_q_shift, idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) ); q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - move16(); q_temp2 = sub( add( add( q_cldfb, temp_q_shift ), add( q_cldfb, temp_q_shift ) ), 31 ); - move16(); FOR( l = 0; l < num_freq_bands; l++ ) { @@ -3025,7 +3105,7 @@ void protoSignalComputation2_fx( move32(); } - IF( EQ_16( l, 0 ) ) + IF( l == 0 ) { RealSubtract_fx = L_sub( re1, re2 ); ImagSubtract_fx = L_sub( im1, im2 ); @@ -3034,19 +3114,21 @@ void protoSignalComputation2_fx( IF( LT_16( q_temp, stereo_type_detect->q_subtract_power_y ) ) { stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); + move32(); stereo_type_detect->q_subtract_power_y = q_temp; move16(); } ELSE { stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); + move32(); } } /* Compute protos (and their power) for direct sound rendering */ /* W prototype */ - IF( GT_16( stereo_type_detect->interpolator, 0 ) ) + IF( stereo_type_detect->interpolator > 0 ) { IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) ) { @@ -3065,9 +3147,9 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); } ELSE @@ -3087,9 +3169,9 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[add( 2 * l, 1 )] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); move32(); } } @@ -3112,9 +3194,9 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); } ELSE @@ -3131,9 +3213,9 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = re1; + p_proto_buffer_fx[2 * l] = re1; move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + p_proto_buffer_fx[add( 2 * l, 1 )] = im1; move32(); } } @@ -3151,20 +3233,20 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); } /* Y prototype */ - IF( GT_16( stereo_type_detect->interpolator, 0 ) ) + IF( stereo_type_detect->interpolator > 0 ) { IF( LT_16( l, dipole_freq_range[0] ) ) { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[i_mult( 2, l )], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( i_mult( 2, l ), 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); move32(); } ELSE IF( LT_16( l, dipole_freq_range[1] ) ) @@ -3176,9 +3258,9 @@ void protoSignalComputation2_fx( } ELSE { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[i_mult( 2, l )], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( i_mult( 2, l ), 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); move32(); } @@ -3198,9 +3280,9 @@ void protoSignalComputation2_fx( { IF( LT_16( l, dipole_freq_range[0] ) ) /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[i_mult( 2, l )]; + p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( i_mult( 2, l ), 1 )]; + p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; move32(); proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; move32(); @@ -3226,9 +3308,9 @@ void protoSignalComputation2_fx( } ELSE /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[i_mult( 2, l )]; + p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( i_mult( 2, l ), 1 )]; + p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; move32(); proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; move32(); @@ -3255,9 +3337,9 @@ void protoSignalComputation2_fx( } /* Compute protos for decorrelation */ - proto_frame_f_fx[i_mult( 2, l )] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; move32(); - proto_frame_f_fx[i_mult( 2, l ) + 1] = Imag_aux_fx; + proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; move32(); @@ -3270,11 +3352,13 @@ void protoSignalComputation2_fx( } stereo_type_detect->q_sum_power = s_min( stereo_type_detect->q_sum_power, q_temp2 ); + move16(); stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp ); + move16(); q_sum_total_ratio = Q15; move16(); - IF( GT_16( stereo_type_detect->interpolator, 0 ) ) + IF( stereo_type_detect->interpolator > 0 ) { stereo_type_detect->interpolator++; IF( EQ_16( stereo_type_detect->interpolator, MASA_STEREO_INTERPOLATION_SLOTS ) ) @@ -3282,6 +3366,7 @@ void protoSignalComputation2_fx( stereo_type_detect->interpolator = 0; move16(); stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; + move32(); } } @@ -3289,47 +3374,57 @@ void protoSignalComputation2_fx( IF( LT_16( q_temp, stereo_type_detect->q_left_bb_power ) ) { stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_temp ) ) ); + move32(); stereo_type_detect->q_left_bb_power = q_temp; move16(); } ELSE { stereo_type_detect->left_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ) ); + move32(); } temp = Mpy_32_32( a_fx, right_bb_power_fx ); IF( LT_16( q_temp, stereo_type_detect->q_right_bb_power ) ) { stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_temp ) ) ); + move32(); stereo_type_detect->q_right_bb_power = q_temp; move16(); } ELSE { stereo_type_detect->right_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ) ); + move32(); } temp = Mpy_32_32( a_fx, total_bb_power_fx ); IF( LT_16( q_temp, stereo_type_detect->q_total_bb_power ) ) { stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_temp ) ) ); + move32(); stereo_type_detect->q_total_bb_power = q_temp; move16(); } ELSE { stereo_type_detect->total_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ) ); + move32(); } IF( LT_16( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ) { lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); + move32(); q_lr_bb_power = stereo_type_detect->q_left_bb_power; + move16(); } ELSE { lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); + move32(); q_lr_bb_power = stereo_type_detect->q_right_bb_power; + move16(); } q_lr_bb_power = sub( q_lr_bb_power, 1 ); /* = (lr_bb_power_fx * 2) */ @@ -3347,46 +3442,54 @@ void protoSignalComputation2_fx( IF( LT_16( q_temp, stereo_type_detect->q_left_hi_power ) ) { stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); + move32(); stereo_type_detect->q_left_hi_power = q_temp; move16(); } ELSE { stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); + move32(); } temp = Mpy_32_32( a_fx, right_hi_power_fx ); IF( LT_16( q_temp, stereo_type_detect->q_right_hi_power ) ) { stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); + move32(); stereo_type_detect->q_right_hi_power = q_temp; move16(); } ELSE { stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); + move32(); } temp = Mpy_32_32( a_fx, total_hi_power_fx ); IF( LT_16( q_temp, stereo_type_detect->q_total_hi_power ) ) { stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); + move32(); stereo_type_detect->q_total_hi_power = q_temp; move16(); } ELSE { stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); + move32(); } IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ) { lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); + move32(); q_lr_hi_power = stereo_type_detect->q_left_hi_power; } ELSE { lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); + move32(); q_lr_hi_power = stereo_type_detect->q_right_hi_power; } q_lr_hi_power = sub( q_lr_hi_power, 1 ); /* = (q_lr_hi_power * 2) */ @@ -3425,7 +3528,6 @@ void protoSignalComputation2_fx( p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - move16(); FOR( l = 0; l < num_freq_bands; l++ ) { @@ -3438,6 +3540,7 @@ void protoSignalComputation2_fx( Imag_aux_fx = L_add( im1, im2 ); reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + move32(); IF( LT_16( q_temp, *q_proto_power_smooth ) ) { @@ -3450,9 +3553,9 @@ void protoSignalComputation2_fx( move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( re1, re2 ); @@ -3472,9 +3575,9 @@ void protoSignalComputation2_fx( move32(); } - proto_frame_f_fx[i_mult( 2, l )] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; move32(); - proto_frame_f_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; move32(); proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; @@ -3489,20 +3592,17 @@ void protoSignalComputation2_fx( } *q_proto_frame_f = add( q_cldfb, min_q_shift ); + move16(); *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift ); + move16(); *q_proto_power_smooth = s_min( *q_proto_power_smooth, q_temp ); + move16(); *q_reference_power = q_temp; move16(); return; } #else -/*------------------------------------------------------------------------- - * protoSignalComputation2() - * - * - *-------------------------------------------------------------------------*/ - void protoSignalComputation2( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -3823,13 +3923,15 @@ void protoSignalComputation2( return; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*------------------------------------------------------------------------- - * protoSignalComputation4_fx() + * protoSignalComputation4() * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void protoSignalComputation4_fx( Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -3892,6 +3994,7 @@ void protoSignalComputation4_fx( } sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 ); + move16(); min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); @@ -3920,6 +4023,7 @@ void protoSignalComputation4_fx( } } *proto_frame_f_q = sub( add( add( min_q_shift, q_cldfb ), Q29 ), 31 ); + move16(); /* calculate the shift possible to up scale the buffer proto_power_smooth_fx*/ min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) ); @@ -3927,6 +4031,7 @@ void protoSignalComputation4_fx( Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift ); + move16(); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); @@ -3936,6 +4041,7 @@ void protoSignalComputation4_fx( Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift ); + move16(); offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; @@ -3979,12 +4085,6 @@ void protoSignalComputation4_fx( return; } #else -/*------------------------------------------------------------------------- - * protoSignalComputation4() - * - * - *-------------------------------------------------------------------------*/ - void protoSignalComputation4( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -4045,6 +4145,7 @@ void protoSignalComputation4( } #endif + /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_diffuse_proto() * @@ -4095,7 +4196,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( smooth_e = sub( 31, h_dirac_output_synthesis_state->proto_power_diff_smooth_q ); proto_e = sub( 31, hDirACRend->proto_frame_dec_f_q ); - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { diff_square_e = add( shl( proto_e, 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); @@ -4106,13 +4207,16 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( FOR( l = 0; l < num_freq_bands_diff; l++ ) { *p_diff_buffer_fx = *( p_proto_diff_fx++ ); + move32(); *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); + move32(); - diff_square = Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ) >> 1; // 2 * proto_e + 1 - diff_square_1 = Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ) >> 1; // 2 * proto_e + 1 + diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2 * proto_e + 1 + diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2 * proto_e + 1 diff_square_sum = L_add( diff_square, diff_square_1 ); diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + move32(); p_power_smooth_fx++; p_diff_buffer_fx += 2; @@ -4120,6 +4224,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( } } diff_e = proto_e; + move16(); } ELSE { @@ -4136,13 +4241,17 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); *p_diff_buffer_fx = 0; + move32(); *p_diff_buffer_1_fx = 0; + move32(); /*LS to HOA*/ FOR( m = 0; m < hDirACRend->num_outputs_diff; m++ ) { *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); + move32(); *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); + move32(); p_hoa_enc_fx += hDirACRend->hOutSetup.nchan_out_woLFE; p_proto_diff_fx += shl( num_freq_bands, 1 ); } @@ -4150,8 +4259,9 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 diff_square_sum = L_add( diff_square, diff_square_1 ); - diff_square_sum = L_shr( diff_square_sum, max_e - diff_square_e ); + diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + move32(); p_power_smooth_fx++; @@ -4162,6 +4272,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( diff_e = add( proto_e, gb ); } h_dirac_output_synthesis_state->proto_power_diff_smooth_q = sub( 31, max_e ); + move16(); Word16 new_diff_e = s_max( diff_e, old_diff_e ); Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); @@ -4173,6 +4284,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( sub( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_len, diffuse_start ), sub( diff_e, new_diff_e ) ); #endif h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q = sub( 31, new_diff_e ); + move16(); return; } @@ -4254,12 +4366,13 @@ void ivas_dirac_dec_compute_diffuse_proto( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * computeDirectionAngles_fx() + * computeDirectionAngles() * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void computeDirectionAngles_fx( Word32 *intensity_real_x_fx, Word32 *intensity_real_y_fx, @@ -4343,23 +4456,30 @@ void computeDirectionAngles_fx( temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); radius = Sqrt32( temp, &exp ); - res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); // Q13 - azimuth[k] = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; + res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */ + res = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ + azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); + IF( res < 0 ) + { + azimuth[k] = negate( azimuth[k] ); + move16(); + } - res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); // Q13 - elevation[k] = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ) / ONE_IN_Q7; // Q0; + res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */ + res = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ + elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); + IF( res < 0 ) + { + elevation[k] = negate( elevation[k] ); + move16(); + } } return; } #else -/*------------------------------------------------------------------------- - * computeDirectionAngles() - * - *------------------------------------------------------------------------*/ - void computeDirectionAngles( float *intensity_real_x, float *intensity_real_y, @@ -4416,48 +4536,79 @@ void ivas_masa_init_stereotype_detection_fx( MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + move32(); stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; + move32(); stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; + move32(); stereo_type_detect->counter = 0; + move16(); stereo_type_detect->interpolator = 0; + move16(); stereo_type_detect->dipole_freq_range[0] = 1; + move16(); stereo_type_detect->dipole_freq_range[1] = 3; + move16(); stereo_type_detect->left_bb_power_fx = 0; /* Broadband estimates */ + move32(); stereo_type_detect->q_left_bb_power = Q31; + move16(); stereo_type_detect->right_bb_power_fx = 0; + move32(); stereo_type_detect->q_right_bb_power = Q31; + move16(); stereo_type_detect->total_bb_power_fx = 0; + move32(); stereo_type_detect->q_total_bb_power = Q31; + move16(); stereo_type_detect->left_hi_power_fx = 0; /* High-frequency estimates */ + move32(); stereo_type_detect->q_left_hi_power = Q31; + move16(); stereo_type_detect->right_hi_power_fx = 0; + move32(); stereo_type_detect->q_right_hi_power = Q31; + move16(); stereo_type_detect->total_hi_power_fx = 0; + move32(); stereo_type_detect->q_total_hi_power = Q31; + move16(); set32_fx( stereo_type_detect->sum_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); set32_fx( stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS ); stereo_type_detect->q_sum_power = Q31; + move16(); stereo_type_detect->q_total_power = Q31; + move16(); stereo_type_detect->subtract_power_y_fx = 0; + move32(); stereo_type_detect->q_subtract_power_y = Q31; + move16(); stereo_type_detect->subtract_power_y_smooth_fx = 0; + move32(); stereo_type_detect->q_subtract_power_y_smooth = Q31; + move16(); stereo_type_detect->target_power_y_smooth_fx = 0; + move32(); #ifdef MSAN_FIX stereo_type_detect->q_target_power_y_smooth = 31; + move16(); #endif stereo_type_detect->lr_total_bb_ratio_db_fx = 0; + move32(); stereo_type_detect->lr_total_hi_ratio_db_fx = 0; + move32(); stereo_type_detect->min_sum_total_ratio_db_fx = 0; + move32(); stereo_type_detect->subtract_target_ratio_db_fx = 0; + move32(); return; } @@ -4500,13 +4651,13 @@ void ivas_masa_init_stereotype_detection( #endif -#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_masa_stereotype_detection_fx() + * ivas_masa_stereotype_detection() * * Detect the type of the transport audio signals *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_masa_stereotype_detection_fx( MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { @@ -4563,7 +4714,7 @@ void ivas_masa_stereotype_detection_fx( /* Determine if the determined features match the downmix type, according to a metric */ change_to_downmix_selection = 0; move16(); - IF( GT_32( subtract_target_ratio_db_fx, 0 ) ) + IF( subtract_target_ratio_db_fx > 0 ) { /* subtract_temp = subtract_target_ratio_db / 3.0f; */ subtract_temp_fx = Mpy_32_32( subtract_target_ratio_db_fx, 715827883 /* 1 / 3.0f in Q31 */ ); /* Q21 */ @@ -4613,35 +4764,29 @@ void ivas_masa_stereotype_detection_fx( IF( EQ_16( change_to_spaced_selection, 1 ) ) { stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; - move16(); + move32(); } ELSE IF( EQ_16( change_to_downmix_selection, 1 ) ) { stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; - move16(); + move32(); } } - IF( EQ_16( stereo_type_detect->interpolator, 0 ) ) + IF( stereo_type_detect->interpolator == 0 ) { IF( NE_16( stereo_type_detect->current_stereo_type, stereo_type_detect->masa_stereo_type ) ) { stereo_type_detect->interpolator = 1; move16(); stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; - move16(); + move32(); } } return; } #else -/*------------------------------------------------------------------------- - * ivas_masa_stereotype_detection() - * - * Detect the type of the transport audio signals - *------------------------------------------------------------------------*/ - void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { @@ -4735,13 +4880,14 @@ void ivas_masa_stereotype_detection( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- * computeIntensityVector_dec() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void computeIntensityVector_dec_fx( Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -4761,6 +4907,7 @@ void computeIntensityVector_dec_fx( Word16 min_q_shift; min_q_shift = Q31; + move32(); /* calculate the max possible shift for the buffers Cldfb_RealBuffer_fx and Cldfb_ImagBuffer_fx*/ FOR( i = 0; i < 4; i++ ) { @@ -4793,16 +4940,11 @@ void computeIntensityVector_dec_fx( } *q_intensity_real = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + move16(); return; } #else -/*------------------------------------------------------------------------- - * computeIntensityVector_dec() - * - * - *------------------------------------------------------------------------*/ - void computeIntensityVector_dec( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -4831,13 +4973,14 @@ void computeIntensityVector_dec( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * ivas_lfe_synth_with_cldfb_fx() + * ivas_lfe_synth_with_cldfb() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_cldfb_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -4870,12 +5013,12 @@ void ivas_lfe_synth_with_cldfb_fx( FOR( i = 0; i < nchan_transport; i++ ) { - IF( RealBuffer_fx[i][0][0] ) + if ( RealBuffer_fx[i][0][0] ) { exp = norm_l( RealBuffer_fx[i][0][0] ); } min_q_shift = s_min( min_q_shift, exp ); - IF( ImagBuffer_fx[i][0][0] ) + if ( ImagBuffer_fx[i][0][0] ) { exp = norm_l( ImagBuffer_fx[i][0][0] ); } @@ -4913,21 +5056,33 @@ void ivas_lfe_synth_with_cldfb_fx( targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 ); hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + move32(); hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + move32(); hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + move32(); hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + move32(); hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); + move32(); hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q ); + move16(); hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); + move32(); hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q ); + move16(); hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); + move32(); hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q ); + move16(); hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); + move32(); hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q ); + move16(); temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) ); @@ -4979,12 +5134,6 @@ void ivas_lfe_synth_with_cldfb_fx( return; } #else -/*------------------------------------------------------------------------- - * ivas_lfe_synth_with_cldfb() - * - * - *------------------------------------------------------------------------*/ - void ivas_lfe_synth_with_cldfb( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -5046,13 +5195,14 @@ void ivas_lfe_synth_with_cldfb( } #endif -#ifdef IVAS_FLOAT_FIXED + /*------------------------------------------------------------------------- - * rotateAziEle_DirAC_fx() + * rotateAziEle_DirAC() * * Apply rotation to DirAC DOAs *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void rotateAziEle_DirAC_fx( Word16 *azi, /* i/o: array of azimuth values */ Word16 *ele, /* i/o: array of elevation values */ @@ -5078,8 +5228,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( ele[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - w_fx = -ptr_cos[sub( abs_s( ele[b] ), 180 )]; // Q31 - move32(); + w_fx = L_negate( ptr_cos[sub( abs_s( ele[b] ), 180 )] ); // Q31 } ELSE { @@ -5090,8 +5239,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( azi[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - tmp = -ptr_cos[sub( abs_s( azi[b] ), 180 )]; // Q31 - move32(); + tmp = L_negate( ptr_cos[sub( abs_s( azi[b] ), 180 )] ); // Q31 } ELSE { @@ -5105,7 +5253,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( azi[b], 180 ) ) { // sin(180 + x) = -sin(x) - tmp = -ptr_sin[sub( azi[b], 180 )]; // Q31 + tmp = L_negate( ptr_sin[sub( azi[b], 180 )] ); // Q31 move32(); } ELSE IF( LT_16( azi[b], -180 ) ) @@ -5124,7 +5272,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( ele[b], 180 ) ) { // sin(180 + x) = -sin(x) - dv_2_fx = -ptr_sin[sub( ele[b], 180 )]; // Q31 + dv_2_fx = L_negate( ptr_sin[sub( ele[b], 180 )] ); // Q31 move32(); } ELSE IF( LT_16( ele[b], -180 ) ) @@ -5161,12 +5309,6 @@ void rotateAziEle_DirAC_fx( return; } #else -/*------------------------------------------------------------------------- - * rotateAziEle_DirAC() - * - * Apply rotation to DirAC DOAs - *------------------------------------------------------------------------*/ - void rotateAziEle_DirAC( int16_t *azi, /* i/o: array of azimuth values */ int16_t *ele, /* i/o: array of elevation values */ @@ -5205,6 +5347,8 @@ void rotateAziEle_DirAC( return; } #endif + + /* A reduced rewrite of the corresponding decoder side function */ #ifndef IVAS_FLOAT_FIXED static void ivas_masa_ext_dirac_render_sf( @@ -5611,6 +5755,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( Word16 Q_surCohRatio, surCohRatio_exp[CLDFB_NO_CHANNELS_MAX]; Word32 dirEne_fx; Word32 surCohEner_fx; + move16(); FOR( Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++ ) { @@ -5641,7 +5786,6 @@ static void ivas_masa_ext_dirac_render_sf_fx( onset_filter_fx = DirAC_mem.onset_filter_fx; reference_power_fix = DirAC_mem.reference_power_fx; reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; - // DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ move16(); @@ -5706,15 +5850,19 @@ static void ivas_masa_ext_dirac_render_sf_fx( move32(); surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q.29 hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); + move32(); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); + move32(); surCohRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &surCohRatio_exp[i] ) ); + move32(); temp_exp = s_max( temp_exp, surCohRatio_exp[i] ); } FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); + move32(); } Q_surCohRatio = sub( 31, temp_exp ); } @@ -5734,13 +5882,15 @@ static void ivas_masa_ext_dirac_render_sf_fx( &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + move16(); IF( coherence_flag ) { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); - move16(); + move32(); } } ELSE @@ -5839,9 +5989,10 @@ static void ivas_masa_ext_dirac_render_sf_fx( DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } - temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); + move16(); } ELSE { @@ -5875,9 +6026,10 @@ static void ivas_masa_ext_dirac_render_sf_fx( DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } - temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); + move16(); BREAK; case 1: @@ -5909,9 +6061,10 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); } - temp_proto_frame_q = getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ) - 2; + temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 ); Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); + move16(); BREAK; default: @@ -6005,10 +6158,6 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); - /*Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); - Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth);*/ - ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix, DirAC_mem.reference_power_q, p_onset_filter_fx, @@ -6031,12 +6180,15 @@ static void ivas_masa_ext_dirac_render_sf_fx( { Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 ); + move16(); DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + move16(); v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0 ); } } /*Rescaling proto_direct_buffer_f*/ Word16 temp = MAX_16; + move16(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { @@ -6129,20 +6281,15 @@ static void ivas_masa_ext_dirac_render_sf_fx( #if 1 IF( hDirACRend->proto_signal_decorr_on ) { - // hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; - Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len ); Word16 new_proto_direct_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q ); hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q ); + move16(); hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q ); - - /*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(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q)); - scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q)); - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q); - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q);*/ + move16(); } #endif /*Buffer Scaling*/ @@ -6159,15 +6306,17 @@ static void ivas_masa_ext_dirac_render_sf_fx( q_cldfb = 11; move16(); - Word16 reference_power_temp_q = getScaleFactor32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len ); scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); + move16(); DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); + move16(); Word16 q_cy_auto_diff_smooth = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len ); Scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth ); h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth ); + move16(); Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; @@ -6183,29 +6332,39 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( hDirACRend->masa_stereo_type_detect ) { hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + move32(); hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + move16(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + move16(); } Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); + move16(); Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); + move16(); Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32( 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, proto_power_diff_smooth_prev_temp_q ); 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, proto_power_diff_smooth_prev_temp_q ); + move16(); Word16 proto_power_diff_smooth_temp_q = getScaleFactor32( 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, proto_power_diff_smooth_temp_q ); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q ); + move16(); 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, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); + move16(); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ); + move16(); Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1 ); @@ -6215,8 +6374,11 @@ static void ivas_masa_ext_dirac_render_sf_fx( Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), DirAC_mem.reference_power_q ) ); hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); + move16(); DirAC_mem.reference_power_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); + move16(); DirAC_mem.reference_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); + move16(); ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, @@ -6230,7 +6392,9 @@ static void ivas_masa_ext_dirac_render_sf_fx( 0, &q_cldfb ); hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q; + move16(); hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = DirAC_mem.reference_power_smooth_q; + move16(); IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ) { Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); @@ -6282,12 +6446,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ FOR( ch = 0; ch < outchannels; ch++ ) { - IF( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) + test(); + IF( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) { /* No LFE for MASA rendering */ - set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + set32_fx( &( output_f_fx[ch][imult1616( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); - IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) + if ( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { idx_lfe++; } @@ -6307,8 +6472,10 @@ static void ivas_masa_ext_dirac_render_sf_fx( } hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = sub( q_cldfb, 1 ); + move16(); } hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered ); + move16(); hSpatParamRendCom->subframes_rendered++; pop_wmops(); @@ -6316,6 +6483,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( return; } #endif + + #ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ @@ -6375,6 +6544,7 @@ void ivas_masa_ext_dirac_render_fx( } hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; + move16(); FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { @@ -6386,7 +6556,8 @@ void ivas_masa_ext_dirac_render_fx( output_f_local[n] += n_samples_sf; } - hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } return; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 3632adde4..fb6abd941 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -41,6 +41,10 @@ #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif + /*-----------------------------------------------------------------------* * Local constants @@ -156,7 +160,7 @@ static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); static void sph2cart( const float azi, const float ele, float *pos ); #else static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); -static Word32 efap_lmodl( const Word32 x, const Word32 y ); +static Word32 efap_32mod32( const Word32 x, const Word32 y ); static Word16 get_poly_num_fx( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); static Word16 in_poly_fx( const Word32 P[2], const EFAP_POLYSET poly ); static Word16 in_tri_fx( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); @@ -176,8 +180,8 @@ static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); ivas_error efap_init_data_fx( EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) (Q22) */ - const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) (Q22) */ + const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) Q22 */ const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ) @@ -187,6 +191,7 @@ ivas_error efap_init_data_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /* Basic init checks */ test(); @@ -240,8 +245,8 @@ ivas_error efap_init_data_fx( move16(); /* Loudspeaker configuration */ - mvl2l( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); - mvl2l( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); + Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); + Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); /* Initialization of the vertex */ vertex_init_fx( efap->aziSpk, efap->eleSpk, &efap->vtxData ); @@ -353,8 +358,8 @@ ivas_error efap_init_data( } #endif -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * efap_determine_gains_fx() * @@ -363,14 +368,11 @@ ivas_error efap_init_data( *-------------------------------------------------------------------------*/ void efap_determine_gains_fx( - EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ - Word32 *gains, /* o : gain vector for speaker nodes for given direction */ - const Word32 azi_deg, - /* i : azimuth in degrees for panning direction (positive left) */ // Q22 - const Word32 ele_deg, - /* i : elevation in degrees for panning direction (positive up) */ // Q22 - const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ - + EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + Word32 *gains, /* o : gain vector for speaker nodes for given direction Q30 */ + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ) { Word16 i, j; @@ -387,20 +389,21 @@ void efap_determine_gains_fx( /* Panning */ efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); - IF( EQ_16( efap_mode, EFAP_MODE_EFAP ) ) + IF( efap_mode == EFAP_MODE_EFAP ) { normBuffer = 0; - move16(); + move32(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { hEFAPdata->bufferShort_fx[j] = 0; - move16(); + move32(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { - hEFAPdata->bufferShort_fx[j] = L_add_sat( hEFAPdata->bufferShort_fx[j], L_shr( Mpy_32_32( hEFAPdata->bufferLong_fx[i], hEFAPdata->dmTranspose_fx[i][j] ), Q1 ) ); // Q30 + hEFAPdata->bufferShort_fx[j] = L_add_sat( hEFAPdata->bufferShort_fx[j], L_shr( Mpy_32_32( hEFAPdata->bufferLong_fx[i], hEFAPdata->dmTranspose_fx[i][j] ), Q1 ) ); /* Q30 */ + move32(); } - normBuffer = L_add_sat( normBuffer, Mpy_32_32( hEFAPdata->bufferShort_fx[j], hEFAPdata->bufferShort_fx[j] ) ); // Q29 + normBuffer = L_add_sat( normBuffer, Mpy_32_32( hEFAPdata->bufferShort_fx[j], hEFAPdata->bufferShort_fx[j] ) ); /* Q29 */ } Word16 exp = 2; move16(); @@ -409,43 +412,47 @@ void efap_determine_gains_fx( FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); - hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); // Q30 + move32(); + hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); /* Q30 */ + move32(); } } ELSE { normBuffer = 0; - move16(); + move32(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { hEFAPdata->bufferShort_fx[j] = 0; - move16(); + move32(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { - hEFAPdata->bufferShort_fx[j] = L_add_sat( hEFAPdata->bufferShort_fx[j], L_shr( Mpy_32_32( hEFAPdata->bufferLong_fx[i], hEFAPdata->dmTranspose_fx[i][j] ), Q1 ) ); // Q30 + hEFAPdata->bufferShort_fx[j] = L_add_sat( hEFAPdata->bufferShort_fx[j], L_shr( Mpy_32_32( hEFAPdata->bufferLong_fx[i], hEFAPdata->dmTranspose_fx[i][j] ), Q1 ) ); /* Q30 */ + move32(); } - normBuffer = L_add_sat( normBuffer, L_shr( hEFAPdata->bufferShort_fx[j], Q1 ) ); // Q29 + normBuffer = L_add_sat( normBuffer, L_shr( hEFAPdata->bufferShort_fx[j], Q1 ) ); /* Q29 */ } Word16 exp = 2; move16(); - normBuffer = Inv16( (Word16) L_shr( normBuffer, Q16 ), &exp ); + normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { Word16 exp_temp = add( exp, 1 ); hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); - hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); // Q30 + move32(); + hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); /* Q30 */ + move32(); } } /* Copy gains to output */ - mvl2l( hEFAPdata->bufferShort_fx, gains, hEFAPdata->numSpk ); + Copy32( hEFAPdata->bufferShort_fx, gains, hEFAPdata->numSpk ); /* Q30 */ return; } #else - /*-------------------------------------------------------------------------* * efap_determine_gains() * @@ -521,6 +528,8 @@ void efap_determine_gains( return; } #endif + + /*-------------------------------------------------------------------------* * efap_free_data() * @@ -528,7 +537,7 @@ void efap_determine_gains( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void efap_free_data( +void efap_free_data_fx( EFAP_HANDLE *hEFAPdata /* i/o: EFAP handle to be freed */ ) { @@ -542,6 +551,7 @@ void efap_free_data( } dim1 = ( *hEFAPdata )->numTot; + move16(); /* instance buffer members */ free( ( *hEFAPdata )->aziSpk ); @@ -638,6 +648,7 @@ void efap_free_data( * Main function for the Efap initialization whose purpose is to initialize * the different polygons and to add the ghost speakers *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static ivas_error poly_init_fx( EFAP *efap, /* i/o: A pointer to a handle to efap instance */ @@ -652,6 +663,7 @@ static ivas_error poly_init_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /* Safety Check */ assert( efap != NULL && "EFAP: efap == NULL" ); @@ -670,8 +682,9 @@ static ivas_error poly_init_fx( /* set isNaN for ghost loudspeakers */ FOR( n = 0; n < efap->vtxData.numVtx; ++n ) { - IF( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || - LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) + test(); + if ( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || + LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) { efap->vtxData.vertexArray[n].isNaN = 1; move16(); @@ -694,9 +707,9 @@ static ivas_error poly_init_fx( { efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; move16(); - efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; + efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; /* Q22 */ move32(); - efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; + efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; /* Q22 */ move32(); efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; move16(); @@ -716,19 +729,29 @@ static ivas_error poly_init_fx( assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ - efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_lmodl( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); - efap->polyData.polysetArray[m + 2].polyAzi[j] = L_sub( efap->polyData.polysetArray[m + 1].polyAzi[j], Q22_360_DEG ); + efap->polyData.polysetArray[add( m, 1 )].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); /* Q22 */ + move32(); + efap->polyData.polysetArray[add( m, 2 )].polyAzi[j] = L_sub( efap->polyData.polysetArray[add( m, 1 )].polyAzi[j], Q22_360_DEG ); /* Q22 */ + move32(); /* Copy the rest of the fields */ - efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; - efap->polyData.polysetArray[m + 1].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; - efap->polyData.polysetArray[m + 1].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; - efap->polyData.polysetArray[m + 1].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[add( m, 1 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + move16(); + efap->polyData.polysetArray[add( m, 1 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + move32(); + efap->polyData.polysetArray[add( m, 1 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + move16(); + efap->polyData.polysetArray[add( m, 1 )].numChan = lengthTri2PolySorted[n]; + move16(); - efap->polyData.polysetArray[m + 2].chan[j] = efap->polyData.polysetArray[m].chan[j]; - efap->polyData.polysetArray[m + 2].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; - efap->polyData.polysetArray[m + 2].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; - efap->polyData.polysetArray[m + 2].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[add( m, 2 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + move16(); + efap->polyData.polysetArray[add( m, 2 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + move32(); + efap->polyData.polysetArray[add( m, 2 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + move16(); + efap->polyData.polysetArray[add( m, 2 )].numChan = lengthTri2PolySorted[n]; + move16(); } finalLength = add( finalLength, 2 ); } @@ -842,32 +865,34 @@ static ivas_error poly_init( } #endif + /*-------------------------------------------------------------------------* * sphere_triangulation() * * *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static ivas_error sphere_triangulation_fx( - const Word16 numSpk, /* i : Number of speakers */ - EFAP_VERTEX_DATA *vtxData, /* i/o: Vertex data structure */ - EFAP_POLYSET_DATA *polyData, /* o : Polygon data structure */ - Word32 ***dmTranspose_fx, /* o : Transpose of the downmix matrix */ - Word16 *numTot, /* o : Number of speakers (real + ghost) */ - const int16_t efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ + const Word16 numSpk, /* i : Number of speakers */ + EFAP_VERTEX_DATA *vtxData, /* i/o: Vertex data structure */ + EFAP_POLYSET_DATA *polyData, /* o : Polygon data structure */ + Word32 ***dmTranspose_fx, /* o : Transpose of the downmix matrix Q31 */ + Word16 *numTot, /* o : Number of speakers (real + ghost) */ + const Word16 efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ ) { - int16_t i; + Word16 i; void **p_dmTranspose; - int16_t vtxInHull[EFAP_MAX_SIZE_TMP_BUFF]; + Word16 vtxInHull[EFAP_MAX_SIZE_TMP_BUFF]; - set_s( vtxInHull, 0, EFAP_MAX_SIZE_TMP_BUFF ); + set16_fx( vtxInHull, 0, EFAP_MAX_SIZE_TMP_BUFF ); /* Add Imaginary Speakers */ add_ghost_speakers_fx( vtxData->vertexArray, &vtxData->numVtx, efip_flag ); /* Sort the vertices according to their index */ - IF( ( vtxData->vtxOrder = (int16_t *) malloc( vtxData->numVtx * sizeof( int16_t ) ) ) == NULL ) + IF( ( vtxData->vtxOrder = (Word16 *) malloc( vtxData->numVtx * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP Vertex Order\n" ) ); } @@ -893,6 +918,7 @@ static ivas_error sphere_triangulation_fx( /* Store the value of numVtx to be used for freeing later (numVtx will change after remap_ghosts() ) */ *numTot = vtxData->numVtx; + move16(); FOR( i = 0; i < vtxData->numVtx; i++ ){ IF( ( p_dmTranspose[i] = malloc( numSpk * sizeof( Word32 ) ) ) == NULL ){ @@ -969,13 +995,14 @@ static ivas_error sphere_triangulation( } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * initial_polyeder() * * *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void initial_polyeder( EFAP_VERTEX_DATA *vtxData, /* i : Vertex data structure */ EFAP_LS_TRIANGLE *triArray, /* o : Triangle array structure */ @@ -1096,12 +1123,6 @@ static void initial_polyeder( return; } #else -/*-------------------------------------------------------------------------* - * initial_polyeder() - * - * - *-------------------------------------------------------------------------*/ - static void initial_polyeder_fx( EFAP_VERTEX_DATA *vtxData, /* i : Vertex data structure */ EFAP_LS_TRIANGLE *triArray, /* o : Triangle array structure */ @@ -1122,32 +1143,34 @@ static void initial_polyeder_fx( assert( triArray != NULL && "EFAP: triArray==NULL" ); /* initialize variables */ - set_s( tmpSurface, -1, 3 ); - set_l( centroid, 0, 3 ); - set_l( tmp1, 0, 3 ); - set_l( tmp2, 0, 3 ); - set_l( tmp3, 0, 3 ); - set_l( tmpCross, 0, 3 ); + set16_fx( tmpSurface, -1, 3 ); + set32_fx( centroid, 0, 3 ); + set32_fx( tmp1, 0, 3 ); + set32_fx( tmp2, 0, 3 ); + set32_fx( tmp3, 0, 3 ); + set32_fx( tmpCross, 0, 3 ); numVtx = vtxData->numVtx; + move16(); /* seed vertices */ FOR( i = 0; i < 4; i++ ) { tetrahedron[i] = i; + move16(); } /* 1. attempt to create an edge with nonzero length */ WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi, vtxData->vertexArray[tetrahedron[1]].azi ) && EQ_32( vtxData->vertexArray[tetrahedron[0]].ele, vtxData->vertexArray[tetrahedron[1]].ele ) ) { - tetrahedron[1]++; + tetrahedron[1] = add( tetrahedron[1], 1 ); assert( tetrahedron[1] < numVtx && "EFAP: convex hull construction failed, vertices are coincident!" ); } /* 2. attempt to create a triangle with nonzero area */ tmp = 0; - move16(); + move32(); v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); WHILE( LT_16( tetrahedron[2], numVtx ) ) { @@ -1159,23 +1182,26 @@ static void initial_polyeder_fx( } IF( GT_32( L_abs( tmp ), Mpy_32_32( POLY_THRESH_Q29, POLY_THRESH_Q29 ) ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ { - break; + BREAK; } tetrahedron[2] = add( tetrahedron[2], 1 ); + move16(); } assert( tetrahedron[2] < numVtx && "EFAP: convex hull construction failed, vertices are colinear!" ); /* 3. attempt to create a tetrahedron with nonzero volume */ tmp = 0; + move32(); WHILE( LT_16( tetrahedron[3], numVtx ) ) { v_sub_fixed( vtxData->vertexArray[tetrahedron[3]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp3, 3, 1 ); // tmp3 Q30 tmp = dotp_fixed( tmp3, tmpCross, 3 ); // tmp Q28 IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 ) ) { - break; + BREAK; } tetrahedron[3] = add( tetrahedron[3], 1 ); + move16(); } assert( tetrahedron[3] < numVtx && "EFAP: convex hull construction failed, vertices are coplanar!" ); @@ -1183,9 +1209,13 @@ static void initial_polyeder_fx( FOR( i = 0; i < 4; i++ ) { vtxInHull[tetrahedron[i]] = 1; /* set vertex as added to hull*/ + move16(); centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); + move32(); centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); + move32(); centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); + move32(); } /* Executed below float operation centroid[0] /= 4; @@ -1195,36 +1225,50 @@ static void initial_polyeder_fx( /* 5. create and orient planes */ tmpSurface[0] = tetrahedron[0]; + move16(); tmpSurface[1] = tetrahedron[1]; + move16(); tmpSurface[2] = tetrahedron[2]; + move16(); flip_plane_fx( vtxData->vertexArray, tmpSurface, centroid ); - mvs2s( tmpSurface, triArray[0].LS, 3 ); + Copy( tmpSurface, triArray[0].LS, 3 ); tmpSurface[0] = tetrahedron[0]; + move16(); tmpSurface[1] = tetrahedron[1]; + move16(); tmpSurface[2] = tetrahedron[3]; + move16(); flip_plane_fx( vtxData->vertexArray, tmpSurface, centroid ); - mvs2s( tmpSurface, triArray[1].LS, 3 ); + Copy( tmpSurface, triArray[1].LS, 3 ); tmpSurface[0] = tetrahedron[0]; + move16(); tmpSurface[1] = tetrahedron[2]; + move16(); tmpSurface[2] = tetrahedron[3]; + move16(); flip_plane_fx( vtxData->vertexArray, tmpSurface, centroid ); - mvs2s( tmpSurface, triArray[2].LS, 3 ); + Copy( tmpSurface, triArray[2].LS, 3 ); tmpSurface[0] = tetrahedron[1]; + move16(); tmpSurface[1] = tetrahedron[2]; + move16(); tmpSurface[2] = tetrahedron[3]; + move16(); flip_plane_fx( vtxData->vertexArray, tmpSurface, centroid ); - mvs2s( tmpSurface, triArray[3].LS, 3 ); + Copy( tmpSurface, triArray[3].LS, 3 ); /* set numTri */ *numTri = 4; + move16(); return; } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * add_ghost_speakers() @@ -1417,7 +1461,9 @@ static void add_ghost_speakers_fx( EFAP_VTX_DMX_TYPE vtxDmxType; vtxDmxType = EFAP_DMX_INTENSITY; + move32(); numVertex = *numVtx; + move16(); maxAngle = 13421773; move32(); //(1.f / 160.0f) in Q31 @@ -1442,15 +1488,17 @@ static void add_ghost_speakers_fx( IF( GT_32( tmpEle, Q22_45_DEG ) ) { vtxDmxType = EFAP_DMX_NONE; + move32(); } ELSE { vtxDmxType = EFAP_DMX_AMPLITUDE; + move32(); } } - add_vertex_fx( vertexArray, 0, Q22_90_DEG, numVertex + a, vtxDmxType ); - ++lengthVertGhst; - ++a; + add_vertex_fx( vertexArray, 0, Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + lengthVertGhst = add( lengthVertGhst, 1 ); + a = add( a, 1 ); } /* ADD VOH IF NECESSERAY (i.e. if the elevation of the lowest LS is > -90 deg) */ @@ -1462,17 +1510,20 @@ static void add_ghost_speakers_fx( IF( LT_32( tmpEle, -Q22_45_DEG ) ) { vtxDmxType = EFAP_DMX_NONE; + move32(); } ELSE { vtxDmxType = EFAP_DMX_AMPLITUDE; + move32(); } } - add_vertex_fx( vertexArray, 0, -Q22_90_DEG, numVertex + a, vtxDmxType ); + add_vertex_fx( vertexArray, 0, -Q22_90_DEG, add( numVertex, a ), vtxDmxType ); - ++lengthVertGhst; - ++a; + lengthVertGhst = add( lengthVertGhst, 1 ); + ; + a = add( a, 1 ); } /* LIST ALL SURROUNDING loudspeakers */ @@ -1484,7 +1535,8 @@ static void add_ghost_speakers_fx( IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG ) ) { tmpAzi[k] = vertexArray[i].azi; - ++k; + move32(); + k = add( k, 1 ); } } @@ -1514,20 +1566,22 @@ static void add_ghost_speakers_fx( FOR( i = 0; i < k - 1; ++i ) { tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); + move32(); sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); + move32(); - IF( GT_32( sectors[i], Q22_1 ) ) + if ( GT_32( sectors[i], Q22_1 ) ) { - ++lengthHorGhst; + lengthHorGhst = add( lengthHorGhst, 1 ); } } - tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[k - 1] ); + tmpAngleDiff[sub( k, 1 )] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[sub( k, 1 )] ); - sectors[k - 1] = ceil_fixed( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); + sectors[sub( k, 1 )] = ceil_fixed( Mpy_32_32( tmpAngleDiff[sub( k, 1 )], maxAngle ), Q22 ); - IF( GT_32( sectors[k - 1], Q22_1 ) ) + if ( GT_32( sectors[sub( k, 1 )], Q22_1 ) ) { - ++lengthHorGhst; + lengthHorGhst = add( lengthHorGhst, 1 ); } /* Adding new virtual speakers */ @@ -1542,23 +1596,25 @@ static void add_ghost_speakers_fx( { newAzi = L_add( tmpAzi[i], L_shl( ( j + 1 ) * newDiff, Q22 ) ); - add_vertex_fx( vertexArray, newAzi, 0, numVertex + a, EFAP_DMX_INTENSITY ); - ++a; + add_vertex_fx( vertexArray, newAzi, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + a = add( a, 1 ); - IF( GT_16( j, 0 ) ) + if ( j > 0 ) { - ++lengthHorGhst; + lengthHorGhst = add( lengthHorGhst, 1 ); } } } } } *numVtx = add( add( numVertex, lengthHorGhst ), lengthVertGhst ); + move16(); return; } #endif + /*-------------------------------------------------------------------------* * sort_vertices() * @@ -1579,6 +1635,7 @@ static void sort_vertices_fx( FOR( i = 0; i < *numVtx; ++i ) { tmpIdx[i] = vertexArray[i].idx; + move16(); } /* Sorting indexes */ @@ -1608,6 +1665,8 @@ static void sort_vertices( return; } #endif + + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * add_vertex_to_convex_hull() @@ -1729,6 +1788,8 @@ static void add_vertex_to_convex_hull_fx( move32(); // -1e-6f in Q28 Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; + Word16 tmp16, tmp_e; + Word32 tmp32; /* If the vertex is already part of the hull, nothing must be done */ IF( vtxInHull[vtxIdx] ) @@ -1746,19 +1807,30 @@ static void add_vertex_to_convex_hull_fx( { numHullVtx = L_add( numHullVtx, 1 ); centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); + move32(); centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); + move32(); centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); + move32(); } } - // Multiplying with 1 / numHullVtx; + /* numHullVtx = 1.0f / numHullVtx; */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); + tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ - centroid[0] /= numHullVtx; - centroid[1] /= numHullVtx; - centroid[2] /= numHullVtx; + centroid[0] = Mpy_32_32( centroid[0], tmp32 ); + move32(); + centroid[1] = Mpy_32_32( centroid[1], tmp32 ); + move32(); + centroid[2] = Mpy_32_32( centroid[1], tmp32 ); + move32(); centroid[0] = L_shl( centroid[0], 4 ); + move32(); centroid[1] = L_shl( centroid[1], 4 ); + move32(); centroid[2] = L_shl( centroid[2], 4 ); + move32(); /* Processing */ k = 0; @@ -1773,12 +1845,12 @@ static void add_vertex_to_convex_hull_fx( { visible[k] = i; move16(); - ++k; + k = add( k, 1 ); } ELSE { - mvs2s( triArray[i].LS, triArrayNew[l].LS, 3 ); - ++l; + Copy( triArray[i].LS, triArrayNew[l].LS, 3 ); + l = add( l, 1 ); } } @@ -1795,16 +1867,17 @@ static void add_vertex_to_convex_hull_fx( flip_plane_fx( vtxData->vertexArray, surface, centroid ); - mvs2s( surface, triArrayNew[l].LS, 3 ); - ++l; + Copy( surface, triArrayNew[l].LS, 3 ); + l = add( l, 1 ); } /* Outputs */ FOR( i = 0; i < l; i++ ) { - mvs2s( triArrayNew[i].LS, triArray[i].LS, 3 ); + Copy( triArrayNew[i].LS, triArray[i].LS, 3 ); } *szTri = l; + move16(); /* Flag the vertex as added to the hull */ vtxInHull[vtxIdx] = 1; @@ -1813,11 +1886,13 @@ static void add_vertex_to_convex_hull_fx( } #endif + /*-------------------------------------------------------------------------* * visible_edges() * * *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void visible_edges_fx( const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ @@ -1849,7 +1924,7 @@ static void visible_edges_fx( move16(); FOR( j = 1; j < 3; ++j ) { - IF( tmpMax[i] < triArray[visible[i]].LS[j] ) + if ( LT_16( tmpMax[i], triArray[visible[i]].LS[j] ) ) { tmpMax[i] = triArray[visible[i]].LS[j]; move16(); @@ -1871,9 +1946,13 @@ static void visible_edges_fx( FOR( j = 0; j < 3; ++j ) { a = tmpSurface[j]; + move16(); b = tmpSurface[j + 1]; + move16(); counter[a][b] = add( counter[a][b], 1 ); + move16(); counterTranspose[b][a] = counter[a][b]; + move16(); } } @@ -1882,21 +1961,23 @@ static void visible_edges_fx( FOR( j = 0; j < maxVertex + 1; ++j ) { counter[i][j] = add( counterTranspose[i][j], counterTranspose[j][i] ); + move16(); } } /* Finding the edges */ k = 0; + move16(); FOR( a = 0; a < maxVertex; ++a ) { FOR( b = a + 1; b < maxVertex + 1; ++b ) { - IF( counter[a][b] == 1 ) + IF( EQ_16( counter[a][b], 1 ) ) { edges[k] = a; move16(); - edges[k + 1] = b; + edges[add( k, 1 )] = b; move16(); k = add( k, 2 ); } @@ -1993,6 +2074,8 @@ static void visible_edges( return; } #endif + + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * flip_plane() @@ -2046,25 +2129,29 @@ static void flip_plane_fx( vtxArray[surface[2]].pos, centroid ); - IF( GT_32( dist, 0 ) ) + IF( dist > 0 ) { /*efap_flipLeftRight( surface, 3 );*/ tmp = surface[0]; + move16(); surface[0] = surface[2]; + move16(); surface[2] = tmp; + move16(); } return; } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * remap_ghosts() * * *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void remap_ghosts( EFAP_VERTEX *vtxArray, /* i/o: Vertex array */ EFAP_LS_TRIANGLE *triArray, /* i/o: Triangle array */ @@ -2209,19 +2296,13 @@ static void remap_ghosts( return; } #else -/*-------------------------------------------------------------------------* - * remap_ghosts_fx() - * - * - *-------------------------------------------------------------------------*/ - static void remap_ghosts_fx( - EFAP_VERTEX *vtxArray, /* i/o: Vertex array */ - EFAP_LS_TRIANGLE *triArray, /* i/o: Triangle array */ - Word16 numSpk, /* i : Number of speakers */ - Word16 *numVertex, /* i/o: Size of vertex array */ - Word16 numTri, /* i : Size of triangle array */ - Word32 **downmixMatrixTranspose /* o : Transpose of downmix matrix */ + EFAP_VERTEX *vtxArray, /* i/o: Vertex array */ + EFAP_LS_TRIANGLE *triArray, /* i/o: Triangle array */ + Word16 numSpk, /* i : Number of speakers */ + Word16 *numVertex, /* i/o: Size of vertex array */ + Word16 numTri, /* i : Size of triangle array */ + Word32 **downmixMatrixTranspose /* o : Transpose of downmix matrix Q31 */ ) { Word16 numGhst = 0; @@ -2235,10 +2316,11 @@ static void remap_ghosts_fx( Word16 neighbours[EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpVec[EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpVec2[EFAP_MAX_SIZE_TMP_BUFF]; - Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; - Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; + Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ + Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpDist; const Word32 thresh = 214748; + Word16 tmp16, tmp_e; move32(); // 1e-4f in Q31 set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2248,7 +2330,7 @@ static void remap_ghosts_fx( FOR( g = numVtx - 1; g > numSpk - 1; --g ) { /* find(triangle_mat == ghost, 1, 'first') */ - IF( EQ_16( find_int_in_tri_fx( triArray, g, numTri, posFound ), 0 ) ) + IF( find_int_in_tri_fx( triArray, g, numTri, posFound ) == 0 ) { remove_vertex_fx( vtxArray, g, numVtx ); --numVtx; @@ -2259,13 +2341,14 @@ static void remap_ghosts_fx( IF( GT_16( triArray[i].LS[j], g ) ) { triArray[i].LS[j] = sub( g, 1 ); + move16(); } } } } ELSE { - ++numGhst; + numGhst = add( numGhst, 1 ); } } @@ -2278,8 +2361,10 @@ static void remap_ghosts_fx( set32_fx( tmpMat[i], 0, numTot ); set32_fx( tmpNewMat[i], 0, numTot ); - tmpMat[i][i] = 0x7fffffff; - tmpNewMat[i][i] = 0x7fffffff; + tmpMat[i][i] = ONE_IN_Q31; + move32(); + tmpNewMat[i][i] = ONE_IN_Q31; + move32(); } /* Generate initial sound energy distribution matrix */ @@ -2291,15 +2376,20 @@ static void remap_ghosts_fx( FOR( j = 0; j < numTot; ++j ) { tmpMat[j][i] = 0; + move32(); tmpNewMat[j][i] = 0; + move32(); } /* The neighbours are set to 1.0/tmpL */ - inv_tmpL = 0x7fffffff / tmpL; + tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); + inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ FOR( j = 0; j < tmpL; ++j ) { - tmpMat[neighbours[j]][i] = inv_tmpL; - tmpNewMat[neighbours[j]][i] = inv_tmpL; + tmpMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ + move32(); + tmpNewMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ + move32(); } } @@ -2308,24 +2398,25 @@ static void remap_ghosts_fx( { FOR( j = 0; j < numTot; ++j ) { - tmpNewMat[i][j] = tmpMat[j][i]; + tmpNewMat[i][j] = tmpMat[j][i]; /* Q31 */ + move32(); } } FOR( i = numSpk; i < numTot; ++i ) { - mvl2l( tmpNewMat[i], tmpVec, numTot ); + Copy32( tmpNewMat[i], tmpVec, numTot ); tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); WHILE( GT_32( tmpDist, thresh ) ) { matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); - mvl2l( tmpVec2, tmpVec, numTot ); - set_l( tmpVec2, 0, numTot ); + Copy32( tmpVec2, tmpVec, numTot ); + set32_fx( tmpVec2, 0, numTot ); tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); } - mvl2l( tmpVec, tmpNewMat[i], numTot ); + Copy32( tmpVec, tmpNewMat[i], numTot ); } FOR( i = 0; i < numSpk; ++i ) @@ -2333,9 +2424,11 @@ static void remap_ghosts_fx( /* Applying a sqrt(2) coeff and obtaining the dmMatrix*/ FOR( j = 0; j < numSpk; ++j ) { - IF( EQ_32( tmpNewMat[j][i], 0 ) || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + test(); + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) { - downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; + downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ + move32(); } ELSE { @@ -2343,7 +2436,8 @@ static void remap_ghosts_fx( move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + move32(); } } /* Downmix ghost loudspeakers according to dmxType */ @@ -2352,16 +2446,20 @@ static void remap_ghosts_fx( SWITCH( vtxArray[j].dmxType ) { case EFAP_DMX_NONE: - downmixMatrixTranspose[j][i] = 0; + downmixMatrixTranspose[j][i] = 0; /* Q31 */ + move32(); BREAK; case EFAP_DMX_AMPLITUDE: - downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; + downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ + move32(); BREAK; case EFAP_DMX_INTENSITY: default: - IF( EQ_32( tmpNewMat[j][i], 0 ) || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + test(); + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 ) ) { - downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; + downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ + move32(); } ELSE { @@ -2369,7 +2467,8 @@ static void remap_ghosts_fx( move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + move32(); } BREAK; } @@ -2384,6 +2483,7 @@ static void remap_ghosts_fx( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * vertex_init() @@ -2432,6 +2532,7 @@ static void vertex_init_fx( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * efap_panning() @@ -2522,7 +2623,9 @@ static void efap_panning_fx( Word32 P[2]; P[0] = azi; + move32(); P[1] = ele; + move32(); /* Finding in which polygon the point is */ polyIdx = get_poly_num_fx( P, polyData ); @@ -2531,18 +2634,23 @@ static void efap_panning_fx( /* Extracting the chan, the azimuth and the ele of the considered poly */ numChan = polyData->polysetArray[polyIdx].numChan; + move16(); FOR( i = 0; i < numChan; ++i ) { chan[i] = polyData->polysetArray[polyIdx].chan[i]; + move16(); aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + move32(); - IF( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) + if ( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) { aziPoly[i] = P[0]; + move32(); } elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + move32(); } /* Computing the gain for the polygon */ @@ -2558,13 +2666,16 @@ static void efap_panning_fx( FOR( i = 0; i < numChan; ++i ) { bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); + move32(); bufferL[chan[i]] = L_shl( bufferL[chan[i]], exp ); // Q31 + move32(); } return; } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * get_poly_gains() @@ -2642,31 +2753,40 @@ static void get_poly_gains_fx( Word32 P_minus_A[2]; P[0] = azi; + move32(); P[1] = ele; + move32(); /* Processing, we search for the triangle in which belong P, then we compute the gain */ FOR( i = 1; i < numChan + 1; ++i ) { A[0] = aziPoly[i - 1]; + move32(); A[1] = elePoly[i - 1]; + move32(); v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ FOR( j = i; j < numChan - 2 + i; ++j ) { - idx1 = 1 + ( j % numChan ); - idx2 = 1 + ( idx1 % numChan ); + idx1 = add( 1, ( j % numChan ) ); + idx2 = add( 1, ( idx1 % numChan ) ); - B[0] = aziPoly[idx1 - 1]; - B[1] = elePoly[idx1 - 1]; + B[0] = aziPoly[sub( idx1, 1 )]; + move32(); + B[1] = elePoly[sub( idx1, 1 )]; + move32(); - C[0] = aziPoly[idx2 - 1]; - C[1] = elePoly[idx2 - 1]; + C[0] = aziPoly[sub( idx2, 1 )]; + move32(); + C[1] = elePoly[sub( idx2, 1 )]; + move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q12 ); - break; + move32(); + BREAK; } } } @@ -2675,6 +2795,7 @@ static void get_poly_gains_fx( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * get_tri_gain() @@ -2735,7 +2856,9 @@ static Word32 get_tri_gain_fx( /* Processing */ tmpN[0] = L_sub( B[1], C[1] ); + move32(); tmpN[1] = L_sub( C[0], B[0] ); + move32(); v_sub_fixed( B, A, tmpSub1, 2, 0 ); @@ -2746,13 +2869,13 @@ static Word32 get_tri_gain_fx( Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); exp = sub( exp, norm_l( tmpDot1 ) ); Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); - v_multc_fixed( tmpN, L_shl( inv_tmpDot1, Q16 + exp ), N, 2 ); + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 gain = L_sub( 0x00040000, tmpDot2 ); /* Set gains <= -60dB to 0 to avoid problems in SVD */ - IF( LT_32( L_abs( gain ), 1 ) ) + if ( LT_32( L_abs( gain ), 1 ) ) { gain = 0; move32(); @@ -2760,6 +2883,8 @@ static Word32 get_tri_gain_fx( return gain; // Q18 } #endif + + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * add_vertex() @@ -2822,8 +2947,8 @@ static void add_vertex( static void add_vertex_fx( EFAP_VERTEX *vtxArray, /* i/o: Handle to the vertex array that will be updated */ - const Word32 azi, /* i : Azimuth of the vertex */ - const Word32 ele, /* i : Elevation of the vertex */ + const Word32 azi, /* i : Azimuth of the vertex Q22 */ + const Word32 ele, /* i : Elevation of the vertex Q22 */ const Word16 pos, /* i : Index in the vtxArray where we want to add the vertex */ const EFAP_VTX_DMX_TYPE dmxType /* i : downmix type for the vertex */ ) @@ -2835,11 +2960,13 @@ static void add_vertex_fx( /* Updating the vertex array */ - tmp = efap_lmodl( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); + tmp = efap_32mod32( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); vtxArray[pos].azi = L_sub( Q22_180_DEG, tmp ); - tmp = ( ( Q22_180_DEG < ele ) ? Q22_180_DEG : ele ); - vtxArray[pos].ele = ( ( -Q22_180_DEG > tmp ) ? -Q22_180_DEG : tmp ); + tmp = ( LT_32( Q22_180_DEG, ele ) ? Q22_180_DEG : ele ); + move32(); + vtxArray[pos].ele = ( GT_32( -Q22_180_DEG, tmp ) ? -Q22_180_DEG : tmp ); + move32(); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); @@ -2857,7 +2984,7 @@ static void add_vertex_fx( idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); /* Final Idx */ - vtxArray[pos].idx = add( (Word16) idxAziTmp, i_mult( 181, (Word16) L_shr( idxEleTmp, Q22 ) ) ); + vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); /* Setting the nan flag to 0 */ vtxArray[pos].isNaN = 0; @@ -2865,11 +2992,13 @@ static void add_vertex_fx( /* Set the default downmix type */ vtxArray[pos].dmxType = dmxType; + move32(); return; } #endif + /*-------------------------------------------------------------------------* * efap_sort_s() * @@ -2890,19 +3019,26 @@ static void efap_sort_s_fx( FOR( i = 0; i < len; i++ ) { idx[i] = i; + move16(); } FOR( i = len - 2; i >= 0; i-- ) { tempr = x[i]; + move16(); tempi = idx[i]; + move16(); FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { x[j - 1] = x[j]; + move16(); idx[j - 1] = idx[j]; + move16(); } x[j - 1] = tempr; + move16(); idx[j - 1] = tempi; + move16(); } return; @@ -2938,13 +3074,15 @@ static void efap_sort_s( return; } #endif -#ifndef IVAS_FLOAT_FIXED + + /*-------------------------------------------------------------------------* * vertex_distance() * * Compute the signed distance between a vertex and a hull surface *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static float vertex_distance( const EFAP_VERTEX *vtxArray, /* i : The considered vertex */ const EFAP_LS_TRIANGLE tri, /* i : The considered triangle */ @@ -2967,12 +3105,6 @@ static float vertex_distance( return point_plane_distance( A, B, C, P ); } #else -/*-------------------------------------------------------------------------* - * vertex_distance() - * - * Compute the signed distance between a vertex and a hull surface - *-------------------------------------------------------------------------*/ - static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, /* i : The considered vertex */ const EFAP_LS_TRIANGLE tri, /* i : The considered triangle */ @@ -2986,16 +3118,21 @@ static Word32 vertex_distance_fx( FOR( i = 0; i < 3; ++i ) { A[i] = vtxArray[tri.LS[0]].pos[i]; + move32(); B[i] = vtxArray[tri.LS[1]].pos[i]; + move32(); C[i] = vtxArray[tri.LS[2]].pos[i]; + move32(); P[i] = vtxArray[vtxIdx].pos[i]; + move32(); } return point_plane_distance_fx( A, B, C, P ); } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * point_poly_distance() @@ -3037,6 +3174,7 @@ static Word32 point_poly_distance_fx( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * point_plane_distance() @@ -3102,6 +3240,14 @@ static Word32 point_plane_distance_fx( // returns output in Q28 Word32 dist; /* Check if the point already matches a triangle vertex */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_32( X[0], P1[0] ) && EQ_32( X[1], P1[1] ) && EQ_32( X[2], P1[2] ) ) || ( EQ_32( X[0], P2[0] ) && EQ_32( X[1], P2[1] ) && EQ_32( X[2], P2[2] ) ) || ( EQ_32( X[0], P3[0] ) && EQ_32( X[1], P3[1] ) && EQ_32( X[2], P3[2] ) ) ) @@ -3128,6 +3274,7 @@ static Word32 point_plane_distance_fx( // returns output in Q28 } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * efap_crossp() @@ -3155,24 +3302,29 @@ static void efap_crossp( *-------------------------------------------------------------------------*/ static void efap_crossp_fx( - const Word32 *v1, /* i : First float vector */ - const Word32 *v2, /* i : Second float vector */ - Word32 *v /* o : Output vector */ + const Word32 *v1, /* i : First float vector Q30 */ + const Word32 *v2, /* i : Second float vector Q30 */ + Word32 *v /* o : Output vector Q29 */ ) { - v[0] = L_sub( Mpy_32_32( v1[1], v2[2] ), Mpy_32_32( v1[2], v2[1] ) ); - v[1] = L_sub( Mpy_32_32( v1[2], v2[0] ), Mpy_32_32( v1[0], v2[2] ) ); - v[2] = L_sub( Mpy_32_32( v1[0], v2[1] ), Mpy_32_32( v1[1], v2[0] ) ); + v[0] = L_sub( Mpy_32_32( v1[1], v2[2] ), Mpy_32_32( v1[2], v2[1] ) ); /* Q29 */ + move32(); + v[1] = L_sub( Mpy_32_32( v1[2], v2[0] ), Mpy_32_32( v1[0], v2[2] ) ); /* Q29 */ + move32(); + v[2] = L_sub( Mpy_32_32( v1[0], v2[1] ), Mpy_32_32( v1[1], v2[0] ) ); /* Q29 */ + move32(); return; } #endif + /*-------------------------------------------------------------------------* * find_int_in_tri() * * Find an integer in triangle array of integers *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, /* i : Triangle array */ @@ -3191,7 +3343,9 @@ static Word16 find_int_in_tri_fx( IF( EQ_16( tri[i].LS[j], n ) ) { pos[0] = i; + move16(); pos[1] = j; + move16(); return 1; } } @@ -3233,6 +3387,7 @@ static int16_t find_int_in_tri( * * Remove a vertex from a vertex structure *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void remove_vertex_fx( EFAP_VERTEX *vtxArray, /* i : Vertex array */ @@ -3279,11 +3434,13 @@ static void remove_vertex( } #endif + /*-------------------------------------------------------------------------* * get_neighbours() * * Returns the neighbouring triangles of a vertex *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ @@ -3301,24 +3458,28 @@ static Word16 get_neighbours_fx( /* Processing */ FOR( i = 0; i < numTri; ++i ) { - mvs2s( triArray[i].LS, tmpTriArray[i].LS, 3 ); + Copy( triArray[i].LS, tmpTriArray[i].LS, 3 ); } k = 0; move16(); WHILE( 1 ) { - IF( EQ_16( find_int_in_tri_fx( tmpTriArray, vtxIdx, numTri, tmpPos ), 0 ) ) + IF( find_int_in_tri_fx( tmpTriArray, vtxIdx, numTri, tmpPos ) == 0 ) { BREAK; } ELSE { tmpNeighbours[k] = tmpTriArray[tmpPos[0]].LS[0]; + move16(); tmpNeighbours[k + 1] = tmpTriArray[tmpPos[0]].LS[1]; + move16(); tmpNeighbours[k + 2] = tmpTriArray[tmpPos[0]].LS[2]; - k += 3; + move16(); + k = add( k, 3 ); tmpTriArray[tmpPos[0]].LS[tmpPos[1]] = -1; + move16(); } IF( GT_16( k, i_mult( 3, numTri ) ) ) @@ -3332,16 +3493,19 @@ static Word16 get_neighbours_fx( /* Creating the output vector, by eliminating redundancies and also deleting the indice == vtxIdx*/ neighbours[0] = tmpNeighbours[0]; + move16(); j = 1; move16(); FOR( i = 1; i < k; ++i ) { + test(); IF( NE_16( tmpNeighbours[i], tmpNeighbours[i - 1] ) && NE_16( tmpNeighbours[i], vtxIdx ) ) { neighbours[j] = tmpNeighbours[i]; - ++j; + move16(); + j = add( j, 1 ); } } @@ -3412,6 +3576,7 @@ static int16_t get_neighbours( } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * matrix_times_row() @@ -3452,13 +3617,14 @@ static void matrix_times_row_fx( Word32 *out /* o : Output vector */ ) { - int16_t i, j; + Word16 i, j; FOR( i = 0; i < L; ++i ) { FOR( j = 0; j < L; ++j ) { out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); + move32(); } } @@ -3466,11 +3632,13 @@ static void matrix_times_row_fx( } #endif + /*-------------------------------------------------------------------------* * tri_to_poly() * * Combines triangles of a surface in order to create polygons *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ @@ -3515,7 +3683,8 @@ static void tri_to_poly_fx( { assert( lenPoly < EFAP_MAX_CHAN_NUM && "EFAP: exceeded max polygon vertices!" ); poly[lenPoly] = j; - ++lenPoly; + move16(); + lenPoly = add( lenPoly, 1 ); } } @@ -3528,30 +3697,35 @@ static void tri_to_poly_fx( { found = compare_poly_fx( sortedChan[j], sortedLengths[j], poly, lenPoly ); - IF( GT_16( found, 0 ) ) + IF( found > 0 ) { BREAK; } - ELSE IF( LT_16( found, 0 ) ) + ELSE IF( found < 0 ) { replaceIdx = j; + move16(); } } - IF( EQ_16( found, 0 ) ) + IF( found == 0 ) { /* append new poly */ - mvs2s( poly, sortedChan[lenPolySet], lenPoly ); + Copy( poly, sortedChan[lenPolySet], lenPoly ); sortedTri[lenPolySet] = i; + move16(); sortedLengths[lenPolySet] = lenPoly; - ++lenPolySet; + move16(); + lenPolySet = add( lenPolySet, 1 ); } ELSE IF( EQ_16( found, -1 ) ) { /* replace with superset */ - mvs2s( poly, sortedChan[replaceIdx], lenPoly ); + Copy( poly, sortedChan[replaceIdx], lenPoly ); sortedTri[replaceIdx] = i; + move16(); sortedLengths[replaceIdx] = lenPoly; + move16(); } } @@ -3564,7 +3738,7 @@ static void tri_to_poly_fx( /* Output */ *outLengthPS = lenPolySet; move16(); - mvs2s( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); + Copy( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); return; } #else @@ -3661,11 +3835,13 @@ static void tri_to_poly( } #endif + /*-------------------------------------------------------------------------* * compare_poly() * * Compares a newly created polygon with an existing one *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 compare_poly_fx( Word16 *old, /* i : Existing polygon */ @@ -3692,6 +3868,8 @@ static Word16 compare_poly_fx( } } + test(); + test(); IF( EQ_16( count, lenOld ) && LT_16( lenOld, lenNew ) ) { /* new polygon is a superset */ @@ -3751,13 +3929,14 @@ static int16_t compare_poly( } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * sort_channels_vertex() * * Sort the channels of a polygon set according to the vertex azimuth *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void sort_channels_vertex( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ @@ -3843,12 +4022,6 @@ static void sort_channels_vertex( return; } #else -/*-------------------------------------------------------------------------* - * sort_channels_vertex() - * - * Sort the channels of a polygon set according to the vertex azimuth - *-------------------------------------------------------------------------*/ - static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ const EFAP_LS_TRIANGLE *triArray, /* i : Triangle array */ @@ -3879,8 +4052,11 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; ++i ) { P1[i] = vtxArray[triArray[idxTri].LS[0]].pos[i]; // Q31 + move32(); P2[i] = vtxArray[triArray[idxTri].LS[1]].pos[i]; // Q31 + move32(); P3[i] = vtxArray[triArray[idxTri].LS[2]].pos[i]; // Q31 + move32(); } /* First Base Vector */ @@ -3898,6 +4074,7 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; i++ ) { tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); + move32(); } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 @@ -3910,7 +4087,8 @@ static void sort_channels_vertex_fx( /* Center of the first Triangle */ FOR( i = 0; i < 3; ++i ) { - MC[i] = L_shl( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ) / 3, Q2 ); + MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); + move32(); } /* Sort Vertices */ @@ -3919,6 +4097,7 @@ static void sort_channels_vertex_fx( FOR( j = 0; j < 3; ++j ) { tmpP[j] = vtxArray[channels[i]].pos[j]; + move32(); } v_sub_fixed( tmpP, MC, P, 3, 1 ); // P Q30 @@ -3927,7 +4106,8 @@ static void sort_channels_vertex_fx( y = dotp_fixed( P, V, 3 ); // y Q29 - exp2 // Executing azi[i] = atan2f( y, x ); - azi[i] = L_shl( (Word32) BASOP_util_atan2( y, x, sub( exp2, exp1 ) ), Q16 ); // azi 2Q29 + azi[i] = L_shl( BASOP_util_atan2( y, x, sub( exp2, exp1 ) ), Q16 ); // azi 2Q29 + move32(); } /* Sorting the azi vec */ @@ -3937,15 +4117,17 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < lengthChannels; ++i ) { newChannels[i] = channels[order[i]]; + move16(); } /* return Success */ - mvs2s( newChannels, channels, lengthChannels ); + Copy( newChannels, channels, lengthChannels ); return; } #endif + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * efap_fmodf() @@ -3963,28 +4145,37 @@ static float efap_fmodf( } #else /*-------------------------------------------------------------------------* - * efap_lmodl() + * efap_32mod32() * * Modulus operation that will handle negative values the same way as matlab *-------------------------------------------------------------------------*/ -static Word32 efap_lmodl( +static Word32 efap_32mod32( const Word32 x, /* i : Dividend */ const Word32 y /* i : Divisor */ ) { Word32 result = x % y; - return GE_32( result, 0 ) ? result : L_add( result, y ); + move32(); + IF( result >= 0 ) + { + return result; + } + ELSE + { + return L_add( result, y ); + } } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * get_poly_num() * * Returns the index of the polygon in which the coordinate is *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t get_poly_num( const float P[2], /* i : Azimuth and elevation of the point */ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ @@ -4041,12 +4232,6 @@ static int16_t get_poly_num( return found_poly; } #else -/*-------------------------------------------------------------------------* - * get_poly_num() - * - * Returns the index of the polygon in which the coordinate is - *-------------------------------------------------------------------------*/ - static Word16 get_poly_num_fx( const Word32 P[2], /* i : Azimuth and elevation of the point */ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ @@ -4072,19 +4257,21 @@ static Word16 get_poly_num_fx( { /* select only polygons which are visible from the point */ dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); - IF( EQ_32( dist_tmp, 0 ) ) + IF( dist_tmp == 0 ) { return i; } - ELSE IF( GT_32( dist_tmp, 0 ) ) + ELSE IF( dist_tmp > 0 ) { poly_tmp[num_poly] = i; + move16(); poly_dist[num_poly] = dist_tmp; - num_poly++; + move32(); + num_poly = add( num_poly, 1 ); } } } - IF( EQ_16( num_poly, 0 ) ) + IF( num_poly == 0 ) { return -1; } @@ -4093,13 +4280,15 @@ static Word16 get_poly_num_fx( found_poly = poly_tmp[0]; move16(); dist_tmp = poly_dist[0]; - move16(); + move32(); FOR( i = 1; i < num_poly; i++ ) { IF( LT_32( poly_dist[i], dist_tmp ) ) { found_poly = poly_tmp[i]; + move16(); dist_tmp = poly_dist[i]; + move32(); } } @@ -4107,13 +4296,14 @@ static Word16 get_poly_num_fx( } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * in_poly() * * Determines if a given point is within a polygon or not *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t in_poly( const float P[2], /* i : Azimuth and elevation of the point */ const EFAP_POLYSET poly /* i : Polyset struct */ @@ -4178,12 +4368,6 @@ static int16_t in_poly( return 0; } #else -/*-------------------------------------------------------------------------* - * in_poly_fx() - * - * Determines if a given point is within a polygon or not - *-------------------------------------------------------------------------*/ - static Word16 in_poly_fx( /* Angles are in Q22 */ const Word32 P[2], /* i : Azimuth and elevation of the point */ const EFAP_POLYSET poly /* i : Polyset struct */ @@ -4195,6 +4379,7 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ Word32 B[2]; Word32 C[2]; Word32 P_minus_A[2]; + move16(); /* Safety check */ @@ -4216,6 +4401,7 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ move32(); } A[1] = poly.polyEle[0]; + move32(); v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ @@ -4224,22 +4410,28 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[n] ) { B[0] = P[0]; + move32(); } ELSE { B[0] = poly.polyAzi[n]; + move32(); } B[1] = poly.polyEle[n]; + move32(); IF( poly.isNaN[n + 1] ) { C[0] = P[0]; + move32(); } ELSE { C[0] = poly.polyAzi[n + 1]; + move32(); } C[1] = poly.polyEle[n + 1]; + move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { @@ -4251,13 +4443,14 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ } #endif -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------------* * in_tri() * * Determines if a given point is within a triangle or not *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t in_tri( float A[2], /* i : Coordinate of one apex of the triangle */ float B[2], /* i : Coordinate of one apex of the triangle */ @@ -4310,12 +4503,6 @@ static int16_t in_tri( } } #else -/*-------------------------------------------------------------------------* - * in_tri_fx() - * - * Determines if a given point is within a triangle or not - *-------------------------------------------------------------------------*/ - static Word16 in_tri_fx( Word32 A[2], /* i : Coordinate of one apex of the triangle */ Word32 B[2], /* i : Coordinate of one apex of the triangle */ @@ -4326,9 +4513,11 @@ static Word16 in_tri_fx( Word32 tmpDot1[2], tmpDot2[2]; Word32 matInv[2][2]; Word32 invFactor; - Word64 invFactor_w64; + Word16 tmp16, tmp_e; Word64 S[2]; + /* Threshold adjusted */ Word64 thresh_int = 21475; // 1e-6f in Q32 + move64(); /* Not a Valid Triangle : Colinear edges @@ -4343,22 +4532,27 @@ static Word16 in_tri_fx( /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); - IF( EQ_32( invFactor, 0 ) ) + IF( invFactor == 0 ) { return 0; } - invFactor_w64 = W_shr( ( (Word64) 0x7FFFFFFFFFFFFFFF ) / ( (Word64) invFactor ), Q19 ); // Q31 - invFactor = (Word32) invFactor_w64; + /* invFactor = 1.f / invFactor; */ + tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); + invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); invFactor = L_shl( invFactor, invFactor_exp ); // Q22 = Q22 * Q31 matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + move32(); matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + move32(); matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + move32(); matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + move32(); /* Computing S (Q13 + matInv_exp_final[i] + P_minus_A_exp_final + invFactor_exp - 1 ) = matInv (Q22 + matInv_exp_final[i] + invFactor_exp) *(P-A) (Q22 + P_minus_A_exp_final) */ @@ -4370,46 +4564,55 @@ static Word16 in_tri_fx( { matInv_exp[i][j] = 31; move16(); - IF( NE_32( matInv[i][j], 0 ) ) + IF( matInv[i][j] != 0 ) { matInv_exp[i][j] = norm_l( matInv[i][j] ); + move16(); } } matInv_exp_final[i] = s_min( matInv_exp[i][0], matInv_exp[i][1] ); + move16(); P_minus_A_exp[i] = 31; move16(); - IF( NE_32( P_minus_A[i], 0 ) ) + IF( P_minus_A[i] != 0 ) { P_minus_A_exp[i] = norm_l( P_minus_A[i] ); + move16(); } } P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + move64(); S[1] = L_add( L_shr( Mpy_32_32( L_shl( matInv[1][0], matInv_exp_final[1] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + move64(); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ // Q32 S - IF( LT_16( ( Q20 - matInv_exp_final[0] - P_minus_A_exp_final - invFactor_exp ), 0 ) ) + IF( sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[0] = S[0] >> ( matInv_exp_final[0] + P_minus_A_exp_final + invFactor_exp - Q20 ); + S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + move64(); } ELSE { - S[0] = S[0] << ( Q20 - matInv_exp_final[0] - P_minus_A_exp_final - invFactor_exp ); + S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); + move64(); } - IF( LT_16( ( Q20 - matInv_exp_final[1] - P_minus_A_exp_final - invFactor_exp ), 0 ) ) + IF( sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[1] = S[1] >> ( matInv_exp_final[1] + P_minus_A_exp_final + invFactor_exp - Q20 ); + S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + move64(); } ELSE { - S[1] = S[1] << ( Q20 - matInv_exp_final[1] - P_minus_A_exp_final - invFactor_exp ); + S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); + move64(); } - IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( ( S[0] + S[1] ), ( ( (Word64) 1 ) << 32 ) + thresh_int ) ) + IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( W_add( S[0], S[1] ), W_add( W_shl( 1, 32 ), thresh_int ) ) ) { return 0; } @@ -4447,9 +4650,9 @@ static void sph2cart( *-------------------------------------------------------------------------*/ static void sph2cart_fx( - const Word32 azi, /* i : Azimuth in degrees (Q22) */ - const Word32 ele, /* i : Elevation in degrees (Q22) */ - Word32 *pos /* o : Cartesian coordinates vector (x, y, z) */ + const Word32 azi, /* i : Azimuth in degrees Q22 */ + const Word32 ele, /* i : Elevation in degrees Q22 */ + Word32 *pos /* o : Cartesian coordinates vector (x, y, z) Q31 */ ) { Word16 azi_temp, ele_temp; @@ -4457,9 +4660,12 @@ static void sph2cart_fx( azi_temp = extract_l( L_shr( Mpy_32_32( azi, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ ele_temp = extract_l( L_shr( Mpy_32_32( ele, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ - pos[0] = Mpy_32_16( getCosWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); - pos[1] = Mpy_32_16( getSineWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); - pos[2] = L_shl( getSineWord16R2( ele_temp ), Q16 ); + pos[0] = Mpy_32_16( getCosWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); /* Q31 */ + move32(); + pos[1] = Mpy_32_16( getSineWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); /* Q31 */ + move32(); + pos[2] = L_shl( getSineWord16R2( ele_temp ), Q16 ); /* Q31 */ + move32(); return; } diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 6a76c438d..28ba346ca 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -201,12 +201,13 @@ void ivas_HRTF_CRend_binary_close( * * Allocate HRTF binary handle for FASTCONV renderer *-----------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED ivas_error ivas_HRTF_fastconv_binary_open_fx( HRTFS_FASTCONV **hHrtfFastConv ) { *hHrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ); - if ( *hHrtfFastConv == NULL ) + IF( *hHrtfFastConv == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" ); } @@ -227,6 +228,7 @@ ivas_error ivas_HRTF_fastconv_binary_open( } #endif + /*-----------------------------------------------------------------------* * ivas_HRTF_fastconv_binary_close() * diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 4d42d645c..fe2b843a7 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -37,12 +37,18 @@ #include "ivas_prot_rend.h" #include "wmc_auto.h" #include +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif + + #ifdef IVAS_FLOAT_FIXED #define ATTACK_CNST_48k ( 2106670080 ) // Q31 #define ATTACK_CNST_32k ( 2086555136 ) // Q31 #define ATTACK_CNST_16k ( 2027355264 ) // Q31 #define ATTACK_CNST_8k ( 1913946752 ) // Q31 #endif + Word32 release_cnst_table[201] = // Q31 { 2106670080, @@ -248,12 +254,15 @@ Word32 release_cnst_table[201] = // Q31 2147277568, }; + /*-------------------------------------------------------------------* * detect_strong_saturations() * * Detection of very strong saturations, * usually happens as a consequence of a heavy corrupted bitstream *-------------------------------------------------------------------*/ + +/*! r: apply_strong_limiting flag */ #ifndef IVAS_FLOAT_FIXED /*! r: apply_strong_limiting flag */ static int16_t detect_strong_saturations( @@ -303,65 +312,70 @@ static int16_t detect_strong_saturations( return apply_strong_limiting; } #else -/*-------------------------------------------------------------------* - * detect_strong_saturations() - * - * Detection of very strong saturations, - * usually happens as a consequence of a heavy corrupted bitstream - *-------------------------------------------------------------------*/ - -/*! r: apply_strong_limiting flag */ static Word16 detect_strong_saturations_fx( const Word16 BER_detect, /* i : BER detect flag */ Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations */ const Word32 max_val, /* i : maximum absolute value */ Word32 *frame_gain, /* i/o: frame gain value */ - Word16 q_factor /*Q factor of the output samples*/ + Word16 q_factor /* i : Q factor of the output samples */ ) { Word16 apply_strong_limiting; Word64 compare_max_value_Mul_3, compare_max_value_Mul_10; apply_strong_limiting = 0; + move16(); compare_max_value_Mul_3 = W_shl( 98187, q_factor ); // 3 * IVAS_LIMITER_THRESHOLD compare_max_value_Mul_10 = W_shl( 327290, q_factor ); // 10 * IVAS_LIMITER_THRESHOLD + test(); IF( BER_detect ) { *strong_saturation_cnt = 50; + move16(); apply_strong_limiting = 1; + move16(); } ELSE IF( GT_64( max_val, compare_max_value_Mul_3 ) && GT_16( *strong_saturation_cnt, 0 ) ) { apply_strong_limiting = 1; + move16(); } ELSE IF( GT_64( max_val, compare_max_value_Mul_10 ) ) { - *strong_saturation_cnt += 20; - *strong_saturation_cnt = min( *strong_saturation_cnt, 50 ); + *strong_saturation_cnt = add( *strong_saturation_cnt, 20 ); + move16(); + *strong_saturation_cnt = s_min( *strong_saturation_cnt, 50 ); + move16(); apply_strong_limiting = 1; + move16(); } - else + ELSE { ( *strong_saturation_cnt )--; - *strong_saturation_cnt = max( *strong_saturation_cnt, 0 ); + *strong_saturation_cnt = s_max( *strong_saturation_cnt, 0 ); + move16(); } - if ( apply_strong_limiting ) + IF( apply_strong_limiting ) { - IF( LT_32( *frame_gain, 322122547 ) ) // Q30 of 0.3 is compared + IF( LT_32( *frame_gain, 322122547 /* 0.3 in Q30 */ ) ) { - *frame_gain = Mpy_32_16_1( *frame_gain, 10923 /* 1/3 in Q15 */ ); // Q30 + /* *frame_gain /= 3.0f; */ + *frame_gain = Mpy_32_16_1( *frame_gain, 10923 /* 1/3 in Q15 */ ); /* Q30 */ + move32(); } ELSE { apply_strong_limiting = 0; + move16(); } } return apply_strong_limiting; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*-------------------------------------------------------------------* * ivas_limiter_open() * @@ -369,61 +383,71 @@ static Word16 detect_strong_saturations_fx( *-------------------------------------------------------------------*/ /*! r : limiter struct handle */ -ivas_error ivas_limiter_open( +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_limiter_open_fx( IVAS_LIMITER_HANDLE *hLimiter_out, /* o : limiter struct handle */ - const int16_t max_num_channels, /* i : maximum number of I/O channels to be processed */ - const int32_t sampling_rate /* i : sampling rate for processing */ + const Word16 max_num_channels, /* i : maximum number of I/O channels to be processed */ + const Word32 sampling_rate /* i : sampling rate for processing */ ) { - int16_t i; + Word16 i; IVAS_LIMITER_HANDLE hLimiter; Word32 attack_cnst_fx = 0; - if ( max_num_channels <= 0 || sampling_rate <= 0 ) + move32(); + test(); + IF( max_num_channels <= 0 || sampling_rate <= 0 ) { return ( IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Wrong parameters for Limiter\n" ) ); } - if ( ( hLimiter = malloc( sizeof( IVAS_LIMITER ) ) ) == NULL ) + IF( ( hLimiter = malloc( sizeof( IVAS_LIMITER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Limiter handle\n" ) ); } hLimiter->max_num_channels = max_num_channels; + move16(); hLimiter->num_channels = max_num_channels; + move16(); - /*if ( ( hLimiter->channel_ptrs = malloc( max_num_channels * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Limiter handle\n" ) ); - }*/ - if ( ( hLimiter->channel_ptrs_fx = malloc( max_num_channels * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hLimiter->channel_ptrs_fx = malloc( max_num_channels * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Limiter handle\n" ) ); } hLimiter->sampling_rate = sampling_rate; + move32(); hLimiter->gain_fx = ONE_IN_Q30; - hLimiter->release_heuristic_fx = 0; + move32(); + hLimiter->release_heuristic_fx = 0; /* Q30 */ + move32(); SWITCH( sampling_rate ) { case 48000: attack_cnst_fx = ATTACK_CNST_48k; + move32(); BREAK; case 32000: attack_cnst_fx = ATTACK_CNST_32k; + move32(); BREAK; case 16000: attack_cnst_fx = ATTACK_CNST_16k; + move32(); BREAK; case 8000: attack_cnst_fx = ATTACK_CNST_8k; + move32(); BREAK; default: assert( 0 ); } hLimiter->attack_constant_fx = attack_cnst_fx; /* Q31 */ + move32(); hLimiter->strong_saturation_count = 0; + move16(); - for ( i = 0; i < max_num_channels; ++i ) + FOR( i = 0; i < max_num_channels; ++i ) { hLimiter->channel_ptrs_fx[i] = NULL; } @@ -433,13 +457,6 @@ ivas_error ivas_limiter_open( return IVAS_ERR_OK; } #else -/*-------------------------------------------------------------------* - * ivas_limiter_open() - * - * Allocate and initialize limiter struct - *-------------------------------------------------------------------*/ - -/*! r : limiter struct handle */ ivas_error ivas_limiter_open( IVAS_LIMITER_HANDLE *hLimiter_out, /* o : limiter struct handle */ const int16_t max_num_channels, /* i : maximum number of I/O channels to be processed */ @@ -482,23 +499,25 @@ ivas_error ivas_limiter_open( return IVAS_ERR_OK; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*-------------------------------------------------------------------* * ivas_limiter_close() * * Deallocate limiter struct *-------------------------------------------------------------------*/ -void ivas_limiter_close( +#ifdef IVAS_FLOAT_FIXED +void ivas_limiter_close_fx( IVAS_LIMITER_HANDLE *phLimiter /* i/o: pointer to limiter handle, can be NULL */ ) { + test(); IF( phLimiter == NULL || *phLimiter == NULL ) { return; } - // free( ( *phLimiter )->channel_ptrs ); free( ( *phLimiter )->channel_ptrs_fx ); free( *phLimiter ); *phLimiter = NULL; @@ -506,12 +525,6 @@ void ivas_limiter_close( return; } #else -/*-------------------------------------------------------------------* - * ivas_limiter_close() - * - * Deallocate limiter struct - *-------------------------------------------------------------------*/ - void ivas_limiter_close( IVAS_LIMITER_HANDLE *phLimiter /* i/o: pointer to limiter handle, can be NULL */ ) @@ -528,7 +541,8 @@ void ivas_limiter_close( return; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*-------------------------------------------------------------------* * ivas_limiter_dec() * @@ -536,18 +550,22 @@ void ivas_limiter_close( * release time and special handling of bit errors *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_limiter_dec_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ const Word16 num_channels, /* i : number of channels to be processed */ const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word16 BER_detect, /* i : BER detect flag */ - Word16 q_factor ) + Word16 q_factor /* i : Q factor of the output samples */ +) { Word16 c; Word32 **channels; /* return early if given bad parameters */ + test(); + test(); IF( hLimiter == NULL || output == NULL || output_frame <= 0 ) { return; @@ -555,7 +573,8 @@ void ivas_limiter_dec_fx( /* Update number of channels and prepare pointers to the beginning of each of them */ assert( num_channels <= hLimiter->max_num_channels && "Number of channels must be lower than the maximum set during limiter initialization!" ); - hLimiter->num_channels = min( num_channels, hLimiter->max_num_channels ); + hLimiter->num_channels = s_min( num_channels, hLimiter->max_num_channels ); + move16(); channels = hLimiter->channel_ptrs_fx; FOR( c = 0; c < num_channels; ++c ) @@ -568,14 +587,6 @@ void ivas_limiter_dec_fx( return; } #else - -/*-------------------------------------------------------------------* - * ivas_limiter_dec() - * - * In-place saturation control for multichannel buffers with adaptive - * release time and special handling of bit errors - *-------------------------------------------------------------------*/ - void ivas_limiter_dec( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ float *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ @@ -608,7 +619,8 @@ void ivas_limiter_dec( return; } #endif -#ifdef IVAS_FLOAT_FIXED + + /*-------------------------------------------------------------------* * limiter_process() * @@ -617,13 +629,14 @@ void ivas_limiter_dec( * of calling this directly. *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void limiter_process_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ const Word16 BER_detect, /* i : BER detect flag */ Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ - Word16 q_factor /*Q factor of output samples*/ + Word16 q_factor /* i : Q factor of output samples */ ) { Word16 i, c; @@ -632,38 +645,46 @@ void limiter_process_fx( Word32 releaseHeuristic, releaseHeuristic_cnst, releaseHeuristic_cnst_2; Word16 apply_limiting, apply_strong_limiting; Word32 **output; - Word16 num_channels, q_fact_gain, scale, result; + Word16 num_channels, scale, result; Word32 release_constant, compare_value; Word32 div32, gain, frame_gain, attack_constant; /* return early if given nonsensical values */ + test(); IF( hLimiter == NULL || output_frame <= 0 ) { return; } apply_limiting = 1; + move16(); apply_strong_limiting = 0; + move16(); gain = hLimiter->gain_fx; + move32(); output = hLimiter->channel_ptrs_fx; num_channels = hLimiter->num_channels; + move16(); // sampling_rate = hLimiter->sampling_rate; attack_constant = hLimiter->attack_constant_fx; /* Q31 */ + move32(); /*-----------------------------------------------------------------* * Find highest absolute peak sample value *-----------------------------------------------------------------*/ max_val = 0; + move32(); FOR( i = 0; i < output_frame; i++ ) { FOR( c = 0; c < num_channels; c++ ) { tmp = L_abs( output[c][i] ); - IF( GT_32( tmp, max_val ) ) + if ( GT_32( tmp, max_val ) ) { max_val = tmp; + move32(); } } } @@ -688,21 +709,25 @@ void limiter_process_fx( case 320: case 160: releaseHeuristic_cnst = 85899345; + move32(); releaseHeuristic_cnst_2 = 21474836; - break; + move32(); + BREAK; default: releaseHeuristic_cnst = 21474836; + move32(); releaseHeuristic_cnst_2 = 5368709; - break; + move32(); + BREAK; } - releaseHeuristic = hLimiter->release_heuristic_fx; - q_fact_gain = Q30; + releaseHeuristic = hLimiter->release_heuristic_fx; /* Q30 */ + move32(); IF( GT_32( max_val, threshold ) ) { - frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to q30 - releaseHeuristic = min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) ); // releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) - // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); + frame_gain = L_shl( divide3232( threshold, max_val ), 15 ); // to q30 + releaseHeuristic = L_min( ONE_IN_Q30, L_add( releaseHeuristic, releaseHeuristic_cnst ) ); // releaseHeuristic_cnst is Q30 of ( 4.f * output_frame / sampling_rate ) + // release_constant = powf( 0.01f, 1.0f / ( 0.005f * powf( 200.f, .08 ) * sampling_rate ) ); /* Unoptimized code for reference */ /* releaseHeuristic = min( 1.f, releaseHeuristic + ( (float) 2.f * output_frame / sampling_rate / adaptiveReleaseWindowLengthInSeconds ) ); * ^ @@ -711,7 +736,7 @@ void limiter_process_fx( } ELSE { - releaseHeuristic = max( 0, L_sub( releaseHeuristic, releaseHeuristic_cnst_2 ) ); // releaseHeuristic_cnst_2 is Q30 of output_frame / sampling_rate ) + releaseHeuristic = L_max( 0, L_sub( releaseHeuristic, releaseHeuristic_cnst_2 ) ); // releaseHeuristic_cnst_2 is Q30 of output_frame / sampling_rate ) /* Unoptimized code for reference */ /*releaseHeuristic = max( 0.f, releaseHeuristic - ( (float) 0.5f * output_frame / sampling_rate / adaptiveReleaseWindowLengthInSeconds ) ); * ^ @@ -719,28 +744,32 @@ void limiter_process_fx( */ /* No samples above threshold and gain from previous frame is already 1.f, * therefore gain == 1.f for the entire frame. Skip processing. */ - IF( GE_32( gain, ( L_shl( 1, q_fact_gain ) ) ) ) + if ( GE_32( gain, ONE_IN_Q30 ) ) { apply_limiting = 0; + move16(); } /* No samples above threshold but gain from previous frame is not 1.f, * transition to gain == 1.f */ - frame_gain = L_shl( 1, q_fact_gain ); + frame_gain = ONE_IN_Q30; } /* Detection of very strong saturations */ - if ( strong_saturation_cnt != NULL ) + IF( strong_saturation_cnt != NULL ) { apply_strong_limiting = detect_strong_saturations_fx( BER_detect, strong_saturation_cnt, max_val, &frame_gain, q_factor ); } compare_value = 107374182; // Q30 of 0.1f + move32(); /* Limit gain reduction to 20dB. Any peaks that require gain reduction * higher than this are most likely due to bit errors during decoding */ + test(); IF( LT_32( frame_gain, compare_value ) && !apply_strong_limiting ) { frame_gain = compare_value; + move32(); } - if ( apply_limiting ) + IF( apply_limiting ) { /* 99% time constants of the gain curve * @@ -748,9 +777,11 @@ void limiter_process_fx( * samples the gain curve will reach 99% of its target value */ div32 = 5368709; // Q30 of 0.005 which is the lowest values for (output_frame / sampling_rate) + move32(); result = BASOP_Util_Divide3232_Scale( releaseHeuristic, div32, &scale ); - release_constant = release_cnst_table[shr( result, ( 15 - scale ) )]; + release_constant = release_cnst_table[shr( result, sub( 15, scale ) )]; /* Q31 */ + move32(); /* Unoptimized code for reference */ /* releaseTimeInSeconds = 0.005f * powf(200.f, releaseHeuristic); <-- Map heuristic value (0; 1) exponentially to range (0.005; 1) * release_constant = powf( 0.01f, 1.0f / ( releaseTimeInSeconds * sampling_rate ) ); @@ -765,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 = L_add( Mpy_32_32( attack_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); /* Q30 */ } ELSE { - gain = L_add( Mpy_32_32( release_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); // q30 + gain = L_add( Mpy_32_32( release_constant, ( L_sub( gain, frame_gain ) ) ), frame_gain ); /* Q30 */ } FOR( c = 0; c < num_channels; c++ ) @@ -777,26 +808,21 @@ void limiter_process_fx( sample = &output[c][i]; /* Apply gain */ - *sample = Mpy_32_32( L_shl_sat( *sample, 1 ), gain ); // q_factor + *sample = Mpy_32_32( L_shl_sat( *sample, 1 ), gain ); /* Q(q_factor) */ + move32(); } } } /* Save last gain and release heuristic values for next frame */ - hLimiter->gain_fx = gain; - hLimiter->release_heuristic_fx = releaseHeuristic; + hLimiter->gain_fx = gain; /* Q30 */ + move32(); + hLimiter->release_heuristic_fx = releaseHeuristic; /* Q30 */ + move32(); return; } #else -/*-------------------------------------------------------------------* - * limiter_process() - * - * hLimiter->channel_ptrs must be set before calling this function. - * Consider using a wrapper function like ivas_limiter_dec() instead - * of calling this directly. - *-------------------------------------------------------------------*/ - void limiter_process( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ const int16_t output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ diff --git a/lib_rend/ivas_masa_merge.c b/lib_rend/ivas_masa_merge.c index b9f2b4f8b..f1e93e224 100644 --- a/lib_rend/ivas_masa_merge.c +++ b/lib_rend/ivas_masa_merge.c @@ -50,29 +50,19 @@ #ifdef IVAS_FLOAT_FIXED static void copy_masa_meta_tile_fx( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta, const UWord8 sf, const UWord8 band ); -#else -static void copy_masa_meta_tile( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta, const uint8_t sf, const uint8_t band ); -#endif -#ifdef IVAS_FLOAT_FIXED static void full_stream_merge_fx( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, Word32 inEne1[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEne1_e, MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, Word32 inEne2[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEne2_e ); -static void diffuse_meta_merge_1x1_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ - Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ - Word16 *inEne_e, /* i : TF-energy of input 1 */ - MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ - Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEneISM_e /* i : TF-energy of input 2 */ -); +static void diffuse_meta_merge_1x1_fx( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta, Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEne_e, MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word16 *inEneISM_e ); #else +static void copy_masa_meta_tile( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta, const uint8_t sf, const uint8_t band ); + static void full_stream_merge( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, float inEne1[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, float inEne2[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] ); static void diffuse_meta_merge_1x1( MASA_DECODER_EXT_OUT_META_HANDLE outMeta, MASA_DECODER_EXT_OUT_META_HANDLE inMeta, float inEne[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, float inEneISM[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] ); - #endif + /*---------------------------------------------------------------------* * copy_masa_meta_tile() * @@ -90,17 +80,23 @@ void copy_masa_meta_tile_fx( outMeta->directionIndex[0][sf][band] = inMeta->directionIndex[0][sf][band]; move16(); outMeta->directToTotalRatio[0][sf][band] = inMeta->directToTotalRatio[0][sf][band]; + move16(); outMeta->spreadCoherence[0][sf][band] = inMeta->spreadCoherence[0][sf][band]; + move16(); outMeta->surroundCoherence[sf][band] = inMeta->surroundCoherence[sf][band]; + move16(); outMeta->diffuseToTotalRatio[sf][band] = inMeta->diffuseToTotalRatio[sf][band]; + move16(); - IF( inMeta->descriptiveMeta.numberOfDirections == 1 ) + IF( EQ_16( inMeta->descriptiveMeta.numberOfDirections, 1 ) ) { outMeta->directionIndex[1][sf][band] = inMeta->directionIndex[1][sf][band]; move16(); outMeta->directToTotalRatio[1][sf][band] = inMeta->directToTotalRatio[1][sf][band]; + move16(); outMeta->spreadCoherence[1][sf][band] = inMeta->spreadCoherence[1][sf][band]; + move16(); } ELSE { @@ -108,7 +104,9 @@ void copy_masa_meta_tile_fx( outMeta->directionIndex[1][sf][band] = SPH_IDX_FRONT; move16(); outMeta->directToTotalRatio[1][sf][band] = 0u; + move16(); outMeta->spreadCoherence[1][sf][band] = 0u; + move16(); } return; @@ -153,7 +151,7 @@ void copy_masa_meta_tile( *---------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void copy_masa_descriptive_meta( +void copy_masa_descriptive_meta_fx( MASA_DECRIPTIVE_META *outMeta, /* o : metadata to be written */ MASA_DECRIPTIVE_META *inMeta /* i : input metadata */ ) @@ -162,14 +160,22 @@ void copy_masa_descriptive_meta( FOR( char_idx = 0; char_idx < 8; char_idx++ ) { outMeta->formatDescriptor[char_idx] = inMeta->formatDescriptor[char_idx]; + move16(); } outMeta->numberOfDirections = inMeta->numberOfDirections; + move16(); outMeta->numberOfChannels = inMeta->numberOfChannels; + move16(); outMeta->sourceFormat = inMeta->sourceFormat; + move16(); outMeta->transportDefinition = inMeta->transportDefinition; + move16(); outMeta->channelAngle = inMeta->channelAngle; + move16(); outMeta->channelDistance = inMeta->channelDistance; + move16(); outMeta->channelLayout = inMeta->channelLayout; + move16(); return; } @@ -275,118 +281,148 @@ void diffuse_meta_merge_1x1( return; } -#endif - - -#ifdef IVAS_FLOAT_FIXED +#else void diffuse_meta_merge_1x1_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ - Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ - Word16 *inEne_e, /* i : TF-energy of input 1 */ - MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ - Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEneISM_e /* i : TF-energy of input 2 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta, /* i : Input metadata 1 */ + Word32 inEne_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 1 */ + Word16 *inEne_e, /* i : TF-energy of input 1 Exponent */ + MASA_DECODER_EXT_OUT_META_HANDLE inMetaISM, /* i : Input metadata 2 */ + Word32 inEneISM_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEneISM_e /* i : TF-energy of input 2 Exponent */ ) { Word8 sf, band; Word16 max_e, in1_e[MASA_FREQUENCY_BANDS], i; FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx = 0, dir_nrg_ratio_fx, total_nrg_fx = 0; + Word32 energyTimesRatio_fx, energyTimesRatioISM_fx, total_diff_nrg_fx, dir_nrg_ratio_fx, total_nrg_fx = 0; Word32 dir_ratio_ism_fx, L_tmp1, L_tmp2; Word16 scale, energyTimesRatio_e, tmp, total_nrg_e = 0, total_diff_nrg_e, dir_ratio_ism_e, energyTimesRatioISM_e, dir_nrg_ratio_e; + move32(); + move16(); - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); - energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); - energyTimesRatio_e = inEne_e[sf] + scale; + tmp = BASOP_Util_Divide1616_Scale( inMeta->directToTotalRatio[0][sf][band], UINT8_MAX, &scale ); + energyTimesRatio_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */ + energyTimesRatio_e = add( inEne_e[sf], scale ); /* target is original MASA diffuseness */ - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); - total_diff_nrg_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); - total_diff_nrg_e = inEne_e[sf] + scale; + tmp = BASOP_Util_Divide1616_Scale( inMeta->directToTotalRatio[0][sf][band], UINT8_MAX, &scale ); + total_diff_nrg_fx = Mpy_32_16_r( inEne_fx[sf][band], tmp ); /* Q( 31 - ( nEne_e[sf] + scale ) ) */ + total_diff_nrg_e = add( inEne_e[sf], scale ); /* criterion is mean of ISM ratio and new ratio */ - dir_ratio_ism_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( (Word16) inMeta->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &dir_ratio_ism_e ) ); + dir_ratio_ism_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( inMeta->directToTotalRatio[0][sf][band], UINT8_MAX, &dir_ratio_ism_e ) ); tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( total_nrg_fx, EPSILON_FX ), &scale ); - L_tmp1 = L_deposit_h( tmp ); - scale = scale + ( total_diff_nrg_e - total_nrg_e ); + L_tmp1 = L_deposit_h( tmp ); /* Q( 31 - ( scale + total_nrg_e - total_diff_nrg_e ) ) */ + scale = add( scale, sub( total_diff_nrg_e, total_nrg_e ) ); L_tmp2 = L_sub( L_shl( 1, scale ), L_tmp1 ); L_tmp1 = BASOP_Util_Add_Mant32Exp( dir_ratio_ism_fx, dir_ratio_ism_e, L_tmp2, scale, &tmp ); L_tmp1 = L_shr( L_tmp1, 1 ); - energyTimesRatioISM_fx = Mpy_32_32( L_tmp1, inEneISM_fx[sf][band] ); - energyTimesRatioISM_e = tmp + inEneISM_e[sf]; + energyTimesRatioISM_fx = Mpy_32_32( L_tmp1, inEneISM_fx[sf][band] ); /* Q( 31 - ( tmp + inEneISM_e[sf] ) ) */ + energyTimesRatioISM_e = add( tmp, inEneISM_e[sf] ); - IF( ( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioISM_fx, energyTimesRatioISM_e, energyTimesRatio_fx, energyTimesRatio_e ) > 1 ) ) + IF( ( BASOP_Util_Cmp_Mant32Exp( energyTimesRatioISM_fx, energyTimesRatioISM_e, energyTimesRatio_fx, energyTimesRatio_e ) > 0 ) ) { Word32 new_dir_ratio_fx, new_diff_ratio_fx; Word16 new_dir_ratio_e; outMeta->directionIndex[0][sf][band] = inMetaISM->directionIndex[0][sf][band]; + move16(); outMeta->directToTotalRatio[0][sf][band] = inMetaISM->directToTotalRatio[0][sf][band]; + move16(); outMeta->spreadCoherence[0][sf][band] = inMetaISM->spreadCoherence[0][sf][band]; + move16(); outMeta->surroundCoherence[sf][band] = inMetaISM->surroundCoherence[sf][band]; + move16(); tmp = BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, L_add( EPSILON_FX, total_nrg_fx ), &scale ); - scale = scale + ( total_diff_nrg_e - total_nrg_e ); + scale = add( scale, sub( total_diff_nrg_e, total_nrg_e ) ); dir_nrg_ratio_fx = L_sub( L_shl( 1, scale ), L_deposit_h( tmp ) ); dir_nrg_ratio_e = scale; + move16(); new_dir_ratio_fx = dir_nrg_ratio_fx; + move32(); new_dir_ratio_e = dir_nrg_ratio_e; + move16(); tmp = BASOP_Util_Cmp_Mant32Exp( dir_nrg_ratio_fx, dir_nrg_ratio_e, dir_ratio_ism_fx, dir_ratio_ism_e ); IF( tmp <= 0 ) { new_dir_ratio_fx = dir_nrg_ratio_fx; + move32(); new_dir_ratio_e = dir_nrg_ratio_e; + move16(); } - outMeta->directToTotalRatio[0][sf][band] = (uint8_t) ( L_shr( new_dir_ratio_fx, 31 - new_dir_ratio_e ) * UINT8_MAX ); - new_diff_ratio_fx = L_shl( 1, 31 - new_dir_ratio_e ) - new_dir_ratio_fx; - outMeta->diffuseToTotalRatio[sf][band] = (uint8_t) ( L_shr( new_diff_ratio_fx, new_dir_ratio_e ) * UINT8_MAX ); + outMeta->directToTotalRatio[0][sf][band] = (UWord8) imult1616( extract_l( L_shr( new_dir_ratio_fx, sub( 31, new_dir_ratio_e ) ) ), UINT8_MAX ); + move16(); + new_diff_ratio_fx = L_sub( L_shl( 1, sub( 31, new_dir_ratio_e ) ), new_dir_ratio_fx ); + outMeta->diffuseToTotalRatio[sf][band] = (UWord8) imult1616( extract_l( L_shr( new_diff_ratio_fx, new_dir_ratio_e ) ), UINT8_MAX ); + move16(); } ELSE { /* use the plain original meta for this tile */ outMeta->directionIndex[0][sf][band] = inMeta->directionIndex[0][sf][band]; + move16(); outMeta->directToTotalRatio[0][sf][band] = inMeta->directToTotalRatio[0][sf][band]; + move16(); outMeta->spreadCoherence[0][sf][band] = inMeta->spreadCoherence[0][sf][band]; + move16(); outMeta->surroundCoherence[sf][band] = inMeta->surroundCoherence[sf][band]; + move16(); outMeta->diffuseToTotalRatio[sf][band] = inMeta->diffuseToTotalRatio[sf][band]; + move16(); } outMeta->directionIndex[1][sf][band] = SPH_IDX_FRONT; + move16(); outMeta->directToTotalRatio[1][sf][band] = 0u; + move16(); outMeta->spreadCoherence[1][sf][band] = 0u; + move16(); inEne_fx[sf][band] = BASOP_Util_Add_Mant32Exp( inEne_fx[sf][band], inEne_e[sf], inEneISM_fx[sf][band], inEneISM_e[sf], &in1_e[band] ); /* Update energy for subsequent mergings */ + move16(); } max_e = in1_e[0]; + move16(); FOR( i = 1; i < MASA_FREQUENCY_BANDS; i++ ) { - IF( max_e < in1_e[i] ) - max_e = in1_e[i]; + if ( LT_16( max_e, in1_e[i] ) ) + { + max_e = in1_e[i]; + move16(); + } } FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { - inEne_fx[sf][i] = L_shr( inEne_fx[sf][i], max_e - in1_e[i] ); + inEne_fx[sf][i] = L_shr( inEne_fx[sf][i], sub( max_e, in1_e[i] ) ); /* Q(31 - max_e) */ + move32(); } inEne_e[sf] = max_e; + move16(); } /* Set descriptive meta for mixed format */ outMeta->descriptiveMeta.sourceFormat = 0u; + move16(); outMeta->descriptiveMeta.transportDefinition = 0u; + move16(); outMeta->descriptiveMeta.channelAngle = 0u; + move16(); outMeta->descriptiveMeta.channelDistance = 0u; + move16(); outMeta->descriptiveMeta.channelLayout = 0u; + move16(); outMeta->descriptiveMeta.numberOfDirections = 0u; + move16(); /* Number of transports should be set outside. */ return; @@ -465,60 +501,56 @@ void full_stream_merge( return; } -#endif - -#ifdef IVAS_FLOAT_FIXED +#else void full_stream_merge_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ - Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ - Word16 *inEne1_e, - MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ - Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEne2_e ) + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ + Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ + Word16 *inEne1_e, /* i/o: TF-energy of input 1 Exponent */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ + Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEne2_e /* i : TF-energy of input 2 Exponent */ +) { - uint8_t n_dirs_1, n_dirs_2; - uint8_t sf, band; - Word16 scale, tmp, dir_nrg_1_e = 0, dir_nrg_2_e = 0, max_e; + UWord8 n_dirs_1, n_dirs_2; + UWord8 sf, band; + Word16 scale, tmp, dir_nrg_1_e, dir_nrg_2_e, max_e, i; Word16 in1_e[MASA_FREQUENCY_BANDS]; Word32 dir_nrg_1_fx, dir_nrg_2_fx, L_tmp; /* full stream select based on total direct energy */ - n_dirs_1 = inMeta1->descriptiveMeta.numberOfDirections + 1u; /* to 1-based */ - n_dirs_2 = inMeta2->descriptiveMeta.numberOfDirections + 1u; + n_dirs_1 = (UWord8) add( inMeta1->descriptiveMeta.numberOfDirections, 1u ); /* to 1-based */ + n_dirs_2 = (UWord8) add( inMeta2->descriptiveMeta.numberOfDirections, 1u ); FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); - dir_nrg_1_fx = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); - dir_nrg_1_e = scale + inEne1_e[sf]; - + tmp = BASOP_Util_Divide1616_Scale( inMeta1->directToTotalRatio[0][sf][band], UINT8_MAX, &scale ); + dir_nrg_1_fx = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */ + dir_nrg_1_e = add( scale, inEne1_e[sf] ); - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[0][sf][band], (Word16) UINT8_MAX, &scale ); - dir_nrg_2_fx = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); - dir_nrg_2_e = scale + inEne2_e[sf]; + tmp = BASOP_Util_Divide1616_Scale( inMeta1->directToTotalRatio[0][sf][band], UINT8_MAX, &scale ); + dir_nrg_2_fx = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */ + dir_nrg_2_e = add( scale, inEne2_e[sf] ); - - IF( n_dirs_1 == 2 ) + IF( EQ_16( n_dirs_1, 2 ) ) { - - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta1->directToTotalRatio[1][sf][band], (Word16) UINT8_MAX, &scale ); - L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); - scale = scale + inEne1_e[sf]; + tmp = BASOP_Util_Divide1616_Scale( inMeta1->directToTotalRatio[1][sf][band], UINT8_MAX, &scale ); + L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne1_fx[sf][band] ); /* Q( 31 - ( scale + inEne1_e[sf] ) ) */ + scale = add( scale, inEne1_e[sf] ); dir_nrg_1_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_1_fx, dir_nrg_1_e, &dir_nrg_1_e ); } - IF( n_dirs_2 == 2 ) + IF( EQ_16( n_dirs_2, 2 ) ) { - tmp = BASOP_Util_Divide1616_Scale( (Word16) inMeta2->directToTotalRatio[1][sf][band], (Word16) UINT8_MAX, &scale ); - L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); - scale = scale + inEne2_e[sf]; + tmp = BASOP_Util_Divide1616_Scale( inMeta2->directToTotalRatio[1][sf][band], UINT8_MAX, &scale ); + L_tmp = Mpy_32_32( L_deposit_h( tmp ), inEne2_fx[sf][band] ); /* Q( 31 - ( scale + inEne2_e[sf] ) ) */ + scale = add( scale, inEne2_e[sf] ); dir_nrg_2_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale, dir_nrg_2_fx, dir_nrg_2_e, &dir_nrg_2_e ); } - IF( BASOP_Util_Cmp_Mant32Exp( dir_nrg_1_fx, dir_nrg_1_e, dir_nrg_2_fx, dir_nrg_2_e ) > 1 ) + IF( BASOP_Util_Cmp_Mant32Exp( dir_nrg_1_fx, dir_nrg_1_e, dir_nrg_2_fx, dir_nrg_2_e ) > 0 ) { copy_masa_meta_tile_fx( outMeta, inMeta1, sf, band ); } @@ -528,36 +560,51 @@ void full_stream_merge_fx( } inEne1_fx[sf][band] = BASOP_Util_Add_Mant32Exp( inEne1_fx[sf][band], inEne1_e[sf], inEne2_fx[sf][band], inEne2_e[sf], &in1_e[band] ); + move32(); } max_e = in1_e[0]; - FOR( Word16 i = 1; i < MASA_FREQUENCY_BANDS; i++ ) + move16(); + FOR( i = 1; i < MASA_FREQUENCY_BANDS; i++ ) { - IF( max_e < in1_e[i] ) - max_e = in1_e[i]; + if ( LT_16( max_e, in1_e[i] ) ) + { + max_e = in1_e[i]; + move16(); + } } - FOR( Word16 i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { - inEne1_fx[sf][i] = L_shr( inEne1_fx[sf][i], max_e - in1_e[i] ); + inEne1_fx[sf][i] = L_shr( inEne1_fx[sf][i], sub( max_e, in1_e[i] ) ); /* Q( 31 - max_e ) */ + move32(); } inEne1_e[sf] = max_e; + move16(); } /* Set descriptive meta for mixed format */ outMeta->descriptiveMeta.sourceFormat = 0u; + move16(); outMeta->descriptiveMeta.transportDefinition = 0u; + move16(); outMeta->descriptiveMeta.channelAngle = 0u; + move16(); outMeta->descriptiveMeta.channelDistance = 0u; + move16(); outMeta->descriptiveMeta.channelLayout = 0u; - IF( n_dirs_1 == 2 || n_dirs_2 == 2 ) + move16(); + test(); + IF( EQ_16( n_dirs_1, 2 ) || EQ_16( n_dirs_2, 2 ) ) { outMeta->descriptiveMeta.numberOfDirections = 1u; + move16(); } ELSE { outMeta->descriptiveMeta.numberOfDirections = 0u; + move16(); } /* Number of transports should be set outside. */ @@ -602,28 +649,32 @@ void ivas_prerend_merge_masa_metadata( return; } -#endif - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_prerend_merge_masa_metadata_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ - IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ - Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ - Word16 *inEne1_e, - MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ - IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ - Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEne2_e /* i : TF-energy of input 2 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ + IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ + Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ + Word16 *inEne1_e, /* i/o: TF-energy of input 1 Exponent */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ + IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ + Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEne2_e /* i : TF-energy of input 2 Exponent */ ) { /* mixing ISMs with non-ISM use different merge */ - IF( inType1 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType2 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( inType1, IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) && NE_32( inType2, IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) { /* meta_1 is ISM and both are 1dir */ diffuse_meta_merge_1x1_fx( outMeta, inMeta2, inEne2_fx, inEne2_e, inMeta1, inEne1_fx, inEne1_e ); } - ELSE IF( inType2 == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && inType1 != IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) + ELSE IF( EQ_32( inType2, IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) && NE_32( inType1, IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) && ( inMeta1->descriptiveMeta.numberOfDirections == 0u && inMeta2->descriptiveMeta.numberOfDirections == 0u ) ) { /* meta_2 is ISM and both are 1dir */ diffuse_meta_merge_1x1_fx( outMeta, inMeta1, inEne1_fx, inEne1_e, inMeta2, inEne2_fx, inEne2_e ); @@ -708,6 +759,7 @@ ivas_error masaPrerendOpen_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hMasaPrerend = (MASA_PREREND_HANDLE) malloc( sizeof( MASA_PREREND_DATA ) ); IF( hMasaPrerend == NULL ) @@ -762,6 +814,7 @@ void masaPrerendClose_fx( { Word16 i; + test(); IF( hMasaPrerendPtr == NULL || *hMasaPrerendPtr == NULL ) { return; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 11cb17e70..4868919f8 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -120,14 +120,13 @@ void ivas_limiter_dec const int16_t BER_detect /* i : BER detect flag */ ); #ifdef IVAS_FLOAT_FIXED -void ivas_limiter_dec_fx -( +void ivas_limiter_dec_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ - const Word16 num_channels, /* i : number of channels to be processed */ - const Word16 output_frame, /* i : number of samples per channel in the buffer */ + Word32 *output[MAX_OUTPUT_CHANNELS], /* i/o: input/output buffer */ + const Word16 num_channels, /* i : number of channels to be processed */ + const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word16 BER_detect, /* i : BER detect flag */ - Word16 q_factor + Word16 q_factor /* i : Q factor of the output samples */ ); #endif void limiter_process( @@ -139,13 +138,13 @@ void limiter_process( ); #ifdef IVAS_FLOAT_FIXED void limiter_process_fx( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ - const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ - const Word16 BER_detect, /* i : BER detect flag */ - Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ - Word16 q_factor - ); + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + const Word16 output_frame, /* i : number of samples to be processed per channel in the I/O buffer */ + const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ + const Word16 BER_detect, /* i : BER detect flag */ + Word16 *strong_saturation_cnt, /* i/o: counter of strong saturations (can be NULL) */ + Word16 q_factor /* i : Q factor of output samples */ +); #endif /*----------------------------------------------------------------------------------* * TD decorr. function prototypes @@ -214,11 +213,11 @@ void ivas_td_decorr_APD_iir_filter_fx( #ifdef IVAS_FLOAT_FIXED ivas_error efap_init_data_fx( - EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ + EFAP_HANDLE *hEFAPdata, /* i/o: handle for EFAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ); #else ivas_error efap_init_data( @@ -235,11 +234,11 @@ void efap_free_data( #ifdef IVAS_FLOAT_FIXED void efap_determine_gains_fx( - EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ - Word32 *gains, /* o : gain vector for speaker nodes for given direction */ - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ + EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + Word32 *gains, /* o : gain vector for speaker nodes for given direction Q30 */ + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ); #else void efap_determine_gains( @@ -395,6 +394,7 @@ float configure_reqularization_factor( const int32_t ivas_total_brate /* i : total IVAS bitrate */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_alloc_mem( DIRAC_REND_HANDLE hDirACRend, const RENDERER_TYPE renderer_type, @@ -402,6 +402,14 @@ ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, const int16_t hodirac_flag ); +#else +ivas_error ivas_dirac_alloc_mem_fx( + DIRAC_REND_HANDLE hDirACRend, + const RENDERER_TYPE renderer_type, + const Word16 num_freq_bands, + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, + const Word16 hodirac_flag); +#endif void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem @@ -941,15 +949,17 @@ void compute_hoa_encoder_mtx_fx( Word32 *response_fx, const Word16 num_responses, const Word16 ambisonics_order); +#endif -void ivas_dirac_dec_compute_power_factors_fx( +#ifndef IVAS_FLOAT_FIXED +void ivas_dirac_dec_compute_gain_factors( const int16_t num_freq_bands, - const Word32 *diffuseness_fx, - const Word16 max_band_decorr, - Word32 *direct_power_factor, - Word32 *diffuse_power_factor + const float *diffuseness, + const int16_t max_band_decorr, + float *direct_gain_factor, + float *diffuse_gain_factor ); - +#else void ivas_dirac_dec_compute_gain_factors_fx( const Word16 num_freq_bands, const Word32 *diffuseness_fx, @@ -960,14 +970,7 @@ void ivas_dirac_dec_compute_gain_factors_fx( ); #endif -void ivas_dirac_dec_compute_gain_factors( - const int16_t num_freq_bands, - const float *diffuseness, - const int16_t max_band_decorr, - float *direct_gain_factor, - float *diffuse_gain_factor -); - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_power_factors( const int16_t num_freq_bands, const float *diffuseness, @@ -975,6 +978,15 @@ void ivas_dirac_dec_compute_power_factors( float *direct_power_factor, float *diffuse_power_factor ); +#else +void ivas_dirac_dec_compute_power_factors_fx( + const Word16 num_freq_bands, + const Word32 *diffuseness_fx, + const Word16 max_band_decorr, + Word32 *direct_power_factor, + Word32 *diffuse_power_factor +); +#endif void ivas_dirac_dec_compute_directional_responses( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ @@ -2836,19 +2848,17 @@ void ivas_prerend_merge_masa_metadata( IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ float inEne2[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i : TF-energy of input 2 */ ); -#endif - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_prerend_merge_masa_metadata_fx( - MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ - MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ - IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ - Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ - Word16 *inEne1_e, - MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ - IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ - Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ - Word16 *inEne2_e /* i : TF-energy of input 2 */ + MASA_DECODER_EXT_OUT_META_HANDLE outMeta, /* o : Merged metadata output */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta1, /* i : Input metadata 1 */ + IVAS_REND_AudioConfigType inType1, /* i : Type of input 1 */ + Word32 inEne1_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o: TF-energy of input 1. after merge, contains the energy of the merged signal */ + Word16 *inEne1_e, /* i/o: TF-energy of input 1 Exponent */ + MASA_DECODER_EXT_OUT_META_HANDLE inMeta2, /* i : Input metadata 2 */ + IVAS_REND_AudioConfigType inType2, /* i : Type of input 2 */ + Word32 inEne2_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : TF-energy of input 2 */ + Word16 *inEne2_e /* i : TF-energy of input 2 Exponent */ ); #endif diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index a44a5077a..b8ac1194b 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1032,12 +1032,12 @@ typedef struct EFAP_VERTEX #else typedef struct EFAP_VERTEX { - Word32 azi; /* azimuth of the loudspeaker */ - Word32 ele; /* elevation of the loudspeaker */ - Word32 pos[3]; /* [x y z] cartesian coordinate vector */ - Word16 idx; /* integer, that corresponds to the first index for the LS in the 1D output */ - Word16 isNaN; /* used to indicate if the vertex is a virtual speaker */ - EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ + Word32 azi; /* azimuth of the loudspeaker */ /* Q22 */ + Word32 ele; /* elevation of the loudspeaker */ /* Q22 */ + Word32 pos[3]; /* [x y z] cartesian coordinate vector */ /* Q31 */ + Word16 idx; /* integer, that corresponds to the first index for the LS in the 1D output */ + Word16 isNaN; /* used to indicate if the vertex is a virtual speaker */ + EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ } EFAP_VERTEX; #endif @@ -1062,11 +1062,11 @@ typedef struct EFAP_POLYSET #else typedef struct EFAP_POLYSET { - Word16 chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ - Word16 isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ - Word16 numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ - Word32 polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ - Word32 polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ + Word16 chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ + Word16 isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ + Word16 numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ + Word32 polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ /* Q22 */ + Word32 polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ /* Q22 */ } EFAP_POLYSET; #endif @@ -1092,8 +1092,8 @@ typedef struct EFAP float *aziSpk; /* Loudspeaker azimuths */ float *eleSpk; /* Loudspeaker elevations */ #else - Word32 *aziSpk; /* Loudspeaker azimuths */ - Word32 *eleSpk; /* Loudspeaker elevations */ + Word32 *aziSpk; /* Loudspeaker azimuths */ /* Q22 */ + Word32 *eleSpk; /* Loudspeaker elevations */ /* Q22 */ #endif EFAP_VERTEX_DATA vtxData; /* Vertex Data, contains all the data concerning the vertex */ EFAP_POLYSET_DATA polyData; /* Polygon data */ @@ -1102,9 +1102,9 @@ typedef struct EFAP float *bufferLong; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ float *bufferShort; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #else - Word32 **dmTranspose_fx; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ - Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ - Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ + Word32 **dmTranspose_fx; /* Downmix Matrix used for redistributing the energy of ghosts LS and its transpose */ /* Q31 */ + Word32 *bufferLong_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is a 1D array of length numVtx */ + Word32 *bufferShort_fx; /* tmp buffer that will be given as a parameter for computing the gain; this is the result of downMixMatrix*bufferLong, length is numSpk */ #endif int16_t numTot; /* Total number of real + ghost loudspeakers, used later for freeing memory */ @@ -1122,15 +1122,15 @@ typedef struct ivas_orient_trk_state_t float offCenterAdaptationRate; float adaptationAngle; #else - Word32 centerAdaptationRate_fx; /* Q31 */ - Word32 offCenterAdaptationRate_fx; /* Q31 */ - Word32 adaptationAngle_fx; /* Q29 */ + Word32 centerAdaptationRate_fx; /* Q31 */ + Word32 offCenterAdaptationRate_fx; /* Q31 */ + Word32 adaptationAngle_fx; /* Q29 */ #endif #ifndef IVAS_FLOAT_FIXED float alpha; #else - Word32 alpha_fx; /* Q(Q_alpha) */ + Word32 alpha_fx; /* Q(Q_alpha) */ Word16 Q_alpha; #endif IVAS_QUATERNION absAvgRot; /* average absolute orientation */ @@ -2245,15 +2245,11 @@ typedef struct { Word16 max_num_channels; Word16 num_channels; - // float **channel_ptrs; Word32 **channel_ptrs_fx; Word32 sampling_rate; - // float gain; - Word32 gain_fx; /* Q30 */ - // float release_heuristic; + Word32 gain_fx; /* Q30 */ Word32 release_heuristic_fx; /* Q30 */ - // float attack_constant; - Word32 attack_constant_fx; /* Q31 */ + Word32 attack_constant_fx; /* Q31 */ Word16 strong_saturation_count; } IVAS_LIMITER, *IVAS_LIMITER_HANDLE; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f9eadb800..2ce925892 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1105,10 +1105,10 @@ static ivas_error initLimiter( /* Support re-init: close if already allocated */ IF( *phLimiter != NULL ) { - ivas_limiter_close( phLimiter ); + ivas_limiter_close_fx( phLimiter ); } - IF( NE_32( ( error = ivas_limiter_open( phLimiter, numChannels, sampleRate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_limiter_open_fx( phLimiter, numChannels, sampleRate ) ), IVAS_ERR_OK ) ) { return error; } @@ -1680,7 +1680,7 @@ static ivas_error initEfap( /* If re-initializing, free existing EFAP handle. */ IF( pEfapWrapper->hEfap != NULL ) { - efap_free_data( &pEfapWrapper->hEfap ); + efap_free_data_fx( &pEfapWrapper->hEfap ); } /* Only initialize EFAP handle if output config is channel-based */ @@ -4098,7 +4098,7 @@ static ivas_error initMcBinauralRendering( { IF( inputMc->efapInWrapper.hEfap != NULL ) { - efap_free_data( &inputMc->efapInWrapper.hEfap ); + efap_free_data_fx( &inputMc->efapInWrapper.hEfap ); } } @@ -4321,7 +4321,7 @@ static ivas_error initMcMasaRendering( IF( inputMc->efapInWrapper.hEfap != NULL ) { - efap_free_data( &inputMc->efapInWrapper.hEfap ); + efap_free_data_fx( &inputMc->efapInWrapper.hEfap ); } IF( NE_32( ( error = ivas_mcmasa_ana_open( &inputMc->hMcMasa, inConfig, inSampleRate ) ), IVAS_ERR_OK ) ) @@ -4640,7 +4640,7 @@ static void clearInputMc( /* Free input's internal handles */ IF( inputMc->efapInWrapper.hEfap != NULL ) { - efap_free_data( &inputMc->efapInWrapper.hEfap ); + efap_free_data_fx( &inputMc->efapInWrapper.hEfap ); } ivas_rend_closeCrend( &inputMc->crendWrapper ); @@ -12447,7 +12447,7 @@ static void renderMasaToMasa( } } - copy_masa_descriptive_meta( &( outMeta->descriptiveMeta ), &( inMeta->descriptive_meta ) ); + copy_masa_descriptive_meta_fx( &( outMeta->descriptiveMeta ), &( inMeta->descriptive_meta ) ); accumulate2dArrayToBuffer_fx( tmpBuffer_fx, &outAudio ); @@ -13481,7 +13481,7 @@ void IVAS_REND_Close( IF( hIvasRend->efapOutWrapper.hEfap != NULL ) { - efap_free_data( &hIvasRend->efapOutWrapper.hEfap ); + efap_free_data_fx( &hIvasRend->efapOutWrapper.hEfap ); } /* clear inputs */ @@ -13505,7 +13505,7 @@ void IVAS_REND_Close( /* clear Config. Renderer */ ivas_render_config_close( &( hIvasRend->hRendererConfig ) ); - ivas_limiter_close( &hIvasRend->hLimiter ); + ivas_limiter_close_fx( &hIvasRend->hLimiter ); closeHeadRotation( hIvasRend ); @@ -13995,7 +13995,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, 0 ); /* Allocate stack memory */ - IF( NE_32( ( error = ivas_dirac_alloc_mem( hDirACRend, RENDERER_DIRAC, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dirac_alloc_mem_fx( hDirACRend, RENDERER_DIRAC, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), 0 ) ), IVAS_ERR_OK ) ) { return error; } -- GitLab From 988c29a091d0aba30d237fa1d166d6ac612746c7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 4 Jul 2024 11:59:54 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/tools.c | 2 +- lib_com/tools_fx.c | 10 +++++----- lib_dec/ivas_init_dec.c | 2 +- lib_rend/ivas_allrad_dec.c | 4 ++-- lib_rend/ivas_limiter.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib_com/tools.c b/lib_com/tools.c index 2132eb9f5..55d866a3e 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -217,7 +217,7 @@ float sum2_f( #ifdef IVAS_FLOAT_FIXED Word32 sum2_f_32_fx( - const Word32 *vec, /* i : input vector */ + const Word32 *vec, /* i : input vector */ const Word16 lvec, /* i : length of input vector */ Word16 gb ) { diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 6369b678f..6d17d6a4a 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -3832,9 +3832,9 @@ void delay_signal( } void delay_signal_fx( - Word32 x[], /* i/o: signal to be delayed */ - const Word16 len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ + 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 */ ) { @@ -3850,9 +3850,9 @@ void delay_signal_fx( } #ifdef IVAS_FLOAT_FIXED void delay_signal_q_adj_fx( - Word32 x[], /* i/o: signal to be delayed */ + Word32 x[], /* i/o: signal to be delayed */ const Word16 len, /* i : length of the input signal */ - Word32 mem[], /* i/o: synchronization memory */ + Word32 mem[], /* i/o: synchronization memory */ const Word16 delay, /* i : delay in samples */ const Word16 q_x, const Word16 q_mem ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d844c7435..bb9894dfd 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2290,7 +2290,7 @@ ivas_error ivas_init_decoder_fx( } ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ), - st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index ca405c01d..b97e877b3 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -292,7 +292,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( // printf( "\n%f", ((float)*p_dec_mtx)/ ONE_IN_Q25 ); p_dec_mtx++; } - p_dec_mtx += sub( SBA_NHARM_HOA3 , num_harm ); + p_dec_mtx += sub( SBA_NHARM_HOA3, num_harm ); } } @@ -310,7 +310,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( move32(); p_dec_mtx++; } - p_dec_mtx += sub( SBA_NHARM_HOA3 , num_harm ); + p_dec_mtx += sub( SBA_NHARM_HOA3, num_harm ); } /* free EFAP handle */ diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index fe2b843a7..07f2ca72d 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -386,8 +386,8 @@ static Word16 detect_strong_saturations_fx( #ifdef IVAS_FLOAT_FIXED 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 */ - const Word32 sampling_rate /* i : sampling rate for processing */ + const Word16 max_num_channels, /* i : maximum number of I/O channels to be processed */ + const Word32 sampling_rate /* i : sampling rate for processing */ ) { Word16 i; -- GitLab