Commit 08a75c40 authored by vaclav's avatar vaclav
Browse files

harmonize encod_gen_voic_fx(), under CLEANUP_ACELP_ENC

parent 374d8c89
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -528,8 +528,13 @@ ivas_error acelp_core_enc_fx(
                hTdCngEnc->burst_ho_cnt = 0;
                move16();
                /* VOICED frames in SC-VBR when bumped up*/
#ifdef CLEANUP_ACELP_ENC
                encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx,
                                   exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new );
#else
                encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx,
                                   exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new );
#endif
            }
        }
        ELSE IF( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_24k40 ) ) )
@@ -541,8 +546,13 @@ ivas_error acelp_core_enc_fx(
        ELSE
        {
            /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
#ifdef CLEANUP_ACELP_ENC
            encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx,
                               exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new );
#else
            encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx,
                               exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new );
#endif
        }

        /* update st->mem_syn1 for ACELP core switching */
@@ -1385,7 +1395,11 @@ ivas_error acelp_core_enc_ivas_fx(
                move16();

                /* VOICED frames in SC-VBR */
#ifdef CLEANUP_ACELP_ENC
                encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
#else
                encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
#endif
            }
        }
        ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) )
@@ -1400,7 +1414,11 @@ ivas_error acelp_core_enc_ivas_fx(
        ELSE
        {
            /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
#ifdef CLEANUP_ACELP_ENC
            encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
#else
            encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
#endif
        }

        /* update mem_syn1_flt for ACELP core switching */
+119 −53
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ static void rem_offset(
/* RETURN ARGUMENTS :                                                   */
/* _ None                                                               */
/*======================================================================*/

#ifndef CLEANUP_ACELP_ENC
void encod_gen_voic_fx(
    Encoder_State *st_fx,              /* i/o: state structure                                  */
    const Word16 speech_fx[],          /* i  : input speech                                     Q0*/
@@ -444,18 +444,22 @@ void encod_gen_voic_fx(

    return;
}
#endif


#ifdef CLEANUP_ACELP_ENC
void encod_gen_voic_fx(
#else
void encod_gen_voic_ivas_fx(
#endif
    Encoder_State *st_fx,              /* i/o: state structure                                  */
    const Word16 speech_fx[],          /* i  : input speech                                     Qnew -1 */
    const Word16 speech_fx[],          /* i  : input speech                                     Q0 / Qnew -1 */
    const Word16 Aw_fx[],              /* i  : weighted A(z) unquantized for subframes          Q12*/
    const Word16 Aq_fx[],              /* i  : 12k8 Lp coefficient                              Q12*/
    const Word16 Es_pred_fx,           /* i  : predicted scaled innov. energy                   Q8*/
    const Word16 *res_fx,              /* i  : residual signal                                  Q_new*/
    Word16 *syn_fx,                    /* i/o: core synthesis                                   Q_new - 1*/
    Word16 *exc_fx,                    /* i/o: current non-enhanced excitation                  Q_new*/
    Word16 *exc2_fx,                   /* i/o: current enhanced excitation                      Q_new*/
    Word16 *syn_fx,                    /* i/o: core synthesis                                   Qnew / Q_new - 1*/
    Word16 *exc_fx,                    /* i/o: current non-enhanced excitation                  Q0 / Q_new*/
    Word16 *exc2_fx,                   /* i/o: current enhanced excitation                      Q0 / Q_new*/
    Word16 *pitch_buf_fx,              /* i/o: floating pitch values for each subframe          Q6*/
    Word16 *voice_factors_fx,          /* o  : voicing factors                                  Q15*/
    Word16 *bwe_exc_fx,                /* o  : excitation for SWB TBE                           Q0*/
@@ -558,7 +562,12 @@ void encod_gen_voic_ivas_fx(
    set16_fx( code_preQ_fx, 0, L_SUBFR );

    shift_wsp = add( Q_new, shift );
#ifdef CLEANUP_ACELP_ENC
    test();
    if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && st_fx->element_mode != EVS_MONO )
#else
    if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
#endif
    {
        shift_wsp = sub( shift_wsp, 1 );
    }
@@ -595,6 +604,20 @@ void encod_gen_voic_ivas_fx(

        Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/

#ifdef CLEANUP_ACELP_ENC
        IF( st_fx->element_mode == EVS_MONO )
        {
            find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx,
                             res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );

            Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 );  /*Q11*/
            Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/
            /* scaling of xn[] to limit dynamic at 12 bits */
            Scale_sig( xn_fx, L_SUBFR, shift );
        }
        ELSE
#endif
        {
            find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx,
                                  res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );

@@ -611,6 +634,7 @@ void encod_gen_voic_ivas_fx(
                rem_offset( xn_fx, xn_fx, L_SUBFR );
                rem_offset( cn_fx, cn_fx, L_SUBFR );
            }
        }

        /*----------------------------------------------------------------*
         * Close-loop pitch search and quantization
@@ -630,7 +654,16 @@ void encod_gen_voic_ivas_fx(
         * Find adaptive exitation
         *-----------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
        IF( st_fx->element_mode == EVS_MONO )
        {
            pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
        }
        ELSE
#endif
        {
            pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
        }

        /*-----------------------------------------------------------------*
         * Gain clipping test to avoid unstable synthesis on frame erasure
@@ -721,7 +754,14 @@ void encod_gen_voic_ivas_fx(
        gcode16 = round_fx_sat( Lgcode );

#ifdef CLEANUP_ACELP_ENC
        IF( st_fx->element_mode == EVS_MONO )
        {
            hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */
        }
        ELSE
        {
            hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR ); /* Q15 */
        }
#else
        hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */
#endif
@@ -747,6 +787,21 @@ void encod_gen_voic_ivas_fx(
         * Update memory of the weighting filter
         *-----------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
        IF( st_fx->element_mode == EVS_MONO )
        {
            /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
            Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/
            Ltmp = L_shl( Ltmp, add( 5, shift ) );        /*Q15+shift*/
            Ltmp = L_negate( Ltmp );
            Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ );       /* Q_new-1+shift+14+1 */
            Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*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        */
        }
        ELSE
#endif
        {
            /*At this point
            xn has to be in Qnew
            yn has to be in Qnew
@@ -771,6 +826,8 @@ void encod_gen_voic_ivas_fx(
            Ltmp = L_shl( Ltmp, sub( 1, shift ) );  // Q14 + Qnew + 1
            hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1        */
            move16();
        }

        IF( gain_preQ_fx != 0 )
        {
            tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new );
@@ -787,10 +844,10 @@ void encod_gen_voic_ivas_fx(
                move16();

                /* code in Q9, gain_pit in Q14 */
                Ltmp = L_mult( gcode16, code_fx[i] );                      /*Qnew + 9 + 1 */
                Ltmp = L_shl( Ltmp, 5 );                                   /*Qnew + 9+ 1+5 */
                Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/
                Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1  */        /* saturation can occur here Q16*/
                Ltmp = L_mult( gcode16, code_fx[i] );                      /*Q10 / Qnew + 9 + 1 */
                Ltmp = L_shl( Ltmp, 5 );                                   /*Q15 / Qnew + 9+ 1+5 */
                Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/
                Ltmp = L_shl_sat( Ltmp, 1 );                               /*Q15 / Qnew + 14 + 1 +1  */
                exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) );
                move16();
            }
