music.gaussian_noise

music.gaussian_noise(mean=1, std=0.5, duration=2, sample_rate=None, number_of_samples=None, seed=None)[source]

Synth gaussian noise

Parameters:
meanint, optional

The centre of the band the noise occupies, in units of 3000 Hz, by default 1 – so 3000 Hz.

stdfloat, optional

The width of that band, in the same units, by default 0.5 – so 1500 Hz wide, running from 2250 to 3750 Hz.

These name a band rather than a distribution, despite the routine’s name and theirs. What is Gaussian here is the shape of the samples that come out, which is what a sum of many random-phase partials tends to; the samples’ own mean and standard deviation are set by the normalization at the end and have nothing to do with these two. A band reaching below 0 Hz is read as the positive part of itself.

durationint, optional

How long in seconds will the noise be, by default 2

sample_rateint or None, optional

The sample rate to use. None, the default, is the rate music.get_sample_rate() returns.

number_of_samplesinteger or None

The number of samples, as noise() takes it: if given, duration is ignored, and zero is no samples.

seedinteger or None

A seed for the random phases, as noise() takes it: the same seed draws the same noise again. None, the default, draws from NumPy’s global random state.

Returns:
array

An array for the gaussian noise

Raises:
ValueError

If std is not positive, or mean and std name a band that holds no frequency at the resolution the length gives, between 0 Hz and the Nyquist frequency. A band of no width zeroed every coefficient, and normalizing an all-zero spectrum divides by its own zero range: the caller got an array of NaN behind a warning. A duration too short to hold a sample is not refused – it renders nothing, as everything here does. Also if sample_rate is not positive, or seed is not a whole number in [0, 2**64).

Parameters:
Return type:

NDArray[float64]

Notes

The band includes both of its ends, as noise()’s does, and stops at the Nyquist frequency. It used to be zeroed after the spectrum was mirrored, so a band reaching past the Nyquist frequency kept some mirrored components: those frequencies came out at twice the level of the rest.

Examples

>>> grains = gaussian_noise(mean=1, std=0.5, duration=0.5)
>>> len(grains)
22050
>>> gaussian_noise(duration=0.3).shape       # a fractional duration
(13230,)