Commit 42aa19fc authored by vaillancour's avatar vaillancour
Browse files

proposed clean-up to 2467

parent 4ba91358
Loading
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ void bands_and_bit_alloc_ivas_fx(
    Word16 etmp;
    Word16 tmp;
    Word16 pos, band;
    Word32 SWB_bit_budget;                        /* Q0 -> Q18 */
    Word16 SWB_bit_budget;                        /* Q0 */
    Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; /* Q18 */
    Word16 w_sum_bit;
    Word16 fzero_val;
@@ -248,7 +248,7 @@ void bands_and_bit_alloc_ivas_fx(
        ELSE IF( EQ_16( GSC_noisy_speech, 1 ) )
        {
            SWB_bit_budget = *bit; /*Q0*/
            move32();
            move16();
            nb_bands = 5;
            move16();
            fzero_val = 0;
@@ -266,7 +266,7 @@ void bands_and_bit_alloc_ivas_fx(
                nb_bands = 3;
                move16();

                if ( GT_32( SWB_bit_budget, 20 ) )
                if ( GT_16( SWB_bit_budget, 20 ) )
                {
                    nb_bands = 5;
                    move16();
@@ -283,7 +283,7 @@ void bands_and_bit_alloc_ivas_fx(

            set32_fx( bits_per_bands, 0, MBANDS_GN );
            /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */
            bit_fracf = Find_bit_frac_fx( nb_bands, extract_l( SWB_bit_budget ) ); /*Q18*/
            bit_fracf = Find_bit_frac_fx( nb_bands, SWB_bit_budget ); /*Q18*/
            nb_tot_bands = sub( nb_bands_max, 6 );
            nb_tot_bands = s_min( nb_tot_bands, 16 );

@@ -904,13 +904,15 @@ static Word16 Find_bit_alloc_IVAS_fx(
{
    Word32 mp, mb, nb_bands_adj, bit_adj;
    Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k];
    Word32 SWB_bit_budget; /* Q0 -> Q18 */
    Word32 SWB_bit_budgetQ5; /* Q0 -> Q5 */
    Word32 SWB_bit_budgetQ18; /* Q0 -> Q18 */
    Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp;
    Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/;
    Word16 d_tmp, e_div, tmp16;
    Word32 Ltmp, etmp_32fx;

    SWB_bit_budget = *bit; /* Q0 */
    SWB_bit_budgetQ18 = L_shl( *bit, 18 ); /* Q0 -> Q18 */
    SWB_bit_budgetQ5 = L_shl( *bit, 5 );   /* Q0 -> Q5 */
    st_band = 5;
    nb_bands_max = nb_tot_bands_in;

@@ -960,12 +962,12 @@ static Word16 Find_bit_alloc_IVAS_fx(
    IF( EQ_16( GSC_IVAS_mode, 1 ) && LT_32( core_brate, GSC_L_RATE_STG ) )
    {
        /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/
        nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, Q18 ) ), Q18_0_75 ); /* Q18 */
        nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, SWB_bit_budgetQ18 ), Q18_0_75 ); /* Q18 */
    }
    ELSE IF( NE_16( GSC_IVAS_mode, 2 ) && GT_32( core_brate, GSC_H_RATE_STG ) )
    {
        /*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/
        nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, Q18 ) ), Q18_1_2 ); /* Q18 */
        nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, SWB_bit_budgetQ18 ), Q18_1_2 ); /* Q18 */
    }
    /*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/

@@ -975,7 +977,7 @@ static Word16 Find_bit_alloc_IVAS_fx(
    /* bit_fracf *= SWB_bit_budget;*/

    /* At this point bit_fracf has a value below 1.0 */
    bit_fracf = Mpy_32_16_1( L_shl( bit_fracf, 10 ), extract_l( L_shl( SWB_bit_budget, 5 ) ) ); /* (Q(18+10)*Q(0+5) + 1 - 16 =  Q18 */
    bit_fracf = Mpy_32_16_1( L_shl( bit_fracf, 10 ), extract_l( SWB_bit_budgetQ5 ) ); /* (Q(18+10)*Q(0+5) + 1 - 16 =  Q18 */

    /* Estimation of the number of bit used in HF */
    /* with only the first weighting The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
@@ -1006,7 +1008,7 @@ static Word16 Find_bit_alloc_IVAS_fx(

    /* nb_tot_bands = (int16_t)((SWB_bit_budget - bit_fracf) / (mp + (mb - mp) / 2.0f)); */
    d_tmp = Find_norm_inv_fx( L_add( mp, mb ), &e_div );
    Ltmp = Mpy_32_16_1( L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ), d_tmp ); /* Perform mult by 1/den */
    Ltmp = Mpy_32_16_1( L_sub( SWB_bit_budgetQ18, bit_fracf ), d_tmp ); /* Perform mult by 1/den */
    nb_tot_bands_loc = extract_h( L_shl( Ltmp, sub( 1, e_div ) ) );                /* adjust exponent:   1 is to take into account the  / 2.0f, and e_div for the num and den of the division*/
    mp = L_min( mp, mb );

