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

📄 usc729fp.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*/////////////////////////////////////////////////////////////////////////////
//
//                  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) 2004-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 floating-point speech codec: USC functions.
//
*/

#include "owng729fp.h"
#include "g729fpapi.h"
#include <string.h>
#include <usc.h>

#define  G729IFP_NUM_RATES   3
#define  G729AFP_NUM_RATES   1

static USC_Status GetInfo_G729I(USC_Handle handle, USC_CodecInfo *pInfo);
static USC_Status GetInfo_G729A(USC_Handle handle, USC_CodecInfo *pInfo);
static USC_Status NumAlloc(const USC_Option *options, int *nbanks);
static USC_Status MemAlloc_G729I(const USC_Option *options, USC_MemBank *pBanks);
static USC_Status MemAlloc_G729A(const USC_Option *options, USC_MemBank *pBanks);
static USC_Status Init_G729I(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle);
static USC_Status Init_G729A(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle);
static USC_Status Reinit_G729I(const USC_Modes *modes, USC_Handle handle );
static USC_Status Reinit_G729A(const USC_Modes *modes, USC_Handle handle );
static USC_Status Control_G729I(const USC_Modes *modes, USC_Handle handle );
static USC_Status Control_G729A(const USC_Modes *modes, USC_Handle handle );
static USC_Status Encode_G729I(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out);
static USC_Status Encode_G729A(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out);
static USC_Status Decode_G729I(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out);
static USC_Status Decode_G729A(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out);
static USC_Status GetOutStreamSizeI(const USC_Option *options, int bitrate, int nbytesSrc, int *nbytesDst);
static USC_Status GetOutStreamSizeA(const USC_Option *options, int bitrate, int nbytesSrc, int *nbytesDst);
static USC_Status SetFrameSize(const USC_Option *options, USC_Handle handle, int frameSize);

#define BITSTREAM_SIZE      15
#define G729_SPEECH_FRAME   80
#define G729_BITS_PER_SAMPLE 16
#define G729_SID_FRAMESIZE    2
#define G729_NUM_UNTR_FRAMES  2


typedef struct {
    int direction;
    int bitrate;
    int vad;
    int reserved; // for future extension
} G729_Handle_Header;

/* global usc vector table */
USCFUN USC_Fxns USC_G729IFP_Fxns=
{
    {
        USC_Codec,
        GetInfo_G729I,
        NumAlloc,
        MemAlloc_G729I,
        Init_G729I,
        Reinit_G729I,
        Control_G729I
    },
    Encode_G729I,
    Decode_G729I,
    GetOutStreamSizeI,
    SetFrameSize

};

USCFUN USC_Fxns USC_G729AFP_Fxns=
{
    {
        USC_Codec,
        GetInfo_G729A,
        NumAlloc,
        MemAlloc_G729A,
        Init_G729A,
        Reinit_G729A,
        Control_G729A
    },
    Encode_G729A,
    Decode_G729A,
    GetOutStreamSizeA,
    SetFrameSize

};

static USC_Option  params;  /* what is supported  */
static USC_PCMType pcmType; /* codec audio source */

static __ALIGN32 CONST short LostFrame[G729_SPEECH_FRAME]=
{
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0
};

static __ALIGN32 CONST USC_Rates pTblRates_G729IFP[G729IFP_NUM_RATES]={
    {11800},
    {8000},
    {6400}
};

static __ALIGN32 CONST USC_Rates pTblRates_G729AFP[G729AFP_NUM_RATES]={
    {8000}
};

static int CheckRate_G729I(int rate_bps)
{
    int rate;

    switch(rate_bps) {
      case 8000:  rate = 0; break;
      case 6400:  rate = 2; break;
      case 11800: rate = 3; break;
      default: rate = -1; break;
    }
    return rate;
}

static int CheckRate_G729A(int rate_bps)
{
    int rate;

    switch(rate_bps) {
      case 8000:  rate = 1; break;
      default: rate = -1; break;
    }
    return rate;
}

static USC_Status GetInfo_G729I(USC_Handle handle, USC_CodecInfo *pInfo)
{

    G729_Handle_Header *g729_header;

    pInfo->name = "G729IFP";
    pInfo->framesize = G729_SPEECH_FRAME*sizeof(short);
    if (handle == NULL) {
       pInfo->params.modes.bitrate = 8000;
       pInfo->params.direction = 0;
       pInfo->params.modes.vad = 1;
    } else {
       g729_header = (G729_Handle_Header*)handle;
       pInfo->params.modes.bitrate = g729_header->bitrate;
       pInfo->params.direction = g729_header->direction;
       pInfo->params.modes.vad = g729_header->vad;
    }
    pInfo->params.modes.truncate = 0;
    pInfo->maxbitsize = BITSTREAM_SIZE;
    pInfo->pcmType.sample_frequency = 8000;
    pInfo->pcmType.bitPerSample = G729_BITS_PER_SAMPLE;
    pInfo->params.modes.hpf = 0;
    pInfo->params.modes.pf = 0;
    pInfo->params.law = 0;
    pInfo->nRates = G729IFP_NUM_RATES;
    pInfo->pRateTbl = (const USC_Rates *)&pTblRates_G729IFP;

    return USC_NoError;
}

