节拍器精度算法数学

Pav*_*van 4 c++ math

简而言之: 我有一种方法,每秒调用次数为44,100次.我想知道在我需要在13781.25th方法调用中输入声音的情况下该怎么做 - 即每分钟192次击败.我可以选择对该数字进行舍入,并在13781st方法调用时使声音打勾,这意味着我过早地将声音滴答为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++;
}
Run Code Online (Sandbox Code Playgroud)

dat*_*olf 6

你的问题只是解决"Bresenham算法"问题的另一个变种,但不是增加用一定斜率绘制的直线的Y坐标(斜率是拍频),而是发出嘀嗒声.

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