[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] duration of song



> "Ian Mallett" <geometrian@xxxxxxxxx> wrote:
> On 7/14/07, Dave LeCompte (really) <dave@xxxxxxxxxxxx> wrote:

>> That works for OGG and WAV sounds, but does not work for other music
>> files, like MP3, MOD, and MIDI, right?
>
> Oh, opps.  You're probably right.  I'm curious now, why don't you know the
> length of the file?

Conceivably, you might want to intelligently deal with music provided by
the user. For example:

- some games, including "The Sims", allow players to put their own music
into a certain directory, and the game will take advantage of the music.

- some games, including "Monster Rancher", use user-provided music as an
integral part of gameplay. With "Monster Rancher", players inserted a CD,
which seeded the procedural content routines for making monsters.


I was thinking more about some crude ways to get approximate answers, and
I was thinking that the file size on disk might be a guide to the duration
of the song. For MP3, I think typical compression ratios (vs a 44kHz 16
bit stereo WAV file) is something like 11:1, so you can do the math (or,
better yet, just look at a collection of known MP3s and figure out an
average multipler) to convert from bytes to seconds.

However, this doesn't work for MIDI or MOD music - for MIDI, a song with
four instruments playing in harmony might use four times the space as a
solo for the same length of time. MOD music is even less predictable, as
the sound patches are a large part of the file size, and there's little
knowing how many times any patch might be used.


That said, I think that specific modules for the various file types exist
that could be used to determine the duration of MP3 and MIDI, and maybe
even MOD.

-Dave LeCompte