Commit a0501b1d authored by vaclav's avatar vaclav
Browse files

harmonize encod_unvoiced_fx(), under CLEANUP_ACELP_ENC

parent 63c48a83
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -95,12 +95,17 @@ ivas_error acelp_core_enc_fx(
    ivas_error error;

    error = IVAS_ERR_OK;

#ifdef CLEANUP_ACELP_ENC
    (void) hStereoTD;
#else
    test();
    IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->core_brate, SID_2k40 ) )
    {
        /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */
        return error;
    }
#endif
    /*------------------------------------------------------------------*
     * Initialization
     *------------------------------------------------------------------*/
@@ -196,6 +201,7 @@ ivas_error acelp_core_enc_fx(
        move16();
    }

#ifndef CLEANUP_ACELP_ENC
    /* TD stereo */
    test();
    IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) )
@@ -206,21 +212,25 @@ ivas_error acelp_core_enc_fx(
        tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf_fx;
    }
    ELSE
#endif
    {
        tdm_lp_reuse_flag = 0;
        tdm_low_rate_mode = 0;
        move16();
        move16();
#ifndef CLEANUP_ACELP_ENC
        if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode )
        {
            tdm_low_rate_mode = 1;
            move16();
        }
#endif
        tdm_Pitch_reuse_flag = 0;
        tdm_Pri_pitch_buf = NULL;
        move16();
        move16();
    }

    /*-----------------------------------------------------------------*
     * ACELP@12k8 / ACELP@16k switching
     *-----------------------------------------------------------------*/
@@ -551,21 +561,26 @@ ivas_error acelp_core_enc_fx(
        E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] );
        Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); // Q_syn

#ifndef CLEANUP_ACELP_ENC
        test();
        IF( st_fx->element_mode > EVS_MONO && st_fx->hTcxEnc != NULL )
        {
            Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 ); // Q_syn
        }

#endif
        /*--------------------------------------------------------------------------------------*
         * Modify the excitation signal when the noise is stationary
         *--------------------------------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
        IF( NE_16( nelp_mode, 1 ) )
#else
        test();
        test();
        test();
        test();
        IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
#endif
        {
            L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] );
            move32();
@@ -1335,7 +1350,11 @@ ivas_error acelp_core_enc_ivas_fx(
        ELSE IF( EQ_16( st->coder_type, UNVOICED ) )
        {
            /* UNVOICED frames (Gauss. excitation) */
#ifdef CLEANUP_ACELP_ENC
            encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
#else
            encod_unvoiced_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
#endif
        }
        ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
        {
+55 −14
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
 *
 * Encode unvoiced (UC) frames
 *-------------------------------------------------------------------*/

#ifndef CLEANUP_ACELP_ENC
void encod_unvoiced_fx(
    Encoder_State *st_fx,           /* i/o: state structure                         */
    const Word16 *speech_fx,        /* i  : Input speech                            Q_new*/
@@ -247,9 +247,13 @@ void encod_unvoiced_fx(

    return;
}
#endif


#ifdef CLEANUP_ACELP_ENC
void encod_unvoiced_fx(
#else
void encod_unvoiced_ivas_fx(
#endif
    Encoder_State *st_fx,           /* i/o: state structure                         */
    const Word16 *speech_fx,        /* i  : Input speech                            Q_new*/
    const Word16 Aw_fx[],           /* i  : weighted A(z) unquantized for subframes Q12*/
@@ -257,7 +261,7 @@ void encod_unvoiced_ivas_fx(
    const Word16 Es_pred,           /* i  : predicted scaled innov. energy          Q8*/
    const Word16 uc_two_stage_flag, /* i  : flag indicating two-stage UC            Q0*/
    const Word16 *res_fx,           /* i  : residual signal                         Q_new*/
    Word16 *syn_fx,                 /* o  : core synthesis                          Q_new*/
    Word16 *syn_fx,                 /* o  : core synthesis                          Q_new-1 (EVS) / Qnew*/
    Word16 *tmp_noise_fx,           /* o  : long-term noise energy                  Q0*/
    Word16 *exc_fx,                 /* i/o: current non-enhanced excitation         Q_new*/
    Word16 *pitch_buf_fx,           /* o  : floating pitch values for each subframe Q6*/
@@ -280,7 +284,7 @@ void encod_unvoiced_ivas_fx(
    Word16 y1[L_SUBFR];      /* Filtered adaptive excitation                   */
    Word16 code2[L_SUBFR];   /* Gaussian excitation                            */
    Word16 y22[L_SUBFR];     /* Filtered Gaussian excitation                   */
    // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
    Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
    const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */
    Word32 norm_gain_code_fx;
    ACELP_config *acelp_cfg;
@@ -329,12 +333,25 @@ void encod_unvoiced_ivas_fx(
        i_subfr_idx = shr( i_subfr, 6 );
        Copy( &res_fx[i_subfr], &exc_fx[i_subfr], 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, &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);*/
            Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
        }
        ELSE
#endif
        {
            find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
                                  res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );

            q_h1 = sub( 14, norm_s( h1_fx[0] ) );
            Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) );
            Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) );
        }

        /* scaling of xn[] to limit dynamic at 12 bits */
        Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift
@@ -366,16 +383,31 @@ void encod_unvoiced_ivas_fx(
             *-----------------------------------------------------------------*/

            Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn );

            *pt_pitch_fx = L_SUBFR << 6;
            move16();
#ifdef CLEANUP_ACELP_ENC
            if ( st_fx->element_mode == EVS_MONO )
            {
                *pt_pitch_fx = L_SUBFR;
                move16();
            }
#endif

            /*----------------------------------------------------------------------*
             *                 Encode the algebraic innovation                      *
             *----------------------------------------------------------------------*/

#ifdef CLEANUP_ACELP_ENC
            IF( st_fx->element_mode == EVS_MONO )
            {
                E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate );
            }
            ELSE
            {
                inov_encode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx,
                                gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new );
            }
#else
            inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame,
                                 UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx,
@@ -394,7 +426,16 @@ void encod_unvoiced_ivas_fx(
            move16();

            assert( gain_pit_fx == 0 );
#ifdef CLEANUP_ACELP_ENC
            IF( st_fx->element_mode == EVS_MONO )
            {
                gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
            }
            ELSE
#endif
            {
                gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
            }

            /*----------------------------------------------------------*
             *  - Compute the fixed codebook gain                       *
+2 −2
Original line number Diff line number Diff line
@@ -2010,7 +2010,7 @@ void encod_unvoiced_fx(
    Word16 *bwe_exc_fx,             /* i/o: excitation for SWB TBE                    Q_exc*/
    const Word16 Q_new,
    const Word16 shift );

#ifndef CLEANUP_ACELP_ENC
void encod_unvoiced_ivas_fx(
    Encoder_State *st_fx,           /* i/o: state structure                         */
    const Word16 *speech_fx,        /* i  : Input speech                            Q_new*/
@@ -2027,7 +2027,7 @@ void encod_unvoiced_ivas_fx(
    Word16 *bwe_exc_fx,             /* i/o: excitation for SWB TBE                    Q_exc*/
    const Word16 Q_new,
    const Word16 shift );

#endif
void enc_acelp_tcx_main_fx(
    const Word16 new_samples[],         /* i  : new samples                          Q15*/
    Encoder_State *st,                  /* i/o: encoder state structure              */