Skip to content

webtools: record why the AudioContext resume is needed, with the measurement - #83

Merged
mormegil6 merged 2 commits into
EnvelopSound:masterfrom
mormegil6:gainslider-comment
Aug 22, 2026
Merged

webtools: record why the AudioContext resume is needed, with the measurement#83
mormegil6 merged 2 commits into
EnvelopSound:masterfrom
mormegil6:gainslider-comment

Conversation

@mormegil6

Copy link
Copy Markdown
Collaborator

The audioContext.resume() in setGain landed in #64. This adds the reasoning directly above it.

video.js constructs the AudioContext at module-import time, before any user gesture, so a browser enforcing an autoplay policy hands it back suspended and the whole graph is stopped. Unmuting the element and raising a gain then change nothing audible, which is exactly what a user dragging the slider experiences: no sound and no clue why.

Measured on a live 16-channel stream, each step added alone (RMS into ctx.destination):

step RMS
gain up 0.0
+ element unmuted 0.0
+ resume() 5.6e-4

Only the resume makes it audible.

Comment only, no behaviour change. The reason for sending it: a bare resume() with no explanation reads as defensive boilerplate and invites removal, and the next person to hit this would have to measure it again.

…urement

The resume itself landed in EnvelopSound#64. This adds the reasoning above it, so the
next reader does not have to rediscover it: video.js builds the
AudioContext at module-import time, before any user gesture, so an
autoplay-policy browser hands it back suspended and the whole graph is
stopped. Unmuting the element and raising a gain then change nothing
audible, which is exactly what a user dragging the slider experiences.

Measured on a live 16-channel stream, each step added alone (RMS into
ctx.destination): gain up 0.0, plus element unmuted 0.0, plus resume()
5.6e-4. Only the resume makes it audible.

Without this note a bare resume() call reads as defensive boilerplate and
invites removal.
Copilot AI lite review requested due to automatic review settings August 22, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explanatory comment in GainSliderBox.setGain() documenting why audioContext.resume() is required when the AudioContext is created before a user gesture (autoplay policy), including a brief measurement showing the audible effect.

Changes:

  • Document the autoplay-policy “suspended” AudioContext root cause in setGain
  • Record measured RMS impact demonstrating that resume() is the step that restores audibility
  • Clarify why setGain (user gesture path) is the appropriate place to resume the context

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread webtools/src/GainSliderBox.js Outdated
// Video.js constructs the AudioContext at module-import time, which is
// before any user gesture, so browsers with an autoplay policy hand it back
// "suspended" and the whole graph is stopped. Unmuting the element and
// raising a gain then change nothing audible, which is exactly what a user
'then change' put the adverb between a compound subject and its verb,
which reads as a disagreement even though it is not one.
@mormegil6

Copy link
Copy Markdown
Collaborator Author

The subject there is compound ("unmuting the element and raising a gain"), so the plural verb agrees and "changes" would be the error.

It does read badly though, because then sits between the subject and its verb. Reworded in 0c2244b to "do nothing audible on their own", which avoids the question entirely.

@mormegil6
mormegil6 merged commit 81d5511 into EnvelopSound:master Aug 22, 2026
4 checks passed
@mormegil6
mormegil6 deleted the gainslider-comment branch August 22, 2026 20:28
mormegil6 added a commit to mormegil6/Earshot that referenced this pull request Aug 22, 2026
Both PRs were cut from this fork, so their changes arrive as conflicts
against the local copies they were taken from. Upstream's side wins in
all three: it is the same change plus the content-type line that review
added. The deployment-only patches in these files are untouched.
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.

2 participants