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

📄 encg729.c

📁 G.711,G.723.1,G.726,G.729,GSM CODEC C/C++ code
💻 C
📖 第 1 页 / 共 5 页
字号:
/*/////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2005 Intel Corporation. All Rights Reserved.
//
//     Intel(R) Integrated Performance Primitives
//     USC - Unified Speech Codec interface library
//
// By downloading and installing USC codec, you hereby agree that the
// accompanying Materials are being provided to you under the terms and
// conditions of the End User License Agreement for the Intel(R) Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ipplic.htm located in the root directory of your Intel(R) IPP
// product installation for more information.
//
// A speech coding standards promoted by ITU, ETSI, 3GPP and other
// organizations. Implementations of these standards, or the standard enabled
// platforms may require licenses from various entities, including
// Intel Corporation.
//
//
// Purpose: G.729/A/B/D/E speech codec: encoder API functions.
//
*/

#include <stdio.h>
#include <stdlib.h>
#include <ippsc.h>
#include <ipps.h>
#include "owng729.h"

static __ALIGN32 CONST short LUT1_6k[CDBK1_DIM_6K] = { 0, 4,
 6, 5,
 2, 1,
 7, 3};
static __ALIGN32 CONST short LUT2_6k[CDBK2_DIM_6K] = { 0, 4,
 3, 7,
 5, 1,
 6, 2};

static __ALIGN32 CONST short tab1[3] = {
 (1<<10)+875,
 -3798,
 (1<<10)+875
};
static __ALIGN32 CONST short tab2[3] = {
 (1<<12),
 (1<<12)+3711,
 -3733
};

static __ALIGN32 CONST short hammingWin[LP_WINDOW_DIM] = {
    (1<<11)+573,  (1<<11)+575,(1<<11)+581,  2638,  2651,
    2668,  2689,
    2713,  2741,  2772,
    2808,  2847,  2890,
    2936,  2986,
    3040,  3097,  3158,  3223,  3291,  3363,  3438,  3517,  3599,  3685,  3774,  3867, 3963,
    4063,  4166,  4272,  4382,  4495,  4611,  4731,  4853,  4979,
    5108,  5240,  5376,  5514,  5655,  5800,  5947,
    6097,  6250,  6406,  6565,  6726,  6890,
    7057,  7227,  7399,  7573,  7750,  7930,
    8112,  8296,  8483,  8672,  8863,
    9057,  9252,  9450,  9650,  9852,
    10055, 10261, 10468, 10677, 10888,
    11101, 11315, 11531, 11748, 11967,
    12187, 12409, 12632, 12856,
    13082, 13308, 13536, 13764, 13994,
    14225, 14456, 14688, 14921,
    15155, 15389, 15624, 15859,
    16095, 16331, 16568, 16805,
    17042, 17279, 17516, 17754, 17991,
    18228, 18465, 18702, 18939,
    19175, 19411, 19647, 19882,
    20117, 20350, 20584, 20816, 21048,
    21279, 21509, 21738, 21967,
    22194, 22420, 22644, 22868,
    23090, 23311, 23531, 23749, 23965,
    24181, 24394, 24606, 24816,
    25024, 25231, 25435, 25638, 25839,
    26037, 26234, 26428, 26621, 26811, 26999,
    27184, 27368, 27548, 27727, 27903,
    28076, 28247, 28415, 28581, 28743, 28903,
    29061, 29215, 29367, 29515, 29661, 29804, 29944,
    30081, 30214, 30345, 30472, 30597, 30718, 30836, 30950,
    31062, 31170, 31274, 31376, 31474, 31568, 31659, 31747, 31831, 31911, 31988,
    32062, 32132, 32198, 32261, 32320, 32376, 32428, 32476, 32521, 32561, 32599,
    32632, 32662, 32688, 32711, 32729, 32744, 32755, 32763, IPP_MAX_16S, IPP_MAX_16S,
    32741, 32665, 32537, 32359, 32129,
    31850, 31521, 31143,
    30716, 30242,
    29720, 29151,
    28538,
    27879, 27177,
    26433,
    25647,
    24821,
    23957, 23055,
    22117,
    21145,
    20139,
    19102,
    18036,
    16941,
    15820,
    14674,
    13505,
    12315,
    11106,
    9879,
    8637,
    7381,
    6114,
    4838,
    3554,
    2264,
    971
};

