esp-adf icon indicating copy to clipboard operation
esp-adf copied to clipboard

pipeline_passthru example does not actually pass audio through the ESP32 for ES8388 (AUD-1169)

Open Jeija opened this issue 5 years ago • 6 comments

My understanding from looking at the passthru.c code from the passthru example is that this example is supposed to read the I²S data from the codec chip's ADC input and then write back to it's DAC output in real time. However, it seems that this is not actually what is happening. I have tested this on my ESP32-LyraT board with an ES8388 codec, but this issue might possibly also affect other boards.

Instead, the passthru code just enables the internal analog bypass mode of the ES8388. This is how it happens:

  • The line audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_LINE_IN, AUDIO_HAL_CTRL_START); in passthru.c calls audio_hal_ctrl_codec in audio_hal.c, which calls audio_hal->audio_codec_ctrl, which points to the function es8388_ctrl_state in the case of a board with an ES8388 codec.
  • Since the specified audio_hal_codec_mode_t was AUDIO_HAL_CODEC_MODE_LINE_IN, the function es8388_ctrl_state calls es8388_start with parameter ES_MODULE_LINE
  • In es8388_start, the following configuration is written via I2C

https://github.com/espressif/esp-adf/blob/3438db90b6f66fd0cd6a52accc68619d12bd72db/components/audio_hal/driver/es8388/es8388.c#L175-L180

Note that ES8388_DACCONTROL17 and ES8388_DACCONTROL20 are set to 0x50. When looking at the ES8388 datasheet, you will find that this configuration disables the "DAC to mixer" connection and enables the "LIN / RIN to mixer" connection. So the ADC and DAC are completely bypassed.

The original passthru example worked just fine for me (on my ESP32-LyraT it takes the microphone input, reads it via I²S, writes it back via I²S and outputs it through the headphone jack), I believe that it was this commit that broke it: https://github.com/espressif/esp-adf/commit/e05f405c61b73c9389241c1fec2c33009b628c87

Can you reproduce this problem?

I think a quick fix would be to just revert https://github.com/espressif/esp-adf/commit/e05f405c61b73c9389241c1fec2c33009b628c87.

Jeija avatar Dec 29 '19 12:12 Jeija

Hi Jeija Your discovery is great. Using audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_LINE_IN, AUDIO_HAL_CTRL_START) is more suitable for readme ,That's why we have this commit.

espressif-zhanghu avatar Jan 08 '20 12:01 espressif-zhanghu

I don't think this issue has been fixed yet. This commit does as Jeija suggested above. It routes the audio around the ADC and DAC. Looking at the registers of the ES8388 after the command :: audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_LINE_IN, AUDIO_HAL_CTRL_START) there are a few registers that are incorrectly set if the intent is to have AUX IN pass through ADC DAC to HEADPHONES. For example Register 10 – ADC Control 2, sets the input to ADC to LINE1 after this command is executed. AUX IN is on LINE2. Adding the following lines of code after this command sets the registers properly to have audio pass through the whole system as it did before the commit

	es8388_write_reg(39, 144); // left DAC to left mixer enable
	es8388_write_reg(42, 144);// right DAC to right mixer enable
	es8388_write_reg(10, 80); // set LINE2 as input to ADC
	es8388_write_reg(43, 128); //DACLRC and ADCLRC same

es8388.h must be included for this to work.

jimruxton avatar Jan 26 '20 06:01 jimruxton

The pipeline_passthru example did not work for me using the LyraT v4.3. Reverting e05f405 fixed the issue for me.

chf2117 avatar Jan 14 '21 22:01 chf2117

Still doesn't work properly a year later...

alamaral avatar Jan 09 '23 21:01 alamaral

Issue is still present!! Stopping the pipeline immediately after starting it does not make any difference. Audio must be routed through the mixer of the codec, still. Please fix this, and if I may suggest: a simple gain adjustment in code would be nice too for an example like this.

crosswick avatar Jan 14 '24 20:01 crosswick