diff --git a/main/audio_codecs/es8388_audio_codec.cc b/main/audio_codecs/es8388_audio_codec.cc index 432f4894..347ef119 100644 --- a/main/audio_codecs/es8388_audio_codec.cc +++ b/main/audio_codecs/es8388_audio_codec.cc @@ -149,7 +149,7 @@ void Es8388AudioCodec::EnableInput(bool enable) { .mclk_multiple = 0, }; ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs)); - ESP_ERROR_CHECK(esp_codec_dev_set_in_gain(input_dev_, 40.0)); + ESP_ERROR_CHECK(esp_codec_dev_set_in_gain(input_dev_, 24.0)); } else { ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_)); } @@ -170,6 +170,14 @@ void Es8388AudioCodec::EnableOutput(bool enable) { }; ESP_ERROR_CHECK(esp_codec_dev_open(output_dev_, &fs)); ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, output_volume_)); + + // Set analog output volume to 0dB, default is -45dB + uint8_t reg_val = 30; // 0dB + uint8_t regs[] = { 46, 47, 48, 49 }; // HP_LVOL, HP_RVOL, SPK_LVOL, SPK_RVOL + for (uint8_t reg : regs) { + ctrl_if_->write_reg(ctrl_if_, reg, 1, ®_val, 1); + } + if (pa_pin_ != GPIO_NUM_NC) { gpio_set_level(pa_pin_, 1); } @@ -195,11 +203,3 @@ int Es8388AudioCodec::Write(const int16_t* data, int samples) { } return samples; } - -void Es8388AudioCodec::WriteReg(uint8_t reg_addr, uint8_t data) { - if (ctrl_if_ != nullptr) { - ctrl_if_->write_reg(ctrl_if_, reg_addr, 1, &data, 1); - } else { - ESP_LOGE(TAG, "Control interface is not initialized"); - } -} diff --git a/main/audio_codecs/es8388_audio_codec.h b/main/audio_codecs/es8388_audio_codec.h index f9df32c8..10807a41 100644 --- a/main/audio_codecs/es8388_audio_codec.h +++ b/main/audio_codecs/es8388_audio_codec.h @@ -32,8 +32,6 @@ public: virtual void SetOutputVolume(int volume) override; virtual void EnableInput(bool enable) override; virtual void EnableOutput(bool enable) override; - - void WriteReg(uint8_t reg_addr, uint8_t data); }; #endif // _ES8388_AUDIO_CODEC_H diff --git a/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc b/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc index 764803f4..663f86a6 100644 --- a/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc +++ b/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc @@ -167,10 +167,6 @@ public: audio_codec = new Es8388AudioCodec(i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE, AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN, GPIO_NUM_NC, AUDIO_CODEC_ES8388_ADDR); - - audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME); //设置默认音量 - audio_codec->WriteReg(0x30, AUDIO_ADD_OUTPUT_VOLUME); - audio_codec->WriteReg(0x31, AUDIO_ADD_OUTPUT_VOLUME);//音量增益设置 } return audio_codec; } diff --git a/main/boards/atk-dnesp32s3/config.h b/main/boards/atk-dnesp32s3/config.h index cbe72f7a..c91dd706 100644 --- a/main/boards/atk-dnesp32s3/config.h +++ b/main/boards/atk-dnesp32s3/config.h @@ -7,8 +7,6 @@ #define AUDIO_INPUT_SAMPLE_RATE 24000 #define AUDIO_OUTPUT_SAMPLE_RATE 24000 -#define AUDIO_DEFAULT_OUTPUT_VOLUME 90 -#define AUDIO_ADD_OUTPUT_VOLUME 90 #define AUDIO_I2S_GPIO_MCLK GPIO_NUM_3 #define AUDIO_I2S_GPIO_WS GPIO_NUM_9