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…



29 Comments

  1. 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 ?

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

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

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

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

  6. 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!

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

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

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

  10. Yes, yes, yes! Thank you so much for this! This fixed everything, and now I can finally listen while I record! You are AWESOME!

  11. @Michal

    Michal :
    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.

    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

    HIH,
    Spart

  12. Oh my god !!

    I looked for this for sooooo long ! You’re the man !

    Greetings and many thanks 🙂

  13. 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!

  14. Thanks a lot. The moment I wrote the first line of commands and pressed enter the sound came out of my speakers.

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

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

  17. Future people here – 11 years later – this is still being omitted from almost every modern OS!!!

    We haven’t learned from history, apparently.

8 Trackbacks / Pingbacks

  1. PulseAudio: Monitoring your Line-In Interface | The Linux Experiment | Linux Affinity
  2. Unwanted Effects on my Line-in Interface | The Linux Experiment
  3. Captura de vídeo no linux ;) – (Dica) « Fred Chevitarese …
  4. Fix PulseAudio loopback delay | The Linux Experiment
  5. How to monitor your microphone through headphones in Ubuntu » Mike Beach
  6. How to monitor your microphone through headphones in Ubuntu « Mike Beach
  7. Web browsers, music players, workarounds, and PulseAudio – The Cat Fox Life
  8. Listen to your own microphone in pulseaudio | Knowledge Base

Leave a Reply

Your email address will not be published.


*