Skip to content

s3diag: microphone level meter is too noisy to read #76

Description

@iamankushpandit

Not needed by the firmware today — Braino has no feature that listens. Filed so the work is not lost, and because the microphone is already proven working on the Freenove FNK0104B and the next person to touch it should not rediscover the same noise problem.

Current state

pio run -e s3diag reads the ES8311 ADC over I2S and shows a live level meter plus a record-and-playback test. The capture path works: a 5-second recording plays back recognisably.

The level meter is unusably jittery. Observed with nothing in the room but a ceiling fan, the bar jumps constantly and never settles at zero.

Why

sampleMic() in src/s3_diag.cpp computes a plain RMS over a 128-frame block and scales it directly:

  • No DC removal. The ES8311 ADC carries a DC offset; squaring it puts a constant floor under every reading.
  • No smoothing. Each frame's RMS is displayed raw, so block-to-block variance shows as jitter.
  • No noise floor. Steady broadband room noise — a fan is close to ideal broadband plus low-frequency rumble — reads as signal, because nothing distinguishes "quiet room" from "quiet sound".

What would fix it

  1. DC block — subtract a running mean before squaring, or a one-pole high-pass at ~80 Hz, which also removes most of a fan's rumble.
  2. EMA smoothing on the displayed level, so the bar has a time constant instead of following every block.
  3. Noise-floor gate — track a slowly-decaying minimum as the room's floor and display the level relative to it, so a steady fan settles to zero while a clap still spikes. The floor must adapt up slowly and down quickly, or a loud room permanently desensitises the meter.
  4. Keep the existing echoPeak readout raw and unfiltered. It is the honest "did the ADC see anything at all" number and filtering it would hide exactly the failure it caught — see the reg17 finding in FNK0104B: no sound in the app, though the ES8311 codec works #71, where the peak was 1 count out of 32767.

Constraints

  • Static buffers only; no heap. See the memory rule in CLAUDE.md.
  • No float accumulation over long windows if it can be avoided — this is a diagnostic, but the same code is the obvious starting point if audio input ever reaches the firmware.

If audio input ever becomes a product feature

This stops being a diagnostic nicety. Note that CLAUDE.md's no-data-collection rule is absolute: a microphone that records is fine, a microphone whose output leaves the device is not. Exactly three things leave a Braino — an NTP query, one ip-api.com timezone lookup, and the opt-in BLE beacon — and that list is closed. Any feature that listens must process on-device only, and would need the maintainer's agreement in an issue before the code exists.

Related: #71 (ES8311 audio output support).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: P4Backlog - portability epic and the rename; sequence, do not parallelise

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions