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

📄 dec_amr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* ------------------------------------------------------------------ * 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/dec_amr.c Funtions: Decoder_amr_init           Decoder_amr_reset           Decoder_amr     Date: 04/11/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Updated template used to PV coding template. First attempt at          optimizing C code. Description: Synchronized file with UMTS version 3.2.0. Updated coding              template. Removed unnecessary include files. Description: Made the following changes per comments from Phase 2/3 review:              1. Fixed Input/Output descriptions by adding typedefs and                 clarifying definitions.              2. Used #define instead of hard-coded loop counts.              3. Modified FOR loops to count down.              4. Copied function descriptions from dec_amr.h header file.              5. Defined one local variable per line. Description: Copied function descriptions from header file (forgot to do it              prior to checking-in -- oops!). Description: Removed the function decoder_amr_exit. The decoder_amr related structure is no longer dynamically allocated. Also, modified function calls throughout to reflect the fact that the members of the structure Decoder_amrState are no longer pointers to be set via malloc, but full-blown structures.  (Changes of the type D_plsfState *lsfState to D_plsfState lsfState) Description: Fixed bug in the Decoder_amr() caused non-bit exactness. The              Overflow flag was inadvertently taken out of the IF statement              that calls agc2 and Syn_filt. It was restored to the original              form. Updated copyright year. Description: Adding changes for EPOC regarding pOverflow being passed in              rather than being a global variable. Description: Initialize overflow flag in Decoder_amr_init() and               Decoder_amr_reset(). Initialize pointer to overflow flag in               Decoder_amr(). Description: Changed round function name to pv_round to avoid conflict with              round function in C standard library. Description:  Replaced OSCL mem type functions and eliminated include               files that now are chosen by OSCL definitions Description:  Replaced "int" and/or "char" with defined types.               Added proper casting (Word32) to some left shifting operations Description:------------------------------------------------------------------------------ MODULE DESCRIPTION This file contains the function used to decode one speech frame using a given codec mode. The functions used to initialize, reset, and exit are also included in this file.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "dec_amr.h"#include "typedef.h"#include "cnst.h"#include "copy.h"#include "set_zero.h"#include "syn_filt.h"#include "d_plsf.h"#include "agc.h"#include "int_lpc.h"#include "dec_gain.h"#include "dec_lag3.h"#include "dec_lag6.h"#include "d2_9pf.h"#include "d2_11pf.h"#include "d3_14pf.h"#include "d4_17pf.h"#include "d8_31pf.h"#include "d1035pf.h"#include "pred_lt.h"#include "d_gain_p.h"#include "d_gain_c.h"#include "dec_gain.h"#include "ec_gains.h"#include "ph_disp.h"#include "c_g_aver.h"#include "int_lsf.h"#include "lsp_lsf.h"#include "lsp_avg.h"#include "bgnscd.h"#include "ex_ctrl.h"#include "sqrt_l.h"#include "frame.h"#include "bitno_tab.h"#include "b_cn_cod.h"#include "basic_op.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----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: Decoder_amr_init------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a pointer to structures of type Decoder_amrState Outputs:    structure pointed to by the pointer which is pointed to by state is      initialized to each field's initial values    state pointer points to the address of the memory allocated by      Decoder_amr_init function Returns:    return_value = 0, if the initialization was successful; -1, otherwise (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function allocates and initializes state memory used by the Decoder_amr function. It stores the pointer to the filter status structure in state. This pointer has to be passed to Decoder_amr in each call. The function returns 0, if initialization was successful and -1, otherwise.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint Decoder_amr_init (Decoder_amrState **state){  Decoder_amrState* s;  Word16 i;  if (state == (Decoder_amrState **) NULL){      fprintf(stderr, "Decoder_amr_init: invalid parameter\n");      return -1;  }  *state = NULL;  // allocate memory  if ((s= (Decoder_amrState *) malloc(sizeof(Decoder_amrState))) == NULL){      fprintf(stderr, "Decoder_amr_init: can not malloc state structure\n");      return -1;  }  s->T0_lagBuff = 40;  s->inBackgroundNoise = 0;  s->voicedHangover = 0;  for (i = 0; i < 9; i++)     s->ltpGainHistory[i] = 0;  s->lsfState = NULL;  s->ec_gain_p_st = NULL;  s->ec_gain_c_st = NULL;  s->pred_state = NULL;  s->ph_disp_st = NULL;  s->dtxDecoderState = NULL;  if (D_plsf_init(&s->lsfState) ||      ec_gain_pitch_init(&s->ec_gain_p_st) ||      ec_gain_code_init(&s->ec_gain_c_st) ||      gc_pred_init(&s->pred_state) ||      Cb_gain_average_init(&s->Cb_gain_averState) ||      lsp_avg_init(&s->lsp_avg_st) ||      Bgn_scd_init(&s->background_state) ||      ph_disp_init(&s->ph_disp_st) ||      dtx_dec_init(&s->dtxDecoderState)) {      Decoder_amr_exit(&s);      return -1;  }  Decoder_amr_reset(s, (enum Mode)0);  *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 Decoder_amr_init(Decoder_amrState *s){    Word16 i;    if (s == (Decoder_amrState *) NULL)    {        /* fprint(stderr, "Decoder_amr_init: invalid parameter\n");  */        return(-1);    }    s->T0_lagBuff = 40;    s->inBackgroundNoise = 0;    s->voicedHangover = 0;    /* Initialize overflow Flag */    s->overflow = 0;    for (i = 0; i < LTP_GAIN_HISTORY_LEN; i++)    {        s->ltpGainHistory[i] = 0;    }    D_plsf_reset(&s->lsfState);    ec_gain_pitch_reset(&s->ec_gain_p_st);    ec_gain_code_reset(&s->ec_gain_c_st);    Cb_gain_average_reset(&s->Cb_gain_averState);    lsp_avg_reset(&s->lsp_avg_st);    Bgn_scd_reset(&s->background_state);    ph_disp_reset(&s->ph_disp_st);    dtx_dec_reset(&s->dtxDecoderState);    gc_pred_reset(&s->pred_state);    Decoder_amr_reset(s, MR475);    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Decoder_amr_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a structure of type Decoder_amrState    mode = codec mode (enum Mode) Outputs:    structure pointed to by state is initialized to its reset value Returns:    return_value = 0, if reset was successful; -1, otherwise (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function resets the state memory used by the Decoder_amr function. It returns a 0, if reset was successful and -1, otherwise.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint Decoder_amr_reset (Decoder_amrState *state, enum Mode mode){  Word16 i;  if (state == (Decoder_amrState *) NULL){      fprintf(stderr, "Decoder_amr_reset: invalid parameter\n");      return -1;  }  // Initialize static pointer  state->exc = state->old_exc + PIT_MAX + L_INTERPOL;  // Static vectors to zero  Set_zero (state->old_exc, PIT_MAX + L_INTERPOL);  if (mode != MRDTX)     Set_zero (state->mem_syn, M);  // initialize pitch sharpening  state->sharp = SHARPMIN;  state->old_T0 = 40;  // Initialize state->lsp_old []  if (mode != MRDTX) {      Copy(lsp_init_data, &state->lsp_old[0], M);  }  // Initialize memories of bad frame handling  state->prev_bf = 0;  state->prev_pdf = 0;  state->state = 0;  state->T0_lagBuff = 40;  state->inBackgroundNoise = 0;  state->voicedHangover = 0;  if (mode != MRDTX) {      for (i=0;i<9;i++)          state->excEnergyHist[i] = 0;  }  for (i = 0; i < 9; i++)     state->ltpGainHistory[i] = 0;  Cb_gain_average_reset(state->Cb_gain_averState);  if (mode != MRDTX)     lsp_avg_reset(state->lsp_avg_st);  D_plsf_reset(state->lsfState);  ec_gain_pitch_reset(state->ec_gain_p_st);  ec_gain_code_reset(state->ec_gain_c_st);  if (mode != MRDTX)     gc_pred_reset(state->pred_state);  Bgn_scd_reset(state->background_state);  state->nodataSeed = 21845;  ph_disp_reset(state->ph_disp_st);  if (mode != MRDTX)     dtx_dec_reset(state->dtxDecoderState);  return 0;}------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below.

⌨️ 快捷键说明

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