Home > God Damnit Linux, Hardware, Jon F, Linux > PulseAudio: Monitoring your Line-In Interface

PulseAudio: Monitoring your Line-In Interface

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…




On my Laptop, I am running Fedora 13.
On my PC, I am running Ubuntu 10.04
Check out my profile for more information.
  1. komposita
    October 2nd, 2010 at 18:08 | #1

    Thx.

    That was exactly the thing i was missing.

    Works like a charm.

  2. Jon F
    October 5th, 2010 at 21:07 | #2

    @komposita – Glad to hear that I could help you out.

  3. Cedric
    October 7th, 2010 at 06:41 | #3

    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 ?

  4. Jon F
    October 9th, 2010 at 14:15 | #4

    @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.

  5. December 28th, 2010 at 18:34 | #5

    Thank you!
    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

  6. anon
    January 25th, 2011 at 00:33 | #6

    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.

  7. Tyler B
    June 30th, 2011 at 23:36 | #7

    Cedric :

    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 ?

    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.

  8. Greg
    August 2nd, 2011 at 22:36 | #8

    Thank you! I wish I could have found this earlier.

  9. September 7th, 2011 at 19:22 | #9

    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!

  10. Jon F
    September 8th, 2011 at 21:42 | #10

    @Tom

    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,

    Jon

  11. Colin
    October 30th, 2011 at 00:03 | #11

    @anon
    Hello
    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.

    Good luck.

    Rob

  12. November 21st, 2011 at 15:16 | #12

    Lots Of Love
    Works like a charm for my tv tuner :)

  13. Joghurt
    December 24th, 2011 at 16:14 | #13

    Thank you, also works on Debian Squeeze. :)

  14. Nitsuga
    January 15th, 2012 at 11:08 | #14

    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)

  15. Michal
    March 5th, 2012 at 07:10 | #15

    @Nitsuga
    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…

  16. qux
    April 29th, 2012 at 03:50 | #16

    Solved similar issue with your post. Thank you!

  17. kevin
    May 17th, 2012 at 23:06 | #17

    Thanks, works like a charm to play records on my turntable.

  1. July 12th, 2010 at 03:40 | #1
  2. August 26th, 2010 at 21:36 | #2
  3. November 11th, 2010 at 07:17 | #3
  4. July 1st, 2011 at 14:09 | #4
  5. July 26th, 2011 at 21:02 | #5
  6. November 13th, 2011 at 18:58 | #6