-
Notifications
You must be signed in to change notification settings - Fork 43
Description
I have made a WAV music player based on RP2 and asyncio. Because of the issue with allocations I am using the nonblocking I2S driver with a two phase buffer.
I can calculate the size of these buffers based on measurements of blocking: SD card read time and display refresh. The buffers need to be large enough to keep the I2S driver fed during the blocking period plus a margin. This led to a pair of 16KiB buffers.
Where I am puzzled is how to calculate the size of the I2S buffer. I am currently using 10KiB which works fine, but I would like to understand the basis for defining this. When the IRQ occurs my code switches to the second audio buffer and issues an I2S write in under 1ms. This might indicate a smaller buffer - but what other considerations apply?
[EDIT]
Official docs
It might be good if the docs gave some hints on sizing this buffer - the examples offer a wide range of sizes up to 40KiB.
It is not self-evident that the nonblocking driver continues to access the user buffer after the write has occurred. The naive user might assume that write transfers the contents of the user buffer to the driver's buffer; they might then start refilling the user buffer. In fact it is not safe to modify the user buffer until the IRQ occurs.