Mercurial > pygame
diff lib/sndarray.doc @ 898:424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
| author | marcus |
|---|---|
| date | Sat, 26 Jan 2008 20:13:06 +0000 |
| parents | src/sndarray.doc@48d403fff022 |
| children | 4a852f241fd3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/sndarray.doc Sat Jan 26 20:13:06 2008 +0000 @@ -0,0 +1,92 @@ +pygame.sndarray +pygame module for accessing sound sample data + +Functions to convert between Numeric or numpy arrays and Sound +objects. This module will only be available when pygame can use the +external numpy or Numeric 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. + +Supported array systems are + + numeric + numpy + +The default will be Numeric, if installed. Otherwise, numpy will be set +as default if installed. If neither Numeric nor numpy are installed, the +module will raise an ImportError. + +The array type to use can be changed at runtime using the use_array() +method, which requires one of the above types as string. + +Note: numpy and Numeric are not completely compatible. Certain array +manipulations, which work for one type, might behave differently or even +completely break for the other. + +Additionally, in contrast to Numeric numpy can use unsigned 16-bit +integers. Sounds with 16-bit data will be treated as unsigned integers, +if the sound sample type requests this. Numeric instead always uses +signed integers for the representation, which is important to keep in +mind, if you use the module's functions and wonder about the values. +<SECTION> + +array +copy Sound samples into an array +pygame.sndarray.array(Sound): return 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(). +<END> + +samples +reference Sound samples into an array +pygame.sndarray.samples(Sound): return 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(). +<END> + +make_sound +convert an array into a Sound object +pygame.sndarray.make_sound(array): return Sound + +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. +<END> + +use_array +Sets the array system to be used for sound arrays +pygame.sndarray.use_array (arraytype): return None + +Uses the requested array type for the module functions. +Currently supported array types are: + + numeric + numpy + +If the requested type is not available, a ValueError will be raised. + +New in pygame 1.8. +<END> + +get_arraytypes +Gets the array system types currently supported. +pygame.sndarray.get_arraytypes (): return tuple + +Checks, which array systems are available and returns them as a tuple of +strings. The values of the tuple can be used directly in the +pygame.sndarray.use_array() method. If no supported array system could +be found, None will be returned. + +New in pygame 1.8. +<END> +<END>
