FAAC编码问题
红茶加红糖 2012-01-13 04:25:34 要做一个实时采集pcm码流,并且编码生成aac文件。
码流采集参数:44100hz、2通道、立体声。可以将采集到的音频数据存储为wav文件。
但是将采集到的音频数据编码时,编码后的音频文件失真严重,基本听不清楚原音
采集过程省略
myFormat = faacEncGetCurrentConfiguration(hEncoder);
myFormat->aacObjectType = LOW;
myFormat->mpegVersion = MPEG2;
myFormat->useTns = 0;//DEFAULT_TNS;
myFormat->shortctl=SHORTCTL_NORMAL;
myFormat->inputFormat=FAAC_INPUT_16BIT;
myFormat->outputFormat=1;//ADTS_STREAM;
//myFormat->bitRate???这个应该怎么设
if (!faacEncSetConfiguration(hEncoder, myFormat))
{
fprintf(stderr, "Unsupported output format!\n");
}
pcmbuf = (short*)malloc(samplesInput*sizeof(short));//samplesInput = 2048
bitbuf = (unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char));//maxBytesOutput = 1536
while(1)
{
r = snd_pcm_readi(handle, data, count);
printf("r = %d\n",r);//有时候为1225,有时候为-EPIPE
samplesRead = read_int16(pcmbuf, samplesInput, data_buf);
bytesWritten = faacEncEncode(hEncoder,(int32_t *)pcmbuf ,samplesRead ,bitbuf,maxBytesOutput);
if (bytesWritten < 0)
{
fprintf(stderr, "faacEncEncode() failed\n");
break ;
}
fwrite(bitbuf, 1, bytesWritten, outfile);
}
大家帮忙看看,这个流程对不对,哪里有问题呀???
谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!