~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to lib/sndarray.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
Supported array systems are
37
37
 
 
38
  numpy
38
39
  numeric
39
 
  numpy
40
40
 
41
 
The default will be Numeric, if installed. Otherwise, numpy will be set
42
 
as default if installed. If neither Numeric nor numpy are installed, the
 
41
The default will be numpy, if installed. Otherwise, Numeric will be set
 
42
as default if installed. If neither numpy nor Numeric are installed, the
43
43
module will raise an ImportError.
44
44
 
45
45
The array type to use can be changed at runtime using the use_arraytype()
63
63
 
64
64
# Try to import the necessary modules.
65
65
try:
 
66
    import pygame._numpysndarray as numpysnd
 
67
    __hasnumpy = True
 
68
    __arraytype = "numpy"
 
69
except ImportError:
 
70
    __hasnumpy = False
 
71
 
 
72
try:
66
73
    import pygame._numericsndarray as numericsnd
67
74
    __hasnumeric = True
68
 
    __arraytype = "numeric"
69
 
except ImportError, msg:
 
75
    if not __hasnumpy:
 
76
        __arraytype = "numeric"
 
77
except ImportError:
70
78
    __hasnumeric = False
71
79
 
72
 
try:
73
 
    import pygame._numpysndarray as numpysnd
74
 
    __hasnumpy = True
75
 
    if not __hasnumeric:
76
 
        __arraytype = "numpy"
77
 
except ImportError:
78
 
    __hasnumpy = False
79
 
 
80
80
if not __hasnumpy and not __hasnumeric:
81
 
    raise ImportError, "no module named numpy or Numeric found"
 
81
    raise ImportError("no module named numpy or Numeric found")
82
82
 
83
83
def array (sound):
84
84
    """pygame.sndarray.array(Sound): return array
93
93
        return numericsnd.array (sound)
94
94
    elif __arraytype == "numpy":
95
95
        return numpysnd.array (sound)
96
 
    raise NotImplementedError, "sound arrays are not supported"
 
96
    raise NotImplementedError("sound arrays are not supported")
97
97
 
98
98
def samples (sound):
99
99
    """pygame.sndarray.samples(Sound): return array
108
108
        return numericsnd.samples (sound)
109
109
    elif __arraytype == "numpy":
110
110
        return numpysnd.samples (sound)
111
 
    raise NotImplementedError, "sound arrays are not supported"
 
111
    raise NotImplementedError("sound arrays are not supported")
112
112
 
113
113
def make_sound (array):
114
114
    """pygame.sndarray.make_sound(array): return Sound
123
123
        return numericsnd.make_sound (array)
124
124
    elif __arraytype == "numpy":
125
125
        return numpysnd.make_sound (array)
126
 
    raise NotImplementedError, "sound arrays are not supported"
 
126
    raise NotImplementedError("sound arrays are not supported")
127
127
 
128
128
def use_arraytype (arraytype):
129
129
    """pygame.sndarray.use_arraytype (arraytype): return None
145
145
        if __hasnumeric:
146
146
            __arraytype = arraytype
147
147
        else:
148
 
            raise ValueError, "Numeric arrays are not available"
 
148
            raise ValueError("Numeric arrays are not available")
149
149
        
150
150
    elif arraytype == "numpy":
151
151
        if __hasnumpy:
152
152
            __arraytype = arraytype
153
153
        else:
154
 
            raise ValueError, "numpy arrays are not available"
 
154
            raise ValueError("numpy arrays are not available")
155
155
    else:
156
 
        raise ValueError, "invalid array type"
 
156
        raise ValueError("invalid array type")
157
157
 
158
158
def get_arraytype ():
159
159
    """pygame.sndarray.get_arraytype (): return str