At home, my setup consists of three machines -Â a laptop, a PC, and an XBOX 360. The latter two share a set of speakers, but I hate having to climb under the desk to switch the cables around, and wanted a better way to switch them back and forth. My good friend Tyler B suggested that I run the line out from the XBOX into the line-in on my sound card, and just let my computer handle the audio in the same way that it handles music and movies. In theory, this works great. In practice, I had one hell of a time figuring out how to force the GNOME sound manager applet into doing my bidding.
After quite a bit of googling, I found the answer on the Ubuntu forums. It turns out that the secret lies in a pulse audio module that isn’t enabled by default. Open up a terminal and use the following commands to permanently enable this behaviour. As always, make sure that you understand what’s up before running random commands that you find on the internet as root:
pactl load-module module-loopback sudo sh -c ' echo "load-module module-loopback" >> /etc/pulse/default.pa '
The first line instructs PulseAudio (one of the many ways that your system talks with the underlying sound hardware) to load a module called loopback, which unsurprisingly, loops incoming audio back through your outputs. This means that you can hear everything that comes into your line-in port in real time. Note that this behaviour does not extend to your microphone input by design. The second line simply tells PulseAudio to load this module whenever the system starts.
Now if you’ll excuse me, I have jerks to run over in GTA…
That was exactly the thing i was missing.
Works like a charm.
@komposita – Glad to hear that I could help you out.
Hi, I also tried this and it worked and I was really excited. Only problem is : the lags behind by about 1 sec, which kinda beats the point of playing video games through line-in :S
Does anybody know how to tweak pulseaudio to get less (or no) lag ?
@Cedric, unfortunately, I’m not sure. From what I can tell, the PulseAudio control panels usually aren’t installed by default, so you might have to go looking for them.
This was one of the things that has kept my last Windows machine from being formatted. Now to find a way to play those Popcap games under Linux
Great article, my only question is how do you unload the module? It’s VERY loud and i had to jab a cord in the headset part so it would shut up. Unfortunately it didn’t work on my laptop, presumably because there is a microphone already setup on it.
I found a way to fix it. Basically make a script that starts on startup (no need to add the above loopback module). In the script but the line:
pacat -r –latency-msec=1 -d alsa_input.pci-0000_05_02.0.analog-stereo | pacat -p –latency-msec=1 -d alsa_output.pci-0000_05_02.0.analog-surround-51
where alsa_input.pci-0000_05_02.0.analog-stereo is your input device and alsa_output.pci-0000_05_02.0.analog-surround-51 is your output device as listed in the program paman. Best of luck.
Thank you! I wish I could have found this earlier.
While the loopback module may work for video games, is there any way to cut down on the delay?
I’m recording through some m-audio software, and I can’t monitor through my system which is a total bummer.
Please help. Many thanks!
Hey Tom, Tyler posted a piece about this awhile ago http://thelinuxexperiment.com/guinea-pigs/tyler-b/fix-pulseaudio-loopback-delay/
However, I’ve heard that if you’re trying to record on Linux, your best bet is to move to an audio application that supports JACK. It’s supposed to be faster and provide lower-latency recording than something like PulseAudio.
To be honest though, I record a weekly podcast (http://www.slightlysauced.com) and I record it on Windows, because recording audio on Linux is a pain in the ass.
Best of luck,
It didn’t work for me and shut down my audio. Thanks to a Uberuser I know I was able to roll back the changes doing this:
The website said to do the following:
pactl load-module module-loopback
sudo sh -c ‘ echo “load-module module-loopback”>> /etc/pulse/default.pa ‘
The first line only affects your current session. It should have no effect after you restart your system. The second line appends the text “load-module module-loopback” to the end of the file /etc/pulse/default.pa. To remove that line from that file use this command in terminal:
sudo gedit /etc/pulse/default.pa
That just opens the file with gedit with root permissions. You could also just type “sudo gedit” by itself and then open the file from within gedit. That’s a good way of editing any files that require root permissions.
Scroll to the bottom of the file, delete the line that says “load-module module-loopback” (should be the last line) and then save and close the file. Restart your system and things should hopefully be back the way they were.
Lots Of Love
Works like a charm for my tv tuner 🙂
Thank you, also works on Debian Squeeze. 🙂
Why noone ever reads the documentation?
To remove the delay: load-module module-loopback latency_msec=1 (Warning: It may eat your CPU, increase the value if the CPU usage is too high)
What I always wanted to find out is how to activate HARDWARE monitoring that most sound cards support (coupling from mic input to sound output). It used to just work with ALSA, with no weird commands and CPU overhead.
How do you do that with pulse?
Just don’t dare tell me I’m not supposed to want that for whatever reason…
Solved similar issue with your post. Thank you!
Thanks, works like a charm to play records on my turntable.
Yes, yes, yes! Thank you so much for this! This fixed everything, and now I can finally listen while I record! You are AWESOME!
Exactly! I suspect that’s what 99% people arriving here through Googling really wants for their game console, and not some exotic, expensive software re-routing of sound streams.
Pulseaudio is technically great but the GUIs that have been built around it have taken the idiotic, dumbed-down path of hiding the real hardware soundcards beneath it, so you can’t tweak such simple parameters except with old, rudimentary programs like alsamixer.
All you have access to in your GUI mixers nowadays is global pulseaudio level when you should have BOTH pulseaudio and hardware levels and switches.
So here is what you need to do to enable CPU FREE HARDWARE monitoring of line-in, like we used to enjoy since *FRIGGIN 1995* – it is still here buried in alsa but very often muted by default :
– open a console (the program “Konsole” or “Gnome Terminal” for instance)
– type the command “alsamixer”
– select your *physical* sound card instead of Pulseaudio by hitting the F6 key and choosing the correct card
– navigate to the [Line] output level columns with the right/left arrows of keyboard
– unmute this output by hitting “M” so that a figure is displayed at the bottom of the column (eg. [0 0] instead of [MM]) unless it’s already unmuted
– raise the sound level to satisfying level with the up/down arrow keys
– hit escape to exit the program
man pages is our friend 🙂
thanks for pointing us in the right directions
thanks a bunch
Oh my god !!
I looked for this for sooooo long ! You’re the man !
Greetings and many thanks 🙂
I needed something like this for doing digital HAM networks. Previously I could not hear when the transmission ended and talking began. Now I can monitor the signal and talking using my speakers. Thanks!
Thanks a lot. The moment I wrote the first line of commands and pressed enter the sound came out of my speakers.
works like a charm with my Stanton USB vinyl player. now i don’t need to run the command every time i boot up. Thank you
Thanks! it helps a lot !
Greetings from a Manjaro Linux user in 2021! I can’t believe this trick is *still* needed…
Greetings from the future. This was very helpful to me with OpenSUSE Tumbleweed.
Thanks! And I just noticed the corresponding volume/mute controls appearing in the gnome sound panel after the module loads, so I don’t have to unload it when it isn’t wanted. Very nice.
Future people here – 11 years later – this is still being omitted from almost every modern OS!!!
We haven’t learned from history, apparently.