Changeset 1192
- Timestamp:
- 08/04/08 06:29:40 (4 months ago)
- Files:
-
- trunk/audiolab/scikits/audiolab/soundio/_alsa.pyx (modified) (6 diffs)
- trunk/audiolab/scikits/audiolab/soundio/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/audiolab/scikits/audiolab/soundio/_alsa.pyx
r1190 r1192 60 60 61 61 ctypedef struct snd_pcm_t 62 # XXX: how to make sure the typedef is OK ? 63 ctypedef unsigned long snd_pcm_uframes_t 62 64 63 65 int snd_pcm_open(snd_pcm_t **, char*, int, int) 64 66 int snd_pcm_close(snd_pcm_t *) 67 int snd_pcm_drain(snd_pcm_t *) 65 68 66 69 int snd_pcm_set_params(snd_pcm_t *, snd_pcm_format_t, 67 70 snd_pcm_access_t, unsigned int, 68 71 unsigned int, int, unsigned int) 72 73 int snd_pcm_writei(snd_pcm_t *, void*, snd_pcm_uframes_t) 69 74 70 75 char* snd_strerror(int error) … … 73 78 int snd_card_get_name(int icard, char** name) 74 79 char* snd_asoundlib_version() 80 81 cdef extern from "numpy/arrayobject.h": 82 ctypedef int intp 83 ctypedef extern class numpy.ndarray [object PyArrayObject]: 84 cdef char *data 85 cdef int nd 86 cdef intp *dimensions 87 cdef intp *strides 88 cdef int flags 75 89 76 90 cdef extern from "stdlib.h": … … 81 95 size_t strlen(char *s) 82 96 char *strcpy(char *dest, char *src) 97 98 cdef extern from "stdint.h": 99 ctypedef unsigned short int16_t 83 100 84 101 cdef extern from "Python.h": … … 117 134 return cardname 118 135 119 cdef class PCM:136 cdef class _PCM: 120 137 cdef snd_pcm_t* pcmhdl 121 138 cdef public char* name … … 136 153 137 154 cdef class Device: 138 cdef PCM pcm155 cdef _PCM pcm 139 156 cdef unsigned int samplerate 140 cdef unsigned int channels 157 # XXX: set property instead 158 cdef public unsigned int channels 159 cdef snd_pcm_format_t format 160 cdef snd_pcm_access_t access 141 161 def __init__(self, samplerate = 48000, channels = 1, 142 162 format = SND_PCM_FORMAT_S16, 143 163 access = SND_PCM_ACCESS_RW_INTERLEAVED): 144 self.pcm = PCM()164 self.pcm = _PCM() 145 165 146 166 self.samplerate = samplerate 147 167 self.channels = channels 168 169 self.access = access 170 self.format = format 148 171 149 172 st = snd_pcm_set_params(self.pcm.pcmhdl, format, access, channels, … … 152 175 raise AlsaException() 153 176 177 def play_short(self, ndarray input): 178 cdef int16_t* p = <int16_t*>input.data 179 cdef int16_t* buff = NULL 180 #cdef int n = input.dimensions[0] 181 cdef int n = input.dimensions[0] 182 cdef int nb = n / 1024 / 16 183 cdef snd_pcm_uframes_t bufsz = 1024 * 16 184 185 assert self.format == SND_PCM_FORMAT_S16 186 assert self.access == SND_PCM_ACCESS_RW_INTERLEAVED 187 188 for i from 0 <= i < nb: 189 st = snd_pcm_writei(self.pcm.pcmhdl, &p[i * bufsz], bufsz) 190 if not st == bufsz: 191 print "Error while writing to device", st 192 print snd_strerror(st) 193 194 snd_pcm_drain(self.pcm.pcmhdl) 195 154 196 def _get_name(self): 155 197 return self.pcm.name trunk/audiolab/scikits/audiolab/soundio/setup.py
r1184 r1192 2 2 from distutils.extension import Extension 3 3 from Cython.Distutils import build_ext 4 from numpy.distutils.misc_util import get_numpy_include_dirs 4 5 5 6 setup(name = "PyrexGuide", 6 ext_modules=[Extension("_alsa", ["_alsa.pyx"], libraries = ['asound'])], 7 ext_modules=[ 8 Extension("_alsa", ["_alsa.pyx"], 9 libraries = ['asound'], 10 include_dirs = get_numpy_include_dirs())], 7 11 cmdclass = {'build_ext': build_ext}) 8 12
