HydrogenAudio

Lossy Audio Compression => AAC => AAC - Tech => Topic started by: hub2 on 2013-01-15 12:01:50

Title: libfaac encoding problem
Post by: hub2 on 2013-01-15 12:01:50
Hi,
I'm making a C++ program that recordes audio from microphone and encodes it to MPEG4 MAIN AAC file . I made a function for encoding to AAC using libfaac and i got weird output file.I don't know what i'm doing wrong .Could you tell me what's wrong in my function.This is my RAW PCM 16-bit file File (http://www.4shared.com/file/mZ9bNjkP/temp0.html) and this is output file File (http://www.4shared.com/file/bd3U9BLo/audio0.html)
Here's my code.
Code: [Select]
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);
    

}
Title: libfaac encoding problem
Post by: nu774 on 2013-01-15 12:36:11
If your input is 16bit PCM and type of SAMPLE is int16_t or short, probably you need
Code: [Select]
conf->inputFormat = FAAC_INPUT_16BIT;

before passing conf to faacEncSetConfiguration().
Why don't you read faac and frontend source?
Title: libfaac encoding problem
Post by: hub2 on 2013-01-15 12:43:14
Thanks nu774 that helped. I read pdf that was with libfaac and there in faacEncConfiguration reference wasn't anything about inputFormat . Thanks i'll read source code before asking again.