A small program uses faad to decode AAC audio and can only decode the frames encapsulated by ADTs. Compiled programs can be downloaded from here: http://download.csdn.net/detail/gavinr/3782154
/*** Faaddec. C * use faad library to decode AAC, only can decode frame with ADTs head */# include <stdio. h> # include <memory. h> # include "faad. H "# define frame_max_len 1024*5 # define buffer_max_len 1024*1024 void show_usage () {printf (" usage \ nfaaddec src_file dst_file ");} /*** fetch one ADTs frame */INT get_one_adts_frame (unsigned char * buffer, size_t buf_size, unsigned char * data, size_t * data_size) {s Ize_t size = 0; If (! Buffer |! Data |! Data_size) {return-1;} while (1) {If (buf_size <7) {return-1;} If (buffer [0] = 0xff) & (buffer [1] & 0xf0) = 0xf0) {size | = (buffer [3] & 0x03) <11 ); // high 2 bit size | = buffer [4] <3; // middle 8 bit size | = (buffer [5] & 0xe0)> 5 ); // low 3bit break;} -- buf_size; ++ buffer;} If (buf_size <size) {return-1;} memcpy (data, buffer, size ); * data_size = size; return 0;} int main (INT argc, Char * argv []) {static unsigned char frame [frame_max_len]; static unsigned char buffer [buffer_max_len] = {0}; char src_file [128] = {0 }; char dst_file [128] = {0}; file * ifile = NULL; file * ofile = NULL; unsigned long samplerate; unsigned char channels; neaacdechandle decoder = 0; size_t data_size = 0; size_t size = 0; neaacdecframeinfo frame_info; unsigned char * input_data = buffer; unsigned char * Pcm_data = NULL; // analyze parameter if (argc <3) {show_usage (); Return-1 ;}sscanf (argv [1], "% s", src_file ); sscanf (argv [2], "% s", dst_file); ifile = fopen (src_file, "rb"); ofile = fopen (dst_file, "WB"); If (! Ifile |! Ofile) {printf ("source or destination file"); Return-1;} data_size = fread (buffer, 1, buffer_max_len, ifile ); // open decoder = neaacdecopen (); If (get_one_adts_frame (buffer, data_size, frame, & size) <0) {return-1;} // initialize decoder neaacdecinit (decoder, frame, size, & samplerate, & channels); printf ("samplerate % d, channels % d \ n", samplerate, channels); While (get_one_adts_frame (input_data, data_size, frame, & size) = 0) {// printf ("frame size % d \ n", size); // decode ADTs frame pcm_data = (unsigned char *) neaacdecdecode (decoder, & frame_info, frame, size); If (frame_info.error> 0) {printf ("% s \ n", neaacdecgeterrormessage (frame_info.error ));} else if (pcm_data & frame_info.samples> 0) {printf ("frame info: bytesconsumed % d, channels % d, header_type % d \ object_type % d, samples % d, samplerate % d \ n ", parameters, frame_info.channels, channels, frame_info.object_type, frame_info.samples, parameters); fwrite (pcm_data, 1, frame_info.samples * frame_info.channels, ofile ); // two channels fflush (ofile);} data_size-= size; input_data + = size;} neaacdecclose (decoder); fclose (ifile); fclose (ofile ); return 0 ;}