[linux-audio-user] ALSA, ens1371 and/or intel8x0, full-duplex, pcm back to input.

Tomi Ollila Tomi.Ollila at iki.fi
Fri Mar 14 15:32:00 EST 2003


I've been wondering/working a bit trying to use microphone and headphones
at the same time in different Linux systems; I have exactly the same
problem in both systems, and the "partial" fix works similarly in both

I've tried to find out documentation of the problem, with low success
ratio; I'd be suprised is no-one else has same problems... maybe
the search keywords I've been using has been poor choises...

As a last resort I turn to this list ;/

The problem is when opening the audio device in full duplex mode the pcm
output is feed back to the input; this continues even I mute the microphone
input -- then I just can not feed more of my voice back to the "loop".

So the problem can not be that the output coming out of headphones loops
back to the microphone over the air -- and eventually I can verify this
with a partial solution explained below.

In the first place, to get full duplex audio working I installed alsa
software to my machines. Both of the machines have Red Hat 8.0, and
the alsa stuff was downloaded from www.freshrpms.net -- the latest version,
alsa-kernel-0.9.1-fr1_2.4.18_26.8.0 was uploaded there in just a day or two

The machines were one desktop machine with soundblaster 64. More
detailed information of it can be found at

The other one is Dell laptop, with Intel 8x0... More detailed
information of that is at:

Note: Below I have not described which machine of the above I were using,
for the simple reason, that the functionality was identical...

To do my tests I began with $ arecord | aplay. Pretty soon I had horrible
noise in my headphones, and started to adjust mixed settings with
aumix (Since then I've used gnome-volume-control and alsamixer to setup,
but with same results). The final values, with best results, of aumix
settings are (graphical version at http://www.iki.fi/too/snd/aumix.png)

vol 100, 100, R
pcm 48, 48
speaker 0, 0
line 0, 0, P
mic 100, 100, P
cd 0, 0, P
igain 100, 100
line1 0, 0, P
phin 0, 0, P
video 0, 0, P

To get some delay between record and play I wrote simple utility program
called delaypipe (http://www.iki.fi/too/snd/delaypipe.c). Delaypipe
buffers the number of bytes given on the command line from stdin and
feeds that to stdout after buffer is full. For example:

$ arecord | ./delaypipe 16000 | aplay

stored (about) 2 secs of data from arecord (default 8bits, 8000 hz, mono) 
before aplay gets the data. If I now say `foo' to the microphone, it
is echoed after 2 secs -- and then again after 2 secs (with some additional
noise, and then again and again...

$ arecord  -f S16_LE -r 44100 | ./delaypipe 176000 | aplay  -f S16_LE -r 44100

does the same, with somewhat better sound quality.

while reading the .asoundrc (which I could not understand much) there was
an example

$ arecord -f S16_LE -r 44100 -c 4 -D multi \
  | aplay -f S16_LE -r 44100 -c 4 -D multi

While this did not work: 
ALSA lib pcm.c:1906:(snd_pcm_open_noupdate) Unknown PCM multi

... and with removing -D multi from the above command line I could
get only silence, after few trial&error tests I come up with:

$ arecord -f S16_LE -r 44100 -c 3 | ./delaypipe 80000 |
  | aplay -f S16_LE -r 44100 -c 3

Now, if I spoke to the microphone, after a very short delay (1/3 of a
second) I could hear myself speaking, in one of the headphone, *ONLY
ONCE*. I had short fun with it, then gave headphones (with mic) to my 4
year old son -- he played with it about 10 minutes :D.

At last I tested with 
$ arecord -c 3 | ./delaypipe 10000 | aplay -c 3

The difference was that now the sound came from the other headphone than
with the previous command line.

The interesting thing is that with the sb64 compared to intel8x0 the
it was different headphone where I heard my voice (or at least I think
it was so).

This shows it is possible to record and listen sound through the soundcards
I have at the same time. why simple arecord | aplay doesn't work properly I
don't understand (due to lack of knowledge in this issue).

Does anyone know (other) solutions how to get it working as I'd like.
Preferably so that also oss -applications work. I need this stuff for
VOIP purposes (is there clients that work with alsa out-of-the box and
probably knows to tweak settings so that this works.)

The only way I could do any solutions with my current knowledge would be

$ arecord -c 3 | onechannel | gsmcompress | udpsend <host>/<port> &

$ udpreceive <port> | gsmdecompress | threechannels | aplay -c 3 &

where: onechannel strips the 2 other channels (how are the channels packed?)
       gsmcompress compresses the data with gsm... (or ADPCM or ...)
       udpsend ...
       udpreceive ...
       gsmdecompress ...
       threechannels adds 2 (silent) channels to the input data ...

Anybody care to integrate all of this stuff to single `alsavoip'
application. If not, and there is no no more suitable working
voip applications I might take the task ACN.

Anyway, any info to my problems is greatly appreciated.


PS: If you get this mail twice, it is probably my fault.

More information about the Linux-audio-user mailing list