Commit 110b4754 authored by multrus's avatar multrus
Browse files

[cleanup] accept OPT_NBE_2311_HARM_GSC_GAIN

parent de08a5eb
Loading
Loading
Loading
Loading
+0 −542
Original line number Diff line number Diff line
@@ -392,9 +392,7 @@ void Ener_per_band_comp_ivas_fx(

static void GSC_gain_adj(
    const Word16 coder_type, /* i  : Coder type        */
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    const Word16 Mbands_gn, /* i  : Number of band    */
#endif
    const Word32 core_brate,  /* i  : Bit rate          */
    const Word16 mean_g,      /* i  : Average gain Q12  */
    Word16 *old_y_gain,       /* i/o: Previous frame dequantized vector */
@@ -404,24 +402,14 @@ static void GSC_gain_adj(
{
    /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
    Word16 Gain_off, i;
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    Word16 Fac_div;
    Fac_div = 102;
    move16();
#endif

#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    test();
    IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) )
#else
    IF( coder_type != INACTIVE )
#endif
    {
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
        FOR( i = 0; i < Mbands_gn; i++ )
#else
        FOR( i = 0; i < MBANDS_GN; i++ )
#endif
        {
            old_y_gain[i] = y_gain_tmp[i];
            move16();
@@ -434,7 +422,6 @@ static void GSC_gain_adj(
        Gain_off = 0;
        move16();

#ifdef OPT_NBE_2311_HARM_GSC_GAIN
        test();
        IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) /* IVAS LR mode only */
        {
@@ -444,9 +431,6 @@ static void GSC_gain_adj(
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_7k20 ) )
#else
        IF( LE_32( core_brate, ACELP_7k20 ) )
#endif
        {
            Gain_off = 32767;
            move16(); /* 8 -> Q12 */
@@ -478,11 +462,7 @@ static void GSC_gain_adj(
            old_y_gain[i] = y_gain_tmp[i];
            move16();
            /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
            y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, Fac_div /* 20/MBANDS_GN in Q15 */ ) ) ) );
#else
            y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 102 /* 20/MBANDS_GN in Q15 */ ) ) ) );
#endif
            move16();
        }
    }
@@ -490,483 +470,6 @@ static void GSC_gain_adj(
    return;
}

#ifndef OPT_NBE_2311_HARM_GSC_GAIN
/*-------------------------------------------------------------------*
 * GSC_gain_adj_ivas_fx()
 *
 * Quantization of the energy per band
 *-------------------------------------------------------------------*/

static void GSC_gain_adj_ivas_fx(
    const Word16 coder_type,  /* i  : Coder type        */
    const Word16 Mbands_gn,   /* i  : Number of band                          */
    const Word32 core_brate,  /* i  : Bit rate          */
    const Word16 mean_g,      /* i  : Average gain Q12  */
    Word16 *old_y_gain,       /* i/o: Previous frame dequantized vector */
    const Word16 *y_gain_tmp, /* i  : Dequantized gains */
    Word16 *y_gainQ           /* i/o: Output gains Q12  */
)
{
    /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
    Word16 Gain_off, i;

    test();
    IF( ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) )
    {
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            old_y_gain[i] = y_gain_tmp[i];
            move16();
            y_gainQ[i] = add( y_gain_tmp[i], mean_g );
            move16();
        }
    }
    ELSE
    {
        Gain_off = 0;
        move16();

        test();
        IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) )
        {
            Gain_off = 18432;
            move16(); /* 9 -> Q11 */
        }
        IF( LE_32( core_brate, ACELP_7k20 ) )
        {
            Gain_off = 16384;
            move16(); /* 8 -> Q11 */
        }
        ELSE IF( LE_32( core_brate, ACELP_8k00 ) )
        {
            Gain_off = 13517;
            move16(); /* 6.6f -> Q11 */
        }
        ELSE IF( LE_32( core_brate, ACELP_9k60 ) )
        {
            Gain_off = 9830;
            move16(); /*4.8f-> Q11 */
        }
        ELSE IF( LE_32( core_brate, ACELP_11k60 ) )
        {
            Gain_off = 7168;
            move16(); /* 3.5f -> Q11 */
        }
        ELSE IF( LE_32( core_brate, ACELP_13k20 ) )
        {
            Gain_off = 6144;
            move16(); /* 3.0f -> Q11 dB */
        }

        /*mimic ACELP decay of energy for low rates*/
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            old_y_gain[i] = y_gain_tmp[i];
            move16();
            y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 205 /* 20/MBANDS_GN in Q16 */ ) ) ) );
            move16();
        }
    }

    return;
}

