Skip to content

AudioFrame doesn't accept negative indexes or slices #188

Closed
@microbit-carlos

Description

@microbit-carlos

Tested with v2.1.2 and the latest version (at the time of writing) of the recording & playback branch: 0b06914

We can use positive array indexes to access and modify the data inside an AudioFrame, but not a negative index to access.

>>> af = audio.AudioFrame()
>>> af[len(af) - 1] = 123
>>> af[-1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: index out of bounds
>>> af[1:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert slice to int
>>> af[1:2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert slice to int
>>> 

Technically we could use a memoryview for this, but it's not a well know feature, so even if we documented well and add it to the examples it might not be used as much.
We also have issue #187 released to memoryview.

If we wanted to enabled this for AudioFrame we should probably enable it for V1 as well. Is the performance/size penalty for this significant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions