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

[pygame] Re: [BUG] mixer.init() mixer.get_init() inconsistancies 1.8.0



On Jun 7, 3:59 pm, Frankie <Frankie.Robert...@xxxxxxxxxxxxxx> wrote:
*snip*

Here's a related possible bug that makes me suspect that those
inconsistancies may be something to do with my setup. (I get these
problems on the release and the svn HEAD running on Ubuntu 8.04. The
versions of the requirements are all the ones from the repositories.)

#The problem is that:
import pygame
import numpy
import math
#when the mixer is initialised with 1 output channel
pygame.mixer.init(44100, -8, 1)
#and numpy is used instead of numpy for sndarray
pygame.sndarray.use_arraytype('numpy')
#and then make_sound is run on a one-dimension array (in this case a
sine wave at the pitch of the note A4)
pygame.sndarray.make_sound(numpy.sin(numpy.array(xrange(10000)) * 440
* 2 * math.pi / 44100)
#I get this error
<type 'exceptions.ValueError'>: Array must be 2-dimensional for stereo
mixer

For me it works just changing "if channels == 1:" to "if channels ==
0:" on line 122 of _numpysndarray.py. But this fix conflicts with
fixing the bug this is a reply to.

Numeric arrays work fine for me by the way. Which is weird, because I
looked at the c for that and it seemed more or less a 1:1 translation
(for that section).

Oh, and whilst I was in _numpysndarray.py I saw array(...) and
samples(...) (whose implementation should probably be merged, even if
they're left seperate in the api considering the only difference is
the ".raw" in the line "data = sound.get_buffer().raw" unilke the
Numeric implementation) use the line "channels =
mixer.get_num_channels()" to get the number of mixing channels, but
then treat that as if it's the number of *OUTPUT* channels.

Sure enough in certain situations this causes the line "array.shape =
shape" to raise the error "ValueError: total size of new array must be
unchanged". So it's clear that pygame.mixer.get_init() should be used
instead just as Mix_QuerySpec (which does appear to return a 1-based
number of output channels rather than the 0-based one my
pygame.mixer.get_init() does) is used in the Numeric implementation.