/*-------------------------------------------------------------------*
 * GSC_gain_DQ()
 *
 * Form the final vector after gain quantization/Dequantization
 * Common to both encoder and decoder
 *-------------------------------------------------------------------*/

static void GSC_gain_DQ_fx(
    const Word16 element_mode, /* i  : element mode                            */
    const Word16 enc_dec,      /* i  : encoder/decoder flag                    */
    const Word16 coder_type,   /* i  : Coder type                              */
    const Word16 Mbands_gn,    /* i  : Number of band                          */
    const Word32 core_brate,   /* i  : Core bitrate                            */
    const Word16 mean_g,       /* i  : Average gain Q12                            */
    const Word16 *Gain_in,     /* i  : Unquantized gain vector Q12                 */
    Word16 *Gain_out           /* o  : Level adjusted unquantized gain vector Q12  */
)
{
    Word16 Gain_off;
    Word16 i;

    /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
    Gain_off = 0;
    move16();

    test();
    IF( coder_type == INACTIVE || EQ_16( coder_type, UNVOICED ) )
    {
        test();
        IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) )
        {
            Gain_off = 1843; // 9/20 in Q12
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_7k20 ) )
        {
            Gain_off = 1638; // 8/20 in Q12; /* 0 dB */
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_8k00 ) )
        {
            Gain_off = 1351; // 6.6f/20 in Q12 /* ~-3.3 dB */
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_9k60 ) )
        {
            Gain_off = 983; // 4.8f/20 in Q12 /* ~-2.4 dB */
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_11k60 ) )
        {
            Gain_off = 717; // 3.5f/20 in Q12 /* ~-2.4 dB */
            move16();
        }
        ELSE IF( LE_32( core_brate, ACELP_13k20 ) )
        {
            Gain_off = 614; // 3.0f/20 in Q12 /* ~-2.4 dB */
            move16();
        }
    }

    test();
    IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) )
    {
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            Gain_out[i] = add( Gain_in[i], mean_g ); // Q12
            move16();
        }
    }
    ELSE
    {
        /*mimic ACELP decay of energy for low rates*/
        test();
        IF( element_mode == EVS_MONO && EQ_16( enc_dec, DEC ) )
        {
            /* This is to keep EVS mono bit-exact with the standard (there might be a small desynchronization between encoder and decoder but there is no real quality or interop. issue) */
            FOR( i = 0; i < Mbands_gn; i++ )
            {
                Gain_out[i] = add( Gain_out[i], sub( mean_g, mult( Gain_off, div_s( i, Mbands_gn ) ) ) ); // Q12
                move16();
                // Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn );
            }
        }
        ELSE
        {
            FOR( i = 0; i < Mbands_gn; i++ )
            {
                Gain_out[i] = add( Gain_in[i], sub( mean_g, mult( Gain_off, div_s( i, Mbands_gn ) ) ) ); // Q12
                move16();
                // Gain_out[i] = Gain_in[i] + mean_g - ( i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ) );
            }
        }
    }

    return;
}


/*-------------------------------------------------------------------*
 * gsc_gainQ()
 *
 * Quantization of the energy per band
 *-------------------------------------------------------------------*/

