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

📄 phi_xits.c

📁 C写的MPEG4音频源代码(G.723/G.729)
💻 C
📖 第 1 页 / 共 3 页
字号:
/*====================================================================*//*         MPEG-4 Audio (ISO/IEC 14496-3) Copyright Header            *//*====================================================================*//*This software module was originally developed by Rakesh Taori and AndyGerrits (Philips Research Laboratories, Eindhoven, The Netherlands) inthe course of development of the MPEG-4 Audio (ISO/IEC 14496-3). Thissoftware module is an implementation of a part of one or more MPEG-4Audio (ISO/IEC 14496-3) tools as specified by the MPEG-4 Audio(ISO/IEC 14496-3). ISO/IEC gives users of the MPEG-4 Audio (ISO/IEC14496-3) free license to this software module or modifications thereoffor use in hardware or software products claiming conformance to theMPEG-4 Audio (ISO/IEC 14496-3). Those intending to use this softwaremodule in hardware or software products are advised that its use mayinfringe existing patents. The original developer of this softwaremodule and his/her company, the subsequent editors and theircompanies, and ISO/IEC have no liability for use of this softwaremodule or modifications thereof in an implementation. Copyright is notreleased for non MPEG-4 Audio (ISO/IEC 14496-3) conforming products.CN1 retains full right to use the code for his/her own purpose, assignor donate the code to a third party and to inhibit third parties fromusing the code for non MPEG-4 Audio (ISO/IEC 14496-3) conformingproducts.  This copyright notice must be included in all copies orderivative works. Copyright 1996.*//*====================================================================*//*======================================================================*//*                                                                      *//*      SOURCE_FILE:    PHI_XITS.C                                      *//*      PACKAGE:        WDBxx                                           *//*      COMPONENT:      Subroutines for Excitation Modules              *//*                                                                      *//*======================================================================*//*======================================================================*//*      I N C L U D E S                                                 *//*======================================================================*/#include <stdio.h>#include <stdlib.h>#include <math.h>#include <malloc.h>#include <float.h>#include <assert.h>#include "phi_excq.h"#include "phi_xits.h"/*======================================================================*//* Function Definition:  perceptual_weighting                           *//*======================================================================*/void PHI_perceptual_weighting(long  nos,              /* In:     Number of samples to be processed    */float *vi,              /* In:     Array of input samps to be processe  */float *vo,              /* Out:    Perceptually Weighted Output Speech  */ long  order,            /* In:     LPC-Order of the weighting filter    */ float *a_gamma,         /* In:     Array of the Weighting filter coeffs */float *vp1              /* In/Out: The delay line states                */){    int i, j;           /* Local: Loop indices                          */    for (i = 0; i < (int)nos; i ++)    {        register float temp_vo = vi[i];                for (j = 0; j < (int)order; j ++)        {            temp_vo += (vp1[j] * a_gamma[j]);        }        vo[i] = temp_vo;        for (j = (int)order - 1; j > 0; j --)        {            vp1[j] = vp1[j - 1];        }        vp1[0] = vo[i];    }    return;}/*------------------------------------------------------------------------  zero input response ------------------------------------------------------------------------*/void PHI_calc_zero_input_response(long  nos,               /* In:     Number of samples to be processed   */float *vo,               /* Out:    The zero-input response             */ long  order,             /* In:     Order of the Weighting filter       */float *a_gamma,          /* In:     Coefficients of the weighting filter*/float *vp                /* In:     Filter states                       */){    float *vpp;         /* Local: To copy the filter states             */    int i, j;           /* Local: Loop indices                          */    /*==================================================================*/    /* Allocate temp states                                             */    /*==================================================================*/    if ((vpp = (float *)malloc((unsigned int)order * sizeof(float))) == NULL )    {       fprintf(stderr, "\n Malloc Failure in Block: Excitation Analysis \n");       exit(1);    }      /*==================================================================*/    /* Initiallise temp states                                          */    /*==================================================================*/    for (i = 0; i < (int)order; i ++)    {        vpp[i] = vp[i];    }            /*==================================================================*/    /* Compute zero-input response                                      */    /*==================================================================*/    for (i = 0; i < (int)nos; i ++)    {        register float temp_vo = (float)0.0;                for (j = 0; j < (int)order; j ++)        {            temp_vo += a_gamma[j] * vpp[j];        }        vo[i] = temp_vo;        for (j =(int)order  - 1; j > 0; j --)        {            vpp[j] = vpp[j - 1];        }        vpp[0] = vo[i];    }        /*==================================================================*/    /* Free temp states                                                 */    /*==================================================================*/    free(vpp);        return;}/*----------------------------------------------------------------------------  weighted target signal----------------------------------------------------------------------------*/void PHI_calc_weighted_target(long nos,               /* In:     Number of samples to be processed    */float *v1,              /* In:     Array of Perceptually weighted speech*/ float *v2,              /* In:     The zero-input response              */ float *vd               /* Out:    Real Target signal for current frame */){    int i;              /* Local:  Loop index                           */    for (i = 0; i < (int)nos; i ++)        vd[i] = v1[i] - v2[i];    return;}/*----------------------------------------------------------------------------  impulse response----------------------------------------------------------------------------*/void PHI_calc_impulse_response(long  nos,              /* In:     Number of samples to be processed    */float *h,               /* Out:    Impulse response of the filter       */long  order,            /* In:     Order of the filter                  */ float *a_gamma          /* In:     Array of the filter coefficients     */){    float *vpp;         /* Local: Local filter states                   */    int i, j;           /* Local: Loop indices                          */    /*==================================================================*/    /* Allocate temp states                                             */    /*==================================================================*/    if ((vpp = (float *)malloc((unsigned int)order * sizeof(float)))== NULL )    {       fprintf(stderr, "\n Malloc Failure in Block:Excitation Anlaysis \n");       exit(1);    }      /*==================================================================*/    /* Initiallise temp states                                          */    /*==================================================================*/    for (i = 0; i < (int)order; i ++)    {        vpp[i] = (float)0.0;    }    h[0] = (float)1.0;    for (i = 1; i < (int)nos; i ++)        h[i] = (float)0.0;    /*==================================================================*/    /* Compute Impulse response                                         */    /*==================================================================*/    for (i = 0; i < (int)nos; i ++)    {        register float temp_h = h[i];                for (j = 0; j < (int)order; j ++)        {            temp_h += a_gamma[j] * vpp[j];        }        h[i] = temp_h;        for (j = (int)order - 1; j > 0; j --)        {            vpp[j] = vpp[j - 1];        }        vpp[0] = h[i];    }        /*==================================================================*/    /* Free temp states                                                 */    /*==================================================================*/    free(vpp);        return;}/*------------------------------------------------------------------------  backward filtering ------------------------------------------------------------------------*/void PHI_backward_filtering(long  nos,              /* In:     Number of samples to be processed    */float *vi,              /* In:     Array of samples to be filtered      */ float *vo,              /* Out:    Array of filtered samples            */ float *h                /* In:     The filter coefficients              */){    int i, j;           /* Local:  Loop indices                         */    for (i = 0; i < (int)nos; i ++)    {        register float temp_vo = (float)0.0;                for (j = 0; j <= i; j ++)        {            temp_vo += h[i - j] * vi[(int)nos - 1 - j];        }        vo[(int)nos - 1 - i] = temp_vo;    }    return;}/*----------------------------------------------------------------------------  adaptive codebook search----------------------------------------------------------------------------*/void PHI_cba_search(long   nos,             /* In:     Number of samples to be processed    */long   max_lag,         /* In:     Maximum Permitted Adapt cbk Lag      */long   min_lag,         /* In:     Minimum Permitted Adapt cbk Lag      */float  *cb,             /* In:     Segment of Adaptive Codebook         */long   *pi,             /* In:     Array of preselected-lag indices     */long   n_lags,          /* In:     Number of lag candidates to be tried */float  *h,              /* In:     Impulse response of synthesis filter */ float  *t,              /* In:     The real target signal               */ float  *g,              /* Out:    Adapt-cbk gain(Quantised but uncoded)*/long   *vid,            /* Out:    The final adaptive cbk lag index     */ long   *gid             /* Out:    The gain index                       */){    float *y, *yp;             float num, den;                 float rs, r;    int   ks;    int   i, j, k;    int   m = 0;    int   prevm;    /*==================================================================*/    /* Allocate temp states                                             */    /*==================================================================*/    if ( ((y = (float *)malloc((unsigned int)nos * sizeof(float))) == NULL )||         ((yp = (float *)malloc((unsigned int)nos * sizeof(float))) == NULL ))    {       fprintf(stderr, "\n Malloc Failure in Block: Excitation Anlaysis \n");       exit(1);    }    rs = -FLT_MAX;    /*==================================================================*/    /* Codebook Vector Search                                           */    /*==================================================================*/    for (k = 0; k < (int)n_lags; k ++)    {        int end_correction;                /* =============================================================*/        /* Compute Lag index                                            */        /* =============================================================*/        prevm = m;        m = (int)(max_lag - min_lag - pi[k]);                /* =============================================================*/        /* Check if we can use end_correction                           */        /* =============================================================*/        if ( (k > 0) && (( prevm - m ) == 1))        {            end_correction = 1;        }        else        {            end_correction = 0;        }        /* =============================================================*/        /* If end_correction can be used, use complexity reduced method */        /* =============================================================*/        if (end_correction)        {            y[0] = h[0] * cb[m];            for (i = 1; i < (int)nos; i ++)            {                y[i] = yp[i - 1] + h[i] * cb[m];            }        }        else        {            for (i = 0; i < (int)nos; i ++)            {                register float temp_y = (float)0.0;                for (j = 0; j <= i; j ++)                {                    temp_y += h[i - j] * cb[m + j];                }                    y[i] = temp_y;            }        }                /* =============================================================*/        /* Copy the current to y to previous y (for the next iteration) */        /* =============================================================*/        for (i = 0; i < (int)nos; i ++)        {            yp[i] = y[i];        }        /* =============================================================*/        /* Compute normalised cross correlation coefficient             */        /* =============================================================*/        num = (float)0.0;        den = FLT_MIN;        for (i = 0; i < (int)nos; i ++)        {            num += t[i] * y[i];

⌨️ 快捷键说明

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