Commit 65bee438 authored by vaclav's avatar vaclav
Browse files

review and remove ADD_LRTD

parent 9002a018
Loading
Loading
Loading
Loading
+13 −22
Original line number Original line Diff line number Diff line
@@ -40,18 +40,12 @@ Word16 est_tilt_fx( /* o : tilt of the code
                    const Word32 gain_code, /* i  : algebraic code gain             Q16 */
                    const Word32 gain_code, /* i  : algebraic code gain             Q16 */
                    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
                    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
                    const Word16 Q_exc      /* i  : Scaling factor of excitation    Q0  */
                    const Word16 Q_exc      /* i  : Scaling factor of excitation    Q0  */
#ifdef ADD_LRTD
                    ,
                    const Word16 L_subfr /* i  : Sub frame length                    */
#endif
)
)
{
{
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
    Word32 L_tmp;
    Word32 L_tmp;
    Word16 tilt_code;
    Word16 tilt_code;
#ifdef ADD_LRTD

    PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " )
#endif
    ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) );
    ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) );
    exp1 = sub( exp1, add( Q_exc, Q_exc ) );
    exp1 = sub( exp1, add( Q_exc, Q_exc ) );
    L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
    L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
@@ -117,26 +111,23 @@ Word16 est_tilt_fx( /* o : tilt of the code
/* RETURN ARGUMENTS :                                                    */
/* RETURN ARGUMENTS :                                                    */
/* _ (Word16) tolt_code :  tilt of the code           Q15                */
/* _ (Word16) tolt_code :  tilt of the code           Q15                */
/*=======================================================================*/
/*=======================================================================*/
Word16 est_tilt_ivas_fx(                         /* o  : tilt of the code              Q15      */

/* o  : tilt of the code Q15 */
Word16 est_tilt_ivas_fx(
    const Word16 *exc,      /* i  : adaptive excitation vector      Qx  */
    const Word16 *exc,      /* i  : adaptive excitation vector      Qx  */
    const Word16 gain_pit,  /* i  : adaptive gain                   Q14 */
    const Word16 gain_pit,  /* i  : adaptive gain                   Q14 */
    const Word16 *code,     /* i  : algebraic excitation vector    Q9  */
    const Word16 *code,     /* i  : algebraic excitation vector    Q9  */
    const Word32 gain_code, /* i  : algebraic code gain             Q16 */
    const Word32 gain_code, /* i  : algebraic code gain             Q16 */
    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
                         const Word16 Q_exc      /* i  : Scaling factor of excitation    Q0  */
    const Word16 Q_exc,     /* i  : Scaling factor of excitation    Q0  */
#if 1                                            // def ADD_LRTD
                         ,
    const Word16 L_subfr,   /* i  : Sub frame length                    */
    const Word16 L_subfr,   /* i  : Sub frame length                    */
    const Word16 flag_tilt  /* i  : flag for special tilt        */
    const Word16 flag_tilt  /* i  : flag for special tilt        */
#endif
)
)
{
{
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
    Word32 L_tmp;
    Word32 L_tmp;
    Word16 tilt_code;
    Word16 tilt_code;
#ifdef ADD_LRTD

    PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " )
#endif
    ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) );
    ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) );
    exp1 = sub( exp1, add( Q_exc, Q_exc ) );
    exp1 = sub( exp1, add( Q_exc, Q_exc ) );
    L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
    L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
+245 −680
Original line number Original line Diff line number Diff line
@@ -120,40 +120,7 @@ void bands_and_bit_alloc_fx(
    move16();
    move16();
    bit_new_bands = 5;
    bit_new_bands = 5;
    move16();
    move16();
#ifdef ADD_LRTD
    if ( GT_32( core_brate, ACELP_16k40 ) && EQ_16( L_frame, L_FRAME16k ) )
    {
        bit_new_bands = 7;
        move16();
    }

    i = 0;
    move16();
    WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) )
    {
        IF( LE_32( core_brate, brate_intermed_tbl[i] ) )
        {
            BREAK;
        }

        IF( EQ_32( brate_intermed_tbl[i], ACELP_24k40 ) )
        {
            BREAK;
        }

        i = add( i, 1 );
    }

    if ( GT_16( element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) &&
         LE_32( core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */
    {
        i = sub( i, 1 );
    }

    bit_index = i_mult2( BRATE2IDX_fx( brate_intermed_tbl[i] ), 17 );
#else
    bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 );
    bit_index = i_mult2( BRATE2IDX_fx( core_brate ), 17 );
#endif
    bit_index_mem = bit_index;
    bit_index_mem = bit_index;
    move16();
    move16();


@@ -189,202 +156,6 @@ void bands_and_bit_alloc_fx(
        move16();
        move16();
    }
    }


