Friday, October 5, 2018

audio - 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: enter image description here


What about modelling the "distance" from the listener?



Answer



Spherical head, distant source


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:


Unit circle head, distant source


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.


$\sin(\alpha) + \alpha$


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.


Spherical head, nearby source


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:


enter image description here


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:


ITD with distance


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...