audiodev.i2s_audio
MCU I2S adapter: wrap machine.I2S as audiodev.PCMOutput / PCMInput.
- class audiodev.i2s_audio.I2SPCMOutput(i2s, format, *, wire=None, audio_power=None, **kwargs)[source]
Bases:
PCMOutputPlayback through
machine.I2S(or any object withwrite).machine.I2Scannot report how much of its ring is filled, and the inheritedqueued_size() == 0told the pump’s backpressure that the queue was always empty - so every service call rendered its full catch-up allowance and paid for it inside blockingwrite()calls at realtime speed (measured 88-160ms per service on the ESP32-P4, which starved LVGL and made every interaction stutter). DMA consumption is exactly realtime, so a software byte-clock - bytes written minus rate x elapsed - reports the queue well enough for backpressure. It is an estimate;queued_sizesays how far it can be off.On open, a POLL ioctl flips the driver to asyncio mode so
write()returns a partial/zero count instead of holding the GIL until DMA has room.PaceOutputkeeps the remainder.- queued_size()[source]
Estimate the bytes still queued for the DAC.
machine.I2Scan’t say how full its DMA ring is, so this is a byte clock: bytes written minus the rate times the time since the first write. While the stream is kept fed it holds. On an ESP32-P4, refilled every 10-40 ms for 90 s, it stayed within 11 ms of what a refill found had played (median 1 ms), with no drift. Each time the ring runs dry, the clock clamps at zero and doesn’t match the DMA exactly when it restarts. Over a long stream with frequent underruns it can read well above the real fill: in a 60 s intercom run with about 12 underruns a minute it read 150-240 ms while the ring held under 100 ms. Treat it as an upper bound for backpressure, not as a latency measurement.
- class audiodev.i2s_audio.I2SPCMInput(i2s, format, **kwargs)[source]
Bases:
PCMInputCapture through
machine.I2S(or any object withreadinto).
- audiodev.i2s_audio.pcm_out(i2s, format, **kwargs)[source]
Build an
I2SPCMOutputaround i2s (instance or factory).wire=(the board’sI2SWire) andaudio_power=(its power role) are what let the audio pump take the peripheral over on esp32. Leave them out and the board plays the old way.
- audiodev.i2s_audio.pcm_in(i2s, format, **kwargs)[source]
Build an
I2SPCMInputaround i2s (instance or factory).