music.note_with_phase¶
- music.note_with_phase(freq=220, duration=2, phase=0, waveform_table=array([-1., -0.99975586, -0.99951172, ..., -0.99926758, -0.99951172, -0.99975586], shape=(16384,)), number_of_samples=None, sample_rate=None)[source]¶
Synthesize a basic musical note with a phase.
It’s useful in more complex synthesis routines. For synthesizing a musical note directly, you probably want to use note() and disconsider the phase.
- Parameters:
- freqscalar
The frequency of the note in Hertz.
- durationscalar
The duration of the note in seconds.
- phasescalar
The phase of the wave in radians.
- waveform_tablearray_like
The table with the waveform to synthesize the sound.
- 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 note.
note_with_vibratoA note with vibrato.
tremoloA tremolo envelope.
Notes
note(), with the table read from a point the phase \(\phi\), in radians, puts a fraction \(\phi / 2\pi\) of the way through it [1]:\[t_i = \tilde{l}_{\gamma_i \bmod \tilde{\Lambda}}, \qquad \gamma_i = \left\lfloor \frac{\phi \tilde{\Lambda}}{2 \pi} + i f \frac{\tilde{\Lambda}}{f_s} \right\rfloor .\]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_phase()) # writes a WAV file of a note >>> s = horizontal_stack( ... *[note_with_phase(i, j) for i, j in zip([200, 500, 100], ... [2, 1, 2])]) >>> s2 = note_with_phase(440, 1.5, waveform_table=WAVEFORM_SAWTOOTH)