Can't simultaneously read/write from ossaudio dsp device

Discussion in 'Python' started by Tito, Mar 12, 2006.

  1. Tito

    Tito Guest

    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
     
    Tito, Mar 12, 2006
    #1
    1. Advertising

  2. Tito

    Tito Guest

    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.
     
    Tito, Mar 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Davis
    Replies:
    16
    Views:
    915
    Dennis Lee Bieber
    Jan 12, 2007
  2. kanchan
    Replies:
    1
    Views:
    834
    Karthik Kumar
    Nov 13, 2004
  3. Pallav singh
    Replies:
    6
    Views:
    1,965
    James Kanze
    Jun 14, 2009
  4. pravin.vhdl
    Replies:
    0
    Views:
    663
    pravin.vhdl
    Aug 17, 2009
  5. Stoyan Stoyanov

    read/write to a character device

    Stoyan Stoyanov, Feb 15, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    392
    Stoyan Stoyanov
    Feb 16, 2004
Loading...

Share This Page