Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioFrame doesn't accept negative indexes or slices #188

Closed
microbit-carlos opened this issue Apr 9, 2024 · 3 comments
Closed

AudioFrame doesn't accept negative indexes or slices #188

microbit-carlos opened this issue Apr 9, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@microbit-carlos
Copy link
Contributor

microbit-carlos commented Apr 9, 2024

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?

@microbit-carlos
Copy link
Contributor Author

This will be covered as well with this new proposal:

@microbit-carlos
Copy link
Contributor Author

No need to implement this in AudioFrame, just need to make sure it is in the AudioTrack implementation.

@dpgeorge
Copy link
Collaborator

dpgeorge commented Aug 5, 2024

AudioTrack's should now be able to be indexed with negative numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants