ossaudiodev full duplex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rjm@si.rr.com

    #1

    ossaudiodev full duplex

    I'm messing around with trying to record sound reflections off of
    various objects at different frequencies. I'm using python 2.4 on
    Fedora Core 3 and I have an SBLive card. Basically, I want to send
    some samples through a speaker and then record from an input source
    (the line input on the sound card which I have the output of a mixer
    going into and a mic plugged into the mixer). So I want to using the
    soundcard in full duplex mode. I'm trying something like this:

    number_of_chann els= 1
    sample_rate= 44100
    sample_width= 2
    frames_out= get_frames("tes t.wav")

    fh= ossaudiodev.ope n("/dev/dsp", "rw")
    fh.setparameter s(ossaudiodev.A FMT_S16_LE, number_of_chann els,
    sample_rate)
    fh.writeall(fra mes_out)
    frames_in= fh.read(number_ of_samples * sample_width)
    fh.close()


    However, even if I turn off the speakers I get the original output tone
    back from the read (as well as the input from the mic). I'm assuming
    it's the same internal buffer somewhere on the soundcard so when I do
    the read I'm really reading what the write just wrote (because I get
    that orginal tone in the background even though I turned off the
    speaker so it's just not the reflections coming back through the
    mic...it's happening internally somewhere). If I unplug everything from
    the sound card I'll still get it.

    I tried closing the filehandle after the write and then reopening it
    before the read and I also tried opening two filehandles, one to
    /dev/dsp and another to /dev/dsp1 and still have th same problem. In
    the above example I tried the ossaudiodev's sync() and reset()
    functions inbetween the write() and read(). Also still have the same
    problem even when I do this:

    fh= ossaudiodev.ope n("/dev/dsp", "w")
    fh.setparameter s(ossaudiodev.A FMT_S16_LE, number_of_chann els,
    sample_rate)
    fh.writeall(fra mes_out)
    fh.close()

    fh= ossaudiodev.ope n("/dev/dsp", "r")
    fh.setparameter s(ossaudiodev.A FMT_S16_LE, number_of_chann els,
    sample_rate)
    frames_in= fh.read(number_ of_samples * sample_width)
    fh.close()


    Any ideas? Am I doing something fundamentally wrong? Any help would
    be greatly appreciated.
    Thanks.
    -richie

  • Marc 'BlackJack' Rintsch

    #2
    Re: ossaudiodev full duplex

    In <1111849301.867 062.271060@f14g 2000cwb.googleg roups.com>, rjm wrote:
    [color=blue]
    > [recording the output]
    >
    > Any ideas? Am I doing something fundamentally wrong? Any help would
    > be greatly appreciated.[/color]

    You have to use the mixer to select which channel(s) should be the source
    of the recording. It's best is to deselect all other sources except the
    line-in or microphone input because some soundcards can mix several input
    sources when recording.

    The `ossaudiodev` module has an `openmixer()` function but it may be
    easier to use one of the graphical mixer programs like `kmix` or
    `alsamixergui`.

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • rjm@si.rr.com

      #3
      Re: ossaudiodev full duplex

      Thanks that was helpful.

      The mixer seems werid though. I tested first with the alsamixer and the
      only way I can get the line-in in to record is to put the "mix" channel
      into capture mode. However, doing that mixes all the record sources
      together so I get the orginal sound that is played through the output
      on the "Wave" channel recorded as well. If I don't select the "mix"
      channel for capture I still get the "wave" channel in the record but I
      don't get the line-in channel anymore.

      Thanks again for your help at least it set me in the right direction
      for things to look for.
      -richie



      Marc 'BlackJack' Rintsch wrote:[color=blue]
      > In <1111849301.867 062.271060@f14g 2000cwb.googleg roups.com>, rjm[/color]
      wrote:[color=blue]
      >[color=green]
      > > [recording the output]
      > >
      > > Any ideas? Am I doing something fundamentally wrong? Any help[/color][/color]
      would[color=blue][color=green]
      > > be greatly appreciated.[/color]
      >
      > You have to use the mixer to select which channel(s) should be the[/color]
      source[color=blue]
      > of the recording. It's best is to deselect all other sources except[/color]
      the[color=blue]
      > line-in or microphone input because some soundcards can mix several[/color]
      input[color=blue]
      > sources when recording.
      >
      > The `ossaudiodev` module has an `openmixer()` function but it may be
      > easier to use one of the graphical mixer programs like `kmix` or
      > `alsamixergui`.
      >
      > Ciao,
      > Marc 'BlackJack' Rintsch[/color]

      Comment

      • Greg Ewing

        #4
        Re: ossaudiodev full duplex

        rjm@si.rr.com wrote:[color=blue]
        > fh= ossaudiodev.ope n("/dev/dsp", "rw")
        > fh.setparameter s(ossaudiodev.A FMT_S16_LE, number_of_chann els,
        > sample_rate)
        > fh.writeall(fra mes_out)
        > frames_in= fh.read(number_ of_samples * sample_width)
        > fh.close()[/color]

        One problem with this is that you can't use a single file
        object for independent reading and writing at the same
        time. C stdio implementations tend to get confused if
        you try to do that.

        You may have other problems as well, but you'll at least
        need to open two separate file objects.

        --
        Greg Ewing, Computer Science Dept,
        University of Canterbury,
        Christchurch, New Zealand

        Comment

        Working...