music.note_with_doppler

music.note_with_doppler(freq=220, duration=2, waveform_table=array([-1., -0.99975586, -0.99951172, ..., -0.99926758, -0.99951172, -0.99975586], shape=(16384,)), x=(-10, 10), y=(1, 1), stereo=True, zeta=0.215, air_temp=20, number_of_samples=None, sample_rate=None)[source]

A simple note with a transition of localization and resulting Doppler effect.

Parameters:
freqscalar

The frequency of the note in Hertz.

durationscalar

The duration of the note in seconds.

waveform_tablearray_like

The table with the waveform to synthesize the sound.

xiterable of scalars

The starting and ending x positions.

yiterable of scalars

The starting and ending y positions.

stereobool

If True, return two channels with the initial interaural delay represented by zero padding. Otherwise return a mono array.

zetafloat

The distance between the listener’s ears in meters. It is used to compute interaural differences when generating stereo output.

air_tempscalar

The air temperature in Celsius. (Used to calculate the acoustic velocity.)

number_of_samplesinteger or None

The number of source samples; if given, duration is ignored, and zero is no samples. Stereo output additionally includes the initial delay padding.

sample_rateinteger or None

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

Returns:
sndarray

The PCM samples of the resulting sound.

Raises:
ValueError

If zeta is negative: it is the distance between the ears, and below zero the interaural delay reached numpy as an array of negative length.

See also

note_with_vibrato_seq_localization

a note with arbitrary vibratos, transitions of pitch and transitions of localization.

note_with_vibratos_glissandos

a note with an arbitrary sequence of pitch transition and a meta-vibrato.

Notes

The source moves in a straight line from \((x_0, y_0)\) to \((x_1, y_1)\) over the note. At each sample its distance \(d_i\) from an ear, and the speed \(s_i = f_s (d_{i+1} - d_i)\) at which that distance grows, set the frequency heard there, by the article’s eq:fDoppler with the listener still, and the amplitude, by the inverse distance [1]:

\[f_i = \frac{c}{c + s_i} \, f, \qquad a_i = \frac{1}{d_i},\]

with \(c = 331.3 + 0.606\,T\) m/s the speed of sound at air_temp \(T\). The note’s table is read where the \(f_i\) accumulate, as note_with_glissando() reads it. In stereo each ear is computed apart, zeta meters from the other, and the farther one starts later by the delay between them at the start; in mono the distance is from the centre of the head.

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_stereo(note_with_doppler())
>>> write_wav_mono(tremolo()*note_with_doppler(stereo=False))