Commit 2ad49e70 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Resolving issues reported with decod_gen_2sbfr_ivas_fx()

[x] Updated Wrong scaling when going from float
to fixed point for Aq, causing Overflow in syn_filt_s_lc_fx()
[x] Fix for issue when computing the excitation in
decod_gen_2sbfr_ivas_fx()
[x] Addressed uninitialized variables used in
decod_gen_2sbfr_ivas_fx() + call to enhancer_fx
has wrong parameters.
parent 8afb9bf0
Loading
Loading
Loading
Loading
Loading
+43 −30
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ void tdm_low_rate_dec(

    return;
#else
    st->Q_exc = 0;

    /*hGSCDec float2fix*/
    st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx;
    st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit;
@@ -178,7 +180,7 @@ void tdm_low_rate_dec(
    st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed(st->hGSCDec->Last_frame_ener, Q3) : MAX_32;
    floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME);
    st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx;
    floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, 0, L_FRAME);
    floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME);
    //st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0);
    Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6);
    st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
@@ -208,15 +210,15 @@ void tdm_low_rate_dec(
    for (int i = 0; i < M; i++) {
        lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f);
    }
    tdm_low_rate_dec_fx(st, dct_epit_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, 0);
    fixedToFloat_arr(dct_epit_fx, dct_epit, 0, L_FRAME);
    tdm_low_rate_dec_fx(st, dct_epit_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, st->Q_exc);
    fixedToFloat_arr(dct_epit_fx, dct_epit, st->Q_exc, L_FRAME);
    //*tmp_noise = fixedToFloat(tmp_noise_fx, Q3);
    fixedToFloat_arr(pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k);
    fixedToFloat_arr(voice_factors_fx, voice_factors, Q15, 5);
    fixedToFloat_arr(exc_fx, exc, 0, L_FRAME);
    fixedToFloat_arr(exc2_fx, exc2  , 0, L_FRAME);
    fixedToFloat_arr(exc_fx, exc, st->Q_exc, L_FRAME);
    fixedToFloat_arr(exc2_fx, exc2  , st->Q_exc, L_FRAME);
    if (bwe_exc) {
        fixedToFloat_arr(bwe_exc_fx, bwe_exc, 0, L_FRAME32k);
        fixedToFloat_arr(bwe_exc_fx, bwe_exc, st->Q_exc, L_FRAME32k);
    }
    
    /*hGSCDec fix2float*/
@@ -228,7 +230,7 @@ void tdm_low_rate_dec(
    st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, Q3);
    fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME);
    st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx;
    fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, 0, L_FRAME);
    fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME);
    st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0);
    Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6);
    st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
@@ -245,13 +247,13 @@ void tdm_low_rate_dec(
#ifdef IVAS_FLOAT_FIXED
void tdm_low_rate_dec_fx(
    Decoder_State *st,    /* i/o: decoder static memory                   */
    Word16 dct_epit[],     /* o  : GSC excitation in DCT domain Q0           */
    Word16 dct_epit[],     /* o  : GSC excitation in DCT domain Q_exc           */
    //Word16 *tmp_noise,     /* o  : long term temporary noise energy Q3       */
    Word16 *pitch_buf,     /* o  : floating pitch values for each subframe Q6 */
    Word16 *voice_factors, /* o  : voicing factors Q15                        */
    Word16 *exc,           /* i/o: adapt. excitation exc Q0?                  */
    Word16 *exc2,          /* i/o: adapt. excitation/total exc Q0?            */
    Word16 *bwe_exc,       /* o  : excitation for SWB TBE Q0?                 */
    Word16 *exc,           /* i/o: adapt. excitation exc Q_exc                  */
    Word16 *exc2,          /* i/o: adapt. excitation/total exc Q_exc            */
    Word16 *bwe_exc,       /* o  : excitation for SWB TBE Q_exc                 */
    const Word16 *lsf_new,  /* i  : ISFs at the end of the frame Q8/100 (2.56x)          */
    Word16 Q_exc
)
@@ -518,6 +520,8 @@ void decod_gen_2sbfr(

    return;
#else
    st->Q_exc = 0;

    /*hGSCDec float2fix*/
    st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx;
    st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit;
@@ -527,7 +531,7 @@ void decod_gen_2sbfr(
    st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed( st->hGSCDec->Last_frame_ener, Q3 ) : MAX_32;
    floatToFixed_arr( st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME );
    st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx;
    floatToFixed_arr( st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, 0, L_FRAME );
    floatToFixed_arr( st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME );
    // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0);
    Copy( st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6 );
    st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
@@ -543,6 +547,9 @@ void decod_gen_2sbfr(
    st->last_coder_type_fx = st->last_coder_type;
    /*hGSCDec end*/

    st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16);
    st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15);

    Word16 Aq_fx[NB_SUBFR16k * (M + 1)];
    Word16 pitch_buf_fx[NB_SUBFR16k];
    Word16 voice_factors_fx[5];
@@ -551,11 +558,11 @@ void decod_gen_2sbfr(
    Word16 bwe_exc_fx[L_FRAME32k], * p_bwe_exc_fx;
    Word16 gain_buf_fx[NB_SUBFR16k];
    Word16 tdm_Pri_pitch_buf_fx[NB_SUBFR];
    floatToFixed_arr((Float32 *)Aq, Aq_fx, Q14, NB_SUBFR16k * (M + 1));
    floatToFixed_arr((Float32 *)Aq, Aq_fx, Q12, NB_SUBFR16k * (M + 1));
    floatToFixed_arr((Float32 *)tdm_Pri_pitch_buf, tdm_Pri_pitch_buf_fx, Q6, NB_SUBFR);
    floatToFixed_arr(exc - L_EXC_MEM_DEC, old_exc_fx, Q8, L_EXC_DEC);
    floatToFixed_arr(exc - L_EXC_MEM_DEC, old_exc_fx, st->Q_exc, L_EXC_DEC);
    exc_fx = old_exc_fx + L_EXC_MEM_DEC;
    floatToFixed_arr(exc2 - L_EXC_MEM, old_exc2_fx, Q8, L_FRAME16k + L_EXC_MEM);
    floatToFixed_arr(exc2 - L_EXC_MEM, old_exc2_fx, st->Q_exc, L_FRAME16k + L_EXC_MEM);
    exc2_fx = old_exc2_fx + L_EXC_MEM;
    floatToFixed_arr(gain_buf, gain_buf_fx, Q14, NB_SUBFR16k);
    if (bwe_exc) {
@@ -565,14 +572,14 @@ void decod_gen_2sbfr(
    else {
        p_bwe_exc_fx = NULL;
    }
    decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, p_bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q8);
    decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, p_bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, st->Q_exc);
    fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k );
    fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, 5 );
    fixedToFloat_arr( exc_fx, exc, Q8, L_FRAME );
    fixedToFloat_arr( exc2_fx, exc2, Q8, L_FRAME );
    fixedToFloat_arr( exc_fx, exc, st->Q_exc, L_FRAME );
    fixedToFloat_arr( exc2_fx, exc2, st->Q_exc, L_FRAME );
    fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k);
    if (bwe_exc) {
        fixedToFloat_arr(p_bwe_exc_fx, bwe_exc, Q8, L_FRAME32k);
        fixedToFloat_arr(p_bwe_exc_fx, bwe_exc, st->Q_exc, L_FRAME32k);
    }

    /*hGSCDec fix2float*/
