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

📄 pitch_ol.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 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             : pitch_ol.c*      Purpose          : Compute the open loop pitch lag.**********************************************************************************//**********************************************************************************                         MODULE INCLUDE FILE AND VERSION ID*********************************************************************************/#include "pitch_ol.h"const char pitch_ol_id[] = "@(#)$Id $" pitch_ol_h;/**********************************************************************************                         INCLUDE FILES*********************************************************************************/#include <uclib.h>#include <uclib.h>#include "typedef.h"#include "basic_op.h"#include "oper_32b.h"#include "count.h"#include "cnst.h"#include "inv_sqrt.h"#include "vad.h"#include "calc_cor.h"#include "hp_max.h"//add for jzmedia accerative instruction sets#ifdef JZ4740_MXU_OPT#include "jzmedia.h"#endif /**********************************************************************************                         LOCAL VARIABLES AND TABLES*********************************************************************************/#define THRESHOLD 27853/**********************************************************************************                         LOCAL PROGRAM CODE*********************************************************************************//************************************************************************* * *  FUNCTION:  Lag_max * *  PURPOSE: Find the lag that has maximum correlation of scal_sig[] in a *           given delay range. * *  DESCRIPTION: *      The correlation is given by *           cor[t] = <scal_sig[n],scal_sig[n-t]>,  t=lag_min,...,lag_max *      The functions outputs the maximum correlation after normalization *      and the corresponding lag. * *************************************************************************/#ifdef VAD2static Word16 Lag_max ( /* o   : lag found                               */    Word32 corr[],      /* i   : correlation vector.                     */    Word16 scal_sig[],  /* i   : scaled signal.                          */        Word16 scal_fac,    /* i   : scaled signal factor.                   */    Word16 scal_flag,   /* i   : if 1 use EFR compatible scaling         */    Word16 L_frame,     /* i   : length of frame to compute pitch        */    Word16 lag_max,     /* i   : maximum lag                             */    Word16 lag_min,     /* i   : minimum lag                             */    Word16 *cor_max,    /* o   : normalized correlation of selected lag  */    Word32 *rmax,       /* o   : max(<s[i]*s[j]>)                        */    Word32 *r0,         /* o   : residual energy                         */    Flag dtx            /* i   : dtx flag; use dtx=1, do not use dtx=0   */    )#elsestatic Word16 Lag_max ( /* o   : lag found                               */    vadState *vadSt,    /* i/o : VAD state struct                        */    Word32 corr[],      /* i   : correlation vector.                     */    Word16 scal_sig[],  /* i   : scaled signal.                          */        Word16 scal_fac,    /* i   : scaled signal factor.                   */    Word16 scal_flag,   /* i   : if 1 use EFR compatible scaling         */    Word16 L_frame,     /* i   : length of frame to compute pitch        */    Word16 lag_max,     /* i   : maximum lag                             */    Word16 lag_min,     /* i   : minimum lag                             */    Word16 *cor_max,    /* o   : normalized correlation of selected lag  */    Flag dtx            /* i   : dtx flag; use dtx=1, do not use dtx=0   */    )#endif{    Word16 i, j;    Word16 *p;    Word32 max, t0;    Word16 max_h, max_l, ener_h, ener_l;    Word16 p_max = 0; /* initialization only needed to keep gcc silent */        max = MIN_32;               //move32 ();     p_max = lag_max;            //move16 ();       for (i = lag_max, j = (PIT_MAX-lag_max-1); i >= lag_min; i--, j--)      {       //test ();         if (L_sub (corr[-i], max) >= 0)        {           max = corr[-i];       //move32 ();            p_max = i;            //move16 ();         }     }        /* compute energy */    t0 = 0;                     //move32 ();     #ifdef JZ4740_MXU_OPT#define  ADD_MASK 0xFFFFFFFC#define  REF_MASK 0x03    Word32 ref1, ref2;       p = (unsigned int) (scal_sig - p_max) & ADD_MASK;       ref1 = 4 - (unsigned int)(scal_sig - p_max) & REF_MASK;       S32LDD(xr10, p, 0x00);       Q16SLL(xr12, xr0,xr0,xr13,0);  // t0 = 0;       for(j = 0; j < L_frame / 2; j++){          S32LDI(xr1, p, 0x04);          S32ALN(xr2, xr10, xr1, ref1);          Q16SLL(xr10,xr1,xr0,xr0,0);          D16MAC_AA_WW(xr12,xr2,xr2,xr13);        }        Q16SLL(xr1, xr12,xr13,xr2,1);        D32ADD_AA(xr3,xr1,xr2,xr0);        t0 = S32M2I(xr3);#else    p = &scal_sig[-p_max];      //move16 ();     for (i = 0; i < L_frame; i++, p++)    {        t0 = L_mac (t0, *p, *p);    }#endif    /* 1/sqrt(energy) */    if (dtx)    {  /* no test() call since this if is only in simulation env */#ifdef VAD2       *rmax = max;		//move32();       *r0 = t0;		//move32();#else       /* check tone */       vad_tone_detection (vadSt, max, t0);#endif    }        t0 = Inv_sqrt (t0); //move32 (); /* function result */    //test();    if (scal_flag)    {       t0 = L_shl (t0, 1);    }        /* max = max/sqrt(energy)  */    L_Extract (max, &max_h, &max_l);    L_Extract (t0, &ener_h, &ener_l);    t0 = Mpy_32 (max_h, max_l, ener_h, ener_l);        //test();    if (scal_flag)    {      t0 = L_shr (t0, scal_fac);      *cor_max = extract_h (L_shl (t0, 15)); /* divide by 2 */    }    else    {      *cor_max = extract_l(t0);    }    return (p_max);}/**********************************************************************************                         PUBLIC PROGRAM CODE*********************************************************************************//************************************************************************* * *  FUNCTION:  Pitch_ol * *  PURPOSE: Compute the open loop pitch lag. * *  DESCRIPTION: *      The open-loop pitch lag is determined based on the perceptually *      weighted speech signal. This is done in the following steps: *        - find three maxima of the correlation <sw[n],sw[n-T]>, *          dividing the search range into three parts: *               pit_min ... 2*pit_min-1 *             2*pit_min ... 4*pit_min-1 *             4*pit_min ...   pit_max *        - divide each maximum by <sw[n-t], sw[n-t]> where t is the delay at *          that maximum correlation. *        - select the delay of maximum normalized correlation (among the *          three candidates) while favoring the lower delay ranges. * *************************************************************************/Word16 Pitch_ol (      /* o   : open loop pitch lag                         */    vadState *vadSt,   /* i/o : VAD state struct                            */    enum Mode mode,    /* i   : coder mode                                  */    Word16 signal[],   /* i   : signal used to compute the open loop pitch  */                       /*    signal[-pit_max] to signal[-1] should be known */    Word16 pit_min,    /* i   : minimum pitch lag                           */    Word16 pit_max,    /* i   : maximum pitch lag                           */    Word16 L_frame,    /* i   : length of frame to compute pitch            */    Word16 idx,        /* i   : frame index                                 */    Flag dtx           /* i   : dtx flag; use dtx=1, do not use dtx=0       */    )

⌨️ 快捷键说明

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