static USC_Status GetInfo_G729A(USC_Handle handle, USC_CodecInfo *pInfo)
{

    G729_Handle_Header *g729_header;

    pInfo->name = "G729AFP";
    pInfo->framesize = G729_SPEECH_FRAME*sizeof(short);
    if (handle == NULL) {
       pInfo->params.modes.bitrate = 8000;
       pInfo->params.direction = 0;
       pInfo->params.modes.vad = 1;
    } else {
       g729_header = (G729_Handle_Header*)handle;
       pInfo->params.modes.bitrate = g729_header->bitrate;
       pInfo->params.direction = g729_header->direction;
       pInfo->params.modes.vad = g729_header->vad;
    }
    pInfo->params.modes.truncate = 0;
    pInfo->maxbitsize = BITSTREAM_SIZE;
    pInfo->pcmType.sample_frequency = 8000;
    pInfo->pcmType.bitPerSample = G729_BITS_PER_SAMPLE;
    pInfo->params.modes.hpf = 0;
    pInfo->params.modes.pf = 0;
    pInfo->params.law = 0;
    pInfo->nRates = G729AFP_NUM_RATES;
    pInfo->pRateTbl = (const USC_Rates *)&pTblRates_G729AFP;

    return USC_NoError;
}

static USC_Status NumAlloc(const USC_Option *options, int *nbanks)
{
   if(options==NULL) return USC_BadDataPointer;
   if(nbanks==NULL) return USC_BadDataPointer;
   *nbanks = 1;
   return USC_NoError;
}

static USC_Status MemAlloc_G729I(const USC_Option *options, USC_MemBank *pBanks)
{
    unsigned int nbytes;
    int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(pBanks==NULL) return USC_BadDataPointer;

    pBanks->pMem = NULL;

    bitrate_idx = CheckRate_G729I(options->modes.bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

    if (options->direction == 0) /* encode only */
    {
        apiG729FPEncoder_Alloc(G729I_CODEC, &nbytes);
    }
    else if (options->direction == 1) /* decode only */
    {
        apiG729FPDecoder_Alloc(G729I_CODEC, &nbytes);
    } else {
        return USC_NoOperation;
    }
    pBanks->nbytes = nbytes + sizeof(G729_Handle_Header); /* include header in handle */
    return USC_NoError;
}

static USC_Status MemAlloc_G729A(const USC_Option *options, USC_MemBank *pBanks)
{
    unsigned int nbytes;
    int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(pBanks==NULL) return USC_BadDataPointer;

    pBanks->pMem = NULL;

    bitrate_idx = CheckRate_G729A(options->modes.bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

    if (options->direction == 0) /* encode only */
    {
        apiG729FPEncoder_Alloc((G729Codec_Type)bitrate_idx, &nbytes);
    }
    else if (options->direction == 1) /* decode only */
    {
        apiG729FPDecoder_Alloc((G729Codec_Type)bitrate_idx, &nbytes);
    } else {
        return USC_NoOperation;
    }
    pBanks->nbytes = nbytes + sizeof(G729_Handle_Header); /* include header in handle */
    return USC_NoError;
}

static USC_Status Init_G729I(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
    G729_Handle_Header *g729_header;
    int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(pBanks==NULL) return USC_BadDataPointer;
   if(pBanks->pMem==NULL) return USC_NotInitialized;
   if(pBanks->nbytes<=0) return USC_NotInitialized;
   if(handle==NULL) return USC_InvalidHandler;

    *handle = (USC_Handle*)pBanks->pMem;
    g729_header = (G729_Handle_Header*)*handle;

    bitrate_idx = CheckRate_G729I(options->modes.bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;
    g729_header->vad = options->modes.vad;
    g729_header->bitrate = options->modes.bitrate;
    g729_header->direction = options->direction;

    if (options->direction == 0) /* encode only */
    {
        G729FPEncoder_Obj *EncObj = (G729FPEncoder_Obj *)((char*)*handle + sizeof(G729_Handle_Header));
        apiG729FPEncoder_Init((G729FPEncoder_Obj*)EncObj,
        (G729Codec_Type)G729I_CODEC,(G729Encode_Mode)options->modes.vad);
    }
    else if (options->direction == 1) /* decode only */
    {
        G729FPDecoder_Obj *DecObj = (G729FPDecoder_Obj *)((char*)*handle + sizeof(G729_Handle_Header));
        apiG729FPDecoder_Init((G729FPDecoder_Obj*)DecObj, (G729Codec_Type)G729I_CODEC);
    } else {
        return USC_NoOperation;
    }
    return USC_NoError;
}

static USC_Status Init_G729A(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
    G729_Handle_Header *g729_header;
    int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(pBanks==NULL) return USC_BadDataPointer;
   if(pBanks->pMem==NULL) return USC_NotInitialized;
   if(pBanks->nbytes<=0) return USC_NotInitialized;
   if(handle==NULL) return USC_InvalidHandler;

    *handle = (USC_Handle*)pBanks->pMem;
    g729_header = (G729_Handle_Header*)*handle;

    bitrate_idx = CheckRate_G729A(options->modes.bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;
    g729_header->vad = options->modes.vad;
    g729_header->bitrate = options->modes.bitrate;
    g729_header->direction = options->direction;

    if (options->direction == 0) /* encode only */
    {
        G729FPEncoder_Obj *EncObj = (G729FPEncoder_Obj *)((char*)*handle + sizeof(G729_Handle_Header));
        apiG729FPEncoder_Init((G729FPEncoder_Obj*)EncObj,
        (G729Codec_Type)bitrate_idx,(G729Encode_Mode)options->modes.vad);
    }
    else if (options->direction == 1) /* decode only */
    {
        G729FPDecoder_Obj *DecObj = (G729FPDecoder_Obj *)((char*)*handle + sizeof(G729_Handle_Header));
        apiG729FPDecoder_Init((G729FPDecoder_Obj*)DecObj, (G729Codec_Type)bitrate_idx);
    } else {
        return USC_NoOperation;
    }
    return USC_NoError;
}

static USC_Status Reinit_G729I(const USC_Modes *modes, USC_Handle handle )
{
    G729_Handle_Header *g729_header;

⌨️ 快捷键说明

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