annotate lib/sndarray.py @ 1849:301bc61643a9 math_module

merged changes from trunk
author lorenz
date Mon, 16 Nov 2009 18:31:40 +0000
parents c35441d4f466
children 4cf10018fadd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
1 ## pygame - Python Game Library
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
2 ## Copyright (C) 2008 Marcus von Appen
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
3 ##
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
4 ## This library is free software; you can redistribute it and/or
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
5 ## modify it under the terms of the GNU Library General Public
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
6 ## License as published by the Free Software Foundation; either
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
7 ## version 2 of the License, or (at your option) any later version.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
8 ##
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
9 ## This library is distributed in the hope that it will be useful,
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
12 ## Library General Public License for more details.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
13 ##
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
14 ## You should have received a copy of the GNU Library General Public
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
15 ## License along with this library; if not, write to the Free
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
17 ##
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
18 ## Marcus von Appen
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
19 ## mva@sysfault.org
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
20
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
21 """pygame module for accessing sound sample data
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
22
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
23 Functions to convert between Numeric or numpy arrays and Sound
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
24 objects. This module will only be available when pygame can use the
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
25 external numpy or Numeric package.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
26
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
27 Sound data is made of thousands of samples per second, and each sample
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
28 is the amplitude of the wave at a particular moment in time. For
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
29 example, in 22-kHz format, element number 5 of the array is the
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
30 amplitude of the wave after 5/22000 seconds.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
31
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
32 Each sample is an 8-bit or 16-bit integer, depending on the data format.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
33 A stereo sound file has two values per sample, while a mono sound file
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
34 only has one.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
35
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
36 Supported array systems are
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
37
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
38 numpy
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
39 numeric
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
40
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
41 The default will be numpy, if installed. Otherwise, Numeric will be set
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
42 as default if installed. If neither numpy nor Numeric are installed, the
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
43 module will raise an ImportError.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
44
927
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
45 The array type to use can be changed at runtime using the use_arraytype()
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
46 method, which requires one of the above types as string.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
47
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
48 Note: numpy and Numeric are not completely compatible. Certain array
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
49 manipulations, which work for one type, might behave differently or even
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
50 completely break for the other.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
51
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
52 Additionally, in contrast to Numeric numpy can use unsigned 16-bit
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
53 integers. Sounds with 16-bit data will be treated as unsigned integers,
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
54 if the sound sample type requests this. Numeric instead always uses
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
55 signed integers for the representation, which is important to keep in
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
56 mind, if you use the module's functions and wonder about the values.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
57 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
58
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
59 import pygame
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
60
927
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
61 # Global array type setting. See use_arraytype().
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
62 __arraytype = None
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
63
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
64 # Try to import the necessary modules.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
65 try:
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
66 import pygame._numpysndarray as numpysnd
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
67 __hasnumpy = True
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
68 __arraytype = "numpy"
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
69 except ImportError:
1460
623d3b0bae58 Fixed __hasnumpy/__hasnumeric confusion in sndarray
marcus
parents: 1459
diff changeset
70 __hasnumpy = False
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
71
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
72 try:
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
73 import pygame._numericsndarray as numericsnd
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
74 __hasnumeric = True
1468
38ded5e3df87 completing the process to actually have numpy be the default
brian
parents: 1460
diff changeset
75 if not __hasnumpy:
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
76 __arraytype = "numeric"
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
77 except ImportError:
1460
623d3b0bae58 Fixed __hasnumpy/__hasnumeric confusion in sndarray
marcus
parents: 1459
diff changeset
78 __hasnumeric = False
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
79
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
80 if not __hasnumpy and not __hasnumeric:
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
81 raise ImportError("no module named numpy or Numeric found")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
82
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
83 def array (sound):
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
84 """pygame.sndarray.array(Sound): return array
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
85
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
86 Copy Sound samples into an array.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
87
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
88 Creates a new array for the sound data and copies the samples. The
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
89 array will always be in the format returned from
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
90 pygame.mixer.get_init().
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
91 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
92 if __arraytype == "numeric":
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
93 return numericsnd.array (sound)
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
94 elif __arraytype == "numpy":
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
95 return numpysnd.array (sound)
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
96 raise NotImplementedError("sound arrays are not supported")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
97
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
98 def samples (sound):
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
99 """pygame.sndarray.samples(Sound): return array
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
100
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
101 Reference Sound samples into an array.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
102
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
103 Creates a new array that directly references the samples in a Sound
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
104 object. Modifying the array will change the Sound. The array will
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
105 always be in the format returned from pygame.mixer.get_init().
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
106 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
107 if __arraytype == "numeric":
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
108 return numericsnd.samples (sound)
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
109 elif __arraytype == "numpy":
900
2417a5397ae2 Fixed numpy sndarray calls.
marcus
parents: 898
diff changeset
110 return numpysnd.samples (sound)
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
111 raise NotImplementedError("sound arrays are not supported")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
112
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
113 def make_sound (array):
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
114 """pygame.sndarray.make_sound(array): return Sound
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
115
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
116 Convert an array into a Sound object.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
117
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
118 Create a new playable Sound object from an array. The mixer module
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
119 must be initialized and the array format must be similar to the mixer
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
120 audio format.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
121 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
122 if __arraytype == "numeric":
901
f9932c5e0e2a Fixed typo in sndarray.
marcus
parents: 900
diff changeset
123 return numericsnd.make_sound (array)
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
124 elif __arraytype == "numpy":
900
2417a5397ae2 Fixed numpy sndarray calls.
marcus
parents: 898
diff changeset
125 return numpysnd.make_sound (array)
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
126 raise NotImplementedError("sound arrays are not supported")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
127
927
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
128 def use_arraytype (arraytype):
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
129 """pygame.sndarray.use_arraytype (arraytype): return None
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
130
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
131 Sets the array system to be used for sound arrays.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
132
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
133 Uses the requested array type for the module functions.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
134 Currently supported array types are:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
135
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
136 numeric
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
137 numpy
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
138
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
139 If the requested type is not available, a ValueError will be raised.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
140 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
141 global __arraytype
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
142
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
143 arraytype = arraytype.lower ()
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
144 if arraytype == "numeric":
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
145 if __hasnumeric:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
146 __arraytype = arraytype
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
147 else:
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
148 raise ValueError("Numeric arrays are not available")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
149
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
150 elif arraytype == "numpy":
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
151 if __hasnumpy:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
152 __arraytype = arraytype
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
153 else:
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
154 raise ValueError("numpy arrays are not available")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
155 else:
1568
c35441d4f466 allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents: 1468
diff changeset
156 raise ValueError("invalid array type")
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
157
927
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
158 def get_arraytype ():
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
159 """pygame.sndarray.get_arraytype (): return str
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
160
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
161 Gets the currently active array type.
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
162
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
163 Returns the currently active array type. This will be a value of the
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
164 get_arraytypes() tuple and indicates which type of array module is
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
165 used for the array creation.
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
166 """
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
167 return __arraytype
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
168
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
169 def get_arraytypes ():
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
170 """pygame.sndarray.get_arraytypes (): return tuple
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
171
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
172 Gets the array system types currently supported.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
173
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
174 Checks, which array system types are available and returns them as a
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
175 tuple of strings. The values of the tuple can be used directly in
927
4a852f241fd3 Added get_arraytype() to sndarray and surfarray for querying the active array type. Renamed use_array() to use_arraytype().
marcus
parents: 901
diff changeset
176 the use_arraytype () method.
898
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
177
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
178 If no supported array system could be found, None will be returned.
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
179 """
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
180 vals = []
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
181 if __hasnumeric:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
182 vals.append ("numeric")
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
183 if __hasnumpy:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
184 vals.append ("numpy")
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
185 if len (vals) == 0:
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
186 return None
424ef30fa1ea Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
diff changeset
187 return tuple (vals)