我是 python 新手,我正在尝试创建一个简单的节拍器程序。当我运行我的程序时,我遇到了一个问题,即音频听起来没有均匀分布。我在 Raspberry Pi 2 Model B 上运行它。我也尝试过使用 sleep() 和 time.monotonic(),但我遇到了同样的问题。有谁知道这里发生了什么?
import time
import pygame
path = ("/home/pi/Documents/Loop/")
sound_file = ["kick.wav"]
pygame.mixer.init()
pygame.mixer.music.load(path + sound_file)
BPM = 60
BPMS = 60/(4*BPM)
#Metronome plays on quarter notes
delay = BPMS
past = 0
note = 1
while True:
now = time.perf_counter()
if now >= past + delay:
if note == 1:
pygame.mixer.music.play()
elif note == 2:
pygame.mixer.music.play()
elif note == 3:
pygame.mixer.music.play()
elif note == 4:
pygame.mixer.music.play()
past = now
note = note + 1
if note > 4:
note = 1