Linux optimize

PulseAudio: An Achilles Heel that needs repair

Jack Wallen takes on PulseAudio and runs head first into an issue that has been around since 2008. With Steam gaining ground, sound is going to become a crucial element for Linux. Can the PulseAudio developers solve this troubling issue?

I don't usually have a case to go off on a Linux or an open source project. But in the case of PulseAudio -- I do. Let me set this stage.

One of my other, many jobs, is recording audio books. For this job I use Audacity -- it's a perfect solution for the task. I use Audacity on Ubuntu 12.10. Since purchasing a new computer (one with an Intel i5 chip), I've had nothing but issues with skipping sound (which caused 'hiccups' in the system and in my recordings). And I have gone through a long list of troubleshooting steps:

  • Replaced motherboard
  • Ran memtest86
  • Replaced hard drive
  • Tested CPU
  • Installed three flavors of Linux (Ubuntu Studio, Linux Mint, Ubuntu 12.10)
  • Installed three different kernels (3.7, 3.8, and low-latency)
  • Tried various multimedia players
  • Tweaked PulseAudio settings
  • Read more about sound than I thought I ever would

Turns out -- the issue has been around for some time and is still a problem. Now, before I lay blame on a single project, I understand it's a challenge. The PulseAudio developers have to deal with multiple hardware, many distributions, desktops, and applications. It would be a daunting task for anyone. But --  and here's where the sympathy leaves the building for me -- prior to PulseAudio, this wasn't an issue (and the developers of Esound, OSS, and Alsa had the same pressures on their shoulders).