@@ -1042,7 +1044,7 @@ static Word16 Find_bit_alloc_IVAS_fx(
    }

    /* SWB_bit_budget -= bit_fracf; */
    SWB_bit_budget = L_sub( L_shl( SWB_bit_budget, Q18 ), bit_fracf ); /* Q0->Q18 */
    SWB_bit_budgetQ18 = L_sub( SWB_bit_budgetQ18, bit_fracf ); /* Q0->Q18 */

    /* Find low energy band in HF */
    set16_fx( nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k );
@@ -1081,7 +1083,7 @@ static Word16 Find_bit_alloc_IVAS_fx(

        /* mb = ( SWB_bit_budget * 2 / ( nb_tot_bands_loc - st_band ) ) - mp; */
        d_tmp = Find_norm_inv_fx( L_deposit_h( sub( nb_tot_bands_loc, st_band ) ), &e_div );
        mb = L_sub( L_shr( Mpy_32_16_1( L_shl( SWB_bit_budget, 1 ), d_tmp ), e_div ), mp ); /* Q18 */
        mb = L_sub( L_shr( Mpy_32_16_1( L_shl( SWB_bit_budgetQ18, 1 ), d_tmp ), e_div ), mp ); /* Q18 */

        /* bit_fracf = ( mb - mp ) / ( nb_tot_bands_loc - st_band ); */
        bit_fracf = L_shr( Mpy_32_16_1( L_sub( mb, mp ), d_tmp ), e_div ); /* Q18 */
@@ -1098,21 +1100,21 @@ static Word16 Find_bit_alloc_IVAS_fx(
                move32();
            }
            mb = L_sub( mb, bit_fracf );
            SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); /* Q18 */
            SWB_bit_budgetQ18 = L_sub( SWB_bit_budgetQ18, bits_per_bands[max_ener_band[j]] ); /* Q18 */
        }
    }

    /* Series of verification in case bit allocated != the budget */
    IF( SWB_bit_budget > 0 )
    IF( SWB_bit_budgetQ18 > 0 )
    {
        i = sub( st_band, 1 );
        WHILE( SWB_bit_budget > 0 )
        WHILE( SWB_bit_budgetQ18 > 0 )
        {
            /* bits_per_bands[i]++; */
            bits_per_bands[i] = L_add( bits_per_bands[i], Q18_1_0 ); /*Q18*/
            move32();
            /* SWB_bit_budget--; */
            SWB_bit_budget = L_sub( SWB_bit_budget, Q18_1_0 ); /*Q18*/
            SWB_bit_budgetQ18 = L_sub( SWB_bit_budgetQ18, Q18_1_0 ); /*Q18*/
            i = sub( i, 1 );
            if ( EQ_16( i, -1 ) )
            {