We are calling out to libc's rand() function, which has significant
overhead, especially since we are calling it 88200 times per second
(2 channels * 44100 samples).
Implement a very simple linear congruential generator in our code that
is plenty good enough for dithering purposes, and small enough for the
compiler to optimize and inline.
The math operations are all equivalent, but are simplified a bit for the
benefit of processors with slower floating point performance.
* Don't use float casts when we need to eventually convert to double
precision anyway.
* Use multiplication instead of division when possible.
We need to use this any time we write to or access any of the
audio-buffer related variables. This also removes the need to use
'volatile', which cripples the compiler optimizations.
Using the `volatile` qualifier in multithreading code is never the right
answer. Mutexes should be used as was attempted with the audio buffer
code. Here, we implement a new mutex for the volume and fix_volume
globals, and grab a lock on it when necessary, which is for both reads
and writes.
If you turned set `debug = 1` in hairtunes, you'd quickly get a mess of
debug messages that showed bf_est_drift in bf_est_update() going quicky
out of range toward a float NaN value (usually negative). Clearly the
presence of this `out` variable in biquad_filt was meant to be used, not
marked as unused.
This allows the compiler to do a much better job on this file, as it
currently can't inline most of the functions because they are
technically visible outside the file. Mark most functions and variables
static to let the compiler work.