music.note_with_fm¶
- music.note_with_fm(freq=220, duration=2, fm=100, max_fm_deviation=2, waveform_table=array([-1., -0.99975586, -0.99951172, ..., -0.99926758, -0.99951172, -0.99975586], shape=(16384,)), fm_waveform_table=array([0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835], shape=(16384,)), number_of_samples=None, sample_rate=None)[source]¶
Synthesize a musical note with FM synthesis.
Set fm=0 or max_fm_deviation=0 (or use synth_note()) for a note without FM. A FM is a linear oscillatory pattern of frequency [1].
- Parameters:
- freqscalar
The frequency of the note in Hertz.
- durationscalar
The duration of the note in seconds.
- fmscalar
The frequency of the modulator in Hertz.
- max_fm_deviationscalar
The maximum deviation of frequency in the modulator in Hertz.
- waveform_tablearray_like
The table with the waveform for the carrier.
- fm_waveform_tablearray_like
The table with the waveform for the modulator.
- number_of_samples
integerorNone The number of samples in the sound. If given, duration is ignored, and zero is no samples.
- sample_rate
integerorNone The sample rate. None, the default, is the rate
music.get_sample_rate()returns.
- Returns:
- result
ndarray A numpy array where each value is a PCM sample of the note.
- result
- Parameters:
- Return type:
NDArray[float64]
See also
noteA basic musical note without vibrato.
note_with_vibratoA musical note with an oscillation of pitch.
tremoloA tremolo, an oscillation of loudness.
amA linear oscillation of amplitude (not linear loudness).
Notes
The modulator is read from its table as a vibrato’s pattern is, and it moves the carrier’s frequency by up to \(\mu\) Hertz either way, as the article writes FM [1]:
\[ \begin{align}\begin{aligned}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,\\f_i = f + \mu \, t'_i, \qquad t_i = \tilde{l}_{\gamma_i \bmod \tilde{\Lambda}}, \qquad \gamma_i = \left\lfloor \sum_{j=0}^{i} f_j \frac{\tilde{\Lambda}}{f_s} \right\rfloor,\end{aligned}\end{align} \]where \(\tilde{m}\) is fm_waveform_table, \(f'\) is fm, \(\mu\) is max_fm_deviation and \(f\) is freq. The deviation is in Hertz, where a vibrato’s is in semitones: this is the linear modulation whose spectrum the article expands into sidebands at \(f \pm k f'\), weighted by Bessel functions of the index \(\mu / f'\) (
eq:fmEsp).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_fm()) # writes a WAV file of a note >>> sonic_vector = horizontal_stack( ... *[note_with_fm(i, j) for i, j in zip([200, 500, 100], ... [2, 1, 2])]) >>> s2 = note_with_fm(440, 1.5, 600, 10)