[PR #1133] [MERGED] Audio: pan like OpenAL Soft's stereo output (explosions were ~6 dB too loud) #3079

Closed
opened 2026-11-02 16:01:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1133
Author: @ludovic111
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ludovic111

Base: main ← Head: fix/openal-stereo-panning


📝 Commits (1)

  • 082cc27 Audio: pan like OpenAL Soft's stereo output, not at full gain on both sides

📊 Changes

2 files changed (+131 additions, -22 deletions)

View changed files

📝 crates/horizon-client/src/audio.rs (+130 -21)
📝 crates/horizon-client/src/game.rs (+1 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #488. Reported on Discord by rdbt ("explosions are definitely louder than minecraft"), with a recording of the same 11×11×11 TNT cube in both games.

What

Horizon's mixer now pans and limits the way vanilla's OpenAL Soft (1.25.2, the LWJGL 3.4.3 natives vanilla ships) does on a stereo output with HRTF off:

  • Panning. Each mono source is panned between the two speakers with OpenAL Soft's pairwise-panning gains instead of being played at full gain on both sides:
    • front azimuths are stretched ×1.5 (ScaleAzimuthFront) and capped at 90°;
    • L = 0.5 − 0.5·sin(az)·cos(el) + 0.0956608·cos(az)·cos(el), and R is the same with +0.5·sin(az).
    • So a sound straight ahead plays at 0.5957 per side (−4.5 dB), one behind at 0.4043 and one straight up or down at 0.5. A source at distance 0 counts as in front. A mono output device still plays every source at gain 1.
  • Listener orientation. Mixer::set_listener now takes the camera pitch as well as the yaw, so the left/right split follows where the camera looks. Relative sources (UI, music) use OpenAL's listener-relative axes.
  • Limiter release. The output limiter's release goes from 50 ms to 0.2 s, OpenAL Soft's value. Vanilla turns the limiter on (ALC_OUTPUT_LIMITER_SOFT = 1 in Library.createAttributes).

Why

SoundEngine.calculateVolume already clamps like vanilla, so the extra loudness came from the backend. Horizon summed every voice at full gain on both channels, where OpenAL Soft's stereo panning puts at most 0.5957 of a centred source on each side. That is about 4.5 dB on its own. The fast limiter release added the rest under heavy load.

How it was measured

Vanilla's own libopenal.dylib (from the 26.3 natives) was driven offline through ALC_SOFT_loopback, with the same attributes as Library.createAttributes, a 247-source pool and the decoded entity.generic.explode OGGs. Horizon's real Mixer::mix() got the same scenarios: same positions, same volumes and pitches ((1 + (r1 − r2)·0.2)·0.7), same linear attenuation over 64 blocks. Levels are the mean over the clip in dBFS. Clipped = samples at ±1.0.

Scenario Vanilla (OpenAL Soft) Horizon main This PR
One explosion 4 blocks ahead −17.21 dBFS −12.73 −17.23
10 TNT −14.26 −11.43 −13.33
50 TNT −11.56 −9.36 −10.83
1,331 TNT (299 played, 247-voice cap) −10.80, 170 clipped −8.24, 293 clipped −9.77, 144 clipped
  • With vanilla's limiter switched off, the 1,331 case peaks at +18.69 dBFS (mean +0.99), so the limiter does matter.
  • The pan model matches the dylib to within 4.5e-6 over 40 random source directions.
  • Under heavy load about 1 dB remains. That comes from OpenAL Soft's compressor (automatic attack, release and knee, plus lookahead), which this PR doesn't model. A single source now matches to 0.02 dB.

How tested

New unit tests in audio.rs:

  • stereo_panning_matches_openal_soft: a table of gains measured from the dylib.
  • panning_follows_the_camera_rotation.
  • a_mono_output_plays_sources_unpanned.

Two existing tests now expect panned levels.

cargo fmt --all -- --check                                   OK
set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings
                                                             Finished, no warnings
cargo test -p horizon-client                                 962 + 84 + 15 + 2 + 2 + 2 + 1 passed, 0 failed
tools/parity.py --changed origin/main (branch)               101 passed, 0 failed in 77.1 min

No harness failed on the branch, so none needed a comparison run on main.

What needs Ludovic

  • A listen in game. Stereo placement changes for every sound, not just explosions: things to your left are now louder in the left ear, as in vanilla. Everything is a bit quieter overall (−4.5 dB for a centred sound).
  • Under very heavy load Horizon still runs about 1 dB hotter than vanilla (the compressor note above).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1133 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/openal-stereo-panning` --- ### 📝 Commits (1) - [`082cc27`](https://github.com/horizon-rust/horizon/commit/082cc278afb22d1196bfc8b698a4ce1ae9510984) Audio: pan like OpenAL Soft's stereo output, not at full gain on both sides ### 📊 Changes **2 files changed** (+131 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/audio.rs` (+130 -21) 📝 `crates/horizon-client/src/game.rs` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #488. Reported on Discord by **rdbt** ("explosions are definitely louder than minecraft"), with a recording of the same 11×11×11 TNT cube in both games. ## What Horizon's mixer now pans and limits the way vanilla's OpenAL Soft (1.25.2, the LWJGL 3.4.3 natives vanilla ships) does on a stereo output with HRTF off: - **Panning.** Each mono source is panned between the two speakers with OpenAL Soft's pairwise-panning gains instead of being played at full gain on both sides: - front azimuths are stretched ×1.5 (`ScaleAzimuthFront`) and capped at 90°; - L = 0.5 − 0.5·sin(az)·cos(el) + 0.0956608·cos(az)·cos(el), and R is the same with +0.5·sin(az). - So a sound straight ahead plays at 0.5957 per side (−4.5 dB), one behind at 0.4043 and one straight up or down at 0.5. A source at distance 0 counts as in front. A mono output device still plays every source at gain 1. - **Listener orientation.** `Mixer::set_listener` now takes the camera pitch as well as the yaw, so the left/right split follows where the camera looks. Relative sources (UI, music) use OpenAL's listener-relative axes. - **Limiter release.** The output limiter's release goes from 50 ms to 0.2 s, OpenAL Soft's value. Vanilla turns the limiter on (`ALC_OUTPUT_LIMITER_SOFT` = 1 in `Library.createAttributes`). ## Why `SoundEngine.calculateVolume` already clamps like vanilla, so the extra loudness came from the backend. Horizon summed every voice at full gain on both channels, where OpenAL Soft's stereo panning puts at most 0.5957 of a centred source on each side. That is about 4.5 dB on its own. The fast limiter release added the rest under heavy load. ## How it was measured Vanilla's own `libopenal.dylib` (from the 26.3 natives) was driven offline through `ALC_SOFT_loopback`, with the same attributes as `Library.createAttributes`, a 247-source pool and the decoded `entity.generic.explode` OGGs. Horizon's real `Mixer::mix()` got the same scenarios: same positions, same volumes and pitches (`(1 + (r1 − r2)·0.2)·0.7`), same linear attenuation over 64 blocks. Levels are the mean over the clip in dBFS. Clipped = samples at ±1.0. | Scenario | Vanilla (OpenAL Soft) | Horizon `main` | This PR | | --- | ---: | ---: | ---: | | One explosion 4 blocks ahead | −17.21 dBFS | −12.73 | **−17.23** | | 10 TNT | −14.26 | −11.43 | **−13.33** | | 50 TNT | −11.56 | −9.36 | **−10.83** | | 1,331 TNT (299 played, 247-voice cap) | −10.80, 170 clipped | −8.24, 293 clipped | **−9.77, 144 clipped** | - With vanilla's limiter switched off, the 1,331 case peaks at +18.69 dBFS (mean +0.99), so the limiter does matter. - The pan model matches the dylib to within 4.5e-6 over 40 random source directions. - Under heavy load about 1 dB remains. That comes from OpenAL Soft's compressor (automatic attack, release and knee, plus lookahead), which this PR doesn't model. A single source now matches to 0.02 dB. ## How tested New unit tests in `audio.rs`: - `stereo_panning_matches_openal_soft`: a table of gains measured from the dylib. - `panning_follows_the_camera_rotation`. - `a_mono_output_plays_sources_unpanned`. Two existing tests now expect panned levels. ``` cargo fmt --all -- --check OK set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings Finished, no warnings cargo test -p horizon-client 962 + 84 + 15 + 2 + 2 + 2 + 1 passed, 0 failed tools/parity.py --changed origin/main (branch) 101 passed, 0 failed in 77.1 min ``` No harness failed on the branch, so none needed a comparison run on `main`. ## What needs Ludovic - A listen in game. Stereo placement changes for every sound, not just explosions: things to your left are now louder in the left ear, as in vanilla. Everything is a bit quieter overall (−4.5 dB for a centred sound). - Under very heavy load Horizon still runs about 1 dB hotter than vanilla (the compressor note above). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:01:20 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3079
No description provided.