Commit 3700cbf5 authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Merge remote-tracking branch 'origin/main' into 3gpp_issue_1348_fix

parents 5b1e3e14 1ccc3c58
Loading
Loading
Loading
Loading
Loading
+0 −143
Original line number Diff line number Diff line
@@ -7555,146 +7555,3 @@ void rfft_fx(

    return;
}

Word16 find_guarded_bits_fx( Word32 n )
{
    // return n <= 1 ? 0 : n <= 2 ? 1
    //   : n <= 4 ? 2
    //   : n <= 8 ? 3
    //   : n <= 16 ? 4
    //   : n <= 32 ? 5
    //   : n <= 64 ? 6
    //   : n <= 128 ? 7
    //   : n <= 256 ? 8
    //   : n <= 512 ? 9
    //   : n <= 1024 ? 10
    //   : n <= 2048 ? 11
    //   : n <= 4096 ? 12
    //   : n <= 8192 ? 13
    //   : n <= 16384 ? 14
    //   : 15;
    /*Word16 val = 0;
    move32();
    test();
    WHILE( GT_32( n, L_shl( 1, val ) ) && LT_32( val, 16 ) )
    {
        val = add( val, 1 );
    }*/
    IF( LE_32( n, 1 ) )
    {
        return 0;
    }
    ELSE
    {

        return sub( 31, norm_l( L_sub( n, 1 ) ) );
    }
}

Word16 L_norm_arr( const Word32 *arr, Word16 size )
{
    Word16 q = 31;
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        Word16 q_tst;

        q_tst = norm_l( arr[i] );
        if ( arr[i] != 0 )
        {
            q = s_min( q, q_tst );
        }
    }

    return q;
}

Word16 norm_arr( Word16 *arr, Word16 size )
{
    Word16 q = 15;
    Word16 exp = 0;
    move16();
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        if ( arr[i] != 0 )
        {
            exp = norm_s( arr[i] );
        }
        if ( arr[i] != 0 )
        {
            q = s_min( q, exp );
        }
    }
    return q;
}

Word16 W_norm_arr( Word64 *arr, Word16 size )
{
    Word16 q = 63;
    Word16 exp = 0;
    move16();
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        if ( arr[i] != 0 )
        {
            exp = W_norm( arr[i] );
        }
        if ( arr[i] != 0 )
        {
            q = s_min( q, exp );
        }
    }
    return q;
}

Word16 get_min_scalefactor( Word32 x, Word32 y )
{
    Word16 scf_y;
    Word16 scf = Q31;
    move16();

    test();
    if ( x == 0 && y == 0 )
    {
        scf = 0;
        move16();
    }

    if ( x != 0 )
    {
        scf = norm_l( x );
    }

    scf_y = norm_l( y );
    if ( y != 0 )
    {
        scf = s_min( scf_y, scf );
    }

    return scf;
}


Flag is_zero_arr( Word32 *arr, Word16 size )
{
    FOR( Word16 i = 0; i < size; i++ )
    IF( arr[i] != 0 )
    {
        return 0;
    }

    return 1;
}

Flag is_zero_arr16( Word16 *arr, Word16 size )
{
    FOR( Word16 i = 0; i < size; i++ )
    IF( arr[i] != 0 )
    {
        return 0;
    }

    return 1;
}
+13 −0
Original line number Diff line number Diff line
@@ -1444,6 +1444,13 @@ void scale_sig32(
    const Word16 lg,  /* i  : size of x[]                     Q0        */
    const Word16 exp0 /* i  : exponent: x = round(x << exp)   Qx xx exp  */
);
void Scale_sig64(
    Word64 x[], /* i/o: signal to scale                 Qx        */
    Word16 len, /* i  : size of x[]                     Q0        */
    Word16 exp  /* i  : exponent: x = round(x << exp)   Qx  exp   */
);
void scale_sig32_r(
    Word32 x[],       /* i/o: signal to scale                 Qx        */
    const Word16 lg,  /* i  : size of x[]                     Q0        */
@@ -10855,8 +10862,11 @@ void ProcessStereoIGF_fx(
    Word16 q_pITFMDCTSpectrum_1,
    Word16 q_pITFMDCTSpectrum_2,
    Word32 *pPowerSpectrum_fx[CPE_CHANNELS],              /* i/o: MDCT^2 + MDST^2 spectrum, or estimate   */
    Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS],           /* i/o: exp of pPowerSpectrum_fx                */
    Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i  : inverse power spectrum                  */
    Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS],      /* i/o: exp of pPowerSpectrumMsInv_fx           */
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],        /* i  : inverse spectrum                        */
    Word16 exp_inv_spectrum_fx[CPE_CHANNELS],             /* i/o: exp of inv_spectrum_fx                  */
    const Word16 frameno,                                 /* i  : flag indicating index of current subfr. */
    const Word16 sp_aud_decision0,                        /* i  : sp_aud_decision0                        */
    const Word32 element_brate,                           /* i  : element bitrate                         */
