📄 c8_31pf.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/c8_31pf.c Functions: Date: 05/26/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Modified to pass overflow flag through to basic math function. The flag is passed back to the calling function by pointer reference. Description: Optimized file to reduce clock cycle usage. Updated copyright year. Removed unnecessary include files and unused #defines. Description: Changed round function name to pv_round to avoid conflict with round function in C standard library. Description: Replaced "int" and/or "char" with OSCL defined types. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION Purpose : Searches a 31 bit algebraic codebook containing : 8 pulses in a frame of 40 samples. : in the same manner as GSM-EFR------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "c8_31pf.h"#include "typedef.h"#include "cnst.h"#include "inv_sqrt.h"#include "cor_h.h"#include "cor_h_x2.h"#include "set_sign.h"#include "s10_8pf.h"#include "basic_op.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*/#define NB_PULSE 8/* define values/representation for output codevector and sign */#define POS_CODE 8191#define NEG_CODE 8191#define POS_SIGN 32767#define NEG_SIGN (Word16) (-32768L)/*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES; Declare variables used in this module but defined elsewhere----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME:------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: codvec[] Array of type Word16 -- position of pulses sign[] Array of type Word16 -- sign of pulses h[] Array of type Word16 -- impulse response of weighted synthesis filter Outputs: cod[] Array of type Word16 -- innovative code vector y[] Array of type Word16 -- filtered innovative code sign_indx[] Array of type Word16 -- signs of 4 pulses (signs only) pos_indx[] Array of type Word16 -- position index of 8 pulses(position only) pOverflow Pointer to Flag -- set when overflow occurs Returns: indx Global Variables Used: None Local Variables Needed:------------------------------------------------------------------------------ FUNCTION DESCRIPTION------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES [1] c8_31pf.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]------------------------------------------------------------------------------*//************************************************************************* * * FUNCTION: build_code() * * PURPOSE: Builds the codeword, the filtered codeword and a * linear uncombined version of the index of the * codevector, based on the signs and positions of 8 pulses. * *************************************************************************/static void build_code( Word16 codvec[], /* i : position of pulses */ Word16 sign[], /* i : sign of d[n] */ Word16 cod[], /* o : innovative code vector */ Word16 h[], /* i : impulse response of weighted synthesis filter*/ Word16 y[], /* o : filtered innovative code */ Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */ Word16 pos_indx[], /* o : position index of 8 pulses(position only) */ Flag * pOverflow /* o : Flag set when overflow occurs */){ Word16 i; Word16 j; Word16 k; Word16 track; Word16 sign_index; Word16 pos_index; Word16 _sign[NB_PULSE]; Word16 *p0; Word16 *p1; Word16 *p2; Word16 *p3; Word16 *p4; Word16 *p5; Word16 *p6; Word16 *p7; Word16 *p_cod = &cod[0]; Word16 *p_codvec = &codvec[0]; Word32 s; for (i = 0; i < L_CODE; i++) { *(p_cod++) = 0; } for (i = 0; i < NB_TRACK_MR102; i++) { pos_indx[i] = -1; sign_indx[i] = -1; } for (k = 0; k < NB_PULSE; k++) { /* read pulse position */ i = codvec[k]; /* read sign */ j = sign[i]; pos_index = i >> 2; /* index = pos/4 */ track = i & 3; /* track = pos%4 */ if (j > 0) { cod[i] = (Word16)((Word32) cod[i] + POS_CODE); _sign[k] = POS_SIGN; sign_index = 0; /* bit=0 -> positive pulse */ } else { cod[i] = (Word16)((Word32) cod[i] - NEG_CODE); _sign[k] = NEG_SIGN; sign_index = 1; /* bit=1 => negative pulse */ /* index = add (index, 8); 1 = negative old code */ } if (pos_indx[track] < 0) { /* first set first NB_TRACK pulses */ pos_indx[track] = pos_index; sign_indx[track] = sign_index; } else { /* 2nd row of pulses , test if positions needs to be switched */ if (((sign_index ^ sign_indx[track]) & 1) == 0) { /* sign of 1st pulse == sign of 2nd pulse */ if (pos_indx[track] <= pos_index) { /* no swap */ pos_indx[track + NB_TRACK_MR102] = pos_index; } else { /* swap*/ pos_indx[track + NB_TRACK_MR102] = pos_indx[track]; pos_indx[track] = pos_index; sign_indx[track] = sign_index; } } else { /* sign of 1st pulse != sign of 2nd pulse */ if (pos_indx[track] <= pos_index) { /*swap*/ pos_indx[track + NB_TRACK_MR102] = pos_indx[track]; pos_indx[track] = pos_index; sign_indx[track] = sign_index; } else { /*no swap */ pos_indx[track + NB_TRACK_MR102] = pos_index; } } } } p0 = h - *(p_codvec++); p1 = h - *(p_codvec++); p2 = h - *(p_codvec++); p3 = h - *(p_codvec++); p4 = h - *(p_codvec++); p5 = h - *(p_codvec++); p6 = h - *(p_codvec++); p7 = h - *(p_codvec); for (i = 0; i < L_CODE; i++) { s = 0; s = L_mac( s, *p0++, _sign[0], pOverflow); s = L_mac( s, *p1++, _sign[1], pOverflow); s = L_mac( s, *p2++, _sign[2], pOverflow); s = L_mac( s, *p3++, _sign[3], pOverflow); s = L_mac( s, *p4++, _sign[4], pOverflow); s = L_mac( s, *p5++, _sign[5], pOverflow); s = L_mac( s, *p6++, _sign[6], pOverflow); s = L_mac( s, *p7++, _sign[7], pOverflow); y[i] = pv_round( s, pOverflow); } /* for (i = 0; i < L_CODE; i++) */} /* build_code *//****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: compress_code()------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: Outputs: Returns: None Global Variables Used: None Local Variables Needed:------------------------------------------------------------------------------ FUNCTION DESCRIPTION FUNCTION: PURPOSE: compression of three indeces [0..9] to one 10 bit index minimizing the phase shift of a bit error.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES [1] c8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -