[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] write sound to file for fast loading?



hey gumm,

you may or may not get better results with the process you describe - the resulting sound file will most likely be much much larger (like orders of magnitude larger) which increases the time it takes to load it from disk, so if disk is the bottleneck (as opposed to cpu decoding), the trick would make things slower.

Also, the problem you are experiencing is precisely what pygame.mixer.music is for - it uses SDL's underlying feature for streaming a song from disk, so the loading time is amortized over the game play time:
http://www.pygame.org/docs/ref/music.html

So what kind of sound file are you loading? mp3? ogg? wav? can you share one of the problem files?
What does your sound loading code look like? Are you loading by filename or file-like object?

... and to the poster who mentioned pyglet - why do you think it would help? pyglet and pygame are very similar in music loading. Both pygame and pyglet offer streaming music options that only help if you use them, and unless you distribute avbin with your game, pyglet loads sounds with pure python code, while pygame always uses mature decoding libraries.


On Mon, Feb 1, 2010 at 10:32 PM, B W <stabbingfinger@xxxxxxxxx> wrote:
Howdy, folks.

I have a problem I've been studying a while and I can't figure out a solution. Pygame or SDL--not sure which--is pretty slow at loading sounds. For large sounds, like songs, this means significant pauses in your game; or very long loading times at startup if you have a few of them to load.

I tried using a thread to load a song, but as expected that only resulted in a very laggy game for the duration.

So I was thinking it might be faster to pre-process a song: load it via the mixer, write the buffer to a data file, then later load it into an array and feed the array to the mixer. I can see that part of that idea is implemented in _sndarray.py, but I didn't really want to require numpy and I couldn't see how to convert that module's code to my purpose anyhow.

I'm strikin' out. Is this even feasible, or is it a hair-brained scheme doomed to failure? Has anyone solved this problem, and would s/he be willing to share? :)

Gumm