SphereAudio MCP Server
# SphereAudio (v2.0.0)
**Open-source full-sphere (`-90°` under feet to `+90°` overhead) 3D spatial audio engine scaling from 2-channel binaural headphones (with optional AES69 SOFA HRTFs) up to 255-channel Ultra-Dome rigs, featuring a `.sph` Opus container, Web Studio with real-time REST/WebSocket/OSC head-tracking bridge, Physical Speaker Calibration Wizard, and MCP server for AI agents.**
Licensed under **Apache 2.0**.
## Key Capabilities
- **Full-Sphere Binaural Headphone Renderer (`sphereaudio/dsp.py`)**: Woodworth ITD, head-shadow ILD, pinna elevation notch shifts (`-90°` to `+90°`), overhead Blauert boost, below-ear torso bounce/shadowing, and early floor reflections.
- **Real AES69 SOFA HRTF Convolution (`sphereaudio/hrtf_sofa.py`)**: Optional `.sofa` loader for standard **KEMAR**, **SADIE II**, and **HUTUBS** datasets via `sofar` or `h5py` (with graceful fallback to the built-in parametric full-sphere HRTF engine when neither is installed). Includes spherical Delaunay **barycentric + ITD-aligned** and **nearest-neighbor** HRIR interpolation across `-90°` to `+90°`, exposed via `--sofa` in CLI and `sofa_path` in MCP `render_scene`.
- **Physical Speaker Mapper (`sphereaudio/rigs.py`)**: Scales seamlessly up to **255 discrete channels** (matching the Opus multistream ceiling):
- `headphones_binaural` (2ch full-sphere binaural headphones)
- `bedroom_underbed_hybrid` (9ch: 4 ear + 2 overhead + 2 edge-firing under-bed + tactile bass)
- `home_5_1_4_2_underseat` (12ch: 5 ear + 4 overhead + 2 under-sofa with fabric occlusion EQ + tactile LFE)
- `theater_full_sphere_24ch` (24ch cinema dome with perforated riser & under-seat vents)
- `theater_flagship_128ch` (128ch symmetrical full-sphere cinema dome)
- `theater_ultradome_255ch` (255ch maximum-density full-sphere dome: 51 ear-level, 96 overhead, 96 mirrored perforated-riser/under-seat/floor-grid, 12 LFE/tactile)
- **Interactive 3D Web Studio & Python Bridge (`studio/index.html`, `sphereaudio/studio_server.py`)**: Launch with `sphereaudio studio --api` for a live REST + RFC 6455 WebSocket + UDP OSC bridge enabling **Render High-Quality WAV**, **Test Physical Under-Seat Rig**, and real-time **Webcam / WebXR / OSC** head-tracking (`yaw`/`pitch`/`roll`).
- **Physical Speaker Calibration Wizard (`sphereaudio/calibrate.py`)**: `sphereaudio calibrate` CLI and `calibrate_speaker` MCP tool generate logarithmic sine sweeps and 1/f pink noise WAVs for `under_seat`, `perforated_riser`, and `under_bed` speakers, and compute custom `OcclusionProfile` EQ curves (`cutoff_hz`, `high_shelf_comp_db`, `max_usable_hz`) from recorded room microphone WAVs.
- **`.sph` Opus Container (`sphereaudio/container.py`)**: Packs `.sphere.json` trajectory metadata + Opus-compressed mono sound objects (via `ffmpeg`/`libopus`, with FLAC and WAV fallbacks) into a tiny, self-contained `.sph` delivery file that renders live to any rig (2ch to 255ch).
- **Per-Channel Mono Stem Exporter (`--stems`)**: Writes balanced mono WAV stems + `manifest.json` for 24ch, 128ch, and 255ch rigs without hitting the 4 GB standard WAV limit.
- **MCP Server & Agent Demo (`sphereaudio/mcp_server.py`, `examples/mcp_agent_demo.py`)**: 12 JSON-RPC 2.0 stdio tools and 3 resources so AI agents can create scenes, pack/unpack `.sph` Opus containers, calibrate speakers, inspect rigs, and render SOFA or multi-channel audio.
## Quickstart
```bash
pip install -e .
# Optional: enable AES69 .sofa HRTF dataset loading (KEMAR / SADIE II / HUTUBS)
pip install -e ".[sofa]"
# 1. Pack a scene into a compressed .sph Opus container
sphereaudio pack examples/full_sphere_demo.sphere.json -o demo.sph --codec opus --bitrate 48
# 2. Inspect the compressed .sph container
sphereaudio inspect demo.sph
# 3. Render with built-in parametric HRTF, an external .sofa HRTF, or 255ch Ultra-Dome stems
sphereaudio render demo.sph -o demo_headphones.wav --rig headphones_binaural
sphereaudio render demo.sph -o demo_kemar.wav --rig headphones_binaural --sofa path/to/KEMAR.sofa --hrtf-interp barycentric
sphereaudio render demo.sph -o stems_255 --rig theater_ultradome_255ch --stems
# 4. Launch the Interactive 3D Web Studio with Python DSP, Under-Seat Rig Test, WebSocket & OSC Head-Tracking
sphereaudio studio --api --osc-port 9001
# 5. Calibrate physical under-seat / perforated-riser / under-bed speakers
sphereaudio calibrate generate -o cal_underseat.wav --target under_seat --signal sweep
sphereaudio calibrate measure recorded_mic.wav --reference cal_underseat.wav --target under_seat -o custom_profile.json
# 6. Run the AI Agent MCP stdio demo (renders headphones + 24ch theater output)
python3 examples/mcp_agent_demo.py -o mcp_demo_out
```
## MCP Server Configuration
```json
{
"mcpServers": {
"sphereaudio": {
"command": "sphereaudio-mcp",
"args": [],
"cwd": "/path/to/SphereAudio"
}
}
}
```
Or invoke directly via Python (`python3 -m sphereaudio.mcp_server`).
## Running Tests
```bash
python3 -m unittest discover -s tests -v
```
TDQS
Scored across 12 tools
Most tools target clearly distinct operations (create/add/move/render/pack/validate), and descriptions explicitly state inputs and outputs. The only real confusion risk is between inspect_sph (metadata only) and unpack_sph (full decode), and to a lesser degree render_scene accepting a .sph input, but the descriptions do disambiguate them.
Every tool follows a strict snake_case verb_noun pattern (validate_scene, create_scene, add_sound_object, pack_sph, list_speaker_rigs, analyze_speaker_gains). No mixed conventions or vague standalone verbs.
12 tools sits squarely in the well-scoped range, and each maps to a distinct stage of the scene lifecycle (author, validate, render, pack/unpack, inspect, rig analysis, calibration). No obvious filler tools.
The surface covers create/add/move/validate/render/pack/unpack/inspect plus rig analysis, but there is no delete_sound_object or remove-keyframe operation, so an agent cannot undo additions, and no scene-level delete or metadata edit. These are notable lifecycle gaps rather than fatal ones, since scenes remain editable externally.