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

Re: [pygame] Music



Denise,
Mp3's store the music as one "thing" just as a zip file does.

Imagine a video.
it's just a collection of frames, but when played consecutively
very quickly it turns into a movie.
Analog sound recordings are different, I don't really understand the
difference,
but anyway digital recordings are like this.
the reason a raw "wave" file is bigger than an Mp3 is the same
reason a JPG is smaller than a bmp.
Someone decided what "was unnecessary" and got rid of it.
so JPG's look about the same as the bmp equivalent, unless
it's low quality in which case it's all blurry and crappy looking.
If an mp3 is compressed at a low bitrate, it will be crappy sounding.
bitrate is just the maximum amount of storage space will be used per second
of audio.
192 kb/s Mp3 will use 192 kilobits per second, which is equal to 24
kilobytes.

aside: I prefer ogg's to mp3's because it's an open-source file format.
any mp3 player you have *should* have payed a royalty fee for using the mp3
format,
because it's patented.  so any "free" mp3 player is probably breaking
patent / copyright laws.
not that anyone really seems to care.  also I just like the idea of oggs.
proprietary software is scary.


so you're right, an mp3 can't be split into something like

bass :-0-------0-0-----
snare:-----o-------o---
hihat:-x-x-x-x-x-x-x-x-

just like you couldn't extract actors from a movie.
You could go through and analyze the colors etc. and figure out where the
actors were,
but you can't just watch the movie without the rest of the scene.

however, there is a solution to your problem that you probably won't like.
it's called midi.
Musical Instrument Digital Interface.
and all it is is a list of different instruments and an exact timing of
everything they play.
I attached one for reference and for *educational use only* please don't
distribute etc.
I have no idea how a midi file is formatted.
or if pygame can play them.
but check it out in windows media player, etc and see what you think.

I made a crude, sorta-working emulation of midi for a project i'm working
on.
I just have an array of numbers, like:
153424253433534
and each number is a reference to a note.
so I just play the note for however long I choose, go back to the array,
find out what is next, play it, and so on.  It is much more limited than
midi but it is exactly what I need for the project.


So look into midi, if you figure out how to read them,
they have "C E G" etc, all of the notes, stored in them somehow.
so you could say "on every middle c that is followed by a d 2 octaves down
do whatever"
like I said, I have no idea how to read in midi files but that is definitely
something that may help you so I thought i'd mention it.
Hope That Helps,
-Luke


----- Original Message -----
From: "D. Hartley" <denise.hartley@xxxxxxxxx>
To: <pygame-users@xxxxxxxx>
Sent: Wednesday, July 13, 2005 5:20 PM
Subject: [pygame] Music


Hi, everyone!

I am looking into adding music to my game, but, more importantly,
making that music actually do something/matter.

I have read the pygame documentation on mixer, and have googled
additional tutorials on adding music through mixer, accessing music
from a cd, and PyMedia (although for my current purposes I'm not sure
I would need any of that stuff quite yet).

The first step will be adding a background song to my level.  I'm
fairly confident I can do that.  It might take some prodding to figure
out how to loop it nicely, but that'll come in time (although any
suggestions/tutorials/helpful pointers are always appreciated).

My real question is this:

"Real" music (that's what I'll call it, for my present purposes),
composed in the real world, is made up of a bunch of individual
elements - notes, chords, crashes, sounds, what have you.  In my house
growing up, a lot of these elements resulted in Little Brother Noise.
In other places, they result in what people would call music. ;)

But when I have a music *file* - let's say an mp3 - it is one...
"thing."  I load that one thing, I play it, I can pause it or stop it
or fade it out into another thing.  I read that in pygame you can only
have one music file at a time (not a bunch of overlain tracks? that
would be cool...), so in my understanding you have this one thing
playing and that's it.  The actual sound that comes out of it might be
made of a bunch of things you hear as distinct elements, but to the
computer it's just one thing.

Correct me if I'm wrong.

What I'd *like* is to be able to listen for certain individual
elements in the song, and make them game events.  In theory I could do
this when the song ended, make something happen and replay the song,
but I couldn't do it, for example, every time a high C was played, or
a drum beat, etc.

Can pygame do anything like this? (or anything else, for that matter?)
the closest thing I've seen so far is finding the position in the
song, so that if you knew you had a high C (for example) every x
number of miliseconds, you could make an event happen at every x
number of miliseconds. They wouldnt exactly be tied (and you'd pretty
much have to create some boring music), but I can't find much else.

Anybody who's played something like Lumines, O2Jam, Band Brothers, or
I'm assuming DDR (i've never played but believe it's tied to events in
the music) will know the kind of tie I'm talking about.

Has anyone looked into this, or know where I could find out more? Any
pointers would be much appreciated!

~Denise