Muse Proto: Simple Speaker, unable to set volume

Hello :wave:,

First, @Raspiaudio team, your work is :star_struck: ( :star: :star: :star: :star: :star:)

I try to use ESP MUSE proto with espressif framework. I gather some code from your various examples using arduino framework and also from squeezelight repository but i can’t figure out how to set volume up.

I try to make this example as simple as possible, it come from espressif get-started package.
I simply add (from espressif template) a custom board matching ESP Muse proto specification from informations i gather in various example.

Everything is working smooth, except than i can’t set volume level.
Following, the source code example, working with espressif esp-adf-v2.4

Can someone help me ?
Thanks for any help!

Hello and thank you for your encouragement !

Muse Proto volume should be controlled by software, so it is really depending on the library you are using but all of them have usually volume for example look at this old example for Proto :

or this one that is the Mn Cast but is more up to date and uses the same volume control :
mangaTEST/MangaTEST.ino at main · RASPIAUDIO/mangaTEST · GitHub (line 284)

Thanks a lot for your answer.

I try to have a look :eyes: as soon as i find some time .

I keep you informed and will post you feedback.

Thanks again :pray:

Hello,

So i finally got something working.
Not sure it’s the best software design choice :man_shrugging:
I add a callback function inside the stream audio pipeline to set volume directly on the datastream. I use normally function to set and get volume level and i query this information from callback.

It seem to work as wanted but I still have some code chunk that puzzling me.


int16_t Gain(int16_t s, int vol) {
    int32_t v = 0;
    v= (s * vol) >> 6;
    return (int16_t)(v & 0xffff);
}

int mp3_music_volume(audio_element_handle_t el, char *buf, int len, TickType_t wait_time, void *ctx)
{
    size_t bytes_written = 0;
    uint16_t test = 0;
    int vol = 0; 
    audio_board_handle_t board_handle = (audio_board_handle_t)ctx;
    audio_hal_get_volume(board_handle->audio_hal, &vol);
    memset(m_lastSample, 0, len);
   
    for(size_t i = 1; i < len; i+=2 ){
        test = (buf[i] << 8) + buf[i + 1];
        m_lastSample[i/2] = Gain(test, vol);
    }
    i2s_write(0, m_lastSample, len, &bytes_written, portMAX_DELAY);  

	return bytes_written;
}

If i start the loop on first buffer element, i just get white noise.
I don’t get what i miss, may be some casting from 16 to 32 bits :man_shrugging:

Do you know if some board component from adf repositoy could match any of muse proto or muse luxe board ?

Anyway, Thanks :pray: for your help,