microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

Should `microphone.record_into()` raise an error if the rate is <= 0 ? #203

Closed microbit-carlos closed 2 months ago

microbit-carlos commented 2 months ago

microphone.record() and AudioFrame raise errors if the rate is set to zero:

>>> microphone.record(1000, rate=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: rate out of bounds
>>> microphone.record(1000, rate=-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: rate out of bounds
>>> audio.AudioFrame(1000, rate=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: rate out of bounds
>>> audio.AudioFrame(1000, rate=-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: rate out of bounds

But microphone.record_into() doesn't:

>>> af = audio.AudioFrame()
>>> microphone.record_into(af, rate=0)
>>> microphone.record_into(af, rate=-1)
>>> 

I'm guessing 0 is the default value and in that case it'll use the AudioFrame rate. If that's the case, should the default value be changed to None? (similar to https://github.com/microbit-foundation/micropython-microbit-v2/issues/186#issuecomment-2075036123)

dpgeorge commented 2 months ago

I'm guessing 0 is the default value and in that case it'll use the AudioFrame rate. If that's the case, should the default value be changed to None?

That's correct, the default is 0.

Now changed so the default is None.