Commits

illume  committed 438669b

Fixed bug with mixer.get_init() Thanks Frankie Robertson

  • Participants
  • Parent commits 8282465

Comments (0)

Files changed (3)

 #
 #
 
+Jun 13, 2008
+    [BUG] Fixed bug with mixer.get_init() Thanks Frankie Robertson!
+
 Jun 9, 2008
     [BUG] Fixed locking and reference count leaks in Numeric surfarray
        implementation.

File lib/_numpysndarray.py

 import pygame.mixer as mixer 
 import numpy
 
-def array (sound):
-    """pygame._numpysndarray.array(Sound): return array
-
-    Copy Sound samples into an array.
-
-    Creates a new array for the sound data and copies the samples. The
-    array will always be in the format returned from
-    pygame.mixer.get_init().
-    """
+def _array_samples(sound, raw):
     # Info is a (freq, format, stereo) tuple
     info = mixer.get_init ()
     if not info:
         raise pygame.error, "Mixer not initialized"
     fmtbytes = (abs (info[1]) & 0xff) >> 3
-    channels = mixer.get_num_channels ()
-    data = sound.get_buffer ().raw
+    channels = info[2]
+    if raw:
+        data = sound.get_buffer ().raw
+    else:
+        data = sound.get_buffer ()
 
     shape = (len (data) / channels * fmtbytes, )
     if channels > 1:
     array.shape = shape
     return array
 
+def array (sound):
+    """pygame._numpysndarray.array(Sound): return array
+
+    Copy Sound samples into an array.
+
+    Creates a new array for the sound data and copies the samples. The
+    array will always be in the format returned from
+    pygame.mixer.get_init().
+    """
+    return _array_samples(sound, True)
+
 def samples (sound):
     """pygame._numpysndarray.samples(Sound): return array
 
         Py_RETURN_NONE;
 
     //create a signed or unsigned number of bits per sample
+    // XXX: When mixer is init'd with a format of -8, this returns +8
     realform = format&~0xff ? - (format&0xff) : format&0xff;
-    return Py_BuildValue ("(iii)", freq, realform, channels > 1);
+    return Py_BuildValue ("(iii)", freq, realform, channels);
 }
 
 static PyObject*