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.

methodstr

“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_samplesinteger

The number of samples of the fade. If supplied, d is ignored.

sonic_vectorarray_like

Samples for the fade to be applied to. If supplied, d and nsamples are ignored.

sample_rateinteger

The sample rate. Only used if number_of_samples and sonic_vector are not supplied.

Returns:
aindarray

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.

See also

adsr

An ADSR envelope.

loud

A transition of loudness.

louds

An envelope with an arbitrary number or loudness transitions.

tremolo

An oscillation of loudness.

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=V())
...                       for i, j in zip([1, 0, 1],
...                                       ["exp", "exp", "linear"])])
>>> envelope = fade(duration=10, fade_out=0, perc=0.1)