Commit 5b82c88b authored by Nishant S Kulgod's avatar Nishant S Kulgod
Browse files

commit 6

parent 5aabc156
Loading
Loading
Loading
Loading
Loading
+382 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
#include "options.h" /* Compilation switches                   */
#include "cnst.h"    /* Common constants                       */
#include "rom_com.h" /* Common constants                       */
//#include "prot_fx.h"        /* Function prototypes                    */
#include "prot.h"        /* Function prototypes                    */
#include "prot_fx.h"     /* Function prototypes                    */
#include "prot_fx_enc.h" /* Function prototypes                    */

@@ -341,6 +341,318 @@ void acelp_2t32_fx(
    return;
}

void acelp_2t32_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                      */
    const Word16 dn[],     /* i  : corr. between target and h[].                 */
    const Word16 h[],      /* i  : impulse response of weighted synthesis filter */
    Word16 code[],         /* o  : algebraic (fixed) codebook excitation         */
    Word16 y[]             /* o  : filtered fixed codebook excitation            */
)
{
    Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1, index;
    Word16 ps1, ps2, alpk, alp1, alp2;
    Word16 sq, psk;
    Word16 pol[L_SUBFR], dn_p[L_SUBFR];
    Word16 ii, jj;
    Word16 *p0, *p1, *p2;
    const Word16 *ptr_h1, *ptr_h2, *ptr_hf;

    Word32 s, L_cor;
    Word32 L_tmp;
    Word16 rrixix[NB_TRACK_FCB_2T][NB_POS_FCB_2T];
    Word16 rrixiy[MSIZE];
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
#endif
    /*----------------------------------------------------------------*
     * Compute rrixix[][] needed for the codebook search.
     *----------------------------------------------------------------*/

    /* Init pointers to last position of rrixix[] */
    p0 = &rrixix[0][NB_POS_FCB_2T - 1];
    move16();
    p1 = &rrixix[1][NB_POS_FCB_2T - 1];
    move16();

    ptr_h1 = h;
    move16();
    L_cor = L_deposit_h( 1 );
    FOR( i = 0; i < NB_POS_FCB_2T; i++ )
    {
#ifdef BASOP_NOGLOB
        L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow );
#else
        L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 );
#endif
        ptr_h1++;
        *p1-- = extract_h( L_cor );
        move16(); /*Q9 Q7*/
#ifdef BASOP_NOGLOB
        L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow );
#else
        L_cor = L_mac( L_cor, *ptr_h1, *ptr_h1 );
#endif
        ptr_h1++;
        *p0-- = extract_h( L_cor );
        move16(); /*Q9 Q7*/
    }

    p0 = rrixix[0];
    move16();
    p1 = rrixix[1];
    move16();

    FOR( i = 0; i < NB_POS_FCB_2T; i++ )
    {
        *p0 = shr( *p0, 1 );
        move16();
        p0++;
        *p1 = shr( *p1, 1 );
        move16();
        p1++;
    }

    /*------------------------------------------------------------*
     * Compute rrixiy[][] needed for the codebook search.
     *------------------------------------------------------------*/

    pos = MSIZE - 1;
    move16();
    pos2 = MSIZE - 2;
    move16();
    ptr_hf = h + 1;
    move16();

    FOR( k = 0; k < NB_POS_FCB_2T; k++ )
    {
        /* Init pointers to last position of diagonals */
        p1 = &rrixiy[pos];
        move16();
        p0 = &rrixiy[pos2];
        move16();

        ptr_h1 = h;
        move16();
        ptr_h2 = ptr_hf;
        move16();

        L_cor = L_mult( *ptr_h1++, *ptr_h2++ );
        FOR( i = k; i < NB_POS_FCB_2T - 1; i++ )
        {
#ifdef BASOP_NOGLOB
            *p1 = round_fx_o( L_cor, &Overflow );
            L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow );
#else
            *p1 = round_fx( L_cor );
            L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ );
#endif
#ifdef BASOP_NOGLOB
            *p0 = round_fx_o( L_cor, &Overflow );
            L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow );
#else
            *p0 = round_fx( L_cor );
            L_cor = L_mac( L_cor, *ptr_h1++, *ptr_h2++ );
#endif
            p1 -= ( NB_POS_FCB_2T + 1 );
            move16();
            p0 -= ( NB_POS_FCB_2T + 1 );
            move16();
        }

#ifdef BASOP_NOGLOB
        *p1 = round_fx_o( L_cor, &Overflow );
#else
        *p1 = round_fx( L_cor );
