Mercurial > pygame
annotate lib/_numpysndarray.py @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 018779fb04f5 |
| children |
| 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 |
| 899 | 21 """pygame module for accessing sound sample data using numpy |
| 22 | |
| 23 Functions to convert between numpy arrays and Sound objects. This module | |
| 24 will only be available when pygame can use the external numpy package. | |
| 25 | |
| 26 Sound data is made of thousands of samples per second, and each sample | |
| 27 is the amplitude of the wave at a particular moment in time. For | |
| 28 example, in 22-kHz format, element number 5 of the array is the | |
| 29 amplitude of the wave after 5/22000 seconds. | |
| 30 | |
| 31 Each sample is an 8-bit or 16-bit integer, depending on the data format. | |
| 32 A stereo sound file has two values per sample, while a mono sound file | |
| 33 only has one. | |
|
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
|
34 """ |
|
424ef30fa1ea
Added numpy 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 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
|
37 import pygame.mixer as 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
|
38 import 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
|
39 |
|
424ef30fa1ea
Added numpy 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 |
|
1109
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
41 def array (sound): |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
42 """pygame._numpysndarray.array(Sound): return array |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
43 |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
44 Copy Sound samples into an array. |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
45 |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
46 Creates a new array for the sound data and copies the samples. The |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
47 array will always be in the format returned from |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
48 pygame.mixer.get_init(). |
|
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
49 """ |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2080
diff
changeset
|
50 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2080
diff
changeset
|
51 return numpy.array (sound, copy=True) |
|
1109
438669b899b0
Fixed bug with mixer.get_init() Thanks Frankie Robertson
Rene Dudfield <renesd@gmail.com>
parents:
903
diff
changeset
|
52 |
|
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
|
53 def samples (sound): |
| 899 | 54 """pygame._numpysndarray.samples(Sound): return array |
| 55 | |
| 56 Reference Sound samples into an array. | |
| 57 | |
| 58 Creates a new array that directly references the samples in a Sound | |
| 59 object. Modifying the array will change the Sound. The array will | |
| 60 always be in the format returned from pygame.mixer.get_init(). | |
|
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
|
61 """ |
|
424ef30fa1ea
Added numpy 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 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2080
diff
changeset
|
63 return numpy.array (sound, copy=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
|
64 |
|
424ef30fa1ea
Added numpy 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 def make_sound (array): |
| 899 | 66 """pygame._numpysndarray.make_sound(array): return Sound |
| 67 | |
| 68 Convert an array into a Sound object. | |
| 69 | |
| 70 Create a new playable Sound object from an array. The mixer module | |
| 71 must be initialized and the array format must be similar to the mixer | |
| 72 audio format. | |
|
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 """ |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2080
diff
changeset
|
74 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2080
diff
changeset
|
75 return mixer.Sound (array=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
|
76 |
