embassy icon indicating copy to clipboard operation
embassy copied to clipboard

Revise the I2S driver interface.

Open liarokapisv opened this issue 9 months ago • 0 comments

Currently, the I2S driver is just a small wrapper over the SPI driver, just enabling the I2S-specific configuration and then delegating to the SPI read/write functionality.

I don't think this works good enough for the usual use-cases of the I2S driver, which is audio processing/streaming. In this domain, losing any sample results in catastrophic audio glitches. Usual sampling rates are 44.1/48 khz, but it's not unusual to also use 96 khz. The issue with the read/write interface is that it forces the user to re-start the DMA transfer, this means that we need to copy the DMA buffer and restart the DMA in under 20/10us in order for audio samples to not be lost and even that may not be possible due to the peripheral & DMA latencies.

The usual approach is to use DMA in circular mode and process on each half, this adds some configurable latency but allows for processing without losing any audio samples. This is not currently possible with the I2S driver. I think it would be better for the driver to only expose a circular ring-buffered interface similar to the RingBufferedUsart one. This avoids the footgun of using the read/write methods and leads the user to a more robust approach. Any thoughts are welcome!

liarokapisv avatar May 25 '24 10:05 liarokapisv