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
Speaker volume control
Re: Speaker volume control
audio_hal_set_volume(board_handle->audio_hal, 100);
Re: Speaker volume control
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);
- parabuzzle
- Posts: 1
- Joined: Fri Jun 16, 2023 5:15 pm
Re: Speaker volume control
If you're attempting to use ALC you have to enable it on the i2s stream writer:
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)
so to make it half volume you call this:
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:
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.
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);
If you review the docs (https://docs.espressif.com/projects/esp ... _handle_ti)
So 0 is file volume level.. if you want it quieter you go into the negative where -64 is muteSupported range [-64, 63], unit: dB
so to make it half volume you call this:
Code: Select all
i2s_alc_volume_set(i2s_stream_writer, -32);
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);
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 19 guests