Page 1 of 1

[TUT] tweaking pulseaudio

Posted: 15 Dec 2015 06:46
by kurotsugi
I made this guide mainly for documentation about pulse related tweak. feel free to use it, or discuss it if you have any thought about this post. as usual this thread is intended as open discussion :3

this tweak is for improving audio quality on pulseaudio. the first part is about fixing audio glitich and revolve around modifying /etc/pulse/daemon.conf. it could be divided into several part. the second part is about adding audio effect on pulseaudio.


1-1 Processing
make sure you enable realtime processing.

Code: Select all

; realtime-scheduling = yes
; realtime-priority = 5
find this line and change the value like this one

Code: Select all

resample-method = src-sinc-best-quality
as for default sample format, I'd recommend to use float32ne. it's faster and better. but you can also use a value match to your device spec. run 'pacmd info' then scroll down to 'alsa_output.pci-xxxxxxx'

Code: Select all

4 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
	driver: <module-alsa-card.c>
	state: RUNNING
	suspend cause: 
	priority: 9959
	volume: front-left: 30124 /  46% / -20.25 dB,   front-right: 30124 /  46% / -20.25 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 61.43 ms
	max request: 10 KiB
	max rewind: 64 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
as for default and alternate sampling rate I prefer 48000 and 44100 respectfully. using value higher than 48000 is useless since it produce freq outside of human spec.

1-3 Buffer

Code: Select all

pacmd info |grep buffer
it will give a result like this

Code: Select all

		device.buffering.buffer_size = "65536"
		device.buffering.fragment_size = "32768"
		device.buffering.buffer_size = "65536"
		device.buffering.fragment_size = "32768"
now we need to calculate the fragment size and number of fragments. this is an example of the calculation.
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
the fragment size is the value we got from the calculation above while default fragment value is device.buffering.buffer_size divided by device.buffering.fragment_size.

save the new configuration file then do a 'pulseaudio -k' to kill and restart pulseaudio.


since I've made a tutorial about it, to make it short, please refer these thread before you continue to know how it works.
- adding BS2B on pulse
- combining pulse with JACK and dsp

I mainly use CAPS. there are several other LADSPA plugin in the repo but CAPS is lot easier to use. this is the audio effects added into my system on most times. it's the content of

Code: Select all

#load bs2b
load-module module-ladspa-sink sink_name=bs2b master=alsa_output.pci-0000_00_1b.0.analog-stereo plugin=bs2b label=bs2b control=700,6.0

#load CAPS stereo compressor. the main problem with this compressor is that the algorithm is dead too simple. with the standard value it works too slow and ruin the audio output. the compression rate also too hight. after spending several hours I found this value is quite good if you didn't increase low freq output with EQ, bass enhancer or something similar. 
load-module module-ladspa-sink sink_name=compress master=bs2b plugin=caps label=CompressX2 control=0,0,0.25,0.5,0.05,0.20,5

#load CAPS 10equalizer 
#load-module module-ladspa-sink sink_name=equal master=bs2b plugin=caps label=Eq10 control=7,6,-3,-3,0,0,2,2,0,-2

#load CAPS EqFA4p - 4 variable parametric equalizer. works better than old 10 bands. all freq is independent and give more natural output. 
load-module module-ladspa-sink sink_name=equal master=compress plugin=caps label=EqFA4p control=1,75,1,6,1,250,1,-3,1,2000,2,3,1,8000,1,0,0

aside from it sometimes I use calf-plugins within JACK. my calf setting is

Code: Select all

<?xml version="1.1" encoding="utf-8"?>
<rack><plugin type="bassenhancer" instance-name="bassenhancer" input-index="7" output-index="5">
<preset bank="0" program="0" plugin="bassenhancer" name="">
  <param name="bypass" value="0" />
  <param name="level_in" value="1" />
  <param name="level_out" value="1" />
  <param name="amount" value="1" />
  <param name="meter_in" value="0.163447" />
  <param name="meter_out" value="0.180112" />
  <param name="clip_in" value="0" />
  <param name="clip_out" value="0" />
  <param name="drive" value="8.5" />
  <param name="blend" value="0" />
  <param name="meter_drive" value="0.0394344" />
  <param name="freq" value="120" />
  <param name="listen" value="0" />
  <param name="floor_active" value="1" />
  <param name="floor" value="20" />
