gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Helix MP3 decoder

#141444 - Blue Frenzy - Tue Sep 25, 2007 6:00 pm

Is there any way to change the playback position of a playing mp3?

#141446 - simonjhall - Tue Sep 25, 2007 6:59 pm

All mp3 frames are the exact same length.
To seek, I'd figure out what time you I to go to then compute which frame that'd be in (based on the size of the frame, the bitrate, the sample frequency etc) then make the next fread where I think that frame will start.
EDIT: this would be for CBR. VBR would be more entertaining :-)
_________________
Big thanks to everyone who donated for Quake2

#141454 - tepples - Tue Sep 25, 2007 8:04 pm

Does an MP3 frame have a timestamp in it? If so, you can try seeking using a Newton-Raphson search through the file, and then seek back a few frames to fill the byte reservoir.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#141465 - DragonMinded - Tue Sep 25, 2007 10:22 pm

Most mpeg decoders are flexible enough to resync if the header is lost, to the point where you can just seek to any random spot in the file and it'll continue playing from the next frame. That's what DSOrganize does, except using libmad as the decoder.
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#141474 - Blue Frenzy - Tue Sep 25, 2007 11:53 pm

do anyone know what functions or variables should i change to do this?

#141507 - tepples - Wed Sep 26, 2007 1:01 pm

DragonMinded wrote:
Most mpeg decoders are flexible enough to resync if the header is lost, to the point where you can just seek to any random spot in the file and it'll continue playing from the next frame.

But how will it know where in the file it has seeked to so that it can display the correct numbers on the clock? I can imagine cases where the bitrate for one part of the file differs from another, such as an MP3 ripped from a CD that contains an ordinary track, several minutes of silence (at 32 kbps), and a "hidden track".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#141528 - DragonMinded - Wed Sep 26, 2007 6:17 pm

tepples wrote:
DragonMinded wrote:
Most mpeg decoders are flexible enough to resync if the header is lost, to the point where you can just seek to any random spot in the file and it'll continue playing from the next frame.

But how will it know where in the file it has seeked to so that it can display the correct numbers on the clock? I can imagine cases where the bitrate for one part of the file differs from another, such as an MP3 ripped from a CD that contains an ordinary track, several minutes of silence (at 32 kbps), and a "hidden track".


He didn't ask for time, just to seek. Time is a very different beast. If you want exactly accurate timing on VBR, you really must parse each header and skip through the file. If you want a mostly accurate time, you can read the XING (or similar header). Also, a trick that somewhat works is to initially calculate the time by parsing each header and coming up with a final time, then calculating the average bitrate from that and using that number to estimate time and seek position.
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?