【发布时间】:2020-01-15 17:30:39
【问题描述】:
我正在尝试用这个循环节拍:
while(True):
t0 = time.time() #start timing
print(c) #c is the position of the pattern (e.g. kick = [1, 0, 1, 0])
if self.patterns['kick'][c] == 1:
channel1.play(kick)
if self.patterns['snare'][c] == 1:
channel2.play(snare)
c = (c+1)%l #increase counter/jump to start
d = int((2400-1000*(time.time()-t0))/l) #calculates the time delay (whole loop is 2400 milliseconds); l is the pattern-lenght
pygame.time.delay(d)
print (time.time() - t0)
如您所见,我测量了整个过程的时间,然后适当地纠正了我的时间延迟。但是有了这个我仍然得到+-20ms的延迟。
有没有人知道在 python 中完美地计时音频播放的好方法? 或者你能给我建议如何让我的代码更高效地获得最小延迟?
谢谢!
【问题讨论】:
-
你想要多精确?
标签: python python-3.x audio pygame timing