📄 uscg711.c
字号:
/*/////////////////////////////////////////////////////////////////////////////
//
// 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: G711 speech codec: USC functions.
//
*/
#include <string.h>
#include <usc.h>
#include "owng711.h"
#include "g711api.h"
static USC_Status GetInfoA(USC_Handle handle, USC_CodecInfo *pInfo);
static USC_Status GetInfoU(USC_Handle handle, USC_CodecInfo *pInfo);
static USC_Status NumAlloc(const USC_Option *options, int *nbanks);
static USC_Status MemAlloc(const USC_Option *options, USC_MemBank *pBanks);
static USC_Status InitA(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle);
static USC_Status InitU(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle);
static USC_Status ReinitA(const USC_Modes *modes, USC_Handle handle );
static USC_Status ReinitU(const USC_Modes *modes, USC_Handle handle );
static USC_Status ControlA(const USC_Modes *modes, USC_Handle handle );
static USC_Status ControlU(const USC_Modes *modes, USC_Handle handle );
static USC_Status Encode(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out);
static USC_Status Decode(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out);
static USC_Status GetOutStreamSize(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 80
#define G711_NUM_RATES 1
#define G711_SPEECH_FRAME 80
#define G711_BITS_PER_SAMPLE 16
#define G711_SAMPLE_FREQUENCE 8000
typedef struct {
int direction;
int pf;
int vad;
int law; /* 0 - pcm, 1 - aLaw, 2 -muLaw */
} G711_Handle_Header;
/* global usc vector table */
USC_Fxns USC_G711A_Fxns=
{
{
USC_Codec,
GetInfoA,
NumAlloc,
MemAlloc,
InitA,
ReinitA,
ControlA
},
Encode,
Decode,
GetOutStreamSize,
SetFrameSize
};
USC_Fxns USC_G711U_Fxns=
{
{
USC_Codec,
GetInfoU,
NumAlloc,
MemAlloc,
InitU,
ReinitU,
ControlU
},
Encode,
Decode,
GetOutStreamSize,
SetFrameSize
};
static __ALIGN32 CONST USC_Rates pTblRates_G711[G711_NUM_RATES]={
{64000}
};
static USC_Status GetInfoA(USC_Handle handle, USC_CodecInfo *pInfo)
{
G711_Handle_Header *g711_header;
pInfo->name = "G711A";
pInfo->framesize = G711_SPEECH_FRAME*sizeof(short);
if (handle == NULL) {
pInfo->params.direction = 0;
pInfo->params.law = G711_ALAW_CODEC;
pInfo->params.modes.bitrate = 64000;
pInfo->params.modes.vad = 1;
pInfo->params.modes.pf = 1;
} else {
g711_header = (G711_Handle_Header*)handle;
pInfo->params.direction = g711_header->direction;
pInfo->params.law = g711_header->law;
pInfo->params.modes.vad = g711_header->vad;
pInfo->params.modes.pf = g711_header->pf;
}
pInfo->maxbitsize = BITSTREAM_SIZE;
pInfo->pcmType.sample_frequency = G711_SAMPLE_FREQUENCE;
pInfo->pcmType.bitPerSample = G711_BITS_PER_SAMPLE;
pInfo->params.modes.truncate = 0;
pInfo->params.modes.hpf = 0;
pInfo->nRates = G711_NUM_RATES;
pInfo->pRateTbl = (const USC_Rates *)&pTblRates_G711;
return USC_NoError;
}
static USC_Status GetInfoU(USC_Handle handle, USC_CodecInfo *pInfo)
{
G711_Handle_Header *g711_header;
pInfo->name = "G711U";
pInfo->framesize = G711_SPEECH_FRAME*sizeof(short);
if (handle == NULL) {
pInfo->params.direction = 0;
pInfo->params.law = G711_ALAW_CODEC;
pInfo->params.modes.bitrate = 64000;
pInfo->params.modes.vad = 1;
pInfo->params.modes.pf = 1;
} else {
g711_header = (G711_Handle_Header*)handle;
pInfo->params.direction = g711_header->direction;
pInfo->params.law = g711_header->law;
pInfo->params.modes.vad = g711_header->vad;
pInfo->params.modes.pf = g711_header->pf;
}
pInfo->maxbitsize = BITSTREAM_SIZE;
pInfo->pcmType.sample_frequency = G711_SAMPLE_FREQUENCE;
pInfo->pcmType.bitPerSample = G711_BITS_PER_SAMPLE;
pInfo->params.modes.truncate = 0;
pInfo->params.modes.hpf = 0;
pInfo->nRates = G711_NUM_RATES;
pInfo->pRateTbl = (const USC_Rates *)&pTblRates_G711;
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(const USC_Option *options, USC_MemBank *pBanks)
{
unsigned int nbytes;
if(options==NULL) return USC_BadDataPointer;
if(pBanks==NULL) return USC_BadDataPointer;
pBanks->pMem = NULL;
if (options->direction == 0) { /* encode only */
apiG711Encoder_Alloc(&nbytes);
pBanks->nbytes = nbytes+sizeof(G711_Handle_Header); /* include direction in handle */
} else if (options->direction == 1) { /* decode only */
apiG711Decoder_Alloc(&nbytes);
pBanks->nbytes = nbytes+sizeof(G711_Handle_Header); /* include direction in handle */
} else {
return USC_NoOperation;
}
return USC_NoError;
}
static USC_Status InitA(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
G711_Handle_Header *g711_header;
if(options==NULL) return USC_BadDataPointer;
if(pBanks==NULL) return USC_BadDataPointer;
if(handle==NULL) return USC_BadDataPointer;
if(pBanks->pMem==NULL) return USC_NotInitialized;
if(pBanks->nbytes<=0) return USC_NotInitialized;
if(options->modes.vad > 1) return USC_UnsupportedVADType;
*handle = (USC_Handle*)pBanks->pMem;
g711_header = (G711_Handle_Header*)*handle;
g711_header->direction = options->direction;
g711_header->law = G711_ALAW_CODEC;
g711_header->vad = options->modes.vad;
g711_header->pf = options->modes.pf;
if (options->direction == 0) { /* encode only */
G711Encoder_Obj *EncObj = (G711Encoder_Obj *)((char*)*handle + sizeof(G711_Handle_Header));
apiG711Encoder_Init((G711Encoder_Obj*)EncObj,
(G711Codec_Type)G711_ALAW_CODEC,(G711Encode_Mode)options->modes.vad);
} else if (options->direction == 1) { /* decode only */
G711Decoder_Obj *DecObj = (G711Decoder_Obj *)((char*)*handle + sizeof(G711_Handle_Header));
apiG711Decoder_Init((G711Decoder_Obj*)DecObj,
(G711Codec_Type)G711_ALAW_CODEC);
apiG711Decoder_Mode(DecObj, g711_header->pf);
} else {
return USC_NoOperation;
}
return USC_NoError;
}
static USC_Status InitU(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
G711_Handle_Header *g711_header;
if(options==NULL) return USC_BadDataPointer;
if(pBanks==NULL) return USC_BadDataPointer;
if(handle==NULL) return USC_BadDataPointer;
if(pBanks->pMem==NULL) return USC_NotInitialized;
if(pBanks->nbytes<=0) return USC_NotInitialized;
if(options->modes.vad > 1) return USC_UnsupportedVADType;
*handle = (USC_Handle*)pBanks->pMem;
g711_header = (G711_Handle_Header*)*handle;
g711_header->direction = options->direction;
g711_header->law = G711_MULAW_CODEC;
g711_header->vad = options->modes.vad;
g711_header->pf = options->modes.pf;
if (options->direction == 0) { /* encode only */
G711Encoder_Obj *EncObj = (G711Encoder_Obj *)((char*)*handle + sizeof(G711_Handle_Header));
apiG711Encoder_Init((G711Encoder_Obj*)EncObj,
(G711Codec_Type)G711_MULAW_CODEC,(G711Encode_Mode)options->modes.vad);
}
else if (options->direction == 1) { /* decode only */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -