39

I work on two computers with one USB headset. I want to listen to both by piping the non-Linux computers' output into the Linux computer's line in (blue audio jack) and mixing the signal into the Linux computer's headset output using PulseAudio.

Audio hardware diagram

pavucontrol shows a "Built-in Audio Analog Stereo" Input Device which allows me to pick ports like "Line In" (selected), "Front Microphone", "Rear Microphone". I can see the device's volume meter reacting to audio playback on the non-Linux machine.

Built-in Audio Analog Stereo

How do I make PulseAudio play that audio signal into my choice of Output Device?

3 Answers 3

52

1. Load the loopback module

pacmd load-module module-loopback latency_msec=5

creates a playback and a recording device.

2. Configure the devices in pavucontrol

In pavucontrol, in the Recording tab, set the "Loopback" device's from input device to the device which receives the line in signal.

recording settings

In the Playback tab, set the "Loopback" device's on output device to the device through which you want to hear the line in signal.

playback settings

3. Troubleshooting

If the audio signal has issues, remove the module with pacmd unload-module module-loopback and retry a higher latency_msec= value

Additional Notes

Your modern Mid-Range computer might easily be able to manage lower latency with the latency_msec=1 option:

pacmd load-module module-loopback latency_msec=1

This answer was made possible by this forum post. Thanks!

7
  • 1
    I do not see that loopback text in pavucontrol, but it works anyway. I can unmute the input device and adjust the input level in Input Devices tab. Maybe it is due to newer version of software, Ubuntu 20.04 here. See also the module documentation.
    – jarno
    Nov 11, 2020 at 19:25
  • I had to add source setting in the load-module command to make it work more reliably.
    – jarno
    Nov 11, 2020 at 20:53
  • @jarno Thanks for that info. I do not see any "loopback" text inside the Playback tab of pavcontrol, but I do see it inside the Recording tab. Also, when I first ran the pacmd load-module module-loopback latency_msec=5, it emitted a loud noise through the speakers that were currently playing. I had to quickly execute pacmd unload-module module-loopback to turn it off...
    – bgoodr
    Nov 29, 2020 at 6:14
  • ... then reduce the speaker volume (via a physical volume control dial on the side of the speakers), then try loading the module again. Again the noise continued, but then I discovered only when I switched to the Recording tab, and switched "Loopback to Builtin Audio Analog Stereo from" from "Monitor of Built-in Audio Analog Stereo" to just "Built-in Audio Analog Stereo", it started to play normally without the noise. This is running under Xubuntu 20.04.1 LTS.
    – bgoodr
    Nov 29, 2020 at 6:16
  • 1
    BTW It is good to unload the module, when you do not use it, because it uses CPU for nothing otherwise.
    – jarno
    Nov 29, 2020 at 9:43
0

As stated in the preferred answer

pacmd load-module module-loopback latency_msec=5

Which should create a playback and recording device, doesn't seem to work in all cases. In that case, you can attempt

pactl load-module module-loopback latency_msec=5

Notice the similar arguments, using pactl

For me it didn't work with pacmd, did with pactl.

Note: Both these options are only for Pulse Audio and not for Pipewire

1
  • Please edit this so it makes sense even if the other answer is deleted.   Reference the other answer (by stating the name of the author), but copy all essential information into your answer. Dec 1, 2018 at 18:50
0

I've got a very similar situation here! 2 PCs, one Linux machine (my primary) plus one Windows machine. I set something nice up to automate TWO-WAY audio connection, using my headset with the Linux machine and Pulseaudio, I'm both hearing the Windows machine, AND am able to talk into the mic, through Linux, back into the Windows machine mic in.

Obviously, this is going to require not 1, but 2 AUX cables to be hooked between the machines. But works like a charm ever since I figured it out once. To make it easy on anyone interested in doing the same, I'll share my script here. All you should need to do to get it to work, is find two specific audio sink names for your machine and put them inside the script's variables for them, if they're different from mine.

#!/usr/bin/env bash

