📄 dec_lpc.c
字号:
if ( (ExcitationMode == MultiPulseExc) && (SampleRateMode==fs16kHz) ) {
Wideband_VQ = Optimized_VQ;
}
/* -------------------------------------------------------------------*/
/* Memory allocation */
/* -------------------------------------------------------------------*/
hdrStream = BsOpenBufferRead(bitHeader);
/* ---------------------------------------------------------------- */
/* Conversion of parameters from float to longs */
/* ---------------------------------------------------------------- */
bit_rate = (long)(bitRate+.5);
sampling_frequency = (long)(fSample+.5);
/* ---------------------------------------------------------------- */
/* Decoder Initialisation */
/* ---------------------------------------------------------------- */
celp_initialisation_decoder(
hdrStream, bit_rate, complexity_level, reduced_order, DecEnhStage, DecBwsMode, PostFilterSW, &frame_size, &n_subframes, &sbfrm_size,
&lpc_order,&num_lpc_indices,&num_shape_cbks,&num_gain_cbks,&org_frame_bit_allocation,
&ExcitationMode,
&SampleRateMode, &QuantizationMode, &FineRateControl, &LosslessCodingMode, &RPE_configuration,
&Wideband_VQ, &MPE_Configuration, &NumEnhLayers, &BandwidthScalabilityMode, &BWS_configuration,
&InstanceContext,mp4ffFlag);
*frameNumSample = frame_size;
*delayNumSample = 0;
BsClose(hdrStream);
}
void DecLpcInitNew (
char *decPara, /* in: decoder parameter string */
FRAME_DATA* fD,
LPC_DATA* lpcData,
int layer
) /* out: decoder delay (num samples) */
{
int parac;
char **parav;
int result;
int numChannel;
#if 0
int MPE_conf;
#endif
double frameLengthTime;
#if 0
BsBitBuffer *bitHeader;
#endif
BsBitStream *hdrStream=NULL;
AUDIO_SPECIFIC_CONFIG* audSpC ;
int mp4ffFlag =1;
lpcData->coreBitBuf = BsAllocBuffer( 4000 ); /* just some large number. For G729 required: 160 */
if((lpcData->sampleBuf=(float**)(malloc(1 * sizeof (float*) )))==NULL)
CommonExit(1, "Memory allocation error in enc_lpc");
if((lpcData->sampleBuf[0] =(float*)malloc(sizeof(float)*1024))==NULL)
CommonExit(1, "Memory allocation error in enc_lpc");
audSpC = &fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig;
#if 0
bitHeader=NULL;
#endif
switch (audSpC->channelConfiguration.value) {
case 1 :numChannel=1;
break;
default: CommonExit(1,"wrong channel config");
}
/* evalute decoder parameter string */
parav = CmdLineParseString(decPara,SEPACHAR,¶c);
result = CmdLineEval(parac,parav,NULL,switchList,1,NULL);
if (result==1)
{
DecLpcInfo(stdout);
exit (1);
}
if (strstr(decPara, "-celp_sys") != NULL)
sysFlag = 1;
if ( (ExcitationMode == MultiPulseExc) && (SampleRateMode==fs16kHz) ) {
Wideband_VQ = Optimized_VQ;
}
#if 0
/* -------------------------------------------------------------------*/
/* Memory allocation */
/* -------------------------------------------------------------------*/
if (bitHeader != NULL)
hdrStream = BsOpenBufferRead(bitHeader);
/* ---------------------------------------------------------------- */
/* Conversion of parameters from float to longs */
/* ---------------------------------------------------------------- */
bit_rate = (long)(fD->od->ESDescriptor[layer]->DecConfigDescr.avgBitrate.value +.5);
sampling_frequency = (long)(samplFreqIndex[
fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value]+.5);
if (sampling_frequency==7350) {
sampling_frequency=8000;
}
MPE_conf=fD->od->ESDescriptor[0]->DecConfigDescr\
.audioSpecificConfig.specConf.celpSpecificConfig.MPE_Configuration.value;
lpcData->frameNumSample=MPE_Table[MPE_conf];
frameLengthTime=(double)lpcData->frameNumSample/(double)sampling_frequency;
lpcData->bitsPerFrame = (int)(bit_rate*frameLengthTime);
#endif
if (mp4ffFlag==1) {
int layer=0;
CELP_SPECIFIC_CONFIG *celpConf=
&fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.celpSpecificConfig;
ExcitationMode = celpConf->excitationMode.value ;
SampleRateMode = celpConf->sampleRateMode.value ;
FineRateControl = celpConf->fineRateControl.value;
RPE_configuration = celpConf->RPE_Configuration.value;
MPE_Configuration = celpConf->MPE_Configuration.value ;
NumEnhLayers = celpConf->numEnhLayers.value;
BandwidthScalabilityMode = celpConf->bandwidthScalabilityMode.value;
/* celp enhancement layer is not yet supported */
BWS_configuration = 0; /* in celpConf of celp enhancement layer */
if ( NumEnhLayers != 0 || BandwidthScalabilityMode != 0 ) {
CommonExit(1,"celp enhancement layer is not yet supported");
}
}
/* ---------------------------------------------------------------- */
/* Decoder Initialisation */
/* ---------------------------------------------------------------- */
celp_initialisation_decoder(
hdrStream,
bit_rate,
complexity_level,
reduced_order,
DecEnhStage,
DecBwsMode,
PostFilterSW,
&frame_size,
&n_subframes,
&sbfrm_size,
&lpc_order,
&num_lpc_indices,
&num_shape_cbks,
&num_gain_cbks,
&org_frame_bit_allocation,
&ExcitationMode,
&SampleRateMode,
&QuantizationMode,
&FineRateControl,
&LosslessCodingMode,
&RPE_configuration,
&Wideband_VQ,
&MPE_Configuration,
&NumEnhLayers,
&BandwidthScalabilityMode,
&BWS_configuration,
&InstanceContext,
mp4ffFlag);
lpcData->frameNumSample = frame_size;
lpcData->delayNumSample = 0;
bit_rate = (long)(fD->od->ESDescriptor[layer]->DecConfigDescr.avgBitrate.value +.5);
sampling_frequency = (long)(samplFreqIndex[
fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value]+.5);
if (sampling_frequency==7350) {
sampling_frequency=8000;
}
frameLengthTime=(double)lpcData->frameNumSample/(double)sampling_frequency;
lpcData->bitsPerFrame = (int)(bit_rate*frameLengthTime);
/* free(lpcData->p_bitstream); we use the memory in DecLpcFrameNew*/
}
/* ------------------------------------------------------------------- */
/* DecLpcFrame() */
/* Decode one bit stream frame into one audio frame with */
/* LPC-based decoder core. */
/* ------------------------------------------------------------------- */
void DecLpcFrame (
BsBitBuffer *bitBuf, /* in: bit stream frame */
float **sampleBuf, /* out: audio frame samples */
/* sampleBuf[numChannel][frameNumSample] */
int *usedNumBit) /* out: num bits used for this frame */
{
/* ----------------------------------------------------------------- */
/* Memory allocation */
/* ----------------------------------------------------------------- */
BsBitStream *bitStream = BsOpenBufferRead(bitBuf);
//printf("\nframe size\n=%d",frame_size);
//printf("\nsub frame size\n=%d",sbfrm_size);
//printf("\n n_subframes\n=%d",n_subframes);
/* ----------------------------------------------------------------- */
/*Call Decoder */
/* ----------------------------------------------------------------- */
celp_decoder( bitStream, sampleBuf,
ExcitationMode,
SampleRateMode, QuantizationMode, FineRateControl, LosslessCodingMode,
RPE_configuration, Wideband_VQ, MPE_Configuration, NumEnhLayers, BandwidthScalabilityMode,
BWS_configuration, frame_size, n_subframes, sbfrm_size, lpc_order,
num_lpc_indices, num_shape_cbks, num_gain_cbks,
org_frame_bit_allocation,
InstanceContext );
*usedNumBit = BsCurrentBit(bitStream);
BsCloseRemove(bitStream,1);
#if 0
{
BsBitStream* layer_stream ;
layer_stream= BsOpenBufferRead(bitBuf);
BsGetSkip(layer_stream,p_bitstream->valid_bits);
BsCloseRemove(layer_stream,1);
}
#endif
}
void DecLpcFrameNew (
BsBitBuffer *bitBuf, /* in: bit stream frame */
float **sampleBuf, /* out: audio frame samples */
/* sampleBuf[numChannel][frameNumSample] */
LPC_DATA* lpcData,
int *usedNumBit) /* out: num bits used for this frame */
{
BsBitStream *bitStream = BsOpenBufferRead(bitBuf) ;
/* ----------------------------------------------------------------- */
/*Call Decoder */
/* ----------------------------------------------------------------- */
celp_decoder( bitStream, sampleBuf,
ExcitationMode,
SampleRateMode, QuantizationMode, FineRateControl, LosslessCodingMode,
RPE_configuration, Wideband_VQ, MPE_Configuration, NumEnhLayers, BandwidthScalabilityMode,
BWS_configuration, frame_size, n_subframes, sbfrm_size, lpc_order,
num_lpc_indices, num_shape_cbks, num_gain_cbks,
org_frame_bit_allocation,
InstanceContext );
*usedNumBit = BsCurrentBit(bitStream);
if (sysFlag) {
int celp_sys_align;
celp_sys_align = 8 - (*usedNumBit % 8);
if (celp_sys_align == 8) celp_sys_align = 0;
BsGetSkip(bitStream,celp_sys_align);
*usedNumBit = BsCurrentBit(bitStream);
}
BsCloseRemove(bitStream,1);
/* BsClose(bitStream); */
#pragma warning "BsCloseRemove must be used instead of BsClose"
}
/* ------------------------------------------------------------------- */
/* DeLpcrFree() */
/* Free memory allocated by LPC-based decoder core. */
/* ------------------------------------------------------------------- */
void DecLpcFree ()
{
celp_close_decoder(ExcitationMode, SampleRateMode, BandwidthScalabilityMode, org_frame_bit_allocation, &InstanceContext);
}
int lpcframelength( CELP_SPECIFIC_CONFIG *celpConf )
{
int frame_size;
if ( celpConf->excitationMode.value == RegularPulseExc ) {
if (celpConf->RPE_Configuration.value == 0) {
frame_size = FIFTEEN_MS;
} else if (celpConf->RPE_Configuration.value == 1) {
frame_size = TEN_MS;
} else if (celpConf->RPE_Configuration.value == 2) {
frame_size = FIFTEEN_MS;
} else if (celpConf->RPE_Configuration.value == 3) {
frame_size = FIFTEEN_MS;
} else {
fprintf(stderr, "ERROR: Illegal RPE Configuration\n");
exit(1);
}
}
if ( celpConf->excitationMode.value == MultiPulseExc ) {
if ( celpConf->sampleRateMode.value == fs8kHz) {
if ( celpConf->MPE_Configuration.value < 3 ) {
frame_size = NEC_FRAME40MS;
}
if ( celpConf->MPE_Configuration.value >= 3 &&
celpConf->MPE_Configuration.value < 6 ) {
frame_size = NEC_FRAME30MS;
}
if ( celpConf->MPE_Configuration.value >= 6 &&
celpConf->MPE_Configuration.value < 22 ) {
frame_size = NEC_FRAME20MS;
}
if ( celpConf->MPE_Configuration.value >= 22 &&
celpConf->MPE_Configuration.value < 27 ) {
frame_size = NEC_FRAME10MS;
}
if ( celpConf->MPE_Configuration.value == 27 ) {
frame_size = NEC_FRAME30MS;
}
if ( celpConf->MPE_Configuration.value > 27 ) {
fprintf(stderr,"Error: Illegal MPE Configuration.\n");
exit(1);
}
if ( celpConf->bandwidthScalabilityMode.value == ON ) {
frame_size = 2 * frame_size;
}
}
if ( celpConf->sampleRateMode.value == fs16kHz) {
if ( celpConf->MPE_Configuration.value < 16 ) {
frame_size = NEC_FRAME20MS_FRQ16;
}
if ( celpConf->MPE_Configuration.value >= 16 &&
celpConf->MPE_Configuration.value < 32 ) {
frame_size = NEC_FRAME10MS_FRQ16;
}
if ( celpConf->MPE_Configuration.value == 7 ||
celpConf->MPE_Configuration.value == 23 ) {
fprintf(stderr,"Error: Illegal BitRate configuration.\n");
exit(1);
}
}
}
return( frame_size );
}
/* end of dec_lpc.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -