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

📄 dtx_enc.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        log_en = (Word16)(((Word32) st->log_en_index) << (-2 + 10));        log_en = sub(log_en, 11560, pOverflow);        if (log_en > 0)        {            log_en = 0;        }        else if (log_en < -14436)        {            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 = (Word16)(((Word32)(5443 * log_en)) >> 15);        /* 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, pOverflow);        Reorder_lsf(lsf, LSF_GAP, M, pOverflow);        Lsf_lsp(lsf, lsp, M, pOverflow);        /* Quantize lsp and put on parameter list */        Q_plsf_3(qSt, MRDTX, lsp, lsp_q, st->lsp_index,                 &st->init_lsf_vq_index, pOverflow);    }    *(*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 */}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: dtx_buffer------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to structures of type dtx_encState    lsp_new = LSP vector whose elements are of type Word16; vector          length is M    speech = vector of speech samples of type Word16; vector length is         BFR_SIZE_GSM Outputs:    structure pointed to by st contains the new LSPs and logarithmic      frame energy Returns:    return_value = 0 (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function handles the DTX buffer.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint dtx_buffer(dtx_encState *st,   // i/o : State struct               Word16 lsp_new[],   // i   : LSP vector               Word16 speech[]     // i   : speech samples){   Word16 i;   Word32 L_frame_en;   Word16 log_en_e;   Word16 log_en_m;   Word16 log_en;   // update pointer to circular buffer   st->hist_ptr = add(st->hist_ptr, 1);   if (sub(st->hist_ptr, DTX_HIST_SIZE) == 0)   {      st->hist_ptr = 0;   }   // copy lsp vector into buffer   Copy(lsp_new, &st->lsp_hist[st->hist_ptr * M], M);   // compute log energy based on frame energy   L_frame_en = 0;     // Q0   for (i=0; i < L_FRAME; i++)   {      L_frame_en = L_mac(L_frame_en, speech[i], speech[i]);   }   Log2(L_frame_en, &log_en_e, &log_en_m);   // convert exponent and mantissa to Word16 Q10   log_en = shl(log_en_e, 10);  // Q10   log_en = add(log_en, shr(log_en_m, 15-10));   // divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193   log_en = sub(log_en, 8521);   // insert into log energy buffer with division by 2   log_en = shr(log_en, 1);   st->log_en_hist[st->hist_ptr] = log_en; // Q10   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_buffer(dtx_encState *st,   /* i/o : State struct                    */                Word16 lsp_new[],   /* i   : LSP vector                      */                Word16 speech[],    /* i   : speech samples                  */                Flag   *pOverflow   /* i/o : overflow indicator              */               ){    register Word16 i;    Word32 L_frame_en;    Word32 L_temp;    Word16 log_en_e;    Word16 log_en_m;    Word16 log_en;    Word16 *p_speech = &speech[0];    /* update pointer to circular buffer      */    st->hist_ptr += 1;    if (st->hist_ptr == DTX_HIST_SIZE)    {        st->hist_ptr = 0;    }    /* copy lsp vector into buffer */    oscl_memcpy(&st->lsp_hist[st->hist_ptr * M], lsp_new, M*sizeof(Word16));    /* compute log energy based on frame energy */    L_frame_en = 0;     /* Q0 */    for (i = L_FRAME; i != 0; i--)    {        L_frame_en += (((Word32) * p_speech) * *(p_speech)) << 1;        p_speech++;        if (L_frame_en < 0)        {            L_frame_en = MAX_32;            break;        }    }    Log2(L_frame_en, &log_en_e, &log_en_m, pOverflow);    /* convert exponent and mantissa to Word16 Q10 */    /* Q10 */    L_temp = ((Word32) log_en_e) << 10;    if (L_temp != (Word32)((Word16) L_temp))    {        *pOverflow = 1;        log_en = (log_en_e > 0) ? MAX_16 : MIN_16;    }    else    {        log_en = (Word16) L_temp;    }    log_en += log_en_m >> (15 - 10);    /* divide with L_FRAME i.e subtract with log2(L_FRAME) = 7.32193 */    log_en -= 8521;    /* insert into log energy buffer with division by 2 */    st->log_en_hist[st->hist_ptr] = log_en >> 1; /* Q10 */}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: tx_dtx_handler------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to structures of type dtx_encState    vad_flag = VAD decision flag of type Word16    usedMode = pointer to the currently used mode of type enum Mode Outputs:    structure pointed to by st contains the newly calculated speech      hangover Returns:    compute_new_sid_possible = flag to indicate a change in the                   used mode; store type is Word16 Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function adds extra speech hangover to analyze speech on the decoding side.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dtx_enc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEWord16 tx_dtx_handler(dtx_encState *st,      // i/o : State struct                      Word16 vad_flag,       // i   : vad decision                      enum Mode *usedMode    // i/o : mode changed or not                      ){   Word16 compute_new_sid_possible;   // this state machine is in synch with the GSMEFR txDtx machine   st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1);   compute_new_sid_possible = 0;   if (vad_flag != 0)   {      st->dtxHangoverCount = DTX_HANG_CONST;   }   else   {  // non-speech      if (st->dtxHangoverCount == 0)      {  // out of decoder analysis hangover         st->decAnaElapsedCount = 0;         *usedMode = MRDTX;         compute_new_sid_possible = 1;      }      else      { // in possible analysis hangover         st->dtxHangoverCount = sub(st->dtxHangoverCount, 1);         // decAnaElapsedCount + dtxHangoverCount < DTX_ELAPSED_FRAMES_THRESH         if (sub(add(st->decAnaElapsedCount, st->dtxHangoverCount),                 DTX_ELAPSED_FRAMES_THRESH) < 0)         {            *usedMode = MRDTX;            // if short time since decoder update, do not add extra HO         }         // else         //   override VAD and stay in         //   speech mode *usedMode         //   and add extra hangover      }   }   return compute_new_sid_possible;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/Word16 tx_dtx_handler(dtx_encState *st,      /* i/o : State struct           */                      Word16 vad_flag,       /* i   : vad decision           */                      enum Mode *usedMode,   /* i/o : mode changed or not    */                      Flag   *pOverflow      /* i/o : overflow indicator     */                     ){    Word16 compute_new_sid_possible;    Word16 count;    /* this state machine is in synch with the GSMEFR txDtx machine */    st->decAnaElapsedCount = add(st->decAnaElapsedCount, 1, pOverflow);    compute_new_sid_possible = 0;    if (vad_flag != 0)    {        st->dtxHangoverCount = DTX_HANG_CONST;    }    else    {  /* non-speech */        if (st->dtxHangoverCount == 0)        {  /* out of decoder analysis hangover  */            st->decAnaElapsedCount = 0;            *usedMode = MRDTX;            compute_new_sid_possible = 1;        }        else        { /* in possible analysis hangover */            st->dtxHangoverCount -= 1;            /* decAnaElapsedCount + dtxHangoverCount < */            /* DTX_ELAPSED_FRAMES_THRESH               */            count = add(st->decAnaElapsedCount, st->dtxHangoverCount,                        pOverflow);            if (count < DTX_ELAPSED_FRAMES_THRESH)            {                *usedMode = MRDTX;                /* if short time since decoder update, */                /* do not add extra HO                 */            }        }    }    return(compute_new_sid_possible);}

⌨️ 快捷键说明

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