Skip to content

Spatial Audio and Binaural Tools

youtube-at-vach edited this page Jul 23, 2026 · 1 revision

Spatial Audio and Binaural Tools

Relevant source files

The following files were used as context for generating this wiki page:

This section covers the specialized modules in MeasureLab designed for 3D audio rendering, binaural perception visualization, and stereo field analysis. These tools leverage Head-Related Transfer Functions (HRTF), psychoacoustic models, and cross-correlation techniques to process or visualize spatial information.

HRTF and Spatial Rendering Architecture

The spatial audio suite relies on the SOFA (Spatially Oriented Format for Acoustics) standard to define how sound interacts with human anatomy. The system implements high-precision interpolation and convolution to render point sources in a virtual 3D sphere.

Spatial Binaural Mixer

The SpatialBinauralMixer is an offline rendering module specialized for multi-track stem processing docs/widgets/spatial_binaural_mixer.md:5-7. Unlike real-time engines that use block-based Overlap-Add (OLA) which can introduce windowing artifacts, this mixer performs full-track FFT convolution using scipy.signal.fftconvolve docs/widgets/spatial_binaural_mixer.md:13-15.

Key Implementation Details:

  • IDW Interpolation: Uses Inverse Distance Weighting to synthesize Head-Related Impulse Responses (HRIR) for arbitrary Azimuth and Elevation coordinates by blending the nearest measured points from a SOFA file docs/widgets/spatial_binaural_mixer.md:11-12.
  • Precision: Internal mixing occurs in Float64 to prevent clipping during summation docs/widgets/spatial_binaural_mixer.md:14-14.
  • Resampling: Uses Polyphase Sinc interpolation (resample_poly) to match source audio sample rates to the SOFA dataset rate docs/widgets/spatial_binaural_mixer.md:15-15.

Data Flow: Multi-Track Spatial Rendering

The following diagram illustrates how tracks are processed from raw audio files to a binaural mix.

Diagram: Spatial Rendering Pipeline

graph TD
    subgraph "Input Space"
        T1["Track 1 (WAV/FLAC)"]
        T2["Track 2 (WAV/FLAC)"]
        SOFA["SOFA File (.sofa/.nc)"]
    end

    subgraph "Coordinate Mapping"
        C1["Azimuth/Elevation 1"]
        C2["Azimuth/Elevation 2"]
    end

    subgraph "SpatialBinauralMixer Logic"
        IDW["IDW Interpolator"]
        FFTC["FFT Convolution (fftconvolve)"]
        SUM["Float64 Summing Bus"]
    end

    SOFA --> IDW
    C1 & C2 --> IDW
    IDW -->|"Interpolated HRIR"| FFTC
    T1 & T2 --> FFTC
    FFTC --> SUM
    SUM -->|"Normalize 0.99 FS"| OUT["Final Binaural WAV"]
Loading

Sources: docs/widgets/spatial_binaural_mixer.md:21-62, src/gui/widgets/spatial_binaural_mixer.py


Binaural Perception Visualization

BNIM Meter (Neural Map)

The BNIM (Binaural Neural Information Mapping) Meter simulates how the human brain processes Interaural Time Differences (ITD) and Interaural Level Differences (ILD) docs/widgets/bnim_meter.md:7-9.

  • Visualization: A heat map where the X-axis represents ITD (Direction) and the Y-axis represents Frequency docs/widgets/bnim_meter.md:19-23.
  • Psychoacoustic Weights: The Enable ILD weighting feature incorporates level differences, which are critical for directional perception at high frequencies where ITD becomes ambiguous docs/widgets/bnim_meter.md:46-49.
  • Interaction: The "Click-to-play" feature allows users to click the neural map to generate a burst signal at a specific ITD/Frequency coordinate, facilitating auditory training docs/widgets/bnim_meter.md:53-61.

Sources: docs/widgets/bnim_meter.md:1-83


Stereo Alignment and Phase Analysis

Stereo Alignment Monitor

The StereoAlignmentMonitor provides real-time analysis of the relationship between Left and Right channels. It utilizes a smoothed cross-power spectrum to derive metrics src/gui/widgets/stereo_alignment_monitor.py:28-57.

Metric Calculation / Purpose
L/R Balance Ratio of total energy between $S_{LL}$ and $S_{RR}$ in dB src/gui/widgets/stereo_alignment_monitor.py:175-177.
Center Focus Derived from Mid/Side (M/S) energy ratios to determine "phantom center" strength src/gui/widgets/stereo_alignment_monitor.py:179-183.
Phase Issue % Percentage of energy in frequency bins where the cross-correlation $C_f$ is negative src/gui/widgets/stereo_alignment_monitor.py:185-196.
Volume Gang Error Logs $L-R$ differences across levels to detect tracking errors in analog potentiometers src/gui/widgets/stereo_alignment_monitor.py:122-138.

Sources: src/gui/widgets/stereo_alignment_monitor.py:106-202


Technical Mapping: Logic to Code

This diagram maps the high-level spatial and alignment concepts to the specific classes and methods in the codebase.

Diagram: Spatial Audio Code Entity Map

classDiagram
    class SpatialBinauralMixer {
        +render_to_wav()
        +render_and_monitor()
        +idw_interpolation()
    }
    class StereoAlignmentMonitor {
        +s_ll : ndarray
        +s_rr : ndarray
        +s_lr : complex128
        +_callback(indata)
        +compute_metrics()
    }
    class BNIMMeter {
        +itd_range : float
        +ild_weighting : bool
        +process_neural_map()
    }
    class AudioEngine {
        +register_callback()
        +sample_rate : int
    }

    SpatialBinauralMixer ..> AudioEngine : "Uses for monitoring"
    StereoAlignmentMonitor --|> MeasurementModule : "Inherits"
    StereoAlignmentMonitor --> AudioEngine : "Registers FFT callback"
    BNIMMeter --|> MeasurementModule : "Inherits"
Loading

Sources: src/gui/widgets/stereo_alignment_monitor.py:28-106, src/gui/widgets/spatial_binaural_mixer.py, docs/widgets/bnim_meter.md:7-15

Precision Impedance and Linearity

While often used for general audio, the ImpedanceAnalyzer and LinearityAnalyzer provide the foundational precision required for calibrating spatial audio hardware (e.g., matching headphone drivers).

  • Impedance Analyzer: Uses a dual-lock-in approach to measure voltage and current simultaneously, employing a post-mix IIR LPF (up to 8 poles) to achieve high dynamic reserve src/gui/widgets/impedance_analyzer.py:90-97. It features dynamic buffering to ensure at least 8 cycles are captured even at low frequencies src/gui/widgets/impedance_analyzer.py:51-53.
  • Linearity Analyzer: Sweeps levels (dBFS) to detect gain compression or expansion. It includes a calculate_hysteresis function to compare forward and reverse sweeps, identifying memory effects in transducers src/gui/widgets/linearity_analyzer.py:30-60.

Sources: src/gui/widgets/impedance_analyzer.py:44-103, src/gui/widgets/linearity_analyzer.py:30-96


Clone this wiki locally