@@ -10869,8 +10879,11 @@ void IGFEncApplyStereo_fx(
    const Word16 igfGridIdx,                              /* i  : IGF grid index                          */
    Encoder_State *sts[CPE_CHANNELS],                     /* i  : Encoder state                           */
    Word32 *pPowerSpectrum_fx[CPE_CHANNELS],              /* i/o: MDCT^2 + MDST^2 spectrum, or estimate   */
    Word16 exp_pPowerSpectrum_fx[CPE_CHANNELS],           /* i/o: exp of pPowerSpectrum_fx                */
    Word32 *pPowerSpectrumMsInv_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse power spectrum                  */
    Word16 exp_pPowerSpectrumMsInv_fx[CPE_CHANNELS],      /* i/o: exp of pPowerSpectrumMsInv_fx           */
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],        /* i  : inverse spectrum                        */
    Word16 exp_inv_spectrum_fx[CPE_CHANNELS],             /* i  : exp of inverse spectrum                 */
    const Word16 frameno,                                 /* i  : flag indicating index of current subfr. */
    const Word16 sp_aud_decision0,                        /* i  : sp_aud_decision0                        */
    const Word32 element_brate,                           /* i  : element bitrate                         */
+166 −2
Original line number Diff line number Diff line
@@ -3579,8 +3579,8 @@ Word16 erb_diff_search_fx( Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif
            }
            ELSE
            {
                dh = sub( dif_erb[i + offset], cb_fx[j * cb_dim + i] ); /* Q13 */
                Ltemp1 = L_mult( dh, dh );                              /* Q27 */
                dh = sub_sat( dif_erb[i + offset], cb_fx[j * cb_dim + i] ); /* Q13 */
                Ltemp1 = L_mult_sat( dh, dh );                              /* Q27 */
                dh = extract_h( Ltemp1 );
                dl = extract_l( Ltemp1 );

@@ -4526,3 +4526,167 @@ void v_add_fixed_me(

    return;
}

Word16 find_guarded_bits_fx( Word32 n )
{
    // return n <= 1 ? 0 : n <= 2 ? 1
    //   : n <= 4 ? 2
    //   : n <= 8 ? 3
    //   : n <= 16 ? 4
    //   : n <= 32 ? 5
    //   : n <= 64 ? 6
    //   : n <= 128 ? 7
    //   : n <= 256 ? 8
    //   : n <= 512 ? 9
    //   : n <= 1024 ? 10
    //   : n <= 2048 ? 11
    //   : n <= 4096 ? 12
    //   : n <= 8192 ? 13
    //   : n <= 16384 ? 14
    //   : 15;
    /*Word16 val = 0;
    move32();
    test();
    WHILE( GT_32( n, L_shl( 1, val ) ) && LT_32( val, 16 ) )
    {
        val = add( val, 1 );
    }*/
    IF( LE_32( n, 1 ) )
    {
        return 0;
    }
    ELSE
    {

        return sub( 31, norm_l( L_sub( n, 1 ) ) );
    }
}

Word16 L_norm_arr( const Word32 *arr, Word16 size )
{
    Word16 q = 31;
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        Word16 q_tst;

        q_tst = norm_l( arr[i] );
        if ( arr[i] != 0 )
        {
            q = s_min( q, q_tst );
        }
    }

    return q;
}

