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
- Code: Select all
echo autospawn = no >> ~/.pulse/client.conf
killall pulseaudio
LANG=C pulseaudio -vvvv > ~/pulseverbose.log 2>&1- Code: Select all
rm ~/.pulse/client.conf- Code: Select all
grep device.buffering -m2 ~/pulseverbose.log- Code: Select all
: sink.c: device.buffering.buffer_size = "352800"
: sink.c: device.buffering.fragment_size = "176400"
- 1st, you'll need PA verbose logging:
Run the code above, press Ctrl+C.
- run:
You should see something like:
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
- Code: Select all
sudo gedit /etc/pulse/daemon.conf- Code: Select all
; default-fragments = X
; default-fragment-size-msec = Y- Code: Select all
default-fragment-size-msec = 125
default-fragments = 2- Code: Select all
default-sample-format = s16le
default-sample-rate = 44100
default-sample-channels = 2
- The config file is located at /etc/pulse/daemon.conf
- Locate & uncomment (remove leading semicolons) these lines:
- 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.
While you're doing that, you should set also those:
- (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
- Code: Select all
; high-priority = yes
; nice-level = -20
; realtime-scheduling = yes
; realtime-priority = 1- Code: Select all
<$USER> - nice -11 # values from -20 upto 19 allowed
<$USER> - rtprio 9 # values from 1 upto 99 allowed- 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!
- in the PA conf, you can find params like:
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:
Each user who wants high-priority and/or realtime scheduling may put config into his ~/.pulse
- (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