static __ALIGN32 CONST short CodecTypeToRate[5] = {
 3,
 3,
 2,
 4,
 0
};

static __ALIGN32 CONST short prevRCpreset[2]={
 0,
 0
};

static void ACFsumUpd(short *ACFsum,short *ACFsumSfs,short *pACF,short *ACFsfs, int* pSumMem);

static int EncoderObjSize(void) {
    int fltSize;
    int objSize=sizeof(G729Encoder_Obj);
    ippsHighPassFilterSize_G729(&fltSize);
    objSize += fltSize;
    SynthesisFilterSize_G729(&fltSize);
    objSize += 2 * fltSize;
    VoiceActivityDetectSize_G729(&fltSize);
    objSize += fltSize;
    objSize += 4*32;
    return objSize;
}

G729_CODECFUN( APIG729_Status, apiG729Codec_ScratchMemoryAlloc,(int *pCodecSize)) {
    if(NULL==pCodecSize)
        return APIG729_StsBadArgErr;
    *pCodecSize = G729_ENCODER_SCRATCH_MEMORY_SIZE;
    return APIG729_StsNoErr;
}
G729_CODECFUN( APIG729_Status, apiG729Encoder_Alloc,
               (G729Codec_Type codecType, int *pCodecSize)) {
    if((codecType != G729_CODEC)&&(codecType != G729A_CODEC)
       &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)) {
        return APIG729_StsBadCodecType;
    }
    *pCodecSize =  EncoderObjSize();
    return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729Encoder_Mode,
               (G729Encoder_Obj* encoderObj, G729Encode_Mode mode)) {
    if(G729Encode_VAD_Enabled != mode && G729Encode_VAD_Disabled != mode) {
        return APIG729_StsBadArgErr;
    }
    encoderObj->objPrm.mode = mode;
    return APIG729_StsNoErr;
}

