I am trying to create a command-line metronome app in C using PlaySound() from windows API. I am using the following code to generate a ticking metronome with 120 bmp tempo. The sound plays perfectly with my local .wav files but the tempo is not consistent. Sometimes it is rushed sometimes it is delayed. Any solution on how to make it consistent?
#include <stdio.h>
#include <windows.h>
int main() {
while (1) {
PlaySound("lib\\tick.wav", NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
Sleep(500);
for (int i = 0;i < 3;i++) {
PlaySound("lib\\click.wav", NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
Sleep(500);
}
}
return 0;
}