@@ -806,10 +863,10 @@ void encod_gen_voic_ivas_fx(
            {
                /* code in Q9, gain_pit in Q14 */
                /*gcode16 in Qnew*/
                Ltmp = L_mult( gcode16, code_fx[i] );                          /*Qnew + 9 + 1 */
                Ltmp = L_shl_sat( Ltmp, 5 );                                   /*Qnew + 9+ 1+5 */
                Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/
                Ltmp = L_shl_sat( Ltmp, 1 );                                   /*Qnew + 14 + 1 +1  */
                Ltmp = L_mult( gcode16, code_fx[i] );                          /*Q10 / Qnew + 9 + 1 */
                Ltmp = L_shl_sat( Ltmp, 5 );                                   /*Q15 / Qnew + 9+ 1+5 */
                Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/
                Ltmp = L_shl_sat( Ltmp, 1 );                                   /*Q15 / Qnew + 14 + 1 +1  */
                exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp );
            }
        }
@@ -828,7 +885,16 @@ void encod_gen_voic_ivas_fx(
         * Update A(z) filters
         *-----------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
        IF( st_fx->element_mode == EVS_MONO )
        {
            Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 );
        }
        ELSE
#endif
        {
            syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 );
        }

        p_Aw_fx += ( M + 1 );
        p_Aq_fx += ( M + 1 );
