IPB

Welcome Guest ( Log In | Register )

libfaac encoding problem, libfaac gets me weird output
hub2
post Jan 15 2013, 13:01
Post #1





Group: Members
Posts: 3
Joined: 7-January 13
Member No.: 105674



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

}
Go to the top of the page
+Quote Post
 
Start new topic
Replies (1 - 2)
nu774
post Jan 15 2013, 13:36
Post #2





Group: Developer
Posts: 528
Joined: 22-November 10
From: Japan
Member No.: 85902



If your input is 16bit PCM and type of SAMPLE is int16_t or short, probably you need
CODE
conf->inputFormat = FAAC_INPUT_16BIT;

before passing conf to faacEncSetConfiguration().
Why don't you read faac and frontend source?
Go to the top of the page
+Quote Post
hub2
post Jan 15 2013, 13:43
Post #3





Group: Members
Posts: 3
Joined: 7-January 13
Member No.: 105674



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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd September 2014 - 03:00