Sorry to post twice in a row, but I've now got a more specific question.
I've been looking at the mad winamp plugin source code, and I've worked out what causes the bug. When winamp tells the plugin to seek it basically calculates a file position to seek to by doing:-
(seekpos / song length) * (filelength).
This works with CBR files but not with VBR files as they have different data rates throughout the files.
I assume that the mad library seeks correctly and I would like to be able to use it to do the seeking with the winamp plugin (as my alternative would be to cludge it by reading frames from the beginning of the file until I got to the right time). Any pointers on what functions I could use in the library?
On Sat, Dec 14, 2002 at 02:41:16PM +0000, Robert K Marlton wrote:
Sorry to post twice in a row, but I've now got a more specific question.
I've been looking at the mad winamp plugin source code, and I've worked out what causes the bug. When winamp tells the plugin to seek it basically calculates a file position to seek to by doing:-
(seekpos / song length) * (filelength).
This works with CBR files but not with VBR files as they have different data rates throughout the files.
I assume that the mad library seeks correctly and I would like to be able to use it to do the seeking with the winamp plugin (as my alternative would be to cludge it by reading frames from the beginning of the file until I got to the right time). Any pointers on what functions I could use in the library?
MAD doesn't handle seeking; it just exposes enough of an interface so you can do it yourself.
Seeking is a huge pain with MP3s, actually, depending on how fast and/or accurate you want it to be.
In my code, I have code to:
"hard seek" (actually decode frames--without synthing--to accurately get from one place to another)
frame index seek (uses one of two frame indexes; the Xing index, if present, and a frame index that I keep running myself)
guessing via the bitrate; if we're CBR, this is pretty accurate; if we're VBR with no Xing tag we use a bitrate guess (at load, we jump to the middle of the file and take a sample), which isn't very accurate and is a fallback measure for fast seeking
An MP3 player probably doesn't need all that, of course.
The source for this is at
http://zewt.org/~glenn/madlib.c .
It's for SDL_sound. If anyone wants to use this, 1: it's for a much modified SDL_sound; the stock distribution doesn't have separate "fast" and "accurate" entry points; and 2: MAD is GPL, so although SDL_sound is LGPL, if you're linking against both you do need to be GPL-compatible. This source is being used but hasn't been used in a release, so it probably has bugs. The full modified SDL_sound source is available in the SourceForge CVS project "stepmania".
Hmm. It's annoying to have to copy the Xing code, even though it's pretty small. Could that be included in an appropriate place in MAD; perhaps as a bonus to the id3 library?