# 2-way audio connection - Slaves 2nd device audio through this device:
# - Directs AUX in to default speakers (connect 2nd device -> AUX).
# - Directs Mic to AUX out (connect AUX out -> 2nd device AUX in).
# 
# Then sleeps forever. Stops audio redirection when killed.
# 
# Requires:
# sudo apt-get install pactl
# 
# Manual Process:
# 1) pavucontrol > Configuration > Built-in Audio > Analog Stereo Duplex
# 2) Find - look for "analog-stereo" (no frills) in both commands:
#    pacmd list-sources | grep name:
#    pacmd list-sinks | grep name:
# 3) Select - enter found name or ID in this command:
#    pactl load-module module-loopback source=$auxinsource source_dont_move=1 sink=$defaultsink
# 4) pavucontrol > Input > Built-in Analog Stereo > Line in (plugged in)
# 5) pavucontrol > Playback > Loopback from Built-in Analog Stereo > SELECT_SPEAKERS
# 6) pavucontrol > Output > Built-in Analog Stereo > Line Out (plugged in)
# 7) pavucontrol > Recording > Loopback to Built-in Analog Stereo > SELECT_HEADSET_MIC
#
# BREAKPOINT:
# read -n 1 -s -r -p 'BREAKPOINT'

auxinsource='alsa_input.pci-0000_00_1f.3.analog-stereo'                                                 # Get name of AUX in (Replace these with yours!)
micsink='alsa_output.pci-0000_00_1f.3.analog-stereo'                                                    # Get name of AUX out (Replace these with yours!)

set -e

printf '\n 1) Connect Audio IN (Win->)...'
defaultsink=$(pactl get-default-sink)                                                                   # Get name of currently selected speakers
modulein=$(pactl load-module module-loopback source=$auxinsource source_dont_move=1 sink=$defaultsink)  # Locked from manual selection in GUI, will not jump around
#modulein=$(pactl load-module module-loopback source=$auxinsource sink=$defaultsink)                    # Unlocked for manual selection in GUI, but may jump around
#echo ' ' $defaultsink ' connected!'                                                                    # Debug output
echo ' connected!'


printf '\n 2) Connect Audio OUT (<-Mic)...'
modulemic=$(pactl load-module module-loopback latency_msec=10 source_dont_move=1 sink=$micsink)         # Locked from manual selection in GUI, will not jump around
#modulemic=$(pactl load-module module-loopback latency_msec=10 sink=$micsink)                           # Unlocked for manual selection in GUI, but may jump around
#echo ' ' $micsink ' connected!'                                                                        # Debug output
echo ' connected!'


printf '\n CTRL+C to stop'                                                                              # Flavor text.


function cleanup
{
  pactl unload-module $modulemic
  if [ ! -z ${modulein+x} ]; then
    pactl unload-module $modulein
  else
    echo
  fi
}

trap cleanup EXIT

sleep infinity

And for guided step by step troubleshooting of this setup (optional),

#!/usr/bin/env bash

# Troubleshooting steps for audioconnect
#
# Requires:
# sudo apt-get install pactl
# 
# BREAKPOINT:
# read -n 1 -s -r -p 'BREAKPOINT'


printf ' 1) pavucontrol > Configuration > Built-in Audio > Analog Stereo Duplex'
read -n 1 -s -r -p ''
echo ': OK'
printf ' 2) pavucontrol > Input > Built-in Analog Stereo > Line in (plugged in)'
read -n 1 -s -r -p ''
echo ': OK'
printf ' 3) pavucontrol > Playback > Loopback from Built-in Analog Stereo > SELECT_SPEAKERS'
read -n 1 -s -r -p ''
echo ': OK'
printf ' 4) pavucontrol > Output > Built-in Analog Stereo > Line Out (plugged in)'
read -n 1 -s -r -p ''
echo ': OK'
printf ' 5) pavucontrol > Recording > Loopback to Built-in Analog Stereo > SELECT_MIC'
read -n 1 -s -r -p ''
echo ': OK'
New contributor
John Smith is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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