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

📄 pvamrwbdecoder.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.173    ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec    Available from http://www.3gpp.org(C) 2007, 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.****************************************************************************************//*------------------------------------------------------------------------------ Filename: pvamrwbdecoder.cpp     Date: 05/08/2004------------------------------------------------------------------------------ REVISION HISTORY Description:------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS     int16 mode,                      input : used mode     int16 prms[],                    input : parameter vector     int16 synth16k[],                output: synthesis speech     int16 * frame_length,            output:  lenght of the frame     void *spd_state,                 i/o   : State structure     int16 frame_type,                input : received frame type     int16 ScratchMem[]------------------------------------------------------------------------------ FUNCTION DESCRIPTION   Performs the main decoder routine AMR WB ACELP coding algorithm with 20 ms   speech frames for wideband speech signals.------------------------------------------------------------------------------ REQUIREMENTS------------------------------------------------------------------------------ REFERENCES------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "pv_amr_wb_type_defs.h"#include "pvamrwbdecoder_mem_funcs.h"#include "pvamrwbdecoder_basic_op.h"#include "pvamrwbdecoder_cnst.h"#include "pvamrwbdecoder_acelp.h"#include "e_pv_amrwbdec.h"#include "get_amr_wb_bits.h"#include "pvamrwb_math_op.h"#include "pvamrwbdecoder_api.h"#include "pvamrwbdecoder.h"#include "synthesis_amr_wb.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL STORE/BUFFER/POINTER DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//* LPC interpolation coef {0.45, 0.8, 0.96, 1.0}; in Q15 */static const int16 interpol_frac[NB_SUBFR] = {14746, 26214, 31457, 32767};/* isp tables for initialization */static const int16 isp_init[M] ={    32138, 30274, 27246, 23170, 18205, 12540, 6393, 0,    -6393, -12540, -18205, -23170, -27246, -30274, -32138, 1475};static const int16 isf_init[M] ={    1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192,    9216, 10240, 11264, 12288, 13312, 14336, 15360, 3840};/*----------------------------------------------------------------------------; EXTERNAL FUNCTION REFERENCES; Declare functions defined elsewhere and referenced in this module----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES; Declare variables used in this module but defined elsewhere----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; FUNCTION CODE----------------------------------------------------------------------------*//*---------------------------------------------------------------------------- FUNCTION DESCRIPTION   pvDecoder_AmrWb_Init   Initialization of variables for the decoder section.----------------------------------------------------------------------------*/void pvDecoder_AmrWb_Init(void **spd_state, void *pt_st, int16 **ScratchMem){    /* Decoder states */    Decoder_State *st = &(((PV_AmrWbDec *)pt_st)->state);    *ScratchMem = (int16 *)(&(((PV_AmrWbDec *)pt_st)->ScratchMem));    /*     *  Init dtx decoding     */    dtx_dec_amr_wb_reset(&(st->dtx_decSt), isf_init);    pvDecoder_AmrWb_Reset((void *) st, 1);    *spd_state = (void *) st;    return;}/*----------------------------------------------------------------------------; FUNCTION CODE----------------------------------------------------------------------------*/void pvDecoder_AmrWb_Reset(void *st, int16 reset_all){    int16 i;    Decoder_State *dec_state;    dec_state = (Decoder_State *) st;    pv_memset((void *)dec_state->old_exc,              0,              (PIT_MAX + L_INTERPOL)*sizeof(*dec_state->old_exc));    pv_memset((void *)dec_state->past_isfq,              0,              M*sizeof(*dec_state->past_isfq));    dec_state->old_T0_frac = 0;               /* old pitch value = 64.0 */    dec_state->old_T0 = 64;    dec_state->first_frame = 1;    dec_state->L_gc_thres = 0;    dec_state->tilt_code = 0;    pv_memset((void *)dec_state->disp_mem,              0,              8*sizeof(*dec_state->disp_mem));    /* scaling memories for excitation */    dec_state->Q_old = Q_MAX;    dec_state->Qsubfr[3] = Q_MAX;    dec_state->Qsubfr[2] = Q_MAX;    dec_state->Qsubfr[1] = Q_MAX;    dec_state->Qsubfr[0] = Q_MAX;    if (reset_all != 0)    {        /* routines initialization */        dec_gain2_amr_wb_init(dec_state->dec_gain);        oversamp_12k8_to_16k_init(dec_state->mem_oversamp);        band_pass_6k_7k_init(dec_state->mem_hf);        low_pass_filt_7k_init(dec_state->mem_hf3);        highpass_50Hz_at_12k8_init(dec_state->mem_sig_out);        highpass_400Hz_at_12k8_init(dec_state->mem_hp400);        Init_Lagconc(dec_state->lag_hist);        /* isp initialization */        pv_memcpy((void *)dec_state->ispold, (void *)isp_init, M*sizeof(*isp_init));        pv_memcpy((void *)dec_state->isfold, (void *)isf_init, M*sizeof(*isf_init));        for (i = 0; i < L_MEANBUF; i++)        {            pv_memcpy((void *)&dec_state->isf_buf[i * M],                      (void *)isf_init,                      M*sizeof(*isf_init));        }        /* variable initialization */        dec_state->mem_deemph = 0;        dec_state->seed  = 21845;              /* init random with 21845 */        dec_state->seed2 = 21845;        dec_state->seed3 = 21845;        dec_state->state = 0;        dec_state->prev_bfi = 0;        /* Static vectors to zero */        pv_memset((void *)dec_state->mem_syn_hf,                  0,                  M16k*sizeof(*dec_state->mem_syn_hf));        pv_memset((void *)dec_state->mem_syn_hi,                  0,                  M*sizeof(*dec_state->mem_syn_hi));        pv_memset((void *)dec_state->mem_syn_lo,                  0,                  M*sizeof(*dec_state->mem_syn_lo));        dtx_dec_amr_wb_reset(&(dec_state->dtx_decSt), isf_init);        dec_state->vad_hist = 0;    }    return;}/*----------------------------------------------------------------------------; FUNCTION CODE----------------------------------------------------------------------------*/int32 pvDecoder_AmrWbMemRequirements(){    return(sizeof(PV_AmrWbDec));}/*----------------------------------------------------------------------------; FUNCTION CODE----------------------------------------------------------------------------*//*              Main decoder routine.                                       */int32 pvDecoder_AmrWb(    int16 mode,              /* input : used mode                     */    int16 prms[],            /* input : parameter vector              */    int16 synth16k[],        /* output: synthesis speech              */    int16 * frame_length,    /* output:  lenght of the frame          */    void *spd_state,         /* i/o   : State structure               */    int16 frame_type,        /* input : received frame type           */    int16 ScratchMem[]){    /* Decoder states */    Decoder_State *st;    int16 *ScratchMem2 = &ScratchMem[ L_SUBFR + L_SUBFR16k + ((L_SUBFR + M + M16k +1)<<1)];    /* Excitation vector */    int16 *old_exc = ScratchMem2;    int16 *Aq = &old_exc[(L_FRAME + 1) + PIT_MAX + L_INTERPOL];/* A(z)   quantized for the 4 subframes */    int16 *ispnew  = &Aq[NB_SUBFR * (M + 1)];/* immittance spectral pairs at 4nd sfr */    int16 *isf     = &ispnew[M];             /* ISF (frequency domain) at 4nd sfr    */    int16 *isf_tmp = &isf[M];    int16 *code    = &isf_tmp[M];             /* algebraic codevector                 */    int16 *excp    = &code[L_SUBFR];    int16 *exc2    = &excp[L_SUBFR];         /* excitation vector                    */    int16 *HfIsf   = &exc2[L_FRAME];    int16 *exc;    /* LPC coefficients */    int16 *p_Aq;                          /* ptr to A(z) for the 4 subframes      */    int16 fac, stab_fac, voice_fac, Q_new = 0;    int32 L_tmp, L_gain_code;    /* Scalars */    int16 i, j, i_subfr, index, ind[8], tmp;    int32 max;    int16 T0, T0_frac, pit_flag, T0_max, select, T0_min = 0;    int16 gain_pit, gain_code;    int16 newDTXState, bfi, unusable_frame, nb_bits;    int16 vad_flag;    int16 pit_sharp;    int16 corr_gain = 0;    st = (Decoder_State *) spd_state;    /* mode verification */    nb_bits = AMR_WB_COMPRESSED[mode];    *frame_length = AMR_WB_PCM_FRAME;    /* find the new  DTX state  SPEECH OR DTX */    newDTXState = rx_amr_wb_dtx_handler(&(st->dtx_decSt), frame_type);    if (newDTXState != SPEECH)    {        dtx_dec_amr_wb(&(st->dtx_decSt), exc2, newDTXState, isf, &prms);    }    /* SPEECH action state machine  */    if ((frame_type == RX_SPEECH_BAD) ||            (frame_type == RX_SPEECH_PROBABLY_DEGRADED))    {        /* bfi for all index, bits are not usable */        bfi = 1;        unusable_frame = 0;    }    else if ((frame_type == RX_NO_DATA) ||             (frame_type == RX_SPEECH_LOST))    {        /* bfi only for lsf, gains and pitch period */        bfi = 1;        unusable_frame = 1;    }    else    {        bfi = 0;        unusable_frame = 0;    }    if (bfi != 0)    {        st->state += 1;        if (st->state > 6)        {            st->state = 6;        }    }    else

⌨️ 快捷键说明

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