How to create a virtual audio output and route it in Ubuntu-based distro

16,129

Let me repeat: A single program or group of programs A (game) should output sound both to OBS and the headphone, while another single program or group of programs B (voice chat) should only output sound to the headphone, all on the Pulseaudio level. Correct?

Don't use snd-dummy, it works on the ALSA level. Instead, create a "null sink" on the Pulseaudio level:

pacmd load-module module-null-sink sink_name=game_sink sink_properties=device.description=Game-Sink

Use pavucontrol or, if it can do that, the sound configuration of elementary OS to switch all group A sound outputs to that sink. Each sink in Pulseaudio comes with a corresponding "monitor" source (you can see those in the OBS menu you included), so setup OBS to record from "Monitor of Game Sink".

That takes care of recording from group A only, but doesn't output it to the headphones. For that, you need a loopback from the mentioned monitor source to the headphone sink:

pacmd load-module module-loopback source="game_sink.monitor" sink="your-headphone-sink"

You can find out the names of all sinks, including the headphone sink, with

pacmd list-sinks | grep name:

Leave out the angular brackets when using the names as arguments.

Share:
16,129
RobotUnderscore
Author by

RobotUnderscore

Updated on September 18, 2022

Comments

  • RobotUnderscore
    RobotUnderscore over 1 year

    I am on elementaryOS 0.4.1 Loki, which is based on Ubuntu 16.04.1.

    I want to use OBS, a screen recorder, to record gameplay along with the sounds that come from the same video game. I also want to use a voice chat application in the background while playing the game, but I do not want any of it recorded by OBS.

    OBS can't selectively ignore the audio of certain programs, but it can record sound from a specified input device.

    enter image description here

    I want to create a virtual input and use pavucontrol's output list to route my voice chat application to that input so it's not picked up by OBS. At the same time, I want this input to play back to a headphone/line out port.

    enter image description here

    I know this can be done in Windows with software such as Virtual Audio Cables, but I don't know how to do the same thing in Linux.

    I already attempted to do something with sudo modprobe snd-dummy but it doesn't let me route the dummy to a headphone output.

    How should I approach this?

  • RobotUnderscore
    RobotUnderscore almost 7 years
    This is a great answer! The null sink setup works and I can set programs to output to it, but I'm having a bit of a snag with the loopback: i.imgur.com/aRJSVuf.png
  • dirkt
    dirkt almost 7 years
    Sorry, the loopback source should of course be the associated monitor (edited). If it still doesn't work, list all sources, and check if the name is correct: pacmd list-sources | grep name: