【发布时间】:2018-07-21 21:11:19
【问题描述】:
我正在尝试获取不受应用内其他进程影响的精确时钟。
我目前在线程中使用 System.nanoTime(),如下所示。 我用十六步中的每一步来计算时间。
当前定时操作有时会出现明显的延迟,我会尝试修复。
我想知道是否有更精确的方法来获得定时操作,也许通过检查内部声卡时钟并使用它来生成我需要的时间。
我需要它将 MIDI 音符从 android 设备发送到外部音频合成器,对于音频我需要精确的计时
有没有人可以帮我改进这方面的?
谢谢
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 ;
}
}
}
【问题讨论】:
标签: android processing midi