PulseAudio - Tune your setting and prevent glitching

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

PulseAudio - Tune your setting and prevent glitching

Postby kwevej on Fri Mar 26, 2010 7:48 am

I had some problems with glitches & drop-outs during playback...
Yesterday, I've found the solution*. Here it is:

*In case it looks too complicated, or you still experience glitches at high CPU usage, look for # section down here.

    (1) Find out your audio device parameters

      1st, you'll need PA verbose logging:
      Code: Select all
      echo autospawn = no >> ~/.pulse/client.conf
      killall pulseaudio
      LANG=C pulseaudio -vvvv > ~/pulseverbose.log 2>&1
      (source: https://wiki.ubuntu.com/PulseAudio/Log)
      Run the code above, press Ctrl+C.

      Code: Select all
      rm ~/.pulse/client.conf

      run:
      Code: Select all
      grep device.buffering -m2 ~/pulseverbose.log

      You should see something like:
      Code: Select all
      : sink.c:     device.buffering.buffer_size = "352800"
      : sink.c:     device.buffering.fragment_size = "176400"
      (those are values of my NuForce uDAC)

      Write down the values. Proceed to step (2)
    (2) Calculate your fragment size in msecs and number of fragments

      For my configuration I do use the standard sampling rate and bit depth ( 44,1 kHz @ 16bit )

      That means, that I need 44100*16 = 705600 bits per second. That's 1411200 bps for stereo.
      Let's take a look at the parameters we've found in the previous step:
      device.buffering.buffer_size = "352800" => 352800/1411200 = 0,25s = 250 msecs
      device.buffering.fragment_size = "176400" => 176400/1411200 = 0,125s = 125 msecs

      Now, I got the values in secs, regarding to the sampling rate & bith depth.
      (source: me)
    (3) Modify PA daemon configuration

      The config file is located at /etc/pulse/daemon.conf
      Code: Select all
      sudo gedit /etc/pulse/daemon.conf

      Locate & uncomment (remove leading semicolons) these lines:
      Code: Select all
      ; default-fragments = X
      ; default-fragment-size-msec = Y

      What are those parameters for?
      Some hardware drivers require the hardware playback buffer to be subdivided into several fragments.
      default-fragments= The default number of fragments. Defaults to 4.
      default-fragment-size-msec=The duration of a single fragment. Defaults to 25ms (i.e. the total buffer is thus 100ms long).
      (see man of pulse-daemon.conf)

      Let's fill them in.
      In the part (2), We've calculated the fragment size parameter.
      Number of fragments is simply buffer_size/fragment_size. That's, in my case, 2.
      Code: Select all
      default-fragment-size-msec = 125
      default-fragments = 2

      While you're doing that, you should set also those:
      Code: Select all
      default-sample-format = s16le
      default-sample-rate = 44100
      default-sample-channels = 2

    (4) Restart PA daemon

      Code: Select all
      pulseaudio -k
      pulseaudio --start

    (5) Test
      Listen your favorite music & hit your PC with some load. I find Fink, to be fine test music ;)

    (6) Still not satisfied? Let's tune the PA priority & scheduling

      in the PA conf, you can find params like:
      Code: Select all
      ; high-priority = yes
      ; nice-level = -20
      ; realtime-scheduling = yes
      ; realtime-priority = 1

      That's what we need, but there is a bug (https://bugs.launchpad.net/ubuntu/+sour ... bug/265010) which prevents us to use them in the standard way.

      At the link above, you can find a solution written by Oliver Joos:

      PA daemon can gain high-priority and realtime scheduling by editing "/etc/security/limits.conf". For each desktop user add the following 2 lines:
      Code: Select all
      <$USER> - nice -11 # values from -20 upto 19 allowed
      <$USER> - rtprio 9 # values from 1 upto 99 allowed
      Substitute <$USER> with your login name.

      Each user who wants high-priority and/or realtime scheduling may put config into his ~/.pulse
      Code: Select all
      #~/.pulse/daemon.conf
      high-priority = yes         # default no
      rlimit-nice = 31            # default 31, values higher than 31 are interpreted as 31!
      nice-level = -11            # default -11, lowest value allowed: (20 - rlimit-nice), lower means more CPU-%

      realtime-scheduling = yes   # default no
      rlimit-rtprio = 9           # default 9, values from -20 upto 19 allowed
      realtime-priority = 9       # default 5, highest value allowed: rlimit-rtprio, higher means more priority

      ; log-level = info          # uncomment only to check if it works. this will spam syslog a lot!
      (Download at http://launchpadlibrarian.net/36662952/daemon.conf)
    (7) Reboot
    (8) Pleasure your ears with some fine tunes from NinjaTunes

# Glitches @ high CPU usage (http://wiki.archlinux.org/index.php/PulseAudio)

Since 0.9.14, the PulseAudio sound server has been rewritten to use timer-based audio scheduling instead of the traditional interrupt-driven approach. Timer-based scheduling may expose issues in some Alsa drivers. To turn timer-based scheduling off, replace the line:
Code: Select all
load-module module-udev-detect

in /etc/pulse/default.pa by:
Code: Select all
load-module module-udev-detect tsched=0


kwevej
Last edited by kwevej on Sun Sep 19, 2010 4:34 am, edited 2 times in total.
User avatar
kwevej
Level 5
Level 5
 
Posts: 624
Joined: Mon Mar 22, 2010 3:35 pm
Location: Delft / Prague [@ LMDE]

Linux Mint is funded by ads and donations.
 

Re: PulseAudio - Tune your setting and prevent glitching

Postby Aging Technogeek on Fri Mar 26, 2010 8:00 am

kwevej,
Very useful How-to considering the number of users posting with audio problems.

Nice job.
Image

Registered Linux User 483387
User avatar
Aging Technogeek
Level 13
Level 13
 
Posts: 4605
Joined: Sun Jan 11, 2009 9:54 am
Location: Right about here

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Sat Feb 08, 2014 11:28 am

I use this configuration, thanks.

It made the situation much better. In case of glitches, I restarted Mint.

Edit : one month later I can say there is no more glitches

Unfortunately on march 25 2014 glitches are again here. I checked the config which did not change.
Last edited by robert leleu on Thu Jul 03, 2014 5:45 am, edited 4 times in total.
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby theAntiBob on Mon Mar 10, 2014 9:45 pm

What's wrong with this solution for pulseaudio crackling?
found on these common pages:
viewtopic.php?f=42&t=44862
https://wiki.archlinux.org/index.php/Pu ... _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 info your default buffer setting
theAntiBob
Level 1
Level 1
 
Posts: 1
Joined: Mon Mar 10, 2014 9:40 pm

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Sat Mar 29, 2014 12:25 pm

I just tried to fix these glitches (which came back on March 25, perhaps after an update) following informations in the above post, and the links it gives. No success.
I checked that the bug occurs also, on the same machine, with a Mint16 or Lubuntu 12.10 live CD. BTW Lubuntu runs smoothly on another machine.

I'm now considering trying other OS (non ubuntu ones) which could be free of the bug. If anyone knows such an OS (save Windows), thanks !

Hurrah ! I found https://help.ubuntu.com/community/Sound ... gProcedure and applied, see https://answers.launchpad.net/ubuntu/+s ... ion/246272

The sound is back, no glitches.

/etc/pulse/daemon.conf shows the values calculated according to the first post of this thread.
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Mon Apr 21, 2014 9:45 am

But the sound disappeared around the 13th of april.

I recover it on the 21st morning by installing the trusty pavucontrol debian package on my Mint16 MATE=saucy

Then I uninstall/reinstall project-neon (a daily upgrading of KDE unstable master)....the sound had disappeared...from my MATE session, which doesn't use the project-neon packages.
I (only) uninstalled this project-neon, and the sound was back......
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Mon May 19, 2014 12:18 pm

One week ago glitches came back. Perhaps with an update, sinc I update very often to follow project neon which is now my standard session. Came back only in project neon MATE sound is OK !
I go on alternating MATE and NEON sessions.....
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Tue May 20, 2014 5:56 am

... and now play smoothly in both sessions, MATE and NEON
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby robert leleu on Thu Jul 03, 2014 5:46 am

Theycame back on july 2d, all the day session long. They were there at the beginning of the july 3d session, but just for half an hour, and disappeared.
…… and returned around 2 pm, while the computer was inactive.....

I searched for pulse in the logs, but saw nothing which seemed relevant
robert leleu
Level 1
Level 1
 
Posts: 33
Joined: Fri Apr 26, 2013 11:55 am

Re: PulseAudio - Tune your setting and prevent glitching

Postby xenopeek on Tue Aug 12, 2014 2:28 am

This tutorial is more than 4 years old. Don't post support questions here; post a new topic in one of the support forums instead. And while PulseAudio in its first few releases was problematic, don't assume any audio problems you have are caused by PulseAudio these days--it's been stable and problem free for many years now. If you have audio problems, approach it with an open mind as to what may be the cause.

Locked.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14996
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Linux Mint is funded by ads and donations.
 

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 14 guests