Skip to content

fix(useMicrophone): reset level to 0 on stop() - #213

Merged
childrentime merged 1 commit into
childrentime:mainfrom
ostapondo:fix/microphone-level-reset
Jul 30, 2026
Merged

fix(useMicrophone): reset level to 0 on stop()#213
childrentime merged 1 commit into
childrentime:mainfrom
ostapondo:fix/microphone-level-reset

Conversation

@ostapondo

Copy link
Copy Markdown
Contributor

Description

After stop(), useMicrophone leaves level frozen at the last value it
measured instead of dropping to 0.

teardownAudioGraph() cancels the rAF loop, disconnects the source and nulls the
analyser — but that loop is the only writer of level, so whatever it read on
the final frame stays in state indefinitely. A volume meter bound to level
keeps showing input after the microphone has been released, which reads as "still
recording" to the user.

Easy to see in the demo: talk into the mic until the bar moves, hit stop, and the
bar stays where it was.

One line in teardownAudioGraph(). It also covers the device-switch path, where
the graph is torn down and rebuilt — the meter now resets instead of briefly
showing the old device's level against the new stream.

Type of Change

  • Bug fix
  • New hook
  • Enhancement to existing hook
  • Documentation update
  • Other (please describe)

Checklist

  • I have read the Contributing Guide
  • My code follows the project's coding style
  • I have added tests for my changes
  • All existing tests pass
  • I have updated the documentation

No doc change — this is the behaviour the docs already imply.

The new test sits next to clears the analyser when stop() is called, which
covers the analyser but never looked at level. It uses the existing mock
harness in that file and fails on main with 0.9921875 instead of 0.

teardownAudioGraph() cancels the rAF loop, which is the only writer of
`level`, so after stop() the value stays frozen at whatever the last
frame measured. A meter bound to it keeps showing input long after the
microphone has been released.
@childrentime
childrentime merged commit ae9363e into childrentime:main Jul 30, 2026
5 checks passed
@childrentime

Copy link
Copy Markdown
Owner

Thanks @ostapondo! A one-liner in exactly the right place — putting the reset in teardownAudioGraph() means stop, device-switch, and mic-disconnect all zero the meter for free. Nice spot that the existing analyser test never looked at level. Merged 🎉

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