Changeset 1189

Show
Ignore:
Timestamp:
08/04/08 05:03:07 (4 months ago)
Author:
cdavid
Message:

Start working on alsa device abstraction.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/audiolab/scikits/audiolab/soundio/_alsa.pyx

    r1188 r1189  
    5858                SND_PCM_FORMAT_FLOAT64 
    5959                SND_PCM_FORMAT_IEC958_SUBFRAME 
     60 
     61        ctypedef struct snd_pcm_t 
     62 
     63        int snd_pcm_open(snd_pcm_t **, char*, int, int) 
     64        int snd_pcm_close(snd_pcm_t *) 
     65 
    6066        char* snd_strerror(int error) 
    6167 
     
    106112                free(sptr) 
    107113        return cardname 
     114 
     115cdef class Device: 
     116        cdef snd_pcm_t* pcmhdl 
     117        cdef public char* name 
     118 
     119        def __new__(self, device = "default", stream = SND_PCM_STREAM_PLAYBACK): 
     120                self.pcmhdl = NULL 
     121 
     122                st = snd_pcm_open(&self.pcmhdl, device, stream, 0) 
     123                if st < 0: 
     124                        raise AlsaException("Cannot open device %s: %s" % (device, snd_strerror(st))) 
     125 
     126        def __init__(self, device = "default", stream = SND_PCM_STREAM_PLAYBACK): 
     127                self.name = device 
     128 
     129        def __dealloc__(self): 
     130                if self.pcmhdl: 
     131                        snd_pcm_close(self.pcmhdl) 
  • trunk/audiolab/scikits/audiolab/soundio/alsa.py

    r1188 r1189  
    11from _alsa import card_name, card_indexes, asoundlib_version 
     2from _alsa import Device 
    23 
    34if __name__ == '__main__': 
     
    56    for i in card_indexes(): 
    67        print card_name(i) 
     8 
     9    dev = Device() 
     10    print "Device name:", dev.name