-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Since audioio has been reworked in 3.0, it now allocates two buffers of 512 bytes each when .play() is called on a file: https://github.com/adafruit/circuitpython/blob/master/shared-module/audioio/WaveFile.c#L102-L112
That is problematic for large programs that already use most of memory, because they can fail pretty much randomly at any moment due to memory fragmentation.
In 2.x, the buffers were allocated once, when the AudioInOut object was created:
https://github.com/adafruit/circuitpython/blob/2.x/atmel-samd/common-hal/audioio/AudioOut.c#L363-L375
What I would like to add is the ability to pass pre-allocated buffers (possibly even smaller than 512 bytes) that would be used for this — this way I can create them in advance at the beginning of the program, avoiding memory fragmentation, re-use them for playing different sounds, and even share with other functions that need buffers, such as SPI communication with the display (as long as they don't need them at the same time). Those parameters would be optional, and by default the buffers would be created as they are now.