-
Notifications
You must be signed in to change notification settings - Fork 29
AudioFrame.copyfrom()
should move the internal used_size
marker
#190
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
Comments
AudioFrame
copyfrom()
should move the internal used_size
markerAudioFrame.copyfrom()
should move the internal used_size
marker
Copying comment #163 (comment) here: This needs discussion. copyfrom() actually allows copying from any object with the buffer protocol (eg bytes, memoryview) and they won't necessarily have the used_size attribute. This method should probably just set used_size to the total bytes copied fro the buffer-like object. The only issue there is copying from another AudioFrame it will copy the total allocated size, not the used_size, of the other AudioFrame. |
Yes, I think So, if we start with a long The question would be, do we special-case copying from another af_long = audio.AudioFrame(duration=5000)
af_short = audio.AudioFrame(duration=2000)
microphone.record_into(af_short, wait=False)
sleep(1000) # Record for only 1 second, af_short is only half filled
microphone.stop_recording()
In my opinion, for a user option 1. and 3. make most sense for easy-of-use. Option 2. is not too bad, as it makes sense if you already know about the marker, however I think it's a lot more likely that the users would want 1 second playback instead of 2, so making that default makes sense. From options 1. and 3. , I'm a lot more inclined on option 1., because option 3. limiting how much data is copied doesn't feel quite right. This might also need to be discussed with #194 in mind, as one of the suggestions is to add an extra argument to have af_long = AudioFrame(duration=5000)
af_short = AudioFrame(duration=2000)
while True:
if button_a.is_pressed():
microphone.record_into(af_short, wait=False)
while button_a.is_pressed():
pass
microphone.stop()
af_long.copyfrom(af_short, index=af_long.get_position())
if button_b.is_pressed():
audio.play(large_af)
sleep(200) So in these cases we would need to make sure that when calculating the |
This can be separated in two parts:
So, 1. can be implemented already, and 2 will be considered as part of the new proposal: |
We've changed the implementation and the new audio objects do not have an "internal marker": |
Using the latest version (at the time of writing) of the recording & playback branch: 0b06914
Hex: https://github.com/microbit-foundation/micropython-microbit-v2/actions/runs/8416237764?pr=163
If we manually edit the last byte in
b
it then does play a short clip:The text was updated successfully, but these errors were encountered: