Hello,

I am writing an app that records from the soundcard using ossaudiodev.
In the OSS programmer's guide they recommend when reading data fragments from 
the soundcard
to use the fragment size as it is requested by the driver. According to the 
programmer's guide
the ioctl call to determine the requested fragment size is:

    int frag_size;
    if ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1)
        error();

Unfortunately this procedure is not implemented in the ossaudiodev module, so I
tried to write it myself.
>From reading the fcntl module's docs, I came to the following solution:

    try:
        f = array.array('h', [0])
        fcntl.ioctl(audio_fd, ossaudiodev.SNDCTL_DSP_GETBLKSIZE, f, 1)
        frag_size = f.tolist()[0]
    except:
        frag_size = -1
    if frag_size <= 0:
        frag_size = 4096


This *seems* to work, I tried several soundcards and got frag_size values like 
4096, 8192 or 16384 .
However I am not really sure about what I am doing there, so I would feel more 
confident
if anyone could explain how ioctl is supposed to be used ( I also felt that I 
should use
the try...except block for the call in case it fails, but I don't have an idea 
"except *what*").

Any hints are much appreciated.

thanks in advance

Michael
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to