#endif
        pos -= NB_POS_FCB_2T;
        move16();
        pos2--;
        ptr_hf += STEP;
        move16();
    }

    /*----------------------------------------------------------------*
     * computing reference vector and pre-selection of polarities
     *----------------------------------------------------------------*/

    L_tmp = L_deposit_h( dn[0] );
    FOR( i = 0; i < L_SUBFR; i++ )
    {
        /* FIR high-pass filtering */
        IF( i == 0 )
        {
            L_tmp = L_msu( L_tmp, dn[1], 11469 );
        }
        ELSE IF( EQ_16( i, L_SUBFR - 1 ) )
        {
            L_tmp = L_deposit_h( dn[i] );
            L_tmp = L_msu( L_tmp, dn[i - 1], 11469 );
        }
        ELSE
        {
            L_tmp = L_deposit_h( dn[i] );
            L_tmp = L_msu( L_tmp, dn[i - 1], 11469 );
            L_tmp = L_msu( L_tmp, dn[i + 1], 11469 );
        }

        /* pre-selection of polarities */
        IF( L_tmp >= 0 )
        {
            pol[i] = 1;
            move16();
            dn_p[i] = dn[i];
            move16();
        }
        ELSE
        {
            pol[i] = -1;
            move16();
            dn_p[i] = negate( dn[i] );
            move16();
        }
    }

    /*----------------------------------------------------------------*
     * compute denominator ( multiplied by polarity )
     *----------------------------------------------------------------*/

    k = 0;
    ii = 0;
    move16();
    move16();
    FOR( i = 0; i < NB_POS_FCB_2T; i++ )
    {
        jj = 1;
        move16();
        FOR( j = 0; j < NB_POS_FCB_2T; j++ )
        {
            test();
            if ( EQ_16( s_and( pol[ii], pol[jj] ), 1 ) && EQ_16( s_or( pol[ii], pol[jj] ), -1 ) )
            {
                rrixiy[k + j] = negate( rrixiy[k + j] );
                move16();
            }
            jj = add( jj, 2 );
        }
        ii = add( ii, 2 );
        k = add( k, NB_POS_FCB_2T );
    }

    /*----------------------------------------------------------------*
     * search 2 pulses
     * All combinaisons are tested:
     * 32 pos x 32 pos x 2 signs = 2048 tests
     *----------------------------------------------------------------*/

    p0 = rrixix[0];
    move16();
    p1 = rrixix[1];
    move16();
    p2 = rrixiy;
    move16();
    psk = -1;
    move16();
    alpk = 1;
    move16();
    ix = 0;
    move16();
    iy = 1;
    move16();

    FOR( i0 = 0; i0 < L_SUBFR; i0 += STEP )
    {
        ps1 = dn_p[i0];
        move16();
        alp1 = *p0++;
        move16();
        pos = -1;
        move16();
        FOR( i1 = 1; i1 < L_SUBFR; i1 += STEP )
        {
            ps2 = add( ps1, dn_p[i1] );
#ifdef BASOP_NOGLOB
            alp2 = add_o( alp1, add_o( *p1++, *p2++, &Overflow ), &Overflow );
#else
            alp2 = add( alp1, add( *p1++, *p2++ ) );
#endif
            sq = mult( ps2, ps2 );
#ifdef BASOP_NOGLOB
            s = L_msu_o( L_mult( alpk, sq ), psk, alp2, &Overflow );
#else
            s = L_msu( L_mult( alpk, sq ), psk, alp2 );
#endif
            IF( s > 0 )
            {
                psk = sq;
                move16();
                alpk = alp2;
                move16();
                pos = i1;
                move16();
            }
        }
        p1 -= NB_POS_FCB_2T;
        move16();

        IF( pos >= 0 )
        {
            ix = i0;
            move16();
            iy = pos;
            move16();
        }
    }

    i0 = shr( ix, 1 );
    i1 = shr( iy, 1 );

    sign0 = shl( pol[ix], 9 );
    sign1 = shl( pol[iy], 9 );

    /*-------------------------------------------------------------------*
     * Build the codeword, the filtered codeword and index of codevector.
     *-------------------------------------------------------------------*/

    set16_fx( code, 0, L_SUBFR );

    code[ix] = sign0;
    move16();
    code[iy] = sign1;
    move16();

    index = add( shl( i0, 6 ), i1 );


    if ( sign0 < 0 )
    {
        index = add( index, 0x800 );
    }
    if ( sign1 < 0 )
    {
        index = add( index, 0x20 ); /* move16();*/
    }

    set16_fx( y, 0, L_SUBFR );
    /* y_Q9 = sign_Q9<<3 * h_Q12 */

    sign0 = shl( sign0, 3 );
    sign1 = shl( sign1, 3 );

    FOR( i = ix; i < L_SUBFR; i++ )
    {
        y[i] = mult_r( sign0, h[i - ix] );
        move16();
    }
    FOR( i = iy; i < L_SUBFR; i++ )
    {
        y[i] = round_fx( L_mac( L_deposit_h( y[i] ), sign1, h[i - iy] ) );
    }
    {
        /* write index to array of indices */
        push_indice( hBstr, IND_ALG_CDBK_2T32, index, 12 );
    }
    return;
}
/*----------------------------------------------------------------------------------
 * Function  acelp_1t64()
 *
@@ -418,3 +730,72 @@ void acelp_1t64_fx(

    return;
}

void acelp_1t64_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                      */
    const Word16 dn[],     /* i  : corr. between target and h[].                 */
    const Word16 h[],      /* i  : impulse response of weighted synthesis filter */
    Word16 code[],         /* o  : algebraic (fixed) codebook excitation         */
    Word16 y[],            /* o  : filtered fixed codebook excitation            */
    const Word16 L_subfr   /* i  : subframe length                               */
)
{
    Word16 i, pos, sgn, index;
    Word32 L_tmp;
    /*-------------------------------------------------------------------*
     * Find position and sign of maximum impulse.
     *-------------------------------------------------------------------*/
    pos = emaximum_fx( 0, dn, L_subfr, &L_tmp );

    IF( dn[pos] < 0 )
    {
        sgn = -512;
        move16();
    }
    ELSE
    {
        sgn = 512;
        move16();
    }

    /*-------------------------------------------------------------------*
     * Build the codeword, the filtered codeword and index of codevector.
     *-------------------------------------------------------------------*/

    set16_fx( code, 0, L_subfr );
    code[pos] = sgn;
    move16();

    set16_fx( y, 0, L_subfr );

    FOR( i = pos; i < L_subfr; i++ )
    {
        IF( sgn > 0 )
        {
            y[i] = shr_r( h[i - pos], 3 );
            move16();
        }
        ELSE
        {
            y[i] = negate( shr_r( h[i - pos], 3 ) );
            move16();
        }
    }

    index = pos;
    move16();
    if ( sgn > 0 )
    {
        index = add( index, L_subfr );
    }
    IF( EQ_16( L_subfr, L_SUBFR ) )
    {
        push_indice( hBstr, IND_ALG_CDBK_1T64, index, 7 );
    }
    ELSE /* L_subfr == 2*L_SUBFR */
    {
        push_indice( hBstr, IND_ALG_CDBK_1T64, index, 8 );
    }

    return;
}
+28 −0
Original line number Diff line number Diff line
@@ -109,3 +109,31 @@ void corr_xh_ivas_fx(
    return;

}

