0

I'm trying to encode a 16-bit RAW PCM file to MPEG-4 MAIN AAC File using libfaac in my C program.I don't know what i'm doing wrong so i get 2 times longer file and in audacity when i record silence it looks like this _| _| _| _| _ when raw file looks like this _ _ _ _ _ _

Could you tell me what i'm doing wrong ? Here's my code.

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);


}
hub2
  • 11
  • 1
  • 4
  • 1
    Start by examining the code you have. Explain why you do `unsigned long* one; one=new unsigned long;` and figure out what you _should_ do. Also, `new` and `delete` are not available in C, but in C++. – HonkyTonk Jan 15 '13 at 13:47
  • Thanks but i figured it out I just hadn't set inputType. But thanks to that I learned to read source code because in reference there wasn't anything about that. – hub2 Jan 15 '13 at 15:22

0 Answers0