Binaural cues

A sound off to one side reaches the nearer ear sooner and louder: an interaural time difference (ITD) and an interaural level difference (ILD). How alike the two ears' signals are, their interaural correlation, decides whether the image is a compact point or a diffuse cloud. Each example on this page changes one of these and holds the others still. They need headphones: over speakers the two ears' signals mix in the room and the effects disappear.

  • Timing alone: a sound moved sideways by an ITD with no level difference.
  • Correlation that changes: binaural beats, phasewarp and Oscor, sounds whose interaural phase or correlation changes over time while each ear alone hears something steady.
  • Up and down: a source that rises in front of the head and drops behind it, where none of these change and the spectrum does.

For real sources at real positions, with every cue together, see Moving talkers, where three talkers are rendered through measured head-related impulse responses and one of them moves.

Press play and a line follows the sound across every time axis in its plots. Click any time axis to play from that point. The audio is lossless, since compression would alter the binaural sounds. Start with your volume low.

To run this page yourself, open it as a notebook in Colab or download it. It is the same code, and it fetches the recordings it needs from the sonore repository.

How the cues are measured

so.interaural_cues cuts the two ears' signals into short windows (10 ms here) and, in each, finds the ITD as the lag (within ±1 ms) of the peak of the interaural cross-correlation, the ILD as the level difference in dB, and the correlation both at zero lag and at its peak over lags (the coherence). It can also do this per frequency band, given a filterbank; here it uses the whole signal. Each figure shows the waveforms, the ITD and ILD, and the two correlations, all measured from the sound you hear.

Setup, the same on every page
import os
import urllib.request

import matplotlib.pyplot as plt
import numpy as np

import sonore as so

plt.rcParams.update({"font.size": 9, "axes.titlesize": 10, "figure.dpi": 100})


def fetch(path):
    """A file from the sonore repository, by its path there: the local copy when this runs from
    the repository root, otherwise downloaded from GitHub to the same relative path."""
    if not os.path.exists(path):
        os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
        urllib.request.urlretrieve("https://raw.githubusercontent.com/choyun1/sonore/main/" + path, path)
    return path


def finish(snd):
    """How every sound in the gallery is played: 5 ms ramps, RMS 0.1, peak at most 0.95."""
    snd = snd.ramp(5e-3).normalize(rms=0.1)
    return snd.normalize(peak=0.95) if snd.peak > 0.95 else snd
Code
FS = 44100


def show(snd):
    """Waveforms, ITD and ILD, and interaural correlation, all on one time axis.
    Returns the figure and the panels the playhead follows."""
    fig, axes = plt.subplots(3, 1, figsize=(10, 6.6), sharex=True, layout="constrained")
    snd.plot(axes[0], lw=0.4)
    axes[0].set_title("Waveform, left and right")
    cues = so.interaural_cues(snd, win_dur=10e-3)
    cues.plot(axes[1])
    axes[1].set_xlabel("")
    axes[2].plot(cues.t, cues.corr0, color="tab:orange", lw=1, label="correlation at zero lag")
    axes[2].plot(cues.t, cues.iac, color="k", alpha=0.6, lw=1, label="coherence (peak over lags)")
    axes[2].axhline(0, color="k", alpha=0.25, lw=0.8)
    axes[2].set(ylim=(-1.05, 1.05), ylabel="Interaural corr.", xlabel="Time [s]", xlim=(0, snd.duration))
    axes[2].legend(loc="lower right", fontsize=8)
    axes[2].grid(ls=":")
    return fig, list(axes)

Timing alone

Timing alone 🎧

Noise with a 500 µs interaural time difference, leading in the left ear and then in the right. The level difference is zero except in the first and last few milliseconds, where one ear has started or stopped and the other not yet; the sideways shift comes from timing. The zero-lag correlation is near 0, since broadband noise is uncorrelated with itself 500 µs later, while the coherence is 1: the two ears hold the same noise, 500 µs apart.

10_timing_alone.flac, 1.9 s, stereo

Plots of the timing alone sound
Code
noise = so.gaussian_noise(0.8, FS, rng=0).ramp(20e-3)
noise2 = so.gaussian_noise(0.8, FS, rng=1).ramp(20e-3)
sound = finish(
    so.concat(
        [
            so.apply_itd_ild(noise, itd=-500e-6),
            so.silence(0.3, FS),
            so.apply_itd_ild(noise2, itd=500e-6),
        ]
    )
)
fig, playhead = show(sound)

Correlation that changes

