uttrflow / uttrflow/uttrflow-swift
The microphone peak level can go far above its documented 0...1 range
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 3h 32m
- Merged PRs (30d)
- 277
Description
## 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](https://github.com/uttrflow/uttrflow-swift/blob/main/CONTRIBUTING.md) first, and say on this issue that you are taking it.
**Size:** S, about 1-2 hours.
Contributor guide
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.
Assessment
- Tech stack
- swift
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100