<plugin type="deesser" instance-name="deesser" input-index="11" output-index="11">
<preset bank="0" program="0" plugin="deesser" name="">
  <param name="bypass" value="0" />
  <param name="detected" value="0.0341255" />
  <param name="compression" value="1" />
  <param name="detected_led" value="0" />
  <param name="clip_out" value="0" />
  <param name="detection" value="0" />
  <param name="mode" value="1" />
  <param name="threshold" value="0.234" />
  <param name="ratio" value="3" />
  <param name="laxity" value="15" />
  <param name="makeup" value="1" />
  <param name="f1_freq" value="8000" />
  <param name="f2_freq" value="6500" />
  <param name="f1_level" value="1" />
  <param name="f2_level" value="4" />
  <param name="f2_q" value="1" />
  <param name="sc_listen" value="0" />
<plugin type="multibandcompressor" instance-name="multibandcompressor" input-index="13" output-index="13">
<preset bank="0" program="0" plugin="multibandcompressor" name="">
  <param name="bypass" value="0" />
  <param name="level_in" value="1" />
  <param name="level_out" value="0.846745" />
  <param name="meter_inL" value="0.189805" />
  <param name="meter_inR" value="0.171171" />
  <param name="meter_outL" value="0.321103" />
  <param name="meter_outR" value="0.355087" />
  <param name="clip_inL" value="0" />
  <param name="clip_inR" value="0" />
  <param name="clip_outL" value="0" />
  <param name="clip_outR" value="0" />
  <param name="freq0" value="120" />
  <param name="freq1" value="1000" />
  <param name="freq2" value="6000" />
  <param name="mode" value="1" />
  <param name="threshold0" value="0.25" />
  <param name="ratio0" value="2" />
  <param name="attack0" value="150" />
  <param name="release0" value="300" />
  <param name="makeup0" value="2" />
  <param name="knee0" value="2.82843" />
  <param name="detection0" value="0" />
  <param name="compression0" value="1" />
  <param name="output0" value="0.105173" />
  <param name="bypass0" value="0" />
  <param name="solo0" value="0" />
  <param name="threshold1" value="0.25" />
  <param name="ratio1" value="2" />
  <param name="attack1" value="150" />
  <param name="release1" value="300" />
  <param name="makeup1" value="2" />
  <param name="knee1" value="2.82843" />
  <param name="detection1" value="0" />
  <param name="compression1" value="1" />
  <param name="output1" value="0.306647" />
  <param name="bypass1" value="0" />
  <param name="solo1" value="0" />
  <param name="threshold2" value="0.25" />
  <param name="ratio2" value="2" />
  <param name="attack2" value="150" />
  <param name="release2" value="300" />
  <param name="makeup2" value="2" />
  <param name="knee2" value="2.82843" />
  <param name="detection2" value="0" />
  <param name="compression2" value="1" />
  <param name="output2" value="0.133959" />
  <param name="bypass2" value="0" />
  <param name="solo2" value="0" />
  <param name="threshold3" value="0.25" />
  <param name="ratio3" value="2" />
  <param name="attack3" value="150" />
  <param name="release3" value="300" />
  <param name="makeup3" value="2" />
  <param name="knee3" value="1.257" />
  <param name="detection3" value="0" />
  <param name="compression3" value="1" />
  <param name="output3" value="0.034787" />
  <param name="bypass3" value="0" />
  <param name="solo3" value="0" />
  <param name="notebook" value="0" />
