Commit 603e62d0 authored by multrus's avatar multrus
Browse files

[cleanup] accept CLEANUP_185_NO_AGC_EXCEPTION

parent 15d6f279
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -315,9 +315,6 @@ typedef struct ivas_huff_coeffs_t
/* AGC structures */
typedef struct ivas_agc_chan_data_t
{
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
    int16_t gainException;
#endif
    int16_t absGainExp;
    int16_t absGainExpCurr;

+0 −1
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@
#define SBA_BR_SWITCHING                                /* Issue 114: Changes for sba bit rate switching*/
#define FIX_ITD                                         /* Contribution 16: TD renderer ITD improvement and code cleanup */
#define BRATE_SWITCHING_RENDERING                       /* Bitrate switching changes related to the renderers */
#define CLEANUP_185_NO_AGC_EXCEPTION                    /* Issue 185: Cleanup AGC EXCEPTION code */
#define FIX_I220_PARAMMC_CPROTO                         /* Issue 220: sanitizer error in the svd due to NaNs coming from negative energies in Cproto */
#define FIX_221_BR_SWITCH_STEREO                        /* Issue 221: Fix missing initialization when switchin from TD to MDCT stereo*/
#define FIX_DTX_RANGE                                   /* Issue 118: fix the DTX usage: default DTX up to 64 kbps, otherwise only in silence */
+0 −42
Original line number Diff line number Diff line
@@ -78,9 +78,6 @@ static void ivas_agc_dec_init(
        /* gain_data */
        ptr->absGainExp = hAgcDec->agc_com.absEmin;
        ptr->absGainExpCurr = hAgcDec->agc_com.absEmin;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        ptr->gainException = false;
#endif
        ptr++;
    }

@@ -201,10 +198,6 @@ void ivas_agc_dec_process(
        pState->gain_state[i].lastGain = powf( pState->agc_com.winFunc[offset - 1], ( -1.f * (float) ( pState->gain_data[i].absGainExp - pState->agc_com.absEmin ) ) );
        gainLast = 1.f / pState->gain_state[i].lastGain;

#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        if ( !pState->gain_data[i].gainException )
        {
#endif
            if ( pState->gain_state[i].gainExpVal != 0 )
            {
                for ( idx = 0; idx < output_frame; idx++ )
@@ -231,28 +224,6 @@ void ivas_agc_dec_process(
                    pcm_out[i][idx] = pcm_in[i][idx] * gain;
                }
            }
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        }
        else
        {
            float gainCurr = powf( pState->agc_com.winFunc[offset - 1], ( -1.f * (float) pState->gain_state[i].gainExpVal ) );
            float gainTot = gainCurr * gainLast;

            for ( idx = 0; idx < output_frame; idx++ )
            {
                if ( idx >= pState->agc_com.in_delay )
                {
                    gain = gainTot;
                }
                else
                {
                    gain = gainLast;
                }
                pcm_out[i][idx] = pcm_in[i][idx] * gain;
            }
            pState->gain_state[i].lastGain /= gainCurr;
        }
#endif
        pState->gain_data[i].absGainExp = pState->gain_data[i].absGainExpCurr;
    }

@@ -300,16 +271,10 @@ void ivas_agc_read_bits(
            if ( per_ch_bit[i] == 1 )
            {
                pState->gain_data[i].absGainExpCurr = get_next_indice( st0, (int16_t) pState->agc_com.betaE );
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                pState->gain_data[i].gainException = false;
#endif
            }
            else
            {
                pState->gain_data[i].absGainExpCurr = (int32_t) pState->agc_com.absEmin;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                pState->gain_data[i].gainException = false;
#endif
            }
        }
    }
@@ -318,9 +283,6 @@ void ivas_agc_read_bits(
        for ( i = 0; i < n_channels; i++ )
        {
            pState->gain_data[i].absGainExpCurr = (int32_t) pState->agc_com.absEmin;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            pState->gain_data[i].gainException = false;
#endif
        }
    }

