Author Topic: PulseAudio defaults can actually be improved for near-professional use.  (Read 15986 times)

0 Members and 1 Guest are viewing this topic.

Offline Nystagmus

  • Full Member
  • ***
  • Posts: 28
  • Karma: +0/-0
  • AVLinux User
Hello and thanks for continuing AVLINUX, a very wonderful distro. 

I wanted to finally mention that PulseAudio's default configuration files for both user and system can be edited to allow much much smaller latency and real-world audio use which is on par with professional use even though everyone and their dog says that PulseAudio can't be used for pro audio. 

At least for non-input composing and mixing and synthesis, actually, PulseAudio can be used professionally. 

I will try to gather together my materials and post them up here in this thread when I get a chance later this week. 
I learned about the optimizations from a variety of websites a few years ago and although the info I can't seem to find on the web anymore, well I haven't really looked that hard, but I did save the info that I learned and have been implementing it time after time successfully in AVLINUX, Debian, and Xubuntu. 

There are about 4 simple text edits. 
The one that doesn't get a lot of publicity is actually probably the most important:  "tsched=0"
I don't entirely understand how it helps, but it does.  I will try to relook up the explaination. 

But the good news is that with the PulseAudio edits I have been able to run Cockos 32-bit Reaper v4.x and 5.x (for Windows) for multiple in Windows 7 mode years without significant problems. 
There are also some other Reaper and Wine specific settings that help to make it possible.  Also, these days I only use Wine-staging, as it's much more up to date and even it's command syntax for some things is more compatible with Windows. 

For now, here's the link on IDM Forums where I discuss this type of thing: 

http://idmforums.com/showpost.php?p=1459475&postcount=1

https://s26.postimg.org/oqo5nfd0p/etc-default-pa_Optimization.png
https://s26.postimg.org/49898w78p/etc-pulse-daemon_conf.png

The format is a bit messy, and it jumps around just a little bit, but I tried to keep it still easy to read and without errors. 
I've archived my own DAW tweaks each time, and use these tweaks myself, so I'm used to them.  The main thing to look for is the PulseAudio stuff. 

My own files are slightly different, so I will take fresh snapshots of my files to make sure I provide up to date info. 
My current system is Xubuntu 17.10 fully updated and modelled after Ubuntu Studio but without all the bloatware. 
I also implemented whatever I could learn from the AVLINUX manual. 

If nothing else, just glance at the embedded images.  Some of those are self explanatory. 
But I know there's some missing infos, so I'll try to just put the full basics up here when I can and just limit it to PulseAudio for simplicity. 

The other topics I discuss there might not all successfully apply to AVLINUX since it's different from Xubuntu and Ubuntu Studio.   

But quite a lot of the ideas are still the same; disable unneeded services, remove unneeded programs, turn off resource-heavy effects, disable last file access logging. 
However, importantly, most of this you don't have to worry about in AVLINUX, because it's already optimized quite well and tends to outperform Ubuntu Studio even after being optimized.  But each distro can learn some tricks from the others. 

I used to have a successfully popular link on UbuntuForums.com, but the admins/mods there were foolish enough to remove the Ubuntu Studio section from activity and archived it, thus making it hard to get to and no longer accepting new posts. 

Anyways, I apologize that this info is not in neat form yet, but glance at the images linked above and check back here later on this week. 
I will try to also just upload a simple copy of the sections of the 4 /etc/pulse/ files that were changed.  It's really pretty simple stuff. 
I don't know why the PulseAudio creators don't set things up this way because their defaults are really bad. 

Offline Nystagmus

  • Full Member
  • ***
  • Posts: 28
  • Karma: +0/-0
  • AVLinux User
OK, this is much simpler...

