Commit 146b4f8e authored by Anjaneyulu Sana's avatar Anjaneyulu Sana
Browse files

Merge branch 'mct_core_encoder_updates' into 'main'

Updates in MCT core encoder path for precision improvement

See merge request !1148
parents b4a8a48f fc5fb077
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -3346,8 +3346,9 @@ void mctStereoIGF_enc_fx(
    Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2],       /* i  : MDCT spectrum for ITF                      */
    Word16 q_origSpec,                                   /* i  : Q for MDCT spectrum                        */
    Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k],   /* i/o: MDCT^2 + MDST^2 spectrum,or estimate       */
    Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i  : same as above but for inverse spect.*/
    Word16 q_powerSpec[MCT_MAX_CHANNELS],                /* i  : Q for powSpec_fx and powSpecMsInv_fx*/
    Word16 q_powerSpec[MCT_MAX_CHANNELS],                /* i  : Q for powSpec_fx                           */
    Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i  : same as powerSpec_fx but for inverse spect.*/
    Word16 q_powerSpecMsInv[MCT_MAX_CHANNELS],           /* i  : Q for powSpecMsInv_fx                      */
    Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV],   /* i  : inverse spectrum                           */
    const Word16 sp_aud_decision0[MCT_MAX_CHANNELS]      /* i  : speech audio decision                      */
);
+2 −2
Original line number Diff line number Diff line
@@ -943,9 +943,9 @@ static void IGF_CalculateEnvelope_ivas_fx(
                move16();
                sfbEnergyR = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); // sfbEnergyR_e
                sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) );
                gain = sfbEnergyR; // gain_e
                gain = L_shl( sfbEnergyR, 16 ); // gain_e
                move32();
                gain_e = add( sfbEnergyR_e, 16 );
                gain_e = sfbEnergyR_e;

                IF( element_mode > EVS_MONO )
                {
+4 −3
Original line number Diff line number Diff line
@@ -199,12 +199,13 @@ static void ivas_lfe_enc_quant_fx(
                q_lfe_abs_sum = sub( q_lfe_abs_sum, q_tmp );
            }

            tmp = BASOP_Util_Divide3232_Scale( max_value, W_extract_l( lfe_abs_sum ), &q_tmp );
            tmp = L_shl( tmp, sub( q_lfe_abs_sum, sub( 15, q_tmp ) ) ); /* Q0 (max_value / lfe_abs_sum) */
            tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( max_value, W_extract_l( lfe_abs_sum ), &q_tmp ) );
            // tmp = L_shl( tmp, sub( q_lfe_abs_sum, sub( 15, q_tmp ) ) ); /* Q0 (max_value / lfe_abs_sum) */
            q_tmp = sub( Q16, sub( q_lfe_abs_sum, sub( 15, q_tmp ) ) );

            /* log2_f(max_value / lfe_abs_sum) -> Q25 */
            tmp = BASOP_Util_Log2( tmp );
            tmp = L_add( tmp, 1040187392 ) /* (31<<25) -> 1040187392 */; /* Q25 */
            tmp = L_add( tmp, L_shl( sub( Q31, q_tmp ), Q25 ) ) /* (31<<25) -> 1040187392 */; /* Q25 */

            /* IVAS_LFE_SHIFTS_PER_DOUBLE * log2_f(max_value / lfe_abs_sum) */
            tmp = Mpy_32_16_1( tmp, IVAS_LFE_SHIFTS_PER_DOUBLE ); /* 25-15 -> Q10 */
