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

Re: [pygame] pygame.init before pygame.mixer.init?



directX audio backend sets things up in a way that audio can't be
played until after a window is created. The docs for pygame.mixer.init
allude to this:
http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init
***
    Yes, that is what I read and was refering to when I tried explaining it. I did not go and test Clare's problem myself, just relied on what I had read. Also, my demo/key thing has all the screen stuff set up and that allows the init stuff to be ignored as you stated below. Including the SDL installation. So Clare probably will never use the example given, but it is is an interesting thing to note. Who knows, it may cause problems down the road in some special cases, to early to tell...

        Bruce


I tested the cases Clare mentioned, and was able to get the same
behavior as her (specifically that doing a pygame.init first, sound
would never be heard until after a display was sucessfully created,
while doing a pygame.mixer.init first, the sound worked in all cases).
Also, if I replace pygame.init with pygame.display.init, same results
(display before mixer + no window = no sound)

Ethan seems to have got things pegged with his DirectX comments too...

On 10/11/07, Ethan Glasser-Camp <glasse@xxxxxxxxxx> wrote:
> To force a non-DirectX audio driver, you could try doing something like:
>
> import pygame, os
> os.environ['SDL_AUDIODRIVER'] = waveout'
>
> before doing any pygame*.init(). As you may have gathered, I have no
> idea if this will actually work.
>
When adding the code Ethan suggested above before pygame.init(), the
sound worked for me even if the display wasn't created.

So it seems clear to me that Ethan hit the nail on the head - the
directX audio backend sets things up in a way that audio can't be
played until after a window is created. The docs for pygame.mixer.init
allude to this:
http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init

It seems though, that as Clare discovered, the directX backend only
has that problem if pygame.display.init() is called before
pygame.mixer.init(). pygame.init must call SDL in a way that does the
display before the mixer.

...Ultimately, it seems to me that if you are making a game, with a
window, none of this will matter at all. if you are making something
that plays sounds with no window, then either force waveout for
windows like Ethan suggested, or call pygame.mixer.init and forget
about pygame.init and others.