music.fade¶
- music.fade(duration=2, fade_out=True, method='exp', db=-80, alpha=1, perc=1, number_of_samples=0, sonic_vector=0, sample_rate=44100)[source]¶
A fade in or out.
Implements the loudness transition and asserts that it reaches zero amplitude.
- Parameters:
- durationscalar
The duration in seconds of the fade.
- fade_outbool
If True, the fade is a fade out, else it is a fade in.
- method
str “exp” for an exponential transition of amplitude (linear loudness). “linear” for a linear transition of amplitude.
- dbscalar
The decibels from which to reach before using the linear transition to reach zero. Not used if method=”linear”.
- alphascalar
An index to make the exponential fade slower or faster [1]. Ignored if transitions=”linear”.
- percscalar
The percentage of the fade that is linear to ensure it reaches zero. It has no effect if method=”linear”.
- number_of_samples
integer The number of samples of the fade. If supplied, duration is ignored.
- sonic_vectorarray_like
Samples for the fade to be applied to. If supplied, duration and number_of_samples are ignored.
- sample_rate
integer The sample rate. Only used if number_of_samples and sonic_vector are not supplied.
- Returns:
- ai
ndarray Each value is a value of the envelope for the PCM samples. If sonic_vector is input, ai is the sonic vector with the fade applied to it.
- ai
- Raises:
ValueErrorIf
percis outside [0, 100], or ifmethodnames neither “lin” nor “exp”. A percentage over 100 used to reach anIndexErrorfrom inside the routine, and an unknown method anUnboundLocalError, neither of which says what the caller did.
See also
Notes
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
>>> write_wav_mono(note_with_vibrato() * fade()) >>> s = horizontal_stack(*[note_with_vibrato() * fade(fade_out=i, method=j) ... for i, j in zip([1, 0, 1], ... ["exp", "exp", "linear"])]) >>> s = horizontal_stack( ... *[fade(fade_out=i, method=j, sonic_vector=note_with_vibrato()) ... for i, j in zip([1, 0, 1], ... ["exp", "exp", "linear"])]) >>> envelope = fade(duration=10, fade_out=0, perc=0.1)