Exemplo n.º 1
0
void pre_big(
    enum Mode mode,            /* i  : coder mode                             */
    const Word16 gamma1[],     /* i  : spectral exp. factor 1                 */
    const Word16 gamma1_12k2[],/* i  : spectral exp. factor 1 for EFR         */
    const Word16 gamma2[],     /* i  : spectral exp. factor 2                 */
    Word16 A_t[],              /* i  : A(z) unquantized, for 4 subframes, Q12 */
    Word16 frameOffset,        /* i  : Start position in speech vector,   Q0  */
    Word16 speech[],           /* i  : speech,                            Q0  */
    Word16 mem_w[],            /* i/o: synthesis filter memory state,     Q0  */
    Word16 wsp[],              /* o  : weighted speech                    Q0  */
    Flag   *pOverflow          /* o  : overflow indicator                     */
)
{
    Word16 Ap1[MP1];            /* A(z) with spectral expansion         */
    Word16 Ap2[MP1];            /* A(z) with spectral expansion         */
    const Word16 *g1;           /* Pointer to correct gammma1 vector    */
    Word16 aOffset;
    Word16 i;

    if (mode <= MR795)
    {
        g1 = gamma1;
    }
    else
    {
        g1 = gamma1_12k2;
    }

    if (frameOffset > 0)
    {
        aOffset = 2 * MP1;
    }
    else
    {
        aOffset = 0;
    }

    /* process two subframes (which form the "big" subframe) */
    for (i = 0; i < 2; i++)
    {
        Weight_Ai(&A_t[aOffset], g1, Ap1);
        Weight_Ai(&A_t[aOffset], gamma2, Ap2);
        Residu(Ap1, &speech[frameOffset], &wsp[frameOffset], L_SUBFR);

        Syn_filt(Ap2, &wsp[frameOffset], &wsp[frameOffset], L_SUBFR, mem_w, 1);

        aOffset = add(aOffset, MP1, pOverflow);

        frameOffset = add(frameOffset, L_SUBFR, pOverflow);
    }

    return;
}
Exemplo n.º 2
0
/*
**************************************************************************
*  Function:  Post_Filter
*  Purpose:   postfiltering of synthesis speech.
*  Description:
*      The postfiltering process is described as follows:
*
*          - inverse filtering of syn[] through A(z/0.7) to get res2[]
*          - tilt compensation filtering; 1 - MU*k*z^-1
*          - synthesis filtering through 1/A(z/0.75)
*          - adaptive gain control
*
**************************************************************************
*/
int Post_Filter (
    Post_FilterState *st, /* i/o : post filter states                        */
    enum Mode mode,       /* i   : AMR mode                                  */
    Word16 *syn,          /* i/o : synthesis speech (postfiltered is output) */
    Word16 *Az_4          /* i   : interpolated LPC parameters in all subfr. */
)
{
    /*-------------------------------------------------------------------*
     *           Declaration of parameters                               *
     *-------------------------------------------------------------------*/

    Word16 Ap3[MP1], Ap4[MP1];  /* bandwidth expanded LP parameters */
    Word16 *Az;                 /* pointer to Az_4:                 */
    /*  LPC parameters in each subframe */
    Word16 i_subfr;             /* index for beginning of subframe  */
    Word16 h[L_H];

    Word16 i;
    Word16 temp1, temp2;
    Word32 L_tmp;
    Word16 *syn_work = &st->synth_buf[M];
    move16 ();


    /*-----------------------------------------------------*
     * Post filtering                                      *
     *-----------------------------------------------------*/

    Copy (syn, syn_work , L_FRAME);

    Az = Az_4;

    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
    {
        /* Find weighted filter coefficients Ap3[] and ap[4] */

        test ();
        test ();
        if (sub(mode, MR122) == 0 || sub(mode, MR102) == 0)
        {
            Weight_Ai (Az, gamma3_MR122, Ap3);
            Weight_Ai (Az, gamma4_MR122, Ap4);
        }
        else
        {
            Weight_Ai (Az, gamma3, Ap3);
            Weight_Ai (Az, gamma4, Ap4);
        }

        /* filtering of synthesis speech by A(z/0.7) to find res2[] */

        Residu (Ap3, &syn_work[i_subfr], st->res2, L_SUBFR);

        /* tilt compensation filter */

        /* impulse response of A(z/0.7)/A(z/0.75) */

        Copy (Ap3, h, M + 1);
        Set_zero (&h[M + 1], L_H - M - 1);
        Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0);

        /* 1st correlation of h[] */

        L_tmp = L_mult (h[0], h[0]);
        for (i = 1; i < L_H; i++)
        {
            L_tmp = L_mac (L_tmp, h[i], h[i]);
        }
        temp1 = extract_h (L_tmp);

        L_tmp = L_mult (h[0], h[1]);
        for (i = 1; i < L_H - 1; i++)
        {
            L_tmp = L_mac (L_tmp, h[i], h[i + 1]);
        }
        temp2 = extract_h (L_tmp);

        test ();
        if (temp2 <= 0)
        {
            temp2 = 0;
            move16 ();
        }
        else
        {
            temp2 = mult (temp2, MU);
            temp2 = div_s (temp2, temp1);
        }

        preemphasis (st->preemph_state, st->res2, temp2, L_SUBFR);

        /* filtering through  1/A(z/0.75) */

        Syn_filt (Ap4, st->res2, &syn[i_subfr], L_SUBFR, st->mem_syn_pst, 1);

        /* scale output to input */

        agc (st->agc_state, &syn_work[i_subfr], &syn[i_subfr],
             AGC_FAC, L_SUBFR);

        Az += MP1;
    }

    /* update syn_work[] buffer */

    Copy (&syn_work[L_FRAME - M], &syn_work[-M], M);

    return 0;
}
Exemplo n.º 3
0
/*
********************************************************************************
*                         PUBLIC PROGRAM CODE
********************************************************************************
*/
int subframePreProc(
    enum Mode mode,            /* i  : coder mode                            */
    const Word16 gamma1[],     /* i  : spectral exp. factor 1                */
    const Word16 gamma1_12k2[],/* i  : spectral exp. factor 1 for EFR        */
    const Word16 gamma2[],     /* i  : spectral exp. factor 2                */
    Word16 *A,                 /* i  : A(z) unquantized for the 4 subframes  */
    Word16 *Aq,                /* i  : A(z)   quantized for the 4 subframes  */
    Word16 *speech,            /* i  : speech segment                        */
    Word16 *mem_err,           /* i  : pointer to error signal               */
    Word16 *mem_w0,            /* i  : memory of weighting filter            */
    Word16 *zero,              /* i  : pointer to zero vector                */
    Word16 ai_zero[],          /* o  : history of weighted synth. filter     */
    Word16 exc[],              /* o  : long term prediction residual         */
    Word16 h1[],               /* o  : impulse response                      */
    Word16 xn[],               /* o  : target vector for pitch search        */
    Word16 res2[],             /* o  : long term prediction residual         */
    Word16 error[]             /* o  : error of LPC synthesis filter         */
)
{
   Word16 i;
   Word16 Ap1[MP1];              /* A(z) with spectral expansion         */
   Word16 Ap2[MP1];              /* A(z) with spectral expansion         */
   const Word16 *g1;             /* Pointer to correct gammma1 vector    */

   /*---------------------------------------------------------------*
    * mode specific pointer to gamma1 values                        *
    *---------------------------------------------------------------*/
	test (); test ();
	if ( sub(mode, MR122) == 0 || sub(mode, MR102) == 0 )
        {
           g1 = gamma1_12k2; move16 (); 
	}
        else
        {
           g1 = gamma1;      move16 (); 
	}
   /*---------------------------------------------------------------*
    * Find the weighted LPC coefficients for the weighting filter.  *
    *---------------------------------------------------------------*/
   Weight_Ai(A, g1, Ap1);
   Weight_Ai(A, gamma2, Ap2);
   
   /*---------------------------------------------------------------*
    * Compute impulse response, h1[], of weighted synthesis filter  *
    *---------------------------------------------------------------*/
   for (i = 0; i <= M; i++)
   {
      ai_zero[i] = Ap1[i];        move16 ();
   }

   Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0);
   Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0);
   
   /*------------------------------------------------------------------------*
    *                                                                        *
    *          Find the target vector for pitch search:                      *
    *                                                                        *
    *------------------------------------------------------------------------*/
   
   /* LPC residual */
   Residu(Aq, speech, res2, L_SUBFR); 
   Copy(res2, exc, L_SUBFR);

   Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0);
   
   Residu(Ap1, error, xn, L_SUBFR);
   
   /* target signal xn[]*/
   Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0);    

   return 0;
}
Exemplo n.º 4
0
void Post_Filter (
    INT16 *syn,    /* in/out: synthesis speech (postfiltered is output)    */
    INT16 *Az_4    /* input: interpolated LPC parameters in all subframes  */
)
{
    /*-------------------------------------------------------------------*
     *           Declaration of parameters                               *
     *-------------------------------------------------------------------*/

    INT16 syn_pst[L_FRAME];    /* post filtered synthesis speech   */
    INT16 Ap3[MP1], Ap4[MP1];  /* bandwidth expanded LP parameters */
    INT16 *Az;                 /* pointer to Az_4:                 */
                                /*  LPC parameters in each subframe */
    INT16 i_subfr;             /* index for beginning of subframe  */
    INT16 h[L_H];

    INT16 i;
    INT16 temp1, temp2;
    //INT32 L_tmp;
    register INT32 tmp_hi=0;
    register UINT32 tmp_lo=0;

    VPP_EFR_PROFILE_FUNCTION_ENTER(Post_Filter);


    /*-----------------------------------------------------*
     * Post filtering                                      *
     *-----------------------------------------------------*/

    Az = Az_4;

    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
    {
        /* Find weighted filter coefficients Ap3[] and ap[4] */

        Weight_Ai (Az, F_gamma3, Ap3);
        Weight_Ai (Az, F_gamma4, Ap4);

        /* filtering of synthesis speech by A(z/0.7) to find res2[] */

        Residu (Ap3, &syn[i_subfr], res2, L_SUBFR);

        /* tilt compensation filter */

        /* impulse response of A(z/0.7)/A(z/0.75) */

        Copy (Ap3, h, M + 1);

        //Set_zero (&h[M + 1], L_H - M - 1);
        memset ((INT8*)&h[M + 1], 0, (L_H - M - 1)<<1);

        Syn_filt (Ap4, h, h, L_H, &h[M + 1], 0);

        /* 1st correlation of h[] */


		//L_tmp = L_MULT(h[0], h[0]);
        VPP_MLX16(tmp_hi,tmp_lo, h[0], h[0]);

        for (i = 1; i < L_H; i++)
        {

			//L_tmp = L_MAC(L_tmp, h[i], h[i]);
			VPP_MLA16(tmp_hi,tmp_lo, h[i], h[i]);

        }
        //temp1 = extract_h (L_tmp);
        //temp1 = EXTRACT_H(VPP_SCALE64_TO_16(tmp_hi,tmp_lo));
        temp1 = L_SHR_D((INT32)tmp_lo, 15);


		//L_tmp = L_MULT(h[0], h[1]);
        VPP_MLX16(tmp_hi,tmp_lo, h[0], h[1]);
        for (i = 1; i < L_H - 1; i++)
        {

			//L_tmp = L_MAC(L_tmp, h[i], h[i + 1]);
			VPP_MLA16(tmp_hi,tmp_lo, h[i], h[i + 1]);
        }
        //temp2 = extract_h (L_tmp);
		//temp2 = EXTRACT_H(VPP_SCALE64_TO_16(tmp_hi,tmp_lo));
        temp2 = L_SHR_D((INT32)tmp_lo, 15);


        if (temp2 <= 0)
        {
            temp2 = 0;
        }
        else
        {
            //temp2 = mult (temp2, MU);
			temp2 = MULT(temp2, MU);
            temp2 = div_s (temp2, temp1);
        }

        preemphasis (res2, temp2, L_SUBFR);

        /* filtering through  1/A(z/0.75) */

        Syn_filt (Ap4, res2, &syn_pst[i_subfr], L_SUBFR, mem_syn_pst, 1);

        /* scale output to input */

        agc (&syn[i_subfr], &syn_pst[i_subfr], AGC_FAC, L_SUBFR);

        Az += MP1;
    }

    /* update syn[] buffer */

    Copy (&syn[L_FRAME - M], &syn[-M], M);
    /* overwrite synthesis speech by postfiltered synthesis speech */

    Copy (syn_pst, syn, L_FRAME);

    VPP_EFR_PROFILE_FUNCTION_EXIT(Post_Filter);
    return;
}