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

With low rates, microphone.record_into() takes less time than expected #202

Open
microbit-carlos opened this issue Apr 24, 2024 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@microbit-carlos
Copy link
Contributor

microbit-carlos commented Apr 24, 2024

Similar to:

But in this case, I would not expect CODAL to be able to return early as it needs to record the expected length of audio before it returns.

With the default rate works as expected:

>>> af = audio.AudioFrame(100)
>>> t1 = running_time(); microphone.record_into(af); t2 = running_time(); t2-t1
101

With low enough rates with have issue #201 and it returns immediately:

>>> af = audio.AudioFrame(1000, rate=128)
>>> t1 = running_time(); microphone.record_into(af); t2 = running_time(); t2-t1
2
>>> bytes(af)
b'\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80'
>>> 

But with a rate of 256, data does go into the AudioFrame, but takes less time than expected:

>>> af = audio.AudioFrame(200, rate=256)
>>> len(af)
64
>>> t1 = running_time(); microphone.record_into(af); t2 = running_time(); t2-t1
162
>>> bytes(af)
b'\x81\x81\x80\x83\x81\x81\x80\x82\x81z~\x7f\x81\x81\x80\x7f\x80\x82~\x81\x80\x81\x80{|\x80\x80z\x85\x80\x80\x7f~~\x80\x81\x80\x83\x81\x85\x81\x82\x83\x82{|\x80{|\x82}\x80\x80\x80~\x82\x81}}\x7f|}\x80\x81'
>>> af.get_rate()
256
>>> 

I guess this could also be an issue in CODAL, if that's the case let me know and I'll raise it in the codal-microbit-v2 repository.

@microbit-carlos microbit-carlos added this to the 2.2.0-beta.1 milestone Apr 24, 2024
@microbit-carlos microbit-carlos added the bug Something isn't working label Apr 24, 2024
@microbit-carlos
Copy link
Contributor Author

I'll try to replicate this on CODAL first to check if this is an issue there.

@microbit-carlos microbit-carlos self-assigned this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant