music.am

music.am(duration=2, fm=50, max_amplitude=0.4, waveform_table=array([0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835], shape=(16384,)), number_of_samples=None, sonic_vector=0, sample_rate=None)[source]

Synthesize an AM envelope or apply it to a sound.

Set fm=0 or max_amplitude=0 for a constant envelope with value 1. An AM is a linear oscillatory pattern of amplitude [1].

Parameters:
durationscalar

The duration of the envelope in seconds.

fmscalar

The frequency of the modulation in Hertz.

max_amplitudescalar

The maximum deviation of amplitude of the AM.

waveform_tablearray_like

The table with the waveform for the AM oscillatory pattern.

number_of_samplesinteger or None

The number of samples of the envelope. If given, duration is ignored, and zero is an envelope of no samples.

sonic_vectorarray_like

Samples for the modulation to be applied to. If supplied, duration and number_of_samples are ignored. Mono, or of shape (nchannels, nsamples), every channel shaped alike.

sample_rateinteger or None

The sample rate. None, the default, is the rate music.get_sample_rate() returns.

Returns:
tndarray

A numpy array where each value is a PCM sample of the envelope. If sonic_vectoris input, T is the sonic vector with the AM applied to it.

See also

note_with_vibrato

A musical note with an oscillation of pitch.

note_with_fm

A linear oscillation of fundamental frequency.

tremolo

A tremolo, an oscillation of loudness.

Notes

The modulator is read from its table as a vibrato’s pattern is, and it scales the amplitude linearly, as the article writes AM [1]:

\[a_i = 1 + \alpha \, t'_i, \qquad t'_i = \tilde{m}_{\gamma'_i \bmod \tilde{\Lambda}_M}, \qquad \gamma'_i = \left\lfloor i f' \frac{\tilde{\Lambda}_M}{f_s} \right\rfloor,\]

where \(\tilde{m}\) is waveform_table, \(f'\) is fm and \(\alpha\) is max_amplitude. Given a sonic_vector \(t\), it returns \(t_i a_i\), and a sinusoidal carrier at \(f\) comes out with one sideband each side of it, at \(f \pm f'\) (eq:specAM). tremolo() oscillates the level in decibels instead.

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() * am())  # a note with AM
>>> s = horizontal_stack(
...     *[note_with_vibrato() * am(fm=i, max_amplitude=j)
...      for i, j in zip([60, 150, 100],
... [2, 1, 20])])
>>> s = horizontal_stack(
...     *[am(fm=i, max_amplitude=j, sonic_vector=note_with_vibrato())
...      for i, j in zip([60, 150, 100],
... [2, 1, 20])])
>>> envelope2 = am(440, 150, 60)  # a lengthy envelope