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

`microbit.set_volume()` halves the value sent to `uBit.audio.setVolume()` #159

Closed microbit-carlos closed 2 months ago

microbit-carlos commented 11 months ago

https://github.com/microbit-foundation/micropython-microbit-v2/blob/eeb1db318df7d678dbc7063934efe4258eaa70ab/src/codal_app/microbithal_audio.cpp#L78-L84

And uBit.audio.setVolume() input range is 0 to 255: codal-microbit-v2/source/MicroBitAudio.cpp#L161-L169

int MicroBitAudio::setVolume(int volume)
{
    if (volume < 0 || volume > 255)
        return DEVICE_INVALID_PARAMETER;

    mixer.setVolume(volume*4);

    return DEVICE_OK;
}

And Synthesizer::setVolume() does take a value between 0 and 1023: codal-core/source/streams/Synthesizer.cpp#L277-L289

So in a programme like this, we can hear the volume drop:

from microbit import *
import music

music.pitch(440, duration=1000)
set_volume(255)
music.pitch(440, duration=1000)
dpgeorge commented 8 months ago

Should be fixed by a37bc963d23dc2fb39fd7998775db003b52bdf12

dpgeorge commented 3 months ago

This just needs testing @microbit-carlos

microbit-carlos commented 2 months ago

Can confirm this is now working, thanks Damien!