Repository navigation
Audio: Fade Out BGM falls from where it is, not most of the way at once (runtime 20261130.3) - #103
Open
Xehanort88 wants to merge 3 commits into
Open
Xehanort88 wants to merge 3 commits into
Xehanort88 wants to merge 3 commits into
Conversation
… may repeat (runtime 20261130.1) Adaptive scores overlap their segments by different amounts (a 28.4s file holding 24s of music and a 4.4s tail beside segments with 4.8s and one-shots with none), draw with weights, and let some layers repeat. A palette had one fade-out for every track, drew evenly and never repeated, so such a score could only be approximated by padding the audio files with silence. - tail on a pool track: seconds before its end that the next draw starts, the track fading out under it; overrides the palette fade-out for that hand-over, 0 plays it to its end. AudioManager._bgmSequenceLayerFade decides _bgmSequenceLayerIsEnding, the retire fade and a single-shot advance. - weight on a pool track or silence: its share of a Random draw (0 never drawn; all zero falls back to an even draw). - repeats on a layer: a Random draw may pick the entry just played. All three are optional and written only when they say something; a sequence without them plays as before, and an older runtime ignores them. The editor gets Tail (s) and Draw weight on pool rows and Allow repeats on a layer, with the six phrases in all 17 locales (machine-assisted first pass). "Draw weight", not "Weight": the catalog already holds "Weight" as body weight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A palette's layers used to start each track when its file had loaded and hand over from a once-per-frame check, so stems drifted apart and joins landed wherever a frame fell. Now, with the scheduled WebAudio API: - every layer's first draw is decoded before any sounds, and all start on one context frame; - each next draw is decoded while the one before it plays and committed with playAt on the frame its predecessor hands over (end less its tail or the palette fade-out; exactly at the end for tail 0, gapless); - the outgoing fade and the palette's own end after `duration` are written on the clock (fadeOutAt + stopAt); nothing is drawn past the end frame; - the frame loop only keeps the books: promotions, retiring tails, a single-shot's end, and starting what follows the palette. Weights, repeats, order, once-entries, trims, tails, ME duck, the volume option, Fade In/Out BGM and stop all behave as before. A WebAudio without the scheduled API (a replacement class, a stub, no context) keeps the old frame path, which the existing bgm-sequence-runtime tests exercise. WebAudio gains fadeInAt and fadeOutAt. fadeOutAt always anchors its level with setValueAtTime: Chromium's cancelAndHoldAtTime inserts no event when no ramp is under way, so a ramp written next would start from the event before (measured on NW.js 0.120 / Chromium 157). The offline audio model's cancelAndHoldAtTime now follows the spec the same way, and a ramp with no earlier event starts when it is written. New tests: bgm-palette-clock (19), rendered at 48 kHz and held frame by frame to the palette rules; the same scenarios on Chromium's own OfflineAudioContext (tests/smoke/palette-clock-offline) come out within 5.5e-7, a one-frame shift 0.26-0.55. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ce (runtime 20261130.3) WebAudio._holdGain called cancelAndHoldAtTime(now) and the fade then wrote linearRampToValueAtTime(0, now + d). Per spec, and in Chromium, cancelAndHoldAtTime inserts an event only when a ramp is under way; on a param merely holding a value it adds nothing, and the ramp starts from the event before -- for a track's fade stage, the setValueAtTime(1) made when it started. Measured on NW.js 0.120 / Chromium 157: Fade Out BGM 0.3 s into a track dropped from 1.0 to 0.399 on its first frame; the master fade-out to 0.453. A 3 s fade a minute in started at about 5%. The hold now always anchors the level it read with setValueAtTime, as its fallback branch already did. Every fade-out through it is fixed at once: WebAudio.prototype.fadeOut (BGM/BGS/ME), the master _fadeOut, the plan bus. webaudio-fade-automation: two assertions spelled out the old call order; they now expect the anchor. New webaudio-fade-render (3 tests) renders the fades through the real AudioManager over the spec-correct offline model; with the old hold, two of them fail. tests/smoke/fade-render-offline runs them on Chromium's own OfflineAudioContext: 5e-7 fixed, 0.32 before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #102 (palette pools and palette layers on the context clock). This branch holds those two commits plus one of its own,
Audio: Fade Out BGM falls from where it is(runtime 20261130.3). Please review or merge that one first; once it is in, this pull request shows the one commit alone.It depends on it for its tests, not its fix: the one-line change to
WebAudio._holdGainwould apply to 0.99.8 by itself, butwebaudio-fade-render.test.cjsrenders through the offline audio model, and the model'scancelAndHoldAtTimeonly follows the spec (inserting no event when no ramp is under way, which is the case this bug lives in) since the palette change.The problem
Fade Out BGM (and BGS, ME, and the master fade a mobile page makes when hidden) did not fade from
the level the music was at. It dropped at once and then faded from there. The deeper into the
track, the bigger the drop. Measured on Chromium 157 (NW.js 0.120.0), the engine's own fades:
fadeOut(0.05), 12,800 frames inA 3 s Fadeout BGM a minute into a track starts at about 3 / 63 ≈ 5 % of its level: close to a cut.
A fade-out during a fade-in was fine, which is probably why nobody caught it: the case that
was measured and fixed earlier (the comment above
_holdGain) is exactly the one that works.Why
WebAudio._holdGaincalledcancelAndHoldAtTime(now), and the fade then wrotelinearRampToValueAtTime(0, now + d). Per the Web Audio spec, and in Chromium,cancelAndHoldAtTimeinserts an event only when a ramp is under way at that time (the ramp iscut to end there). When the param is simply holding a value, it inserts nothing. A linear ramp
starts from the previous event, which for a track's fade stage is the
setValueAtTime(1, <creation time>)made when the track started. So the ramp ran from the track's start to the endof the fade, and at "now" it was already most of the way down.
The plan player's bus was not affected: its fade stage has no earlier event, and a ramp with no
earlier event starts when it is written.
What changed
runtime/reactor_core_io.js,WebAudio._holdGainonly: it readsgain.valuefirst and, aftercancelAndHoldAtTime(orcancelScheduledValueswhere that is missing), always writessetValueAtTime(held, now). The fallback branch already did this; now both branches do. Everycaller benefits at once:
WebAudio.prototype.fadeOut(Fade Out BGM / BGS / ME,AudioManager.fadeOutBgm, the frame-pathpalette hand-overs, a track entry's
fadeOut);WebAudio._fadeOut(master, on a hidden mobile page);AudioManager._fadeOutBgmPlan(already right; still right).Fades in (
_restartGain) already set their value explicitly and are unchanged.Verification
Rendered (
editor/tests/webaudio-fade-render.test.cjs, 3 tests, all pass)The real
AudioManagerandWebAudioplay a 1 s track at 48 kHz over the modelOfflineAudioContext, whosecancelAndHoldAtTimefollows the spec since the palette change. Eachfade's output is held frame by frame to what the fade should sound like, at 1e-5. Each test also
checks that there is no step at the fade's first frame and silence after it.
With the old
_holdGainput back, tests 1 and 3 fail (worst 0.317 and 0.290 at the fade'sstart). Test 2 passes either way, as explained above.
On Chromium's own
OfflineAudioContext(measured)tests/smoke/fade-render-offline, run on this branch with the NW.js 0.120.0 SDK, Chromium 157.0.8103.39. "Old" is the same smoke run against the runtime of the palette branch, before this fix:One honest cost. During a running ramp, the anchor written is
gain.value. Chromium reportsit very slightly behind the ramp, so a fade-out started mid fade-in now begins with a step of
about 3e-5 (−90 dB). Before, it was exact there. It is far below hearing, and it is the price of
anchoring at all: Web Audio offers no way to ask whether a ramp is under way.
Tests on this branch (base 0.99.8, with the palette commits below it)
bgm-*,audio-*andwebaudio-*file (16 files, 216 tests),webaudio-fade-renderandwebaudio-fade-automationincluded: all pass.i18n,user-visible-i18n-routing,i18n-routing-audit(40) andruntime-manifest,audit-shell-sync-runtime,project-manager, which read the revision (35): all pass.sync-runtime.cjs --checkreportstemplate/Demo/jsin step withruntime/.webaudio-fade-automation.test.cjs: two assertions spelled out the old call order,[cancelAndHold, linearRamp], which is the bug. They now expect[cancelAndHold, setValueAtTime(held), linearRamp]. The other four are unchanged.npm run test:changedin four slices): 25 files fail, none of them an audio test. 23 are on the known Windows list as of 0.99.7: symlinks refused without Developer Mode, nozip, GNUtarreadingC:as a host, Linux-only AppImage tooling, POSIX fixture paths (database-sections,audit-3d-editor-workshop,media-surface-panel,rgss-port-screenshots,vehicles-starting-position,tactics-card-convert), and the RTP tests that readAPPDATA. The other two were checked on plain 0.99.8:distribution-stagingfails there in the same way, andcharacter-helper-threadsfailed only under 16 workers and passes when run alone on both trees.character-3d-creatures(a time budget) failed once under load and passed on its rerun.Limits
quickest check by ear: in a playtest, let a BGM play for a minute and use Fadeout BGM (3 s). It
should fall smoothly from full level instead of dipping at once.
_fadeGainNodeand relies on the old orderwould see the extra
setValueAtTime. None of the plugins this was checked against touches_holdGainorcancelAndHoldAtTime(searched).Changelog text for the next release
No
changelog/file:docs.test.cjsties the newest entry to the package version, and 0.99.8 is released.🤖 Generated with Claude Code