music.noise¶
- music.noise(noise_type='brown', duration=2, min_freq=15, max_freq=15000, number_of_samples=0, sample_rate=44100, seed=None)[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. A component exactly at it is kept.
- max_freqscalar
in[0, fs/2] The highest frequency allowed, kept too if a component falls exactly on it. 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.
- seed
integerorNone Optional deterministic seed for local random phases. Default None preserves legacy use of NumPy’s global random state.
- noise_type
- Returns:
ndarrayA mono sequence of PCM samples, normalized to [-1, 1].
- Raises:
ValueErrorIf
noise_typeis neither a finite number of decibels per octave nor one of the named colours, ifsample_rateis not positive, or if the band is empty:min_freqabovemax_freqor above the Nyquist frequency. A misspelt colour would otherwise render as silence or as an unrelated slope, a slope of NaN as NaN, and an empty band as silence.
- 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
The components are the multiples of that resolution from
min_freqtomax_freq, both included. The band used to be rounded down at both ends, which let in a component belowmin_freqwhenever it fell between two, and always left out one atmax_freq. A noise too short to hold any component in the band is silence.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