PDA

View Full Version : setting up virtual audio cables in linux



skj310
April 2nd, 2017, 06:11
To start we need to add some new sinks and loopbacks to these sinks within the pulse startup configuration. We do this by altering the default.pa script in the pulse folder. More information on pulse sinks can be found here:
https://wiki.archlinux.org/index.php/PulseAudio/Examples#Monitor_specific_output
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/#index1h3
https://askubuntu.com/questions/257992/how-can-i-use-pulseaudio-virtual-audio-streams-to-play-music-over-skype

Here are the additions I added to the end of default.pa

naftahorn@hostname ~ $ sudo vi /etc/pulse/default.pa

...

#naftahorn - to add echo cancel on startup for recording with internal microphones that
# tend to pickup a lot of background noise
.nofail
load-module module-echo-cancel
#naftahorn - create 2 new audio sinks (i.e. mimic physical devices)
# virtual1 - required to link with h/w microphone and an application that is playing
# sound/music (e.g. discord, teamspeak, music player, etc.)
# virtual2 - required to link with virtual1
load-module module-null-sink sink_name=virtual1 sink_properties=device.description=v1_mic_music
load-module module-null-sink sink_name=virtual2 sink_properties=device.description=v2_music
# naftahorn - the loopbacks are the recording channels
# 1st loopback for virtual1 - link this to your Microphone device
# 2nd loopback for virtual1 - link this to "Monitor of Built-in Audio Analog Stereo"
# loopback for virtual2 - link this to "Monitor of v1_mic_music"
load-module module-loopback sink=virtual1
load-module module-loopback sink=virtual1
load-module module-loopback sink=virtual2
After starting and logging in to your desktop session, open a terminal and run the following command to check that your echo-cancel sink and virtual sinks have loaded:

naftahorn@hostname ~ $ pactl list short sinks
0 alsa_output.pci-0000_00_1f.3.analog-stereo module-alsa-card.c s16le 2ch 48000Hz IDLE
1 alsa_output.pci-0000_00_1f.3.analog-stereo.echo-cancel module-echo-cancel.c s16le 1ch 32000Hz IDLE
2 virtual1 module-null-sink.c s16le 2ch 48000Hz RUNNING
3 virtual2 module-null-sink.c s16le 2ch 48000Hz RUNNING
Now let's start to take a look at what this looks like within the Pulse Audio Volume Controller. If you do not have the application installed then install it with "sudo apt install pavucontrol". Once installed start the application and let's take a look at the "Playback" tab:
https://www.fantasygrounds.com/forums/attachment.php?attachmentid=18406

From the playback tab, you can see that both Discord and Teamspeak are playing back on the default "Built-in Audio Analog Stereo", which is in fact the default internal speakers. If you flip over to the "Output Devices" tab you will notice that "Built-in Audio Analog Stereo" is the name tied to either:

the internal speakers, or
the headphones (if you've connected and are using)

https://www.fantasygrounds.com/forums/attachment.php?attachmentid=18407

The significant changes are tied tothe "Recording" tab as this is where we need to make changes:
https://www.fantasygrounds.com/forums/attachment.php?attachmentid=18408


First link the physical microphone to the echo-cancel virtual device, in my case I'm linking to a Logitech: HD Webcam C910
this will create a new recording entry called "xxxx (echo cancelled with Built-in Audio Analog Stereo)"; this is important when using something like an internal microphone or a microphone attached to a webcam (in my case I'm using a USB connected Logitech HD Webcam C910 which has a built in microphone that is better quality than my laptops internal microphone)
Link to "xxxx (echo cancelled with Built-in Audio Analog Stereo)"
Link to "Monitor of Built-in Audio Analog Stereo"
you should notice that "Monitor of Built-in Audio Analog Stereo" is related to the "Built-in Audio Analog Stereo" that was used on the "Playback" tab ... in essence we are linking to the monitoring of output via the internal speakers/headphones
Link to "Monitor of v1_mic_music"
simply put, with this virtual device we are tying the output from the microphone and the output from the application together into 1 stream
Ignore this ... not related
Although not properly indicated within pavucontrol, WEBRTC is actually the input/recording side of Discord, and therefore we tie this to the same link as used in 2 above "xxxx (echo cancelled with Built-in Audio Analog Stereo)"
Teamspeak is the same as Discord, and must be linked to "xxxx (echo cancelled with Built-in Audio Analog Stereo)"
This last item is me recording the audio session and it's tied to "Monitor of v1_mic_music"
in this case we are feeding the recording inputs into Audactiy so that both my voice and the Discord/Teamspeak/Application are being recorded.

If recording video you'd find anotherentry in the "Recording" tab and you'd need to make sure that the video recording application (similar to audacity) is recording from"Monitor of v1_mic_music"