#ifdef ADD_LRTD
    if ( L_frame == L_FRAME16k )
    {
        *bit -= 8;
    }

    if ( coder_type == INACTIVE && core_brate <= GSC_LRES_GAINQ_LIMIT ) /* can happen only for 2nd channel inactive */
    {
        *bit += GSC_LRES_NB_NITS;
    }

    if ( *bit > 0 )
    {
        if ( GSC_IVAS_mode > 0 )
        {
            SWB_bit_budget = *bit;
            st_band = 5;

            set_f( bits_per_bands, 0, MBANDS_GN_BITALLOC16k );

            /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */
            bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100;
            bit_fracf = check_bounds( bit_fracf, 0.50f, 0.75f );

            /* Adjusment of the bitrate between LF and HF base on the content type */
            /* 1 = new GSC bit alloc
               2 = GSC bit alloc for tc frame
               3 = more music like (should not happen often given music is coded with dft) */

            if ( GSC_IVAS_mode <= 3 )
            {
                nb_bands_max -= 6;
            }

            if ( GSC_IVAS_mode == 2 )
            {
                bit_fracf += 0.1f;
                nb_bands_max--;
            }

            if ( GSC_IVAS_mode == 3 )
            {
                bit_fracf -= 0.1f;
                nb_bands_max += 3;
            }

            /* First find how much we want to share between LF and HF, at low bitrate, a miminum of bits is needed in LF by limitating the number of bands*/
            /* Adjust the number of band based on the content type and bitrate */
            nb_bands_adj = 1.0f;
            if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG )
            {
                nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;
            }
            else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG )
            {
                nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;
            }
            nb_bands_max = (int16_t) ( nb_bands_max * nb_bands_adj + 0.5f );
            nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands );

            bit_fracf *= SWB_bit_budget;

            /* Estimation of the number of bit used in HF */
            /* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
            mb = .17f * bit_fracf;
            mp = ( 2.0f * DSR_NB_PULSE );
            if ( core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3 )
            {
                mp = 1.5f * DSR_NB_PULSE;
            }
            else if ( core_brate < GSC_L_RATE_STG )
            {
                mp = DSR_NB_PULSE;
            }

            /* We want  max_ener_band[st_band] <=  max_ener_band[st_band-1] and  max_ener_band[nb_bands_max-1] <=  max_ener_band[st_band]*/
            /* We will estimate the number of bits to allocate of HF and put the remaining bits, if any, back on LF */
            /* compute the total possible number of band to be coded */
            nb_tot_bands = (int16_t) ( ( SWB_bit_budget - bit_fracf ) / ( mp + ( mb - mp ) / 2.0f ) );
            mp = min( mp, mb );
            if ( nb_tot_bands + st_band > nb_bands_max )
            {
                bit_adj = ( ( mb + mp ) / 2 ) * ( nb_tot_bands + st_band - nb_bands_max );
                bit_adj = max( 0, bit_adj );
                nb_tot_bands = nb_bands_max - st_band;
                bit_fracf += bit_adj;
            }
            nb_tot_bands += st_band;

            /* Allocate bits to LF */
            etmp = 0.23f;
            for ( j = 0; j < st_band; j++ )
            {
                i = j;
                max_ener_band[j] = i;
                ener_vec[i] = MIN16B;
                bits_per_bands[j] = etmp * bit_fracf;
                etmp -= 0.015f;
            }

            SWB_bit_budget -= bit_fracf;

            /* Find low energy band in HF */
            set_s( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k );
            for ( i = st_band + 2; i < nb_tot_bands - 1; i++ )
            {
                if ( ener_vec[i] < ener_vec[i - 1] && ener_vec[i] < ener_vec[i + 1] )
                {
                    nb_pulse_per_band[i] = 1;
                }
            }
            for ( j = st_band; j < nb_tot_bands; j++ )
            {
                if ( j > 6 )
                {
                    i = maximum( ener_vec, nb_tot_bands, &etmp );
                }
                else
                {
                    i = j;
                }

                max_ener_band[j] = i;
                ener_vec[i] = MIN16B;
            }

            /* Recompute the final bit distribution for HF */
            if ( nb_tot_bands > st_band )
            {
                bit_fracf = DSR_NB_PULSE;
                mb = ( SWB_bit_budget * 2 / ( nb_tot_bands - st_band ) ) - mp;
                bit_fracf = ( mb - mp ) / ( nb_tot_bands - st_band );
                mb -= bit_fracf;
                /* Do the distribution */
                for ( j = st_band; j < nb_tot_bands; j++ )
                {
                    if ( nb_pulse_per_band[max_ener_band[j]] > 1 )
                    {
                        bits_per_bands[max_ener_band[j]] = mb;
                    }
                    else
                    {
                        bits_per_bands[max_ener_band[j]] = 4.5f;
                    }
                    mb -= bit_fracf;
                    SWB_bit_budget -= bits_per_bands[max_ener_band[j]];
                }
            }

            /* Series of verification in case bit allocated != the budget */
            if ( SWB_bit_budget > 0 )
            {
                i = st_band - 1;
                while ( SWB_bit_budget > 0 )
                {
                    bits_per_bands[i]++;
                    SWB_bit_budget--;
                    i--;
                    if ( i == -1 )
                    {
                        i = st_band - 1;
                    }
                }
            }

            nb_bands = nb_tot_bands;

            sum_bit = 0;
            j = 0;
            for ( i = 0; i < nb_bands; i++ )
            {
                if ( bits_per_bands[i] > 112 )
                {
                    sum_bit += bits_per_bands[i] - 112;
                    bits_per_bands[i] = 112;
                    j = i + 1;
                }

                /* safety check for overage bit reallocation */
                else if ( bits_per_bands[i] + sum_bit / 3 > 112 )
                {
                    j = i + 1;
                }
            }

            if ( sum_bit != 0 )
            {
                sum_bit /= ( nb_bands - j );
                for ( i = j; i < nb_bands; i++ )
                {
                    bits_per_bands[i] += sum_bit;
                }
            }
        }
        else
