Can't simultaneously read/write from ossaudio dsp device

Tito generic_user25 at yahoo.com
Sun Mar 12 18:50:09 EST 2006


For an internet telephone application, I need to be able to read and
write data to and from /dev/dsp simultaneously.  I wrote some code and
its not working.  Anyone have any working code to do this?  I am
assuming my card is full duplex, it is a built-in sound card on a new
dell 600m laptop, but I am not sure how to tell for sure.  But I think
the problem is not so much my sound card, but that I am making some
fundamentally wrong assumption on the way to do this ;)  Also I am
definitely a newbie when it comes to audio coding, so any corrections
or tips are welcome.

Here is some test code that is failing for me
--------------------------------------------------------

from twisted.internet.task import LoopingCall
from twisted.internet import reactor
import os, sys, wave, audioop

"""
While playing the contents of test1.wav,  talk into the mic
and have the audio recorded into /tmp/out.wav
"""

def playnlisten_out():
    audio = wavin.readframes(1024)
    stereoaudio = audioop.tostereo(audio, 2, 1, 1)
    dsp.write(stereoaudio)

def playnlisten_in():
    audio = dsp.read(640)
    wavout.write(audio)

def both():
    playnlisten_out()
    playnlisten_in()

dsp = ossaudiodev.open('/dev/dsp', 'rw')

wavin = wave.open("test1.wav", "r")
wavout = wave.open("/tmp/out.wav", "w")

both_loop = LoopingCall(both)
both_loop.start(0.02)

reactor.run()

------------ Actual behavior  ------------------------

It fails with an error:

     dsp.write(stereoaudio)
exceptions.IOError: [Errno 19] No such device

If I comment either playnlisten_out() or playnlisten_in() then the
other function will work.  They just don't work at the same time.

------------ Sys info ------------------------
box:~# lsmod | grep -i audio
i810_audio             30356  1
ac97_codec             16908  1 i810_audio
soundcore               9824  3 snd,i810_audio
box:~# lsmod | grep -i snd
snd_pcm_oss            48168  0
snd_mixer_oss          16640  1 snd_pcm_oss
snd_intel8x0m          18632  0
snd_intel8x0           33068  0
snd_ac97_codec         59268  2 snd_intel8x0m,snd_intel8x0
snd_pcm                85412  3 snd_pcm_oss,snd_intel8x0m,snd_intel8x0
snd_timer              23172  1 snd_pcm
snd_page_alloc         11144  3 snd_intel8x0m,snd_intel8x0,snd_pcm
gameport                4736  1 snd_intel8x0
snd_mpu401_uart         7296  1 snd_intel8x0
snd_rawmidi            23232  1 snd_mpu401_uart
snd_seq_device          7944  1 snd_rawmidi
snd                    50148  10
snd_pcm_oss,snd_mixer_oss,snd_intel8x0m,snd_intel8x0,snd_ac97_codec,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device
soundcore               9824  3 snd,i810_audio

box:~# lspci
0000:00:1f.5 Multimedia audio controller: Intel Corp. 82801DB/DBL/DBM
(ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller (rev 01)

box:~# uname -a
Linux box 2.6.7-1-386 #1 Thu Jul 8 05:08:04 EDT 2004 i686 GNU/Linux




More information about the Python-list mailing list