3

I have an application that I need to record audio coming from. For that purpose I am using pavucontrol to set the audio input for the recording software to the monitor of the audio output. Now my issue is that most of the times, I do not want to hear the output. For that purpose I created a dummy output device using modprobe snd-aloop. This works great, but sometimes I want to listen in on the live audio stream, while still recording. That means I always have to change both the audio output of the sound application and the audio input of the recording application, which can get really tiring. Plus, that will result in the recording application to record everything I hear, not just the specific application.

I found this answer, but it's not exactly what I want since I don't want the sound output on all devices. Just the dummy loop and another output of my choosing. My system is arch-linux using gnome3-shell. I do NOT want this to be permanently so I need a solution that I can change on-the-fly.

Bonus question: I would love to have a shortcut that enabled/disables "live listening" (adding a second audio output to the application's audio stream), for that reason a CLI command would be great.

To be perfectly clear, I want to be able to switch between the following audio routings:

[playback app] --> [dummy aloop] --> [monitor of aloop] --> [recording app]

and

[playback app] --> [dummy aloop] --> [monitor of aloop] --> [recording app]
               \-> [headphones] (simultanously)
2

If you are using Pulseaudio anyway, have a look at Pulseaudio's modules, in particular module-loopback and module-null-sink. In my experience, snd-aloop is a bit of a pain to use, and as Pulseaudio mostly deals with sound stream transport, it's much easier in Pulseaudio.

So if the use case is "record output of one app in the background, use loadspeakers in the meantime for other stuff, occasionally listen in on the app", I'd create an appropriately named null sink, connect the app to it with pavucontrol (this will be remembered by Pulseaudio), record from the monitor source of this sink (again, this will be remembered, if necessary with command line options for the recording app to set the app name for Pulseaudio). When you want to listen in, make a loopback connection from the monitor source to your loudspeaker sink. Or make this loopback permanent, and mute/unmute it as required.

You can use pacmd or pactl to try all this out on the commandline. With the same commands you can also script your shortcuts. Make it permanent by using the Pulseaudio startup scripts.

So something along the lines of

pactl load-module module-null-sink sink_name=recsink
pactl load-module module-loopback source=recsink.monitor sink=your_loadspeaker_sink

Use pactl list short sinks to see your sink names. pactl help and pacmd help for more commands.

  • 1
    This is absolutely perfect. Exactly what I want. I'm even able to control the sink/source using pavucontrol, and muting via shortcut works too. Thank you very much! – confetti Jul 24 '18 at 16:39
  • I just realized that the pulseaudio process usage is now 11% - constant. That is with only the null-sink active and no live-listening. It's 12% with live listening on. Usually pulseaudio wouldn't even use 1% at all. Is there a way to reduce this? – confetti Jul 25 '18 at 2:16
  • Is that with the loopback active, but muted? If yes, I guess have to stop or unload the loopback stream instead of just muting it. Continuously duplicating a buffer and possibly doing format conversion will incur CPU usage, no matter what you do... – dirkt Jul 25 '18 at 5:44
  • It seems that the load was caused mainly by module-null-sink. I'm using alsa's snd-aloop again with your loopback solution and it still works great while CPU usage with live-listening is only 4%, 3% without. – confetti Jul 25 '18 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.