Word16 norm_arr( Word16 *arr, Word16 size )
{
    Word16 q = 15;
    Word16 exp = 0;
    move16();
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        if ( arr[i] != 0 )
        {
            exp = norm_s( arr[i] );
        }
        if ( arr[i] != 0 )
        {
            q = s_min( q, exp );
        }
    }
    return q;
}

Word16 W_norm_arr( Word64 *arr, Word16 size )
{
    Word16 q = 63;
    Word16 exp = 0;
    move16();
    move16();
    FOR( Word16 i = 0; i < size; i++ )
    {
        if ( arr[i] != 0 )
        {
            exp = W_norm( arr[i] );
        }
        if ( arr[i] != 0 )
        {
            q = s_min( q, exp );
        }
    }
    return q;
}

Word16 get_min_scalefactor( Word32 x, Word32 y )
{
    Word16 scf_y;
    Word16 scf = Q31;
    move16();

    test();
    if ( x == 0 && y == 0 )
    {
        scf = 0;
        move16();
    }

    if ( x != 0 )
    {
        scf = norm_l( x );
    }

    scf_y = norm_l( y );
    if ( y != 0 )
    {
        scf = s_min( scf_y, scf );
    }

    return scf;
}


Flag is_zero_arr( Word32 *arr, Word16 size )
{
    FOR( Word16 i = 0; i < size; i++ )
    IF( arr[i] != 0 )
    {
        return 0;
    }

    return 1;
}

Flag is_zero_arr16( Word16 *arr, Word16 size )
{
    FOR( Word16 i = 0; i < size; i++ )
    IF( arr[i] != 0 )
    {
        return 0;
    }

    return 1;
}

