Commit 42023f79 authored by vaillancour's avatar vaillancour
Browse files

possible fix to 1320

parent 6ccfabfa
Loading
Loading
Loading
Loading
+48 −5
Original line number Diff line number Diff line
@@ -222,6 +222,10 @@ void encod_gen_2sbfr(

    LPD_state_HANDLE hLPDmem = st->hLPDmem;

#ifdef FIX_1320_LOWRATE_ACELP
    Word16 gcode16;
    Word32 Lgcode, Ltmp;
#endif
#ifdef MSAN_FIX
    set16_fx( cn, 0, 2 * L_SUBFR ); /* Target vector in residual domain  */
#endif
@@ -269,8 +273,12 @@ void encod_gen_2sbfr(
        // Scale_sig( &hLPDmem->mem_w0, M + 1, sub( add( *Q_new, hLPDmem->e_mem_syn ), Q16 ) ); // M + 1 to sync mem_syn exponent with mem_w0 exponent
        // hLPDmem->e_mem_syn = sub( Q16, *Q_new );

        find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 );

#ifndef FIX_1320_LOWRATE_ACELP
        find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 );
#else
        find_targets_ivas_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, 2 * L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 );
#endif
        /*Scale_sig(h1, L_SUBFR, shift);  */ /*Q14-shift */
        Copy_Scale_sig( h1, h2, 2 * L_SUBFR, -2 );
        Scale_sig( h1, 2 * L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
@@ -300,8 +308,11 @@ void encod_gen_2sbfr(
         * LP filtering of the adaptive excitation, codebook target computation
         *-----------------------------------------------------------------*/

#ifndef FIX_1320_LOWRATE_ACELP
        lp_filt_exc_enc_fx( MODE1, coder_type, i_subfr, exc, h1, xn, y1, xn2, 2 * L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &st->acelp_cfg.ltf_mode );

#else
        lp_filt_exc_enc_ivas_fx( MODE1, coder_type, i_subfr, exc, h1, xn, y1, xn2, 2 * L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &st->acelp_cfg.ltf_mode );
#endif
        /* update long-term pitch gain for speech/music classifier */
        st->hSpMusClas->lowrate_pitchGain = add( mult( 29491, st->hSpMusClas->lowrate_pitchGain ), mult( 3277, gain_pit ) ); // Q14
        move16();
@@ -334,14 +345,30 @@ void encod_gen_2sbfr(

        gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx );

#ifndef FIX_1320_LOWRATE_ACELP
        hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, Q_new, 2 * L_SUBFR, 0 );
#else
        Lgcode = L_shl_sat( gain_code, sub( Q_new, 0 ) ); /* scaled gain_code with Qnew -> Q16*/
        gcode16 = round_fx_sat( Lgcode );          /*Q0*/
        hLPDmem->tilt_code = est_tilt_ivas_fx(exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR, 0);
#endif
        move16();

        /*-----------------------------------------------------------------*
         * Update memory of the weighting filter
         *-----------------------------------------------------------------*/

#ifndef FIX_1320_LOWRATE_ACELP
        hLPDmem->mem_w0 = sub( sub( xn[2 * L_SUBFR - 1], mult_r( gain_pit, y1[2 * L_SUBFR - 1] ) ), mult_r( extract_h( gain_code ), y2[2 * L_SUBFR - 1] ) );
#else
        Ltmp = L_mult0( gcode16, y2[2 * L_SUBFR - 1] ); /*Q10*/
        Ltmp = L_shl( Ltmp, add(5, shift ) );        /*Q15+shift*/
        Ltmp = L_negate( Ltmp );
        Ltmp = L_mac( Ltmp, xn[2 * L_SUBFR - 1], 16384 /*Q14*/ );       /* Q_new-1+shift+14+1 */
        Ltmp = L_msu( Ltmp, y1[2 * L_SUBFR - 1], gain_pit /*Q14*/ ); /* Q_new-1+shift+14+1 */
        Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );                     /* 15 + Q_new */
        hLPDmem->mem_w0 = round_fx_sat( Ltmp );                        /*Q_new-1        */
#endif
        move16();

        /*-----------------------------------------------------------------*
@@ -349,6 +376,7 @@ void encod_gen_2sbfr(
         * Save the non-enhanced excitation for FEC_exc
         *-----------------------------------------------------------------*/

#ifndef FIX_1320_LOWRATE_ACELP
        FOR( i = 0; i < 2 * L_SUBFR; i++ )
        {
            exc2[i + i_subfr] = mult( gain_pit, exc[i + i_subfr] );
@@ -356,7 +384,20 @@ void encod_gen_2sbfr(
            exc[i + i_subfr] = add( exc2[i + i_subfr], mult( extract_h( gain_code ), code[i] ) );
            move16();
        }

#else
        FOR(i = 0; i < 2 * L_SUBFR; i++)
        {
            /* code in Q9, gain_pit in Q14 */
            exc2[i + i_subfr] = shl_sat( mult( gain_pit, exc[i + i_subfr] ), 1 );
            Ltmp = L_mult( gcode16, code[i] );                                   /* Q10 */
            Ltmp = L_shl_sat( Ltmp, 5 );                                   /* Q15 */
            Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 */
            Ltmp = L_shl_sat( Ltmp, 1 );                                   /* saturation can occur here Q16*/
            exc[i + i_subfr] = round_fx_sat( Ltmp );
            move16();
            move16();
        }
#endif
        /*-----------------------------------------------------------------*
         * Prepare TBE excitation
         *-----------------------------------------------------------------*/
@@ -370,9 +411,11 @@ void encod_gen_2sbfr(
         * Synthesize speech to update mem_syn_flt[].
         * Update A(z) filters
         *-----------------------------------------------------------------*/

#ifndef FIX_1320_LOWRATE_ACELP
        E_UTIL_synthesis( 0, p_Aq, &exc[i_subfr], &syn[i_subfr], 2 * L_SUBFR, hLPDmem->mem_syn, 1, M );

#else
        Syn_filt_s(1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], 2 * L_SUBFR, hLPDmem->mem_syn, 1 );
#endif
        p_Aw += 2 * ( M + 1 );
        p_Aq += 2 * ( M + 1 );