Speaker volume control

maxbraun
Posts: 1
Joined: Sat Dec 23, 2023 6:29 pm

Speaker volume control

Postby maxbraun » Sat Dec 23, 2023 7:15 pm

Hi!

I'm using an ESP32-S3-Korvo-2 (V3.1) and I was wondering how to adjust the speaker volume.

I'm able to run the pipeline_http_mp3 example (https://github.com/espressif/esp-adf/tr ... e_http_mp3) just fine. How would I adjust it to increase the volume?

I tried i2s_alc_volume_set(i2s_stream_writer, ...), but that call gives an error. I'm also not sure what values are valid.

Thanks!
Max

volksvorg
Posts: 3
Joined: Mon Feb 06, 2023 8:09 pm

Re: Speaker volume control

Postby volksvorg » Thu Jan 04, 2024 10:48 am

audio_hal_set_volume(board_handle->audio_hal, 100);

gyui21g
Posts: 4
Joined: Thu Mar 21, 2024 3:38 am

Re: Speaker volume control

Postby gyui21g » Sun Mar 31, 2024 2:20 pm

When making i2s_stream_writer initialization, configure the i2s_cfg.use_alc=true.

Code: Select all

ESP_LOGI(TAG, "[2.2] Create i2s stream to write data to codec chip");
    int player_volume=0;
    i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
    i2s_cfg.use_alc = true;
    i2s_cfg.volume = player_volume;
    i2s_cfg.type = AUDIO_STREAM_WRITER;
    i2s_stream_writer = i2s_stream_init(&i2s_cfg);

Linc08
Posts: 13
Joined: Mon May 20, 2024 7:54 am

Re: Speaker volume control

Postby Linc08 » Tue May 28, 2024 9:00 am

volksvorg wrote:
Thu Jan 04, 2024 10:48 am
audio_hal_set_volume(board_handle->audio_hal, 100);
This works for me! Thanks! :lol:

User avatar
parabuzzle
Posts: 1
Joined: Fri Jun 16, 2023 5:15 pm

Re: Speaker volume control

Postby parabuzzle » Sat Aug 31, 2024 2:46 pm

If you're attempting to use ALC you have to enable it on the i2s stream writer:

Code: Select all

i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.use_alc = true;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
Then when you call it to set the volume. You need to make make sure you are setting the volume properly.

If you review the docs (https://docs.espressif.com/projects/esp ... _handle_ti)
Supported range [-64, 63], unit: dB
So 0 is file volume level.. if you want it quieter you go into the negative where -64 is mute

so to make it half volume you call this:

Code: Select all

i2s_alc_volume_set(i2s_stream_writer, -32);
In my app I usually use 0 to 100 for volume so if you want to do that you can just convert it like this:

Code: Select all

float vol = -64.0 + 0.64 * volume; // volume is an int from 0 to 100
i2s_alc_volume_set(i2s_stream_writer, (int)vol);
This works well on all i2s streams and has no reliance on the HAL or special connections because the ALC adjustment is applied to the i2s stream data and mutates the bits to adjust gain level going to your DAC.

I hope this helps. The ADF is a bit of a tricky mess to figure out.

Who is online

Users browsing this forum: No registered users and 21 guests