<plugin type="eq12" instance-name="eq12" input-index="23" output-index="23">
<preset bank="0" program="0" plugin="eq12" name="">
  <param name="bypass" value="0" />
  <param name="level_in" value="1" />
  <param name="level_out" value="1" />
  <param name="meter_inL" value="0.201082" />
  <param name="meter_inR" value="0.197748" />
  <param name="meter_outL" value="0.199718" />
  <param name="meter_outR" value="0.19308" />
  <param name="clip_inL" value="0" />
  <param name="clip_inR" value="0" />
  <param name="clip_outL" value="0" />
  <param name="clip_outR" value="0" />
  <param name="hp_active" value="4" />
  <param name="hp_freq" value="30" />
  <param name="hp_mode" value="1" />
  <param name="lp_active" value="0" />
  <param name="lp_freq" value="18000" />
  <param name="lp_mode" value="1" />
  <param name="ls_active" value="4" />
  <param name="ls_level" value="2.11404" />
  <param name="ls_freq" value="100" />
  <param name="hs_active" value="5" />
  <param name="hs_level" value="1" />
  <param name="hs_freq" value="5000" />
  <param name="p1_active" value="4" />
  <param name="p1_level" value="1.94531" />
  <param name="p1_freq" value="60" />
  <param name="p1_q" value="1" />
  <param name="p2_active" value="4" />
  <param name="p2_level" value="0.659754" />
  <param name="p2_freq" value="120" />
  <param name="p2_q" value="1" />
  <param name="p3_active" value="1" />
  <param name="p3_level" value="0.846745" />
  <param name="p3_freq" value="250" />
  <param name="p3_q" value="1" />
  <param name="p4_active" value="1" />
  <param name="p4_level" value="1.08673" />
  <param name="p4_freq" value="500" />
  <param name="p4_q" value="1" />
  <param name="p5_active" value="1" />
  <param name="p5_level" value="1.28343" />
  <param name="p5_freq" value="1000" />
  <param name="p5_q" value="1" />
  <param name="p6_active" value="1" />
  <param name="p6_level" value="1.28343" />
  <param name="p6_freq" value="2000" />
  <param name="p6_q" value="1" />
  <param name="p7_active" value="1" />
  <param name="p7_level" value="1.28343" />
  <param name="p7_freq" value="4000" />
  <param name="p7_q" value="1" />
  <param name="p8_active" value="5" />
  <param name="p8_level" value="1.28343" />
  <param name="p8_freq" value="8000" />
  <param name="p8_q" value="1" />
  <param name="individuals" value="0" />
  <param name="zoom" value="0.25" />
  <param name="analyzer" value="1" />
  <param name="analyzer_mode" value="2" />
man pulse-daemon.conf

Re: [TUT] tweaking pulseaudio

Posted: 16 Dec 2015 14:32
by ilu
Since I sometimes have weird audio behaviour (which I usually solve by wildly clicking any switch available in pulse until it works again) I'd like to know at whom this tutorial is directed: The second part obviously deals with very special stuff for those who need audio effects (I don't even know what that is). But would the average user gain anything from the first part? What glitch are you fixing there?

Re: [TUT] tweaking pulseaudio

Posted: 17 Dec 2015 04:54
by kurotsugi
Due to many layer used on linux, pulse sometimes produce glitchy sound. You'll need the first part to fix this issue.


In my experience pulse was never produce good sound by default. I think most user simply didn't notice the different

Re: [TUT] tweaking pulseaudio

Posted: 17 Dec 2015 07:02
by Arjen Balfoort
Moved to the tutorials section.

Re: [TUT] tweaking pulseaudio

Posted: 24 Nov 2016 03:37
by Albert
I was attempting to follow your instructions '[TUT] tweaking pulseaudio' in 'Board index Multilingual Support Tutorials'
I ran in console:

Code: Select all

pacmd info
I then scrolled down to 'alsa_output.pci-0000_00_1b.0.analog-stereo'.

My info had different values than the code block you show, e.g. I had 'state: SUSPENDED' and your code had 'state: RUNNING'. I then assumed that the info outputed by 'pacmd info' was to be duplicated with the changes in your code. However, I did not know how to change the output in a console, therefore I copied the info from the console into mousepad and made changes there. By this time I was very confused. I realized that I had no idea where that 'info' file was, or if it was even actually in a text format.

What was your intent? Your next step, '1-3 Buffer', indicates that you expect the corrected info to be available to a second invocation of 'pacmd info', and I have no idea how to get it there.

Re: [TUT] tweaking pulseaudio

Posted: 24 Nov 2016 06:13
by kurotsugi
the first part is optimizing pulse conf setting. you can skip that part if you have no issue with your audio setting. step 1-2 was optimizing the resampling method. 'pacmd info' will show you the resample spec of your soundcard. you can scroll down my exampe above and you'll see

Code: Select all

sample spec : s16le 2ch 44100khz.
this is my hardware spec. based on this information you can choose the best resample method for your device

step 1-3 is optimizing buffer value.

if you can't follow this part you can directly jump into part two. please note that what I wrote here in the 2nd part is a concept. the codes/values were an example. you can actually create your own setting based on this concept. the audio world in linux is too vast for this small tutorial.

Re: [TUT] tweaking pulseaudio

Posted: 24 Nov 2016 16:15
by Albert
Wow. Thank you. I didn't expect a reply on Thanksgiving.

Re: [TUT] tweaking pulseaudio

Posted: 24 Nov 2016 20:49
by kurotsugi
it's just ordinary friday in my country :3

btw, if you missed it, part 1 is about modifying /etc/pulse/daemon.conf. all the changes was made there. part 2 is modifying /etc/pulse/