Saturday, September 24, 2022

Limiters, Limitations, and Pink Noise

Sigh, a rather difficult and horrid day. I've spent a lot of it programming, which I dislike; programming is the antithesis of art - but, I programmed to help me with my music, as I kept repeating to myself today. Yesterday I thought that my new 'organic' limiter was fine and spectacular, especially on sine waves. It turned out to only be fine and spectacular on sine waves.

It worked by tracing any volume levels over the 'floor' then constraining these to between 'floor' and 'ceiling' based on 'sky' (sky is the ultimate high). My only reason for doing it at all was an idea to auto-calculate 'sky' on the fly, but I abandoned that idea and aimed to smooth out the results instead by interpolating the constrained results (which can sound buzzy and distorted) with an undistorted signal. Unfortunately the undistorted signal could be all over the place. I added a second volume tracer to the result, a 'second pass' and clipped the peaks. This did something, but the results were still a little to organic.

The result reminded me of the meaty tentacle monsters in Akira, and I toyed with calling it an Akira Limiter because of the way the waves bent and curled all over the place, never quite staying put. I gave up. The very least a limiter should do, the very least, is stay within its limits.

I took a break and studied Pink Noise. I realised that this sounds rather like 'Rock White' which is a white noise wave that I've filtered over the past year or more with the results of spectrum analysis of commercial rock music. Rock White is, therefore, like a tuning fork for balancing audio tracks to studio quality. It's not quite like Pink Noise, but it is close, so I wondered about making a Pink Noise Generator. It turned out to be easy. It's a mix of white noise waves, each halving in frequency, so you can generate a white noise wave every frame, another a second every other frame, a third every 4th frame etc. Then add them up. It makes a pattern like this:

This is the The Voss-McCartney algorithm, as detailed here: https://www.firstpr.com.au/dsp/pink-noise/ (in the vast course of history, this will be a dead link, so I won't link to it).

But, it's flawed. The pattern looks symmetrical but the x in the middle shows that there are an ODD number of intervals to the pattern, so how can you have a regular degree of switching? Consider a wave every frame, then every 2, 4, 8... 1+2+4+8=15 not 16... if you repeat the 15 then some events will be closer than others. The implementations on that page seem to ignore this and use 16 steps, yet this means that the slowest step must repeat twice...

Anyway. I made the generator. Here is my code:

lword offsets[16]={2,3,2,4,2,3,2,5,2,3,2,4,2,3,2,6};
float out;
// Generate one sample of noise...
// Counter, cycle zero to 15
longutility[0]++;
longutility[0]&=15;
// Generate a random number -1 to 1
seed=seed*196314165+907633515;
// floatutility[1] changes every time.
floatutility[1]=0.00002f*(seed%100000)-1;
// Generate alternative noise
seed=seed*196314165+907633515;
floatutility[offsets[longutility[0]]]=0.00002f*(seed%100000)-1;
out=(floatutility[1]+floatutility[2]+floatutility[3]+floatutility[4]+floatutility[5]+floatutility[6])/6;
// Result
dataleft+=out*parm[0];
dataright+=out*parm[0];

parm[0] is the volume, the 'utility' variables should be obvious. I cheated by using the lookup table, but the list of offsets there illustrate the problem above - '5' and '6' are repeated just once each.

Anyway, I realised that my 'Grey Wave' plugin can do this anyway! So I didn't use this at all, but it was a distraction from my limiting.

Then I tried limiting again, I used my normal 'Gothic' Limiter, which does nothing to any signal until it gets over 'ceiling' then chops it short:

Even for this extreme wave, it works ok. It sounds a bit buzzy, but not that bad. Audio engineers with headphones would hear it, but 90% of listeners wouldn't even notice. It's certainly better than hard limiting, but it wasn't designed for harsh conditions like this anyway. This is a test.

I thought that I'd try to smooth it by interpolating it with a smoother result, and it worked! Here's the new version, my 'Glass Limiter'. Sounds as good as the original... nearly... the very fact that it's this loud makes it sound a bit odd...

One odd thing is that line at the bottom, dangling in the middle like a thread. I noticed this phenomenon on a Björk track, which as you can see is hyper-squashed:

Maybe I'm on the right track then. The Björk track is too loud and too squashed, which is so very sad. What should be gentle and lovely music is ear-wobbling noise, even when the melodies and instruments are actually soft. It sounds distorted in a different way. The very lack of dynamic range, the ear-blast of constancy, has harmed the musical quality. All modern music seems to suffer from this, it makes my cry, as well as inducing a headache.

My experiments are done. I must rest, pause, forget about programming.