+14 −0
Original line number Diff line number Diff line
@@ -374,6 +374,14 @@ void enc_pit_exc_fx(
        }
        ELSE IF( use_fcb == 2 )
        {
#ifdef CLEANUP_ACELP_ENC
            /*-----------------------------------------------------------------*
             * Innovation encoding
             *-----------------------------------------------------------------*/

            inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq,
                            gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new );
#else
#ifdef FIX_1904_HARM_GSC_ENC
            IF( NE_16( st_fx->element_mode, EVS_MONO ) )
            {
@@ -400,6 +408,7 @@ void enc_pit_exc_fx(
                                gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift );
#endif
            }
#endif

            /*-----------------------------------------------------------------*
             * Gain encoding
@@ -413,6 +422,10 @@ void enc_pit_exc_fx(
             * Innovation & gain encoding
             *-----------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
            inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq,
                            gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new );
#else
#ifdef FIX_1904_HARM_GSC_ENC
            IF( NE_16( st_fx->element_mode, EVS_MONO ) )
            {
@@ -435,6 +448,7 @@ void enc_pit_exc_fx(
                                gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift );
#endif
            }
#endif

            /*-----------------------------------------------------------------*
             * Gain encoding
+4 −1
Original line number Diff line number Diff line
@@ -370,7 +370,7 @@ Word16 inov_encode_ivas_fx(
    Word16 *unbits,            /* o  : number of unused bits for  PI                   */
    const Word16 L_subfr,      /* i  : subframe length                                 */
    const Word16 shift,
    const Word16 Q_new )
    Word16 Q_new )
{
    Word16 dn[2 * L_SUBFR], Qdn, Qcn, Qh2;
    Word16 nBits, cmpl_flag;
@@ -422,6 +422,9 @@ Word16 inov_encode_ivas_fx(
#ifdef CLEANUP_ACELP_ENC
    ELSE
    {
        Q_new = 0;
        move16();

        Qxn = 0;
        move16();
        Qcn = 0;
+7 −2
Original line number Diff line number Diff line
@@ -2071,6 +2071,7 @@ ivas_error encod_ppp_ivas_fx(
    Word16 Q_new,
    Word16 shift );

#ifndef CLEANUP_ACELP_ENC
void encod_gen_voic_fx(
    Encoder_State *st_fx,              /* i/o: state structure                                  */
    const Word16 speech_fx[],          /* i  : i   speech                                       Q0*/
@@ -2089,8 +2090,12 @@ void encod_gen_voic_fx(
    const Word16 tdm_Pri_pitch_buf[],  /* i  : primary channel pitch buffer            Q6*/
    Word16 shift,
    Word16 Q_new );

#endif
#ifdef CLEANUP_ACELP_ENC
void encod_gen_voic_fx(
#else
void encod_gen_voic_ivas_fx(
#endif
    Encoder_State *st_fx,              /* i/o: state structure                                  */
    const Word16 speech_fx[],          /* i  : input speech                                     Q0*/
    const Word16 Aw_fx[],              /* i  : weighted A(z) unquantized for subframes          Q12*/
@@ -3564,7 +3569,7 @@ Word16 inov_encode_fx(
    Word16 *unbits,            /* o  : number of unused bits for  PI                   */
    const Word16 L_subfr,      /* i  : subframe length                                 */
    const Word16 shift,
    const Word16 Q_new );
    Word16 Q_new );

void gain_enc_mless_fx(
    BSTR_ENC_HANDLE hBstr,     /* i/o: encoder bitstream handle                                         */