@@ -584,7 +591,7 @@ void decod_gen_2sbfr(
    st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, Q3 );
    fixedToFloat_arr( st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME );
    st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx;
    fixedToFloat_arr( st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, Q8, L_FRAME );
    fixedToFloat_arr( st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME );
    st->hGSCDec->last_ener = fixedToFloat( st->hGSCDec->last_ener_fx, 0 );
    Copy( st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6 );
    st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
@@ -596,6 +603,8 @@ void decod_gen_2sbfr(
    st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16);
    fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6);
/*hGSCDec end*/
    st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16);
    st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15);
#endif
}

@@ -609,15 +618,15 @@ void decod_gen_2sbfr(
void decod_gen_2sbfr_ivas_fx(
    Decoder_State *st,                 /* i/o: decoder static memory                     */
    const Word16 sharpFlag,            /* i  : formant sharpening flag                   */
    const Word16 *Aq,                  /* i  : LP filter coefficient                     */
    Word16 *pitch_buf,                 /* o  : floating pitch values for each subframe   */
    Word16 *voice_factors,             /* o  : voicing factors                           */
    Word16 *exc,                       /* i/o: adapt. excitation exc                     */
    Word16 *exc2,                      /* i/o: adapt. excitation/total exc               */
    Word16 *bwe_exc,                   /* o  : excitation for SWB TBE                    */
    Word16 *gain_buf,                  /* o  : floating pitch gain for each subframe     */
    const Word16 *Aq,                  /* i  : LP filter coefficient Q12                    */
    Word16 *pitch_buf,                 /* o  : floating pitch values for each subframe Q6  */
    Word16 *voice_factors,             /* o  : voicing factors Q15                          */
    Word16 *exc,                       /* i/o: adapt. excitation exc Q_exc                    */
    Word16 *exc2,                      /* i/o: adapt. excitation/total exc Q_exc              */
    Word16 *bwe_exc,                   /* o  : excitation for SWB TBE Q_exc                   */
    Word16 *gain_buf,                  /* o  : floating pitch gain for each subframe Q14    */
    const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag          */
    const Word16 tdm_Pri_pitch_buf[],  /* i  : pitch values for primary channel          */
    const Word16 tdm_Pri_pitch_buf[],  /* i  : pitch values for primary channel Q6         */
    Word16 Q_exc )
{
    Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables                          */
@@ -721,12 +730,16 @@ void decod_gen_2sbfr_ivas_fx(
         * Find the total excitation
         *----------------------------------------------------------------------*/

        Word16 gain_code16 = round_fx(L_shl(gain_code, st->Q_exc)); /*Q_exc*/

        for ( i = 0; i < 2 * L_SUBFR; i++ )
        {
            // exc2[i + i_subfr] = gain_pit * exc[i + i_subfr];
            exc2[i + i_subfr] = mult_r( gain_pit, shl( exc[i + i_subfr], Q15 - Q14 ) );
            Word32 L_tmp = L_shl(L_mult(gain_pit, exc[i + i_subfr]), 1); /*Q16+Q_exc*/
            exc2[i + i_subfr] = round_fx(L_tmp); /*Q_exc*/
            // exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];
            exc[i + i_subfr] = add( exc2[i + i_subfr], (Word16) L_shr( Mpy_32_16_1( gain_code, code[i] ), Q9 ) );
            L_tmp = L_add(L_tmp, L_shl(L_mult(gain_code16, code[i]), 6)); /*Q16+Q_exc*/
            exc[i + i_subfr] = round_fx(L_tmp); /*Q_exc*/
        }

        /*-----------------------------------------------------------------*