ó
ÜStLc           @   sU   d  Z  d d l Z d d l j Z d d l Z d „  Z d „  Z d „  Z d „  Z d S(   s`  pygame module for accessing sound sample data using numpy

Functions to convert between numpy arrays and Sound objects. This module
will only be available when pygame can use the external numpy package.

Sound data is made of thousands of samples per second, and each sample
is the amplitude of the wave at a particular moment in time. For
example, in 22-kHz format, element number 5 of the array is the
amplitude of the wave after 5/22000 seconds.

Each sample is an 8-bit or 16-bit integer, depending on the data format.
A stereo sound file has two values per sample, while a mono sound file
only has one.
iÿÿÿÿNc   	      C   sõ   t  j ƒ  } | s$ t j d ƒ ‚ n  t | d ƒ d @d ?} | d } | r^ |  j ƒ  j } n |  j ƒ  } t | ƒ | f } | d k r  | d | | f } n  i t j	 d 6t j
 d 6t j d	 6t j d
 6| d } t j | | ƒ } | | _ | S(   Ns   Mixer not initializedi   iÿ   i   i   i    i   i   iøÿÿÿiðÿÿÿ(   t   mixert   get_initt   pygamet   errort   abst
   get_buffert   rawt   lent   numpyt   uint8t   uint16t   int8t   int16t
   fromstringt   shape(	   t   soundR   t   infot   fmtbytest   channelst   dataR   t   typecodet   array(    (    s6   C:\Python27\Lib\site-packages\pygame\_numpysndarray.pyt   _array_samples(   s&    



	c         C   s   t  |  t ƒ S(   sö   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().
    (   R   t   True(   R   (    (    s6   C:\Python27\Lib\site-packages\pygame\_numpysndarray.pyR   D   s    	c         C   sÝ   t  j j ƒ  } | s' t  j d ƒ ‚ n  t | d ƒ d @d ?} | d } |  j ƒ  } | j | f } | d k rˆ | d | | f } n  i t j d 6t j	 d 6t j
 d	 6t j d
 6| d } t j | | ƒ } | | _ | S(   s5  pygame._numpysndarray.samples(Sound): return array

    Reference Sound samples into an array.

    Creates a new array that directly references the samples in a Sound
    object. Modifying the array will change the Sound. The array will
    always be in the format returned from pygame.mixer.get_init().
    s   Mixer not initializedi   iÿ   i   i   i    i   i   iøÿÿÿiðÿÿÿ(   R   R    R   R   R   R   t   lengthR   R	   R
   R   R   t
   frombufferR   (   R   R   R   R   R   R   R   R   (    (    s6   C:\Python27\Lib\site-packages\pygame\_numpysndarray.pyt   samplesO   s"    




	c         C   sº   t  j j ƒ  } | s' t  j d ƒ ‚ n  | d } |  j } | d k rj t | ƒ d k rª t d ƒ ‚ qª n@ t | ƒ d k r‹ t d ƒ ‚ n | d | k rª t d ƒ ‚ n  t j d |  ƒ S(   s  pygame._numpysndarray.make_sound(array): return Sound

    Convert an array into a Sound object.
    
    Create a new playable Sound object from an array. The mixer module
    must be initialized and the array format must be similar to the mixer
    audio format.
    s   Mixer not initializedi   i   s*   Array must be 1-dimensional for mono mixers,   Array must be 2-dimensional for stereo mixers/   Array depth must match number of mixer channelst   buffer(   R   R    R   R   R   R   t
   ValueErrort   Sound(   R   R   R   R   (    (    s6   C:\Python27\Lib\site-packages\pygame\_numpysndarray.pyt
   make_soundp   s    

	(	   t   __doc__R   t   pygame.mixerR    R   R   R   R   R   (    (    (    s6   C:\Python27\Lib\site-packages\pygame\_numpysndarray.pyt   <module>"   s   			!