Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: libfaac encoding problem (Read 4333 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

libfaac encoding problem

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 and this is output file File
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);
    

}

libfaac encoding problem

Reply #1
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?

 

libfaac encoding problem

Reply #2
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.