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
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:
seek(offset, whence) and tell() from the Python file object
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).
AudioFrame
has an internal marker to indicate how much data has been recorded into it already.This marker is moved via:
microphone.record()
andmicrophone.record_into()
AudioFrame
via indexes, egmy_audioframe[n]
AudioFrame.copyfrom()
methodAudioFrame
copy constructor or clone methodWe 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:
buffer_offset
parameter tomicrophone.record_into()
, then (https://github.com/microbit-foundation/micropython-microbit-v2/issues/197) it would be useful for cases like this:microphone.record_into(my_audioframe, buffer_offset=my_audioframe.get_position())
offset
parameter toAudioFrame.copyfrom()
(https://github.com/microbit-foundation/micropython-microbit-v2/issues/194), then it would be useful to understand where to continue from (af.copyfrom(buffer, af.get_position()
)In the case we'd like to implement this, we have a couple options:
seek(offset, whence)
andtell()
from the Python file objectset_position()
andget_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).