CarlosDerSeher / snapclient

snapclient on ESP32
GNU General Public License v3.0
125 stars 16 forks source link

AI Thinker support #67

Closed unknown0816 closed 7 months ago

unknown0816 commented 7 months ago
alexyao2015 commented 7 months ago

What great timing! I was looking into adding this today too. I gave your branch a try and it works well with the exception of the psram being turned off. Suggest you set CONFIG_ESP32_SPIRAM_SUPPORT to y so there aren't out of memory issues.

unknown0816 commented 7 months ago

I'm happy to hear, that it works well.

Regarding you suggestion: As far as I understand is this a sdkconfig setting. So everybody can just set or unset this. I guess I could add ai_thinker example sdkconfigs (with and without this setting). Is this what you would like to have?

alexyao2015 commented 7 months ago

Something with the scaling factor of the volume isn't right. It seems like anything below 80 is inaudible.

CarlosDerSeher commented 7 months ago

Ok I double checked the code and it seems @unknown0816 volume is controlled both digitally AND analog? Maybe this is the problem? So try setting analog gain to it's max value for this board and control volume digital only?

alexyao2015 commented 7 months ago

The datasheet is not well written but I see here that the left right is set to 0 gain and the volume only adjusts the main 4+5 gain. https://github.com/espressif/esp-adf/blob/33ba0c5c698b6719e0cd8e2bd97d8e4c5a13d9d2/components/audio_hal/driver/es8388/es8388.c

unknown0816 commented 6 months ago

I know that the scaling is not perfect. For me anything below 50 is mute and anything above 70 is not bearable. I guess it would be possible to modify the lower and upper case to have a more usable scaling, but that would not be datasheet conform.

I tried, to only set 4+5 respectivily 24-27, but here I always had no good scaling, too.

unknown0816 commented 6 months ago

I did an experiment, which worked kind of well:

  int inv_volume = (100 - volume)*0.5;
  res = es_write_reg (ES8388_ADDR, ES8388_DACCONTROL5, inv_volume);
  res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL4, inv_volume);

  volume /= 8;
  res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL24, volume);
  res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL25, volume);
  res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL26, volume);
  res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL27, volume);

Playing around with the 0.5 and the 8 will influence the scaling of the volume. For me this works quite well, but this could be different from board to board, I guess.

Edit: 0.33 and 6 works good, too.