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

📄 c2_9pf.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/c2_9pf.c Funtions: code_2i40_9bits           search_2i40           Test_search_2i40           build_code           Test_build_code     Date: 05/26/2000------------------------------------------------------------------------------ REVISION HISTORY Description: Changed 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: Synchronized file with UMTS version 3.2.0. Updated coding              template. Description: Replaced basic_op.h with the header files of the math functions              used by the file. Description: Made the following changes per comments from Phase 2/3 review:              1. Defined one local variable per line. Description: Passed in pOverflow flag for EPOC compatibility. Description: Optimized search_2i40() to reduce clock cycle usage. Description: Removed unnecessary include files and #defines. Description: Changed 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: Added #ifdef __cplusplus around extern'ed table. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION This file contains the functions that search a 9 bit algebraic codebook containing 2 pulses in a frame of 40 samples.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "c2_9pf.h"#include "typedef.h"#include "basic_op.h"#include "inv_sqrt.h"#include "cnst.h"#include "cor_h.h"#include "cor_h_x.h"#include "set_sign.h"/*--------------------------------------------------------------------------*/#ifdef __cplusplusextern "C"{#endif    /*----------------------------------------------------------------------------    ; MACROS    ; Define module specific macros here    ----------------------------------------------------------------------------*/    /*----------------------------------------------------------------------------    ; DEFINES    ; Include all pre-processor statements here. Include conditional    ; compile variables also.    ----------------------------------------------------------------------------*/#define NB_PULSE  2    /*----------------------------------------------------------------------------    ; LOCAL FUNCTION DEFINITIONS    ; Function Prototype declaration    ----------------------------------------------------------------------------*/    static void search_2i40(        Word16 subNr,       /* i : subframe number                               */        Word16 dn[],        /* i : correlation between target and h[]            */        Word16 rr[][L_CODE],/* i : matrix of autocorrelation                     */        Word16 codvec[],    /* o : algebraic codebook vector                     */        Flag   * pOverflow  /* o : Flag set when overflow occurs                 */    );    static Word16 build_code(        Word16 subNr,       /* i : subframe number                               */        Word16 codvec[],    /* i : algebraic codebook vector                     */        Word16 dn_sign[],   /* i : sign of dn[]                                  */        Word16 cod[],       /* o : algebraic (fixed) codebook excitation         */        Word16 h[],         /* i : impulse response of weighted synthesis filter */        Word16 y[],         /* o : filtered fixed codebook excitation            */        Word16 sign[],      /* o : sign of 2 pulses                              */        Flag   * pOverflow  /* o : Flag set when overflow occurs                 */    );    /*----------------------------------------------------------------------------    ; LOCAL VARIABLE DEFINITIONS    ; Variable declaration - defined here and used outside this module    ----------------------------------------------------------------------------*/    const Word16 trackTable[4*5] =    {        0, 1, 0, 1, -1, /* subframe 1; track to code;                         * -1 do not code this position                         */        0, -1, 1, 0, 1, /* subframe 2 */        0, 1, 0, -1, 1, /* subframe 3 */        0, 1, -1, 0, 1    };/* subframe 4 */    /*----------------------------------------------------------------------------    ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES    ; Declare variables used in this module but defined elsewhere    ----------------------------------------------------------------------------*/    extern const Word16 startPos[];    /*    ------------------------------------------------------------------------------     FUNCTION NAME: code_2i40_9bits    ------------------------------------------------------------------------------     INPUT AND OUTPUT DEFINITIONS     Inputs:        subNr = subframe number (Word16)        x  = target buffer (Word16)        h  = buffer containing the impulse response of the             weighted synthesis filter; h[-L_subfr .. -1] must be             set to zero (Word16)        T0 = pitch lag (Word16)        pitch_sharp = last quantized pitch gain (Word16)        code = buffer containing the innovative codebook (Word16)        y = buffer containing the filtered fixed codebook excitation (Word16)        sign = pointer to the signs of 2 pulses (Word16)     Outputs:        code buffer contains the new innovation vector gains     Returns:        index = code index (Word16)     Global Variables Used:        Overflow = overflow flag (Flag)     Local Variables Needed:        None    ------------------------------------------------------------------------------     FUNCTION DESCRIPTION     This function searches a 9 bit algebraic codebook containing 2 pulses in a     frame of 40 samples.     The code length is 40, containing 2 nonzero pulses: i0...i1. All pulses can     have two possible amplitudes: +1 or -1. Pulse i0 can have 8 possible positions,     pulse i1 can have 8 positions. Also coded is which track pair should be used,     i.e. first or second pair. Where each pair contains 2 tracks.        First subframe:        first   i0 :  0, 5, 10, 15, 20, 25, 30, 35.            i1 :  2, 7, 12, 17, 22, 27, 32, 37.        second  i0 :  1, 6, 11, 16, 21, 26, 31, 36.                    i1 :  3, 8, 13, 18, 23, 28, 33, 38.        Second subframe:        first   i0 :  0, 5, 10, 15, 20, 25, 30, 35.                    i1 :  3, 8, 13, 18, 23, 28, 33, 38.        second  i0 :  2, 7, 12, 17, 22, 27, 32, 37.                    i1 :  4, 9, 14, 19, 24, 29, 34, 39.        Third subframe:        first   i0 :  0, 5, 10, 15, 20, 25, 30, 35.                    i1 :  2, 7, 12, 17, 22, 27, 32, 37.        second  i0 :  1, 6, 11, 16, 21, 26, 31, 36.                    i1 :  4, 9, 14, 19, 24, 29, 34, 39.        Fourth subframe:        first   i0 :  0, 5, 10, 15, 20, 25, 30, 35.                    i1 :  3, 8, 13, 18, 23, 28, 33, 38.        second  i0 :  1, 6, 11, 16, 21, 26, 31, 36.                    i1 :  4, 9, 14, 19, 24, 29, 34, 39.    ------------------------------------------------------------------------------     REQUIREMENTS     None    ------------------------------------------------------------------------------     REFERENCES     [1] c2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001    ------------------------------------------------------------------------------     PSEUDO-CODE    Word16 code_2i40_9bits(        Word16 subNr,       // i : subframe number        Word16 x[],         // i : target vector        Word16 h[],         // i : impulse response of weighted synthesis filter                            //     h[-L_subfr..-1] must be set to zero.        Word16 T0,          // i : Pitch lag        Word16 pitch_sharp, // i : Last quantized pitch gain        Word16 code[],      // o : Innovative codebook        Word16 y[],         // o : filtered fixed codebook excitation        Word16 * sign       // o : Signs of 2 pulses    )    {        Word16 codvec[NB_PULSE];        Word16 dn[L_CODE], dn2[L_CODE], dn_sign[L_CODE];        Word16 rr[L_CODE][L_CODE];        Word16 i, index, sharp;        sharp = shl(pitch_sharp, 1);        if (sub(T0, L_CODE) < 0)           for (i = T0; i < L_CODE; i++) {              h[i] = add(h[i], mult(h[i - T0], sharp));           }        cor_h_x(h, x, dn, 1);        set_sign(dn, dn_sign, dn2, 8); // dn2[] not used in this codebook search        cor_h(h, dn_sign, rr);        search_2i40(subNr, dn, rr, codvec);        index = build_code(subNr, codvec, dn_sign, code, h, y, sign);       *-----------------------------------------------------------------*       * Compute innovation vector gain.                                 *       * Include fixed-gain pitch contribution into code[].              *       *-----------------------------------------------------------------*        if (sub(T0, L_CODE) < 0)           for (i = T0; i < L_CODE; i++) {              code[i] = add(code[i], mult(code[i - T0], sharp));           }        return index;    }    ------------------------------------------------------------------------------     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 code_2i40_9bits(        Word16 subNr,       /* i : subframe number                          */        Word16 x[],         /* i : target vector                            */        Word16 h[],         /* i : impulse response of weighted synthesis   */        /*     filter h[-L_subfr..-1] must be set to 0. */        Word16 T0,          /* i : Pitch lag                                */        Word16 pitch_sharp, /* i : Last quantized pitch gain                */        Word16 code[],      /* o : Innovative codebook                      */        Word16 y[],         /* o : filtered fixed codebook excitation       */        Word16 * sign,      /* o : Signs of 2 pulses                        */        Flag   * pOverflow  /* o : Flag set when overflow occurs            */    )    {        Word16 codvec[NB_PULSE];        Word16 dn[L_CODE];        Word16 dn2[L_CODE];        Word16 dn_sign[L_CODE];        Word16 rr[L_CODE][L_CODE];        register Word16 i;        Word16 index;        Word16 sharp;        Word16 temp;        Word32 L_temp;        L_temp = ((Word32) pitch_sharp) << 1;        /* Check for overflow condition */        if (L_temp != (Word32)((Word16) L_temp))        {            *(pOverflow) = 1;            sharp = (pitch_sharp > 0) ? MAX_16 : MIN_16;        }        else        {            sharp = (Word16) L_temp;        }        if (T0 < L_CODE)        {            for (i = T0; i < L_CODE; i++)            {                temp =                    mult(                        *(h + i - T0),                        sharp,                        pOverflow);                *(h + i) =                    add(                        *(h + i),                        temp,                        pOverflow);            }        }        cor_h_x(            h,            x,            dn,            1,            pOverflow);        /* dn2[] not used in this codebook search */        set_sign(            dn,            dn_sign,            dn2,            8);        cor_h(            h,            dn_sign,            rr,            pOverflow);        search_2i40(            subNr,            dn,            rr,            codvec,            pOverflow);        index =            build_code(                subNr,                codvec,                dn_sign,                code,                h,                y,                sign,                pOverflow);        /*-----------------------------------------------------------------*         * Compute innovation vector gain.                                 *         * Include fixed-gain pitch contribution into code[].              *         *-----------------------------------------------------------------*/        if (T0 < L_CODE)        {            for (i = T0; i < L_CODE; i++)            {                temp =

⌨️ 快捷键说明

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