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: PCMOutput

Playback through machine.I2S (or any object with write).

machine.I2S cannot report how much of its ring is filled, and the inherited queued_size() == 0 told 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 blocking write() 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_size says 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. PaceOutput keeps the remainder.

queued_size()[source]

Estimate the bytes still queued for the DAC.

machine.I2S can’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.

service()[source]

Per-tick housekeeping. Queued hosts override; default is a no-op.

class audiodev.i2s_audio.I2SPCMInput(i2s, format, **kwargs)[source]

Bases: PCMInput

Capture through machine.I2S (or any object with readinto).

audiodev.i2s_audio.pcm_out(i2s, format, **kwargs)[source]

Build an I2SPCMOutput around i2s (instance or factory).

wire= (the board’s I2SWire) and audio_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 I2SPCMInput around i2s (instance or factory).