Skip to content

Commit 140c954

Browse files
committed
Merge branch 'feat/lower_the_audio_gain' into 'master'
feat(adc_mic): add adc mic apply gain config See merge request ae_group/esp-iot-solution!1291
2 parents 6f25eba + cb3ee85 commit 140c954

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ChangeLog
2+
3+
## v0.2.0 - 2024-05-22
4+
5+
### Enhancements:
6+
7+
* Add config ADC_MIC_APPLY_GAIN to apply gain to the ADC mic.
8+
9+
## v0.1.0 - 2024-05-22
10+
11+
### Enhancements:
12+
13+
* Initial version.

components/audio/adc_mic/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
menu "ADC Mic"
2+
3+
config ADC_MIC_APPLY_GAIN
4+
int "Apply Gain"
5+
default 3
6+
range 0 4
7+
help
8+
Apply gain to the ADC mic.
9+
0: No gain applied
10+
1: Left shift 1 bit (2x gain)
11+
2: Left shift 2 bits (4x gain)
12+
3: Left shift 3 bits (8x gain)
13+
4: Left shift 4 bits (16x gain)
14+
15+
config ADC_MIC_OFFSET
16+
int
17+
default 2048 if ADC_MIC_APPLY_GAIN = 0
18+
default 4095 if ADC_MIC_APPLY_GAIN = 1
19+
default 8190 if ADC_MIC_APPLY_GAIN = 2
20+
default 16380 if ADC_MIC_APPLY_GAIN = 3
21+
default 32760 if ADC_MIC_APPLY_GAIN = 4
22+
23+
endmenu

components/audio/adc_mic/adc_mic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int _adc_data_read(const audio_codec_data_if_t *h, uint8_t *data, int siz
138138
for (int i = 0; i < item_count; i++) {
139139
uint16_t raw_value = buffer[i].val;
140140
// Left shift to amplify audio.
141-
p[i] = (raw_value << 4) - 32768;
141+
p[i] = (raw_value << CONFIG_ADC_MIC_APPLY_GAIN) - CONFIG_ADC_MIC_OFFSET;
142142
}
143143

144144
cnt += ret_num;
@@ -154,7 +154,7 @@ static int _adc_data_read(const audio_codec_data_if_t *h, uint8_t *data, int siz
154154
for (int i = 0; i < item_count; i++) {
155155
uint16_t raw_value = buffer[i].val & 0xFFFF;
156156
// Left shift to amplify audio.
157-
p[i] = (raw_value << 4) - 32768;
157+
p[i] = (raw_value << CONFIG_ADC_MIC_APPLY_GAIN) - CONFIG_ADC_MIC_OFFSET;
158158
}
159159
cnt += ret_num / 2;
160160
left_size -= ret_num / 2;

components/audio/adc_mic/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.0"
1+
version: "0.2.0"
22
description: ADC mic input driver for ESP32 Series socs
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/audio/adc_mic
44
repository: https://github.com/espressif/esp-iot-solution.git

0 commit comments

Comments
 (0)