#endif
    IF( EQ_16( GSC_noisy_speech, 1 ) )
    IF( EQ_16( GSC_noisy_speech, 1 ) )
    {
    {
        SWB_bit_budget = *bit;
        SWB_bit_budget = *bit;
@@ -392,29 +163,6 @@ void bands_and_bit_alloc_fx(
        nb_bands = 5;
        nb_bands = 5;
        move16();
        move16();


#ifdef ADD_LRTD

                fzero_val = 0.0f;
                if ( element_mode > EVS_MONO )
                {
                    fzero_val = MIN16B_FLT;
                }

                if ( coder_type == UNVOICED && element_mode > EVS_MONO )
                {
                    nb_bands = 3;
                    if ( SWB_bit_budget > 20 )
                    {
                        nb_bands = 5;
                    }
                }
                else if ( bwidth < SWB )
                {
                    nb_bands = 7;
                }

#endif

        st_band = nb_bands;
        st_band = nb_bands;
        move16();
        move16();


@@ -434,14 +182,7 @@ void bands_and_bit_alloc_fx(
            ener_vec[i] = 0;
            ener_vec[i] = 0;
            move16();
            move16();
        }
        }
#ifdef ADD_LRTD

                if ( bwidth < SWB )
                {
                    if ( coder_type == UNVOICED && element_mode > EVS_MONO )
                    {
                        nb_tot_bands = 5;
                    }
#endif
        FOR( ; j < nb_bands; j++ )
        FOR( ; j < nb_bands; j++ )
        {
        {
            i = maximum_fx( ener_vec, nb_tot_bands, &etmp );
            i = maximum_fx( ener_vec, nb_tot_bands, &etmp );
@@ -450,18 +191,7 @@ void bands_and_bit_alloc_fx(
            ener_vec[i] = 0;
            ener_vec[i] = 0;
            move16();
            move16();
        }
        }
#ifdef ADD_LRTD

                }
                else
                {
                    for ( ; j < nb_bands; j++ )
                    {
                        i = maximum( ener_vec, nb_tot_bands, &etmp );
                        max_ener_band[j] = i;
                        ener_vec[i] = fzero_val;
                    }
                }
#endif
        set32_fx( bits_per_bands, bit_fracf, nb_bands );
        set32_fx( bits_per_bands, bit_fracf, nb_bands );
    }
    }
    ELSE
    ELSE
@@ -476,16 +206,7 @@ void bands_and_bit_alloc_fx(
        move16();
        move16();
        st_band = 7;
        st_band = 7;
        move16();
        move16();
#ifdef ADD_LRTD

            if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
            {
                *pvq_len = 160;
                st_band = 10;
                nb_bands = *pvq_len / 16;
                bit_tmp -= 35;
                bit_new_bands = 5;
            }
#endif
        IF( LE_32( core_brate, ACELP_9k60 ) )
        IF( LE_32( core_brate, ACELP_9k60 ) )
        {
        {
            *pvq_len = 80;
            *pvq_len = 80;
@@ -507,9 +228,7 @@ void bands_and_bit_alloc_fx(
        }
        }


        nb_bands = shr( *pvq_len, 4 );
        nb_bands = shr( *pvq_len, 4 );
#ifdef ADD_LRTD

            nb_bands_max = min( nb_bands_max, MBANDS_GN_BITALLOC16k );
#endif
        /*------------------------------------------------------------------------
        /*------------------------------------------------------------------------
             * Ajustement of the maximum number of bands in function of the
             * Ajustement of the maximum number of bands in function of the
             * dynamics of the spectrum (more or less speech like)
             * dynamics of the spectrum (more or less speech like)
@@ -521,17 +240,6 @@ void bands_and_bit_alloc_fx(
        IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) )
        IF( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) )
        {
        {
            /* Probably classification error -> concentrate bits on LF */
            /* Probably classification error -> concentrate bits on LF */
#ifdef ADD_LRTD
                if ( L_frame == L_FRAME16k && core_brate >= ACELP_24k40 )
                {
                    nb_bands_max = nb_tot_bands - 2;
                }
                else if ( core_brate >= ACELP_16k40 )
                {
                    nb_bands_max = nb_bands + 2;
                }
                else
#endif
            if ( GE_32( core_brate, ACELP_8k00 ) )
            if ( GE_32( core_brate, ACELP_8k00 ) )
            {
            {
                nb_bands_max = add( nb_bands, 1 );
                nb_bands_max = add( nb_bands, 1 );
@@ -551,28 +259,7 @@ void bands_and_bit_alloc_fx(
        {
        {
            nb_bands_max = sub( nb_bands_max, 1 );
            nb_bands_max = sub( nb_bands_max, 1 );
        }
        }
#ifdef ADD_LRTD
            if ( L_frame == L_FRAME16k )
            {
                if ( core_brate < ACELP_24k40 )
                {
                    nb_bands_max -= 4;
                }
                else if ( core_brate < ACELP_32k )
                {
                    if ( Diff_len > 0 || noise_lev >= NOISE_LEVEL_SP2 )
                    {
                        nb_bands_max -= 2;
                        bit_new_bands *= 2;
                    }
                }
                else if ( core_brate >= ACELP_32k )
                {
                    bit_new_bands *= 2;
                }
            }


#endif
        test();
        test();
        if ( ( EQ_16( bwidth, NB ) ) && GT_16( nb_bands_max, 10 ) )
        if ( ( EQ_16( bwidth, NB ) ) && GT_16( nb_bands_max, 10 ) )
        {
        {
@@ -594,13 +281,7 @@ void bands_and_bit_alloc_fx(
        /*------------------------------------------------------------------------
        /*------------------------------------------------------------------------
             * Fractional bits to distribute on the first x bands
             * Fractional bits to distribute on the first x bands
             *-----------------------------------------------------------------------*/
             *-----------------------------------------------------------------------*/
#ifdef ADD_LRTD

            if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
            {
                bit_fracf = 0;
            }
            else
#endif
        {
        {
            bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18  */
            bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18  */
        }
        }
@@ -621,22 +302,7 @@ void bands_and_bit_alloc_fx(
            move32(); /* Q18 */
            move32(); /* Q18 */
            bit_index = add( bit_index, 1 );
            bit_index = add( bit_index, 1 );
        }
        }
#ifdef ADD_LRTD
            if ( L_frame == L_FRAME16k && core_brate > ACELP_16k40 )
            {
                bit_index = 0;
                i = imax - 1;
                bits_per_bands[i] += Compl_GSC_freq_bits[bit_index];
                i++;
                bit_index++;


                for ( ; i < 10; i++ )
                {
                    bits_per_bands[i] += Compl_GSC_freq_bits[bit_index] + bit_fracf;
                    bit_index++;
                }
            }
#endif
        IF( Diff_len == 0 )
        IF( Diff_len == 0 )
        {
        {
            bit_index = add( bit_index_mem, 10 );
            bit_index = add( bit_index_mem, 10 );
@@ -647,39 +313,11 @@ void bands_and_bit_alloc_fx(
                bit_index = add( bit_index, 1 );
                bit_index = add( bit_index, 1 );
            }
            }
        }
        }
#ifdef ADD_LRTD
            if ( bit_fracf < 0 )
            {
                for ( j = 0; j < nb_tot_bands; j++ )
                {
                    bits_per_bands[j] = max( bits_per_bands[j], 0 );
                }
            }


#endif
        /*--------------------------------------------------------------------------
        /*--------------------------------------------------------------------------
             * Complete the bit allocation per frequency band for 16kHz high brate mode
             * Complete the bit allocation per frequency band for 16kHz high brate mode
             *--------------------------------------------------------------------------*/
             *--------------------------------------------------------------------------*/
#ifdef ADD_LRTD
            if ( L_frame == L_FRAME16k && core_brate > ACELP_32k )
            {
                for ( j = st_band; j < nb_bands; j++ )
                {
                    bits_per_bands[j] = bit_new_bands;
                }

                bit_fracf = ( 1.0f / nb_bands ) * ( bit_tmp );


                etmp = 2.0f * bit_fracf / ( nb_bands + 1 );
                bit_fracf = etmp;
                for ( j = nb_bands - 1; j >= 0; j-- )
                {
                    bits_per_bands[j] += etmp;
                    etmp += bit_fracf;
                }
            }
            else
#endif
        {
        {
            FOR( j = st_band; j < nb_bands; j++ )
            FOR( j = st_band; j < nb_bands; j++ )
            {
            {
@@ -841,16 +479,7 @@ void bands_and_bit_alloc_fx(
        w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */
        w_sum_bit = add( w_sum_bit, out_bits_per_bands[i] ); /* Q3 */
    }
    }
    tmp = shl( *bit, 3 );
    tmp = shl( *bit, 3 );
#ifdef ADD_LRTD

        if ( GSC_IVAS_mode != 0 && sum_bit < *bit ) /* If we need to add bits, we are doing it on the LF */
        {
            reajust_bits( bits_per_bands, 0, nb_bands, (int16_t) sum_bit, *bit );
        }
        else
        {
            reajust_bits( bits_per_bands, nb_bands - 1, 0, (int16_t) sum_bit, *bit );
        }
#else
    IF( GT_16( tmp, w_sum_bit ) )
    IF( GT_16( tmp, w_sum_bit ) )
    {
    {
        i = sub( nb_bands, 1 );
        i = sub( nb_bands, 1 );
@@ -866,7 +495,7 @@ void bands_and_bit_alloc_fx(
            }
            }
        }
        }
    }
    }
#endif

    /*--------------------------------------------------------------------------
    /*--------------------------------------------------------------------------
         * Recompute the real number/length of frequency bands to encode
         * Recompute the real number/length of frequency bands to encode
         *--------------------------------------------------------------------------*/
         *--------------------------------------------------------------------------*/
@@ -884,70 +513,6 @@ void bands_and_bit_alloc_fx(
            Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 );
            Copy( exc_diff + shl( max_ener_band[j], 4 ), concat_in + shl( j, 4 ), 16 );
        }
        }
    }
    }
#ifdef ADD_LRTD
    }
    else /* *bit == 0 */
    {
        set_s( bits_per_bands_s, 0, nb_tot_bands );
        *nb_subbands = 0;
        *pvq_len = 0;
    }
#endif
    return;
}
#ifdef ADD_LRTD
/*-------------------------------------------------------------------*
 * reajust_bits()
 *
 *
 *-------------------------------------------------------------------*/

static void reajust_bits(
    float *bits_per_bands,
    const int16_t st_band,
    const int16_t end_band,
    const int16_t sum_bit_in,
    const int16_t bit_bdgt_in )
{
    int16_t i, amount_to_add, incr;
    int16_t bit_bdgt, sum_bit;

    incr = 1;
    if ( end_band < st_band )
    {
        incr = -1;
    }

    if ( bit_bdgt_in < sum_bit_in )
    {
        amount_to_add = -1;
        bit_bdgt = sum_bit_in;
        sum_bit = bit_bdgt_in;
    }
    else
    {
        bit_bdgt = bit_bdgt_in;
        sum_bit = sum_bit_in;
        amount_to_add = 1;
    }

    i = st_band;
    while ( bit_bdgt > sum_bit )
    {
        if ( amount_to_add > 0 || ( amount_to_add < 0 && bits_per_bands[i] > 1 ) )
        {
            bits_per_bands[i] += amount_to_add;
            sum_bit += (int16_t) abs( amount_to_add );
        }

        i += incr;
        if ( i == end_band )
        {
            i = st_band;
        }
    }


    return;
    return;
}
}

