Skip to content

Restore SoundPan / ChannelPan on the OpenAL audio backend#80

Merged
CoreyRDean merged 3 commits into
developfrom
align/restore-audio-pan
May 30, 2026
Merged

Restore SoundPan / ChannelPan on the OpenAL audio backend#80
CoreyRDean merged 3 commits into
developfrom
align/restore-audio-pan

Conversation

@CoreyRDean
Copy link
Copy Markdown
Collaborator

Non-technical summary

SoundPan and ChannelPan — classic Blitz3D commands for placing a sound left/right in the stereo field — were lost when the audio backend moved from DirectSound to OpenAL, even though BlitzForge still ships their documentation and examples. Legacy games calling them failed to compile. This PR restores both commands, so those programs compile and run again (INTENT #1 drop-in compatibility, and it fixes a docs-vs-reality gap).

Technical summary

  • gxChannel/gxSound: added setPan() (pure-virtual on the bases; the only implementers are SampleChannel/StreamChannel and gxSoundSample/gxSoundStream — no macOS audio backend exists, so no stub needed).
  • Channels: constant-power stereo pan on a listener-relative OpenAL source — clamp pan∈[-1,1], AL_SOURCE_RELATIVE=AL_TRUE, alSource3f(AL_POSITION, pan, 0, -sqrt(1-pan²)). Mutually exclusive with set3d (last-call-wins, matching legacy pan/3D semantics).
  • Sounds: store a default pan applied at play() (so SoundPan sets the default for subsequently-played channels).
  • bbaudio: re-enabled bbSoundPan (debugSound-guarded) and bbChannelPan (verifyChannel-guarded, matching sibling channel commands) + their rtSym registrations, using the typed (BBSound)/(BBChannel) signatures.

No compiler/codegen/front-end change. Windows OpenAL backend only.

Acceptance criteria + results

  • Build clean (0 errors); SoundPan/ChannelPan registered.
  • spider.bb now compiles → removed from scripts/corpus_compile_allowlist.txt; corpus sweep green. aristoids.bb's SoundPan blocker is resolved but it also uses PlayMusic (a separate, still-disabled builtin), so it stays allowlisted with its reason updated to PlayMusic.
  • New tests/AudioPanTest.bb passes under blitzcc -t: the commands resolve and tolerate a Null sound/channel (incl. an out-of-range pan value) without crashing — headless-safe (no audio device in CI).
  • Full test.bat green; corpus sweep green.
  • Audible pan correctness: not headless-verifiable (no audio device in CI). The OpenAL constant-power formula is standard and the relative-source setup is confirmed; audible verification is a manual Windows step (documented).

Trade-offs, deferred follow-ups

  • Pure-virtual chosen over a non-pure default (only 4 concrete implementers, all updated; forces correctness).
  • Deferred (cheap next pick, same file): gxSoundSample::load short-filename crash — LoadSound("abc")substr(filename.size()-4) underflows → std::out_of_range → process kill. One-line guard at gxsound.cpp:25.
  • Other Class B builtins (PlayMusic/CreateListener/Load3DSound/StartNetGame); linker loadImage hardening; TCP-socket UAF; GC reference_map soundness; contextual-keyword Phase 2; the manual audible-pan listen.

🤖 Generated with Claude Code

CoreyRDean and others added 3 commits May 30, 2026 02:40
SoundPan and ChannelPan are classic Blitz3D stereo-pan commands that BlitzForge
still ships docs/examples for, but the runtime no longer registered or implemented
them -- casualties of the DirectSound->OpenAL port (the impls/registrations were
commented out in bbaudio.cpp and the setPan virtual had been dropped from
gxChannel/gxSound). Legacy programs calling them failed to compile ("SoundPan not
found"); they're corpus-allowlist Class B entries. Restore them (INTENT #1 drop-in
compatibility + a docs-vs-reality fix).

- gxChannel/gxSound: add setPan() (pure-virtual on the bases; only SampleChannel/
  StreamChannel + gxSoundSample/gxSoundStream implement these -- no macOS audio
  backend exists).
- Channels implement constant-power stereo pan on a listener-relative source:
  clamp pan in [-1,1], alSourcei(AL_SOURCE_RELATIVE,AL_TRUE),
  alSource3f(AL_POSITION, pan, 0, -sqrt(1-pan^2)). Mutually exclusive with set3d
  (last call wins, matching legacy semantics).
- Sounds store a default pan applied at play() (SoundPan sets the default for
  subsequently-played channels).
- bbaudio: re-enable bbSoundPan (debugSound-guarded) and bbChannelPan
  (verifyChannel-guarded, matching the other channel commands) + their rtSyms,
  using the typed (BBSound)/(BBChannel) signatures.

Audible pan correctness is not headless-verifiable (no audio device in CI); the
OpenAL formula is standard and the relative-source setup is confirmed -- audible
verification is a manual Windows step.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add tests/AudioPanTest.bb: a headless-safe smoke test proving SoundPan/ChannelPan
resolve and tolerate a Null sound/channel (CI has no audio device). With the
commands restored, spider.bb compiles and is removed from the allowlist; aristoids.bb's
SoundPan blocker is gone but it also uses PlayMusic (still disabled), so it stays
allowlisted with its reason updated. Corpus sweep green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Per-file plan, OpenAL constant-power pan mechanism, the spider-cleared/aristoids-now-
PlayMusic outcome, and deferred follow-ups (gxsound short-filename crash, other Class B
builtins, audible verification).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CoreyRDean CoreyRDean added the enhancement New feature or request label May 30, 2026
@CoreyRDean CoreyRDean requested a review from a team as a code owner May 30, 2026 07:42
@CoreyRDean CoreyRDean merged commit 23fbdaf into develop May 30, 2026
4 checks passed
@CoreyRDean CoreyRDean deleted the align/restore-audio-pan branch May 30, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant