I'm trying to build a steady metronome that ticks every beat, but it seems like there is a problem.
How long the metronome waits for each beat is determined by this formula: 60000 / BPM
But, the value seems to return a specific number no matter what value you plug into BPM.
I have a property that returns the value of this formula, along with a bpm integer:
static private int bpm = 125;
static private int BeatLength
{
get
{
return 60000 / bpm;
}
}
static public int beat = 0;
And here is the function that's responsible for the metronome (it runs on a dedicated thread):
public static void RhythmUpdate()
{
lock (threadLock)
{
while (true)
{
Thread.Sleep(BeatLength); // Sleep until the next beat
AddRequest(BeatLength * beat);
beat++;
DefaultSounds.def_CowBell.Play();
OnBeat?.Invoke();
}
}
}
When breakpointing the def_CowBell.Play();
, Visual Studio notes that it takes around 600ms to loop. This is how I know the value.
Extra Info:
I'm using OpenGL
Maybe some more if asked...
I appreciate your help in advance.