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

📄 cod_amr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* ------------------------------------------------------------------ * Copyright (C) 2008 PacketVideo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. * See the License for the specific language governing permissions * and limitations under the License. * ------------------------------------------------------------------- *//****************************************************************************************Portions of this file are derived from the following 3GPP standard:    3GPP TS 26.073    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec    Available from http://www.3gpp.org(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)Permission to distribute, modify and use this file under the standard licenseterms listed above has been obtained from the copyright holder.****************************************************************************************//*------------------------------------------------------------------------------ Pathname: ./audio/gsm-amr/c/src/cod_amr.c Funtions: cod_amr_init           cod_amr_reset           cod_amr_exit           cod_amr_first           cod_amr     Date: 06/09/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Made changes based on comments from the review meeting. Description: Synchronized file with UMTS version 3.2.0. Updated coding              template. Removed unnecessary include files. Description: Added initialization of the overflow flag in cod_amr_init()              and in cod_amr_reset(). This overflow flag is now part of              the cod_amrState structure. Description: Cleaned up INCLUDES. removed inclusion of basic_op.h and repeat              inclusion of copy.h Description: Updated function call to dtx_enc Description:  For cod_amr_first() and cod_amr()              1. Replaced copy() function with memcpy() Description:  Replaced OSCL mem type functions and eliminated include               files that now are chosen by OSCL definitions Description:  Replaced "int" and/or "char" with OSCL defined types. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION These functions comprise the main encoder routine operating on a frame basis.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "cod_amr.h"#include "typedef.h"#include "cnst.h"#include "copy.h"#include "qua_gain.h"#include "lpc.h"#include "lsp.h"#include "pre_big.h"#include "ol_ltp.h"#include "p_ol_wgh.h"#include "spreproc.h"#include "cl_ltp.h"#include "pred_lt.h"#include "spstproc.h"#include "cbsearch.h"#include "gain_q.h"#include "convolve.h"#include "ton_stab.h"#include "vad.h"#include "dtx_enc.h"#include "oscl_mem.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//* Spectral expansion factors */static const Word16 gamma1[M] ={    30802, 28954, 27217, 25584, 24049,    22606, 21250, 19975, 18777, 17650};/* gamma1 differs for the 12k2 coder */static const Word16 gamma1_12k2[M] ={    29491, 26542, 23888, 21499, 19349,    17414, 15672, 14105, 12694, 11425};static const Word16 gamma2[M] ={    19661, 11797, 7078, 4247, 2548,    1529, 917, 550, 330, 198};/*------------------------------------------------------------------------------ FUNCTION NAME: cod_amr_init------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a pointer to a structure of type cod_amrState Outputs:    Structure pointed to by the pointer pointed to by state is      initialized to its reset value    state points to the allocated memory Returns:    Returns 0 if memory was successfully initialized,        otherwise returns -1. Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function allocates memory and initializes state variables.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint cod_amr_init (cod_amrState **state, Flag dtx){  cod_amrState* s;  if (state == (cod_amrState **) NULL){      fprintf(stderr, "cod_amr_init: invalid parameter\n");      return -1;  }  *state = NULL;  // allocate memory  if ((s= (cod_amrState *) malloc(sizeof(cod_amrState))) == NULL){      fprintf(stderr, "cod_amr_init: can not malloc state structure\n");      return -1;  }  s->lpcSt = NULL;  s->lspSt = NULL;  s->clLtpSt = NULL;  s->gainQuantSt = NULL;  s->pitchOLWghtSt = NULL;  s->tonStabSt = NULL;  s->vadSt = NULL;  s->dtx_encSt = NULL;  s->dtx = dtx;  // Init sub states  if (cl_ltp_init(&s->clLtpSt) ||      lsp_init(&s->lspSt) ||      gainQuant_init(&s->gainQuantSt) ||      p_ol_wgh_init(&s->pitchOLWghtSt) ||      ton_stab_init(&s->tonStabSt) ||#ifndef VAD2      vad1_init(&s->vadSt) ||#else      vad2_init(&s->vadSt) ||#endif      dtx_enc_init(&s->dtx_encSt) ||      lpc_init(&s->lpcSt)) {     cod_amr_exit(&s);     return -1;  }  cod_amr_reset(s);  *state = s;  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_init(cod_amrState **state, Flag dtx){    cod_amrState* s;    if (state == (cod_amrState **) NULL)    {        /* fprint(stderr, "cod_amr_init: invalid parameter\n");  */        return(-1);    }    *state = NULL;    /* allocate memory */    if ((s = (cod_amrState *) oscl_malloc(sizeof(cod_amrState))) == NULL)    {        /* fprint(stderr, "cod_amr_init:                           can not malloc state structure\n");  */        return(-1);    }    s->lpcSt = NULL;    s->lspSt = NULL;    s->clLtpSt = NULL;    s->gainQuantSt = NULL;    s->pitchOLWghtSt = NULL;    s->tonStabSt = NULL;    s->vadSt = NULL;    s->dtx_encSt = NULL;    s->dtx = dtx;    /* Initialize overflow Flag */    s->overflow = 0;    /* Init sub states */    if (cl_ltp_init(&s->clLtpSt) ||            lsp_init(&s->lspSt) ||            gainQuant_init(&s->gainQuantSt) ||            p_ol_wgh_init(&s->pitchOLWghtSt) ||            ton_stab_init(&s->tonStabSt) ||#ifndef VAD2            vad1_init(&s->vadSt) ||#else            vad2_init(&s->vadSt) ||#endif            dtx_enc_init(&s->dtx_encSt) ||            lpc_init(&s->lpcSt))    {        cod_amr_exit(&s);        return(-1);    }    cod_amr_reset(s);    *state = s;    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: cod_amr_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a structure of type cod_amrState Outputs:    Structure pointed to by state is initialized to initial values. Returns:    Returns 0 if memory was successfully initialized,        otherwise returns -1. Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function resets the state memory for cod_amr.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES cod_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint cod_amr_reset (cod_amrState *st){   Word16 i;   if (st == (cod_amrState *) NULL){      fprintf(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];   // Static vectors to zero   Set_zero(st->old_speech, L_TOTAL);   Set_zero(st->old_exc,    PIT_MAX + L_INTERPOL);   Set_zero(st->old_wsp,    PIT_MAX);   Set_zero(st->mem_syn,    M);   Set_zero(st->mem_w,      M);   Set_zero(st->mem_w0,     M);   Set_zero(st->mem_err,    M);   Set_zero(st->zero,       L_SUBFR);   Set_zero(st->hvec,       L_SUBFR);    // set to zero "h1[-L_SUBFR..-1]"

⌨️ 快捷键说明

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