@@ -331,10 +293,6 @@ void ivas_agc_read_bits(
    {
        fread( &( pState->gain_data[i].absGainExpCurr ), sizeof( int32_t ), 1, stream ); /* n bits */
        num_bits += pState->agc_com.betaE;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        fread( &( pState->gain_data[i].gainException ), sizeof( int16_t ), 1, stream ); /* 1 bit */
        num_bits++;
#endif
        num_dmx_bits[i]++;

        /*fprintf(stdout, "AbsGain[%d]:= %d[%d bits]; ", i, pState->gain_data[i].absGainExp, pState->betaE);*/
+0 −88
Original line number Diff line number Diff line
@@ -130,9 +130,6 @@ static void ivas_agc_enc_init(
        /* gain_data */
        ptr->absGainExp = hAgcEnc->agc_com.absEmin;
        ptr->absGainExpCurr = hAgcEnc->agc_com.absEmin;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        ptr->gainException = FALSE;
#endif
        ptr++;
    }

@@ -290,9 +287,6 @@ void ivas_agc_enc_process(
        isGainAdjusted = FALSE;
        if ( !isClipped )
        {
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            pState->gain_data[i].gainException = FALSE;
#endif

            if ( pState->gain_state[i].lastExp == AGC_EMAX || MaxAbsVal < FLT_MIN )
            {
@@ -327,25 +321,15 @@ void ivas_agc_enc_process(
        {
            float actualMaxAbsVal = 0.f;
            int16_t currMaxAttExp
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                ,
                gainExpValMaxRange
#endif
                ;

            currMaxAttExp = min( ( pState->gain_state[i].lastExp + pState->agc_com.absEmin ), pState->agc_com.maxAttExp );
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            gainExpValMaxRange = min( ( pState->gain_state[i].lastExp + pState->agc_com.absEmin ), pState->agc_com.maxAttExp + 1 );
#endif
            extendedExpVal = FALSE;

            if ( isClipped )
            {
                int16_t isCompensated = FALSE;
                actualMaxAbsVal = pState->gain_state[i].lastMaxAbs * pState->gain_state[i].lastGain;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                pState->gain_data[i].gainException = FALSE;
#endif
                pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal * MDFT_NORM_SCALING ) / logf( pState->agc_com.winFunc[min( offset - 1, MaxAbsValIdx )] ) );

                while ( !isCompensated )
@@ -383,29 +367,9 @@ void ivas_agc_enc_process(
                        break;
                    }

#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                    if ( pState->gain_state[i].gainExpVal > currMaxAttExp )
                    {
                        pState->gain_data[i].gainException = TRUE;

                        if ( pState->gain_state[i].gainExpVal == gainExpValMaxRange )
                        {
                            extendedExpVal = TRUE;
                            if ( isCompensated )
                            {
                                pState->gain_data[i].gainException = FALSE;
                            }
                        }
                        break;
                    }
#endif
                }
            }

#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            if ( !pState->gain_data[i].gainException )
            {
#endif
                for ( idx = 0; idx < input_frame; idx++ )
                {
                    if ( idx < offset )
@@ -421,32 +385,11 @@ void ivas_agc_enc_process(
                }

                pState->gain_state[i].lastGain *= powf( pState->agc_com.winFunc[offset - 1], pState->gain_state[i].gainExpVal );
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            }
            else
            {
                pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( ( actualMaxAbsVal + pState->minDelta ) * MDFT_NORM_SCALING ) * INV_LOG_2 ) );
                pState->gain_state[i].gainExpVal = min( gainExpValMaxRange, pState->gain_state[i].gainExpVal );

                gain = powf( pState->agc_com.winFunc[offset - 1], pState->gain_state[i].gainExpVal );
                for ( idx = 0; idx < input_frame; idx++ )
                {
                    ppPcm_out[i][idx] *= gain;
                }
                pState->gain_state[i].lastGain *= gain;
            }
#endif
            /*safety check starts*/
            if ( pState->gain_state[i].gainExpVal == pState->agc_com.maxAttExp + 1 )
            {
                extendedExpVal = TRUE;
            }
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            else if ( pState->gain_state[i].gainExpVal == 0 )
            {
                pState->gain_data[i].gainException = FALSE;
            }
#endif
            /*safety check ends*/

            pState->gain_state[i].prevExp = pState->gain_state[i].lastExp;
@@ -455,39 +398,15 @@ void ivas_agc_enc_process(
            if ( extendedExpVal )
            {

#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                if ( !pState->gain_data[i].gainException )
                {
                    pState->gain_data[i].gainException = TRUE;
#endif
                    pState->gain_state[i].gainExpVal = -1;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                }
                else
                {
                    if ( pState->gain_state[i].gainExpVal == gainExpValMaxRange )
                    {
                        pState->gain_state[i].gainExpVal = 0;
                    }
                }
#endif
            }
        }

        pState->gain_data[i].absGainExp = pState->gain_state[i].prevExp + pState->agc_com.absEmin;

        if ( extendedExpVal
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
             && pState->gain_data[i].gainException
#endif
             && pState->gain_state[i].gainExpVal <= 0 )
        {
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
            if ( pState->gain_state[i].gainExpVal == -1 )
            {
                pState->gain_data[i].gainException = FALSE;
            }
#endif
            pState->gain_state[i].gainExpVal = pState->agc_com.maxAttExp + 1;
        }

@@ -528,9 +447,6 @@ void ivas_agc_enc_process(
            if ( per_ch_bit[i] == 1 )
            {
                push_next_indice( hMetaData, (uint16_t) pState->gain_data[i].absGainExpCurr, (int16_t) pState->agc_com.betaE );
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
                assert( pState->gain_data[i].gainException == FALSE );
#endif
            }
        }
    }
@@ -567,10 +483,6 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_

        fwrite( &( pState->gain_data[i].absGainExpCurr ), sizeof( int32_t ), 1, stream ); /* n bits */
        num_bits += pState->agc_com.betaE;
#ifndef CLEANUP_185_NO_AGC_EXCEPTION
        fwrite( &( pState->gain_data[i].gainException ), sizeof( int16_t ), 1, stream ); /* 1 bit */
        num_bits++;
#endif
        num_dmx_bits[i]++;

        /*fprintf(stdout, "absGainExpCurr[%d]:= %d[%d bits]; ", i, pState->gain_data[i].absGainExpCurr, pState->betaE); */