void corr_hh_ivas_fx(
    const Word16 *h,     /* i  : target signal                                  e(norm_s(h1[0])+1) */
    Word16 *y,           /* o  : correlation between x[] and h[]                Q_new + 1 */
    const Word16 L_subfr /* i  : length of the subframe                          */
)
{
    Word16 i, j, scale;
    Word64 s64;

    Word16 shift = add(norm_s(h[0]), 1);
    scale = sub(sub(15, shift), -2 );
    FOR(i = 0; i < L_subfr; i++)
    {
        s64 = 0;
        move16();
        FOR(j = i; j < L_subfr; j++)
        {
            s64 = W_mac0_16_16(s64, h[j], h[j - i]); // Q_new - 1 + 15 - shift
        }

        y[i] = extract_l(W_extract_l(W_shr(s64, scale))); // Q_new + 1
        move16();
    }

    return;

}
+7 −7
Original line number Diff line number Diff line
@@ -792,13 +792,6 @@ void E_ACELP_4tsearchx_ivas_fx(
            alp = round_fx( s ); /*mac0 >>1 sign = 2*/
        }

        WHILE (GT_16(alp , ONE_IN_Q11)) {
            alp = shr(alp, 1);
            Scale_sig(cor, L_SUBFR, -1);
            Scale_sig(R_buf, 2 * L_SUBFR - 1, -1);
            Scale_sig(dn, 2*L_SUBFR, -1);
        }

        /* other stages of 2 pulses */
        st = 0;
        move16();
@@ -821,6 +814,13 @@ void E_ACELP_4tsearchx_ivas_fx(
                                        &ind[j], dn, cor, sign, sign_val_1 );
            }

            IF(GT_16(alp, ONE_IN_Q14)) {
                alp = shr(alp, 1);
                Scale_sig(cor, L_SUBFR, -1);
                Scale_sig(R_buf, 2 * L_SUBFR - 1, -1);
                Scale_sig(dn, 2 * L_SUBFR, -1);
            }


            st = add( st, 1 );
        }
+3 −2
Original line number Diff line number Diff line
@@ -769,9 +769,10 @@ void encod_gen_voic_ivas_fx(
             * Prepare TBE excitation
             *-----------------------------------------------------------------*/

            prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
            prep_tbe_exc_ivas_fx(L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
                &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new,
                T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);
                T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
                st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag);

        /*-----------------------------------------------------------------*
         * Synthesize speech to update mem_syn[].
+3 −2
Original line number Diff line number Diff line
@@ -742,8 +742,9 @@ Word16 encod_tran_ivas_fx(
         * Prepare TBE excitation
         *-----------------------------------------------------------------*/

        prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
                         bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate );
        prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR],
                         bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate,
                         st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag);

        /*-----------------------------------------------------------------*
         * Synthesize speech to update mem_syn[].
Loading