G729_CODECFUN( APIG729_Status, apiG729Encoder_Init,
               (G729Encoder_Obj* encoderObj, G729Codec_Type codecType, G729Encode_Mode mode)) {
    int i,fltSize;
    Ipp16s abEnc[6];

    if(NULL==encoderObj)
        return APIG729_StsBadArgErr;

    if((codecType != G729_CODEC)&&(codecType != G729A_CODEC)
       &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC)&&(codecType != G729I_CODEC)) {
        return APIG729_StsBadCodecType;
    }

    ippsZero_16s((short*)encoderObj,sizeof(*encoderObj)>>1) ;

    encoderObj->objPrm.objSize = EncoderObjSize();
    encoderObj->objPrm.mode = mode;
    encoderObj->objPrm.key = ENC_KEY;
    encoderObj->objPrm.codecType=codecType;


    encoderObj->mode = mode;
    encoderObj->preProc = (char*)encoderObj + sizeof(G729Encoder_Obj);
    encoderObj->preProc = IPP_ALIGNED_PTR(encoderObj->preProc, 16);
    ippsHighPassFilterSize_G729(&fltSize);
    encoderObj->synFltw = (char*)encoderObj->preProc + fltSize;
    encoderObj->synFltw = IPP_ALIGNED_PTR(encoderObj->synFltw, 16);
    SynthesisFilterSize_G729(&fltSize);
    encoderObj->synFltw0 = (char*)encoderObj->synFltw + fltSize;
    encoderObj->synFltw0 = IPP_ALIGNED_PTR(encoderObj->synFltw0, 16);
    encoderObj->vadMem  = (char*)encoderObj->synFltw0 + fltSize;
    encoderObj->vadMem = IPP_ALIGNED_PTR(encoderObj->vadMem, 16);
    abEnc[0] = tab2[0]; abEnc[1] = tab2[1]; abEnc[2] = tab2[2];
    abEnc[3] = tab1[0]; abEnc[4] = tab1[1]; abEnc[5] = tab1[2];
    for(i=0;i<4;i++) encoderObj->prevFrameQuantEn[i]=-14336;
    VoiceActivityDetectInit_G729(encoderObj->vadMem);
    ippsHighPassFilterInit_G729(abEnc,encoderObj->preProc);
    SynthesisFilterInit_G729(encoderObj->synFltw);
    SynthesisFilterInit_G729(encoderObj->synFltw0);


    ippsZero_16s(encoderObj->speechHistory,SPEECH_BUF_DIM);
    ippsZero_16s(encoderObj->prevExcitat, L_prevExcitat);
    ippsZero_16s(encoderObj->prevWgtSpeech, MAX_PITCH_LAG);
    ippsZero_16s(encoderObj->resFilMem0,  BWLPCF_DIM);
    encoderObj->betaPreFilter = PITCH_SHARP_MIN;
    ippsCopy_16s(presetOldA, encoderObj->prevSubfrLPC, LPF_DIM+1);
    encoderObj->prevRC[0] = prevRCpreset[0];
    encoderObj->prevRC[1] = prevRCpreset[1];

    ippsCopy_16s(presetLSP, encoderObj->prevSubfrLSP, LPF_DIM);
    ippsCopy_16s(presetLSP, encoderObj->prevSubfrLSPquant, LPF_DIM);
    ippsZero_16s(encoderObj->zeroPostFiltVec1 + BWLPCF_DIM+1, LP_SUBFRAME_DIM);
    encoderObj->BWDcounter2 = 0;
    encoderObj->FWDcounter2 = 0;

    for(i=0; i<LSP_MA_ORDER; i++)
        ippsCopy_16s( &resetPrevLSP[0], &encoderObj->prevLSPfreq[i][0], LPF_DIM);

    for(i=0; i<4; i++) encoderObj->coderErr[i] = BWF_HARMONIC;

    if(encoderObj->objPrm.codecType == G729A_CODEC) {
        encoderObj->seed = SEED_INIT;
        encoderObj->CNGidx = 0;
        ippsZero_16s(encoderObj->encPrm, PARM_DIM+1);
        Init_CNG_encoder(encoderObj);
    } else {
        encoderObj->prevLAR[0]=encoderObj->prevLAR[1]=0;
        encoderObj->prevSubfrSmooth=1;
        encoderObj->seed = SEED_INIT;
        encoderObj->CNGidx = 0;
        encoderObj->dominantBWDmode = 0;
        encoderObj->interpCoeff2_2 = 4506;
        encoderObj->statGlobal = 10000;
        ippsZero_16s(encoderObj->resFilMem, BWLPCF_DIM);
        ippsZero_16s(encoderObj->pPrevFilt, BWLPCF1_DIM);
        encoderObj->pPrevFilt[0] = (1<<12);
        encoderObj->prevLPmode = 0;
        for(i=0; i<5; i++) {
            encoderObj->pLag[i] = 20;
            encoderObj->pGain[i] = 11469;
        }
        ippsZero_16s(encoderObj->encPrm, PARM_DIM+1);
        Init_CNG_encoder(encoderObj);
        ippsZero_16s(encoderObj->BWDsynth, TBWD_DIM);
        encoderObj->pSynth = encoderObj->BWDsynth + SYNTH_BWD_DIM;
        ippsWinHybridGetStateSize_G729E_16s(&fltSize);
        if(fltSize > BWLPCF1_DIM*sizeof(int)) {
            return APIG729_StsNotInitialized;
        }
        ippsWinHybridInit_G729E_16s((IppsWinHybridState_G729E_16s*)&encoderObj->hwState);
        ippsZero_16s(encoderObj->pPrevBwdRC, 2);
        ippsZero_16s(encoderObj->pPrevBwdLPC, BWLPCF1_DIM);
        encoderObj->pPrevBwdLPC[0]=(1<<12);
        ippsZero_16s(encoderObj->pBwdLPC2, BWLPCF1_DIM);
        encoderObj->pBwdLPC2[0] = (1<<12);
        encoderObj->BWDFrameCounter = 0;
        encoderObj->val_BWDFrameCounter = 0;
    }
    return APIG729_StsNoErr;
}
void Init_CNG_encoder(G729Encoder_Obj *encoderObj) {
    short i;
    ippsZero_16s(encoderObj->ACFsum, TOTAL_ACF_DIM);
    for(i=0; i<ACF_TOTAL; i++)
        encoderObj->ACFsumSfs[i] = 40;
    ippsZero_16s(encoderObj->pACF, ACF_DIM);
    for(i=0; i<ACF_NOW; i++)
        encoderObj->ACFsfs[i] = 40;
    for(i=0; i<GAIN_NUM; i++)
        encoderObj->energySfs[i] = 40;
    for(i=0; i<GAIN_NUM; i++)
        encoderObj->energy[i] = 0;

⌨️ 快捷键说明

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