music.noise¶
- music.noise(noise_type='brown', duration=2, min_freq=15, max_freq=15000, number_of_samples=0, sample_rate=44100)[source]¶
Return a colored or user-refined noise.
- Parameters:
- noise_type
stror scalar Specifies the decibels gain or attenuation per octave. It can be specified numerically (e.g. ntype=3.5 is 3.5 decibels gain per octave) or by strings: - “brown” is -6dB/octave - “pink” is -3dB/octave - “white” is 0dB/octave - “blue” is 3dB/octave - “violet” is 6dB/octave - “black” is -12/dB/octave but, in theory, is any < -6dB/octave See [1] for more information.
- durationscalar
The duration of the noise in seconds.
- min_freqscalar
in[0, fs/2] The lowest frequency allowed.
- max_freqscalar
in[0, fs/2] The highest frequency allowed. It should be > fmin.
- number_of_samples
integer The number of samples of the resulting sonic vector.
- sample_rate
integer The sample rate to use, by default 44100.
- noise_type
- Returns:
ndarrayA mono sequence of PCM samples, normalized to [-1, 1].
- Raises:
ValueErrorIf
noise_typeis neither a number of decibels per octave nor one of the named colours. A misspelt colour would otherwise render as silence or as an unrelated slope.
- Parameters:
- Return type:
NDArray[float64]
Notes
The noise is synthesized with components with random phases, with the moduli that are related to the decibels/octave, and with a frequency resolution of fs / nsamples = fs / (fs*d) = 1/d Hz
Cite the following article whenever you use this function.
References
[1]Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
Examples
>>> hiss = noise("white", duration=0.5) # flat, 0 dB per octave >>> len(hiss) 22050 >>> darker = noise("brown", duration=0.5) # -6 dB per octave >>> tilted = noise(-9, duration=0.5) # or any slope you name