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

📄 bgnscd.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ------------------------------------------------------------------ * 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/bgnscd.c Functions:           Bgn_scd_reset           Bgn_scd     Date: 03/28/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Made prereview changes so the structure of the module conforms    with the others. Added checks for overflow on the shift functions. Description: Made changes based on comments from the review meeting. Description: Fixed a bug found during unit testing. Description: Synchronized code with UMTS version 3.2.0. Updated coding              template. Description: Made the following changes per comments from Phase 2/3 review:              1. Used TRUE/FALSE #defines instead of hard-coded 1/0 in                 Bgn_scd code.              2. Fixed typecasting issue with TI compiler.              3. Modified FOR loop to count down. Description: Modified FOR loop on line 740 to count up. Description: Removed the functions bgn_scd_init and bgn_scd_exit. The bgn_scd related structure is no longer dynamically allocated. Description: Making changes for EPOC. Passing in pOverflow instead of having              it act as a global variable. Updated include files and added              more description about pOverflow. 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 Background noise source characteristic detector (SCD)------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include    "bgnscd.h"#include    "typedef.h"#include    "basic_op.h"#include    "cnst.h"#include    "copy.h"#include    "gmed_n.h"#include    "sqrt_l.h"#include    "oscl_mem.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*/#define TRUE  1#define FALSE 0/*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: Bgn_scd_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = points to memory of type Bgn_scdState. Outputs:    The memory of type Bgn_scdState pointed to by state is set to all        zeros. Returns:    Returns 0 if memory was successfully initialized,        otherwise returns -1. Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Resets state memory.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES bgnscd.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEWord16 Bgn_scd_reset (Bgn_scdState *state){   if (state == (Bgn_scdState *) NULL){      fprintf(stderr, "Bgn_scd_reset: invalid parameter\n");      return -1;   }   // Static vectors to zero   Set_zero (state->frameEnergyHist, L_ENERGYHIST);   // Initialize hangover handling   state->bgHangover = 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  Bgn_scd_reset(Bgn_scdState *state){    if (state == (Bgn_scdState *) NULL)    {        /* fprintf(stderr, "Bgn_scd_reset: invalid parameter\n");  */        return(-1);    }    /* Static vectors to zero */    oscl_memset(state->frameEnergyHist, 0, L_ENERGYHIST*sizeof(Word16));    /* Initialize hangover handling */    state->bgHangover = 0;    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Bgn_scd------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to state variables of type Bgn_scdState    ltpGainHist[] = LTP gain history (Word16)    speech[] = synthesis speech frame (Word16)    voicedHangover = pointer to # of frames after last voiced frame (Word16)    pOverflow      = pointer to overflow indicator (Flag) Outputs:    st = function updates the state variables of type Bgn_scdState        pointed to by st.    voicedHangover = function updates the # of frames after last voiced        frame pointed to by voicedHangover.    pOverflow = 1 if the basic math function L_add() results in saturation.                  else pOverflow is zero. Returns:    inbgNoise = flag if background noise is present (Word16) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Characterize synthesis speech and detect background noise.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES bgnscd.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEWord16 Bgn_scd (Bgn_scdState *st,      // i : State variables for bgn SCD                Word16 ltpGainHist[],  // i : LTP gain history                Word16 speech[],       // o : synthesis speech frame                Word16 *voicedHangover // o : # of frames after last                                              voiced frame                ){   Word16 i;   Word16 prevVoiced, inbgNoise;   Word16 temp;   Word16 ltpLimit, frameEnergyMin;   Word16 currEnergy, noiseFloor, maxEnergy, maxEnergyLastPart;   Word32 s;   // Update the inBackgroundNoise flag (valid for use in next frame if BFI)   // it now works as a energy detector floating on top   // not as good as a VAD.   currEnergy = 0;   s = (Word32) 0;   for (i = 0; i < L_FRAME; i++)   {       s = L_mac (s, speech[i], speech[i]);   }   s = L_shl(s, 2);   currEnergy = extract_h (s);   frameEnergyMin = 32767;   for (i = 0; i < L_ENERGYHIST; i++)   {      if (sub(st->frameEnergyHist[i], frameEnergyMin) < 0)         frameEnergyMin = st->frameEnergyHist[i];   }   noiseFloor = shl (frameEnergyMin, 4); // Frame Energy Margin of 16   maxEnergy = st->frameEnergyHist[0];   for (i = 1; i < L_ENERGYHIST-4; i++)   {      if ( sub (maxEnergy, st->frameEnergyHist[i]) < 0)      {         maxEnergy = st->frameEnergyHist[i];

⌨️ 快捷键说明

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