3.5 KiB
Detection parity with the browser listener
Reference: django/frontend/src/scripts/burst-listener-worklet.js in the same project. The firmware processes each mono PCM sample with the same level-window and trigger state machine. The browser code was not changed.
| Behaviour | Browser reference | ESP32 firmware |
|---|---|---|
| Input | Float32 mono samples, nominally -1 to +1, at the AudioContext rate |
ES8311 16-bit stereo at 16 kHz; configured mic slot divided by 32768, then scaled by hardware calibration and the local sensitivity factor |
| Level window | round(sampleRate / 30) samples |
round(16000 / 30) = 533 samples |
| RMS / peak | Square root of mean squared samples; maximum absolute sample in window | Same calculation in normalised units |
| Starting baseline | 0.01 | 0.01 |
| Baseline update | 0.98 * baseline + 0.02 * min(rms, baseline * 2) while listening and not triggered |
Same |
| Trigger | After more than 1 s and more than 3 s since last trigger: rms > max(0.075, baseline * 5) and peak > 0.16 |
Same sample counts and strict comparisons |
| Tail / clip | 2 s tail, final clip is at most the latest 10 s | 2 s tail, up to 8 s preceding the trigger plus tail, maximum 10 s |
| Resume | User resumes or discards; clears ring and baseline, starts 3 s cooldown | Automatically resumes after saving to SD; clears ring and baseline, starts 3 s cooldown |
The prior firmware used 256-frame (16 ms) windows, independent RMS or peak gates, an RMS and peak noise estimate, 3 s boot warmup, 1.5 s cooldown, and 2.5 s before/after the trigger. Those rules have been removed from detection. Its offline queue, upload receipt checks, and WAV format are unchanged.
Hardware calibration
Shared browser constants are in boomcast_config.h. Hardware-only values are in boomcast_audio_calibration.h: the Waveshare example's ES8311 input gain is 45 dB, and the additional detection input multiplier starts at 1.0. The local sensitivity control scales the normalised detection input by setting / 55; its default 55 means unity. It does not alter the recorded WAV or browser thresholds. Change the hardware multiplier only after measuring representative ambient sound and fireworks on the actual V2 board. Avoid extra noise suppression, which could erase distant impulses.
The browser asks only for one channel in getUserMedia; it does not fix sample rate, echo cancellation, noise suppression, or automatic gain control. Browser support and selected values vary by device; MediaStreamTrack.getSettings() can expose the actual settings during a physical comparison. Safari/iPhone may apply processing that the ES8311 path does not. The browser's actual track settings and iPhone microphone level/clipping need a device measurement. The firmware's fixed mic slot, codec gain, acoustic response, and clipping also need verification with real V2 recordings. Equal PCM samples prove algorithm timing, not equal acoustic sensitivity.
Run PATH=/path/to/node:$PATH python -m unittest discover -s arduino/tests -p 'test_detector_parity.py' -v from the project root for deterministic traces. The test feeds identical 16-bit PCM samples to the compiled C++ detector and the actual unchanged browser worklet, comparing trigger, clip-start, and clip-end sample positions and final baseline across silence, a startup impulse, low-level kitchen activity, one impulse, repeated impulses, and overlap. Physical calibration remains separate.