Delay before sounds played
When playing a sound (wav and ogg) from the 'sounds' directory using:
sounds.soundname.play()
there is a noticeable delay (.5 sec) before the sound is played.
This also happens in Pygame when using:
effect = pygame.mixer.Sound('sounds/soundname.wav')
effect.play()
With Pygame the delay is removed by using:
pygame.mixer.pre_init(22050, -16, 1, 256)
pygame.mixer.init()
before pygame.init()
Are there any specific sound files this occurs for or does not?
Is this on Raspberry Pi?
Hi Daniel,
It’s happening with all the sounds I have tried - I have tried sample rates 44100, 22050 and 8000 in wav 16, 32 and 8 bit integer (although I think I got an error on the 32bit) - I also tried saving as an ogg with 50% compression (I’m not too familiar with the format so I wasn’t sure what else to try).
I noticed the delay on a PC but as it’s for the Raspberry Pi I tried on that too and had the same results.
The fix using pre_init has only been tested on a PC - I have attached the code I used (with pgzero code commented out)
I have also attached the wav files I am using.
Thanks,
Mark
On 28 Aug 2018, at 08:17, Daniel Pope [email protected] wrote:
Are there any specific sound files this occurs for or does not?
Is this on Raspberry Pi?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lordmauve/pgzero/issues/112#issuecomment-416477077, or mute the thread https://github.com/notifications/unsubscribe-auth/AQmeQhc3YXRq5zEO4wvpAHMvzSVCzpfZks5uVO54gaJpZM4WOPma.
This is a pygame initialization issue. See this thread :
https://stackoverflow.com/questions/18273722/pygame-sound-delay
It can be fixed (Verified on Windows) by changing line 2 of runner.py to:
pygame.mixer.pre_init(frequency=22050, size=-16, channels=2, buffer=512)