Commit 0c5691e6 authored by vaclav's avatar vaclav
Browse files

Merge branch 'basop-2273-usan-oob-indexing-in-pitch_fr4_fx-function' into 'main'

basop-2273-usan-oob-indexing-in-pitch_fr4_fx-function

See merge request !2464
parents 8b03f777 d532a673
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@
#define FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH /* FhG: fix oob indexing USAN complaint */
#define FIX_2287_MCT_MDCT_STEREO_DATA_MALLOC_SIZE       /* FhG: correct allocation size for STEREO_MDCT_DEC_DATA struct */
#define FIX_2271_OOB_INDEXING_IN_PIT_OL2                /* VA: Fix for issue 2271, to silence clang18 */
#define FIX_2273_OOB_INDEXING_IN_PIT_FR4                /* VA: Fix to silence clang on ptr init */

/* #################### End BE switches ################################## */

+45 −0
Original line number Diff line number Diff line
@@ -443,6 +443,9 @@ int16_t pitch_fr4(
    int16_t t0, t1, t_min, t_max, pit_min;
    float cor_max, max_val, temp;
    float *corr, corr_v[15 + 2 * L_INTERPOL1 + 1];
#ifdef FIX_2273_OOB_INDEXING_IN_PIT_FR4
    int16_t corr_off;
#endif

    /* initialization */
    if ( limit_flag == 0 )
@@ -482,24 +485,46 @@ int16_t pitch_fr4(

    t_min = t0_min - L_INTERPOL1;
    t_max = t0_max + L_INTERPOL1;

#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
    corr = &corr_v[0] - t_min; /* corr[t_min..t_max] */
#else
    corr = corr_v;
    corr_off = -t_min;
#endif

#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
    norm_corr( exc, xn, h, t_min, t_max, corr, L_subfr );
#else
    norm_corr( exc, xn, h, t_min, t_max, corr + corr_off, L_subfr );
#endif

    /*-----------------------------------------------------------------*
     * Find integer pitch
     *-----------------------------------------------------------------*/

#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
    max_val = corr[t0_min];
#else
    max_val = corr[t0_min + corr_off];
#endif
    t0 = t0_min;

    for ( i = t0_min + 1; i <= t0_max; i++ )
    {
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
        if ( corr[i] >= max_val )
        {
            max_val = corr[i];
            t0 = i;
        }
#else
        if ( corr[i + corr_off] >= max_val )
        {
            max_val = corr[i + corr_off];
            t0 = i;
        }
#endif
    }

    if ( t0_fr1 == pit_min )
@@ -512,7 +537,11 @@ int16_t pitch_fr4(
            {
                i -= 2;
            }
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
            if ( corr[i] > corr[i + 2] )
#else
            if ( corr[i + corr_off] > corr[i + 2 + corr_off] )
#endif
            {
                t0 = i;
            }
@@ -551,15 +580,27 @@ int16_t pitch_fr4(
    if ( t0 == t0_min ) /* Limit case */
    {
        fraction = 0;
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
        cor_max = interpolation( &corr[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 );
#else
        cor_max = interpolation( &corr[t0 + corr_off], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 );
#endif
    }
    else /* Process negative fractions */
    {
        t0--;
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
        cor_max = interpolation( &corr[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 );
#else
        cor_max = interpolation( &corr[t0 + corr_off], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 );
#endif
        for ( i = ( fraction + step ); i <= 3; i = i + step )
        {
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
            temp = interpolation( &corr[t0], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 );
#else
            temp = interpolation( &corr[t0 + corr_off], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 );
#endif
            if ( temp > cor_max )
            {
                cor_max = temp;
@@ -570,7 +611,11 @@ int16_t pitch_fr4(

    for ( i = 0; i <= 3; i = i + step ) /* Process positive fractions */
    {
#ifndef FIX_2273_OOB_INDEXING_IN_PIT_FR4
        temp = interpolation( &corr[t1], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 );
#else
        temp = interpolation( &corr[t1 + corr_off], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 );
#endif
        if ( temp > cor_max )
        {
            cor_max = temp;