Here's some screenshots of the changes highlighted with their working values. 
I use 16-bit settings because I have a 16-bit audio interface, but most will want to change that value to 24-bit as mentioned. 
You will need to use your text editor in root mode to edit these files.   Luckily, it's not very difficult. 
The resampling mode is already set to the highest-quality, lowest CPU setting (speex). 
People have benchmark tested all the other modes, and the default really is the best. 
For regular and alternative samping rates, use whichever two rates you use the most. 
For most people it will probably be 44100 Hz and 48000 Hz. 
But if your card is 96 kHz and you like to use that mode, then you might want 44100 and 96000 or 48000 and 96000. 
Most videos and DVDs are at 48000 Hz and even some MP3s and other audio formats are too.  CD's and plenty of common audio files are 44100. 


These values are set to be compatible with USB audio and to have a latency much lower than the factory defaults. 
These should be low enough to give you some buffer protection against xruns/buffer underruns yet without causing noticeable lag. 
You ought to be able to work with VST instruments and effects latency issues, as long as you configure those programs right for that as well. 
On my system, I set WINE Configuration (winecfg) to use PulseAudio for all the audio ins and outs.  I also installed QasMixer and use PulseAudio Control (pavucontrol?) to make sure that everything is flowing correctly.  Within Cockos Reaper, I disable the audio inputs in the driver prefs because I never use those and it helps with the CPU load to disable them until you actually need them. 

If you are using a Debian system, the defaults here might be different from the Ubuntu defaults, which is what I have been using for several years. 
The parts to pay most attention to are the parts highlighted and also to any parts uncommented. 
To make sure that the settings actually take affect, make sure each section isn't commented with "#"'s at the beginnings of lines. 
After you are done with these edits, reboot the computer. 



add " tsched=0" to the indicated lines; it really helps with playback synch and with reducing latency to a form that's not so buggy.
Do this to both the /etc/pulse/default.pa  and to the /etc/pulse/system.pa . 
You will probably also want to comment out the BlueTooth stuff so it doesn't run either. 
Comment out by putting "##" in front of each line that's part of the section to disable. 


/etc/pulse/client.conf is shown here to see what a working one looks like, but you probably won't have to change anything in this. 

I hope this is helpful. 

Offline Nystagmus

  • Full Member
  • ***
  • Posts: 28
  • Karma: +0/-0
  • AVLinux User
Pulse Audio Configuration for ProAudio Use
« Reply #2 on: October 29, 2017, 04:10:46 PM »
OK, this is much simpler... (sorry about the double post, this message is the one to read!)

Here's some screenshots of the changes highlighted with their working values. 
I use 16-bit settings because I have a 16-bit audio interface, but most will want to change that value to 24-bit as mentioned. 
You will need to use your text editor in root mode to edit these files.   Luckily, it's not very difficult. 
The resampling mode is already set to the highest-quality, lowest CPU setting (speex). 
People have benchmark tested all the other modes, and the default really is the best. 
For regular and alternative samping rates, use whichever two rates you use the most. 
For most people it will probably be 44100 Hz and 48000 Hz. 
But if your card is 96 kHz and you like to use that mode, then you might want 44100 and 96000 or 48000 and 96000. 
Most videos and DVDs are at 48000 Hz and even some MP3s and other audio formats are too.  CD's and plenty of common audio files are 44100. 


These values are set to be compatible with USB audio and to have a latency much lower than the factory defaults. 
These should be low enough to give you some buffer protection against xruns/buffer underruns yet without causing noticeable lag. 

The fragment quantity and the fragmet size are multiplied together to give a latency in milliseconds.  3x2=6 milliseconds. 
And then there's some kind of safety setting below that which is very small.  I have had zero problems with these settings using
Class Compliant USB audio devices, both MIDI and audio.  The 3 fragments is recommended to be ideal, especially for USB audio. 
I used to use 4 fragments instead, but I don't notice any difference at 3.  If you do get buffer underruns/xruns, you could change these to something higher,
but modest increments are probably preferred.  If you are having buffer underruns, my guess is that the error lies in a different section of your system's configuration. 

