Advertisement

How do you synch music with input?

Started by February 28, 2005 04:10 PM
1 comment, last by qazlop 19 years, 8 months ago
I haven't really ever dealt with sound programming before, so forgive my ignorance. How I would synchronize my sound and input? What I eventually want to try is to create a simple Stepmania-like clone that will play a song while the user hits keys along with the music. Ideally, I would want to be able to use a MIDI keyboard for input. If anyone could explain how I would ensure that silly things like task-switching and lag don't put the song out of synch with the input.
Please have a look here for a tutorial on MIDI input.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
This depends on how you are playing the sound.

If you use directshow, you can get reasonable accuracy using the GetPosition() (but only if you are playing mp3 or ogg, it seems wma may not be very accurate).

However once you start the music and the level, you only need to check every once in awhile to make sure your notes are matched to the correct song position. this can be done easily by using GetPosition() each frame to adjust where you are in the level for display ofthe notes.

Input is actually pretty straight forward once you know the difference between the midi and directshow clock. Then its a matter of finding out the absolute time the input was recieved and compare it the level data at that point in time to see if the correct key was pressed within a certain tolerence and score it accordingly.

For keyboard or joystick you could:

1. start the song and call timeGetTime() and store this in starttime
2. now on each frame call timeGetTime() after GetPosition().
3. this value of timeGetTime() will be subtracted from the starttime, and then compared to getposition(). this will allow you to adjust the offset you will need to make sure that calls to timeGetTime()-starttime will be close enough to GetPosition().
4. on a key press you will call timeGetTime() and figure out the time, dont forget about the offset. you then compare this to the level, however you should know what notes are currently in "view" and see how close you are too them.
5. If you are within a tolerence, grade the note and mark it as complete.
6. If you the user misses a note (ie the tolerence becomes to great for waiting) then mark the note as missed.

its important that you have tolerences because they will be latency in the system that you simply cant do much about. There will the limited accuracy of a gamer will have hitting notes on time. So make sure that you have enough grades for a note that a gamer can still hit it somewhat early or late and not miss. Also "perfects" generally are not perfect, but instead within a certain tolerence.

This topic is closed to new replies.

Advertisement