Interaural Time Delay - Maple Programming Help

Home : Support : Online Help : Math Apps : Engineering and Applications : applications/InterauralTimeDelay

 Interaural Time Delay

Humans locate the origin of a sound with several cues. One technique employs the small difference in the time taken for the sound to reach either ear; this is known as the interaural time delay (ITD).

Lord Rayleigh investigated this phenomenon, assuming a spherical head with radius a, and sound waves arriving at an azimuth angle $\mathrm{θ}$.

Sound has to travel a distance  further to reach the left ear than the right ear. Hence, if the speed of the sound is c, then the interaural sound delay is

where c is the speed of sound.

For c = 343 m s-1, a = 0.11 m and $\mathrm{θ}$ = 0.5 (that is, a sound hitting a typical-sized head from the side), the sound delay is about 0.8 ms.

This application modifies a single-channel audio file so that the sound appears to originate at an angle from the observer. It does this by introducing an extra channel of sound. The new channel is equivalent to the old channel, but is padded with zeroes.

Despite both channels having the same amplitude, the sound appears to come from an angle simply by delaying one channel.

 > $\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$

Speed of sound in m s-1

 > $c:=343:$

 > $a:=0.08:$

Angle of sound

 > $\mathrm{soundAngle}:=\frac{30\mathrm{π}}{180}:$

Read sound file and calculate statistics

Example Sound

Optional: Record a Custom Sound

 > $\mathrm{Sound}≔\mathrm{Read}\left(\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["audio/ding.wav"\right],\mathrm{base}=\mathrm{datadir}\right)\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}$
 ${\mathrm{Sound}}{:=}\left[\begin{array}{c}{\mathrm{1 .. 20191}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (1)
 > $\mathrm{SampleRate}:=\mathrm{attributes}{\left(\mathrm{Sound}\right)}_{1}$
 ${\mathrm{SampleRate}}{:=}{22050}$ (2)
 > $\mathrm{BitRate}:=\mathrm{attributes}{\left(\mathrm{Sound}\right)}_{2}$
 ${\mathrm{BitRate}}{:=}{16}$ (3)
 >

Click on the microphone to begin recording:

Interaural time delay

 > $\mathrm{ITD}:=\mathrm{θ}→\frac{a\left(\mathrm{θ}+\mathrm{sin}\left(\mathrm{θ}\right)\right)}{c}:$

Hence we need to delay one channel by this number of samples

 > $\mathrm{TimeDelay}:=⌊\left(\mathrm{SampleRate}\cdot \mathrm{ITD}\left(\mathrm{soundAngle}\right)\right)⌉$
 ${\mathrm{TimeDelay}}{:=}{5}$ (4)
 > $\mathrm{zeroes}≔\mathrm{Array}\left(1..\left|\mathrm{TimeDelay}\right|,\mathrm{order}=\mathrm{C_order}\right):$
 >
 > $\mathrm{DirectionalSound}:=\mathrm{Create}\left(\mathrm{Transpose}\left(\mathrm{Concatenate}\left(1,\mathrm{M0},\mathrm{M1}\right)\right)*~1/2,\mathrm{channels}=2,\mathrm{rate}=\mathrm{SampleRate},\mathrm{order}=\mathrm{C_order}\right):$

 > $\mathrm{SignalProcessing}:-\mathrm{Spectrogram}\left(\mathrm{DirectionalSound},\mathrm{includesignal}\right)$

 >