## Getting Pulseaudio to schedule real-time threads under Debian / Stretch and beyond.

On the computer which I name ‘Phosphene’, I have Debian 9 / Stretch installed, and, going the popular route, the Debian maintainers have decided that ‘Pulseaudio’ should be the main sound server, while in certain cases, it can be made to coexist with the ‘Jack’ / ‘Jack v2′ daemon, the latter for more demanding needs. In my case, starting Jack suspends Pulse.

In addition, Debian systems I’m familiar with run ‘pulseaudio’ as user, and not as root.

But, the way my Pulse daemon is configured, includes a ‘loopback’ module, that sends audio that has been input and sampled from the analog input of my (“Creative X-Fi”) sound card, back to its analog output, so that I can listen to an old-fashioned-but-modern radio receiver, over my speakers, without having to connect anything special to do so.

The problem that I was experiencing was, buffer underruns, and sound drop-outs, due to the way this default sound server was operating the sound card. And, surely enough, it had something to do with a by-now famous issue, of allowing Pulse to schedule certain threads to run with real-time priority. This can be enabled in the config file ‘/etc/pulse/daemon.conf‘, but fails to become actual when just enabled so.

Trying to find an answer to why this attempt was failing, sent me on a trip to many Web-sites and BB-postings, most of which had as disadvantage, the fact that with Pulse, there is an old way and a new way to accomplish this, and the fact that most of the BB-postings assumed the old way, being dated to the year 2016 and earlier.

Rest assured, under Debian 9 / Stretch, authorizing Pulse to schedule some threads with RT priority, is managed according to ‘the new way’. Just to recap how ‘the old way’ worked:

The file ‘/usr/bin/pulseaudio‘ needed to be set with ‘SETUID root’, and when run this way, if the sound server detected that the real user (not the effective user) belonged to the group ‘pulse-rt‘, would schedule the threads it needed to run with RT, and would then drop privileges, so that according to the process-monitor ‘top’, it would never even give a hint that anything had in fact been scheduled with RT.

This is how ‘the new way’ is supposed to work:

If the user needs for Pulse specifically to run with RT, he must actually install the package ‘rtkit‘, which runs as a system user, and which sets certain threads to have RT priority in a curated way, that’s meant to be ‘safer’, than it still is for any one user to belong to a group, that simply allows him or her to run arbitrary processes with RT. In fact, ‘the old way’ was also meant as a similar safeguard.

I had installed the specified package, rebooted my system – with Pulse given its new startup parameters, and found alas, that the file ‘/var/log/syslog‘, which was benefiting from an elevated logging level set by me, revealed numerous messages that I did not understand.

Trying to figure out what was happening resulted in more than one day’s frustration, and then finally, to some peace of mind…

(Updated 4/16/2020, 13h15 … )

If a software-equalizer possesses GUI controls that correspond to approximate octaves, or repeated 1-2-5 sequences, it is entirely likely to be implemented as a set of bandpass filters acting in parallel. However, the simplistic bandpass filters I was contemplating, would also have required that the signal be multiplied by a factor of 4, to achieve unit gain where their low-pass and high-pass cutoff frequencies join, as I described in this posting.

(Edit 03/23/2017:

Actually, the parameters which define each digital filter, are non-trivial to compute, but nevertheless computable when the translation into the digital domain has been carried out correctly. And so a type of equalizer can be achieved, based on derived bandpass-filters, on the basis that each bandpass-filter has been tuned correctly.

If the filters cross over at their -6db point, then one octave lower or higher, one filter will reach its -3db point, while the other will reach its -12db point. So instead of -12db, this combination would yield -15db.

The fact that the signal which has wandered into one adjacent band is at -3db with respect to the center of that band, does not lead to a simple summation, because there is also a phase-shift between the frequency-components that wander across.

I suppose that the user should be aware, that in such a case, the gain of the adjacent bands has not dropped to zero, at the peak of the current band, so that perhaps the signal will simplify, if the corner-frequencies have been corrected. This way, a continuous curve will result from discrete settings.

Now, if the intention is to design a digital bandpass filter with greater than 6 db /Octave falloff curves, the simplistic approach would be just to put two of the previous stages in series – into a pipeline resulting in second-order filters.

Also, the only way then to preserve the accuracy of the input samples, is to convert them into floating-point format first, for use in processing, after which they can be exported to a practical audio-format again. )

(Edit 03/25/2017 :

The way simplistic high-pass filters work, they phase-shift the signal close to +90⁰ far down along the part of the frequency-response-curve, which represents their roll-off. And simplistic low-pass filters will phase-shift the signal close to -90⁰ under corresponding conditions.

OTOH, Either type of filter is supposed to phase-shift their signal ±45⁰, at their -3db point.

What this means is that if the output from several band-pass filters is taken in parallel – i.e. summed – then the center-frequency of one band will be along the roll-off part of the curve of each adjacent band, which combined with the -3db point from either its high-pass or its low-pass component. But then if the output of this one central band is set to zero, the output from the adjacent bands will be 90⁰ apart from each other. )

(Edit 03/29/2017 :

A further conclusion of this analysis would seem to be, that even to implement an equalizer with 1 slider /Octave properly, requires that each bandpass-filter be a second-order filter instead. That way, when the signals wander across to the center-frequency of the slider for the next octave, they will be at -6db relative to the output of that slider, and 180⁰ phase-shifted with respect to each other. Then, setting the center slider to its minimum position will cause the adjacent ones to form a working Notch Filter, and will thus allow any one band to be adjusted arbitrarily low.

And, halfway between the slider-center-frequencies, the gain of each will again be -3db, resulting in a phase-shift of ±90 with respect to the other one, and achieving flat frequency-response, when all sliders are in the same position.

The problem becomes, that if a 20-band equalizer is attempted, because the 1 /Octave example already required second-order bandpass-filters, the higher one will require 4th-order filters by same token, which would be a headache to program… )