+19 −19
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ void ivas_mct_core_enc_fx(
    Word32 inv_spectrum_long_fx[MCT_MAX_CHANNELS][L_FRAME48k]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */
    Word16 total_side_bits;
    Word16 chBitRatios[MCT_MAX_CHANNELS];
    Word16 q_powSpec[MCT_MAX_CHANNELS], q_spec, q_origSpec, tmp_s;
    Word16 q_powSpec[MCT_MAX_CHANNELS], q_powerSpecMsInv[MCT_MAX_CHANNELS], q_spec, q_origSpec, tmp_s;
    Word16 tmp_q_powSpec[L_FRAME48k], tmp_q_powSpecInv[L_FRAME48k], *tmp_q_psi[2];
    Word64 W_tmp;
    Encoder_State *sts[MCT_MAX_CHANNELS];
@@ -437,7 +437,7 @@ void ivas_mct_core_enc_fx(
                FOR( i = 0; i < L_subframeTCX; i++ )
                {
                    W_tmp = W_mac_32_32( W_mult_32_32( mdst_spectrum_fx[ch][n][i], mdst_spectrum_fx[ch][n][i] ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] );
                    tmp_s = sub( W_norm( W_tmp ), 1 );
                    tmp_s = W_norm( W_tmp );
                    W_tmp = W_shl( W_tmp, tmp_s );
                    powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp );
                    tmp_q_powSpec[( i + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -445,7 +445,7 @@ void ivas_mct_core_enc_fx(
                    move16();

                    W_tmp = W_mac_32_32( W_mult_32_32( inv_mdst_spectrum_fx[ch][n][i], inv_mdst_spectrum_fx[ch][n][i] ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] );
                    tmp_s = sub( W_norm( W_tmp ), 1 );
                    tmp_s = W_norm( W_tmp );
                    W_tmp = W_shl( W_tmp, tmp_s );
                    powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp );
                    tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -459,7 +459,7 @@ void ivas_mct_core_enc_fx(
                {
                    /* power spectrum: MDCT^2 + MDST^2 */
                    W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] );
                    tmp_s = sub( W_norm( W_tmp ), 1 );
                    tmp_s = W_norm( W_tmp );
                    W_tmp = W_shl( W_tmp, tmp_s );
                    powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp );
                    tmp_q_psi[n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -471,7 +471,7 @@ void ivas_mct_core_enc_fx(
                        mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); /* An MDST estimate */

                        W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] );
                        tmp_s = sub( W_norm( W_tmp ), 1 );
                        tmp_s = W_norm( W_tmp );
                        W_tmp = W_shl( W_tmp, tmp_s );
                        powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp );
                        tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -480,7 +480,7 @@ void ivas_mct_core_enc_fx(
                    }

                    W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] );
                    tmp_s = sub( W_norm( W_tmp ), 1 );
                    tmp_s = W_norm( W_tmp );
                    W_tmp = W_shl( W_tmp, tmp_s );
                    powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp );
                    tmp_q_psi[n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -490,7 +490,7 @@ void ivas_mct_core_enc_fx(

                /* power spectrum: MDCT^2 + MDST^2 */
                W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][0], sts[ch]->hTcxEnc->spectrum_fx[n][0] );
                tmp_s = sub( W_norm( W_tmp ), 1 );
                tmp_s = W_norm( W_tmp );
                W_tmp = W_shl( W_tmp, tmp_s );
                powerSpec_fx[ch][n * L_subframeTCX] = W_extract_h( W_tmp );
                tmp_q_powSpec[n * L_subframeTCX] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -513,7 +513,7 @@ void ivas_mct_core_enc_fx(
                }

                W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1], sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1] );
                tmp_s = sub( W_norm( W_tmp ), 1 );
                tmp_s = W_norm( W_tmp );
                W_tmp = W_shl( W_tmp, tmp_s );
                powerSpec_fx[ch][( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp );
                tmp_q_powSpec[( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
@@ -524,31 +524,31 @@ void ivas_mct_core_enc_fx(

        /* Aligning the Q-factors */
        {
            q_powSpec[ch] = Q31;
            move16();
            q_powerSpecMsInv[ch] = Q31;
            move16();
            /* NOTE: This logic has been added because using a constant headroom while computing `powSpec` and `powSpecMsInv` leads to significant precision loss, which results in poor quality. */
            FOR( i = 0; i < L_FRAME48k; i++ )
            {
                if ( powerSpec_fx[ch][i] == 0 )
                IF( powerSpec_fx[ch][i] != 0 )
                {
                    tmp_q_powSpec[i] = 63;
                    q_powSpec[ch] = s_min( q_powSpec[ch], add( tmp_q_powSpec[i], norm_l( powerSpec_fx[ch][i] ) ) );
                    move16();
                }
                if ( powerSpecMsInv_fx[ch][0][i] == 0 )
                IF( powerSpecMsInv_fx[ch][0][i] != 0 )
                {
                    tmp_q_powSpecInv[i] = 63;
                    q_powerSpecMsInv[ch] = s_min( q_powerSpecMsInv[ch], add( tmp_q_powSpecInv[i], norm_l( powerSpecMsInv_fx[ch][0][i] ) ) );
                    move16();
                }
            }
            minimum_s( tmp_q_powSpec, L_FRAME48k, &q_powSpec[ch] );
            minimum_s( tmp_q_powSpecInv, L_FRAME48k, &tmp_s );
            q_powSpec[ch] = s_min( q_powSpec[ch], tmp_s );
            move16();

            FOR( n = 0; n < nSubframes; n++ )
            {
                FOR( i = 0; i < L_subframeTCX; i++ )
                {
                    powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powSpec[ch] ) );
                    powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) );
                    powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powerSpecMsInv[ch] ) );
                    powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i + ( n * L_subframeTCX )], q_powSpec[ch] ) );
                    move32();
                    move32();
                }
