【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,celp.cpp,希望对大家有所帮助!
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2000, 2001. All Rights Reserved.
*
* Contributor(s):
* Massimo Villari mvillari@cisco.com
*/
#include "celp.h"
#include "bitstreamStruct.h"
#include "dec_lpc.h"
#include "celp_decoder.h"
//#include "../include/audio.h"
//#include "../include/austream.h"
#include <mp4util/mpeg4_audio_config.h>
#include <mp4util/mpeg4_sdp.h>
#include <mp4v2/mp4.h>
#define DEBUG_SYNC 2
#define bit2byte(a) (((a)+8-1)/8)
const char *celplib="celp";
/*
* Create CELP Codec class
*/
static codec_data_t *celp_codec_create (format_list_t *media_fmt,
audio_info_t *audio,
const uint8_t *userdata,
uint32_t userdata_size,
audio_vft_t *vft,
void *ifptr)
{
int i;
celp_codec_t *celp;
celp = (celp_codec_t *)malloc(sizeof(celp_codec_t));
memset(celp, 0, sizeof(celp_codec_t));
#if 1
celp->m_vft = vft;
celp->m_ifptr = ifptr;
fmtp_parse_t *fmtp = NULL;
BsInit(0, 0, 0);
// Start setting up CELP stuff...
celp->m_resync_with_header = 1;
celp->m_record_sync_time = 1;
celp->m_celp_inited = 0;
celp->m_audio_inited = 0;
//celp->m_temp_buff = (float *)malloc(4096);
// Use media_fmt to indicate that we're streaming.
if (media_fmt != NULL) {
// haven't checked for null buffer
// This is not necessarilly right - it is, for the most part, but
// we should be reading the fmtp statement, and looking at the config.
// (like we do below in the userdata section...
celp->m_freq = media_fmt->rtpmap->clock_rate;
fmtp = parse_fmtp_for_
mpeg4(media_fmt->fmt_param, vft->log_msg);
if (fmtp != NULL) {
userdata = fmtp->config_binary;
userdata_size = fmtp->config_binary_len;
}
} else {
if (audio != NULL) {
celp->m_freq = audio->freq;
} else {
celp->m_freq = 44100;
}
}
//celp->m_chans = 1; // this may be wrong - the isma spec, Appendix A.1.1 of
// Appendix H says the default is 1 channel...
//celp->m_output_frame_size = 2048;
// celp->m_object_type = 8;CELP AACMAIN;
mpeg4_audio_config_t audio_config;
if (userdata != NULL || fmtp != NULL) {
celp_message(LOG_DEBUG, celplib, "config len %d %02x %02x %02x %02x",
userdata_size, userdata[0], userdata[1], userdata[2],
userdata[3]);
decode_mpeg4_audio_config(userdata, userdata_size, &audio_config);
celp->m_object_type = audio_config.audio_object_type;
celp->m_freq = audio_config.frequency;
celp->m_chans = audio_config.channels;
}
// write
BsBitBuffer *bitHeader;
BsBitStream *hdrStream;
bitHeader=BsAllocBuffer(userdata_size * 8);
//wmay removed
bitHeader->numBit=userdata_size*8;
bitHeader->size=userdata_size*8;
memcpy(bitHeader->data,userdata,userdata_size);
hdrStream = BsOpenBufferRead(bitHeader);
BsGetSkip (hdrStream,userdata_size*8-audio_config.codec.celp.NumOfBitsInBuffer);
BsBitBuffer *bBuffer=BsAllocBuffer(userdata_size*8);
BsGetBuffer (hdrStream, bBuffer,audio_config.codec.celp.NumOfBitsInBuffer);
int delayNumSample;
DecLpcInit(celp->m_chans,celp->m_freq,0,NULL,
bBuffer ,&celp->m_output_frame_size,&delayNumSample);
celp->m_msec_per_frame *= M_LLU;
celp->m_msec_per_frame /= celp->m_freq;
celp->m_last=userdata_size;
BsFreeBuffer (bitHeader);
BsFreeBuffer (bBuffer);
celp->m_sampleBuf=(float**)malloc(celp->m_chans*sizeof(float*));
for(i=0;i<celp->m_chans;i++)
// wmay - added 2 times
celp->m_sampleBuf[i]=(float*)malloc(2*celp->m_output_frame_size*sizeof(float));
celp->m_bufs =
(uint16_t *)malloc(sizeof(uint16_t) * 2 * celp->m_chans * celp->m_output_frame_size);
//celp->audiFile = AudioOpenWrite("out1.au",".au",
// celp->m_chans,celp->m_freq);
celp_message(LOG_INFO, celplib,"CELP object type is %d", celp->m_object_type);
//celp_message(LOG_INFO, celplib,"CELP channel are %d", celp->m_chans );
celp_message(LOG_INFO, celplib, "Setting freq to %d", celp->m_freq);
celp_message(LOG_INFO, celplib, "output frame size is %d", celp->m