The microphone peak level can go far above its documented 0...1 range

Open Beginner friendly
#497 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift

Research direction

Read CONTRIBUTING.md, then inspect Sources/UttrflowAudio/SampleAccumulator.swift:37-55 and :99-116 to trace peakLevel and momentaryLevel handling. Extend Tests/UttrflowAudioTests/SampleAccumulatorTests.swift with out-of-range, NaN, and infinite inputs, preserving the existing non-finite-sample test. Run make verify with the specified DEVELOPER_DIR; done means both levels remain in 0...1 and all tests pass.

Written by the indexing model from the issue text.

Description

area:dictation bug good first issue P2

What happens

SampleAccumulator.append (Sources/UttrflowAudio/SampleAccumulator.swift:43-47) skips NaN and infinite samples, but keeps any finite magnitude as the new peak. peakLevel is documented at line 99 as being in 0...1, yet a block containing Float.greatestFiniteMagnitude (about 3.4e38), or any sample above 1, sets the peak to that value. The momentary level is already protected against the same input by the isFinite check on the RMS at line 52.

Why it matters

The peak is what says afterwards whether the microphone was muted or clipping. A driver glitch or a converter bug that delivers an out-of-range sample leaves a nonsense peak that anything comparing against 1 will misread.

How to check

In Tests/UttrflowAudioTests/SampleAccumulatorTests.swift, append [Float.greatestFiniteMagnitude, 0.3] and read peakLevel: it is about 3.4e38, not a value in 0...1.

Acceptance criteria

  • peakLevel is always in 0...1, for any input, including values just above 1, huge finite values, NaN and infinities.
  • momentaryLevel stays in 0...1 for the same inputs (add an expectation if one is missing).
  • The existing tests, including "ignores a non-finite sample instead of pinning the meter", still pass.

Where to start

  • Sources/UttrflowAudio/SampleAccumulator.swift:37-55 and :99-116
  • Tests to extend: Tests/UttrflowAudioTests/SampleAccumulatorTests.swift.
  • Before pushing, run make verify (export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer first). It is the same command CI runs, and it enforces the 95% coverage floor per module.
  • Read CONTRIBUTING.md first, and say on this issue that you are taking it.

Size: S, about 1-2 hours.

Dominant language
Swift
Stars
4
Forks
17
Avg merge
18h 15m
Merged PRs (30d)
442

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uttrflow/uttrflow-swift

All issues in uttrflow/uttrflow-swift

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.