Pygame 声音延迟 - 与缓冲/采样无关 [英] Pygame sound delay - Not related to buffer/sampling

查看:61
本文介绍了Pygame 声音延迟 - 与缓冲/采样无关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户将鼠标悬停在按钮上时,我都会尝试在我的小游戏中播放简单的 wav 文件,播放一点点击声(实际按下按钮时也是如此).有了这个,我遇到了每个没有正确初始化混频器的人都会遇到的一般滞后.但是,当我正确初始化它时,它仍然有 0.5 秒的延迟.我按如下方式初始化我的游戏:

I am trying to play simple wav files in my little game whenever the user hovers over a button, a little click sound is played (same goes for when the button is actually pressed). With that I encounter the generic lag that everyone who has not initialized the mixer properly does. However, when I correctly initialize it, it still has a .5 second delay. I initialize my game as follows:

pygame.mixer.pre_init(11025, -16, 2, 512)
pygame.mixer.init()
pygame.init()

我用不同的初始化设置摆弄了(这是一个词吗?),但没有成功.wav 文件清晰,音频从文件开头立即开始.所以我的问题是:有没有其他方法可以弥补在 pygame 中播放声音时出现的延迟?

I have fiddled around (is that a word?) with the different init settings, without success. The wav file is clear and the audio starts immediately from the beginning of the file. So my question is: are there any other ways to remedy the lag that occurs when playing sounds in pygame?

推荐答案

答案:

我结束了以 pre_init 设置启动混音器,然后退出混音器,然后再次启动它:

I wound up initiating the mixer with pre_init settings, then quitting the mixer, then initiating it again:

pygame.mixer.pre_init(22050, -16, 2, 1024)
pygame.init()
pygame.mixer.quit()
pygame.mixer.init(22050, -16, 2, 1024)

现在一切正常.

这篇关于Pygame 声音延迟 - 与缓冲/采样无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