annotate lib/sndarray.py @ 3182:0c07af110477 docs-changes

Ignore Sphinx-generated files
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 22:35:43 +0000
parents 4cf10018fadd
children
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
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
39 numeric (deprecated; to be removed in Pygame 1.9.3.)
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
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
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
42 as default if installed, and a deprecation warning will be issued.
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
43 If neither numpy nor Numeric are installed, the module will raise an
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
44 ImportError.
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
45
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
46 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
47 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
48
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 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
50 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
51 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
52
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 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
54 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
55 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
56 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
57 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
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
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 import pygame
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
61 import imp
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
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
63 # 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
64 __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
65
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
66 # 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
67 try:
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
68 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
69 __hasnumpy = True
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
70 __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
71 except ImportError:
1460
623d3b0bae58 Fixed __hasnumpy/__hasnumeric confusion in sndarray
marcus
parents: 1459
diff changeset
72 __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
73
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
74 try:
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
75 if not __hasnumpy:
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
76 import pygame._numericsndarray as numericsnd
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
77 __arraytype = "numeric"
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
78 warnings.warn(warnings.DeprecationWarning(
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
79 "Numeric support to be removed in Pygame 1.9.3"))
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
80 else:
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
81 f, p, d = imp.find_module("Numeric")
1459
ac7c93b62b1e numpy now takes priority over Numeric in sndarry and surfarray
Lenard Lindstrom <len-l@telus.net>
parents: 927
diff changeset
82 __hasnumeric = True
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
83 except ImportError:
1460
623d3b0bae58 Fixed __hasnumpy/__hasnumeric confusion in sndarray
marcus
parents: 1459
diff changeset
84 __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
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 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
87 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
88
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 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
90 """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
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 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
93
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 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
95 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
96 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
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 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
99 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
100 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
101 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
102 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
103
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 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
105 """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
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 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
108
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 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
110 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
111 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
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 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
114 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
115 elif __arraytype == "numpy":
900
2417a5397ae2 Fixed numpy sndarray calls.
marcus
parents: 898
diff changeset
116 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
117 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
118
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 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
120 """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
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 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
123
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 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
125 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
126 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
127 """
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
128 if __arraytype == "numeric":
901
f9932c5e0e2a Fixed typo in sndarray.
marcus
parents: 900
diff changeset
129 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
130 elif __arraytype == "numpy":
900
2417a5397ae2 Fixed numpy sndarray calls.
marcus
parents: 898
diff changeset
131 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
132 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
133
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
134 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
135 """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
136
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 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
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 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
140 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
141
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
142 numeric (deprecated; will be removed in Pygame 1.9.3.)
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
143 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
144
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 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
146 """
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 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
148
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 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
150 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
151 if __hasnumeric:
2142
4cf10018fadd Using Numeric by default now issues a deprecation warning. Fix hanging pointer bug in color.c.
Lenard Lindstrom <len-l@telus.net>
parents: 1568
diff changeset
152 import pygame._numericsndarray as numericsnd
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
153 __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
154 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
155 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
156
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 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
158 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
159 __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
160 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
161 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
162 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
163 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
164
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
165 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
166 """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
167
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 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
169
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
170 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
171 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
172 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
173 """
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
174 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
175
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
176 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
177 """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
178
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 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
180
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 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
182 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
183 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
184
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 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
186 """
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 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
188 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
189 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
190 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
191 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
192 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
193 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
194 return tuple (vals)