@@ -606,7 +606,7 @@ void ivas_mct_core_enc_fx(
    {
        IF( hMCT->currBlockDataCnt > 0 )
        {
            mctStereoIGF_enc_fx( hMCT, sts, orig_spectrum_fx, q_origSpec, powerSpec_fx, powerSpecMsInv_fx, q_powSpec, inv_spectrum_fx, sp_aud_decision0 );
            mctStereoIGF_enc_fx( hMCT, sts, orig_spectrum_fx, q_origSpec, powerSpec_fx, q_powSpec, powerSpecMsInv_fx, q_powerSpecMsInv, inv_spectrum_fx, sp_aud_decision0 );
        }
        ELSE
        {
+15 −10
Original line number Diff line number Diff line
@@ -986,8 +986,9 @@ void mctStereoIGF_enc_fx(
    Word32 *orig_spectrum_fx[MCT_MAX_CHANNELS][2],       /* i  : MDCT spectrum for ITF                      */
    Word16 q_origSpec,                                   /* i  : Q for MDCT spectrum                        */
    Word32 powerSpec_fx[MCT_MAX_CHANNELS][L_FRAME48k],   /* i/o: MDCT^2 + MDST^2 spectrum,or estimate       */
    Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i  : same as above but for inverse spect.*/
    Word16 q_powerSpec[MCT_MAX_CHANNELS],                /* i  : Q for powSpec_fx and powSpecMsInv_fx*/
    Word16 q_powerSpec[MCT_MAX_CHANNELS],                /* i  : Q for powSpec_fx                           */
    Word32 *powerSpecMsInv_fx[MCT_MAX_CHANNELS][NB_DIV], /* i  : same as powerSpec_fx but for inverse spect.*/
    Word16 q_powerSpecMsInv[MCT_MAX_CHANNELS],           /* i  : Q for powSpecMsInv_fx                      */
    Word32 *inv_spectrum_fx[MCT_MAX_CHANNELS][NB_DIV],   /* i  : inverse spectrum                           */
    const Word16 sp_aud_decision0[MCT_MAX_CHANNELS]      /* i  : speech audio decision                      */
)
@@ -999,6 +1000,7 @@ void mctStereoIGF_enc_fx(

    Word16 b, nSubframes, L_subframeTCX;
    Word16 p_ch[2], n, ch, ch1, ch2, s = 31;
    Word16 q_pSI_ch[2];
    Word16 q_pS_ch[2];
    Encoder_State *p_st[NB_DIV];
    Encoder_State *st;
@@ -1062,7 +1064,9 @@ void mctStereoIGF_enc_fx(
            p_inv_spectrum_fx[0][n] = inv_spectrum_fx[ch1][n];
            p_inv_spectrum_fx[1][n] = inv_spectrum_fx[ch2][n];
            q_pS_ch[0] = q_powerSpec[ch1];
            q_pSI_ch[0] = q_powerSpecMsInv[ch1];
            q_pS_ch[1] = q_powerSpec[ch2];
            q_pSI_ch[1] = q_powerSpecMsInv[ch2];
            move16();
            move16();

@@ -1075,6 +1079,7 @@ void mctStereoIGF_enc_fx(
                {
                    s = s_min( s, sub( 31, p_st[ch]->hTcxEnc->spectrum_e[n] ) );
                    s = s_min( s, q_pS_ch[ch] );
                    s = s_min( s, q_pSI_ch[ch] );
                }
                FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
                {
@@ -1085,7 +1090,7 @@ void mctStereoIGF_enc_fx(
                    move16();
                    move16();

                    scale_sig32( p_powerSpecMsInv_fx[ch][0], L_FRAME48k, sub( s, q_pS_ch[ch] ) );
                    scale_sig32( p_powerSpecMsInv_fx[ch][0], L_FRAME48k, sub( s, q_pSI_ch[ch] ) );
                    scale_sig32( &p_powerSpec_fx[ch][0], sts[ch]->hTcxEnc->L_frameTCX, sub( s, q_pS_ch[ch] ) );
                    q_powerSpec[ch1] = s;
                    q_powerSpec[ch2] = s;
Loading