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

📄 dtx_enc.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------------ FUNCTION NAME: dtx_enc_exit------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to an array of pointers to structures of type         dtx_encState Outputs:    st points to the NULL address Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function deallocates the state memory used by dtx_enc function.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid dtx_enc_exit (dtx_encState **st){   if (st == NULL || *st == NULL)      return;   // deallocate memory   free(*st);   *st = NULL;   return;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/void dtx_enc_exit(dtx_encState **st){    if (st == NULL || *st == NULL)    {        return;    }    /* deallocate memory */    oscl_free(*st);    *st = NULL;    return;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: dtx_enc------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to structures of type dtx_encState    computeSidFlag = compute SID flag of type Word16    qSt = pointer to structures of type Q_plsfState    predState = pointer to structures of type gc_predState    anap = pointer to an array of pointers to analysis parameters of           type Word16 Outputs:    structure pointed to by st contains the newly calculated SID      parameters    structure pointed to by predState contains the new logarithmic frame      energy    pointer pointed to by anap points to the location of the new      logarithmic frame energy and new LSPs Returns:    return_value = 0 (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function calculates the SID parameters when in the DTX mode.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint dtx_enc(dtx_encState *st,        // i/o : State struct            Word16 computeSidFlag,   // i   : compute SID            Q_plsfState *qSt,        // i/o : Qunatizer state struct            gc_predState* predState, // i/o : State struct        Word16 **anap            // o   : analysis parameters        ){   Word16 i,j;   Word16 log_en;   Word16 lsf[M];   Word16 lsp[M];   Word16 lsp_q[M];   Word32 L_lsp[M];   // VOX mode computation of SID parameters   if ((computeSidFlag != 0)  ||        (st->log_en_index == 0))   {      // compute new SID frame if safe i.e don't      // compute immediately after a talk spurt      log_en = 0;      for (i = 0; i < M; i++)      {         L_lsp[i] = 0;      }      // average energy and lsp      for (i = 0; i < DTX_HIST_SIZE; i++)      {         log_en = add(log_en,                      shr(st->log_en_hist[i],2));         for (j = 0; j < M; j++)         {            L_lsp[j] = L_add(L_lsp[j],                             L_deposit_l(st->lsp_hist[i * M + j]));         }      }      log_en = shr(log_en, 1);      for (j = 0; j < M; j++)      {         lsp[j] = extract_l(L_shr(L_lsp[j], 3));   // divide by 8      }      //  quantize logarithmic energy to 6 bits      st->log_en_index = add(log_en, 2560);          // +2.5 in Q10      st->log_en_index = add(st->log_en_index, 128); // add 0.5/4 in Q10      st->log_en_index = shr(st->log_en_index, 8);      if (sub(st->log_en_index, 63) > 0)      {         st->log_en_index = 63;      }      if (st->log_en_index < 0)      {         st->log_en_index = 0;      }      // update gain predictor memory      log_en = shl(st->log_en_index, -2+10); // Q11 and divide by 4      log_en = sub(log_en, 2560);            // add 2.5 in Q11      log_en = sub(log_en, 9000);      if (log_en > 0)      {         log_en = 0;      }      if (sub(log_en, -14436) < 0)      {         log_en = -14436;      }      // past_qua_en for other modes than MR122      predState->past_qua_en[0] = log_en;      predState->past_qua_en[1] = log_en;      predState->past_qua_en[2] = log_en;      predState->past_qua_en[3] = log_en;      // scale down by factor 20*log10(2) in Q15      log_en = mult(5443, log_en);      // past_qua_en for mode MR122      predState->past_qua_en_MR122[0] = log_en;      predState->past_qua_en_MR122[1] = log_en;      predState->past_qua_en_MR122[2] = log_en;      predState->past_qua_en_MR122[3] = log_en;      // make sure that LSP's are ordered      Lsp_lsf(lsp, lsf, M);      Reorder_lsf(lsf, LSF_GAP, M);      Lsf_lsp(lsf, lsp, M);      // Quantize lsp and put on parameter list      Q_plsf_3(qSt, MRDTX, lsp, lsp_q, st->lsp_index,               &st->init_lsf_vq_index);   }   *(*anap)++ = st->init_lsf_vq_index; // 3 bits   *(*anap)++ = st->lsp_index[0];      // 8 bits   *(*anap)++ = st->lsp_index[1];      // 9 bits   *(*anap)++ = st->lsp_index[2];      // 9 bits   *(*anap)++ = st->log_en_index;      // 6 bits                                       // = 35 bits   return 0;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/void dtx_enc(dtx_encState *st,        /* i/o : State struct                  */             Word16 computeSidFlag,   /* i   : compute SID                   */             Q_plsfState *qSt,        /* i/o : Qunatizer state struct        */             gc_predState* predState, /* i/o : State struct                  */             Word16 **anap,           /* o   : analysis parameters           */             Flag   *pOverflow        /* i/o : overflow indicator            */            ){    register Word16 i, j;    Word16 temp;    Word16 log_en;    Word16 lsf[M];    Word16 lsp[M];    Word16 lsp_q[M];    Word32 L_lsp[M];    /* VOX mode computation of SID parameters */    if ((computeSidFlag != 0)  ||            (st->log_en_index == 0))    {        /* compute new SID frame if safe i.e don't         * compute immediately after a talk spurt  */        log_en = 0;        for (i = M - 1; i >= 0; i--)        {            L_lsp[i] = 0;        }        /* average energy and lsp */        for (i = DTX_HIST_SIZE - 1; i >= 0; i--)        {            if (st->log_en_hist[i] < 0)            {                temp = ~((~(st->log_en_hist[i])) >> 2);            }            else            {                temp = st->log_en_hist[i] >> 2;            }            log_en = add(log_en, temp, pOverflow);            for (j = M - 1; j >= 0; j--)            {                L_lsp[j] = L_add(L_lsp[j],                                 (Word32)(st->lsp_hist[i * M + j]),                                 pOverflow);            }        }        if (log_en < 0)        {            log_en = ~((~log_en) >> 1);        }        else        {            log_en = log_en >> 1;        }        for (j = M - 1; j >= 0; j--)        {            /* divide by 8 */            if (L_lsp[j] < 0)            {                lsp[j] = (Word16)(~((~L_lsp[j]) >> 3));            }            else            {                lsp[j] = (Word16)(L_lsp[j] >> 3);            }        }        /*  quantize logarithmic energy to 6 bits */        /* +2.5 in Q10 */        st->log_en_index = add(log_en, 2560, pOverflow);        /* add 0.5/4 in Q10 */        st->log_en_index = add(st->log_en_index, 128, pOverflow);        if (st->log_en_index < 0)        {            st->log_en_index = ~((~st->log_en_index) >> 8);        }        else        {            st->log_en_index = st->log_en_index >> 8;        }        /*---------------------------------------------*/        /* Limit to max and min allowable 6-bit values */        /* Note: For assembly implementation, use the  */        /*       following:                            */        /*       if(st->long_en_index >> 6 != 0)       */        /*       {                                     */        /*           if(st->long_en_index < 0)         */        /*           {                                 */        /*               st->long_en_index = 0         */        /*           }                                 */        /*           else                              */        /*           {                                 */        /*               st->long_en_index = 63        */        /*           }                                 */        /*       }                                     */        /*---------------------------------------------*/        if (st->log_en_index > 63)        {            st->log_en_index = 63;        }        else if (st->log_en_index < 0)        {            st->log_en_index = 0;        }        /* update gain predictor memory */        /* Q11 and divide by 4 */

⌨️ 快捷键说明

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