Pink noise generator

Hi everyone,
In the tutorial:Tutorial: Build a white noise generator, it generates white noise signal in real time.How could generate pink noise signal in real time in this way?

 void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
    for (auto channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
    // Get a pointer to the start sample in the buffer for this audio output channel
    auto* buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);

    // Fill the required number of samples with noise between -0.125 and +0.125
    for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
        buffer[sample] = random.nextFloat() * 0.25f - 0.125f;


Best regards!

there are several different methods.

you can approximate a -3db/octave “pinking filter” using an FIR, as shown in this snippet posted by paul kellet on

Filter to make pink noise from white  (updated March 2000)

This is an approximation to a -10dB/decade filter using a weighted sum
of first order filters. It is accurate to within +/-0.05dB above 9.2Hz 
(44100Hz sampling rate). Unity gain is at Nyquist, but can be adjusted
by scaling the numbers at the end of each line.

If 'white' consists of uniform random numbers, such as those generated
by the rand() function, 'pink' will have an almost gaussian level 

  b0 = 0.99886 * b0 + white * 0.0555179;
  b1 = 0.99332 * b1 + white * 0.0750759;
  b2 = 0.96900 * b2 + white * 0.1538520;
  b3 = 0.86650 * b3 + white * 0.3104856;
  b4 = 0.55000 * b4 + white * 0.5329522;
  b5 = -0.7616 * b5 - white * 0.0168980;
  pink = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
  b6 = white * 0.115926;

An 'economy' version with accuracy of +/-0.5dB is also available.

  b0 = 0.99765 * b0 + white * 0.0990460;
  b1 = 0.96300 * b1 + white * 0.2965164;
  b2 = 0.57000 * b2 + white * 1.0526913;
  pink = b0 + b1 + b2 + white * 0.1848;


and there is the “voss” or “gardner/voss” or “voss/mccartney” algorithm, which involves summing white noise generated at successively lower octaves. (mccartney’s innovation was to stagger the calculation of each octave, making the CPU load constant.) Robin Whittle has a good overview of these methods here.

this method from stefan stenzel innovates on the white-noise-octaves structure by upsampling the octaves with linear interpolation, in a highly efficient implementation. to my ears, the results are excellent. (downside is that it is a little harder to grok what is actually going on - at least for me.)


Thank you !!!

Any specific reason you properly capitalize all names but mine ?

Anyway, I once wrote a description that is still online:

Only the Web Audio is so outdated that it is no longer working.

But seems you are not targeted, Paul Kellet faces the same fate… :wink:

1 Like

nope! here, i’ve updated the post for consistency. :slight_smile:

(i think i added caps because “mccartney” looked strange otherwise.)

anyways, many thanks for sharing your algorithm. my comment about the opacity of the implementation was more about the heavy use of bitwise operations on floats, macros, that sort of thing; not a criticism of the writeup which is very clear!

It might be easier to first look at the integer version without float hacks, basically just 10 lines of code where it all happens.

1 Like