节拍器精度算法数学

时间:2012-05-05 09:21:15

标签: c++ math

简称: 我有一个方法被调用,每秒44100次。我想知道在我需要在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++;
}

1 个答案:

答案 0 :(得分:6)

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

Wikipedia on Bresenham's Algorithm