Can I pipe input from a Linux soundcard into 2 different applications?

2

I have an Ubuntu 16.04.3 LTS system with

  • an ASUS Xonar DGX soundcard, and
  • a generic USB sound card.

At our church, we want to be able to broadcast a service as well as record it as a WAV file. To accomplish this, I have the 3.5mm audio output cable from the sound board connected to a splitter, so that there are two cables to plug into the "Line In" connector on each soundcard.

Then, I use "arecord" to record the audio on one card, and "darkice" to create an MP3 stream on the other.

Ideally, I'd like to be able to have one soundcard handle both the recording and streaming simultaneously. Is such a thing possible? Or am I stuck using two soundcards with two applications?

David White

Posted 2017-09-08T01:54:10.043

Reputation: 135

To split piped input, use the tee command. e.g.: "echo hi | tee output.txt >> output2.txt" or "echo hi | tee output.txt | tee output2.txt" or "echo hi | tee output.txt output2.txt" – TOOGAM – 2017-09-08T04:51:06.167

Answers

1

Yes, it's easily possible. Are you really only running only ALSA, or are you also running Pulseaudio (the default on basically all distros for many years)?

With Pulseaudio, it should work out of the box.

With ALSA, make sure you are using the plughw device name (which internally adds a dsnoop pluging) instead of the hw device name. The dsnoop plugin will split the input stream into multiple streams for different applications.

Edit

As I said, instead of -D hw:0 etc. (modify for your hardware address), just use -D plughw:0 for arecord, and similar for the device name in darkice.

A condition is that no other program uses hw:0 directly. All of them must use plughw:0.

You don't really need to know details about dsnoop, ALSA does this automatically for you. (But you can read up details on the plugin page I linked).

You don't have to setup your own ~/.asoundrc, you don't have to modify any configuration files.

dirkt

Posted 2017-09-08T01:54:10.043

Reputation: 11 627

No, I just use plain old ALSA, not PulseAudio. This is a server, so no audio output is needed, and in fact there is almost no custom configuration for ALSA - I just use the devices with "arecord" and "darkice" as they are loaded automatically by modprobe.

Can you give me a few more details about how to use plughw/dsnoop? I see some configuration details in /etc/modprobe.d/alsa-base.conf, but I am not sure how to apply what you mentioned within that file. – David White – 2017-09-10T01:39:31.633

1perhaps I still have something not quite right? I'm using arecord -D plughw:0 -f S16_LE -c2 -r 44100 -vv foo.wav and also using a darkice config that specifies device = plughw:0, but there still appears to be blocking. One program can start, but the other will die with DarkIce: DarkIce.cpp:1273: can't open connector [0] or arecord: main:722: audio open error: Device or resource busy (depending on which one I started second). What am I missing? Thanks again. – David White – 2017-09-13T18:31:58.077

Are you sure that the plughw adds dsnoop? What worked for me was doing arecord -D dsnoop:0,0 which allowed me to run multiple listeners at the same time without modifying the alsa config. – Linus Unnebäck – 2018-01-14T18:38:57.720

0

I accepted dirkt's answer which got me most of the way there. Turns out I needed to create a dsnoop interface:

/etc/asound.conf

pcm.custom_snoop_card {
    type dsnoop
    ipc_key 420042
    ipc_key_add_uid 1
    slave {
        pcm "hw:0,0"   # the actual device
        format S16_LE
        channels 2
        rate 44100
    }
}

Now I can specify device = custom_snoop_card in my darkice config, and simultaneously make a WAV recording with arecord -D custom_snoop_card -f S16_LE -c2 -r 44100 -vv myfile.wav

David White

Posted 2017-09-08T01:54:10.043

Reputation: 135