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.

methodstr

“exp” for an exponential transitions of amplitude (linear loudness). “linear” for a linear transition of amplitude.

number_of_samplesinteger

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_rateinteger

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

Returns:
endarray

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.

See also

louds

An envelope with an arbitrary number of transitions.

fade

Fade in and out.

adsr

An ADSR envelope.

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() * 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)