I should also say that some of my tweaking had better results (I'll share what I did in a moment); but, in the end, the skipping persists. I have to say this: Get it together PulseAudio! I've scoured countless forums to find posts dating back to 2008, posts complaining of the same problem. Countless bugs have been filed, but the pleas for help seem to fall on deaf ears.

Understandably, this issue is more of a show stopper for me. I happen to depend upon sound for income -- and the more I have to re-record sections of a book, the longer it takes me to complete a project. Or, even worse, I miss one of the skips and the book goes to finalization with a flaw -- not good (of course I listen very closely, so I rarely miss them). But this problem has got to be addressed.

Here's the problem: When PulseAudio works well, it's a dream. But when it starts causing problems, it's a nightmare. Removing PulseAudio isn't the solution -- as too many distributions are now in deep with this sound system. Ultimately, the solution is for the skipping audio to be fully, and completely, addressed.

My optimizations

I've managed to get my skipping down to a bare minimum. I've tried quite a lot of tweaks and changes, but ultimately, what has worked the best for me, is the following:

  • kernel 3.8.1 - generic
  • using Audacious to listen to sound (making sure to choose PulseAudio for the output settings)

The following tweaks need to be made in the /etc/pulse/daemon.conf file:

Uncomment the following lines:

  • realtime-scheduling = yes
  • realtime-priority = 5
Uncomment the following lines:
  • default-sample-format = s16le
  • default-sample-rate = 44100
  • default-sample-channels = 2
Set the following*:
  • default-fragment-size-msec = 125
  • default-fragments = 2
* The above numbers were derived from the following steps (done from a terminal window):

  1. echo autospawn = no >> ~/.pulse/client.conf
  2. killall pulseaudio
  3. LANG=C pulseaudio -vvvv > ~/pulseverbose.log 2>&1
Hit Ctrl-c to return to your prompt. Now run the following commands:
  • rm ~/.pulse/client.conf
  • grep device.buffering -m2 ~/pulseverbose.log
The second command should present to you something like:
: sink.c:     device.buffering.buffer_size = "352800" : sink.c:     device.buffering.fragment_size = "176400"
The calculations for the settings are:
  • 352800/1411200 = 0,25s = 250 msecs
  • 176400/1411200 = 0,125s = 125 msecs

Once you've added those settings to /etc/pulse/daemon.conf, restart PulseAudio with the command pulseaudio -k. You should now enjoy less (but not zero) skipping.

This PulseAudio issue has had me climbing the walls over the last couple of months. I sincerely hope someone will take note and push for a concerted effort to resolve a problem that has plagued the system for nearly half a decade. And should the developers not be capable of solving this issue, I would ask the major distributions (those that depend upon PA) to find an alternative! This problem is going to only become worse as more and more people start playing games on Steam. How shameful would that be if Linux begins to start gaining serious momentum on the desktop, only to have it shot down because of a faulty sound server?

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

21 comments
theAntiBob
theAntiBob

WHAT'S WRONG WITH THIS SOLUTION FROM THE ARCHLINUX WIKI https://wiki.archlinux.org/index.php/PulseAudio#Glitches.2C_skips_or_crackling

changing the fragments and fragment size of the buffer in daemon.conf won't do anything without timer-based scheduling being disabled in default.pa by adding tsched=0 to the end of the line load-module module-udev-detect


what's more, the device.buffering strings in the verbose info from pulseaudio (-vvvv) are merely stating what the buffer fragments and size have been set to


what's even more, the grep argument -m2 allows only 2 instances of the filter string "device.buffering" to be annunciated which usually means you're looking at buffer the information for your microphone

grep -C 5 should give you enough info to see what device the buffer info is for...


what's even morer is that default-fragments and default-fragment-size-msec are changed to the nearest usable settings depending on what the audio device will accept, which varies from device to device


SUMMARY:

don't just ask the first pulseaudio device that comes along what it's buffer info is and then try to make that your default buffer setting

83mike
83mike

You're right, Pulseaudio is absolute garbage. It consumes a ton of resources (on my old laptop) to do nothing useful with a half decent onboard sound device. For years, ALSA has already done the mixing that is supposed to be Pulse's special thing. And while Pulse eats processor time to do mixing, ALSA does it on the soundcard. The shockingly low quality of Pulseaudio reminds me of another extremely trashy piece of FOSS, Mono. Such crap projects should never have been incorporated into major distributions. Such terrible bits of BROKEN, USELESS and completely unnecessary software just make whole distributions look bad.

Nathan.
Nathan.

But those other sound systems all had their teething issues. I think last time I looked at Ubuntu, pulse was running on top of ALSA. I've also heard of issues with onboard sound & onboard with additional sound cards causing issues and recommendations of disabling the onboard if you were going to mainly use the card. I think for now you have to play around, try pulse for both frontend/daemon, pulse+ALSA and ALSA only till they get around to fixing the the some of the issues people are having.

dford
dford

I seem to remember seeing a comment, by someone who was working on pulse, that it was not designed to be used for any form of 'serious' recordings - a few years ago, admittedly. On Fedora, using the Planet Karma (CCRMA) 'extras', jackd will stop pulse when it starts and start it again when it stops - this works well for me. Audacity is easier to use than Ardour but it doesn't integrate well with Jackd I'm not an *buntu fan personablly.

techracer7
techracer7

Hi, I've no idea how they've coded it, but it sounds like a time stamp counter issue to me. I read an article recently about how this once reliable tool tool making applications perform smoothly has become far less so with current multi-core desktop CPUs particularly those that change their clock speed all the time. If you are recording for professional reasons, I'm surprised you haven't mentioned some high end sound card being used. Yes there is decent built in sound in mother boards today but I still find a big improvement in background hiss and interference with even mid-range PCI or PCIe expansion cards.

laseray
laseray

As another commenter stated, always use Jack/ALSA for pro-recording. Never rely on PulseAudio(PA) as the solution alone. If it works fine, else turn it off first, then record. Those of us using Linux to record/playback full duplex know you should always go to Jack first. I have had problems with PA on one distro, and then no problems on another. In each case you must always go to Jack anyway for professional use. And that won't necessarily require you to change distros, kernels, etc.

stuart_lesnett@lesnett.
stuart_lesnett@lesnett.

I have encountered nothing but problems video and audio with Ubuntu 10.04 and 12.04. None of the plugins seem to fix the problems and Chromium doesn't help. I've JAVA comments and different plugins but nothing is working. I have the same type of problems with NETFLIX even using the modified Ehoover version of Firefox.

m@rcel
m@rcel

I've had a lot of trouble with pulseAudio too. I went through a lot of try and error until I found out that it's possible to make a dump of the part of the puls audio register (i believe it's called different) and post it on their forum. (I don't know the technical details anymore, but it can be googled). But it seems to have worked , because with the next release of, in this case Linux Mint, it was solved.

sandi_ro
sandi_ro

Also you may try av linux . And just for the sake of completeness please give your hw details and specify if you used a 32 or 64 bit kernel. Guys from ubuntu are friendly and shall be more than interested in solving the problem if they have all details .

Aussie_linux_user
Aussie_linux_user

Jack, I have been using linux for semi pro recording for about a decade and do not get skipping problems.. here is some advice; 1. Get rid of Pulse Audio, it's rubbish ... for general use ALSA with all the plugins installed is fine. It doesn't need an abstraction layer, for general purpose providing the dmix plugin is installed. 2. For recording use jackd (qjackctl is a decent app to control it) - spend an hour learning it and you can get your system tight - if your audio chipset on motherboard is rubbish (as they usually are for recording purposes) you can loosen the latency and reduce audio skips. Although I disagree with a previous posters comments, most IntelHD audio compliant devices run rock solidly these days.... 3. Invest in a half decent USB microphone if you haven't already - standards compliant USB audio devices work very well with ALSA.. I've played with using pulse audio on my mythtv boxes (recycled hardware) and laptop even in recent times, it just doesn't work right. I always go back to vanilla ALSA.. I even keep a spare Behringer UCA 202 in case I have issues with the audio on the mythtv boxes...

frylock
frylock

I've never had the patience to get it working.

janitorman
janitorman

But pulseaudio bothered me. I have Alsamixer installed on Xubuntu, works fine for me. Deal-breaker was, several releases ago someone decided (yes this is petty) to remove the sensible volume icon on the taskbar with some ridiculous thing, and I wanted the old-style one back, and had to jump through hoops to even find out how! Turns out the traditional one was very hard to get when the new indicator applet was released, big mistake. All fixed now though. As to sound card problems, I don't worry much, I don't have a mic and rarely turn my speakers on, unless I go to you-tube (rarely.)

ddalley
ddalley

Just try using Brasero. I haven't had it write a good disc for me in years, over different distributions and a few different computers. And I am not the only one who has had this problem, either. I can't even use it to write a Live DVD to disc, to use it.

allanmount
allanmount

Did you go back to the system which worked for you?

maureyed
maureyed

I simply use Synaptic to rid my computers of pulseaudio and compiz-core. It always feels sooo good when I click that "Apply" button! For my purposes Alsa and VLC cover the bases flawlessly. BTW, if you use Lubuntu, as I do, your computer is automatically in a "Pulse-Free-Zone."

jmmcn
jmmcn

Perhaps a bit old school, (GNU/Linux user since '94) but must comment that I'm always a bit taken back when I read 'fix this now' articles in the Linux/FOSS space. Don't misunderstand, I agree that these types of articles should be expressed, especially by FOSS writers that have a platform to do so. Still, like when Eric Raymond vented/ranted about printing some years ago, there is no 'company' behind PulseAudio (it's organized under freedesktop.org), so to whom exactly are these complaints directed (rhetorical)? It's no accident that audio has languished as, surprise, like video (let's not get into NVidia/Intel/AMD, etc., right?), it is not trivial against so many platform and chipsets (no to mention all the usb and firewire sound interfaces (chipsets) out there). My feeling after many years and FOSS conferences is there is basically a very small ('small' being subjective, I'll agree) pool of individuals who are deep enough to code audio easily from hardware (kernel/alsa) all the way 'up' to the desktop, and my guess is they're likely gainfully employed in the non-FOSS world at some level and probably don't 'do' audio fulltime, imho. At this stage, for mainstream Linux distros everything 'desktop audio' related sits on top of ALSA and I've had the best luck troubleshooting audio (assuming hardware is all OK) when I start with ALSA (kernel upwards, not sound server downwards). I do home audio recording and mixing (Ardour, etc.) so I tend to live in the 'Jack' world, but once I make sure ALSA is set up correctly with a proper .asoundrc and I'm certain the lower audio layer is stable and efficient, I then have no issues with Jack (sound server). I use and love Funtoo, and run i3 as my WM, so I do understand I'm not a typically Linux user. Still, from years past, most audio issues I've had I've resolved by getting the kernel and ALSA 'correct' first. Jack, might be a good 'investigation' article/series to do some articles on 'Who Works on Linux Audio?' or some such. Not sure if Corbet over at LWN has ever done a series on it - a quick search did bring up some Audio articles, but not much focused on the 'who'. I think interviewing the folks who are down in the trenches fighting this audio stuff (like the folks over at ffado?) would be interesting and hearing their thoughts on current status, developments, directions and what needs to be done might get some more people involved. Just a thought.

alijawad1
alijawad1

What is great about Linux Get a live distro - test your hardware all works sound included. Install the live distro - system goes to sleep and wakes up - no sound - - reboot system and it loads with low sound -FN keys + sound display the correct stuff on screen but it does not work -Some apps recognize your sound some dont. The problems above are amongst others I had to deal with , I am an open source enthusiast, but installing in 20 mins and spending 20 hours fixing sound is too much

cherax
cherax

If you're just recording audio, why not use a dedicated voice recorder? For $100 you can get superb audio quality (even better if you connect a good microphone), and a digital audio file that you can edit on your computer.

zefficace
zefficace

Two people use the same software, one has problems while the other wondwers what the hell the first guy is Talking about. I don't record regularly, but when I do, I never had skipping or other problems with pulseaudio, or with audacity for that matter. This variety in experience happens all the time, but more often in free/open source software for some reason. It's really a shame. This is the very phenomena where I say I live with Linux (Arch64) daily without much of a hitch and then a friend tries Ubuntu or some other distro, has major problem, and thinks I lied. Never do they realize that different distros have different behavior and quality. Finding the right distro, that works well with you and your equipment is not a simple task. Why Linux can't unify the quality of behavior across distros is beyond me, as they all have the same building blocks. It also has been my experience that the more the distro is noob friendly, the more it's problems get bizarre and unsolvable. Probably all that fooling around to make the system config itself without the user... Still, Jack (can I call you Jack?), when you wrote "Installed three flavors of Linux (Ubuntu Studio, Linux Mint, Ubuntu 12.10)", did you realise you really installed three version of UBUNTU? Frankly, I feel sticking with the Ubuntu family and expecting different results is... unrealistic. The have the same core, why would they have been so different in behavior? Three actual "other flavors" would involve Opensuse, Fedora, and maybe you could give Arch a try. I have Arch on a total of 4 systems, and I have nothing to complain about, not even pulseaudio. Oh, and under Arch, you could live without pulseaudio if you chose to... At least, drop the Ubuntu based stuff if you want to try other flavors of Linux.