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

📄 cod_amr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   // OL LTP states   for (i = 0; i < 5; i++)   {      st->old_lags[i] = 40;   }   // Reset lpc states   lpc_reset(st->lpcSt);   // Reset lsp states   lsp_reset(st->lspSt);   // Reset clLtp states   cl_ltp_reset(st->clLtpSt);   gainQuant_reset(st->gainQuantSt);   p_ol_wgh_reset(st->pitchOLWghtSt);   ton_stab_reset(st->tonStabSt);#ifndef VAD2   vad1_reset(st->vadSt);#else   vad2_reset(st->vadSt);#endif   dtx_enc_reset(st->dtx_encSt);   st->sharp = SHARPMIN;   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]------------------------------------------------------------------------------*/Word16 cod_amr_reset(cod_amrState *st){    Word16 i;    if (st == (cod_amrState *) NULL)    {        /* fprint(stderr, "cod_amr_reset: invalid parameter\n");  */        return(-1);    }    /*-----------------------------------------------------------------------*     *          Initialize pointers to speech vector.                        *     *-----------------------------------------------------------------------*/    st->new_speech = st->old_speech + L_TOTAL - L_FRAME;   /* New speech     */    st->speech = st->new_speech - L_NEXT;                  /* Present frame  */    st->p_window = st->old_speech + L_TOTAL - L_WINDOW;    /* For LPC window */    st->p_window_12k2 = st->p_window - L_NEXT; /* EFR LPC window: no lookahead */    /* Initialize static pointers */    st->wsp = st->old_wsp + PIT_MAX;    st->exc = st->old_exc + PIT_MAX + L_INTERPOL;    st->zero = st->ai_zero + MP1;    st->error = st->mem_err + M;    st->h1 = &st->hvec[L_SUBFR];    /* Initialize overflow Flag */    st->overflow = 0;    /* Static vectors to zero */    oscl_memset(st->old_speech, 0, sizeof(Word16)*L_TOTAL);    oscl_memset(st->old_exc, 0,    sizeof(Word16)*(PIT_MAX + L_INTERPOL));    oscl_memset(st->old_wsp, 0,    sizeof(Word16)*PIT_MAX);    oscl_memset(st->mem_syn, 0,    sizeof(Word16)*M);    oscl_memset(st->mem_w,   0,    sizeof(Word16)*M);    oscl_memset(st->mem_w0,  0,    sizeof(Word16)*M);    oscl_memset(st->mem_err, 0,    sizeof(Word16)*M);    oscl_memset(st->zero, 0,       sizeof(Word16)*L_SUBFR);    oscl_memset(st->hvec, 0,       sizeof(Word16)*L_SUBFR);    /* set to zero "h1[-L_SUBFR..-1]" */    /* OL LTP states */    for (i = 0; i < 5; i++)    {        st->old_lags[i] = 40;    }    /* Reset lpc states */    lpc_reset(st->lpcSt);    /* Reset lsp states */    lsp_reset(st->lspSt);    /* Reset clLtp states */    cl_ltp_reset(st->clLtpSt);    gainQuant_reset(st->gainQuantSt);    p_ol_wgh_reset(st->pitchOLWghtSt);    ton_stab_reset(st->tonStabSt);#ifndef VAD2    vad1_reset(st->vadSt);#else    vad2_reset(st->vadSt);#endif    dtx_enc_reset(st->dtx_encSt);    st->sharp = SHARPMIN;    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: cod_amr_exit------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a pointer to a structure of type cod_amrState Outputs:    state points to a NULL address Returns:    None. Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function frees the memory used for state memory.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid cod_amr_exit (cod_amrState **state){   if (state == NULL || *state == NULL)      return;   // dealloc members   lpc_exit(&(*state)->lpcSt);   lsp_exit(&(*state)->lspSt);   gainQuant_exit(&(*state)->gainQuantSt);   cl_ltp_exit(&(*state)->clLtpSt);   p_ol_wgh_exit(&(*state)->pitchOLWghtSt);   ton_stab_exit(&(*state)->tonStabSt);#ifndef VAD2   vad1_exit(&(*state)->vadSt);#else   vad2_exit(&(*state)->vadSt);#endif   dtx_enc_exit(&(*state)->dtx_encSt);   // deallocate memory   free(*state);   *state = 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 cod_amr_exit(cod_amrState **state){    if (state == NULL || *state == NULL)    {        return;    }    /* dealloc members */    lpc_exit(&(*state)->lpcSt);    lsp_exit(&(*state)->lspSt);    gainQuant_exit(&(*state)->gainQuantSt);    cl_ltp_exit(&(*state)->clLtpSt);    p_ol_wgh_exit(&(*state)->pitchOLWghtSt);    ton_stab_exit(&(*state)->tonStabSt);#ifndef VAD2    vad1_exit(&(*state)->vadSt);#else    vad2_exit(&(*state)->vadSt);#endif    dtx_enc_exit(&(*state)->dtx_encSt);    /* deallocate memory */    oscl_free(*state); // BX    *state = NULL;    return;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: cod_amr_first------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type cod_amrState    new_speech = pointer to buffer of length L_FRAME that contains                 the speech input (Word16) Outputs:    The structure of type cod_amrState pointed to by st is updated. Returns:    return_value = 0 (int) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function copes with look-ahead and calls cod_amr. No input argument are passed to this function. However, before calling this function, 40 new speech data should be copied to the vector new_speech[]. This is a global pointer which is declared in this file (it points to the end of speech buffer minus 200).------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint cod_amr_first(cod_amrState *st,     // i/o : State struct                  Word16 new_speech[])  // i   : speech input (L_FRAME){   Copy(new_speech,&st->new_speech[-L_NEXT], L_NEXT);   //   Copy(new_speech,st->new_speech,L_FRAME);   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]------------------------------------------------------------------------------*/Word16 cod_amr_first(cod_amrState *st,     /* i/o : State struct           */                     Word16 new_speech[])  /* i   : speech input (L_FRAME) */{    oscl_memcpy(&st->new_speech[-L_NEXT], new_speech, L_NEXT*sizeof(Word16));    /*   Copy(new_speech,st->new_speech,L_FRAME); */    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: cod_amr------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type cod_amrState    mode = AMR mode of type enum Mode    new_speech = pointer to buffer of length L_FRAME that contains             the speech input of type Word16    ana = pointer to the analysis parameters of type Word16    usedMode = pointer to the used mode of type enum Mode    synth = pointer to a buffer containing the local synthesis speech of        type Word16 Outputs:    The structure of type cod_amrState pointed to by st is updated.    The analysis parameter buffer pointed to by ana is updated.    The value pointed to by usedMode is updated.    The local synthesis speech buffer pointed to by synth is updated. Returns:    return_value = 0 (int) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function is the main encoder routine. It is called every 20 ms speech frame, operating on the newly read 160 speech samples. It performs the principle encoding functions to produce the set of encoded parameters which include the LSP, adaptive codebook, and fixed codebook quantization indices (addresses and gains). Before calling this function, 160 new speech data should be copied to the vector new_speech[]. This is a global pointer which is declared in this file (it points to the end of speech buffer minus 160). The outputs of the function are:     ana[]:     vector of analysis parameters.     synth[]:   Local synthesis speech (for debugging purposes)------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES

⌨️ 快捷键说明

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