By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Can't simultaneously read/write from ossaudio dsp device

P: n/a
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_intel8 x0,snd_ac97_codec,snd_pcm,snd_timer,snd_mpu401_uar t,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

Mar 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I got it working! There was another thread http://tinyurl.com/pebqc on
this group where someone had the same problem. I changed my code to
the following:

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)
dspout.write(stereoaudio)

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

def both():
playnlisten_out()
playnlisten_in()

dspout = ossaudiodev.open('/dev/dsp', 'w') # 2 file handles
dspin = ossaudiodev.open('/dev/dsp', 'r')

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

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

reactor.run()

and it worked as expected. I did not need to mess around with
/dev/mixer.

Mar 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.