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

📄 pitch_fr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* ------------------------------------------------------------------ * 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/pitch_fr.c Functions:     Date: 02/04/2002------------------------------------------------------------------------------ REVISION HISTORY Description: Added pOverflow as a passed in value to searchFrac and made              other fixes to the code regarding simple syntax fixes. Removed              the include of stio.h. Description: *lag-- decrements the pointer.  (*lag)-- decrements what is pointed to.  The latter is what the coder intended, but the former is the coding instruction that was used. Description: A common problem -- a comparison != 0 was inadvertantly replaced by a comparison == 0. Description:  For Norm_Corr() and getRange()              1. Eliminated unused include files.              2. Replaced array addressing by pointers              3. Eliminated math operations that unnecessary checked for                 saturation, in some cases this by shifting before adding and                 in other cases by evaluating the operands              4. Unrolled loops to speed up processing, use decrement loops              5. Replaced extract_l() call with equivalent code              6. Modified scaling threshold and group all shifts (avoiding                 successive shifts) Description:  Replaced OSCL mem type functions and eliminated include               files that now are chosen by OSCL definitions Description:  Replaced "int" and/or "char" with OSCL defined types. Description: Removed compiler warnings. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION      File             : pitch_fr.c      Purpose          : Find the pitch period with 1/3 or 1/6 subsample                       : resolution (closed loop).------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "pitch_fr.h"#include "oper_32b.h"#include "cnst.h"#include "enc_lag3.h"#include "enc_lag6.h"#include "inter_36.h"#include "inv_sqrt.h"#include "convolve.h"#include "basic_op.h"#include "oscl_mem.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL VARIABLE DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//* * mode dependent parameters used in Pitch_fr() * Note: order of MRxx in 'enum Mode' is important! */static const struct{    Word16 max_frac_lag;     /* lag up to which fractional lags are used    */    Word16 flag3;            /* enable 1/3 instead of 1/6 fract. resolution */    Word16 first_frac;       /* first fractional to check                   */    Word16 last_frac;        /* last fractional to check                    */    Word16 delta_int_low;    /* integer lag below TO to start search from   */    Word16 delta_int_range;  /* integer range around T0                     */    Word16 delta_frc_low;    /* fractional below T0                         */    Word16 delta_frc_range;  /* fractional range around T0                  */    Word16 pit_min;          /* minimum pitch                               */} mode_dep_parm[N_MODES] ={    /* MR475 */  { 84,  1, -2,  2,  5, 10,  5,  9, PIT_MIN },    /* MR515 */  { 84,  1, -2,  2,  5, 10,  5,  9, PIT_MIN },    /* MR59  */  { 84,  1, -2,  2,  3,  6,  5,  9, PIT_MIN },    /* MR67  */  { 84,  1, -2,  2,  3,  6,  5,  9, PIT_MIN },    /* MR74  */  { 84,  1, -2,  2,  3,  6,  5,  9, PIT_MIN },    /* MR795 */  { 84,  1, -2,  2,  3,  6, 10, 19, PIT_MIN },    /* MR102 */  { 84,  1, -2,  2,  3,  6,  5,  9, PIT_MIN },    /* MR122 */  { 94,  0, -3,  3,  3,  6,  5,  9, PIT_MIN_MR122 }};/*------------------------------------------------------------------------------ FUNCTION NAME: Norm_Corr------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    exc[] = pointer to buffer of type Word16    xn[]  = pointer to buffer of type Word16    h[]   = pointer to buffer of type Word16    L_subfr = length of sub frame (Word16)    t_min  = the minimum table value of type Word16    t_max = the maximum table value of type Word16    corr_norm[] = pointer to buffer of type Word16 Outputs:    pOverflow = 1 if the math functions called result in overflow else zero. Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION  FUNCTION:   Norm_Corr()  PURPOSE: Find the normalized correlation between the target vector           and the filtered past excitation.  DESCRIPTION:     The normalized correlation is given by the correlation between the     target and filtered past excitation divided by the square root of     the energy of filtered excitation.                   corr[k] = <x[], y_k[]>/sqrt(y_k[],y_k[])     where x[] is the target vector and y_k[] is the filtered past     excitation at delay k.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic void Norm_Corr (Word16 exc[], Word16 xn[], Word16 h[], Word16 L_subfr,                       Word16 t_min, Word16 t_max, Word16 corr_norm[]){    Word16 i, j, k;    Word16 corr_h, corr_l, norm_h, norm_l;    Word32 s;    // Usally dynamic allocation of (L_subfr)    Word16 excf[L_SUBFR];    Word16 scaling, h_fac, *s_excf, scaled_excf[L_SUBFR];    k = -t_min;    // compute the filtered excitation for the first delay t_min    Convolve (&exc[k], h, excf, L_subfr);    // scale "excf[]" to avoid overflow    for (j = 0; j < L_subfr; j++) {        scaled_excf[j] = shr (excf[j], 2);    }    // Compute 1/sqrt(energy of excf[])    s = 0;    for (j = 0; j < L_subfr; j++) {        s = L_mac (s, excf[j], excf[j]);    }    if (L_sub (s, 67108864L) <= 0) {            // if (s <= 2^26)        s_excf = excf;        h_fac = 15 - 12;        scaling = 0;    }    else {        // "excf[]" is divided by 2        s_excf = scaled_excf;        h_fac = 15 - 12 - 2;        scaling = 2;    }    // loop for every possible period    for (i = t_min; i <= t_max; i++) {        // Compute 1/sqrt(energy of excf[])        s = 0;        for (j = 0; j < L_subfr; j++) {            s = L_mac (s, s_excf[j], s_excf[j]);        }        s = Inv_sqrt (s);        L_Extract (s, &norm_h, &norm_l);        // Compute correlation between xn[] and excf[]        s = 0;        for (j = 0; j < L_subfr; j++) {            s = L_mac (s, xn[j], s_excf[j]);        }        L_Extract (s, &corr_h, &corr_l);        // Normalize correlation = correlation * (1/sqrt(energy))        s = Mpy_32 (corr_h, corr_l, norm_h, norm_l);        corr_norm[i] = extract_h (L_shl (s, 16));            // modify the filtered excitation excf[] for the next iteration        if (sub (i, t_max) != 0) {            k--;            for (j = L_subfr - 1; j > 0; j--) {                s = L_mult (exc[k], h[j]);                s = L_shl (s, h_fac);                s_excf[j] = add (extract_h (s), s_excf[j - 1]);            }            s_excf[0] = shr (exc[k], scaling);        }    }    return;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/static void Norm_Corr(Word16 exc[],                      Word16 xn[],                      Word16 h[],                      Word16 L_subfr,                      Word16 t_min,                      Word16 t_max,                      Word16 corr_norm[],                      Flag *pOverflow){    Word16 i;    Word16 j;    Word16 k;    Word16 corr_h;    Word16 corr_l;    Word16 norm_h;    Word16 norm_l;    Word32 s;    Word32 s2;    Word16 excf[L_SUBFR];    Word16 scaling;    Word16 h_fac;    Word16 *s_excf;    Word16 scaled_excf[L_SUBFR];    Word16 *p_s_excf;    Word16 *p_excf;    Word16  temp;    Word16 *p_x;    Word16 *p_h;    k = -t_min;    /* compute the filtered excitation for the first delay t_min */    Convolve(&exc[k], h, excf, L_subfr);    /* scale "excf[]" to avoid overflow */    s = 0;    p_s_excf = scaled_excf;    p_excf   = excf;    for (j = (L_subfr >> 1); j != 0; j--)    {        temp = *(p_excf++);        *(p_s_excf++) = temp >> 2;        s += (Word32) temp * temp;        temp = *(p_excf++);        *(p_s_excf++) = temp >> 2;        s += (Word32) temp * temp;    }    if (s <= (67108864L >> 1))    {        s_excf = excf;        h_fac = 12;        scaling = 0;    }    else    {        /* "excf[]" is divided by 2 */        s_excf = scaled_excf;        h_fac = 14;        scaling = 2;    }    /* loop for every possible period */    for (i = t_min; i <= t_max; i++)    {        /* Compute 1/sqrt(energy of excf[]) */        s   = s2 = 0;        p_x      = xn;        p_s_excf = s_excf;        j        = L_subfr >> 1;        while (j--)        {            s  += (Word32) * (p_x++) * *(p_s_excf);            s2 += ((Word32)(*(p_s_excf)) * (*(p_s_excf)));            p_s_excf++;            s  += (Word32) * (p_x++) * *(p_s_excf);            s2 += ((Word32)(*(p_s_excf)) * (*(p_s_excf)));            p_s_excf++;        }        s2     = s2 << 1;        s2     = Inv_sqrt(s2, pOverflow);        norm_h = (Word16)(s2 >> 16);        norm_l = (Word16)((s2 >> 1) - (norm_h << 15));        corr_h = (Word16)(s >> 15);        corr_l = (Word16)((s) - (corr_h << 15));

⌨️ 快捷键说明

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