music.localize¶
- music.localize(sonic_vector=None, theta=0, distance=0, x=0.1, y=0.01, zeta=0.215, air_temp=20, sample_rate=44100)[source]¶
Make a mono sound stereo and localize it by a very naive method.
See bellow for implementation notes.
- Parameters:
- sonic_vectorarray_like
An one dimensional with the PCM samples of the sound.
- xscalar
The lateral component of the position in meters.
- yscalar
The frontal component of the position in meters.
- thetascalar
The azimuthal angle of the position in degrees. If theta is supplied, x and y are ignored and dist must also be supplied for the sound localization to have effect.
- distancescalar
The distance of the source from the listener in meters.
- zetascalar
The distance between the ears in meters.
- air_tempscalar
The temperature in Celsius used for calculating the speed of sound.
- sample_rate
integer The sample rate.
- Returns:
- s
ndarray A (2, nsamples) shaped array with the PCM samples of the stereo sound.
- s
Notes
A Head Related Transfer Function would localize more convincingly than either this or localize2; none is implemented yet.
Uses the most naive ITD and IID calculations as described in [1]. A less naive method is implemented in localize2(). Nonetheless, if dist is small enough (e.g. <.3), the perception of theta occurs and might be used. The advantages of this method are:
It is fast.
It is simple.
It is true to sound propagation phenomenon (although it does not consider the human body beyond the localization of the ears).
It can be used easily for tweaks (such as for a moving source resulting in a Doppler Effect).
When az = tan^{-1}(y/x) lies in the ‘cone of confusion’, many values of x and y have the same ITD and IID [1]. Furthermore, lateral sources have the low frequencies diffracted and reach the opposite ear with a delay of ~0.7s [1]. The height of a source and if it is in front or behind a listener are cues given by the HRTF [1]. These issues are not taken into account in this function.
The value of zeta is ~0.215 for adult humans [1].
This implementation assumes that the speed of sound (in air) is s = 331.2 + 0.606 * temp.
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(localize()) >>> write_wav_stereo(horizontal_stack([ ... localize(note_with_vibrato(duration=1), x=i, y=j) ... for i, j in zip([.1, .7, np.pi - .1, np.pi - .7], ... [.1, .1, .1, .1])]))