fix es8388 input/output volume

This commit is contained in:
Terrence
2025-02-04 23:49:58 +08:00
parent 503c7d8a2a
commit 554152cd00
4 changed files with 9 additions and 17 deletions

View File

@@ -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, &reg_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");
}
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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