From f1b9b09f90d5ed135433661d1d0071e964625054 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 19:32:04 +0530 Subject: [PATCH] MASA path cleanup, Q-info update for decoder/common files --- lib_com/ACcontextMapping.c | 18 +-- lib_com/ACcontextMapping_fx.c | 50 +++--- lib_com/ari_fx.c | 5 +- lib_com/ari_hm.c | 144 +++++++++--------- lib_com/ari_hm_fx.c | 128 ++++++++-------- lib_com/cldfb.c | 18 ++- lib_com/ivas_prot_fx.h | 23 +++ lib_com/ivas_qmetadata_com.c | 17 +-- lib_com/ivas_qspherical_com.c | 8 +- lib_com/prot.h | 38 ++--- lib_com/prot_fx.h | 69 +++++---- lib_enc/ivas_enc.c | 102 +++++++------ lib_enc/ivas_masa_enc.c | 245 +++++++++++++++++++++++++++++- lib_enc/ivas_qmetadata_enc.c | 277 ++++++++++++++++++++-------------- lib_enc/ivas_qspherical_enc.c | 9 +- lib_enc/lib_enc.c | 112 +++++++++++++- lib_rend/ivas_efap.c | 17 ++- 17 files changed, 872 insertions(+), 408 deletions(-) diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c index 1af3286bf..15dcfc0be 100644 --- a/lib_com/ACcontextMapping.c +++ b/lib_com/ACcontextMapping.c @@ -67,21 +67,21 @@ int16_t get_next_coeff_mapped_ivas( } #else Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { UWord32 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); - p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); - *pp = p; + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ + p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); /* Q0 */ + *pp = p; /* Q0 */ move32(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index d55bcd6ac..9fa89cb7e 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -11,15 +11,15 @@ /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { Word16 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ if ( p > 0 ) { p = 0; @@ -30,63 +30,69 @@ Word16 get_next_coeff_mapped( p = 1; move16(); } - *pp = p; + *pp = p; /* Q0 */ move16(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; } /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { (void) pp; (void) hm_cfg; - *idx = ii[0]; + *idx = ii[0]; /* Q0 */ move16(); - ii[0] = add( ii[0], 1 ); + ii[0] = add( ii[0], 1 ); /* Q0 */ move16(); return *idx; } -Word16 update_mixed_context( Word16 ctx, Word16 a ) +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; Word16 t = 0; /* initialize just to avoid compiler warning */ - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ if ( t32 <= 0 ) { - t = extract_l( t32 ); + t = extract_l( t32 ); /* Q0 */ } a = shr( a, 3 ); if ( t32 > 0 ) { - t = s_min( a, 2 ); + t = s_min( a, 2 ); /* Q0 */ } return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) ); } #ifdef IVAS_FLOAT_FIXED -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ) +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ - a = shr( a, 3 ); + a = shr( a, 3 ); /* Q0 */ IF( t32 > 0 ) { - t32 = L_min( a, 2 ); + t32 = L_min( a, 2 ); /* Q0 */ } return L_add( L_shl( L_and( ctx, 0xf ), 4 ), L_add( t32, 13 ) ); } diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index 3b36d10b3..aef9a6635 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -39,7 +39,10 @@ Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ) * * \return r*c */ -Word32 mul_sbc_14bits( Word32 r, Word16 c ) +Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +) { Word32 ret; diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index 8306376e2..159660927 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -101,12 +101,13 @@ void UnmapIndex_ivas( } void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -114,54 +115,54 @@ void UnmapIndex_fx( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ } } @@ -262,19 +263,20 @@ int16_t CountIndexBits_ivas( } Word16 CountIndexBits_fx( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; - result = 8; + result = 8; /* Q0 */ move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -290,9 +292,9 @@ Word16 CountIndexBits_fx( *-------------------------------------------------------------------*/ Word16 tcx_hm_render_ivas( - const Word16 lag, /* i : pitch lag */ - const Word16 fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ) { Word16 k; @@ -305,14 +307,14 @@ Word16 tcx_hm_render_ivas( tmp32 = Mpy_32_16_1( f0, -26474 ); tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( sub( 13915, PeakDeviation ) > 0 ) { @@ -321,22 +323,22 @@ Word16 tcx_hm_render_ivas( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ } return 0; @@ -356,15 +358,15 @@ Word32 tcx_hm_render_fx( f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ tmp32 = Mpy_32_16_1( f0, -26474 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -373,12 +375,12 @@ Word32 tcx_hm_render_fx( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; @@ -386,12 +388,12 @@ Word32 tcx_hm_render_fx( 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 ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -405,12 +407,12 @@ Word32 tcx_hm_render_fx( *-------------------------------------------------------------------*/ void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const Word16 lag, - const Word16 fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const Word16 L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ) { Word16 k, h, x; @@ -423,7 +425,7 @@ void tcx_hm_modify_envelope_ivas( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { - inv_shape[k] = div_s( 512, add( 512, round_fx( L_mult( gain, p[k] ) ) ) ); + inv_shape[k] = div_s( 512 /* 1 in Q24 */, add( 512 /* 1 in Q24 */, round_fx( L_mult( gain, p[k] ) ) ) ); /* Q15 */ move16(); } @@ -435,11 +437,11 @@ void tcx_hm_modify_envelope_ivas( FOR( x = max( 0, k - kTcxHmParabolaHalfWidth ); x <= min( k + kTcxHmParabolaHalfWidth, L_frame - 1 ); ++x ) { - env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[x - k + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - ++h; - k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); /* Q0 */ } return; @@ -465,7 +467,7 @@ void tcx_hm_modify_envelope_fx( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); /* Q15 */ move16(); } @@ -473,21 +475,21 @@ void tcx_hm_modify_envelope_fx( move16(); k = extract_l( L_shr( lag, fract_res ) ); - L_frame_m1 = sub( L_frame, 1 ); - L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); + L_frame_m1 = sub( L_frame, 1 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ - WHILE( LE_16( k, L_frame_for_loop ) ) + WHILE( k <= L_frame_for_loop ) { - l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); - l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); + l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); /* Q0 */ + l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); /* Q0 */ 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[x - k + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 767aea860..ea0c59972 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -13,12 +13,13 @@ #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -26,65 +27,65 @@ void UnmapIndex( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][sub( Multiplier, 1 )] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ move32(); } } void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ) { Word8 Bandwidth, SmallerLags; @@ -97,7 +98,7 @@ void ConfigureContextHm( move16(); if ( GE_16( NumCoeffs, 256 ) ) { - Bandwidth = 1; + Bandwidth = 1; /* Q0 */ move16(); } @@ -106,7 +107,7 @@ void ConfigureContextHm( test(); if ( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) { - SmallerLags = 1; + SmallerLags = 1; /* Q0 */ move16(); } @@ -117,28 +118,28 @@ void ConfigureContextHm( &FractionalResolution, &Lag ); /* Set up and fill peakIndices */ - hm_cfg->peakIndices = hm_cfg->indexBuffer; - tmp = hm_cfg->peakIndices; - Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); + hm_cfg->peakIndices = hm_cfg->indexBuffer; /* Q0 */ + tmp = hm_cfg->peakIndices; /* Q0 */ + Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); /* Q0 */ IF( LT_32( Lag, Limit ) ) { FOR( i = Lag; i < Limit; i += Lag ) { - Index = extract_l( L_shr( i, FractionalResolution ) ); - *tmp++ = sub( Index, 1 ); + Index = extract_l( L_shr( i, FractionalResolution ) ); /* Q0 */ + *tmp++ = sub( Index, 1 ); /* Q0 */ move16(); - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); - *tmp++ = add( Index, 1 ); + *tmp++ = add( Index, 1 ); /* Q0 */ move16(); } } - hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); + hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); /* Q0 */ move16(); /* Set up and fill holeIndices */ - hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; - tmp = hm_cfg->holeIndices; + hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; /* Q0 */ + tmp = hm_cfg->holeIndices; /* Q0 */ Index = 0; move16(); IF( hm_cfg->numPeakIndices > 0 ) @@ -147,7 +148,7 @@ void ConfigureContextHm( { FOR( ; Index < hm_cfg->peakIndices[j]; ++Index ) { - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); } Index = add( Index, 3 ); /* Skip the peak */ @@ -168,19 +169,20 @@ void ConfigureContextHm( } Word16 CountIndexBits( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; result = 8; move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -202,15 +204,15 @@ Word32 tcx_hm_render( f0 = L_shl( lag, sub( 15, fract_res ) ); /* Q31 */ tmp32 = Mpy_32_16_1( f0, -26474 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 603979776L, tmp32 ); - tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); - height = round_fx( tmp32 ); /* Q13 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); /* Q29 */ + height = round_fx( tmp32 ); /* Q13 */ tmp32 = Mpy_32_16_1( f0, -18910 ); - tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); - tmp32 = L_sub( 1395864371L, tmp32 ); - PeakDeviation = round_fx( tmp32 ); /* Q14 */ + tmp32 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -219,26 +221,26 @@ Word32 tcx_hm_render( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); 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 ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( i_mult2( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ move16(); } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -265,16 +267,16 @@ void tcx_hm_modify_envelope( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); + inv_shape[k] = div_s( 512, add( 512, mult_r( gain, p[k] ) ) ); /* Q15 */ move16(); } h = 1; move16(); - k = extract_l( L_shr( lag, fract_res ) ); + k = extract_l( L_shr( lag, fract_res ) ); /* Q0 */ - L_frame_m1 = sub( L_frame, 1 ); - L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); + L_frame_m1 = sub( L_frame, 1 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ WHILE( LE_16( k, L_frame_for_loop ) ) { @@ -282,11 +284,11 @@ 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[add( sub( x, k ), kTcxHmParabolaHalfWidth )] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[( x - k ) + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 9568ab75a..4eae5458f 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -70,7 +70,7 @@ static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead * * Conduct complex multiplication *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void cplxMult( float *yr, /* o : real output */ float *yi, /* o : imag output */ @@ -85,14 +85,14 @@ static void cplxMult( return; } - +#endif /*-------------------------------------------------------------------* * cldfbAnalysis_ivas() * * Conduct multiple overlap complex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas( const float *timeIn, /* i : time buffer */ float **realBuffer, /* o : real value buffer */ @@ -260,7 +260,7 @@ void cldfbAnalysis_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ @@ -477,7 +477,7 @@ void cldfbAnalysis_ivas_fx( * * *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_ivas( const float *timeIn, /* i : time buffer */ float realBuffer[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ @@ -691,7 +691,7 @@ void cldfbAnalysis_ts_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_fx( const Word32 *timeIn_fx, @@ -1238,7 +1238,7 @@ void cldfbAnalysis_ts_fx_fixed_q( * * Conduct inverse multple overlap cmplex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas( float **realBuffer, /* i : real values */ float **imagBuffer, /* i : imag values */ @@ -1419,6 +1419,7 @@ void cldfbSynthesis_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas_fx( Word32 **realBuffer_fx, /* i : real values Qx*/ @@ -3390,7 +3391,7 @@ void cldfb_restore_memory_ivas( * * Resets the memory of filter. *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfb_reset_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -3412,6 +3413,7 @@ void cldfb_reset_memory_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfb_reset_memory_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a9ca1f48d..4a0e4ddb1 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3524,4 +3524,27 @@ void ivas_masa_estimate_energy_fx( const Word16 nchan_transport, /* i : number of MASA input/transport channels */ Word16 q_data /* i : q for data_fx */ ); + +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_masa_encode_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word16 *nb_bits_metadata, /* o : number of metadata bits written */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 Opt_DTX_ON, /* i : DTX on flag */ + const Word16 element_mode, /* i : element mode */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const Word16 nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const Word16 idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const Word16 ism_imp, /* i : importance of separated object */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index a16a4be54..552adb118 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,26 +177,13 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef MSAN_FIX - set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif -#else set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef MSAN_FIX set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif -#endif -#ifdef IVAS_FLOAT_FIXED set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#else - set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif } } @@ -1193,8 +1180,8 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( } #else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth */ - const Word32 el, /* i : elevation */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ Word32 *dv /* o : direction vector */ ) { diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index db931df0f..4c15510fe 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -293,14 +293,20 @@ void small_reduction_direction( { Word16 i, j, k; + test(); FOR( k = 0; ( k < 2 ) && ( *diff > 0 ); k++ ) { + test(); + test(); FOR( i = q_direction->cfg.start_band; ( i < q_direction->cfg.nbands ) && ( *diff > 0 ); i++ ) { + test(); IF( EQ_16( raw_flag[i], 1 ) ) { + test(); FOR( j = 0; ( j < q_direction->cfg.nblocks ) && ( *diff > 0 ); j++ ) { + test(); IF( GT_32( bits_dir[i][j], MASA_MIN_BITS_TF ) ) { bits_dir[i][j] = (UWord16) L_sub( bits_dir[i][j], 1 ); @@ -569,7 +575,7 @@ ELSE } } -*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +*phi_hat = L_add_sat( L_add_sat( ( imult3216( delta_phi_fx, id_phi ) ), dd_fx ), DEGREE_180_Q_22 ); move32(); id_phi = add( id_phi, shr( n, 1 ) ); diff --git a/lib_com/prot.h b/lib_com/prot.h index d286851e0..f895ef5f2 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7926,12 +7926,13 @@ void UnmapIndex_ivas( int32_t *Lag ); void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ); + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); /*! r: PeriodicityIndex */ int16_t SearchPeriodicityIndex( @@ -7962,8 +7963,9 @@ int16_t CountIndexBits_ivas( const int16_t PeriodicityIndex ); Word16 CountIndexBits_fx( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex ); + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); int16_t DecodeIndex( Decoder_State *st, @@ -7973,10 +7975,10 @@ int16_t DecodeIndex( #define GET_ADJ( T, L ) GET_ADJ2( T, L, *FractionalResolution ) #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) -int16_t tcx_hm_render_ivas( - const int16_t lag, /* i : pitch lag */ - const int16_t fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ +Word16 tcx_hm_render_ivas( + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ); Word32 tcx_hm_render_fx( @@ -7986,12 +7988,12 @@ Word32 tcx_hm_render_fx( ); void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const int16_t L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ); void tcx_hm_modify_envelope_fx( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a148ab903..942135fbd 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5704,7 +5704,10 @@ Word16 IGFCommonFuncsIGFGetCFTables( ); // ari_fx.c Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ); -Word32 mul_sbc_14bits( Word32 r, Word16 c ); +Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +); // window.c void ham_cos_window( Word16 *fh, const Word16 n1, const Word16 n2 ); @@ -8750,26 +8753,28 @@ void getLPCparam_fx( // ari_hm_fx.c void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ); + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); void ConfigureContextHm( - const Word16 NumCoeffs, /* (I) Number of coefficients */ - const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - const Word16 PeriodicityIndex, /* (I) Pitch related index */ - const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ + const Word16 NumCoeffs, /* (I) Number of coefficients Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ); Word16 CountIndexBits( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex ); + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); -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 */ @@ -9035,23 +9040,29 @@ void lsf_weight_2st( const Word16 *lsfq, /* i : quantized lsf coefficients (3Q1 /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); -Word16 update_mixed_context( Word16 ctx, Word16 a ); +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +); -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ); +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +); // ACcontextMapping_dec_fx.c @@ -10847,10 +10858,10 @@ ivas_error push_next_bits( /*! r: index of next coefficient */ Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); void RCcontextMapping_encode2_no_mem_s17_LCS_fx( diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c3b8c7cbc..1a5a95af5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -632,7 +632,7 @@ ivas_error ivas_enc( #else ivas_error ivas_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 *data, /* i : input signal */ + const Word16 *data, /* i : input signal Q0 */ const Word16 n_samples /* i : number of input samples */ ) { @@ -642,7 +642,9 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Word16 nb_bits_metadata[MAX_SCE + 1]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#endif Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 ivas_total_brate; ivas_error error; @@ -685,7 +687,9 @@ ivas_error ivas_enc( FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed +#endif data_fx[n] = st_ivas->p_data_fx[n]; } @@ -697,8 +701,10 @@ ivas_error ivas_enc( { FOR( i = 0; i < n_samples_chan; i++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed - data_fx[n][i] = L_mult0( data[add( imult1616( i, nchan_inp ), n )], shl( 1, st_ivas->q_data_fx ) ); +#endif + data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } n = add( n, 1 ); @@ -708,7 +714,9 @@ ivas_error ivas_enc( { FOR( n = 0; n < nchan_inp; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed +#endif set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); } } @@ -741,19 +749,11 @@ ivas_error ivas_enc( test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) { -#ifndef IVAS_FLOAT_FIXED - hp20_flt( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); -#else hp20_fix32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) { -#ifndef IVAS_FLOAT_FIXED - hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); // To be removed -#else hp20_fix32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } } @@ -768,11 +768,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - ivas_write_format( st_ivas ); -#else ivas_write_format_fx( st_ivas ); -#endif + /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ @@ -850,20 +847,28 @@ ivas_error ivas_enc( } } } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { /* MASA configuration */ - if ( ivas_format == MASA_FORMAT ) + IF( EQ_32( ivas_format, MASA_FORMAT ) ) { - ivas_masa_enc_reconfigure( st_ivas ); + ivas_masa_enc_reconfigure_fx( st_ivas ); } /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */ + IF( st_ivas->nSCE > 0 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } + ELSE + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } - if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + test(); + IF( st_ivas->hQMetaData != NULL && EQ_32( ivas_format, MASA_FORMAT ) ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < st_ivas->nchan_transport; i++ ) { @@ -879,65 +884,68 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + + IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } -#endif // IVAS_FLOAT_FIXED - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + ELSE { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } } - else if ( ivas_format == SBA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } } - if ( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { ivas_sba_getTCs( data_f, st_ivas, input_frame ); } /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { float *data_separated_object; Word32 *data_separated_object_fx; @@ -1085,8 +1093,8 @@ ivas_error ivas_enc( } /* Encode MASA parameters and write MASA metadata bitstream */ - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1360,8 +1368,8 @@ ivas_error ivas_enc( #else ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); #endif - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a8375d542..9b975d935 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -172,7 +172,132 @@ static void masa_metadata_direction_alignment( MASA_ENCODER_HANDLE hMasa ); * * open and initialize MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_masa_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + Word16 i; + MASA_ENCODER_HANDLE hMasa; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word32 ism_total_brate; + + error = IVAS_ERR_OK; + move32(); + + IF( ( hMasa = (MASA_ENCODER_HANDLE) malloc( sizeof( MASA_ENCODER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); + } + + hEncoderConfig = st_ivas->hEncoderConfig; + + generate_gridEq_fx( &( hMasa->data.Sph_Grid16 ) ); + + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_FORMAT ) || EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + hMasa->data.num_Cldfb_instances = st_ivas->nchan_transport; + move16(); + } + ELSE + { + hMasa->data.num_Cldfb_instances = 0; + move16(); + } + + FOR( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) + { + IF( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + } + } + + ivas_masa_set_elements_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + + Copy( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); + + hMasa->data.onset_detector_1_fx = 0; + hMasa->data.onset_detector_2_fx = 0; + hMasa->data.q_onset_detector = 0; + move32(); + move32(); + move16(); + + set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + move32(); + + hMasa->data.prevq_lfeIndex = 0; + move16(); + + hMasa->data.sync_state.prev_sim_stop = 0; + hMasa->data.sync_state.prev_offset = 0; + hMasa->data.sync_state.frame_mode = MASA_FRAME_4SF; + move16(); + move16(); + move32(); + + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); + + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + OMASA_ENCODER_DATA_HANDLE hOmasaData; + + IF( ( hOmasaData = (OMASA_ENCODER_DATA_HANDLE) malloc( sizeof( OMASA_ENCODER_DATA_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); + } + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + } + + hOmasaData->lp_noise_CPE_fx = -256; /* -1 in Q8 */ + move16(); + hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + move16(); + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); + set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); + } + + hMasa->data.hOmasaData = hOmasaData; + } + ELSE + { + hMasa->data.hOmasaData = NULL; + } + + st_ivas->hMasa = hMasa; + return error; +} +#else ivas_error ivas_masa_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -326,14 +451,43 @@ ivas_error ivas_masa_enc_open( return error; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_enc_close() * * close MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_enc_close( + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ +) +{ + Word16 i; + test(); + IF( hMasa == NULL || *hMasa == NULL ) + { + return; + } + + FOR( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) + { + deleteCldfb_ivas( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); + } + + IF( ( *hMasa )->data.hOmasaData != NULL ) + { + free( ( *hMasa )->data.hOmasaData ); + ( *hMasa )->data.hOmasaData = NULL; + } + + free( ( *hMasa ) ); + ( *hMasa ) = NULL; + + return; +} +#else void ivas_masa_enc_close( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ) @@ -361,7 +515,7 @@ void ivas_masa_enc_close( return; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_encode() @@ -370,7 +524,7 @@ void ivas_masa_enc_close( *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_masa_encode( +ivas_error ivas_masa_encode_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -1620,6 +1774,7 @@ ivas_error ivas_masa_enc_config_fx( maxBin = extract_l( Mpy_32_32( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_CLDFB_BANDWIDTH_Q31 /*Q31*/ ) ); /*q0+q31-q31->q0*/ maxBand = 0; move16(); + test(); WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) { test(); @@ -1645,6 +1800,7 @@ ivas_error ivas_masa_enc_config_fx( Word16 continueLoop; continueLoop = 1; move16(); + test(); WHILE( GT_16( maxBand, 5 ) && continueLoop ) { test(); @@ -2862,7 +3018,7 @@ void ivas_masa_combine_directions_fx( move32(); } - if ( numSf != 1 ) + IF( NE_16( numSf, 1 ) ) { importance_fx[i] = L_shr( importance_fx[i], 2 ); move32(); @@ -4777,7 +4933,7 @@ static int16_t encode_lfe_to_total_energy_ratio( * * Reconfigure IVAS MASA encoder *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -4845,7 +5001,86 @@ void ivas_masa_enc_reconfigure( return; } +#else +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, tmp; + Word16 sce_id, cpe_id; + Word32 ivas_total_brate; + Word32 ism_total_brate; + Word32 tmp_br, tmp_mod; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[sce_id]->element_brate ); + } + } + + IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp_mod, 0 ); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = tmp_br; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + move32(); + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp_br, 2 ); //( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + + IF( st_ivas->nCPE > 1 ) + { + tmp = 1; + } + ELSE + { + tmp = CPE_CHANNELS; + } + move16(); + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); */ + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, sub( tmp, 1 ) ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + + IF( LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + } + ELSE + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } + move16(); + } + + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + } + + return; +} +#endif /*-------------------------------------------------------------------* * average_masa_metadata() diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bde299111..f34ae9ef0 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -558,7 +558,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( move16(); /* This sets bit budget correctly for the second direction */ - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { bits_diff[d] = bits_diff_sum; move16(); @@ -714,6 +714,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( } /* Requantized directions */ + test(); IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { @@ -1447,7 +1448,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( Word16 ndirections, d; Word16 all_coherence_zero; Word16 bits_ec; - Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; // Q22 ivas_error error; error = IVAS_ERR_OK; @@ -1487,7 +1488,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( move16(); FOR( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { - IF( hQMetaData->twoDirBands[i] == 1 ) + IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); @@ -1620,7 +1621,7 @@ void ivas_qmetadata_enc_sid_encode_fx( const Word16 ivas_format /* i : IVAS format */ ) { - Word16 b, m; + Word16 b, m, i; Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; Word16 nbands, nblocks, start_band; @@ -1717,8 +1718,10 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta > 0 ) { + test(); FOR( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) { + test(); IF( LT_16( q_direction->band_data[b].bits_sph_idx[0], 11 ) ) { bits_delta = sub( bits_delta, 1 ); @@ -1732,7 +1735,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1741,15 +1744,17 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta < 0 ) { + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( GE_16( q_direction->band_data[b].bits_sph_idx[0], 4 ) ) { bits_delta = add( bits_delta, 1 ); q_direction->band_data[b].bits_sph_idx[0] = sub( q_direction->band_data[b].bits_sph_idx[0], 1 ); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1765,10 +1770,11 @@ void ivas_qmetadata_enc_sid_encode_fx( bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; move16(); + move16(); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } @@ -1784,8 +1790,11 @@ void ivas_qmetadata_enc_sid_encode_fx( test(); WHILE( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) { + test(); + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( LT_16( q_direction->band_data[b].energy_ratio_index[0], ( DIRAC_DIFFUSE_LEVELS - 1 ) ) ) { bits_delta = add( bits_delta, q_direction->band_data[b].bits_sph_idx[0] ); @@ -1814,7 +1823,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { /*compute the average direction */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - FOR( int i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); move32(); @@ -2227,13 +2236,13 @@ Word16 quantize_direction2D_fx( IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - id_phi = quantize_phi_chan_compand_fx( L_add( phi, 180 << Q22 ), phi_q, no_cw, 0, mc_format ); + id_phi = quantize_phi_chan_compand_fx( L_add( phi, DEGREE_180_Q_22 ), phi_q, no_cw, 0, mc_format ); } ELSE { - id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, phi_q, no_cw ); } - *phi_q = L_sub( *phi_q, 180 << Q22 ); + *phi_q = L_sub( *phi_q, DEGREE_180_Q_22 ); move32(); *index_phi = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_cw, 1 ) ) ); @@ -2517,10 +2526,10 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( #ifdef IVAS_FLOAT_FIXED static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t *nbits_diff, - int16_t *dfRatioBits, - const int16_t hodirac_flag ) + Word16 *needed_bits, + Word16 *nbits_diff, + Word16 *dfRatioBits, + const Word16 hodirac_flag ) { Word16 j, k, dir2band; Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; @@ -2531,10 +2540,16 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( needed_bits[0] = 0; needed_bits[1] = 0; dir2band = 0; + move16(); + move16(); + move16(); + move16(); + move16(); FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { - IF( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + test(); + IF( EQ_16( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { Word32 diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; /* Q30 */ Word32 dirRatio1, dirRatio2, sumRatio; /* Q30 */ @@ -2547,22 +2562,34 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { /* already encoded as total and ratios in HO-DirAC */ - diffRatio = ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; + diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; + move32(); + move32(); } ELSE { - // TODO dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; - sumRatio = dirRatio1 + dirRatio2; - diffRatio = ( 1 << 30 ) - sumRatio; - dfRatio = sumRatio < EPSILON_FIX ? ( 1 << 29 ) : ( (Word32) div_l( dirRatio1, extract_h( sumRatio ) ) << 15 ); + move32(); + move32(); + sumRatio = L_add( dirRatio1, dirRatio2 ); + diffRatio = L_sub( ONE_IN_Q30, sumRatio ); + IF( LT_32( sumRatio, EPSILON_FIX ) ) + { + dfRatio = ONE_IN_Q30 / 2; // 0.5 in Q30 + move32(); + } + ELSE + { + dfRatio = L_shl( L_deposit_l( div_l( dirRatio1, extract_h( sumRatio ) ) ), 15 ); // Q30 + } } index_diff = masa_sq_fx( diffRatio, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - diffRatioQ = diffuseness_reconstructions_fx[index_diff]; + diffRatioQ = diffuseness_reconstructions_fx[index_diff]; // Q30 + move32(); IF( hodirac_flag ) { @@ -2574,29 +2601,29 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( } dfRatioBits[dir2band] = dfRatio_bits; + move16(); - dfRatio_qsteps = ( 1 << dfRatio_bits ); + dfRatio_qsteps = shl( 1, dfRatio_bits ); IF( hodirac_flag ) { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 2 ), dfRatio_qsteps ); - dfRatioQ = (Word32) dfRatioQ16 << 16; - dirRatio1Q = ( 1 << 30 ) - diffRatioQ; + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ) /* Q13 */, dfRatio_qsteps ); + dfRatioQ = L_deposit_h( dfRatioQ16 ); // Q30 + dirRatio1Q = L_sub( ONE_IN_Q30, diffRatioQ ); // Q30 dirRatio2Q = dfRatioQ; + move32(); } ELSE { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ( 1 << 13 ), ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 3 ), dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ONE_IN_Q13, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ) /* Q12 */, dfRatio_qsteps ); /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ - dirRatio1Q = L_shl( Mpy_32_16_1( ( ( 1 << 30 ) - diffRatioQ ), dfRatioQ16 ), 1 ); - dirRatio2Q = ( ( 1 << 30 ) - diffRatioQ ) - dirRatio1Q; + dirRatio1Q = L_shl( Mpy_32_16_1( L_sub( ONE_IN_Q30, diffRatioQ ), dfRatioQ16 ), 1 ); // Q30 + dirRatio2Q = L_sub( L_sub( ONE_IN_Q30, diffRatioQ ), dirRatio1Q ); // Q30 } - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio1Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio1Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are @@ -2605,26 +2632,31 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; + move16(); + move32(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); IF( hodirac_flag ) { - // TODO Word16 tmp; /* Q14 */ - index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, ( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ) >> 2 ), DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, shr( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ), 2 ) /* Q13 */, DIRAC_DIFFUSE_LEVELS ); } - else + ELSE { - index_dirRatio2Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio2Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio2Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); } FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; + move16(); + move32(); } - nbits_diff[1] += dfRatio_bits; + nbits_diff[1] = add( nbits_diff[1], dfRatio_bits ); + move16(); /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values @@ -2636,33 +2668,45 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; + move16(); + move16(); } - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv_mod] ) ); + move16(); FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; + move16(); + move16(); } - needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + needed_bits[1] = add( needed_bits[1], imult1616( hQMetaData->q_direction[1].cfg.nblocks, bits_direction_masa[index_dirRatio2Inv_mod] ) ); + move16(); - dir2band++; + dir2band = add( dir2band, 1 ); } ELSE { - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0], diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = ( 1 << 30 ) - diffuseness_reconstructions_fx[index_dirRatio1Inv]; + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; + move16(); + move16(); + move32(); + move16(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv] ) ); + move16(); } } @@ -2836,7 +2880,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( { IF( idx > 0 ) { - push_next_indice( hMetaData, ( 1 << idx ) - 1, idx ); + push_next_indice( hMetaData, (UWord16) L_sub( L_shl( 1, idx ), 1 ), idx ); nbits = add( nbits, idx ); } push_next_indice( hMetaData, 0, 1 ); @@ -2845,7 +2889,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( ELSE { push_next_indice( hMetaData, 511, DIFF_EC_HUFF_GR0_LIMIT + 1 ); - push_next_indice( hMetaData, idx - DIFF_EC_HUFF_GR0_LIMIT - 1, 2 ); + push_next_indice( hMetaData, (UWord16) L_sub( idx, DIFF_EC_HUFF_GR0_LIMIT + 1 ), 2 ); nbits = add( nbits, DIFF_EC_HUFF_GR0_LIMIT + 3 ); } return nbits; @@ -2934,6 +2978,7 @@ static void ivas_diffuseness_huff_ec_prepare_fx( { ui_sh_idx[b] = sub( shl( sh_idx, 1 ), 1 ); } + move16(); if ( GE_32( ui_sh_idx[b], 2 * DIRAC_DIFFUSE_LEVELS - 3 ) ) { bits = 100; /* to avoid difference larger than 6 in absolute value */ @@ -3372,7 +3417,7 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( IF( EQ_16( min_index, max_index ) && ec_mode > 0 ) /* all values are equal */ { push_next_indice( hMetaData, 0, 1 ); /* Signal between EC and raw */ - if ( GT_16( ec_mode, 1 ) ) + IF( GT_16( ec_mode, 1 ) ) { /* Only use bit for signaling if necessary */ push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ @@ -3384,11 +3429,11 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( { push_next_indice( hMetaData, 0, 1 ); push_next_indice( hMetaData, 1, 1 ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size - 1 ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, sub( max_alphabet_size, 1 ) ); FOR( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_index, 1 ); /* Band-wise offset values */ + push_next_indice( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], min_index ), 1 ); /* Band-wise offset values */ } } ELSE /* raw coding */ @@ -3747,7 +3792,7 @@ static Word16 GR_bits_azimuth_context( move16(); FOR( i = 0; i < no_data_in; i++ ) { - IF( data_in[i] < MASA_NO_INDEX ) + IF( LT_32( data_in[i], MASA_NO_INDEX ) ) { no_symb_local[no_data] = no_symb[i]; move16(); @@ -4257,7 +4302,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4398,9 +4443,9 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); IF( GE_16( sub( nbands, start_band ), 5 ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 + use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, DEGREE_180_Q_22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4526,7 +4571,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); test(); test(); - if ( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) { azimuth_bits_ec_best = add( azimuth_bits_ec_best, 1 ); } @@ -4598,7 +4643,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( IF( NE_16( gr_param_azimuth_best, 5 ) ) /* not all zero */ { - FOR( idx = 0; idx < min( nblocks, dist_count ); idx++ ) + FOR( idx = 0; idx < s_min( nblocks, dist_count ); idx++ ) { test(); test(); @@ -5739,6 +5784,18 @@ static Word16 truncGR0_fx( Word32 diff_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 indx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 L_temp; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); bits = 0; move16(); set_val_Word32( data_hat_fx, 0, len ); @@ -5781,7 +5838,7 @@ static Word16 truncGR0_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 8, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[i] - data_hat[i] ) ); /*(data[i] - data_hat[i])*(data[i] - data_hat[i]);*/ L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5807,7 +5864,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } IF( LE_16( bits, bits_allowed ) ) @@ -5848,7 +5905,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5866,7 +5923,7 @@ static Word16 truncGR0_fx( FOR( i = len - 1; i >= 0; i-- ) { - if ( data_idx[indx[i]] > 0 ) + IF( data_idx[indx[i]] > 0 ) { bits = sub( bits, data_idx[indx[i]] ); data_idx[indx[i]] = 0; @@ -6070,7 +6127,7 @@ static Word16 truncGR0_chan_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 9, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( ( data[i] - data_hat[i] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -6083,18 +6140,18 @@ static Word16 truncGR0_chan_fx( move16(); idx_crt = -1; move16(); - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); FOR( i = 0; i < len; i++ ) { IF( data_idx[i] > 0 ) { // sort_diff[i] = -st[i] - ct[i] * cosf( ( fabsf( data[i] ) - cb_azi_chan[( ( data_idx[i] + 1 ) >> 1 ) - 1] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( L_abs( data_fx[i] ), cb_azi_chan_fx[( ( data_idx[i] + 1 ) >> 1 ) - 1] ), 91 ), 7 ) ) ) ); // Q31 - sort_diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 // Q30 + sort_diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); sum_diff_fx = sum2_f_32_fx( sort_diff_fx, len, gb ); // Q(2*Q30-31-gb)= Q(Q29-gb) Word16 flag = BASOP_Util_Cmp_Mant32Exp( sum_diff_fx, sub( Q31, sub( Q29, gb ) ), min_diff_fx, min_diff_e ); - if ( EQ_16( flag, -1 ) ) + IF( EQ_16( flag, -1 ) ) { min_diff_fx = sum_diff_fx; move32(); @@ -6116,7 +6173,7 @@ static Word16 truncGR0_chan_fx( // diff[idx_crt] = -st[idx_crt] - ct[idx_crt] * cosf( ( data[idx_crt] - data_hat[idx_crt] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[idx_crt], data_hat_fx[idx_crt] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[idx_crt] = -L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ); // Q30 + diff_fx[idx_crt] = L_negate( L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ) ); // Q30 move32(); } ELSE @@ -6127,7 +6184,7 @@ static Word16 truncGR0_chan_fx( IF( GT_16( bits, bits_allowed ) ) { - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); sort_desc_ind_32_fx( sort_diff_fx, len, indx ); FOR( i = len - 1; i >= 0; i-- ) @@ -6360,7 +6417,7 @@ static Word16 common_direction_fx( // dist += ( elevation_orig[k] - theta_cb[i] ) * ( elevation_orig[k] - theta_cb[i] ); dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( L_sub( elevation_orig_fx[k], theta_cb_fx[i] ), L_sub( elevation_orig_fx[k], theta_cb_fx[i] ) ), gb ) ); // Q(2*Q22-31) = Q13-gb } - if ( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) + IF( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) { id_th = i; move16(); @@ -6706,7 +6763,7 @@ static Word16 encode_directions_subband_fx( move16(); FOR( k = 0; k < no_subframes; k++ ) { - if ( GT_16( bits_dir0[k], use_vq ) ) + IF( GT_16( bits_dir0[k], use_vq ) ) { use_vq = bits_dir0[k]; move16(); @@ -6717,7 +6774,8 @@ static Word16 encode_directions_subband_fx( IF( GT_16( no_subframes, 1 ) ) { - if ( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) + test(); + IF( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) { bits_dir0[max_nb_idx] = sub( bits_dir0[max_nb_idx], 1 ); move16(); @@ -6753,8 +6811,8 @@ static Word16 encode_directions_subband_fx( IF( last_subband == 0 ) { - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); joint_encoding_fx( q_direction, j, next_j, coding_subbands, bits_dir0, allowed_bits, hMetaData, &diff ); } ELSE @@ -6777,8 +6835,8 @@ static Word16 encode_directions_subband_fx( ELSE { /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -6805,8 +6863,8 @@ static Word16 encode_directions_subband_fx( { /* 1 subframe case */ /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -7341,6 +7399,7 @@ static ivas_error requantize_direction_EC_3_fx( } } + test(); IF( LE_16( use_vq, 3 ) && LE_16( allowed_bits, 11 ) ) { @@ -7480,14 +7539,10 @@ static void joint_encoding_fx( q_direction->band_data[j].bits_sph_idx[k] = bits_dir0[k]; move16(); -/* requantize the direction */ -#if 1 + /* requantize the direction */ q_direction->band_data[j].spherical_index[k] = quantize_direction_fx( q_direction->band_data[j].elevation_fx[k], q_direction->band_data[j].azimuth_fx[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation_fx[k], &q_direction->band_data[j].azimuth_fx[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#else - q_direction->band_data[j].spherical_index[k] = quantize_direction( q_direction->band_data[j].elevation[k], q_direction->band_data[j].azimuth[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation[k], - &q_direction->band_data[j].azimuth[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#endif + move16(); IF( GE_32( bits_dir0[k], 3 ) ) { @@ -7541,7 +7596,7 @@ static void joint_encoding_fx( /* encode indexes for current subband and count the number of bits */ - + test(); IF( EQ_16( q_direction->cfg.nblocks, 1 ) && LE_32( q_direction->band_data[j].bits_sph_idx[0], MASA_MIN_BITS_TF + 1 ) ) { /* encode with fixed rate only if only one subframe and very low number of bits */ @@ -7566,12 +7621,13 @@ static void joint_encoding_fx( move16(); FOR( k = 1; k < q_direction->cfg.nblocks; k++ ) { - IF( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) + if ( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) { same = 0; move16(); } } + test(); IF( EQ_16( same, 1 ) && LT_32( q_direction->band_data[j].elevation_index[0], 4 ) ) { nbits = 3; @@ -7619,6 +7675,7 @@ static void joint_encoding_fx( } } *diff = add( *diff, sub( nbits, allowed_bits ) ); + move16(); update_bits_next_block( q_direction, diff, next_j, coding_subbands, q_direction->cfg.nblocks ); return; @@ -8744,7 +8801,7 @@ static Word16 encode_spread_coherence_1sf_fx( IF( idx_ER > 0 ) { // idx_sp_coh[j] = (uint16_t) roundf( q_direction->coherence_band_data[j].spread_coherence[0] / ( 255.0f / (float) idx_ER ) ); - idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 ) ); + idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 /* 1/255.f in Q31 */ ) ); move16(); // q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( idx_sp_coh[j] * ( 255.0f / (float) idx_ER ) ); IF( idx_sp_coh[j] ) @@ -8781,12 +8838,12 @@ static Word16 encode_spread_coherence_1sf_fx( nbits_max = 0; move16(); - if ( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) + IF( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) { j = maximum_s( (Word16 *) idx_sp_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -8893,7 +8950,7 @@ static Word16 encode_spread_coherence_1sf_fx( /* write the min */ bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv, 0 ); + ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -9197,7 +9254,7 @@ static Word16 encode_surround_coherence_fx( j = maximum_s( (Word16 *) idx_sur_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -9225,7 +9282,7 @@ static Word16 encode_surround_coherence_fx( /* write max value*/ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, MASA_MAX_NO_CV_SUR_COH - max_val - 1, MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } @@ -10509,12 +10566,14 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { d = 0; + move16(); FOR( j = 0; j < coding_subbands_0; j++ ) { - if ( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) + IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - two_dir_band[d++] = j; + two_dir_band[d] = j; move16(); + d = add( d, 1 ); } } } @@ -10569,7 +10628,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( { /* make two indxes */ no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands / 2; j++ ) { @@ -10587,7 +10646,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( nbits = sub( 63, W_norm( W_sub( no_cb, 1 ) ) ); } no_cb = 1; - move16(); + move64(); FOR( j = coding_subbands / 2; j < coding_subbands; j++ ) { @@ -10607,7 +10666,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( ELSE { no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands; j++ ) { @@ -10631,17 +10690,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( FOR( j = 0; j < coding_subbands; j++ ) { /* inverse DCT transform */ - -#ifdef IVAS_FLOAT_FIXED - - /*================================flt-2-fix========================================*/ - // floatToFixed_arrL( dct_coh[j], dct_coh_fx[j], Q21, MAX_PARAM_SPATIAL_SUBFRAMES ); // Q21 is used in decoder hence chosed otherwise function can work with variable Q - /*================================fix-2-flt========================================*/ - invdct4_transform_fx( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence, Q21 ); -#else - invdct4_transform( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence ); -#endif } nbits = encode_coherence_indexesDCT0_fx( idx_dct, coding_subbands, no_cb_vec, hMetaData, *indice_coherence, nbits, nbits1 ); @@ -10665,7 +10714,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( move16(); WHILE( k > 0 ) { - push_next_indice( hMetaData, 0, min( 16, k ) ); + push_next_indice( hMetaData, 0, s_min( 16, k ) ); k = sub( k, 16 ); } } @@ -11131,23 +11180,23 @@ static void transform_azimuth_dir2_fx( FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nblocks; b++ ) { Word64 azimuth; - azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), 180 << Q22 ); + azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), DEGREE_180_Q_22 ); - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } hQMetaData->q_direction[1].band_data[i].azimuth_fx[b] = W_extract_l( azimuth ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index d2804108a..48e4bb93d 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -206,6 +206,7 @@ void quantize_direction_frame_fx( &q_direction->band_data[i].azimuth_fx[j], &q_direction->band_data[i].elevation_index[j], &q_direction->band_data[i].azimuth_index[j], q_direction->cfg.mc_ls_setup ); + move16(); q_direction->not_in_2D = add( q_direction->not_in_2D, q_direction->band_data[i].elevation_index[j] ); move16(); @@ -216,11 +217,15 @@ void quantize_direction_frame_fx( { q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3]; q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][q_direction->band_data[i].elevation_index[j]]; + move16(); + move16(); } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[0] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; + move16(); + move16(); } } ELSE @@ -234,7 +239,7 @@ void quantize_direction_frame_fx( } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[idx] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[idx] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[idx] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; move16(); move16(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 4ba0f3444..ac29e728e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -347,7 +347,62 @@ ivas_error IVAS_ENC_ConfigureForStereo( * * Configure and initialize the combined MASA and ISM encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMASAObjects( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const UWord16 numObjects, /* i : number of objects to be encoded */ + const Word16 masaVariant /* i : index specifying the number of MASA transport channels */ +) +{ + Encoder_Struct *st_ivas; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( GT_16( numObjects, MAX_NUM_OBJECTS ) ) + { + return IVAS_ERR_TOO_MANY_INPUTS; + } + st_ivas = hIvasEnc->st_ivas; + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_2CH: + st_ivas->hEncoderConfig->nchan_inp = add( CPE_CHANNELS, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_1CH: + st_ivas->hEncoderConfig->nchan_inp = add( 1, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + st_ivas = hIvasEnc->st_ivas; + + /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT; + st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); + move16(); + move16(); + + return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); +} +#else ivas_error IVAS_ENC_ConfigureForMASAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -395,6 +450,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } +#endif /*---------------------------------------------------------------------* @@ -646,7 +702,56 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( * * Configure and initialize the MASA encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMasa( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const IVAS_ENC_MASA_VARIANT masaVariant /* i : type of MASA input (either 1 or 2 channels) */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + hEncoderConfig->ivas_format = MASA_FORMAT; + move32(); + + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_1CH: + hEncoderConfig->nchan_inp = 1; + hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_2CH: + hEncoderConfig->nchan_inp = 2; + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + hIvasEnc->maxBandwidthUser = max_bwidth_user; + + error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); + + return error; +} +#else ivas_error IVAS_ENC_ConfigureForMasa( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -690,6 +795,7 @@ ivas_error IVAS_ENC_ConfigureForMasa( return error; } +#endif /*---------------------------------------------------------------------* @@ -703,12 +809,13 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ) { - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } - if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) + test(); + IF( NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) && NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { return IVAS_ERR_METADATA_NOT_EXPECTED; } @@ -2379,6 +2486,7 @@ static ivas_error setChannelAwareConfig_fx( static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ) { + test(); IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 2d0b9e08d..2871969ca 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2670,7 +2670,22 @@ static void efap_panning_fx( get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 + Word64 suma; + suma = Mpy_32_32( tmpBuff[0], tmpBuff[0] ); + FOR( i = 1; i < numChan; i++ ) + { + suma = W_add( suma, Mpy_32_32( tmpBuff[i], tmpBuff[i] ) ); + } + IF( GT_64( suma, MAX_32 ) ) + { + normTmpBuff = MAX_32; + move32(); + } + ELSE + { + normTmpBuff = W_extract_l( suma ); // Q31 + } + Word16 exp = 0; move16(); normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp -- GitLab