I managed to find this thread in the archives wich helped quite a bit :
http://www.mars.org/mailman/public/mad-dev/2002-January/000426.html
And this is a great simple description of the MP3 header :
http://www.id3.org/mp3frame.html
I followed the advice posted, and wrote a simple routine to find the start of the next frame (some lines removed for clarity) :
int rio_mad_findNextFrame(char *data, unsigned int dataSize) { [init stream, frame, initalize other variables] for (i=0; i<dataSize-1; i++) { if ( data[i] == 0xff && (data[i+1] & 0xe0) == 0xe0 ) { mad_stream_buffer(&stream, data+i, dataSize-i); if ( mad_header_decode( (struct mad_header*) &frame.header, &stream) != -1) { frameOffset = i; break; } } } [cleanup stream, frame] return frameOffset; }
Which seems to work great, as it the frame.header object has all correct values in it. However, when I take this offset into account and then call mad_stream_buffer() (different stream struct) in the main loop of the program, I promptly get a "bad main_data_begin pointer" error from MAD. What should the first byte passed to mad_stream_buffer() be? Shouldn't the first byte be the Sync byte (value of 0xff)? Again, The full code can be found here
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/grrr/rrr/mad.c
and the other relevant function is rio_mad_shoutcast_input().
Thanks, Reza
It's kind of sad as I keep replying to my emails, but this confuses me. It turns out that if I simply ignore all the errors that mad returns, then it seems to play the audio without any problem. Are the "bad main_data_begin pointer" errors not important?
Reza
Reza Naima wrote:
I managed to find this thread in the archives wich helped quite a bit :
http://www.mars.org/mailman/public/mad-dev/2002-January/000426.html
And this is a great simple description of the MP3 header :
http://www.id3.org/mp3frame.html
I followed the advice posted, and wrote a simple routine to find the start of the next frame (some lines removed for clarity) :
int rio_mad_findNextFrame(char *data, unsigned int dataSize) { [init stream, frame, initalize other variables] for (i=0; i<dataSize-1; i++) { if ( data[i] == 0xff && (data[i+1] & 0xe0) == 0xe0 ) { mad_stream_buffer(&stream, data+i, dataSize-i); if ( mad_header_decode( (struct mad_header*) &frame.header, &stream) != -1) { frameOffset = i; break; } } } [cleanup stream, frame] return frameOffset; }
Which seems to work great, as it the frame.header object has all correct values in it. However, when I take this offset into account and then call mad_stream_buffer() (different stream struct) in the main loop of the program, I promptly get a "bad main_data_begin pointer" error from MAD. What should the first byte passed to mad_stream_buffer() be? Shouldn't the first byte be the Sync byte (value of 0xff)? Again, The full code can be found here
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/grrr/rrr/mad.c
and the other relevant function is rio_mad_shoutcast_input().
Thanks, Reza
On Wed, Jul 24, 2002 at 12:28:36AM -0700, Reza Naima wrote:
It's kind of sad as I keep replying to my emails, but this confuses me. It turns out that if I simply ignore all the errors that mad returns, then it seems to play the audio without any problem. Are the "bad main_data_begin pointer" errors not important?
That's exactly what I do when playing streams. Just ignore the first few errors till mad figures out whats going on.
sam