From 1d48a5fc1da72d56b820b94d4ad7d8338fdb5703 Mon Sep 17 00:00:00 2001 From: ainyan03 <205502311+ainyan03@users.noreply.github.com> Date: Wed, 2 Sep 2026 01:49:34 +0000 Subject: [PATCH 1/2] StopWatch: rework the ES8311 capture gain structure The capture path took all its gain after the ADC: analog PGA at 0 dB with +32 dB of ADC digital volume, which amplified the noise floor along with the signal and clipped loud input early (white noise and flattened waveforms in recordings). Move the gain to the analog side and trim the digital stage: - 0x14: analog PGA 0 dB -> +21 dB (gain code 7, 3 dB/code; the measured SNR plateaus by this level, limited by the mic element) - 0x17: ADC digital volume +32 dB -> +6 dB - 0x1C: HPF stage-2 coefficient 10 -> 4. The dynamic HPF was already enabled by the old value; the new coefficient cuts sub-200 Hz rumble at the default 16 kHz rate (silence rms 312 -> 52) Measured result: SNR 14.6 dB -> ~19 dB against a 440 Hz reference. The reset-witness comparison follows the 0x17 bulk value (0xCB). --- src/M5Unified.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/M5Unified.cpp b/src/M5Unified.cpp index 8467a60c..6f3f14dd 100644 --- a/src/M5Unified.cpp +++ b/src/M5Unified.cpp @@ -1289,9 +1289,9 @@ static constexpr const uint8_t _pin_table_mbus[][31] = { 2, 0x02, 0x18, // 0x02 CLOCK_MANAGER/ MULT_PRE=3 2, 0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry 2, 0x0E, 0x02, // 0x0E SYSTEM/ : Enable analog PGA, enable ADC modulator - 2, 0x14, 0x10, // ES8311_ADC_REG14 : select Mic1p-Mic1n / PGA GAIN (minimum) - 2, 0x17, 0xFF, // ES8311_ADC_REG17 : ADC_VOLUME (MAXGAIN) // (0xBF == ± 0 dB ) - 2, 0x1C, 0x6A, // ES8311_ADC_REG1C : ADC Equalizer bypass, cancel DC offset in digital domain + 2, 0x14, 0x17, // ES8311_ADC_REG14 : select Mic1p-Mic1n / analog PGA +21 dB (gain code 7, 3 dB/code; SNR plateaus by this level) + 2, 0x17, 0xCB, // ES8311_ADC_REG17 : ADC_VOLUME +6 dB (0xBF == 0 dB, 0.5 dB/step) + 2, 0x1C, 0x64, // ES8311_ADC_REG1C : ADC EQ bypass, dynamic HPF, HPF stage-2 coeff 4 (cuts sub-200 Hz rumble at the default 16 kHz rate) 0 }; static constexpr const uint8_t disabled_bulk_data[] = { @@ -1310,7 +1310,7 @@ static constexpr const uint8_t _pin_table_mbus[][31] = { { /// 0x17 loses the value a previous setup wrote on any codec reset, /// so it witnesses a reset done outside this library: re-arm then. uint8_t v = 0; - if (!M5.In_I2C.readRegister(es8311_i2c_addr0, 0x17, &v, 1, 100000) || v != 0xFF) + if (!M5.In_I2C.readRegister(es8311_i2c_addr0, 0x17, &v, 1, 100000) || v != 0xCB) { es8311_capture_armed.store(false, std::memory_order_release); } From 5ad46f822d5779fa4607e8508a7bc4da77250526 Mon Sep 17 00:00:00 2001 From: ainyan03 <205502311+ainyan03@users.noreply.github.com> Date: Wed, 2 Sep 2026 01:49:34 +0000 Subject: [PATCH 2/2] StopWatch: reduce the ES8311 DAC digital volume from +24 dB to +6 dB The speaker enable procedure set DAC volume (reg 0x32) to 0xEF (+24 dB). Since digital gain ahead of the DAC cannot raise the full-scale ceiling, this only moved the clipping point down: any sample above 1/16 of full scale clipped hard, so master volumes above ~64 turned a sine wave into a buzzer-like square wave without getting any louder. Measured with a two-device sweep (StopWatch playing a 1 kHz tone, CoreS3 microphone running a Goertzel harmonic analysis): - clipping onset by 0x32 value: 0xEF = vol 64-128, 0xDF = 128-192, 0xCF = 192-255, 0xBF = none up to 255 - 0xEF at vol 64 and 0xBF at vol 255 produce the same acoustic level, confirming +24 dB adds no loudness - 0xCB (+6 dB) reaches DAC full scale right at vol 255: fundamental rises monotonically 20/100/222/300/380 (vol 64/128/192/224/255) with no 3rd-harmonic explosion, and its maximum clean output is about double the old clean ceiling 0xCB therefore maximizes clean output while removing digital clipping from the entire master volume range. ChainCaptain shares the same 0xEF value but is left unchanged (no hardware at hand to verify). --- src/M5Unified.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/M5Unified.cpp b/src/M5Unified.cpp index 6f3f14dd..8d263913 100644 --- a/src/M5Unified.cpp +++ b/src/M5Unified.cpp @@ -715,7 +715,7 @@ static constexpr const uint8_t _pin_table_mbus[][31] = { 2, 0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry 2, 0x12, 0x00, // 0x12 SYSTEM/ power-up DAC - NOT default 2, 0x13, 0x10, // 0x13 SYSTEM/ Enable output to HP drive - NOT default - 2, 0x32, 0xEF, // 0x32 DAC/ DAC volume (0xBF == ±0 dB ) + 2, 0x32, 0xCB, // 0x32 DAC/ DAC volume +6 dB (0xBF == 0 dB, 0.5 dB/step). Reaches full-scale at max master volume; higher values clip digitally without adding loudness 2, 0x37, 0x08, // 0x37 DAC/ Bypass DAC equalizer - NOT default 0 };