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

📄 dtx_dec.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/dtx_dec.c Functions:           dtx_dec_reset           dtx_dec           dtx_dec_activity_update           rx_dtx_handler     Date: 04/17/2000------------------------------------------------------------------------------ REVISION HISTORY Description: First attempt at optimization. Description: Made changes based on comments from the review. 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. Modified FOR loops to count down.              2. Made some cosmetic changes.              3. Replaced call to "abs" with "abs_s".              4. Added lsp.tab and q_plsf_5.tab to the Include section.              5. Fixed typecasting issue with TI C compiler.              6. Replaced basic_op.h and oper_32b.h with the header files                 of the math functions used by the file. Description: Removed the functions dtx_dec_init and dtx_dec_exit. The dtx_dec related structure is no longer dynamically allocated. Description: Made the following changes to make code bit-exact:              1. Fixed inlining of shl() function in parts of dtx_dec and                 dtx_dec_activity_update functions.              2. Fixed optimazation bugs in dtx_dec function.              3. Modified some FOR loops in dtx_dec to count up.              4. Added call to add() function in rx_dtx_handler function.              5. Updated copyright year. Description: Passing in pOverflow rather than accessing it as a global              variable. Description: Synchronized file with UMTS (3GPP) version 3.3.0 == GSM version              7.6.0 == 3GPP Release 4, version 4.1.0. Description: Removed call to test() on line 843. 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 These modules decode the comfort noise when in DTX.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "dtx_dec.h"#include "typedef.h"#include "basic_op.h"#include "copy.h"#include "set_zero.h"#include "mode.h"#include "log2.h"#include "lsp_az.h"#include "pow2.h"#include "a_refl.h"#include "b_cn_cod.h"#include "syn_filt.h"#include "lsp_lsf.h"#include "reorder.h"#include "lsp_tab.h"#include "oscl_mem.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*/#define PN_INITIAL_SEED 0x70816958L   /* Pseudo noise generator seed value  *//*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//*************************************************** * Scaling factors for the lsp variability operation * ***************************************************/static const Word16 lsf_hist_mean_scale[M] ={    20000,    20000,    20000,    20000,    20000,    18000,    16384,    8192,    0,    0};/************************************************* * level adjustment for different modes Q11      * *************************************************/static const Word16 dtx_log_en_adjust[9] ={    -1023, /* MR475 */    -878, /* MR515 */    -732, /* MR59  */    -586, /* MR67  */    -440, /* MR74  */    -294, /* MR795 */    -148, /* MR102 */    0, /* MR122 */    0, /* MRDTX */};/*------------------------------------------------------------------------------ FUNCTION NAME: dtx_dec_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type dtx_decState Outputs:    Structure pointed to by st is initialized to a set of initial values. Returns:    return_value = 0 if memory was successfully initialized,        otherwise returns -1 (int) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Reset of state memory for dtx_dec.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001------------------------------------------------------------------------------ PSEUDO-CODEint dtx_dec_reset (dtx_decState *st){   int i;   if (st == (dtx_decState *) NULL){      fprintf(stderr, "dtx_dec_reset: invalid parameter\n");      return -1;   }   st->since_last_sid = 0;   st->true_sid_period_inv = (1 << 13);   st->log_en = 3500;   st->old_log_en = 3500;   // low level noise for better performance in  DTX handover cases   st->L_pn_seed_rx = PN_INITIAL_SEED;   // Initialize state->lsp [] and state->lsp_old []   Copy(lsp_init_data, &st->lsp[0], M);   Copy(lsp_init_data, &st->lsp_old[0], M);   st->lsf_hist_ptr = 0;   st->log_pg_mean = 0;   st->log_en_hist_ptr = 0;   // initialize decoder lsf history   Copy(mean_lsf, &st->lsf_hist[0], M);   for (i = 1; i < DTX_HIST_SIZE; i++)   {      Copy(&st->lsf_hist[0], &st->lsf_hist[M*i], M);   }   Set_zero(st->lsf_hist_mean, M*DTX_HIST_SIZE);   // initialize decoder log frame energy   for (i = 0; i < DTX_HIST_SIZE; i++)   {      st->log_en_hist[i] = st->log_en;   }   st->log_en_adjust = 0;   st->dtxHangoverCount = DTX_HANG_CONST;   st->decAnaElapsedCount = 32767;   st->sid_frame = 0;   st->valid_data = 0;   st->dtxHangoverAdded = 0;   st->dtxGlobalState = DTX;   st->data_updated = 0;   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 dtx_dec_reset(dtx_decState *st){    Word16 i;    if (st == (dtx_decState *) NULL)    {        /* fprint(stderr, "dtx_dec_reset: invalid parameter\n");  */        return(-1);    }    st->since_last_sid = 0;    st->true_sid_period_inv = (1 << 13);    st->log_en = 3500;    st->old_log_en = 3500;    /* low level noise for better performance in  DTX handover cases*/    st->L_pn_seed_rx = PN_INITIAL_SEED;    /* Initialize state->lsp [] */    st->lsp[0] = 30000;    st->lsp[1] = 26000;    st->lsp[2] = 21000;    st->lsp[3] = 15000;    st->lsp[4] = 8000;    st->lsp[5] = 0;    st->lsp[6] = -8000;    st->lsp[7] = -15000;    st->lsp[8] = -21000;    st->lsp[9] = -26000;    /* Initialize state->lsp_old [] */    st->lsp_old[0] = 30000;    st->lsp_old[1] = 26000;    st->lsp_old[2] = 21000;    st->lsp_old[3] = 15000;    st->lsp_old[4] = 8000;    st->lsp_old[5] = 0;    st->lsp_old[6] = -8000;    st->lsp_old[7] = -15000;    st->lsp_old[8] = -21000;    st->lsp_old[9] = -26000;    st->lsf_hist_ptr = 0;    st->log_pg_mean = 0;    st->log_en_hist_ptr = 0;    /* initialize decoder lsf history */    st->lsf_hist[0] =  1384;    st->lsf_hist[1] =  2077;    st->lsf_hist[2] =  3420;    st->lsf_hist[3] =  5108;    st->lsf_hist[4] =  6742;    st->lsf_hist[5] =  8122;    st->lsf_hist[6] =  9863;    st->lsf_hist[7] = 11092;    st->lsf_hist[8] = 12714;    st->lsf_hist[9] = 13701;    for (i = 1; i < DTX_HIST_SIZE; i++)    {        Copy(&st->lsf_hist[0], &st->lsf_hist[M*i], M);    }    oscl_memset(st->lsf_hist_mean, 0, sizeof(Word16)*M*DTX_HIST_SIZE);    /* initialize decoder log frame energy */    for (i = 0; i < DTX_HIST_SIZE; i++)    {        st->log_en_hist[i] = st->log_en;    }    st->log_en_adjust = 0;    st->dtxHangoverCount = DTX_HANG_CONST;    st->decAnaElapsedCount = 32767;    st->sid_frame = 0;    st->valid_data = 0;    st->dtxHangoverAdded = 0;    st->dtxGlobalState = DTX;    st->data_updated = 0;    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: dtx_dec------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type dtx_decState    mem_syn = AMR decoder state    lsfState = decoder lsf states    predState = prediction states    averState = CB gain average states    new_state = new DTX state    mode = AMR mode    parm = Vector of synthesis parameters Outputs:    st points to an updated structure of type dtx_decState    mem_syn = AMR decoder state    lsfState = decoder lsf states    predState = prediction states    averState = CB gain average states    synth = synthesised speech    A_t = decoded LP filter in 4 subframes Returns:    return_value = 0 (int) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Decode comfort noise when in DTX.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dtx_dec.c, UMTS GSM AMR speech codec, R99 - Version 3.3.0, December 12, 2001------------------------------------------------------------------------------ PSEUDO-CODEint dtx_dec(   dtx_decState *st,                // i/o : State struct   Word16 mem_syn[],                // i/o : AMR decoder state   D_plsfState* lsfState,           // i/o : decoder lsf states   gc_predState* predState,         // i/o : prediction states   Cb_gain_averageState* averState, // i/o : CB gain average states   enum DTXStateType new_state,     // i   : new DTX state   enum Mode mode,                  // i   : AMR mode   Word16 parm[],                   // i   : Vector of synthesis parameters   Word16 synth[],                  // o   : synthesised speech   Word16 A_t[]                     // o   : decoded LP filter in 4 subframes   ){   Word16 log_en_index;   Word16 i, j;   Word16 int_fac;   Word32 L_log_en_int;   Word16 lsp_int[M];   Word16 log_en_int_e;   Word16 log_en_int_m;   Word16 level;   Word16 acoeff[M + 1];   Word16 refl[M];   Word16 pred_err;   Word16 ex[L_SUBFR];   Word16 ma_pred_init;   Word16 log_pg_e, log_pg_m;   Word16 log_pg;   Flag negative;   Word16 lsf_mean;   Word32 L_lsf_mean;   Word16 lsf_variab_index;   Word16 lsf_variab_factor;   Word16 lsf_int[M];   Word16 lsf_int_variab[M];   Word16 lsp_int_variab[M];   Word16 acoeff_variab[M + 1];   Word16 lsf[M];   Word32 L_lsf[M];   Word16 ptr;   Word16 tmp_int_length;    // This function is called if synthesis state is not SPEECH    // the globally passed  inputs to this function are    // st->sid_frame    // st->valid_data    // st->dtxHangoverAdded    // new_state  (SPEECH, DTX, DTX_MUTE)   if ((st->dtxHangoverAdded != 0) &&       (st->sid_frame != 0))   {      // sid_first after dtx hangover period      // or sid_upd after dtxhangover      // set log_en_adjust to correct value      st->log_en_adjust = dtx_log_en_adjust[mode];      ptr = add(st->lsf_hist_ptr, M);      if (sub(ptr, 80) == 0)      {         ptr = 0;      }      Copy( &st->lsf_hist[st->lsf_hist_ptr],&st->lsf_hist[ptr],M);      ptr = add(st->log_en_hist_ptr,1);

⌨️ 快捷键说明

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