music.loud¶
- music.loud(duration=2, trans_dev=10, alpha=1, to=True, method='exp', number_of_samples=0, sonic_vector=0, sample_rate=44100)[source]¶
An envelope for a linear or exponential transition of amplitude.
An exponential transition of loudness yields a linear transition of loudness (theoretically).
- Parameters:
- durationscalar
The duration of the envelope in seconds.
- trans_devscalar
The deviation of the transition. If method=”exp”, the deviation is in decibels. If method=”linear”, the deviation is an amplitude proportion.
- alphascalar
An index to make the transition slower or faster [1]. Ignored if method=”linear”.
- tobool
If True, the transition ends at the deviation. If False, the transition starts at the deviation.
- method
str “exp” for an exponential transitions of amplitude (linear loudness). “linear” for a linear transition of amplitude.
- number_of_samples
integer The number of samples of the envelope. If supplied, d is ignored.
- sonic_vectorarray_like
Samples for the envelope to be applied to. If supplied, d and nsamples are ignored.
- sample_rate
integer The sample rate. Only used if nsamples and sonic_vector are not supplied.
- Returns:
- e
ndarray A numpy array where each value is a value of the envelope for the PCM samples. If sonic_vector is supplied, e is the sonic vector with the envelope applied to it.
- e
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() * loud()) >>> s = horizontal_stack([note_with_vibrato() * ... loud(trans_dev=i, method=j) ... for i, j in zip([6, -50, 2.3], ... ["exp", "exp", "linear"])]) >>> s = horizontal_stack([ ... loud(trans_dev=i, method=j, sonic_vector=note_with_vibrato()) ... for i, j in zip([6, -50, 2.3], ["exp", "exp", "linear"])]) >>> envelope = loud(duration=10, trans_dev=-80, to=False, alpha=2)