Skip to content

Spectrum meter levels computed in the UAC pump task - #50

Merged
bdbarnett merged 1 commit into
mainfrom
spike/audio-meter
Sep 26, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
spike/audio-meter

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Adds uac_pump_meter(bands, lo_hz, hi_hz) and uac_pump_levels([buf]): band levels computed where the sound card's bytes already pass. The C pump feeds each block it reads to usbif_meter.c, which runs two FFTs about 60 times a second and publishes one byte per band in half-dB steps. uac_pump_meter() with no arguments returns its cost counters.

It's the C half of the spectrum example (pydevices-examples lib/examples/spectrum, pump_levels.py). Proven on the ESP32-P4 panel on 2026-09-25, beside the sound card: the pump costs about 1 % of a 360 MHz core for the feed, and meter-on and meter-off USB delivery match to within 0.03 % once the panel's cache writeback is sliced. That setting landed as micropython-pydevices#23.

Not proven: an S3 build and run with the meter compiled in. The spike only ran on the P4.

uac_pump_meter(bands, lo_hz, hi_hz) turns on band levels computed where the
sound card's bytes already pass: the C pump feeds each block it reads to
usbif_meter.c, which runs two FFTs about 60 times a second (1024 points at the
host rate for the upper bands, 512 points on a 700 Hz low-passed copy
decimated by 16 for the bottom) and publishes one byte per band in half-dB
steps. uac_pump_levels([buf]) reads them under a sequence lock; with no
arguments uac_pump_meter() returns its cost counters.

Also moves the audio receive path (TinyUSB's DWC2 driver, usbd, the audio
class and its FIFO, and usbif's ISR hook) into IRAM with a linker fragment.
On its own that made no measurable difference to delivery; it stays because
the spike's numbers were taken with it.
@bdbarnett
bdbarnett merged commit 5b63fca into main Sep 26, 2026
12 checks passed
@bdbarnett
bdbarnett deleted the spike/audio-meter branch September 26, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant