Skip to content

AudioFrame internal used_size marker accessors #196

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

Closed
microbit-carlos opened this issue Apr 12, 2024 · 2 comments
Closed

AudioFrame internal used_size marker accessors #196

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

Comments

@microbit-carlos
Copy link
Contributor

microbit-carlos commented Apr 12, 2024

AudioFrame has an internal marker to indicate how much data has been recorded into it already.

This marker is moved via:

We still need to document this in the docs, and having a document hidden feature without a way to access it is not ideal.

We were waiting for cases when having these accessors was beneficial, mostly following the general philosophy of "it's easier to add something later than it is to remove it or modify it".

Cases where we would have found these accessors useful:

  • When trying out the current API, the main cases were due to the bugs linked above
  • If we were to add the buffer_offset parameter to microphone.record_into(), then (Should microphone.record_into() have an additional duration and/or buffer_offset parameters? #197) it would be useful for cases like this:
    microphone.record_into(my_audioframe, buffer_offset=my_audioframe.get_position())
  • If we were to add an offset parameter to AudioFrame.copyfrom() (Effective way to get data in and out of an AudioFrame #194), then it would be useful to understand where to continue from (af.copyfrom(buffer, af.get_position())
  • Another useful case with the current API, is if we want to copy data into an AudioFrame already used and set the marker to the end of the copied data
    af = microphone.record(4000)
    af.copyfrom(other_audio_data)
    af.set_position(len(other_audio_data))

In the case we'd like to implement this, we have a couple options:

  1. seek(offset, whence) and tell() from the Python file object
  2. set_position() and get_position()
    • Or similar to this, but with a different word than "position"

Option 1) is more standard, but option 2) might be simpler to understand, and matches similar accessors already used in the micro:bit API.
So, my vote would be for option 2).

@microbit-carlos
Copy link
Contributor Author

While being able to provide accessors to the current implementation of AudioFrame will be beneficial, this new proposal would replace this suggestion:

@microbit-carlos
Copy link
Contributor Author

This has been superseded by:

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

1 participant