Home > Hardware, Linux, Tyler B > Fix PulseAudio loopback delay

Fix PulseAudio loopback delay

Sort of a follow up (in spirit) to two of Jon’s previous posts regarding pulse audio loopback; I noticed that there was quite a bit of delay (~500ms to 1second) in the default configuration and began searching for a way to fix it. After some research I found an alternative way to achieve the loopback but with must less delay.

1. Install paman

First install the PulseAudio Manager application so that you can correctly identify the input device (i.e. your mic or line-in) and your output device (i.e. the sound card you are using).

sudo apt-get install paman

You can find the input sources under the Sources section and the output devices under the Sinks section of the Devices tab. Make note of the names of the two devices.

2. Unload any previous loopback modules

If you had followed Jon’s previous posts then you will need to unload the modules (and potentially change your PulseAudio configuration so they don’t get loaded again on next restart). This is to stop it from doubling all loopback sound.

3. Create an executable script

Create a script and copy the following command into it:

pacat -r --latency-msec=1 -d [input] | pacat -p --latency-msec=1 -d [output]

where [input] is the name of your input device found in step 1 and [output] is the name of the output device. In my case it would look like:

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

4. Run script

By simply running the script now you should get correct loopback and with much less delay than using the default loopback module. Even better if you set this script to run at startup you won’t have to worry about it ever again.




I am currently running a variety of distributions, primarily Linux Mint 17.
Previously I was running KDE 4.3.3 on top of Fedora 11 (for the first experiment) and KDE 4.6.5 on top of Gentoo (for the second experiment).
Check out my profile for more information.
  1. Diego
    July 5th, 2011 at 16:12 | #1

    Thank you very much. I was searching a solution for this problem some time ago. Works really fine.

  2. Tony
    July 26th, 2011 at 10:13 | #2

    This worked perfectly to eliminate the .25-.5 second audio sync delay when playing video.

  3. C Anthony
    March 6th, 2012 at 00:21 | #3

    # cat .pulse/default.pa
    .include /etc/pulse/default.pa
    load-module module-loopback latency_msec=80

    … doesn’t anyone consult the manual these days? ;-)

    no need for root; this method is likely to pound on your machine HARD … esp at 1msec … most humans will not detect lag until it approaches or exceeds 100msec.

  4. April 7th, 2012 at 00:21 | #4

    I also use pacat in the way described on this page with tvtime, but I’ve found that there are still cases where latency is introduced if the play pacat instance gets behind. Once it gets behind it stays behind. To address this problem I’ve made a modification to pacat. The details are on my site:
    http://selliott.org/node/59

    C Anthony,
    I find that module-loopback still occasionally has unreasonable latency even if a low latency_msec is specified.

  5. May 23rd, 2012 at 09:34 | #5

    I’ve refined my patch a bit and added another one. I’ve mentioned my patches on the pulseaudio mailing list:
    http://lists.freedesktop.org/archives/pulseaudio-discuss/2012-May/013588.html
    But the consensus sees to be that the problem should be fixed in tvtime. I can’t say I blame them, but anyone who is still experiencing latency with the pacat solution mentioned in this post are welcome to try my patches. They are named “pacat-drain-experimental.diff” and “pulseaudio-limited-watermark-experimental.diff”. You can read more about them here:
    http://selliott.org/node/59
    I’m happy to receive feedback.

  6. ivan
    June 13th, 2012 at 23:36 | #6

    hell yeah, dude

  7. Matteo
    July 21st, 2012 at 04:06 | #7

    Alright, how do I unload the modules and change the config so that they don’t get loaded again on restart?

  8. Matteo
    August 2nd, 2012 at 18:03 | #8

    Also, what do you mean by “create an executable script”?

  9. Tyler B
    August 28th, 2012 at 21:59 | #9

    Matteo :

    Also, what do you mean by “create an executable script”?

    You can create an executable script by making a new text file and placing this as the first line:

    #!/bin/sh
    (terminal commands go here)

    Then mark the file as executable by issuing the command
    chmod +x myscript

    Now you can run it like a normal program
    ./myscript

  10. venge
    April 17th, 2013 at 05:06 | #10

    This can rape your machine as C Anthony said. If you simply want line in playback, you should just install alsa-utils, type alsamixer -c 0 (or 1 test to find your sound card), and look for the input playback selector, (the only one without a volume slider) to choose your input device. Also don’t forget to raise the line in’s playback volume.

  11. November 18th, 2013 at 12:46 | #11

    I am using loopback modules and null-sinks to combine my game audio and my webcam microphone audio into 1 virtual stream which is then sent to twitch.tv suing ffmpeg. I am having a horrible delay from the audio/video of the game and when I say something. Example: i shoot my gun and at the same time i say into my microphone “bang”, there’s about 25 seconds from the time the video shows me shooting my gun and when you hear my voice say “bang”. How would I fix this, do you have any idea. If i set a latency-msec on the game audio loopback, wont it become out of sync with the game video then? Any ideas

  12. February 12th, 2014 at 18:17 | #12

    Thanks! I’ve now fixed my 30s delay from my bluetooth android to my ubuntu desktop.

  1. No trackbacks yet.