void Scale_sig64(
    Word64 x[], /* i/o: signal to scale                 Qx        */
    Word16 len, /* i  : size of x[]                     Q0        */
    Word16 exp  /* i  : exponent: x = round(x << exp)   Qx exp    */
)
{
    Word16 i;
    assert( exp <= 63 && exp >= -63 );
    IF( exp == 0 )
    {
        return;
    }

    FOR( i = 0; i < len; i++ )
    {
        /* saturation can occur here */
        x[i] = W_shl( x[i], exp );
        move64();
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -2901,11 +2901,11 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W
    Ltemp1 = log10_fx( Ltemp1 );

    /*  subtract 10log10(2)*(2Q-13), Q23 */
    Ltemp1 = L_sub( Ltemp1, Ltemp3 );
    Ltemp1 = L_sub_sat( Ltemp1, Ltemp3 );
    Ltemp1 = L_max( 0, Ltemp1 );
    Ltemp2 = getSpEngyFromResAmp_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, curr_lpc, sin_tab, cos_tab );
    Ltemp2 = log10_fx( Ltemp2 );          /*  Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */
    Ltemp2 = L_sub( Ltemp2, Ltemp3 ); /*  Ltemp2 in Q23 */
    Ltemp2 = L_sub_sat( Ltemp2, Ltemp3 ); /*  Ltemp2 in Q23 */

    Ltemp2 = L_max( 0, Ltemp2 );

@@ -2929,10 +2929,10 @@ void quant_target_fx( DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, W
    tmp = round_fx( Ltemp );            /*  tmp in Q(22-n) */
    Ltemp1 = Mult_32_16( Ltemp1, tmp ); /*  Q(30-n) */
    n = sub( 8, exp );
    w[0] = round_fx( L_shl( Ltemp1, n ) ); /*  w[0] in Q15 */
    w[0] = round_fx_sat( L_shl_sat( Ltemp1, n ) ); /*  w[0] in Q15 */
    move16();
    Ltemp2 = Mult_32_16( Ltemp2, tmp );
    w[1] = round_fx( L_shl( Ltemp2, n ) ); /*  w[1] in Q15 */
    w[1] = round_fx_sat( L_shl_sat( Ltemp2, n ) ); /*  w[1] in Q15 */
    move16();

    logLag = log10_fx( X_fx->lag_fx );                       /*  logLag=10*log10(lag), Q23 */
+30 −70
Original line number Diff line number Diff line
@@ -123,8 +123,8 @@ return noise;
}

static Word16 ivas_IGF_replaceTCXNoise_1_fx(                         /**< out: Q0 | number of noise bands      */
                                             const Word32 *in,       /**< in: Q31 | MDCT spectrum              */
                                             Word16 s_l,             /**< in: Q0  | noise headroom             */
                                             const Word32 *in,       /**< in: in_exp | MDCT spectrum              */
                                             Word16 in_exp,          /**< in: Q0  | noise headroom             */
                                             const Word16 *TCXNoise, /**< in: Q0  | tcx noise indicator vector */
                                             const Word16 start,     /**< in: Q0  | start MDCT subband index   */
                                             const Word16 stop,      /**< in: Q0  | stop MDCT subband index    */
@@ -132,41 +132,44 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q
                                             Word16 *totalNoiseNrg_exp )
{
    Word16 sb;
    Word16 tmp16;
    Word16 tmp16, shift;
    Word16 noise;
    Word32 tmp32;
    Word64 nE;


    tmp16 = 0;
    shift = 2;
    move16();
    noise = 0;
    move16();
    s_l = sub( s_l, 5 );
    nE = 0;
    move64();

    *totalNoiseNrg = 0;
    move32();
    *totalNoiseNrg_exp = 0;
    move16();

    FOR( sb = start; sb < stop; sb++ )
    {
        IF( TCXNoise[sb] )
        {
            tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l
        }
        IF( TCXNoise[sb] )
        {
            nE = W_mac_16_16( nE, tmp16, tmp16 ); // Q31 + s_l
        }
        IF( TCXNoise[sb] )
        {
            noise = add( noise, 1 ); // Q0
            tmp32 = L_shr( in[sb], shift );
            nE = W_mac_32_32( nE, tmp32, tmp32 ); // 62 - (in_exp + shift + in_exp + shift + 1)
            noise = add( noise, 1 );
        }
    }

    IF( nE )
    {
        tmp16 = W_norm( nE );
        nE = W_shl( nE, tmp16 );
        *totalNoiseNrg = W_extract_h( nE );
        move32();
    *totalNoiseNrg_exp = sub( tmp16, 32 );
        *totalNoiseNrg_exp = sub( add( shl( shift, 1 ), shl( in_exp, 1 ) ), tmp16 );
        move16();
    }


    return noise;
}
@@ -3533,14 +3536,8 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in
                specMed_e = igf_spec_e[i];
                move16();

                /*14 seems to be precise enough*/
                hPrivateData->headroom_TCX_noise_white = IGF_getScaleFactor32Cond(
                    hInstance->infoTCXNoise_ptr,
                    igf_spec + hGrid->minSrcSubband,
                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                move16();
                hPrivateData->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_spec,
                                                                             hPrivateData->headroom_TCX_noise_white,
                                                                             igf_spec_e[i],
                                                                             hInstance->infoTCXNoise_ptr,
                                                                             hGrid->minSrcSubband,
                                                                             hGrid->startLine,
@@ -3548,9 +3545,6 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in
                                                                             &hPrivateData->totalNoiseNrg_exp );
                move16();

                hPrivateData->totalNoiseNrg_exp = sub( shl( sub( igf_spec_e[i], sub( hPrivateData->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateData->totalNoiseNrg_exp );
                move16();

                BREAK;
            }
        }
@@ -3560,22 +3554,15 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in
        {
            IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_OFF ) )
            {
                hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond(
                    hInstance->infoTCXNoise_ptr,
                    hPrivateData->pSpecFlat + hGrid->minSrcSubband,
                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                move16();

                hPrivateData->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateData->pSpecFlat,
                                                                                 hPrivateData->headroom_TCX_noise,
                                                                                 hPrivateData->pSpecFlat_exp,
                                                                                 hInstance->infoTCXNoise_ptr,
                                                                                 hGrid->minSrcSubband,
                                                                                 hGrid->startLine,
                                                                                 &hPrivateData->totalNoiseNrg_off,
                                                                                 &hPrivateData->totalNoiseNrg_off_exp );
                move16();
                hPrivateData->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateData->pSpecFlat_exp, sub( hPrivateData->headroom_TCX_noise, 5 ) ), 1 ), hPrivateData->totalNoiseNrg_off_exp );
                move16();
                BREAK;
            }
        }
