首先應該在自己的工程中包含以下三個庫:
- mad_stream stream;
- mad_frame frame;
- mad_synth synth;
- mad_stream_init(&stream);
- mad_frame_init(&frame);
- mad_synth_init(&synth);
- mad_stream_buffer(&stream, buffer, buffer_size);
- mad_frame_decode(&frame, &stream);
- id3_tag_query(stream.this_frame, stream.bufend - stream.this_frame);
- if(tagsize > 0)
- {
- mad_stream_skip(&stream, tagsize);
- }
- mad_synth_frame(&synth, &frame);
- for(int i = 0; i < (int)synth.pcm.length; i++)
- {
- sample0 = audio_linear_dither(16, synth.pcm.samples[0][i], &left_dither, &stats);
- sample1 = audio_linear_dither(16, synth.pcm.samples[1][i], &right_dither, &stats);
- tempBuffer[0] = sample0 >> 0;
- tempBuffer[1] = sample0 >> 8;
- tempBuffer[2] = sample1 >> 0;
- tempBuffer[3] = sample1 >> 8;
- }
- register int sample0;
- for(int i = 0; i < (int)synth.pcm.length; i++)
- {
- sample0 = audio_linear_dither(16, synth.pcm.samples[0][i], &left_dither, &stats);
- tempBuffer[0] = sample0 >> 0;
- tempBuffer[1] = sample0 >> 8;
- }
- mad_synth_finish(&synth);
- mad_frame_finish(&frame);
- mad_stream_finish(&stream);