我正在尝试获得一个精确的时钟,它不受应用程序内部其他进程的影响。
我目前在线程中使用System.nanoTime(),如下所示。我用来计算十六步中每一步的时间。
目前,计时操作有时会有明显的延迟,我会尝试解决这个问题。
我想知道是否有更精确的方法来获得定时操作,也许是通过检查内部声卡时钟并使用它来生成我需要的定时。
我需要它来发送midi音符从安卓设备到外部音频汉化和音频我需要精确的时间
有没有人可以帮我改进这方面的?
谢谢
cellLength = (long)(0.115*1000000000L);
for ( int x = 0; x < 16; x++ ) {
noteStartTimes[x] = x*cellLength ;
}
long startTime = System.nanoTime();
index = 0;
while (isPlaying) {
if (noteStartTimes[index] < System.nanoTime() - startTime) {
index++ ;
if (index == 16) { //reset things
startTime = System.nanoTime() + cellLength;
index = 0 ;
}
}
}发布于 2018-07-22 08:32:30
对于您收到的任何消息,onSend callback都会给您一个时间戳。
对于您send的任何消息,您可以提供时间戳。
这些时间戳是基于System.nanoTime()的,所以您自己的代码也应该使用它。
如果你的代码被延迟了(由它自己的处理,或被其他应用程序,或被后台服务),System.nanoTime()将准确地报告延迟。但是没有一个计时器可以让你的代码更早的运行。
https://stackoverflow.com/questions/51460150
复制相似问题