Three sounds whose two ears, heard alone, are steady: a tone, or plain noise. What changes over time is how the two ears relate. In the first two, the interaural phase turns round and round; in the third, the interaural phase stays put and the correlation falls and rises because the right ear's noise is mixed with an independent one. Each panel of zero-lag correlation follows a cosine or a sine at the rate of the change.

Binaural beats, 4 Hz 🎧

440 Hz in the left ear, 444 Hz in the right: two steady tones, so nothing in either ear beats. Their interaural phase difference turns through a full cycle four times a second, and the binaural system, which follows the phase of low-frequency tones, hears that: the image moves or wobbles inside the head. The zero-lag correlation, measured in 10 ms windows, follows \cos(2\pi \cdot 4\,t) (dotted). The ITD sweeps across the ±1 ms the measurement searches and jumps back when the next cycle of the tone comes closer, while the coherence (the peak over lags) stays close to 1. Binaural beats are heard only at low frequencies, and only for small differences (Licklider, Webster & Hedlun, 1950). Mixed into the same sound, the same two tones beat in loudness instead: Tones and noises plays 440 and 444 Hz added together, and 440 and 480 Hz, whose 40 Hz beat is heard as roughness.

b4_binaural_beats_4_hz.flac, 3.0 s, stereo

Plots of the binaural beats, 4 hz sound
Code
sound = finish(so.Sound.from_channels(so.pure_tone(3, FS, 440), so.pure_tone(3, FS, 444), fs=FS))
fig, playhead = show(sound)
t = so.interaural_cues(sound, win_dur=10e-3).t
playhead[2].plot(t, np.cos(2 * np.pi * 4 * t), color="k", ls=":", lw=1, label="cos(2π·4t)")
playhead[2].legend(loc="lower right", fontsize=8)

Siveke et al. (2008) asked how fast the binaural system can follow such changes, using two noises in which each ear alone hears plain noise. Phasewarp, which they introduced, is a binaural beat for every component of a noise at once: the right ear hears the left ear's noise shifted up in frequency by the modulation rate (sonore makes the shift with a single-sideband modulator), so every component's interaural phase rotates at that rate, as the tones' phase did above. Oscor, an older stimulus they also used, makes the right ear's noise a moving mixture of the left ear's noise and an independent one: the correlation swings between +1 and −1, but the interaural phase is only ever 0 or 180°, so there is no ITD that moves.

Phasewarp 🎧

Phasewarp at 2 Hz. The interaural phase of every component rotates through 360° twice a second, so the zero-lag correlation follows a 2 Hz cosine. Siveke et al. describe it as a noise that rotates around the head.

08_phasewarp.flac, 4.0 s, stereo

Plots of the phasewarp sound
Code
sound = finish(so.phasewarp(4, FS, f_mod=2, rng=0))
fig, playhead = show(sound)

Oscor 🎧

Oscor at 3 Hz. The interaural correlation follows a 3 Hz sine between +1 and −1, and the image alternates between focused and diffuse rather than moving. Each ear alone is plain noise; only the correlation panel shows what changes.

07_oscor.flac, 4.0 s, stereo

Plots of the oscor sound
Code
sound = finish(so.oscor(4, FS, f_mod=3, rng=0))
fig, playhead = show(sound)

Up and down

A source straight ahead that rises overhead and drops behind the head stays the same distance from both ears, so the cues above hardly change. In the head-related impulse responses (HRIRs) used here, measured on a KEMAR manikin at 1 m (PKU-IOA, Qu et al., 2009), the ITD stays under 46 µs and the ILD under 1.8 dB at every measured direction on that path (the median plane), against 763 µs and 15.2 dB for a source at the right. What changes is the spectrum both ears hear, shaped mostly by the outer ear (Middlebrooks & Green, 1991). These HRIRs are one manikin's, not yours: with HRIRs measured on someone else, elevation and front versus back are where listeners make the most errors (Wenzel et al., 1993), so these sounds may not rise or pass behind for every listener. PKU-IOA measures nothing below −40°, and sonore will not interpolate there.

Code
hrirs = so.load_hrirs()  # PKU-IOA KEMAR at 1 m; downloaded on first use


def in_front(elevation):
    """A Cartesian point 1 m away, straight ahead and ``elevation`` degrees up."""
    return np.column_stack(so.hcc_to_rect(100, elevation, 0))[0]

Four heights in front 🎧

Noise from four heights in front: 40° below, level, 40° and 80° above. Each is the same noise filtered by the HRIRs measured there. In the left ear's response (right panel), the clearest differences are the dips above about 5 kHz, which sit at different frequencies at each height; the spectrogram shows them as dark bands in each burst.

