Game Development Community

Best way to time events to music?

by Rachel P · in iTorque 2D · 01/12/2012 (8:47 am) · 4 replies

Hey all,

I'm trying to figure out how best to go about getting events to fire at certain points in a song (for example, think Guitar Hero/Rock Band, how the notes you are supposed to hit appear on the screen at a particular time, going along with the music). I did some research and it appears that the VMPlayer script does exactly what I want, however, since I am making a game for the iPhone, VMPlayer won't work as the iPhone doesn't support .ogg files. A "cheap" way to go about getting events fired at particular points is to use the schedule function to fire an event at a specific time, ie:

%this.sceneGraph.schedule( 500, "event");

The problem with this, however (besides it being hard to time everything correctly to go with the song), is that sometimes the events are called half a second too early or half a second too late, thus messing up with the flow/melody of the song.

Anyone have any suggestions on what to do? Is there anyway to get VMPlayer to work with the iPhone through some editing?

Thanks a lot guys!
Rachel

#1
01/13/2012 (5:20 pm)
integrate FMOD and bind it to the music itself.
Otherwise you will not be able to get in sync with it simply cuase the load of the device can cause a delay due to the time to start the audio, even more if you have more than 1 compressed sound in which case it falls back to all-software decompression
#2
01/14/2012 (3:29 am)
My game Go Beryllium features events synchronized to music. You can download the game here: cokane.com/games/beryllium and the source code (torquescript) here: www.garagegames.com/community/blogs/view/15213

I used a few tricks to keep the events in time with the music. Firstly, writing the music at 120bmp makes the math of scheduling everything easier. Secondly, I cut the music into short parts, so that it never plays for too long and allows latency in the game to take it out of sync with the beat.
#3
01/16/2012 (8:00 pm)
That sounds like a great suggestion, thanks! I'll definitely look into it once I have the time!

#4
01/20/2012 (10:22 pm)
Just so everyone knows, I seem to not be having problems with it anymore really. Originally, I had the music set to play in the "onLevelLoaded" function, with the schedule function calling the events. I have since changed it so that the schedule functions calls the music as well, and that seems to keep it pretty nicely in sync. Cheers! :D