我正在尝试在我的 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);
}