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

📄 gc_pred.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ------------------------------------------------------------------ * 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/gc_pred.c Functions:            gc_pred_reset            gc_pred            gc_pred_update            gc_pred_average_limited     Date: 04/18/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Updated template used to PV coding template. First attempt at          optimizing C code. Description: Updated file per comments gathered from Phase 2/3 review. Description: Added setting of Overflow flag in inlined code. Description: Fixed bug in gc_pred that causes it to not be bit-exact with              the original version. This was done by adding code that sign-              extends the means_ener value. Fixed tabs all over the code              and deleted all calls to test function in gc_pred. Description: Synchronized file with UMTS version 3.2.0. Updated coding              template. Removed unnecessary include files. Description: Replace basic_op.h and oper_32b.h with the header files of the              math functions used in the file. Fixed typecasting issue with              TI compiler. Description: Fixed more typecasting issue with TI C Compiler (per comments              from peer review). Description: Removed the functions gc_pred_init and gc_pred_exit. The gc_pred related structure is no longer dynamically allocated. Description: Adding pOverflow to the functions to remove global variables.              These changes are needed for the EPOC releases. Description:  For gc_pred() and gc_pred_copy()              1. Eliminated gc_pred_copy() (call replaced by memcpy).              2. Eliminated unused include files copy.h and typedef.h.              3. Replaced array addressing by pointers              4. Eliminated math operations that unnecessary checked for                 saturation, in some cases this by shifting before adding and                 in other cases by evaluating the operands              5. Unrolled loops to speed up processing Description:  Cleaned unused code Description:  Modified pointer update order in function gc_pred(). 			   Previous order was accepted by Vcpp by failed when using 			   ARM tools. Current order is correct for all platforms 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: Changed round function name to pv_round to avoid conflict with              round function in C standard library. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION This file contains the functions that perform codebook gain MA prediction.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "gc_pred.h"#include "basicop_malloc.h"#include "basic_op.h"#include "cnst.h"#include "log2.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*/#define NPRED 4  /* number of prediction taps *//* average innovation energy.                               *//* MEAN_ENER  = 36.0/constant, constant = 20*Log10(2)       */#define MEAN_ENER_MR122  783741L  /* 36/(20*log10(2)) (Q17) *//* minimum quantized energy: -14 dB */#define MIN_ENERGY       -14336       /* 14                 Q10 */#define MIN_ENERGY_MR122  -2381       /* 14 / (20*log10(2)) Q10 *//*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//* MA prediction coefficients (Q13) */static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556};/* MA prediction coefficients (Q6)  */static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12};/*------------------------------------------------------------------------------ FUNCTION NAME: gc_pred_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a structure of type gc_predState Outputs:    past_qua_en field in the structure pointed to by state is initialized      to MIN_ENERGY    past_qua_en_MR122 field in the structure pointed to by state is      initialized to MIN_ENERGY_MR122 Returns:    return_value = 0, if reset was successful; -1, otherwise (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function initializes the state memory used by gc_pred to zero.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint gc_pred_reset (gc_predState *state){   Word16 i;   if (state == (gc_predState *) NULL){      fprintf(stderr, "gc_pred_reset: invalid parameter\n");      return -1;   }   for(i = 0; i < NPRED; i++)   {      state->past_qua_en[i] = MIN_ENERGY;      state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;   }  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 gc_pred_reset(gc_predState *state){    Word16 i;    if (state == (gc_predState *) NULL)    {        /* fprintf(stderr, "gc_pred_reset: invalid parameter\n"); */        return -1;    }    for (i = 0; i < NPRED; i++)    {        state->past_qua_en[i] = MIN_ENERGY;        state->past_qua_en_MR122[i] = MIN_ENERGY_MR122;    }    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: gc_pred------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type gc_predState    mode = AMR mode (enum Mode)    code = pointer to the innovative codebook vector; Q12 in MR122 mode,           otherwise, Q13 (Word16)    exp_gcode0 = pointer to the exponent part of predicted gain factor             (Q0) (Word16)    frac_gcode0 = pointer to the fractional part of predicted gain factor              (Q15) (Word16)    exp_en = pointer to the exponent part of the innovation energy; this         is calculated for MR795 mode, Q0 (Word16)    frac_en = pointer to the fractional part of the innovation energy;          this is calculated for MR795 mode, Q15 (Word16)    pOverflow = pointer to overflow (Flag) Outputs:    store pointed to by exp_gcode0 contains the exponent part of the      recently calculated predicted gain factor    store pointed to by frac_gcode0 contains the fractional part of the      recently calculated predicted gain factor    store pointed to by exp_en contains the exponent part of the      recently calculated innovation energy    store pointed to by frac_en contains the fractional part of the      recently calculated innovation energy    pOverflow = 1 if the math functions called by gc_pred                results in overflow else zero. Returns:    None Global Variables Used:    None Local Variables Needed:    pred = table of MA prediction coefficients (Q13) (Word16)    pred_MR122 = table of MA prediction coefficients (Q6) (Word16)------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function performs the MA prediction of the innovation energy (in dB/(20*log10(2))), with the mean removed.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES gc_pred.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEThe original etsi reference code uses a global flag Overflow. However, in theactual implementation a pointer to a the overflow flag is passed in.voidgc_pred(    gc_predState *st,   // i/o: State struct    enum Mode mode,     // i  : AMR mode    Word16 *code,       // i  : innovative codebook vector (L_SUBFR)                        //      MR122: Q12, other modes: Q13    Word16 *exp_gcode0, // o  : exponent of predicted gain factor, Q0    Word16 *frac_gcode0,// o  : fraction of predicted gain factor  Q15    Word16 *exp_en,     // o  : exponent of innovation energy,     Q0                        //      (only calculated for MR795)    Word16 *frac_en     // o  : fraction of innovation energy,     Q15                        //      (only calculated for MR795)){    Word16 i;    Word32 ener_code;    Word16 exp, frac;     *-------------------------------------------------------------------*     *  energy of code:                                                  *     *  ~~~~~~~~~~~~~~~                                                  *     *  ener_code = sum(code[i]^2)                                       *     *-------------------------------------------------------------------*    ener_code = L_mac((Word32) 0, code[0], code[0]);                                                 // MR122:  Q12*Q12 -> Q25                                                 // others: Q13*Q13 -> Q27    for (i = 1; i < L_SUBFR; i++)        ener_code = L_mac(ener_code, code[i], code[i]);    if (sub (mode, MR122) == 0)    {        Word32 ener;        // ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20        ener_code = L_mult (pv_round (ener_code), 26214);   // Q9  * Q20 -> Q30         *-------------------------------------------------------------------*         *  energy of code:                                                  *         *  ~~~~~~~~~~~~~~~                                                  *         *  ener_code(Q17) = 10 * Log10(energy) / constant                   *         *                 = 1/2 * Log2(energy)                              *         *                                           constant = 20*Log10(2)  *         *-------------------------------------------------------------------*        // ener_code = 1/2 * Log2(ener_code); Note: Log2=log2+30        Log2(ener_code, &exp, &frac);        ener_code = L_Comp (sub (exp, 30), frac);     // Q16 for log()                                                    // ->Q17 for 1/2 log()         *-------------------------------------------------------------------*         *  predicted energy:                                                *

⌨️ 快捷键说明

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