fix(audio): resolve ES7210 microphone popping sound by correcting OSR and clock division configuration

This commit is contained in:
Adolfo Reyna
2026-06-18 22:38:47 -04:00
parent 9eca3549c3
commit d778391c5c
7 changed files with 212 additions and 77 deletions
+14 -6
View File
@@ -366,19 +366,20 @@ def main():
except Exception as e:
print("Failed to set mic gain:", e)
# 2. Configure I2S RX for recording (Mono 16kHz)
# 2. Configure I2S RX for recording (Stereo 16kHz — ES7210 outputs stereo)
i2s_rx = I2S(1,
sck=Pin(board_config.audio_i2s_sck),
ws=Pin(board_config.audio_i2s_ws),
sd=Pin(board_config.audio_i2s_rx_sd),
mode=I2S.RX,
ibuf=8000,
ibuf=16000,
rate=16000,
bits=16,
format=I2S.MONO)
format=I2S.STEREO)
total_data_bytes = 0
buffer = bytearray(1024)
buffer = bytearray(2048)
mono_buf = bytearray(1024) # Half size for mono extraction
rec_start_time = time.ticks_ms()
max_rec_duration_ms = 10000 # 10 seconds max duration
@@ -395,8 +396,15 @@ def main():
# Read I2S chunk
bytes_read = i2s_rx.readinto(buffer)
if bytes_read > 0:
f.write(buffer[:bytes_read])
total_data_bytes += bytes_read
# Stereo-to-mono: extract left channel (every other 16-bit sample)
mono_len = bytes_read // 2
j = 0
for i in range(0, bytes_read, 4):
mono_buf[j] = buffer[i]
mono_buf[j + 1] = buffer[i + 1]
j += 2
f.write(mono_buf[:mono_len])
total_data_bytes += mono_len
except Exception as e:
print("Error recording:", e)
finally: