Hi members of the Dev list :-)
These steps:
- call mad_frame_decode
- call mad_synth_frame
- send the data to the sound device
should be repeated until MAD returns the error MAD_ERROR_BUFLEN.
Ok.
You will have to demultiplex the MPEG audio data from the video data and stream this independently to MAD.
Yeah, now I realize this... But I really wonder why all the AVI streams I have tested with have 'sound' frames that are NOT a multiple of the size of the MP3 frame.
Anyway, I have another question now about the timers :-) (now that I may use them to do the synchronisation). When I decode the MP3 stream I saved on disk from an AVI, I get this (it's my program debug output) :
109 - 00:00:00.024 - 1152 - 288 | | | | MP3 frame length | | | Sound output frame length | | Frame length (frame.header.duration) | Frame number
But the header of the AVI gives me this :
STREAMHEADER : - DataType : auds (...) - DataRate : 12000 (...) WAVEFORMATEX : - wFormatTag : 85 ( MPEG Layer3 ) - nChannels : 2 - nSamplesPerSec : 48000 - nAvgBytesPerSec : 12000
We have clearly here a 'fixed' frame MP3 stream with output being a stereo 48 kHz.
But when I look at the the time the frame will take to play : 1152 / 2 (stereo) / 2 (16 bit per sample) / 48000 = 0.006 ms
So why does MAD say that this frame is 0.024 ms long ? Is there some bug in the stream in the AVI file (but well, I have this on ALL the streams I have, generated on at least 3 different encoders).
By the way, out of curiosity, is the MP3 frame always the same size or can it be variable from stream to stream or even in a stream ? Is it possible to get the frame size without decoding a frame ?
You will probably have to deal with the synchronization somehow. MAD's timers can help you keep track of how much audio data has been decoded. They might seem intimidating but they're really quite simple to use. I'll post some details in a follow-up message.
Thanks for your explanation on the timers... I think you should add your post somewhere in the docs section of the source tree :-)
Lionel
PS: I am sure I will have other questions before my player is done :-)