My program was changed based on the faac example in the frontend directory in the faac 1.28 library.
The following is the procedure of running the program:
First, call faacenchandle hencoder = faacencopen (samplerate, channels, & samplesinput,
& Maxbytesoutput );
1.Open the AAC encoding engine and create an AAC encoding handle.
The samplerate parameter is the sampling rate of the audio PCM stream to be encoded, and channels is the number of channels of the audio PCM stream to be encoded (the original example program reads this information from the wav file ), sampleinput is used for encoding, meaning the number of samples to be encoded each time. The maxbytesoutput parameter is the maximum number of bytes output when encoding.
2.Then, set some encoding parameters, such
Int version = MPEG4; // sets the version. You must use MPEG4 to record MP4 files.
Int objecttype = low; // encoding type
Int midside = 1; // m/s Encoding
Int usetns = default_tns; // filter for Temporal Noise Shaping and TNS
Int export CTL = export ctl_normal;
Int inputformat = faac_input_16bit; // input data type
Int outputformat = raw_stream; // raw stream is used for recording MP4 files. This parameter can be set when the encoding is correct.
// Set it to ADTs transmission stream and write the AAC stream into the. AAC file. If the encoding is correct
// You can play the video with a pause.
Other parameters can be set according to the example program.
After setting the parameters, call faacencsetconfiguration (hencoder, aacformat) to set the encoding parameters.
3.If the encoded AAC stream is to be written to an MP4 file, call
Faacencgetdecoderspecificinfo (hencoder, & (ASC), & (asclength); // obtain the decoding information.
// (Mpeg4ip MP4 for recording)
This function supports MPEG4. The obtained ASC and acslength data are used to record MP4 (mpegip Library) files.
4.Then the encoding is completed. samplesinput * channels * (8 bits/8 bits) are read from the real-time PCM audio queue ),
PCM Data of the number of bytes. Then, change the PCM stream to the storage space. I converted it to 16 bits.
You can write a function based on the example program. This is one I wrote,
Size_t read_int16 (aacinfo * SNDF, int16_t * outbuf, size_t num, unsigned char * inputbuf)
{
Size_t I = 0, j = 0;
Unsigned char bufi [8];
While (I <num)
{
Memcpy (bufi, inputbuf + J, SNDF-> samplebytes );
J + = SNDF-> samplebytes;
Int16_t S = (int16_t *) bufi) [0];
Outbuf [I] = s;
I ++;
}
Return I;
}
You can also write a read_float32 (aacinfo * SNDF, float * outbuf, size_t num, unsigned char * inputbuf ),
And size_t read_int24 (aacinfo * SNDF, int32_t * outbuf, size_t num, unsigned char * inputbuf ).
Call
Byteswritten = faacencencode (hencoder,
(Int *) pcmbuf,
Samplesinput,
Outbuff,
Maxbytesoutput );
Encoding: pcmbuf is the converted PCM stream data, samplesinput is the number of input samples obtained when faacencopen is called, and outbuff is the encoded data buff, maxbytesoutput is the maximum number of output bytes when faacencopen is called. Then, each time you get the encoded AAC data stream from outbuff, you can put it in the data queue. If you want to record MP4 files, after the encoded samplesinput (one frame) Sample count, put the timestamp (mpegip library for audio and video synchronization) and put it in the output queue. If you want to test whether the AAC stream of the encoding is correct, set the output format to adts_stream, and write the AAC data to the. AAC file to check whether the stream can be played in a closed loop.
5.Release the resource and call faacencclose (hencoder );