Commit 6f5e4add authored by Jonas Svedberg's avatar Jonas Svedberg
Browse files

fix for issue 1002 removed debug code, active define FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE

parent b917cfed
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@
/* ################### Start DEBUGGING switches ########################### */

#ifndef RELEASE
/*#define DEBUGGING */                           /*1002fix*/    /* Activate debugging part of the code */
/*#define DEBUGGING */                          /* Activate debugging part of the code */
#endif
/*#define WMOPS*/                               /* Activate complexity and memory counters */
/*#define WMOPS_PER_FRAME*/                     /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */
@@ -164,7 +164,7 @@
#define FIX_1001_ARI_HM_OVERFLOW                        /* FhG: fix for undef behaviour in in the harmonic TCX model arithmetic coder */
#define FIX_901_PARAMMC_DEAD_CODE                       /* FhG: issue 901: remove dead ParamMC code             */
#define FIX_1008_EXTORIENT_TARGET_INTERPOLATION         /* FhG: issue #1008, external orientation init was wrong for 5ms */
#define FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE            /* Eri: issue #1002, usan-value-out-of-range-for-int16   */
#define FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE            /* Eri: issue #1002, usan-value-out-of-range-for-int16, non-BE for PLC-conditions   */



+3 −94
Original line number Diff line number Diff line
@@ -1096,86 +1096,16 @@ static void subst_spec(

        Xph = corr_phase[m];
#ifdef FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE

#ifdef DEBUGGING
        /* old :  Xph_short = ( int16_t )( ( ( int32_t )( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff; */
        /*  the costly  "%" modulo 32768 is not the correct way of obtaining the fractional part in Q10 resolution */
#endif
#define WMC_TOOL_SKIP
        tmpf = Xph * ( 1.0f / PI2 );                           /* normalize         :  mult() with a constant                           */
        tmpf = ( 1024.0f ) * ( tmpf - floorf( tmpf ) ) + 0.5f; /* obtain fraction  :  floor(), sub(), mult(), rnd(), out:  [0...1024.5[ */
        //tmpf = ( 1024.0f ) * ( tmpf - floorf( tmpf ) ) ; /* obtain fraction  :  floor(), sub(), mult() ,              out:  [0...1023.x[ */
        Xph_short = ( (int16_t) tmpf ) & 0x03ff;               /* mask to [0..1023]:  s_and()                       */
        Xph_short = ( (int16_t) tmpf ) & 0x03ff;               /* mask to [0..1023]:  s_and()                      , out:  [0...1023]   */

        MULT( 2 );
        MISC( 1 );  /* floor    */
        ADD( 2 );   /* sub, rnd */
        LOGIC( 1 ); /* s_and    */
#undef WMC_TOOL_SKIP

#ifdef DEBUGGING
        if ( 1 )
        {
            int32_t ii;

#define ONE_OVER_PI2 ( 1.0f / ( PI2 ) )
            float Xph_norm = Xph * ( ONE_OVER_PI2 );
            /* extract IEEE single precision mantissa and exponent values */
            int32_t n;
            float frac_3 = frexpf( Xph_norm, &n );                           /* a math.h function,  currently not counted by WMC tool  */
            int32_t L_frac_3 = ( int32_t )( frac_3 * (float) ( 1L << 23 ) ); /* make into Q(23+n) */
            int32_t Xph_int32 = L_frac_3 >> ( 23 - 10 - n );                 /* make into Q10 , no rounding */
            int16_t Xph_short_new_frexpf = ( int16_t )( Xph_int32 & 0x03ff );      /* mask out fractional part */

            /* approx cost:  mul, frexpf, mult, add, shr, s_and  , similar to   1024.0*(x-floor(x))    */

            int16_t Xph_short_new = Xph_short;
            int16_t Xph_short_orig = ( int16_t )( ( ( int32_t )( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff;


            assert( ( (abs( Xph_short - Xph_short_orig)   <= 1 ) ||  (  abs( (Xph_short+1)&1023 - (Xph_short_orig+1)&1023  ) <= 1 ) )   && "Xph_short diff  larger than rounding !! ");
            for ( ii = 0; ii < 2048; ii++ )

            {
                float Xph_tst = Xph + ( ii / 2048.0f ) * PI2;

                float Xph_short_flt0 = ( Xph_tst * ( 1.0f / PI2 ) );                                 /*  (x+"fr")*/
                float Xph_short_flt0_fr = Xph_short_flt0 - (float) floor( (double) Xph_short_flt0 ); /* "fr"  in the range [0..1.0[ */
                float Xph_short_flt1 = 1024.0f * ( Xph_short_flt0_fr );

                float Xph_short_flt2round = (float) floor( (double) ( Xph_short_flt1 + 0.5f ) );
                Xph_short_flt2round -= ( Xph_short_flt2round == 1024.0f ? 1024.0f : 0.0f ); /* wrap 1.0 to 0.0  */

                float Xph_short_flt2floor = (float) floor( (double) Xph_short_flt1 );


                if ( ii == 0 )
                {
                    fprintf( stderr, "\n frame=%5d, m=%3d, ii=%4d,  tst= %.15g rad, Xph_short_orig=%4d, Xph_short_flt2round=%4d, Xph_shortflt2floor=%4d, Xph_short_new=%4d ",
                             frame, m, ii, Xph_tst, Xph_short_orig, (int16_t) Xph_short_flt2round, (int16_t) Xph_short_flt2floor, Xph_short_new );
                }

                if ( ii == 0 && Xph_short_orig != Xph_short_new && ( ( abs( Xph_short_orig - Xph_short_new ) > 1 ) || abs( (Xph_short_orig+1)&1023 - (Xph_short_new+1)&1023) > 1) )
                {
                    fprintf( stderr, " MISS !! Xph_short_orig != Xph_short_new && diff > 1 !!" );
                }
                assert( Xph_short_flt2floor >= 0.0 );
                assert( Xph_short_flt2floor <= 1023.0 );

                if ( ii == 0 && Xph_short_flt2round != Xph_short_flt2floor )
                {
                    // fprintf( stderr, "\n frame=%5d,  m=%3d, ii=%4d,  tst= %.15g rad, Xph_short_orig=%4d, Xph_short_flt2round=%4d, Xph_shortflt2floor=%4d, Xph_short_new=%4d ",
                    //          frame, m, ii, Xph_tst, Xph_short_orig, (int16_t) Xph_short_flt2round, (int16_t) Xph_short_flt2floor, Xph_short_new );

                    fprintf( stderr, "   rounding change   by %.2f   !!**", Xph_short_flt2round - Xph_short_flt2floor );
                }
                assert( Xph_short_flt2round >= 0.0 );
                assert( Xph_short_flt2round <= 1023.0 );

            } /* end for */
        }
#endif

#else
        Xph_short = ( int16_t )( ( ( int32_t )( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff;
#endif
@@ -1227,8 +1157,6 @@ static void subst_spec(
#ifdef FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE
                /* fractional phase of Xph converted to an integer in the range [0..1023] */
                /* in BASOP this is simply a truncation (through extract_l(Word32)) of a 32bit value at the Q16 bimal point + shifting to a 10 bit index  */
                
                /* old:  Xph_short = ( int16_t )( Xph * 512 / EVS_PI ) & 0x03ff; */  /* yields out USAN of range for int16_t */  
#define WMC_TOOL_SKIP
                tmpf = Xph * ( 1.0f / PI2 );                           /* normalize        :  mult() with a constant       */
                tmpf = ( 1024.0f ) * ( tmpf - floorf( tmpf ) ) + 0.5f; /* obtain fraction  :  floor(), sub(), mult(), rnd(), out:  [0...1024.5[ */
@@ -1239,25 +1167,6 @@ static void subst_spec(
                ADD( 2 );   /* sub, rnd */
                LOGIC( 1 ); /* s_and    */
#undef WMC_TOOL_SKIP

#ifdef DEBUGGING
                {
                    int16_t Xph_short_bad;
                    int16_t Xph_short_corrected;
                  

                    Xph_short_bad = ( int16_t )( Xph * 512 / EVS_PI ) & 0x03ff; /*  yields out USAN of range for int16 */
                                                                                /* negative number can be created in cat to int16_t ,  but wraps back with &0x03ff in MSVC  */
 
                    Xph_short_corrected = Xph_short;

                    assert( Xph_short_corrected >= 0 && Xph_short_corrected <= 1023 );
                    if ( Xph_short_bad != Xph_short_corrected )
                    {
                        fprintf( stderr, "\n    fix1002 actually active    %5d -> %5d   !!**", Xph_short_bad, Xph_short_corrected );
                    }
                }
#endif
#else
                Xph_short = ( int16_t )( Xph * 512 / EVS_PI ) & 0x03ff; /*  yields out of range for int16 */
#endif