#endif
+55 −89

File changed.

Preview size limit exceeded, changes collapsed.

+14 −94
Original line number Original line Diff line number Diff line
@@ -793,7 +793,6 @@ void highband_exc_dct_in_fx(
        {
        {
            IF( exc_diffQ[i] == 0 )
            IF( exc_diffQ[i] == 0 )
            {
            {
                // PMT("code below to be validated for IVAS use")
                /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
                /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
                tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
                tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
                tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
                tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
@@ -876,66 +875,7 @@ void highband_exc_dct_in_fx(
    /*--------------------------------------------------------------------------------------*
    /*--------------------------------------------------------------------------------------*
     * Apply decoded gain onto the difference signal
     * Apply decoded gain onto the difference signal
     *--------------------------------------------------------------------------------------*/
     *--------------------------------------------------------------------------------------*/
#ifdef ADD_LRTD
    if ( GSC_IVAS_mode >= 1 )
    {
        float scale_factLF = 0.9f;
        float scale_factHF = 0.9f;

        if ( GSC_IVAS_mode == 1 && GSC_noisy_speech == 0 )
        {
            scale_factHF = 0.8f;
        }
        else if ( GSC_IVAS_mode == 2 || GSC_noisy_speech == 1 )
        {
            scale_factHF = 0.71f;
        }
        else if ( GSC_IVAS_mode == 3 )
        {
            scale_factHF = 0.9f;
        }
        for ( i = 0; i < pit_band_idx * 16; i++ )
        {
            exc_diffQ[i] *= scale_factLF;
        }
        for ( ; i < L_frame; i++ )
        {
            exc_diffQ[i] *= scale_factHF;
        }
    }
    else if ( GSC_noisy_speech )
    {
        float scale_fact = 0.9f;

        if ( element_mode == IVAS_CPE_TD )
        {
            if ( coder_type == INACTIVE )
            {
                scale_fact = 1.0f;
            }
            else
            {
                scale_fact = 0.95f;
            }
        }
        else if ( element_mode > IVAS_SCE )
        {
            scale_fact = 0.71f;
        }


        for ( i = 0; i < L_frame; i++ )
        {
            exc_diffQ[i] *= scale_fact;
        }
    }
    if ( GSC_noisy_speech && element_mode > IVAS_SCE && core_brate < ACELP_7k20 )
    {
        for ( i = 80; i < L_frame; i++ )
        {
            exc_diffQ[i] *= ( +0.0024f * (float) i + 1.192f );
        }
    }
#else
    IF( GSC_noisy_speech )
    IF( GSC_noisy_speech )
    {
    {
        FOR( i = 0; i < L_frame; i++ )
        FOR( i = 0; i < L_frame; i++ )
@@ -944,7 +884,7 @@ void highband_exc_dct_in_fx(
            move16();
            move16();
        }
        }
    }
    }
#endif

    Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
    Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );


    IF( exc_wo_nf != NULL )
    IF( exc_wo_nf != NULL )
@@ -1232,7 +1172,6 @@ void highband_exc_dct_in_ivas_fx(
        {
        {
            IF( exc_diffQ[i] == 0 )
            IF( exc_diffQ[i] == 0 )
            {
            {
                // PMT("code below to be validated for IVAS use")
                /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
                /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
                tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
                tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
                tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
                tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
@@ -1313,105 +1252,86 @@ void highband_exc_dct_in_ivas_fx(
            }
            }
        }
        }
    }
    }

    /*--------------------------------------------------------------------------------------*
    /*--------------------------------------------------------------------------------------*
     * Apply decoded gain onto the difference signal
     * Apply decoded gain onto the difference signal
     *--------------------------------------------------------------------------------------*/
     *--------------------------------------------------------------------------------------*/
#if 1 // def ADD_LRTD

    IF( GSC_IVAS_mode >= 1 )
    IF( GSC_IVAS_mode >= 1 )
    {
    {
        // float scale_factLF = 0.9f;
        Word16 scale_factLF = 29491; /* 0.9f */
        Word16 scale_factLF = 29491;
        move16();
        move16();
        // float scale_factHF = 0.9f;
        Word16 scale_factHF = 29491; /* 0.9f */
        Word16 scale_factHF = 29491;
        move16();
        move16();


        test();
        test();
        test();
        test();
        IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 )
        IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 )
        {
        {
            // scale_factHF = 0.8f;
            scale_factHF = 26214;
            scale_factHF = 26214;
            move16();
            move16();
        }
        }
        ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) )
        ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) )
        {
        {
            // scale_factHF = 0.71f;
            scale_factHF = 23265; /* 0.71f */
            scale_factHF = 23265;
            move16();
            move16();
        }
        }
        ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) )
        ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) )
        {
        {
            // scale_factHF = 0.9f;
            scale_factHF = 29491; /* 0.9f */
            scale_factHF = 29491;
            move16();
            move16();
        }
        }
        FOR( i = 0; i < pit_band_idx * 16; i++ )
        FOR( i = 0; i < pit_band_idx * 16; i++ )
        {
        {
            // exc_diffQ[i] *= scale_factLF;
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF );
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF );
        }
        }
        FOR( ; i < L_frame; i++ )
        FOR( ; i < L_frame; i++ )
        {
        {
            // exc_diffQ[i] *= scale_factHF;
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF );
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF );
            move16();
            move16();
        }
        }
    }
    }
    ELSE IF( GSC_noisy_speech )
    ELSE IF( GSC_noisy_speech )
    {
    {
        // float scale_fact = 0.9f;
        Word16 scale_fact = 29491; /* 0.9f */
        Word16 scale_fact = 29491;
        move16();
        move16();


        IF( EQ_16( element_mode, IVAS_CPE_TD ) )
        IF( EQ_16( element_mode, IVAS_CPE_TD ) )
        {
        {
            IF( coder_type == INACTIVE )
            IF( coder_type == INACTIVE )
            {
            {
                // scale_fact = 1.0f;
                scale_fact = 32767; /* 1.0f */
                scale_fact = 32767;
                move16();
                move16();
            }
            }
            ELSE
            ELSE
            {
            {
                // scale_fact = 0.95f;
                scale_fact = 31129; /* 0.95f */
                scale_fact = 31129;
                move16();
                move16();
            }
            }
        }
        }
        ELSE IF( GT_16( element_mode, IVAS_SCE ) )
        ELSE IF( GT_16( element_mode, IVAS_SCE ) )
        {
        {
            // scale_fact = 0.71f;
            scale_fact = 23265; /* 0.71f */
            scale_fact = 23265;
            move16();
            move16();
        }
        }


        FOR( i = 0; i < L_frame; i++ )
        FOR( i = 0; i < L_frame; i++ )
        {
        {
            // exc_diffQ[i] *= scale_fact;
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact );
            exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact );
            move16();
            move16();
        }
        }
    }
    }

    IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) )
    IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) )
    {
    {
        FOR( i = 80; i < L_frame; i++ )
        FOR( i = 80; i < L_frame; i++ )
        {
        {
            // exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f);
            /* exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); */
            exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ );
            exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ );
            move16();
            move16();
        }
        }
    }
    }
#else

    IF( GSC_noisy_speech )
    {
        FOR( i = 0; i < L_frame; i++ )
        {
            exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 );
            move16();
        }
    }
#endif
    Word16 Q_tmp = *Q_exc;
    Word16 Q_tmp = *Q_exc;
    move16();
    move16();
    Word16 Q_old = *Q_exc;
    Word16 Q_old = *Q_exc;
+1 −6
Original line number Original line Diff line number Diff line
@@ -155,12 +155,7 @@ void pre_echo_att_fx(
         *-------------------------------------------------------*/
         *-------------------------------------------------------*/


        etmp_fx = sum2_fx( exc_fx, L_frame );                          /*2*Q_new+1 */
        etmp_fx = sum2_fx( exc_fx, L_frame );                          /*2*Q_new+1 */
#ifdef ADD_LRTD
        PMTE()
        etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
        etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
#else
        etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
#endif
        *Last_frame_ener_fx = etmp_fx;
        *Last_frame_ener_fx = etmp_fx;
        move32(); /*2*Q_new+1*/
        move32(); /*2*Q_new+1*/
    }
    }
Loading