Skip to content

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

@microbit-carlos

Description

@microbit-carlos

void microbit_hal_audio_set_volume(int value) {
if (value >= 255) {
uBit.audio.setVolume(128);
} else {
uBit.audio.setVolume(value / 2);
}
}

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions