2

I need to create two ALSA loopback interfaces to link two applications.

I have the following in /etc/modprobe.d/sound.conf -

alias snd-card-1 snd-aloop
options snd-aloop pcm_substreams=2,2 id=1,2 enable=1,1 index=10,11

This creates the loopbacks and it's working, but it also creates loads of surround sound interfaces that I do not require. Example below-

surround51:CARD=D2,DEV=0
    Loopback, Loopback PCM
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=D2,DEV=0
    Loopback, Loopback PCM
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

Is there anyway I can create loopback devices for Stereo only?

Thanks

2 Answers 2

2

I discovered there were configuration files in:

/usr/share/alsa/pcm

That were creating the surround sound interfaces. I deleted the files, and the interfaces are no longer created.

4
  • Note that those are the standard configuration files that manage creation of an "additional" layer in ALSA on top of the hardware interfaces. And that means all interfaces, not only the loopback one. And even if you don't need them, some applications may, and keeping them does no harm. Also, I consider snd-aloop one of the most painful ways to get a loopback function, and I'd use it only if it's an ALSA-only system (which most systems today are not).
    – dirkt
    Mar 17, 2018 at 6:42
  • I'm open to other suggestions and indeed got it working with pulseaudio, but one of the applications I am linking only supports ALSA.
    – marrold
    Mar 17, 2018 at 8:23
  • It's fairly easy with Pulseaudio (just attach the recording application to the monitor source of the sink of the playback application). In principle, all ALSA applications should be able to use Pulseaudio via the pulse audio device, which you should configure as default ALSA device. Anything particular about your application so it doesn't work this way?
    – dirkt
    Mar 17, 2018 at 8:30
  • It may well work, but I've found it hard work to find good documentation on doing it. I need two separate loops if that's worth noting. I have experience using Linux, but having to mess around with sound is new to me
    – marrold
    Mar 17, 2018 at 8:34
0

Alternative with Pulseaudio:

To make one application under Pulseaudio record the output of another application is fairly easy:

Pulseaudio has the concept of sound sources and sound sinks. You can arbitrarily connect up application to those. Pulseaudio has modules to remember those connections, and will restore the connection sthe next time the application is restarted (if the connection is possible). Otherwise Pulseaudio will choose default connections for you.

You can inspect and change all this using the pavucontrol GUI, which also allows you to change volume controls both on the connection between application and source/sink, and the source/sink itself.

The basic use case four source/sinks is to represent hardware recording and playback. But it's not limited to that: There are various ways to create other kinds of sources and sinks. In particular, each sink has connected to it a .monitor source, which just loopbacks. Actually pavucontrol uses those to implement the sound metering display.

So settung up two loops, are even 100 loops, or tee-shaped connections with several applications listening to one application is all really straightforward.

If the GUI is not enough for you, there are also commandline applications pacmd and pactl, that allow scripting. See pacmd help or pactl help for details. (I've no idea why there are two of them...). However, their output is not particularly easy to parse, and needs a bit of fiddling with grep -A etc.

Pulseaudio includes a compatibility layer to allow all ALSA applications to use Pulseaudio, via the pulse ALSA device. If you have an .asoundrc like

pcm.!default pulse
ctl.!default pulse

then every ALSA application will use Pulseaudio by default (unless you configure it to use a different ALSA device). Some ALSA applications think they need to use hw:... (which is bad design), and you've to convice those applications to use default instead. A few ALSA applications try to do things that only work on hw:..., and these will cause problems, but they are rare.

Bottom line: Routing sound is a lot easier with Pulseaudio (or with Jack) than with ALSA directly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .