# Are there equations for placing sounds in the stereo field using delays?

I'm thinking of the typical stereo widener (haas, binaural) effects here, those that extend from the typical pan knob to create "out of the headphones" -experience.

These processors can be automated to move sounds around, but I was wondering whether there was mathematics that described how to set the delays in order to move the sound into a certain spot in an angle -like fashion.

Such as in this plug-in: What about modelling the "distance" from the listener?

• Do you just want attenuation and delay, or do you want the full binaural pinna reflections? – endolith Dec 21 '15 at 22:34
• @endolith Whatever effect that creates "more" than mere pan knob. But I want to be able to dictate the position in angles (calculated from the listener position). Like here: noisemakers.fr/wp-content/uploads/2015/09/BinauGUI_V3_web.jpg – mavavilj Dec 22 '15 at 4:52
• Both of the things I said do that – endolith Dec 22 '15 at 5:02
• @endolith I don't care which algorithm it's really (expect that it's good of course). I care that it has an "angle" parameter and how it's been defined. If all algorithms have, then it's even better in the sense of the question. – mavavilj Dec 22 '15 at 10:12
• Well the picture you posted says binaural so you need to model the reflections off the ears in that case – endolith Dec 22 '15 at 12:39

For a spherical head with the ears at opposite points on its surface, a planar wave from a distant sound source reaches an ear on a straight line through air or if blocked by the head then partially through the shortest path along the surface of the sphere. If the sound source is at the same vertical coordinate $z$ as the ears, we can think of the head as a circle on the $x, y$ plane: For simplicity, the head is a unit circle centered at $x = 0, y = 1$, turned so that the nose moves by an angle $\alpha$ counterclockwise from the origin. We are looking for the distances the sound still has to travel after the planar wavefront first reaches the head. There is a shortest straight line path (red dashed) of length $1-\sin(\alpha)$ to the right (red) ear. The shortest path (white dashed) to the left (white) ear consists of a straight line segment of length $1$ plus a curved path of length $\alpha$. The difference between the lengths to the two ears is $\alpha + 1 - (1 - \sin(\alpha)) = \sin(\alpha) + \alpha$. This holds for $0 \le \alpha \le \frac{\pi}{2}$, but because the function is antisymmetrical, it applies also to $-\frac{\pi}{2} \le \alpha \le 0$ giving a negative value for that range. Modifying the equation to include the speed of sound $c$ and the head radius $r$, the inter-aural time difference (ITD) turns out as:

$$\text{ITD}(\alpha) = \frac{r}{c} (\sin(\alpha) + \alpha)$$

The formula is applicable for angles $-\frac{\pi}{2} \le \alpha \le \frac{\pi}{2}$, where $\alpha = 0$ means the source is straight ahead and $\alpha = \frac{\pi}{2}$ means it is 90° to the right, if the left channel is delayed for positive ITD. The plotted $\sin(\alpha) + \alpha$ part swings from $-\frac{\pi}{2} - 1$ to $\frac{\pi}{2} + 1$, so for a realistic maximum ITD of 0.6 ms (for distant sources) one can use simply:

$$\text{ITD}(\alpha) = \frac{0.6\ \text{ms}}{\frac{\pi}{2} + 1} (\sin(\alpha) + \alpha) \approx 0.23\ \text{ms}\ (\sin(\alpha) + \alpha)$$

For sources that are behind, before using the formula, add or subtract $\pi$ to/from $\alpha$ to bring it to $-\frac{\pi}{2}\ldots\frac{\pi}{2}$ and flip its sign.

If one wants to take into account the distance to the source, the wavefront becomes spherical, or circular on the $x, y$ plane. Let's look at a head with just one ear considered: The head is again a unit circle, but this time centered at the origin. The source (blue) is on the negative $y$ axis at a distance $d$ from the center of the head. The ear (red) is rotated by an angle $\alpha$ counterclockwise from the positive $x$ axis, or clockwise if $\alpha$ is negative. We shall constrain $-\frac{\pi}{2} \le \alpha \le \frac{\pi}{2}$ so that the shortest air path to the ear is always via the right side of the head as pictured. At the time the sound first reaches the head, the wavefront (blue) is cicular with radius $d-1$. We don't need that for the calculations, because we can use the time the sound leaves the source as the starting point. There is some negative angle $\beta$ such that if $\alpha \le \beta$, there is a direct air path of length $\sqrt{\cos(\alpha)^2 + \left(d + \sin(\alpha)\right)^2}$ to the ear located at $x = \cos(\alpha)$, $y = \sin(\alpha)$. Otherwise the sound travels a distance $D = \sqrt{\cos(\beta)^2 + \left(d + \sin(\beta)\right)^2}$ to the point $x = \cos(\beta)$, $y = \sin(\beta)$ where the straight path and the circle meet tangentially, and transitions to a further curved path of length $\alpha-\beta$. There is a right triangle (pink) that enables to solve $\beta$ using the pythagorean theorem:

$$d^2 = D^2 + 1^2\\ \Rightarrow \beta = - \text{asin}(\frac{1}{d}),\ D = \sqrt{d^2-1}$$

To recap, modifying the equations to include head radius $r$ and speed of sound $c$:

$$-\frac{\pi}{2} \le \alpha \le \frac{\pi}{2},\\ T_l = \left\{\begin{array}{ll}\frac{r}{c}\sqrt{\cos(\alpha)^2 + \left(\frac{d}{r} + \sin(\alpha)\right)^2}&\text{if } \alpha \le - \text{asin}(\frac{r}{d}),\\ \frac{r}{c}\left(\sqrt{(\frac{d}{r})^2-1} + \alpha + \text{asin}(\frac{r}{d})\right)&\text{otherwise,}\end{array}\right.\\ T_r = \left\{\begin{array}{ll}\frac{r}{c}\sqrt{\cos(\alpha)^2 + \left(\frac{d}{r} - \sin(\alpha)\right)^2}&\text{if } \alpha \geq \text{asin}(\frac{r}{d}),\\ \frac{r}{c}\left(\sqrt{(\frac{d}{r})^2-1} - \alpha + \text{asin}(\frac{r}{d})\right)&\text{otherwise,}\end{array}\right.\\ \text{ITD}(\alpha) = T_l(\alpha) - T_r(\alpha)$$

Again, for sources that are behind, before using the formula, add or subtract $\pi$ to/from $\alpha$ to bring it to $-\frac{\pi}{2}\ldots\frac{\pi}{2}$ and flip its sign.

For increasing distances, this definition of ITD approaches the previous one: • Any idea where to find the derivation of the ITD equation? I'm trying to understand why its that way. – mavavilj Dec 22 '15 at 6:21
• I added the derivation to the answer. The 0.6 ms value is from experimental data. – Olli Niemitalo Dec 22 '15 at 9:13
• What algorithm is this called? That uses the ITD? – mavavilj Dec 22 '15 at 10:53
• Some call this the spherical-head model. What do you mean use ITD? This is a way to estimate it. – Olli Niemitalo Dec 23 '15 at 8:36
• i thought Blumlein defined the ITD without any head, just two omnidirectional ears that were spaced about 15 cm from each other. the ITD was a function of that spacing and the angle of incidence of the wavefront. – robert bristow-johnson Dec 24 '15 at 3:52

Typically simplistic models for don't work very well and don't result in externalization (out of head localization). The diffraction effects are quite complicated and at higher frequencies the details pinna (ear lobes) and shoulder reflections are quite relevant. Interaural time and level differences are also highly frequency dependent.

It's much more effective to use measured HRTFs (Head Related Transfer Function). Some sets are available in the public domain for non-commercial use. Even better work individualized HRTFs, i.e. HRTFs measured with your own head and ears. It's actually not that hard to do.

Using real HRTFs will easily allow for externalization on the sides but it's still not great for median plane (up/down, front/back) and people often report in-head localization for frontal sources. The best way around this is head tracking, i.e. measuring the listeners head movements and updating the HRTF's in real time accordingly. That's pretty complicated though.

• actually Hil, the interaural delay is the most salient que for localizing a sound. but it can only do it on the plane your head is on (azimuth angles). to localize the zenith angles you need HRTFs. the HRTFs affect everything, but it's the fact that the sound reaches one ear before the other that really makes the difference. – robert bristow-johnson Dec 24 '15 at 3:57