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

📄 gc_pred.c

📁 arm音频编解码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************      GSM AMR-NB speech codec   R98   Version 7.6.0   December 12, 2001*                                R99   Version 3.3.0                *                                REL-4 Version 4.1.0                ********************************************************************************      File             : gc_pred.c*      Purpose          : codebook gain MA prediction*******************************************************************************//*******************************************************************************                         MODULE INCLUDE FILE AND VERSION ID******************************************************************************/#include "gc_pred.h"const char gc_pred_id[] = "@(#)$Id $" gc_pred_h;/*******************************************************************************                         INCLUDE FILES******************************************************************************/#include <stdio.h>#include <stdlib.h>#include "typedef.h"#include "basic_op.h"#include "oper_32b.h"#include "cnst.h"#include "count.h"#include "log2.h"#include "copy.h"/*******************************************************************************                         LOCAL VARIABLES AND TABLES******************************************************************************/#define NPRED 4  /* number of prediction taps *//* MA prediction coefficients (Q13) */static const Word16 pred[NPRED] = {5571, 4751, 2785, 1556};/* average innovation energy.                               *//* MEAN_ENER  = 36.0/constant, constant = 20*Log10(2)       */#define MEAN_ENER_MR122  783741L  /* 36/(20*log10(2)) (Q17) *//* MA prediction coefficients (Q6)  */static const Word16 pred_MR122[NPRED] = {44, 37, 22, 12};/* minimum quantized energy: -14 dB */#define MIN_ENERGY       -14336       /* 14                 Q10 */#define MIN_ENERGY_MR122  -2381       /* 14 / (20*log10(2)) Q10 */ /*******************************************************************************                         PUBLIC PROGRAM CODE******************************************************************************//***************************************************************************  Function:   qua_gain_init*  Purpose:    Allocates state memory and initializes state memory****************************************************************************/int gc_pred_init (gc_predState **state){  gc_predState* s;  if (state == (gc_predState **) NULL){      fprintf(stderr, "gc_pred_init: invalid parameter\n");      return -1;  }  *state = NULL;  /* allocate memory */  if ((s= (gc_predState *) malloc(sizeof(gc_predState))) == NULL){      fprintf(stderr, "gc_pred_init: can not malloc state structure\n");      return -1;  }  gc_pred_reset(s);  *state = s;  return 0;}/***************************************************************************  Function:   gc_pred_reset*  Purpose:    Initializes state memory to zero****************************************************************************/int 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:   gc_pred_exit*  Purpose:    The memory used for state memory is freed****************************************************************************/void gc_pred_exit (gc_predState **state){  if (state == NULL || *state == NULL)      return;  /* deallocate memory */  free(*state);  *state = NULL;  return;}/************************************************************************* * * FUNCTION:  gc_pred_copy() * * PURPOSE: Copy MA predictor state variable * *************************************************************************/voidgc_pred_copy(    gc_predState *st_src,  /* i : State struct                           */    gc_predState *st_dest  /* o : State struct                           */){    Copy (st_src->past_qua_en, st_dest->past_qua_en, NPRED);    Copy (st_src->past_qua_en_MR122, st_dest->past_qua_en_MR122, NPRED);}/************************************************************************* * * FUNCTION:  gc_pred() * * PURPOSE: MA prediction of the innovation energy *          (in dB/(20*log10(2))) with mean  removed). * *************************************************************************/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]);        test ();    if (sub (mode, MR122) == 0)    {        Word32 ener;        /* ener_code = ener_code / lcode; lcode = 40; 1/40 = 26214 Q20       */        ener_code = L_mult (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:                                                *         *  ~~~~~~~~~~~~~~~~~                                                *         *  ener(Q24) = (Emean + sum{pred[i]*past_en[i]})/constant           *         *            = MEAN_ENER + sum(pred[i]*past_qua_en[i])              *         *                                           constant = 20*Log10(2)  *         *-------------------------------------------------------------------*/

⌨️ 快捷键说明

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