music.adsr¶
- music.adsr(envelope_duration=2, attack_duration=20, decay_duration=20, sustain_level=-5, release_duration=50, transition='exp', alpha=1, db_dev=-80, to_zero=1, number_of_samples=0, sonic_vector=0, sample_rate=44100)[source]¶
Synthesize an ADSR envelope.
ADSR (Atack, Decay, Sustain, Release) is a very traditional loudness envelope in sound synthesis [1].
- Parameters:
- envelope_durationscalar
The duration of the envelope in seconds.
- attack_durationscalar
The duration of the Attack in milliseconds.
- decay_durationscalar
The duration of the Decay in milliseconds.
- sustain_levelscalar
The Sustain level after the Decay in decibels. Usually negative.
- release_durationscalar
The duration of the Release in milliseconds.
- transition
str “exp” for exponential transitions of amplitude (linear loudness). “linear” for linear transitions of amplitude.
- alphascalar or array_like
An index to make the exponential fade slower or faster [1]. Ignored it transitions=”linear” or alpha=1. If it is an array_like, it should hold three values to be used in Attack, Decay and Release.
- db_devscalar or array_like
The decibels deviation to reach before using a linear fade to reach zero amplitude. If it is an array_like, it should hold two values, one for Attack and another for Release. Ignored if trans=”linear”.
- to_zeroscalar or array_like
The duration in milliseconds for linearly departing from zero in the Attack and reaching the value of zero at the end of the Release. If it is an array_like, it should hold two values, one for Attack and another for Release. It’s ignored if trans=”linear”.
- number_of_samples
integer The number of samples of the envelope. If supplied, d is ignored.
- sonic_vectorarray_like
Samples for the ADSR envelope to be applied to. If supplied, d and nsamples are ignored.
- sample_rate
integer The sample rate.
- Returns:
- as
ndarray A numpy array where each value is a value of the envelope for the PCM samples if sonic_vector is 0. If sonic_vector is input, ad is the sonic vector with the ADSR envelope applied to it.
- as
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() * adsr()) >>> s = horizontal_stack([note_with_vibrato() * ... adsr(attack_duration=i, release_duration=j) ... for i, j in zip([6, 50, 300], [100, 10, 200])]) >>> s = horizontal_stack([adsr(A=i, R=j, sonic_vector=note_with_vibrato()) ... for i, j in zip([6, 15, 100], [2, 2, 20])]) >>> envelope = adsr(d=440, A=10e3, D=0, R=5e3)