Based on the analysis in the previous article, you need to implement several functions declared in aaccodechelper. H, as follows:
# Include "aaccodechelper. H"
# Include "faac. H"
Ulong nsamplerate = 11025; // Sampling Rate
Uint nchannels = 1; // number of audio channels
Uint npcmbitsize = 16; // number of single-sample digits
Ulong ninputsamples = 0;
Ulong nmaxoutputbytes = 0;
Faacenchandle hencoder;
Faacencconfigurationptr pconfiguration;
Byte * pbpcmbuffer;
Byte * pbaacbuffer;
Int32 npcmbuffersize;
Int32 nret = 0;
//////////////////
Int32 T = 0;
//////////////////
Void openfaacengine () {// open the faac Engine
Hencoder = faacencopen (nsamplerate, nchannels, & ninputsamples, & nmaxoutputbytes );
Pconfiguration = faacencgetcurrentconfiguration (hencoder );
Pconfiguration-> inputformat = faac_input_16bit;
Nret = faacencsetconfiguration (hencoder, pconfiguration );
Npcmbuffersize = ninputsamples * npcmbitsize/8;
Pbpcmbuffer = new byte [npcmbuffersize];
Pbaacbuffer = new byte [nmaxoutputbytes];
}
Void closefaacengine () {// disable the faac Engine
Nret = faacencclose (hencoder );
Delete [] pbpcmbuffer;
Delete [] pbaacbuffer;
}
Int wavtoaac (const char * wavdata, int wavdatalen, char * aacdata ){
/**
* Convert WAV audio data of the length of wavdatalen into AAC and write aacdata
* If AAC data is successfully returned, the value-1 is returned if an error occurs.
*/
If (hencoder = NULL ){
Return-1;
}
Int32 ninputsamples = 0;
Int32 readpcmbytesum = 0;
Int32 writeaacbytesum = 0;
Int32 naacencret = 0;
Int32 J = 0;
Int32 K = 0;
While (readpcmbytesum <wavdatalen ){
For (j = 0; j <npcmbuffersize; j ++ ){
* (Pbpcmbuffer + J) = * (wavdata + J + readpcmbytesum );
}
Readpcmbytesum + = npcmbuffersize;
Ninputsamples = npcmbuffersize/(npcmbitsize/8); // calculate the number of Input Samples
/**
* Call the faacencencode () function, which is skipped here
*/
For (k = 0; k <naacencret; k ++ ){
* (Aacdata + K + writeaacbytesum) = * (pbaacbuffer + k );
}
Writeaacbytesum + = naacencret;
Fprintf (stderr, "% d: faacencencode returns % d \ n", t ++, naacencret );
}
Return writeaacbytesum;
}
To be continued ~
PS: I wrote an article at the beginning. Please forgive me. If you have any questions or communication, you can add your YY: 301558660
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/7553317