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

📄 p_ol_wgh.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ------------------------------------------------------------------ * 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/p_ol_wgh.c Funtions: p_ol_wgh_init           p_ol_wgh_reset           p_ol_wgh_exit           Lag_max           Pitch_ol_wgh     Date: 02/05/2002------------------------------------------------------------------------------ REVISION HISTORY Description: t0 was not being declared as Word32. 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: Changed round function name to pv_round to avoid conflict with              round function in C standard library. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION The modules in this file compute the open loop pitch lag with weighting.------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "p_ol_wgh.h"#include "typedef.h"#include "cnst.h"#include "basic_op.h"#include "gmed_n.h"#include "inv_sqrt.h"#include "vad1.h"#include "calc_cor.h"#include "hp_max.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----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: p_ol_wgh_init------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs    state = pointer to a pointer of structure type pitchOLWghtState Outputs:    None Returns:    0 if the memory allocation is a success    -1 if the memory allocation fails Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function allocates state memory and initializes state memory------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint p_ol_wgh_init (pitchOLWghtState **state){    pitchOLWghtState* s;    if (state == (pitchOLWghtState **) NULL){        // fprintf(stderr, "p_ol_wgh_init: invalid parameter\n");        return -1;    }    *state = NULL;    // allocate memory    if ((s= (pitchOLWghtState *) malloc(sizeof(pitchOLWghtState))) == NULL){        // fprintf(stderr, "p_ol_wgh_init: can not malloc state structure\n");        return -1;    }    p_ol_wgh_reset(s);    *state = s;    return 0;}------------------------------------------------------------------------------ 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 p_ol_wgh_init(pitchOLWghtState **state){    pitchOLWghtState* s;    if (state == (pitchOLWghtState **) NULL)    {        /* fprintf(stderr, "p_ol_wgh_init: invalid parameter\n"); */        return -1;    }    *state = NULL;    /* allocate memory */    if ((s = (pitchOLWghtState *) oscl_malloc(sizeof(pitchOLWghtState))) == NULL)    {        /* fprintf(stderr, "p_ol_wgh_init: can not malloc state structure\n"); */        return -1;    }    p_ol_wgh_reset(s);    *state = s;    return 0;}/*----------------------------------------------------------------------------; End Function: p_ol_wgh_init----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: p_ol_wgh_reset------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs    st = pointer to structure type pitchOLWghtState Outputs:    None Returns:    0 if the memory initialization is a success    -1 if the memory initialization fails Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function initializes state memory to zero------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint p_ol_wgh_reset (pitchOLWghtState *st){   if (st == (pitchOLWghtState *) NULL){      // fprintf(stderr, "p_ol_wgh_reset: invalid parameter\n");      return -1;   }   // Reset pitch search states   st->old_T0_med = 40;   st->ada_w = 0;   st->wght_flg = 0;   return 0;}------------------------------------------------------------------------------ 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 p_ol_wgh_reset(pitchOLWghtState *st){    if (st == (pitchOLWghtState *) NULL)    {        /* fprintf(stderr, "p_ol_wgh_reset: invalid parameter\n"); */        return -1;    }    /* Reset pitch search states */    st->old_T0_med = 40;    st->ada_w = 0;    st->wght_flg = 0;    return 0;}/*----------------------------------------------------------------------------; End Function: p_ol_wgh_reset----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: p_ol_wgh_exit------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs    st = pointer to a pointer of structure type pitchOLWghtState Outputs:    None Returns:    0 if the memory initialization is a success    -1 if the memory initialization fails Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function frees the memory used for state memory------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid p_ol_wgh_exit (pitchOLWghtState **state){    if (state == NULL || *state == NULL)        return;    // deallocate memory    free(*state);    *state = NULL;    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]------------------------------------------------------------------------------*/void p_ol_wgh_exit(pitchOLWghtState **state){    if (state == NULL || *state == NULL)        return;    /* deallocate memory */    oscl_free(*state);    *state = NULL;    return;}/*----------------------------------------------------------------------------; End Function: p_ol_wgh_exit----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: Lag_max------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    corr = pointer to buffer of correlation values (Word32)    scal_sig = pointer to buffer of scaled signal values (Word16)    scal_fac = scaled signal factor (Word16)    scal_flag = EFR compatible scaling flag (Word16)    L_frame = length of frame to compute pitch (Word16)    lag_max = maximum lag (Word16)    lag_min = minimum lag (Word16)    cor_max = pointer to the normalized correlation of selected lag (Word16)    rmax = pointer to max(<s[i]*s[j]>), (Word32)    r0 = pointer to the residual energy (Word32)    dtx  = dtx flag; equal to 1, if dtx is enabled, 0, otherwise (Flag)    pOverflow = Pointer to overflow (Flag) Outputs:    cor_max contains the newly calculated normalized correlation of the      selected lag    rmax contains the newly calculated max(<s[i]*s[j]>)    r0 contains the newly calculated residual energy    pOverflow -> 1 if the math functions called by this routine saturate. Returns:    p_max = lag of the max correlation found (Word16) Global Variables Used:    None. Local Variables Needed:    None.------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function finds the lag that has maximum correlation of scal_sig[] in a given delay range. 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.------------------------------------------------------------------------------ REQUIREMENTS None.------------------------------------------------------------------------------ REFERENCES p_ol_wgh.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic 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 L_frame,     // i : length of frame to compute pitch    Word16 lag_max,     // i : maximum lag    Word16 lag_min,     // i : minimum lag    Word16 old_lag,     // i : old open-loop lag    Word16 *cor_max,    // o : normalized correlation of selected lag    Word16 wght_flg,    // i : is weighting function used    Word16 *gain_flg,   // o : open-loop flag    Flag dtx            // i   : dtx flag; use dtx=1, do not use dtx=0    ){    Word16 i, j;    Word16 *p, *p1;    Word32 max, t0;    Word16 t0_h, t0_l;    Word16 p_max;    const Word16 *ww, *we;    Word32 t1;    ww = &corrweight[250];    we = &corrweight[123 + lag_max - old_lag];    max = MIN_32;    p_max = lag_max;    for (i = lag_max; i >= lag_min; i--)    {       t0 = corr[-i];

⌨️ 快捷键说明

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