Word16 gsc_gainQ_ivas_fx(
    BSTR_ENC_HANDLE hBstr,     /* i/o: encoder bitstream handle     */
    const Word16 element_mode, /* i  : element mode                 */
    const Word16 idchan,       /* i  : channel ID                   */
    const Word16 y_gain4[],
    /* i  : Energy per band              */ // Q12
    Word16 y_gainQ[],
    /* o  : quantized energy per band    */ // Q12
    const Word32 core_brate,                /* i  : Core rate                    */
    const Word16 coder_type,                /* i  : coding type                  */
    const Word16 bwidth,                    /* i  : input signal bandwidth       */
    const Word16 L_frame,                   /* i  : frame length                 */
    const Word16 tdm_LRTD_flag,             /* i  : LRTD stereo mode flag        */
    const Word32 core_brate_inp             /* i  : true core bitrate            */
)
{
    Word16 y_gain_tmp[MBANDS_GN16k];
    Word16 y_gain_tmp2[MBANDS_GN16k];
    Word16 i, idx_g = 0;
    move16();
    Word16 mean_4g_fx[1], ftmp1_fx;
    Word16 Mbands_gn = MBANDS_GN;
    move16();
    Word16 y_gain_tmp3[MBANDS_GN];
    Word32 L_tmp;

    if ( EQ_16( L_frame, L_FRAME16k ) )
    {
        Mbands_gn = MBANDS_GN16k;
        move16();
    }

    mean_4g_fx[0] = 0;
    move32();

    test();
    test();
    IF( ( EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && bwidth == NB )
    {
        L_tmp = 0;
        move32();
        FOR( i = 0; i < 10; i++ )
        {
            L_tmp = L_add( L_tmp, y_gain4[i] );
        }
        L_tmp = L_sub( Mpy_32_16_1( L_tmp, 3277 /* (1/10.0f) in Q15 */ ), 2457 /* 0.6f in Q12 */ ); // Q12
        ftmp1_fx = extract_l( L_tmp );
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            IF( LT_16( y_gain4[i], ftmp1_fx ) )
            {
                y_gain_tmp2[i] = ftmp1_fx; /*Q12*/
            }
            ELSE
            {
                y_gain_tmp2[i] = y_gain4[i]; /*Q12*/
            }
            move16();
        }

        /* Quantized mean gain without clipping */
        L_tmp = 0;
        move32();
        FOR( i = 0; i < 10; i++ )
        {
            L_tmp = L_add( L_tmp, y_gain4[i] );
        }
        L_tmp = Mpy_32_16_1( L_tmp, 3277 /* (1/10.0f) in Q15 */ ); // Q12
        mean_4g_fx[0] = extract_l( L_tmp );                        // Q12
        move16();
        idx_g = vquant_fx( mean_4g_fx, Gain_meanNB_fx, mean_4g_fx, Gain_mean_dicNB_fx, 1, 64 );
        push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );

        FOR( i = 0; i < Mbands_gn; i++ )
        {
            y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g_fx[0] ); // Q12
            move16();
        }

        if ( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) )
        {
            y_gain_tmp[9] = -1229; /* -0.3f in Q12 */
            move16();
        }

        set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
        idx_g = vquant_fx( y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64 );
        push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

        IF( LT_32( core_brate, ACELP_9k60 ) )
        {
            idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NB_fx, 3, 32 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

            idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NB_fx, 4, 16 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
        }
        ELSE
        {
            idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NBHR_fx, 3, 64 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

            idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NBHR_fx, 4, 128 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );
        }

        test();
        IF( LE_32( core_brate, ACELP_9k60 ) && coder_type == INACTIVE )
        {
            /* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */
            y_gain_tmp[10] = mean_fx( y_gain_tmp + 6, 3 ); /*Q12*/
            move16();
            y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); /*Q12*/
            move16();
            y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); /*Q12*/
            move16();
            y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); /*Q12*/
            move16();
            y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); /*Q12*/
            move16();
            y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); /*Q12*/
            move16();
        }
        ELSE
        {
            set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 );
        }
    }
    ELSE
    {
        L_tmp = 0;
        move32();
        FOR( i = 0; i < 16; i++ )
        {
            L_tmp = L_add( L_tmp, y_gain4[i] );
        }
        L_tmp = Mpy_32_16_1( L_tmp, 2048 /* (1/16.f) in Q15 */ ); // Q12
        ftmp1_fx = extract_l( L_tmp );
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) )
            {
                y_gain_tmp2[i] = sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ );
            }
            ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) )
            {
                y_gain_tmp2[i] = add( ftmp1_fx, 2457 /* 0.6 in Q12*/ );
            }
            ELSE
            {
                y_gain_tmp2[i] = y_gain4[i];
            }
            move16();
        }

        L_tmp = 0;
        move32();
        FOR( i = 0; i < 16; i++ )
        {
            L_tmp = L_add( L_tmp, y_gain_tmp2[i] );
        }
        L_tmp = Mpy_32_16_1( L_tmp, 2048 /* (1/16.f) in Q15 */ ); // Q12
        mean_4g_fx[0] = extract_l( L_tmp );                       // Q12
        move16();
        idx_g = vquant_fx( mean_4g_fx, mean_m_fx, mean_4g_fx, mean_gain_dic_fx, 1, 64 );
        push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 );

        /* Subtraction of the average gain */
        FOR( i = 0; i < Mbands_gn; i++ )
        {
            y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g_fx[0] ); // Q12
            move16();
        }

        IF( LT_32( core_brate, ACELP_9k60 ) )
        {
            /* prediction and quantization of the average gain */

            /*--------------------------------------------------------------------------------------*
             * Quantization of the first 8 bands
             * Keep only 4 bands out of the last 8 bands
             *--------------------------------------------------------------------------------------*/

            Copy( y_gain_tmp, y_gain_tmp2, 8 );

            y_gain_tmp2[8] = y_gain_tmp[8];
            move16();
            y_gain_tmp2[9] = y_gain_tmp[10];
            move16();
            y_gain_tmp2[10] = y_gain_tmp[12];
            move16();
            y_gain_tmp2[11] = y_gain_tmp[14];
            move16();

            idx_g = 0;
            move16();
            idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

            test();
            test();
            test();
            IF( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && EQ_16( idchan, 1 ) ) || GT_32( core_brate_inp, GSC_LRES_GAINQ_LIMIT ) )
            {
                idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

                /*----------------------------------------------------------------------*
                 * Vector quantization of the first 8 bands + quantization of the 4 bands out of the last 8
                 * Interpolation of the last 4 bands Q to create bands 8-16
                 *----------------------------------------------------------------------*/

                idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

                set16_fx( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 );

                /* Update to quantized vector */
                Copy( y_gain_tmp2, y_gain_tmp, 8 );

                Copy( y_gain_tmp2 + 8, y_gain_tmp3, 4 );
                set16_fx( y_gain_tmp + 8, 0, 8 );
                fft_rel_fx( y_gain_tmp2 + 8, 4, 2 );

                Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 );
                y_gain_tmp[15] = y_gain_tmp2[11];
                move16();
                ifft_rel_fx( y_gain_tmp + 8, 8, 3 );

                FOR( i = 8; i < 16; i++ )
                {
                    y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 /* 1.41 in Q14 */ ), 1 ); /*Q12*/
                    move16();
                }

                y_gain_tmp[8] = y_gain_tmp3[0];
                move16();
                y_gain_tmp[10] = y_gain_tmp3[1];
                move16();
                y_gain_tmp[12] = y_gain_tmp3[2];
                move16();
                y_gain_tmp[14] = y_gain_tmp3[3];
                move16();
            }
            ELSE
            {
                Copy( y_gain_tmp2, y_gain_tmp, 3 );
                set16_fx( y_gain_tmp + 3, 0, MBANDS_GN16k - 3 );
            }
        }
        ELSE
        {
            IF( EQ_16( L_frame, L_FRAME ) )
            {
                idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

                idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16_fx + 4, y_gain_tmp + 4, YG_dicMR_2_fx, 4, 32 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

                idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16_fx + 8, y_gain_tmp + 8, YG_dicMR_3_fx, 4, 32 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

                idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
            }
            ELSE
            {
                idx_g = vquant_fx( y_gain_tmp, YG_mean16HR_fx, y_gain_tmp, YG_dicHR_1_fx, 4, 128 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 );

                idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16HR_fx + 4, y_gain_tmp + 4, YG_dicHR_2_fx, 4, 64 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

                idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16HR_fx + 8, y_gain_tmp + 8, YG_dicHR_3_fx, 4, 64 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

                idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16HR_16kHz_fx, y_gain_tmp + 12, YG_dicHR_4_16kHz_fx, 4, 64 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );

                idx_g = vquant_fx( y_gain_tmp + 16, YG_meanL2G_16kHz_fx, y_gain_tmp + 16, YG_dicL2G_16kHz_fx, 2, 8 );
                push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
            }
        }
    }

    GSC_gain_DQ_fx( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g_fx[0], y_gain_tmp, y_gainQ );

    return mean_4g_fx[0];
}
#endif

