Music Timing System

I think, when planning this type of subsystem, one need to think about a more grand overview of your game mechanism.
Like how RhythmScript described, it would be basically impossible if you don’t have some external hardware to just feed you the stream in concurrent with your game, since you have the same cycles to run but with many things to share your cpu time. But, in a design point, how much delay you can tolerate or how accurate you needed to be is tie to your game.
Say for a guitar hero game, you run maybe at maximum of 5 mins per session, with regard of possible input/buffer lag, as long as it doesn’t destroy the “feeling” of in sync, you should be safe.
I don’t know how accurate would be a proper threshold for musician, but let’s say for a 60fps game, you have about 16ms or less window trying to adjust your event. 300bpm it’s at around 200ms per beat, and I don’t think many people if at all can do 300 bpm without help from electronics. And then you can test if you can tell the difference on a 60fps based game by intentionally creating delay, ie say pad another 5ms per beat and see when you actually notice that your beat is off. After all this is done you can say on a 60fps minimum requirement system, I can run how long in a game with artificial lag and still manage to be “in-sync”.

Then you try to see how you can implement a system that you can offset the lag(at least hardware clock runs independent of your software) when you detect that it goes over a certain range, in the 300bpm example it should be like:

  1. this beat is sending to buffer and I know if I do nothing the next beat event comes I’ll have around 2~3 frames lag(ie 45ms), assume that would be noticeable.
  2. next timing event comes, I know it’s not the time yet(since it’s 200ms space), but start to count what’s the potential event timing to correct the 45ms lag.
  3. when your close to run into the correction range, say you have timer with less than 5 frames to play the next beat, try predict with your average delta.
  4. then you offset your beat by 2~3 frames time, or by 1 frame and do the same for next beat.

It would not be a exact system, but it would be pretty good for plenty of people.
Just so you know that some modern display already have variety range of input lag, and most people that play music games aren’t even complaining.
Note, I have never done such thing before, but I just analyze the problem, and suggest what I think would be a proper solution.

1 Like