Topic: Linux tips - fixes for latency, audio glitches, poor performance ...

TL;DR version:
Cut and paste the following in a terminal window and hit enter:

for ((i=0; i<$(cpufreq-info | grep analyzing | wc -l); i++)); do sudo cpufreq-set -g performance -c $i; done

------------------------

Long version:

How I got Pianoteq 5 flying on Linux (after some initial woes)

I had a bit of trouble getting Pianoteq Std working without issues on my Linux Mint 17.2 Dell laptop. It's a fairly capable machine, i5-3337U 1.8GHz, 8GB RAM - should be plenty to run PTQ.

Yet I kept getting crackling/popping sounds every now and again (even without CPU overload), and latency was not all that reliable or great (not near what PTQ claimed) and polyphony was pathetic (<10, at most 20) on "Pessimistic".

Things I tried (but did not solve the problems)
- Low latency Linux kernel (this is usually a good idea)
- JACK audio set up for realtime audio (this actually made things a bit worse; but it wasn't JACK's fault, see below)
- "sudo renice"-ing the 'Pianoteq 5' process to -20 (if you don't know what that means, don't worry; if you're curious, look up the "renice" command in Linux)

What worked in the end:
- Disable CPU throttling and set all CPUs/cores to run at their maximum speed

You can accomplish this with the cpufreq-set command (part of the cpufrequtils package, installed by default on most Linux systems). But first to see your settings and hardware info run cpufreq-info (in a terminal window). The only info you really need is how many CPUs (cores) the OS thinks you have. You can read the full output of cpufreq-info or if it's too much info, do something like this:

ptquser@mycompter:/home/ptquser/Pianoteq Standard 5.42/Pianoteq 5/amd64 > cpufreq-info | grep analyzing
analyzing CPU 0:
analyzing CPU 1:
analyzing CPU 2:
analyzing CPU 3:

So here we have four CPUs/cores and they are numbered 0 to 3. We want to configure all of these for performance, which will disable on-the-fly CPU speed changes and will always run them at their max rated speed (without overclocking). This is accomplished with cpufreq-set:

ptquser@mycompter:/home/ptquser/Pianoteq Standard 5.42/Pianoteq 5/amd64 > sudo cpufreq-set -g performance -c 0
[sudo] password for ptquser: 
sudo cpufreq-set -g performance -c 1
sudo cpufreq-set -g performance -c 2
sudo cpufreq-set -g performance -c 3

This fixed all the issues. I torture tested it and polyphony "Pessimistic" goes over 100, latency is non-existent, there are no glitches in the sound output and the CPU never overloads. My final PTQ configuration is:

- Audio device type: ALSA (not using JACK, no need for now but may use it in future)
- Output: PulseAudio Sound Server
- Sample rate: 48000 Hz
- Audio buffer size: 128 samples (2.7 ms)
- Multicore rendering ON
- CPU Overload detection ON
- Internal sample rate: 48000 Hz
- Max polyphony: Auto (Pessimistic)

Cheers.

Last edited by SteveLy (25-12-2015 18:24)
3/2 = 5

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

Hi,

could you please show, which scaling_driver your system is running?

with ...

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

groovy wrote:

could you please show, which scaling_driver your system is running?

acpi-cpufreq

3/2 = 5

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

SteveLy wrote:

acpi-cpufreq

Thanks, interesting, that Linux Mint 17.2 has not switched over to scaling_driver intel_pstate.

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

It's strange that you had issues: I'm running fine with a less powerful i3-3217U with Lubuntu 15.04.

I applied the recommended steps in Pianoteq readme.txt (including Jack). It was running fine at 48000 Hz / 128 buffer, but needed to set "performance" governor for more demanding tasks (or increasing buffer size).
Then I installed the low latency kernel, and it made a big difference: now I seldom need to change the default "powersave" governor (it seems to me that the reason is that this low latency kernel is much more reactive to speed change needs). I prefer the "powersave" governor since the notebook is quieter, neeeding less fan cooling.

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

alessandro wrote:

It's strange that you had issues: I'm running fine with a less powerful i3-3217U with Lubuntu 15.04.

I don't know the reason but the CPU speed switching seemed to have caused the glitches. I will try it with slower fixed speed CPU setting and see how that goes.

3/2 = 5

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

I was wondering which Jack you were running (Jack 1 or Jack 2)?  Maybe you already know this, but if running Jack 2, you may want to check to see if you are running it in synchronous or asynchronous mode (for example, see https://help.ubuntu.com/community/HowTo...figuration or https://linuxmusicians.com/viewtopic.ph...mp;t=14000 for more information)?  Running in synchronous mode significantly reduce xruns (i.e. cracks/pops) when running Jack 2.  That is how I always run Jack on my machine and I get good performance this way.

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

I'm using Mint 17.2 and my scaling driver shows up as Intel_Pstate. The RT kernel could be the culprit in switching back to the acpi driver in order to keep a consistent latency.

Could be a Dell BIOS issue or a bad temperature reporting issue.  Perhaps the laptop is reporting that it's getting too hot and so it scales down when in reality it's not.

Re: Linux tips - fixes for latency, audio glitches, poor performance ...

I have JACK 1.9.10 (but I'm not using JACK)

Still having some issues occasionally. Every now and again PTQ stops producing piano sounds and all I get is noise. Restarting it gets it working again. I'm going to upgrade/change the whole OS soon (and ditch bloody KDE) so I won't bother trying to fix it now.

Edit: Actually, restarting PTQ does not always fix the problem. Right now all that works is increasing the buffer size to around 1024 samples which results in unacceptable latency...

Edit #2 (30 Dec 2015): Changing the sampling rate from 48kHz to 44.1kHz got things working again with buffer size of 128 (or even 64). And oddly enough, if I change the sampling rate back to 48kHz, it still works fine. Weird.

Edit #3 (4 Jan 2015) After more of the same issues (ones mentioned in this post) I added myself to the audio group and rebooted. Everything works fine (for some days now). I use JACK sometimes to route MIDI between other software (e.g., MuseScore) and Pianoteq. All good.

Last edited by SteveLy (04-01-2016 13:49)
3/2 = 5