/*==========================================================================*/
/* FUNCTION : Word16 gsc_gaindec_ivas_fx()                                  */
@@ -1158,19 +661,7 @@ Word16 gsc_gaindec_fx(
        }
    }

#ifndef OPT_NBE_2311_HARM_GSC_GAIN
    IF( st_fx->element_mode == EVS_MONO )
    {
        GSC_gain_adj( coder_type, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx );
    }
    ELSE
    {
        /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
        GSC_gain_adj_ivas_fx( coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx );
    }
#else
    GSC_gain_adj( coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx );
#endif

    return mean_4g_fx;
}
@@ -1182,7 +673,6 @@ Word16 gsc_gaindec_fx(
 * Quantization of the energy per band
 *-------------------------------------------------------------------*/

#ifdef OPT_NBE_2311_HARM_GSC_GAIN
Word16 gsc_gainQ_fx(
    BSTR_ENC_HANDLE hBstr,      /* i/o: encoder bitstream handle     */
    const Word16 idchan,        /* i  : channel ID                   */
@@ -1195,43 +685,23 @@ Word16 gsc_gainQ_fx(
    const Word16 tdm_LRTD_flag, /* i  : LRTD stereo mode flag        */
    const Word32 core_brate_inp /* i  : true core bitrate            */
)
#else
Word16 gsc_gainQ_fx(                          /*Q12*/
                     BSTR_ENC_HANDLE hBstr,   /* i/o: bitstream handle            */
                     const Word16 y_gain4[],  /* i  : Energy per band              Q12 */
                     Word16 y_gainQ[],        /* o  : quantized energy per band    Q12 */
                     const Word32 core_brate, /* i  : Core rate                        */
                     const Word16 coder_type, /* i  : coding type                      */
                     const Word16 bwidth      /* i  : input signal bandwidth           */
)
#endif
{
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    Word16 y_gain_tmp[MBANDS_GN16k], y_gain_tmp2[MBANDS_GN16k];
#else
    Word16 y_gain_tmp[MBANDS_GN], y_gain_tmp2[MBANDS_GN];
#endif
    Word16 i, idx_g = 0;
    move16();
    Word16 mean_4g[1] = { 0 }, tmp16, tmp1, tmp2;
    move16();
    Word16 Mbands_gn = MBANDS_GN;
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    Word16 y_gain_tmp3[MBANDS_GN16k];
#else
    Word16 y_gain_tmp3[MBANDS_GN];
#endif
    Word16 cnt;
    Word32 L_tmp;

    mean_4g[0] = 0;
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    if ( EQ_16( L_frame, L_FRAME16k ) )
    {
        Mbands_gn = MBANDS_GN16k;
        move16();
    }
#endif

    test();
    test();
@@ -1385,13 +855,11 @@ Word16 gsc_gainQ_fx( /*Q12*/
            idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 );
            push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );

#ifdef OPT_NBE_2311_HARM_GSC_GAIN
            test();
            test();
            test();
            IF( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && EQ_16( idchan, 1 ) ) || GT_32( core_brate_inp, GSC_LRES_GAINQ_LIMIT ) )
            {
#endif
                idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 );
                idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 );