u1_four_heights_in_front.flac, 3.2 s, stereo

Plots of the four heights in front sound
Code
HEIGHTS = [-40, 0, 40, 80]
bursts = []
for i, elevation in enumerate(HEIGHTS):
    noise = so.gaussian_noise(0.6, FS, rng=i).ramp(20e-3)
    bursts += [so.spatialize(noise, in_front(elevation), hrirs), so.silence(0.25, FS).to_stereo()]
sound = finish(so.concat(bursts[:-1]))
fig, axes = plt.subplots(1, 2, figsize=(10, 3.8), layout="constrained", width_ratios=[1.6, 1])
so.STFT(sound, win_dur=20e-3).plot(axes[0], fmax=16000, db_range=60, colorbar=False)
axes[0].set_title("Left ear")
irs = hrirs.at(np.array([in_front(e) for e in HEIGHTS]))
freqs = np.fft.rfftfreq(4096, 1 / hrirs.fs)
for elevation, ir in zip(HEIGHTS, irs, strict=True):
    axes[1].plot(freqs, 20 * np.log10(np.abs(np.fft.rfft(ir[0], 4096))), lw=1, label=f"{elevation:+d}°")
so.plotting.log_frequency_axis(axes[1], "x")
axes[1].set(xlim=(500, 16000), ylim=(-50, 25), xlabel="Frequency [Hz]", ylabel="Level [dB]")
axes[1].set_title("Left ear's response, in front")
axes[1].legend(fontsize=8)
axes[1].grid(ls=":")
playhead = [axes[0]]

Over the head 🎧

Noise moving through the median plane over 6 s: from 40° below in front, up and over the head, down to 40° below behind. so.hcc_trajectory takes elevations past 90°, which come down behind the head. The spectrogram's dark bands slide as the source moves. The ITD and ILD panel is drawn to the scale of a source at the right (±800 µs, ±16 dB), and on it they barely leave zero.

u2_over_the_head.flac, 6.0 s, stereo

Plots of the over the head sound
Code
DURATION = 6.0
path = so.hcc_trajectory(dist=100, elev=([0, DURATION], [-40, 220]), azim=0)
sound = finish(so.move_sound(so.gaussian_noise(DURATION, FS, rng=4), path, hrirs))
fig, axes = plt.subplots(3, 1, figsize=(10, 7), sharex=True, layout="constrained", height_ratios=[2, 1, 1])
so.STFT(sound, win_dur=20e-3).plot(axes[0], fmax=16000, db_range=60, colorbar=False)
axes[0].set(title="Left ear", xlabel="")
t = np.linspace(0, DURATION, 200)
axes[1].plot(t, np.interp(t, [0, DURATION], [-40, 220]), color="k", lw=1)
axes[1].set_yticks([-40, 0, 90, 180, 220], ["below, front", "front", "overhead", "behind", "below, behind"])
axes[1].set_title("Where the source is")
axes[1].grid(ls=":")
so.interaural_cues(sound, win_dur=10e-3).plot(axes[2])
axes[2].set(xlim=(0, DURATION), ylim=(-800, 800))
fig.axes[-1].set_ylim(-16, 16)  # the ILD axis, which the cues plot adds last
playhead = list(axes)

References

  • Licklider, Webster & Hedlun (1950). On the frequency limits of binaural beats. J. Acoust. Soc. Am. 22(4), 468–473. doi:10.1121/1.1906629.
  • Middlebrooks & Green (1991). Sound localization by human listeners. Annu. Rev. Psychol. 42, 135–159. doi:10.1146/annurev.ps.42.020191.001031.
  • Qu, Xiao, Gong, Huang, Li & Wu (2009). Distance-dependent head-related transfer functions measured with high spatial resolution using a spark gap. IEEE Trans. Audio, Speech, Lang. Process. 17(6), 1124–1132. PKU Scholar. The HRIRs. hrir_data.load_hrirs
  • Siveke, Ewert, Grothe & Wiegrebe (2008). Psychophysical and physiological evidence for fast binaural processing. J. Neurosci. 28(9), 2043–2052. doi:10.1523/JNEUROSCI.4488-07.2008. binaural.oscor binaural.phasewarp
  • Wenzel, Arruda, Kistler & Wightman (1993). Localization using nonindividualized head-related transfer functions. J. Acoust. Soc. Am. 94(1), 111–123. doi:10.1121/1.407089.