@@ -3760,12 +3747,9 @@ void IGFDecApplyStereo(
                    move16();
                }

                hPrivateDataL->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecL->infoTCXNoise_ptr + hGrid->minSrcSubband,
                                                                                    igf_specL_fx + hGrid->minSrcSubband,
                                                                                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                move16();

                hPrivateDataL->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specL_fx,
                                                                              hPrivateDataL->headroom_TCX_noise_white,
                                                                              specMedL_e,
                                                                              hIGFDecL->infoTCXNoise_ptr,
                                                                              hGrid->minSrcSubband,
                                                                              hGrid->startLine,
@@ -3773,9 +3757,6 @@ void IGFDecApplyStereo(
                                                                              &hPrivateDataL->totalNoiseNrg_exp );
                move16();

                hPrivateDataL->totalNoiseNrg_exp = sub( shl( sub( specMedL_e, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataL->totalNoiseNrg_exp );
                move16();

                IF( !bfi )
                {
                    s_l = getScaleFactor32( hPrivateDataR->pSpecFlat + hGrid->minSrcSubband - whiteningLevel,
@@ -3796,21 +3777,14 @@ void IGFDecApplyStereo(
                    move16();
                }

                hPrivateDataR->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecR->infoTCXNoise_ptr,
                                                                                    igf_specR_fx + hGrid->minSrcSubband,
                                                                                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                move16();
                hPrivateDataR->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specR_fx,
                                                                              hPrivateDataR->headroom_TCX_noise_white,
                                                                              specMedR_e,
                                                                              hIGFDecR->infoTCXNoise_ptr,
                                                                              hGrid->minSrcSubband,
                                                                              hGrid->startLine,
                                                                              &hPrivateDataR->totalNoiseNrg,
                                                                              &hPrivateDataR->totalNoiseNrg_exp );
                move16();
                hPrivateDataR->totalNoiseNrg_exp = sub( shl( sub( specMedR_e, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataR->totalNoiseNrg_exp );
                move16();

                BREAK;
            }
        }
@@ -3820,37 +3794,23 @@ void IGFDecApplyStereo(
            test();
            IF( EQ_16( hPrivateDataL->currWhiteningLevel[i], IGF_WHITENING_OFF ) || EQ_16( hPrivateDataR->currWhiteningLevel[i], IGF_WHITENING_OFF ) )
            {
                hPrivateDataL->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecL->infoTCXNoise_ptr + hGrid->minSrcSubband,
                                                                                    hPrivateDataL->pSpecFlat + hGrid->minSrcSubband,
                                                                                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                hPrivateDataL->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataL->pSpecFlat,
                                                                                  hPrivateDataL->headroom_TCX_noise_white,
                                                                                  hPrivateDataL->pSpecFlat_exp,
                                                                                  hIGFDecL->infoTCXNoise_ptr,
                                                                                  hGrid->minSrcSubband,
                                                                                  hGrid->startLine,
                                                                                  &hPrivateDataL->totalNoiseNrg_off,
                                                                                  &hPrivateDataL->totalNoiseNrg_off_exp );
                hPrivateDataL->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateDataL->pSpecFlat_exp, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataL->totalNoiseNrg_off_exp );
                move16();
                move16();
                move16();

                hPrivateDataR->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecR->infoTCXNoise_ptr,
                                                                                    hPrivateDataR->pSpecFlat + hGrid->minSrcSubband,
                                                                                    sub( hGrid->startLine, hGrid->minSrcSubband ) );
                hPrivateDataR->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataR->pSpecFlat,
                                                                                  hPrivateDataR->headroom_TCX_noise_white,
                                                                                  hPrivateDataR->pSpecFlat_exp,
                                                                                  hIGFDecR->infoTCXNoise_ptr,
                                                                                  hGrid->minSrcSubband,
                                                                                  hGrid->startLine,
                                                                                  &hPrivateDataR->totalNoiseNrg_off,
                                                                                  &hPrivateDataR->totalNoiseNrg_off_exp );
                hPrivateDataR->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateDataR->pSpecFlat_exp, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataR->totalNoiseNrg_off_exp );
                move16();
                move16();
                move16();


                BREAK;
            }
        }
Loading