@@ -1424,20 +892,16 @@ Word16 gsc_gainQ_fx( /*Q12*/
                move16();
                y_gain_tmp[14] = y_gain_tmp3[3];
                move16();
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
            }
            ELSE
            {
                Copy( y_gain_tmp2, y_gain_tmp, 3 );
                set16_fx( y_gain_tmp + 3, 0, MBANDS_GN16k - 3 );
            }
#endif
        }
        ELSE
        {
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
            IF( EQ_16( L_frame, L_FRAME ) )
#endif
            {
                idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 );
@@ -1451,7 +915,6 @@ Word16 gsc_gainQ_fx( /*Q12*/
                idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 );
                push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 );
            }
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
            ELSE
            {
                idx_g = vquant_fx( y_gain_tmp, YG_mean16HR_fx, y_gain_tmp, YG_dicHR_1_fx, 4, 128 );
@@ -1469,16 +932,11 @@ Word16 gsc_gainQ_fx( /*Q12*/
                idx_g = vquant_fx( y_gain_tmp + 16, YG_meanL2G_16kHz_fx, y_gain_tmp + 16, YG_dicL2G_16kHz_fx, 2, 8 );
                push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 );
            }
#endif
        }
    }

    /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
#ifdef OPT_NBE_2311_HARM_GSC_GAIN
    GSC_gain_adj( coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ );
#else
    GSC_gain_adj( coder_type, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ );
#endif

    return mean_4g[0]; /*Q12*/
}
+0 −1
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@
/* any switch which is non-be wrt. TS 26.251 V3.0 */

#define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT  /* Dolby: Issue 2250:  random vector generation in GenShapedSHBExcitation() */
#define OPT_NBE_2311_HARM_GSC_GAIN                      /* VA: issue 2311: non-BE part of the GSC gain harmonization */
#define FIX_2261_REMOVE_LP_RESCALING                    /* VA: Remove of unnecessary lpc coefficient rescaling */
#define FIX_2320_OOB_SCE_SWITCHING                      /* VA: basop issue 2320: Correct the length of the buffer to be scaled in SCE/CPE switching */
#define FIX_2302_LSF_CDBK_THRESHOLD                     /* VA: basop issue 2302: fix threshold for LSF Q codebook-type decision  */
+0 −26

File changed.

Preview size limit exceeded, changes collapsed.

+0 −16

File changed.

Preview size limit exceeded, changes collapsed.