The "tsched=0" command disables some type of timer scheduling synchronization or something like that.  However it's not an essential thing, and Wine's audio synch with drivers seems to be better with this option of disabled scheduling.  I think it has something to do with the playback cursor, and transport functions.  In the early days of me testing this, way back on Puppy Studio (linux), this was the defining command that prevented the playback cursor and transport from freezing up or long delays or even crashes of Reaper when triggering starts and stops. 

Because this has tended to work for me, and because of my phobia of JACK use unless needed, I don't use WineASIO or JACK at all.  I've tried them for REAPER long ago, and back then they weren't stable.  A nice guy tried to tell me how to fix that, but I couldn't comprehend his instructions, so instead I learned about this stuff from other websites and people who have gotten PulseAudio to work.  I think I learned some stuff from the Arch Wiki, and the PulseAudio website, and from some freelance audio programmers whose sites I have long since forgotten.  I think the tsched=0 trick might have come directly from the Puppy Linux author back when that wasn't vaporware. 

Anyways, these days I just use 32-bit Windows Reaper on 32-bit enabled 32-bit Wine-staging on 64-bit Xubuntu with the Linux Low-latency kernel.  I do NOT use the KXstudio repos because when they auto update they can break stuff, and they are getting progressively out of date. PPA references to Trusty Tahr and earlier make me nervous.  That was a long time ago in Linux time.  The Linux kernel, Debian, Ubuntu, and Wine have all progressed a lot since then.  Some of the nice programs can be obtained directly from their author's websites and some of them even come nicely as AppImages so they don't even have complex installs. 

