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

📄 vad1.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/vad1.c Functions:     Date: 02/04/2002------------------------------------------------------------------------------ REVISION HISTORY Description: Updated template used to PV coding template. Changed to accept the pOverflow flag for EPOC compatibility. Description: Made changes per review comments (1) Removed include of "count.h" (2) Replaced "basic_op.h" with individual include files (3) Removed some unnecessary instances of sub(). 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: Changed round function name to pv_round to avoid conflict with              round function in C standard library. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "vad.h"#include "typedef.h"#include "shr.h"#include "basic_op.h"#include "cnst_vad.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: first_filter_stage------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    data -- array of type Word16 -- filter memory    in   -- array of type Word16 -- input signal Outputs:    data -- array of type Word16 -- filter memory    out  -- array of type Word16 -- output values, every other                                    output is low-pass part and                                    other is high-pass part every    pOverflow -- pointer to type Flag -- overflow indicator Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose      : Scale input down by one bit. Calculate 5th order                half-band lowpass/highpass filter pair with                decimation.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/static void first_filter_stage(    Word16 in[],      /* i   : input signal                  */    Word16 out[],     /* o   : output values, every other    */    /*       output is low-pass part and   */    /*       other is high-pass part every */    Word16 data[],    /* i/o : filter memory                 */    Flag  *pOverflow  /* o : Flag set when overflow occurs   */){    Word16 temp0;    Word16 temp1;    Word16 temp2;    Word16 temp3;    Word16 i;    Word16 data0;    Word16 data1;    data0 = data[0];    data1 = data[1];    for (i = 0; i < FRAME_LEN / 4; i++)    {        temp0 = mult(COEFF5_1, data0, pOverflow);        temp1 = shr(in[4*i+0], 2, pOverflow);        temp0 = sub(temp1, temp0, pOverflow);        temp1 = mult(COEFF5_1, temp0, pOverflow);        temp1 = add(data0, temp1, pOverflow);        temp3 = mult(COEFF5_2, data1, pOverflow);        temp2 = shr(in[4*i+1], 2, pOverflow);        temp3 = sub(temp2, temp3, pOverflow);        temp2 = mult(COEFF5_2, temp3, pOverflow);        temp2 = add(data1, temp2, pOverflow);        out[4*i+0] = add(temp1, temp2, pOverflow);        out[4*i+1] = sub(temp1, temp2, pOverflow);        temp1 = mult(COEFF5_1, temp0, pOverflow);        temp2 = shr(in[4*i+2], 2, pOverflow);        data0 = sub(temp2, temp1, pOverflow);        temp1 = mult(COEFF5_1, data0, pOverflow);        temp1 = add(temp0, temp1, pOverflow);        data1 = mult(COEFF5_2, temp3, pOverflow);        temp2 = shr(in[4*i+3], 2, pOverflow);        data1 = sub(temp2, data1, pOverflow);        temp2 = mult(COEFF5_2, data1, pOverflow);        temp2 = add(temp3, temp2, pOverflow);        out[4*i+2] = add(temp1, temp2, pOverflow);        out[4*i+3] = sub(temp1, temp2, pOverflow);    }    data[0] = data0;    data[1] = data1;}/*------------------------------------------------------------------------------ FUNCTION NAME: filter5------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    in0 -- array of type Word16 -- input values; output low-pass part    in1 -- array of type Word16 -- input values; output high-pass part    data -- array of type Word16 -- updated filter memory Outputs:    in0 -- array of type Word16 -- input values; output low-pass part    in1 -- array of type Word16 -- input values; output high-pass part    data -- array of type Word16 -- updated filter memory    pOverflow -- pointer to type Flag -- overflow indicator Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose      : Fifth-order half-band lowpass/highpass filter pair with                decimation.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/static void filter5(Word16 *in0,    /* i/o : input values; output low-pass part  */                    Word16 *in1,    /* i/o : input values; output high-pass part */                    Word16 data[],  /* i/o : updated filter memory               */                    Flag  *pOverflow  /* o : Flag set when overflow occurs       */                   ){    Word16 temp0;    Word16 temp1;    Word16 temp2;    temp0 = mult(COEFF5_1, data[0], pOverflow);    temp0 = sub(*in0, temp0, pOverflow);    temp1 = mult(COEFF5_1, temp0, pOverflow);    temp1 = add(data[0], temp1, pOverflow);    data[0] = temp0;    temp0 = mult(COEFF5_2, data[1], pOverflow);    temp0 = sub(*in1, temp0, pOverflow);    temp2 = mult(COEFF5_2, temp0, pOverflow);    temp2 = add(data[1], temp2, pOverflow);    data[1] = temp0;    temp0 = add(temp1, temp2, pOverflow);    *in0 = shr(temp0, 1, pOverflow);    temp0 = sub(temp1, temp2, pOverflow);    *in1 = shr(temp0, 1, pOverflow);}/*------------------------------------------------------------------------------ FUNCTION NAME: filter3------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    in0 -- array of type Word16 -- input values; output low-pass part    in1 -- array of type Word16 -- input values; output high-pass part    data -- array of type Word16 -- updated filter memory Outputs:    in0 -- array of type Word16 -- input values; output low-pass part    in1 -- array of type Word16 -- input values; output high-pass part    data -- array of type Word16 -- updated filter memory    pOverflow -- pointer to type Flag -- overflow indicator Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose      : Third-order half-band lowpass/highpass filter pair with                decimation.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/static void filter3(    Word16 *in0,      /* i/o : input values; output low-pass part  */    Word16 *in1,      /* i/o : input values; output high-pass part */    Word16 *data,     /* i/o : updated filter memory               */    Flag  *pOverflow  /* o : Flag set when overflow occurs         */){    Word16 temp1;    Word16 temp2;    temp1 = mult(COEFF3, *data, pOverflow);    temp1 = sub(*in1, temp1, pOverflow);    temp2 = mult(COEFF3, temp1, pOverflow);    temp2 = add(*data, temp2, pOverflow);    *data = temp1;    temp1 = sub(*in0, temp2, pOverflow);    *in1 = shr(temp1, 1, pOverflow);    temp1 = add(*in0, temp2, pOverflow);    *in0 = shr(temp1, 1, pOverflow);}/*------------------------------------------------------------------------------ FUNCTION NAME: level_calculation------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    data -- array of type Word16 -- signal buffer    sub_level -- pointer to type Word16 -- level calculated at the end of                                           the previous frame    count1 -- Word16 -- number of samples to be counted    count2 -- Word16 -- number of samples to be counted

⌨️ 快捷键说明

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