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

ossaudiodev full duplex

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In <11**********************@f14g2000cwb.googlegroups .com>, 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
Jul 18 '05 #2

P: n/a
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 <11**********************@f14g2000cwb.googlegroups .com>, 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


Jul 18 '05 #3

P: n/a
rj*@si.rr.com wrote:
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()


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
http://www.cosc.canterbury.ac.nz/~greg
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.