microbit-foundation / micropython-microbit-v2

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

`memoryview` of an `AudioFrame` returns signed 8-bit values #187

Closed microbit-carlos closed 5 months ago

microbit-carlos commented 5 months ago

Tested with v2.1.2 and the latest version (at the time of writing) of the recording & playback branch: https://github.com/microbit-foundation/micropython-microbit-v2/commit/0b06914c71c18533da90df85230ac198578669bf

>>> a = audio.AudioFrame()
>>> m = memoryview(a)
>>> a[0], m[0]
(128, -128)
>>> a[0] = 255
>>> a[0], m[0]
(255, -1)
>>> 

Compared with a bytes or bytearray object, where memory view values are 8-bit unsigned:

>>> b = bytes([128, 255])
>>> ba = bytearray([128, 255])
>>> m1 = memoryview(b)
>>> m2 = memoryview(ba)
>>> (b[1], m1[1]), (ba[1], m2[1])
((255, 255), (255, 255))
>>> 

Does AudioFrame change the values from unsigned to signed as a CODAL requirement?

microbit-carlos commented 5 months ago

@dpgeorge based on our conversation this is a bug that should be fixable without any (or minimal) effect on the current AudioFrame implementation.

dpgeorge commented 5 months ago

Now fixed.