From 58e2a3992b1a35d780dd55c0e1b2c138b47a0833 Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Fri, 21 Apr 2023 13:58:41 -0400 Subject: [PATCH 1/6] Some fixes for LyraT and also better inits/docs --- usermods/audioreactive/audio_source.h | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 088574d3..5f26f0ba 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -520,27 +520,30 @@ class ES8388Source : public I2SSource { void _es8388InitAdc() { // https://dl.radxa.com/rock2/docs/hw/ds/ES8388%20user%20Guide.pdf Section 10.1 + // http://www.everest-semi.com/pdf/ES8388%20DS.pdf Better spec sheet, more clear. Registries are decimal, settings are binary. // https://docs.google.com/spreadsheets/d/1CN3MvhkcPVESuxKyx1xRYqfUit5hOdsG45St9BCUm-g/edit#gid=0 generally // Sets ADC to around what AudioReactive expects, and loops line-in to line-out/headphone for monitoring. _es8388I2cBegin(); - _es8388I2cWrite(0x08,0x00); // I2S to slave - _es8388I2cWrite(0x02,0xf3); // Power down DEM and STM - _es8388I2cWrite(0x2b,0x80); // Set same LRCK - _es8388I2cWrite(0x00,0x05); // Set chip to Play & Record Mode - _es8388I2cWrite(0x0d,0x02); // Set MCLK/LRCK ratio to 256 - _es8388I2cWrite(0x01,0x40); // Power up analog and lbias - _es8388I2cWrite(0x03,0x00); // Power up ADC, Analog Input, and Mic Bias - _es8388I2cWrite(0x0a,0x50); // Use Lin2/Rin2 for ADC input ("line-in") - _es8388I2cWrite(0x09,0x00); // Select Analog Input PGA Gain for ADC to 0dB (L+R) - _es8388I2cWrite(0x10,0b01000000); // Set ADC digital volume attenuation to -32dB (left) - _es8388I2cWrite(0x11,0b01000000); // Set ADC digital volume attenuation to -32dB (right) - _es8388I2cWrite(0x04,0x0c); // Turn on LOUT2 and ROUT2 power - _es8388I2cWrite(0x02,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp" - _es8388I2cWrite(0x26,0x09); // Mixer - route LIN2/RIN2 to output - _es8388I2cWrite(0x27,0b01010000); // Mixer - route LIN to left mixer, 0dB gain - _es8388I2cWrite(0x2a,0b01010000); // Mixer - route RIN to right mixer, 0dB gain - _es8388I2cWrite(0x30,0b00011110); // LOUT2VOL - 0 = -45dB, 0b00011110 = +0dB - _es8388I2cWrite(0x31,0b00011110); // ROUT2VOL - 0 = -45dB, 0b00011110 = +0dB + _es8388I2cWrite( 8,0b00000000); // I2S to slave + _es8388I2cWrite( 2,0b11110011); // Power down DEM and STM + _es8388I2cWrite(43,0b10000000); // Set same LRCK + _es8388I2cWrite( 0,0b00000101); // Set chip to Play & Record Mode + _es8388I2cWrite(13,0b00000010); // Set MCLK/LRCK ratio to 256 + _es8388I2cWrite( 1,0b01000000); // Power up analog and lbias + _es8388I2cWrite( 3,0b00000000); // Power up ADC, Analog Input, and Mic Bias + _es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input ("line-in") + _es8388I2cWrite( 9,0b00000000); // Select Analog Input PGA Gain for ADC to 0dB (L+R) + _es8388I2cWrite(16,0b01000000); // Set ADC digital volume attenuation to -32dB (left) + _es8388I2cWrite(17,0b01000000); // Set ADC digital volume attenuation to -32dB (right) + _es8388I2cWrite( 4,0b00111100); // Turn on LOUT1 and ROUT1 and LOUT2 and ROUT2 power + _es8388I2cWrite( 2,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp" + _es8388I2cWrite(38,0b00001001); // Mixer - route LIN2/RIN2 to output + _es8388I2cWrite(39,0b10010000); // Mixer - route LIN to mixL, 0dB gain was 01.. + _es8388I2cWrite(42,0b10010000); // Mixer - route RIN to mixR, 0dB gain was 01.. + _es8388I2cWrite(46,0b00011110); // LOUT1VOL - 0 = -45dB, 0b00011110 = +0dB + _es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0 = -45dB, 0b00011110 = +0dB + _es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0 = -45dB, 0b00011110 = +0dB + _es8388I2cWrite(49,0b00011110); // ROUT2VOL - 0 = -45dB, 0b00011110 = +0dB } public: From 0fd95968601021eddc3d720384b647676565d1a5 Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Sat, 22 Apr 2023 08:35:03 -0400 Subject: [PATCH 2/6] Fixes for LyraT --- usermods/audioreactive/audio_source.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 5f26f0ba..29f938ce 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -538,8 +538,8 @@ class ES8388Source : public I2SSource { _es8388I2cWrite( 4,0b00111100); // Turn on LOUT1 and ROUT1 and LOUT2 and ROUT2 power _es8388I2cWrite( 2,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp" _es8388I2cWrite(38,0b00001001); // Mixer - route LIN2/RIN2 to output - _es8388I2cWrite(39,0b10010000); // Mixer - route LIN to mixL, 0dB gain was 01.. - _es8388I2cWrite(42,0b10010000); // Mixer - route RIN to mixR, 0dB gain was 01.. + _es8388I2cWrite(39,0b01010000); // Mixer - route LIN to mixL, 0dB gain + _es8388I2cWrite(42,0b01010000); // Mixer - route RIN to mixR, 0dB gain _es8388I2cWrite(46,0b00011110); // LOUT1VOL - 0 = -45dB, 0b00011110 = +0dB _es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0 = -45dB, 0b00011110 = +0dB _es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0 = -45dB, 0b00011110 = +0dB From 00e3f5e5fa1d32d0f139d671c910ce5bf1e7b564 Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:45:09 -0300 Subject: [PATCH 3/6] Mic settings for ES8388. Also ALC, pass-thru, etc. --- usermods/audioreactive/audio_source.h | 56 ++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 29f938ce..2e58a348 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -531,19 +531,59 @@ class ES8388Source : public I2SSource { _es8388I2cWrite(13,0b00000010); // Set MCLK/LRCK ratio to 256 _es8388I2cWrite( 1,0b01000000); // Power up analog and lbias _es8388I2cWrite( 3,0b00000000); // Power up ADC, Analog Input, and Mic Bias + _es8388I2cWrite( 4,0b11111100); // Power down DAC, Turn on LOUT1 and ROUT1 and LOUT2 and ROUT2 power + _es8388I2cWrite( 2,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp" + + // #define use_es8388_mic + + #ifdef use_es8388_mic + // Pick one. If you have to use the mics, use a Lyra-T over an AudioKit. + // + // The mics *and* line-in are BOTH connected to LIN2/RIN2 on the AudioKit + // so there's no way to completely eliminate the mics. It's also hella noisy. + // Line-in works OK on the AudioKit, generally speaking, as the mics really need + // amplification to be noticable. + // + // The Lyra-T does a reasonable job with mic input as configured below. + // + _es8388I2cWrite(10,0b00000000); // Use Lin1/Rin1 for ADC input (mic on Lyra-T) + //_es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input (mic *and* line-in on AudioKit) + + _es8388I2cWrite( 9,0b10001000); // Select Analog Input PGA Gain for ADC to +24dB (L+R) + _es8388I2cWrite(16,0b00000000); // Set ADC digital volume attenuation to 0dB (left) + _es8388I2cWrite(17,0b00000000); // Set ADC digital volume attenuation to 0dB (right) + _es8388I2cWrite(38,0b00011011); // Mixer - route LIN1/RIN1 to output after mic gain + + _es8388I2cWrite(39,0b01000000); // Mixer - route LIN to mixL, +6dB gain + _es8388I2cWrite(42,0b01000000); // Mixer - route RIN to mixR, +6dB gain + _es8388I2cWrite(46,0b00100001); // LOUT1VOL - 0b00100001 = +4.5dB + _es8388I2cWrite(47,0b00100001); // ROUT1VOL - 0b00100001 = +4.5dB + _es8388I2cWrite(48,0b00100001); // LOUT2VOL - 0b00100001 = +4.5dB + _es8388I2cWrite(49,0b00100001); // ROUT2VOL - 0b00100001 = +4.5dB + + // Music ALC - the mics like Auto Level Control + // You can also use this for line-in, but it's not really needed. + // + _es8388I2cWrite(18,0b11111000); // ALC: stereo, max gain +35.5dB, min gain -12dB + _es8388I2cWrite(19,0b00110000); // ALC: target -1.5dB, 0ms hold time + _es8388I2cWrite(20,0b10100110); // ALC: gain ramp up = 420ms/93ms, gain ramp down = check manual for calc + _es8388I2cWrite(21,0b00000110); // ALC: use "ALC" mode, no zero-cross, window 96 samples + _es8388I2cWrite(22,0b01011001); // ALC: noise gate threshold, PGA gain constant, noise gate enabled + #else _es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input ("line-in") _es8388I2cWrite( 9,0b00000000); // Select Analog Input PGA Gain for ADC to 0dB (L+R) _es8388I2cWrite(16,0b01000000); // Set ADC digital volume attenuation to -32dB (left) _es8388I2cWrite(17,0b01000000); // Set ADC digital volume attenuation to -32dB (right) - _es8388I2cWrite( 4,0b00111100); // Turn on LOUT1 and ROUT1 and LOUT2 and ROUT2 power - _es8388I2cWrite( 2,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp" _es8388I2cWrite(38,0b00001001); // Mixer - route LIN2/RIN2 to output + _es8388I2cWrite(39,0b01010000); // Mixer - route LIN to mixL, 0dB gain _es8388I2cWrite(42,0b01010000); // Mixer - route RIN to mixR, 0dB gain - _es8388I2cWrite(46,0b00011110); // LOUT1VOL - 0 = -45dB, 0b00011110 = +0dB - _es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0 = -45dB, 0b00011110 = +0dB - _es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0 = -45dB, 0b00011110 = +0dB - _es8388I2cWrite(49,0b00011110); // ROUT2VOL - 0 = -45dB, 0b00011110 = +0dB + _es8388I2cWrite(46,0b00011011); // LOUT1VOL - 0b00011110 = +0dB, 0b00011011 = Lyra-T balance fix + _es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0b00011110 = +0dB + _es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0b00011110 = +0dB + _es8388I2cWrite(49,0b00011110); // ROUT2VOL - 0b00011110 = +0dB + #endif + } public: @@ -554,6 +594,10 @@ class ES8388Source : public I2SSource { void initialize(int8_t sdaPin, int8_t sclPin, int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) { + // BUG: "use global I2C pins" are valid as -1, and -1 is seen as invalid here. + // Workaround: Set I2C pins here, which will also set them globally. + // Bug also exists in ES7243. + // check that pins are valid if ((sdaPin < 0) || (sclPin < 0)) { ERRORSR_PRINTF("\nAR: invalid ES8388 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin); From 32a501c2e38d279eb95145c58eb94bb1fa489e8f Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:47:28 -0300 Subject: [PATCH 4/6] It's offically the LyraT, not Lyra-T. --- usermods/audioreactive/audio_source.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 2e58a348..846e667d 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -537,16 +537,16 @@ class ES8388Source : public I2SSource { // #define use_es8388_mic #ifdef use_es8388_mic - // Pick one. If you have to use the mics, use a Lyra-T over an AudioKit. + // Pick one. If you have to use the mics, use a LyraT over an AudioKit. // // The mics *and* line-in are BOTH connected to LIN2/RIN2 on the AudioKit // so there's no way to completely eliminate the mics. It's also hella noisy. // Line-in works OK on the AudioKit, generally speaking, as the mics really need // amplification to be noticable. // - // The Lyra-T does a reasonable job with mic input as configured below. + // The LyraT does a reasonable job with mic input as configured below. // - _es8388I2cWrite(10,0b00000000); // Use Lin1/Rin1 for ADC input (mic on Lyra-T) + _es8388I2cWrite(10,0b00000000); // Use Lin1/Rin1 for ADC input (mic on LyraT) //_es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input (mic *and* line-in on AudioKit) _es8388I2cWrite( 9,0b10001000); // Select Analog Input PGA Gain for ADC to +24dB (L+R) @@ -578,7 +578,7 @@ class ES8388Source : public I2SSource { _es8388I2cWrite(39,0b01010000); // Mixer - route LIN to mixL, 0dB gain _es8388I2cWrite(42,0b01010000); // Mixer - route RIN to mixR, 0dB gain - _es8388I2cWrite(46,0b00011011); // LOUT1VOL - 0b00011110 = +0dB, 0b00011011 = Lyra-T balance fix + _es8388I2cWrite(46,0b00011011); // LOUT1VOL - 0b00011110 = +0dB, 0b00011011 = LyraT balance fix _es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0b00011110 = +0dB _es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0b00011110 = +0dB _es8388I2cWrite(49,0b00011110); // ROUT2VOL - 0b00011110 = +0dB From 1713204bfecc05beef05e6ff6c42c34ecd94f114 Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Mon, 1 May 2023 21:07:33 -0400 Subject: [PATCH 5/6] Better ES8388 init and mic support --- usermods/audioreactive/audio_source.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 846e667d..f2e8951b 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -520,9 +520,12 @@ class ES8388Source : public I2SSource { void _es8388InitAdc() { // https://dl.radxa.com/rock2/docs/hw/ds/ES8388%20user%20Guide.pdf Section 10.1 - // http://www.everest-semi.com/pdf/ES8388%20DS.pdf Better spec sheet, more clear. Registries are decimal, settings are binary. + // http://www.everest-semi.com/pdf/ES8388%20DS.pdf Better spec sheet, more clear. // https://docs.google.com/spreadsheets/d/1CN3MvhkcPVESuxKyx1xRYqfUit5hOdsG45St9BCUm-g/edit#gid=0 generally // Sets ADC to around what AudioReactive expects, and loops line-in to line-out/headphone for monitoring. + // Registries are decimal, settings are binary as that's how everything is listed in the docs + // ...which makes it easier to reference the docs. + // _es8388I2cBegin(); _es8388I2cWrite( 8,0b00000000); // I2S to slave _es8388I2cWrite( 2,0b11110011); // Power down DEM and STM From 3df2272791236cf0096b9fcad87f4511105b7a99 Mon Sep 17 00:00:00 2001 From: TroyHacks <5659019+troyhacks@users.noreply.github.com> Date: Thu, 4 May 2023 08:55:00 -0400 Subject: [PATCH 6/6] Warnings about AudioKit rubbish --- usermods/audioreactive/audio_source.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index f2e8951b..10e62a3b 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -540,15 +540,16 @@ class ES8388Source : public I2SSource { // #define use_es8388_mic #ifdef use_es8388_mic - // Pick one. If you have to use the mics, use a LyraT over an AudioKit. - // // The mics *and* line-in are BOTH connected to LIN2/RIN2 on the AudioKit // so there's no way to completely eliminate the mics. It's also hella noisy. // Line-in works OK on the AudioKit, generally speaking, as the mics really need - // amplification to be noticable. + // amplification to be noticable in a quiet room. If you're in a very loud room, + // the mics on the AudioKit WILL pick up sound even in line-in mode. + // TL;DR: Don't use the AudioKit for anything, use the LyraT. // // The LyraT does a reasonable job with mic input as configured below. - // + + // Pick one of these. If you have to use the mics, use a LyraT over an AudioKit if you can: _es8388I2cWrite(10,0b00000000); // Use Lin1/Rin1 for ADC input (mic on LyraT) //_es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input (mic *and* line-in on AudioKit)