Skip to content

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

Closed
ostapondo wants to merge 1 commit into
childrentime:mainfrom
ostapondo:fix/microphone-level-reset
Closed

fix(useMicrophone): reset level to 0 on stop()#209
ostapondo wants to merge 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.

@ostapondo
ostapondo force-pushed the fix/microphone-level-reset branch from 6a4a838 to 9bed248 Compare July 29, 2026 13:49
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.
@ostapondo
ostapondo force-pushed the fix/microphone-level-reset branch from 9bed248 to 4a9393d Compare July 29, 2026 13:51
@ostapondo ostapondo closed this by deleting the head repository Jul 29, 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