Skip to content

silent_audio: volume setters refuse NaN; master volume and mute under the lock (RT-SILENT-AUDIO-VOLUME-NAN) - #2519

Closed
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-silent-audio-volume-spatial
Closed

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-silent-audio-volume-spatial

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-SILENT-AUDIO-VOLUME-NAN (#1608 (comment))

What and why

This fixes the first bullet of item 4 in kevincommits' finding in #1608 (#1608 (comment)).

  • NaN volume accepted. SimpleVolume::SetMasterVolume, StreamVolume::SetChannelVolume and StreamVolume::SetAllVolumes tested level < 0.0f || level > 1.0f. That test is false for NaN, so a NaN level was stored and read back. All three now share volume_level(), which accepts only 0 <= level <= 1. SpatialObject::SetVolume in the same file already checks it that way.
  • Unlocked master and mute. SimpleVolume read and wrote AudioClient::master_ and mute_ directly, without client_->lock_, while the channel volumes take that lock. Both members are now private and are reached through locked accessors.

Not changed: the second bullet, about SpatialStream::ActivateSpatialAudioObject outside BeginUpdatingAudioObjects and Reset keeping objects active. Microsoft's own spatial audio sample activates its static objects before Start, outside an update, so refusing that call would break titles that follow it. Nothing I could check shows that Windows' Reset deactivates objects either. Both are left as they are.

Merges cleanly with the other open silent_audio PRs, #2133, #2134 and #2387.

Tested

  • silent_audio_test gains checks:
    • Each setter refuses NaN and keeps the previous level.
    • SetAllVolumes with one NaN sets none.
    • A mute round trip.
  • With main's range check put back, the 3 NaN checks fail. With the fix, 133/133 checks pass.
  • ctest -R silent_audio passes.
  • The lock change has no test of its own: a plain race on a float and a BOOL does not fail on x86 without a race detector.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU-only test)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

… the lock

SimpleVolume::SetMasterVolume, StreamVolume::SetChannelVolume and
StreamVolume::SetAllVolumes tested `level < 0 || level > 1`, which is
false for NaN, so a NaN level was stored (kevincommits' finding in
ProjectLeonida#1608). They now share volume_level(), which accepts only
0 <= level <= 1, as SpatialObject::SetVolume in the same file already
does.

SimpleVolume also read and wrote AudioClient::master_ and mute_ without
the client's lock, unlike the channel volumes. They are now private and
reached through locked accessors.

silent_audio_test gains checks that each setter refuses NaN and keeps
the previous level (3 fail with the old test), plus a mute round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2521 (RT-SILENT-AUDIO-VOLUME-AND-SPATIAL), which two of our sessions opened against the same item at the same time. #2521 covers everything here (NaN volumes refused through one check, master volume and mute under the client's lock) plus the rest of item 4. Sorry for the noise. AI-assisted (Claude Code).

@Tyrannys Tyrannys closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant