📄 agc.cpp
字号:
/* ------------------------------------------------------------------ * 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/agc.c Funtions: energy_old energy_new agc_init agc_reset agc_exit agc agc2 Date: 03/28/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Fixed some problems with overflow and negative saturation. Description: Made changes based on comments from the review meeting. Removed more calls to L_shl in agc and agc2. Description: Synchronized code with the UMTS version 3.2.0. Updated Pseudo- code section on all functions to show the latest version of code that was optimized. Removed hard tabs. Updated to most current PV coding template. Description: Removed basic_op.h and replaced it with the header files of the math functions used by the file. Removed unnecessary include files. Description: Made the following changes per comments from Phase 2/3 review: 1. Changed FOR loops to count down. 2. Reordered IF statement to take advantage of branch prediction. 3. Declared one local variable per line. 4. Copied detailed function description of agc() from the header file. 5. Made minor cosmetic changes. 6. Fixed typecasting issue using a TI C compiler. Description: Made the following changes to make the library EPOC compatible. 1. energy_old(): Passed in pointer to overflow flag. Changed call to L_add() to include overflow flag. 2. energy_new(): Passed in pointer to overflow flag. Changed function calls to L_add() and energy_old() to include overflow flag. 3. agc(): Passed in pointer to overflow flag. Changed function calls to energy_new(), L_shl(), round(), L_shr(), Inv_sqrt(), mult(), add() and L_mult() to include overflow flag. 3. agc2(): Passed in pointer to overflow flag. Changed function calls to energy_new(), L_shl(), round(), L_shr(), Inv_sqrt(), mult(), add() and L_mult() to include overflow flag. Description: Added wrapper functions for energy_old() and energy_new() for access by unit tests. Description: Corrected return type for energy_old() and energy_new() wrapper functions. Removed unneeded header files. Cleaned up code. Description: Fixed bug found in the FOR loop calculation of gain[n] in agc(). Updated copyright year. Description: Removed the functions agc_init() and agc_exit(). The agc related structure is no longer dynamically allocated. Description: Updated Ouputs section for all functions. Description: Optimized agc() to reduce clock cycle usage. Updated copyright year and removed unused files in Include section. Description: Changed function name to pv_round to avoid conflict with round function in C standard library. Description: Removed the usage of l_deposit_l(). Description:------------------------------------------------------------------------------ MODULE DESCRIPTION This set of modules scale the excitation level and output of the speech signals.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "agc.h"#include "cnst.h"#include "inv_sqrt.h"#include "basic_op.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: energy_old------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: in = input signal (Word16) l_trm = input signal length (Word16) pOverflow = address of overflow (Flag) Outputs: pOverflow -> 1 if the energy computation saturates Returns: s = return energy of signal (Word32) Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Returns the energy of the signal.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES agc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic Word32 energy_old( // o : return energy of signal Word16 in[], // i : input signal (length l_trm) Word16 l_trm // i : signal length){ Word32 s; Word16 i, temp; temp = shr (in[0], 2); s = L_mult (temp, temp); for (i = 1; i < l_trm; i++) { temp = shr (in[i], 2); s = L_mac (s, temp, temp); } return s;}------------------------------------------------------------------------------ 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 Word32 energy_old( /* o : return energy of signal */ Word16 in[], /* i : input signal (length l_trm) */ Word16 l_trm, /* i : signal length */ Flag *pOverflow /* overflow: flag to indicate overflow */){ Word32 s = 0; Word32 L_temp; Word16 i; Word16 temp; for (i = l_trm - 1; i >= 0; i--) { temp = in[i]; if (temp < 0) { temp = ~(~temp >> 2); } else { temp = temp >> 2; } L_temp = (((Word32) temp) * temp) << 1; s = L_add(s, L_temp, pOverflow); } return(s);}/*----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: energy_old__Wrapper------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: in = input signal (Word16) l_trm = input signal length (Word16) pOverflow = address of overflow (Flag) Outputs: pOverflow -> 1 if the energy computation saturates Returns: s = return energy of signal (Word32) Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function provides external access to the static function energy_old.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES None------------------------------------------------------------------------------ PSEUDO-CODE CALL energy_old ( in = in l_trm = l_trm pOverflow = pOverflow ) MODIFYING(nothing) RETURNING(energy_old_value = s)------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/Word32 energy_old_Wrapper(Word16 in[], Word16 l_trm, Flag *pOverflow){ Word32 energy_old_value; /*---------------------------------------------------------------------------- CALL energy_old ( in = in l_trm = l_trm pOverflow = pOverflow ) MODIFYING(nothing) RETURNING(energy_old_value = s) ----------------------------------------------------------------------------*/ energy_old_value = energy_old(in, l_trm, pOverflow); return(energy_old_value);}/*--------------------------------------------------------------------------*//*----------------------------------------------------------------------------- FUNCTION NAME: energy_new------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: in = input signal l_trm = input signal length pOverflow = address of overflow (Flag) Outputs: pOverflow -> 1 if the energy computation saturates Returns: s = return energy of signal Global Variables Used: None. Local Variables Needed: None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION Returns the energy of the signal.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -