Commit edbd9692 authored by Arthur Tritthart's avatar Arthur Tritthart
Browse files

added F0_32 in 32-bit to existing code (F0, 16 bit), added lots of debug...

added F0_32 in 32-bit to existing code (F0, 16 bit), added lots of debug prints, all inactive, 32-bit version is active, if FIX_ISSUE_1966 is active
parent cb73ed29
Loading
Loading
Loading
Loading
Loading
+118 −11
Original line number Diff line number Diff line
@@ -460,6 +460,37 @@ static void getEnvelope(
        nFilterLength = s_or( 1, shr( F0, 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/
        move16();
    }
#ifdef DEBUG_ISSUE_1966
    printf("getEnvelope in frame=%d: F0=0x%04X  nFilterLength=%d\n", frame, F0, nFilterLength);
#endif
#ifdef FIX_ISSUE_1966
    IF( F0_32 == 0 )
    {
        nFilterLength = 15; /*Q0*/
        move16();
    }
    ELSE IF( F0_32 <= (10240 << 16) /*10.0f Q10*/ )
    {
        nFilterLength = 11; /*Q0*/
        move16();
    }
    ELSE IF( F0_32 >= (22528 << 16) /*22.0f Q10*/ )
    {
        /* For F0 >= 22 peak is isolated well enough with the filter length of 23.
           This case is however not triggered due to the limit of pit_min,
           but the line is left for security reasons. */
        nFilterLength = 23; /*Q0*/
        move16();
    }
    ELSE
    {
        nFilterLength = s_or( 1, shr( extract_h(F0_32), 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/
        move16();
    }
#ifdef DEBUG_ISSUE_1966
    printf( "getEnvelope in frame=%d: F0_32=0x%08X  nFilterLength=%d\n", frame, F0_32, nFilterLength );
#endif
#endif

    nHalfFilterLength = shr( nFilterLength, 1 );

@@ -565,7 +596,6 @@ static void GetF0(
#ifdef FIX_ISSUE_1966
        Word16 tmp_32 = 0;
        Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton( L_shl( nSamplesCore, Q16 ), tmpPitchLag, &tmp_32 );
        if ( tmp_32 != Q16 )
        F0_32 = L_shl( F0_32, tmp_32 - Q16 );
        *pF0_32 = F0_32;
        move32();
@@ -934,6 +964,9 @@ static void modifyThreshold(
    Word16 fractional /*Q15*/;
    Word16 k /*Q0*/;
    Word16 twoTimesFract /*Q10*/;
#ifdef FIX_ISSUE_1966
    Word32 L_twoTimesFract /*Q10+16*/;
#endif

    harmonic = L_mult( shl( i, 5 ), F0 );                                            /*Q0 * Q10 = 15Q16*/
    k = extract_h( harmonic );                                                       /*Q0*/
@@ -947,12 +980,40 @@ static void modifyThreshold(
    move16();
    thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/
#ifdef DEBUG_ISSUE_1966
    if ( frame == 1384 )
        printf( "modifyThreshold: [%d] %15.15f  %15.15f  %15.15f  F0 %15.15f\n", k - 1,
    //if ( frame == 1384 )
#if 0
        printf( "modifyThreshold[%d] %15.15f  %15.15f  %15.15f  F0 %15.15f  fract %15.15f\n", k - 1,
                (double) thresholdModification[k - 1] / ( 1 << 10 ),
                (double) thresholdModification[k + 0] / ( 1 << 10 ),
                (double) thresholdModification[k + 1] / ( 1 << 10 ),
                (double) F0 / ( 1 << 10 ) );
                (double) F0 / ( 1 << 10 ),
                (double) twoTimesFract / (1 << 10) );
#endif
#endif

#ifdef FIX_ISSUE_1966
    harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) );                                    /*Q0 * Q10 = 15Q16*/
    k = extract_h( harmonic );                                                       /*Q0*/
    fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/
    L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/      /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */

    move32();
    thresholdModification_32[k] = threshold_32;/*Q10+16*/
    move32();
    thresholdModification_32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/
    move32();
    thresholdModification_32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/
#ifdef DEBUG_ISSUE_1966
    //if ( frame == 1384 )
    if (( thresholdModification_32[k + 0]  != (16 << 26) ) && ( thresholdModification[k + 0]  != (16 << 10) ) )
        printf( "modifyThreshold[%d] %15.15f  %15.15f  %15.15f  F0_32 %15.15f  fract %15.15f  diff=%15.15f\n", k - 1,
                (double) thresholdModification_32[k - 1] / ( 1 << 26 ),
                (double) thresholdModification_32[k + 0] / ( 1 << 26 ),
                (double) thresholdModification_32[k + 1] / ( 1 << 26 ),
                (double) F0_32 / ( 1 << 26 ),
                (double) L_twoTimesFract / ( 1 << 26 ),
                (double) thresholdModification_32[k + 0] / ( 1 << 26 ) - (double) thresholdModification[k + 0] / ( 1 << 10 ) );
#endif
#endif

    return;
@@ -1031,7 +1092,7 @@ static void modifyThresholds(
            {
                modifyThreshold( i, F0,
#ifdef FIX_ISSUE_1966
                                 origF0_32,
                                 F0_32,
#endif
                                 358 /*0.35f Q10*/,
#ifdef FIX_ISSUE_1966
@@ -1231,13 +1292,21 @@ static void findTonalComponents_fx(
    Word16 tmp_loop1, tmp_loop2, tmp_loop3;

#ifdef DEBUG_ISSUE_1966
    if ( frame == 1384 )
    {
    //if ( frame == 1384 )
    //{
printf( "findTonalComponents in frame %d\n", frame);
        for ( j = 0; j < nSamples; j++ )
        {
#ifdef FIX_ISSUE_1966
            if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) )
            printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ),
                                                                       (double) thresholdModification32[j] / (double) ( 1 << 26 ),
                    ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) );
#else
            printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) );
#endif
        }
    }
    //}
#endif

#ifdef FIX_ISSUE_1966
@@ -1270,6 +1339,21 @@ static void findTonalComponents_fx(
            Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32
            Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) );
            flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp );
