⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c2_11pf.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    Word16 sq1;    Word16 alpk;    Word16 alp;    Word16 alp_16;    Word32 s;    Word32 alp0;    Word32 alp1;    Word16 i;    Word16 *p_codvec = &codvec[0];    psk = -1;    alpk = 1;    for (i = 0; i < NB_PULSE; i++)    {        *(p_codvec++) = i;    }    /*------------------------------------------------------------------*    * main loop: try 2x4  tracks.                                      *    *------------------------------------------------------------------*/    for (track1 = 0; track1 < 2; track1++)    {        for (track2 = 0; track2 < 4; track2++)        {            /* fix starting position */            ipos[0] = startPos1[track1];            ipos[1] = startPos2[track2];            /*----------------------------------------------------------------*            * i0 loop: try 8 positions.                                      *            *----------------------------------------------------------------*/            for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP)            {                ps0 = dn[i0];                /* alp0 = L_mult(rr[i0][i0], _1_4, pOverflow); */                alp0 = (Word32) rr[i0][i0] << 14;                /*-------------------------------------------------------------*                * i1 loop: 8 positions.                                       *                *-------------------------------------------------------------*/                sq = -1;                alp = 1;                ix = ipos[1];                /*---------------------------------------------------------------*                * These index have low complexity address computation because   *                * they are, in fact, pointers with fixed increment. For example,*                * "rr[i0][i2]" is a pointer initialized to "&rr[i0][ipos[2]]"   *                * and incremented by "STEP".                                    *                *---------------------------------------------------------------*/                for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP)                {                    /* idx increment = STEP */                    ps1 = add(ps0, dn[i1], pOverflow);                    /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */                    /* idx incr = STEP */                    /* alp1 = L_mac(alp0, rr[i1][i1], _1_4, pOverflow); */                    alp1 = alp0 + ((Word32) rr[i1][i1] << 14);                    /* idx incr = STEP */                    /* alp1 = L_mac(alp1, rr[i0][i1], _1_2, pOverflow); */                    alp1 += (Word32) rr[i0][i1] << 15;                    /* sq1 = mult(ps1, ps1, pOverflow); */                    sq1 = (Word16)(((Word32) ps1 * ps1) >> 15);                    /* alp_16 = pv_round(alp1, pOverflow); */                    alp_16 = (Word16)((alp1 + (Word32) 0x00008000L) >> 16);                    /* s = L_mult(alp, sq1, pOverflow); */                    s = ((Word32) alp * sq1) << 1;                    /* s =L_msu(s, sq, alp_16, pOverflow); */                    s -= (((Word32) sq * alp_16) << 1);                    if (s > 0)                    {                        sq = sq1;                        alp = alp_16;                        ix = i1;                    }                } /* for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP) */                /* memorize codevector if this one is better than the last one. */                /* s = L_mult(alpk, sq, pOverflow); */                s = ((Word32) alpk * sq) << 1;                /* s = L_msu(s, psk, alp, pOverflow); */                s -= (((Word32) psk * alp) << 1);                if (s > 0)                {                    psk = sq;                    alpk = alp;                    p_codvec = &codvec[0];                    *(p_codvec++) = i0;                    *(p_codvec) = ix;                }            } /* for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP) */        } /* for (track2 = 0; track2 < 4; track2++) */    } /* for (track1 = 0; track1 < 2; track1++) */    return;} /* search_2i40 *//****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: build_code------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    codvec,  position of pulses, array of type Word16    dn_sign, sign of pulses, array of type Word16    h,       impulse response of weighted synthesis filter, Word16 array Outputs:    cod,       innovative code vector, array of type Word16    y[],       filtered innovative code, array of type Word16    sign[],    sign of 2 pulses, array of type Word16    pOverflow, Flag set when overflow occurs, pointer of type Flag * Returns: Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Builds the codeword, the filtered codeword and index of the codevector, based on the signs and positions of 2 pulses.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES c2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable                used to represent cycle count for each subroutine                called)     where: (cycle count variable) = cycle count for [subroutine                                     name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static Word16 build_code(    Word16 codvec[],    /* i : position of pulses                            */    Word16 dn_sign[],   /* i : sign of pulses                                */    Word16 cod[],       /* o : innovative code vector                        */    Word16 h[],         /* i : impulse response of weighted synthesis filter */    Word16 y[],         /* o : filtered innovative code                      */    Word16 sign[],      /* o : sign of 2 pulses                              */    Flag   * pOverflow  /* o : Flag set when overflow occurs                 */){    Word16 i;    Word16 j;    Word16 k;    Word16 track;    Word16 index;    Word16 _sign[NB_PULSE];    Word16 indx;    Word16 rsign;    Word16 tempWord;    Word16 *p0;    Word16 *p1;    Word32 s;    for (i = 0; i < L_CODE; i++)    {        cod[i] = 0;    }    indx = 0;    rsign = 0;    for (k = 0; k < NB_PULSE; k++)    {        i = codvec[k];      /* read pulse position */        j = dn_sign[i];     /* read sign           */        /* index = pos/5 */        /* index = mult(i, 6554, pOverflow); */        index = (Word16)(((Word32) i * 6554) >> 15);        /* track = pos%5 */        /* tempWord =            L_mult(            index,            5,            pOverflow); */        tempWord = ((Word32) index * 5) << 1;        /* tempWord =            L_shr(            tempWord,            1,            pOverflow); */        tempWord >>= 1;        /* track =            sub(            i,            tempWord,            pOverflow); */        track = i - tempWord;        tempWord = track;        if (tempWord == 0)        {            track = 1;            /* index =                shl(                index,                6,                pOverflow); */            index <<= 6;        }        else if (track == 1)        {            tempWord = k;            if (tempWord == 0)            {                track = 0;                /* index =                    shl(                    index,                    1,                    pOverflow); */                index <<= 1;            }            else            {                track = 1;                /* tempWord =                    shl(                    index,                    6,                    pOverflow); */                tempWord = index << 6;                /* index =                    add(                    tempWord,                    16,                    pOverflow); */                index = tempWord + 16;            }        }        else if (track == 2)        {            track = 1;            /* tempWord =                shl(                index,                6,                pOverflow); */            tempWord = index << 6;            /* index =                add(                tempWord,                32,                pOverflow); */            index = tempWord + 32;        }        else if (track == 3)        {            track = 0;            /* tempWord =                shl(                index,                1,                pOverflow); */            tempWord = index << 1;            /* index =                add(                tempWord,                1,                pOverflow); */            index = tempWord + 1;        }        else if (track == 4)        {            track = 1;            /* tempWord =                shl(                index,                6,                pOverflow); */            tempWord = index << 6;            /* index =                add(                tempWord,                48,                pOverflow); */            index = tempWord + 48;        }        if (j > 0)        {            cod[i] = 8191;            _sign[k] = 32767;            tempWord =                shl(                    1,                    track,                    pOverflow);            rsign =                add(                    rsign,                    tempWord,                    pOverflow);        }        else        {            cod[i] = -8192;            _sign[k] = (Word16) - 32768L;        }        indx =            add(                indx,                index,                pOverflow);    }    *sign = rsign;    p0 = h - codvec[0];    p1 = h - codvec[1];    for (i = 0; i < L_CODE; i++)    {        s = 0;        s =            L_mac(                s,                *p0++,                _sign[0],                pOverflow);        s =            L_mac(                s,                *p1++,                _sign[1],                pOverflow);        y[i] =            pv_round(                s,                pOverflow);    }    return indx;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -