PulseAudio - Tune your setting and prevent glitching

Write tutorials and howtos in 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: 4557
Joined: Sun Jan 11, 2009 9:54 am
Location: Right about here


Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 6 guests