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

`SoundEffect` with frequencies above 10 KHz don't make a sound #120

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

I'm guessing the frequency string format only takes 4 digits?

This works:

audio.play(audio.SoundEffect(
    freq_start=9999,
    freq_end=9999,
    duration=300,
    vol_start=255,
    vol_end=255,
))

But this doesn't make a sound:

audio.play(audio.SoundEffect(
    freq_start=10000,
    freq_end=10000,
    duration=300,
    vol_start=255,
    vol_end=255,
))

I think 10000 is likely converted to 0. As a SoundEfect like this sounds like it's going from high frequency to low frequency.

audio.play(audio.SoundEffect(
    freq_start=9999,
    freq_end=10000,
    duration=500,
    vol_start=255,
    vol_end=255,
))

Should we throw an exception or clamp for values >10K?

microbit-carlos commented 1 year ago

I haven't tried but I guess the same would be true for volume and duration.

dpgeorge commented 1 year ago

I'm guessing the frequency string format only takes 4 digits?

Yes that's correct. Most of the numbers (volume, frequency, duration) are limited to 4 digits.

Should we throw an exception or clamp for values >10K?

Implementing either of those is easy. Probably best to raise an exception.

microbit-carlos commented 1 year ago

Probably best to raise an exception.

Sounds good 👍

dpgeorge commented 1 year ago

Fixed by 0b7552643cb0ab78e511b0772beca2fe3b970833