Another nice tip is to install and configure Synaptic (if it's not already there).  And on a good day, when gdebi is working, that's a big advantage too.  With those (or dpkg -i *.deb) you can install indicator-cpufreq and have panel-based control of CPU throttling and powersaving.  No more scripts and workarounds.  I don't know how much longer that program will be available, so it's worth downloading and archiving it's debian archive for future use.  To use it, there's a drop-down menu and before audio work, choose Performance, and when not busy use On Demand.  When needing to conserve energy, use Power Save, and turn down your monitor brightness to a minimum.  The rest of the settings are pretty much just extra.  The startup default is On Demand which is a pretty good balance for most use and will prevent risk of overheating that Performance might bring. 

OK back to the PulseAudio stuff...

You ought to be able to work with VST instruments and effects latency issues, as long as you configure those programs right for that as well. 
On my system, I set WINE Configuration (winecfg) to use PulseAudio for all the audio ins and outs.  I also installed QasMixer and use PulseAudio Control (pavucontrol?) to make sure that everything is flowing correctly.  Within Cockos Reaper, I disable the audio inputs in the driver prefs because I never use those and it helps with the CPU load to disable them until you actually need them. 

If you are using a Debian system, the defaults here might be different from the Ubuntu defaults, which is what I have been using for several years. 
The parts to pay most attention to are the parts highlighted and also to any parts uncommented. 
To make sure that the settings actually take affect, make sure each section isn't commented with "#"'s at the beginnings of lines. 
After you are done with these edits, reboot the computer. 



add " tsched=0" to the indicated lines; it really helps with playback synch and with reducing latency to a form that's not so buggy.
Do this to both the /etc/pulse/default.pa  and to the /etc/pulse/system.pa . 
You will probably also want to comment out the BlueTooth stuff so it doesn't run either. 
Comment out by putting "##" in front of each line that's part of the section to disable. 


/etc/pulse/client.conf is shown here to see what a working one looks like, but you probably won't have to change anything in this. 

I hope this is helpful. 

Offline GMaq

  • Administrator
  • Hero Member
  • *****
  • Posts: 3089
  • Karma: +45/-0
  • A/V 'Nixer
    • www.bandshed.net
Hi,

Thanks for sharing this, I'm short on time right now and will read it in depth and see how feasible these tweaks are to incorporate into the next ISO update..

Thanks again!

Offline Nystagmus

  • Full Member
  • ***
  • Posts: 28
  • Karma: +0/-0
  • AVLinux User
PulseAudio tweaks
« Reply #4 on: October 31, 2017, 06:06:34 PM »
GMaq, thanks very much.  I understand.  I will try to provide some helpful specs during the upcoming week.  Peace be with you. 

Offline Nystagmus

  • Full Member
  • ***
  • Posts: 28
  • Karma: +0/-0
  • AVLinux User
Re: PulseAudio defaults can actually be improved for near-professional use.
« Reply #5 on: November 05, 2017, 06:19:12 PM »
GMaq, let me know of any info from me which would be helpful for you in your tests. 
Also, I can no longer recommend going to http://IDMforums.com, even for access to the technical infos I provided to them (about Linux DAW use) which a mod turned into a forum Tutorial "sticky" (permanently accessible item). 

Due to either a  misunderstanding (not everyone read my complete explanations and instead jumped to conclusions), or due to typical internet bullying, or both, I've been told that I'm temporarily blocked from posting or editing there, although they didn't inform me via their PM system, so I didn't know that until I was trying to post a regular supportive message about somebody's tune and saw the auto-generated forum error which said that I'm blocked from posting or editing there until July of 2018.  It's probably a mix of both because I complied with their requests and rules and people were responding to things I didn't say and also taking things I said WELL OUT OF CONTEXT, and ignoring everything I said which worked hand in hand with normal acceptable posting.  They either didn't carefully read what I said or they skipped the most important parts.  Also, some of the mods there are seriously bullies in terms of comments and behaviors; so I cannot in good conscience recommend people to go there. 

However, on this site, unlike their site, posts cannot be edited past a rather short time threshold... so I can't remove the link to that forum.   
Don't worry about it too much though, I'm about musicianship and problem-solving, not fighting or internet martial arts. 

It doesn't matter that much though for helping you here, though, because the info I posted on your forum about PulseAudio defaults tweaking is in a much smaller, shorter, form.     
Also, I have my files on my harddrive and of course am still using the same gear all the time.  I'm very familiar with what I've done to my system, because it's become a routine for me every time I install either Ubuntu Studio, or Lubuntu, or Xubuntu, or Debian, or MX Linux, or AVLINUX.  I finally settled upon Xubuntu as my primary Linux partition and still don't have a running AVLINUX partition yet; I've been busy with other things for the moment. 

I'll do some testing of how the tweaks work on AVLINUX too. 
My Xubuntu system is running stable long-term for me now, and I still use it often and Xubuntu is still remarkably similar to Debian anyhow, as you probably already know. 
Also, I have a much better internet connection these days, so I will be better able to upload any infos you'd need. 

Peace be with you, and thanks for the AVLINUX successful Linux DAW project. 
I may have some differences of Linux prefs, but at the core, your distro has many advantages over other distros and can also work side by side with other distros without disturbing them too.  Every distro has some weaknesses as well as strengths, but the weaknesses of AVLINUX aren't bad enough to be deal-breakers for most users as far as I know.  I'm glad it's still going.  When I have more time to learn it's ins and outs, I'll try to be more active in improving my install of it and will share here if I learn any good techniques that others haven't already mentioned.  Again, Peace be with you, and thanks for the AVLINUX successful Linux DAW project. 

Offline protozone

  • Jr. Member
  • **
  • Posts: 18
  • Karma: +1/-0
  • AVLinux User
Embedded images above missing... here's some of the info
« Reply #6 on: May 23, 2018, 09:59:58 PM »
Nystagmus explained most of his tweaks via embedded and hosted image screenshots.  Since they are no longer there, here's some info that could be helpful, a link to a page where some of the specifics are mentioned (by me). 

Instead of using PNG images, it's just [ code ] [ / code ] types of info.  The manually edited files reside within /etc/pulse/ on most systems:

https://linuxmusicians.com/viewtopic.php?f=27&t=18511&p=93257#p93257

I hope this helps repair the missing info. 
Peace

 :halo:

Offline protozone

  • Jr. Member
  • **
  • Posts: 18
  • Karma: +1/-0
  • AVLinux User
In the spirit of what Nystagmus was trying to do, I made some PNG files of the main PulseAudio configuration file edits. 
More info is available here:  https://www.linuxmusicians.com/viewtopic.php?f=27&t=18682

The annotated screenshots (and other data) will eventually be available from this site:  https://archive.org/details/Linux-DAW-Extra-Help

But for now, it's more convenient to just show the images in forums like this. 
I will post the main stuff up at LinuxMusicians.com as I am making the weblog. 
After the weblog is mostly done, I'll let you guys know here at AV LINUX HQ. 

Here's a tiny preview of some of the info... (tips for 32-bit REAPER on WINE-staging)



...the tsched=0 tweak learned about from Puppy Studio...


I'm struggling with formatting a bit since I just started learning how to do this stuff. 
When I'm done, I'll probably make a PDF available and some videos or just plain audio podcasts. 

Aw, what the heck, you'll want to see this too!  No use teasing...



If the images temporarily disappear, don't panic.  It's because I'm editing and fixing mistakes. 
I'll try to get good results.  I want this to be a resource for anybody and everybody who wants to make music with LINUX! 

By the way, some folks might actually get away with a chunk size of 2 instead of 3 or 4, but 3 is necessary for USB devices. 
That beats the 4-8 second default PulseAudio comes at "from the factory". 
But for now, I went for what's fast enough and stable enough for me.  I'll do some more tests at home. 

Good luck. 
Have fun and thanks for being excellent!   :cyclops:
« Last Edit: June 27, 2018, 05:43:20 PM by protozone »

Offline GMaq

  • Administrator
  • Hero Member
  • *****
  • Posts: 3089
  • Karma: +45/-0
  • A/V 'Nixer
    • www.bandshed.net
Hi protozone!

Thanks very much to both you and Nystagmus for sharing this valuable info!

I'm a little hesitant to go ahead and change the PulseAudio defaults in AV Linux but this info is excellent for users after installing, at some point I may also add this info to the AV Linux user manual, thanks again!

Offline sunrat

  • Jr. Member
  • **
  • Posts: 10
  • Karma: +0/-0
  • AVLinux User
I looked into this recently and there is no universally agreed advice on what is best. Some good discussions are found at:
https://forum.manjaro.org/t/solved-terrible-sound-in-linux-much-better-in-windows/8203/18
https://r3dux.org/2013/12/how-to-enable-high-quality-audio-in-linux/
https://www.head-fi.org/threads/bit-perfect-audio-from-linux.561961/#post_7596563

I ended up with this for ~/.config/pulse/daemon.conf :
 
Code: [Select]
default-sample-format = float32le
default-sample-rate = 48000
alternate-sample-rate = 44100
default-sample-channels = 2
default-channel-map = front-left,front-right
default-fragments = 2
default-fragment-size-msec = 125
resample-method = soxr-vhq
enable-lfe-remixing = no
high-priority = yes
nice-level = -11
realtime-scheduling = yes
realtime-priority = 9
rlimit-rtprio = 9
daemonize = no

I have M-Audio Audiophile 2496 card into Adam A5X speakers and it sounds good, although I can't say definitely it is better than default settings.
For production in AVL I use JACK anyway, so Pulse settings are not so important.

Offline protozone

  • Jr. Member
  • **
  • Posts: 18
  • Karma: +1/-0
  • AVLinux User
I looked into this recently and there is no universally agreed advice on what is best. Some good discussions are found at:
https://forum.manjaro.org/t/solved-terrible-sound-in-linux-much-better-in-windows/8203/18
https://r3dux.org/2013/12/how-to-enable-high-quality-audio-in-linux/
https://www.head-fi.org/threads/bit-perfect-audio-from-linux.561961/#post_7596563

I ended up with this for ~/.config/pulse/daemon.conf :
 
Code: [Select]
default-sample-format = float32le
default-sample-rate = 48000
alternate-sample-rate = 44100
default-sample-channels = 2
default-channel-map = front-left,front-right
default-fragments = 2
default-fragment-size-msec = 125
resample-method = soxr-vhq
enable-lfe-remixing = no
high-priority = yes
nice-level = -11
realtime-scheduling = yes
realtime-priority = 9
rlimit-rtprio = 9
daemonize = no

I have M-Audio Audiophile 2496 card into Adam A5X speakers and it sounds good, although I can't say definitely it is better than default settings.
For production in AVL I use JACK anyway, so Pulse settings are not so important.

Thanks for explaining that. 
Yeah, perhaps you're right. 
I do know that the early PulseAudio defaults probably sound just fine, but the latency (lag time) was astonishingly large and too large for MIDI use. 
That's the main advantage of this stuff. 
I had trouble getting onto the PulseAudio mailing list to talk to the devs, so maybe I give up. 

But I think your choice of default format of floating point makes sense.  I noticed that some of my other system settings for ALSA are floating point.  Maybe I should change to that also.  I'm not entirely sure. 

The number of fragments can be 2, as yours is.  I forgot to mention that.  Yours is correct.  But a few types of hardware will complain or fail if the fragment size isn't a multiple of 8 (32,64,128,256,384,512,960,1024,2048,4096) type of thing.  But if your system runs fine, then it runs fine and that's proof enough.  On my old Alesis 320USB device, it had to be multiples of 8.  Also FL Studio ASIO has to be multiples of 8, but is already locked in like that.  125 is close enough to 128 anyhow. 

I'm not an expert on this stuff, just a regular user and I post what tends to work. 
It's good to know you have insights too.  Thanks for the links.  I'm reading them now. 

Maybe the info I was going on is old and outdated (about the conversion algorithm type choices).  SoX probably isn't bad--I don't know what the CPU benchmark for it is. 

Offline sunrat

  • Jr. Member
  • **
  • Posts: 10
  • Karma: +0/-0
  • AVLinux User
Sox is very good. Go to this page to view sample rate conversion sweep plots which compare a vast number of programs and you'll see Sox is cleaner than nearly all others - http://src.infinitewave.ca/
Particularly compare Sox 14.4 VHQ Linear Phase with Xiph.org Speex 1.2rc1 (Quality 10). That's the highest quality Speex and you can clearly see artifacts. Whether you could actually hear them is another matter, but technically Sox seems better.
Quote
The VHQ settings produce 'sweep' graphs with impressively black backgrounds, but in fact these settings are overkill for most situations.
from http://sox.sourceforge.net/SoX/Resampling
It's worth having a browse around the Sox site, particularly the FAQ - http://sox.sourceforge.net/

Offline protozone

  • Jr. Member
  • **
  • Posts: 18
  • Karma: +1/-0
  • AVLinux User
I will check those out.  I think if I remember correctly, I arrived at Speex-0 from a test site report that was measuring CPU load during conversion measured against sound quality.  A few other settings were very low CPU use, but had horrible quality.  If I remember correctly, Speex-0 had the same very low CPU use, but without a drastic drop in quality.  Conversely, some of the better sounding convert algorithms came at a CPU load cost. 

The guy who did the bulk of the tests along with some other contributers seemed to conclude that Speex-0 was the best one for the best of both worlds.  Nicely, that's the default.  I'm not against changing it if you want to. 

On my earlier system, I needed every ounce of CPU power, so I wasn't going for max quality during recording/mixing, only during rendering and jukebox style players.  That's still largely how I operate.  For example, in FL Studio I set it to plain old linear converters.  I don't do much sample rate conversion there anyhow, and linear is super fast.  During render, I set it to the top quality.  I also set to top quality in REAPER during render.  These days, neither is slow. 

Thanks for the feedback. 
I apologize that I'm kinda sloppy with this stuff for a while.