我正在尝试使用我的C程序中的libfaac将16位RAW PCM文件编码为MPEG-4 MAIN AAC文件。我不知道我做错了所以我得到的文件长2倍当我记录沉默时,大胆看起来像这样_ | _ | _ | _ | _当原始文件看起来像这样_ _ _ _ _ _
你能告诉我我做错了什么吗?这是我的代码。static void encodeAac( const char *infilename,const char *filename)
{
faacEncHandle codec;
faacEncConfigurationPtr conf;
SAMPLE* samples;
uint8_t* outbuf;
unsigned long* one;
unsigned long* two;
int outsize;
one=new unsigned long;
two = new unsigned long;
codec=faacEncOpen(SAMPLE_RATE,NUM_CHANNELS,one,two);
if(!codec){
error("Something went wrong");
return;
}
conf=faacEncGetCurrentConfiguration(codec);
conf->mpegVersion=MPEG4;
conf->aacObjectType=MAIN;
faacEncSetConfiguration(codec,conf);
FILE *f = fopen(filename, "wb");
FILE *fin=fopen(infilename,"rb");
if (!fin) {
error("could not open temporary file");
}
if (!f) {
error("could not open output file");
}
samples = new SAMPLE[*one];
outbuf = new uint8_t[*two];
while(fread(samples,sizeof(SAMPLE),*one,fin)){
outsize=faacEncEncode(codec,(int*)samples,*one,outbuf,*two);
fwrite(outbuf,sizeof(uint8_t),outsize,f);
}
while(outsize != 0){
outsize=faacEncEncode(codec,NULL,NULL,outbuf,*two);
fwrite(outbuf,sizeof(uint8_t),outsize,f);
}
fclose(f);
fclose(fin);
delete outbuf;
delete samples;
faacEncClose(codec);
}