Skip to content

audioio allocates extra 2*512 bytes of ram on play in CP 3.0Β #886

@deshipu

Description

@deshipu

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions