ossaudiodev full duplex

2005-03-26 Thread rjm
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_channels= 1
sample_rate= 44100
sample_width= 2
frames_out= get_frames("test.wav")

fh= ossaudiodev.open("/dev/dsp", "rw")
fh.setparameters(ossaudiodev.AFMT_S16_LE, number_of_channels,
sample_rate)
fh.writeall(frames_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.open("/dev/dsp", "w")
fh.setparameters(ossaudiodev.AFMT_S16_LE, number_of_channels,
sample_rate)
fh.writeall(frames_out)
fh.close()

fh= ossaudiodev.open("/dev/dsp", "r")
fh.setparameters(ossaudiodev.AFMT_S16_LE, number_of_channels,
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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ossaudiodev full duplex

2005-03-26 Thread rjm
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:
> In <[EMAIL PROTECTED]>, rjm
wrote:
>
> > [recording the output]
> >
> > Any ideas?  Am I doing something fundamentally wrong?  Any help
would
> > be greatly appreciated.
>
> 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

-- 
http://mail.python.org/mailman/listinfo/python-list