↵ Noise Generator


Noisegen is a simple audio noise generator I have made that makes use of leaky integration.


Download

The source code can be found here.


Usage

Usage: noisegen [OPTION]... FILE
Generates audio noise using leaky integration and stores the result in WAV format.
Example: noisegen --duration 30.0 --order 5 --leak 0.98 output.wav

Options:
  -h, --help               Display this help dialog and exit

  -t, --duration SECONDS   The duration of the output in seconds (float between 0 and 20,000, default: 10.0)

  -n, --order N            The order of integration of the noise (non-negative integer, default: 1)
                           E.g. white noise = 0, brown noise = 1

  -l, --leak FACTOR        The leak factor of the leaky integrator (float between 0.0 and 1.0, default: 0.99)

How it works

To begin, the program generates white noise, which is generated by randomising each sample individually.

The white noise is then integrated using a leaky integrator. A leaky integrator refers to a system that accumulates an input over time, but gradually leaks some of that accumulated value.

A leaky integrator can be modelled by the following equation:

$$ dx/dt = -Ax + C $$

where \(A\) is the rate of leakage and \(C\) is the input.

So when generating our noise, we pass the white noise as our input (\(C\)), and a constant as the rate of leakage (\(A\)). The leaky integrator gives us a gradient, which we can then use as the gradient of our generated noise.

In code

To make this work in code I’ve modelled the integration as this expression which runs for each sample:

integrated_noise = integrated_noise*leak_factor + input_noise*(1-leak_factor)

Here, leak_factor is essentially \(1-A\) and input_noise*(1-leak_factor) is \(C\).

The reason I multiply the input by (1-leak_factor) is so that the amplitude of the integrated noise can never exceed the max value of input, which helps to keep the values within a certain range.

Result of single integration

Integrating the white noise like this results in brown noise (a.k.a red noise), although for it to truly be considered so, the value of leak_factor has to be very close to 1 (e.g. 0.999), otherwise the sound will start to sound like white noise. It also cannot be too close because that may lead to audible quantising.

For other colours of noise, generation usually involves Fourier-transforming the white noise, and then modifying the amplitudes of the different frequency components.

Note that this method can also be used to create brown noise.

This makes brown noise quite special among the other colours of noise, being the only one to use integration.

Many integrations

However, brown noise only involves a single integration (of the white noise). That’s why for my noise generator, I thought it would be interesting to allow for orders of integration greater than 1.

To do this, the program takes the output of the first integration (brown noise) and then uses it as the input for the next (using the same leak factor as before). This can be done as many times as wanted (however there is a cutoff for good results).


Examples

Here are some examples of noise you can create with the program.

White noise

noisegen --order 0 white_raw.wav

# decrease volume (white noise is very harsh) 
ffmpeg -i white_raw.wav -af "volume=0.1" white.wav

Brown noise

noisegen --order 1 --leak 0.999 brown.wav

Order 2, Leak 0.99

noisegen --order 2 --leak 0.99 2-099.wav

Order 4, Leak 0.99

noisegen --order 4 --leak 0.99 4-099.wav

Order 3, Leak 0.9

noisegen --order 3 --leak 0.9 3-09.wav

Order 10, Leak 0.9

noisegen --order 10 --leak 0.9 10-09.wav

Order 30, Leak 0.9

noisegen --order 30 --leak 0.9 30-09.wav