Unity beat-detection game - please help

I realize the true nature of this question has nothing to do with unity, and is more of a general question in beat-detecting, tempo, and sound theory, but I didn’t know where else to ask. If you know a better place to ask, please let me know.

I am creating a “beat-detection” game with Unity. I have .sm file or step mania file that is a series of 0s and 1s indicating when to show an arrow and scroll it. I’m scrolling all arrows at a constant rate and generating them depending on the BPM for that given song.

I’m using Dancing Monkey to generate .sm file. In the file it gives me the BPM (beats per minute) rate. There is a song that is 120 BPM, so in unity I have a Coroutine that releases an arrow everything .5 second for a total of 120 arrows a minute. In the beginning the arrows match with the beats, but after awhile they tapper off and then tapper back on. Everything is inconsistent. I’ve noticed that if I bring the .sm file into Step Mania, it matches up perfect. What am I missing? Any suggestions would be great.

I don’t know that a coroutine will be precise enough to keep the timing ( using WaitForSeconds ). You should be doing something like:

var arrowsSent : int = 0;
function Update() { 
    var arrowsShouldHaveBeenSent : int = Mathf.FloorToInt( audio.time * bpm );
    while( arrowsSent < arrowsShouldHaveBeenSent ){ MakeArrow(); arrowsSent ++; }
}

You’ll at least have a the amount of arrows for how far the time is on. but you would then have to do some positioning code to advance the arrows by their time.

very interesting, i’ll try that out tomorrow, thanks for the feedback,

ok so I’ve tried this but it does’t seem to work, it doesn’t release an arrow every .5 seconds, can you please explain the rational behind everything

int arrowsShouldHaveBeenSent = Mathf.FloorToInt(mainCamera.audio.time * 120f); //also tried .5f
   while(arrowSent < arrowsShouldHaveBeenSent) {
   ReleaseArrow();
   arrowSent++;

}

I was a little off, audio.time is in seconds. So youd get beats per second * time to get the amount of arrows that should have been spawned.

So arrowsShouldHaveBeenSent = Mathf.FloorToInt ( mainCamera.audio.time * ( bpm / 60f ) );