microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

`AudioFrame` with a small rate can result in a size of zero #200

Closed microbit-carlos closed 2 months ago

microbit-carlos commented 2 months ago
>>> len(AudioFrame(1000, 1))
32
>>> len(AudioFrame(999, 1))
0
>>> len(AudioFrame(1, 1))
0
>>> 

Likely the integer division flooring (well, rounding towards zero) from: https://github.com/microbit-foundation/micropython-microbit-v2/blob/c91ae4e83c5a1a82f647740277f7d4a462192160/src/codal_port/modaudio.c#L334

dpgeorge commented 2 months ago

I have changed the code to ensure that the size is always at least 32 bytes.

microbit-carlos commented 2 months ago

Great, thanks Damien!

microbit-carlos commented 2 months ago

I have changed the code to ensure that the size is always at least 32 bytes.

Using a small duration or rate can still create an AudioFrame with less than 32 bytes:

>>> len(AudioFrame(1000, 1))
1
>>> len(AudioFrame(1, 1))
1
>>> 
dpgeorge commented 2 months ago

Using a small duration or rate can still create an AudioFrame with less than 32 bytes:

This is intended.

Now that the code supports arbitrary byte lengths (ie no longer a multiple of 32), it's possible to create frames all the way down to 1 byte in size.

microbit-carlos commented 2 months ago

Sounds good, thanks Damien!