节拍器精度算法数学

metronome precision algorithm maths

本文关键字:算法 精度 节拍器      更新时间:2023-10-16

简而言之:我有一个每秒调用 44,100 次的方法。我想知道在我需要在第 13781.25 个方法调用中勾选声音的情况下该怎么做 - 即每分钟 192 次)。我可以选择四舍五入该数字并在第 13781 个方法调用处发出声音滴答声,这意味着我在第 0.25 次发出声音滴答声太早了。这相当于早了 0.00000566893424 秒。

在 100 个刻度之后,我确信延迟肯定会加起来。是否有任何聪明的解决方法可以跟踪延迟,当延迟超过某个点时,也许±一些数字来保持节拍再次正常进行?

这是我到目前为止下面的代码..

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++;
}

您的问题只是"布雷森汉姆算法"问题的另一种变体,但您不是增加以特定斜率绘制的线的 Y 坐标(斜率将是节拍频率),而是发出即时报价。

关于布雷森纳姆算法的维基百科