Пример #1
0
/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/
void code_10i40_35bits(
    Word16 x[],     /* (i)   : target vector                                */
    Word16 cn[],    /* (i)   : residual after long term prediction          */
    Word16 h[],     /* (i)   : impulse response of weighted synthesis filter
                             h[-L_subfr..-1] must be set to zero            */
    Word16 cod[],   /* (o)   : algebraic (fixed) codebook excitation        */
    Word16 y[],     /* (o)   : filtered fixed codebook excitation           */
    Word16 indx[],  /* (o)   : index of 10 pulses (sign + position)         */
    Flag *pOverflow /* (i/o) : overflow Flag                                */
)
{
    Word16 ipos[NB_PULSE], pos_max[NB_TRACK], codvec[NB_PULSE];
    Word16 dn[L_CODE], sign[L_CODE];
    Word16 rr[L_CODE][L_CODE], i;

    cor_h_x(h, x, dn, 2, pOverflow);
    set_sign12k2(dn, cn, sign, pos_max, NB_TRACK, ipos, STEP, pOverflow);
    cor_h(h, sign, rr, pOverflow);

    search_10and8i40(NB_PULSE, STEP, NB_TRACK,
                     dn, rr, ipos, pos_max, codvec, pOverflow);

    build_code(codvec, sign, cod, h, y, indx, pOverflow);
    for (i = 0; i < 10; i++)
    {
        q_p(&indx[i], i);
    }
    return;
}
Пример #2
0
/*
------------------------------------------------------------------------------
 FUNCTION NAME: code_2i40_11bits
------------------------------------------------------------------------------
 INPUT AND OUTPUT DEFINITIONS

 Inputs:
    x,  target vector, array of type Word16
    h,  impulse response of weighted synthesis filter, array of type Word16
    T0, Pitch lag, variable of type Word16
    pitch_sharp, Last quantized pitch gain, variable of type Word16

 Outputs:
    code[], Innovative codebook, array of type Word16
    y[],    filtered fixed codebook excitation, array of type Word16
    sign,   Signs of 2 pulses, pointer of type Word16 *
    pOverflow  Flag set when overflow occurs, pointer of type Flag *

 Returns:
    index

 Global Variables Used:
    None

 Local Variables Needed:
    None

------------------------------------------------------------------------------
 FUNCTION DESCRIPTION

     Searches a 11 bit algebraic codebook containing 2 pulses
     in a frame of 40 samples.

     The code length is 40, containing 2 nonzero pulses: i0...i1.
     All pulses can have two possible amplitudes: +1 or -1.
     Pulse i0 can have 2x8=16 possible positions, pulse i1 can have
     4x8=32 positions.

        i0 :  1, 6, 11, 16, 21, 26, 31, 36.
              3, 8, 13, 18, 23, 28, 33, 38.
        i1 :  0, 5, 10, 15, 20, 25, 30, 35.
              1, 6, 11, 16, 21, 26, 31, 36.
              2, 7, 12, 17, 22, 27, 32, 37.
              4, 9, 14, 19, 24, 29, 34, 39.

------------------------------------------------------------------------------
 REQUIREMENTS

 None

------------------------------------------------------------------------------
 REFERENCES

 c2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001

------------------------------------------------------------------------------
 PSEUDO-CODE


------------------------------------------------------------------------------
 CAUTION [optional]
 [State any special notes, constraints or cautions for users of this function]

------------------------------------------------------------------------------
*/
Word16 code_2i40_11bits(
    Word16 x[],         /* i : target vector                                 */
    Word16 h[],         /* i : impulse response of weighted synthesis filter */
    /*     h[-L_subfr..-1] must be set to zero.          */
    Word16 T0,          /* i : Pitch lag                                     */
    Word16 pitch_sharp, /* i : Last quantized pitch gain                     */
    Word16 code[],      /* o : Innovative codebook                           */
    Word16 y[],         /* o : filtered fixed codebook excitation            */
    Word16 * sign,      /* o : Signs of 2 pulses                             */
    Flag   * pOverflow  /* o : Flag set when overflow occurs                 */
)
{
    Word16 codvec[NB_PULSE];
    Word16 dn[L_CODE];
    Word16 dn2[L_CODE];
    Word16 dn_sign[L_CODE];

    Word16 rr[L_CODE][L_CODE];

    Word16 i;
    Word16 index;
    Word16 sharp;
    Word16 tempWord;

    sharp = pitch_sharp << 1;

    if (T0 < L_CODE)
    {
        for (i = T0; i < L_CODE; i++)
        {
            tempWord =
                mult(
                    h[i - T0],
                    sharp,
                    pOverflow);

            h[i] =
                add_16(
                    h[i],
                    tempWord,
                    pOverflow);
        }

    }

    cor_h_x(
        h,
        x,
        dn,
        1,
        pOverflow);

    set_sign(
        dn,
        dn_sign,
        dn2,
        8); /* dn2[] not used in this codebook search */

    cor_h(
        h,
        dn_sign,
        rr,
        pOverflow);

    search_2i40(
        dn,
        rr,
        codvec,
        pOverflow);

    /* function result */

    index =
        build_code(
            codvec,
            dn_sign,
            code,
            h,
            y,
            sign,
            pOverflow);

    /*
    * Compute innovation vector gain.
    * Include fixed-gain pitch contribution into code[].
    */

    if (T0 < L_CODE)
    {
        for (i = T0; i < L_CODE; i++)
        {
            tempWord =
                mult(
                    code[i - T0],
                    sharp,
                    pOverflow);

            code[i] =
                add_16(
                    code[i],
                    tempWord,
                    pOverflow);
        }
    }

    return index;
}
Пример #3
0
    Word16 code_2i40_9bits(
        Word16 subNr,       /* i : subframe number                          */
        Word16 x[],         /* i : target vector                            */
        Word16 h[],         /* i : impulse response of weighted synthesis   */
        /*     filter h[-L_subfr..-1] must be set to 0. */
        Word16 T0,          /* i : Pitch lag                                */
        Word16 pitch_sharp, /* i : Last quantized pitch gain                */
        Word16 code[],      /* o : Innovative codebook                      */
        Word16 y[],         /* o : filtered fixed codebook excitation       */
        Word16 * sign,      /* o : Signs of 2 pulses                        */
        Flag   * pOverflow  /* o : Flag set when overflow occurs            */
    )
    {
        Word16 codvec[NB_PULSE];
        Word16 dn[L_CODE];
        Word16 dn2[L_CODE];
        Word16 dn_sign[L_CODE];
        Word16 rr[L_CODE][L_CODE];

        register Word16 i;

        Word16 index;
        Word16 sharp;
        Word16 temp;
        Word32 L_temp;

        L_temp = ((Word32) pitch_sharp) << 1;

        /* Check for overflow condition */
        if (L_temp != (Word32)((Word16) L_temp))
        {
            *(pOverflow) = 1;
            sharp = (pitch_sharp > 0) ? MAX_16 : MIN_16;
        }
        else
        {
            sharp = (Word16) L_temp;
        }

        if (T0 < L_CODE)
        {
            for (i = T0; i < L_CODE; i++)
            {
                temp =
                    mult(
                        *(h + i - T0),
                        sharp,
                        pOverflow);

                *(h + i) =
                    add(
                        *(h + i),
                        temp,
                        pOverflow);
            }
        }

        cor_h_x(
            h,
            x,
            dn,
            1,
            pOverflow);

        /* dn2[] not used in this codebook search */

        set_sign(
            dn,
            dn_sign,
            dn2,
            8);

        cor_h(
            h,
            dn_sign,
            rr,
            pOverflow);

        search_2i40(
            subNr,
            dn,
            rr,
            codvec,
            pOverflow);

        index =
            build_code(
                subNr,
                codvec,
                dn_sign,
                code,
                h,
                y,
                sign,
                pOverflow);

        /*-----------------------------------------------------------------*
         * Compute innovation vector gain.                                 *
         * Include fixed-gain pitch contribution into code[].              *
         *-----------------------------------------------------------------*/

        if (T0 < L_CODE)
        {
            for (i = T0; i < L_CODE; i++)
            {
                temp =
                    mult(
                        *(code + i - T0),
                        sharp,
                        pOverflow);

                *(code + i) =
                    add(
                        *(code + i),
                        temp,
                        pOverflow);
            }
        }

        return(index);
    }