Mathematical Accuracy Metronome Algorithm

SHORT: I have a method called 44,100 times per second. I would like to know what to do in a situation where I need the sound to be marked when the method 13781.25th is called - this is 192 bits per minute). I have the opportunity to round this number and make the sound tick by calling the method 13781st, which would mean that I make the sound at 0.25 too soon. this means that it will be 0.00000566893424 seconds too soon.

after 100 ticks I'm sure that the delay will certainly add up. Is there some kind of smart work around that tracks the delay, and when the delay comes at a certain point, or maybe + plusmn; some numbers to continue the bit again?

Here is my code below.

int counter; // used to track down the amount of times the method has been called signalMethod(){ if(counter % ceil(2,646,000/10) == 0){ //the ceil function turns the decimal point into a whole number so it can be used for analysis. but this will cut off delay.. and over time im sure it will add up.. which will cause the beats to fluctuate... playSound(); } counter++; } 
+4
source share
1 answer

Your problem is another kind of problem posed by the Breshenem Algorithm, but instead of increasing the Y-coordinate of the line drawn with a certain slope (the slope will be the beat frequency), you publish ticks.

Bresenem algorithm wikipedia

+6
source

Source: https://habr.com/ru/post/1410831/


All Articles