Game Development Community

Best way to time events to music?

by Rachel P · in Torque Game Builder · 01/11/2012 (5:54 pm) · 6 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 VMPlayer 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/12/2012 (8:00 am)
VMPlayer is a media player application, isn't it? How is it related to TGB?

There is alxGetStreamPosition() console function which returns current position for the streamed track. It also does not care whether track is played from ogg or some other file format as long as TGB can stream it (but I think currently ogg is the only streaming format TGB knows). Not sure at all if it'll work for iTGB, you should probably ask on the iTGB forum.
#2
01/12/2012 (8:45 am)
Thanks for the reply,

For VMPlayer I was referring to this script: http://www.garagegames.com/community/blogs/view/9560

Unfortunately it doesn't look like the GetStreamPosition function will work with any of the usable audio formats in iTGB (mp3/wav), so I think that option's out of the question, unfortunately.

And hm, yeah, I should've posted this in the iTGB forum, haha. I'll make a thread there now.

Thanks for the advice!
#3
01/14/2012 (8:18 am)
there was some awesome source code released on the forums for a game called Go beryllium. It had some great code for syncing music and sound effect s. I tested and used my own modified versions in my prototypes. Do a quick search I'm quite sure it help you out a lot. I incorporated bits and pieces of it into my overall sound engine that I use in all my prototypes.
#4
01/14/2012 (11:06 pm)
If you can't find the source let me know and I'll try to walk you through it. I'm on medical leave and need something to do.
#5
01/16/2012 (7:59 pm)
Thanks so much for the suggestion! I've been really busy these past few days so I haven't had time to try it, but as soon as I get a chance I'll let you know how it works!
#6
01/20/2012 (10:15 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