#ifdef DEBUG_ISSUE_1966
            printf( " k=%d ->flag: %d spec: 0x%08X (%d)  mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), 
                                                                                          mult_32, mult_exp );
#endif
#ifdef FIX_ISSUE_1966
            mult_64 = W_mult_32_32( envelope[k], thresholdModification32[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10+16
            lshift = W_norm( mult_64 );
            mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32
            mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10+16, lshift ) ), 31 ) );
            flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp );
#ifdef DEBUG_ISSUE_1966
            printf( " k=%d ->flag: %d spec: 0x%08X (%d)  mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ),
                                                                                          mult_32, mult_exp );
#endif
#endif
        }

        /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */
@@ -1426,6 +1510,25 @@ static void RefineThresholdsUsingPitch_fx(
#endif
    Word32 L_tmp;


#ifdef DEBUG_ISSUE_1966
    // if ( frame == 1384 )
    //{
    printf( "RefineThresholdsUsingPitch in frame %d\n", frame );
    for ( int j = 0; j < nSamples; j++ )
    {
#ifdef FIX_ISSUE_1966
        if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) )
        printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ),
                (double) thresholdModification32[j] / (double) ( 1 << 26 ),
                ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) );
#else
        printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) );
#endif
    }
    //}
#endif

    /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/
    pitchIsStable = 0;
    move16();
@@ -1468,6 +1571,10 @@ static void RefineThresholdsUsingPitch_fx(
    {
        *pF0 = 0;
        move16();
#ifdef FIX_ISSUE_1966
        *pF0_32 = 0;
        move32();
#endif
    }

    return;

lib_dec/er_util_fx.c

100644 → 100755
+3 −3
Original line number Diff line number Diff line
@@ -420,7 +420,7 @@ Word16 GetPLCModeDecision_fx(
        st->tonal_mdct_plc_active = 0;
        move16();
#ifdef DEBUG_ISSUE_1966
        printf( "-->tonal_mdct_plc_active=%d  F1\n", st->tonal_mdct_plc_active );
        //printf( "-->tonal_mdct_plc_active=%d  F1\n", st->tonal_mdct_plc_active );
#endif
    }
    ELSE
@@ -475,7 +475,7 @@ Word16 GetPLCModeDecision_fx(
                    test();
                    test();
#ifdef DEBUG_ISSUE_1966
                    printf( "-->pitch=%f  numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices );
                    //printf( "-->pitch=%f  numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices );
#endif
                    IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) )
                    {
+1 −1

File changed.

Contains only whitespace changes.