mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-02-16 17:08:07 +00:00
* refactor: Remove hardcoded loop delay for GIF playback in LcdDisplay class * chore: Update esp-ml307 and uart-eth-modem component versions in idf_component.yml - Bump esp-ml307 version from ~3.6.3 to ~3.6.4 - Update uart-eth-modem version from ~0.3.1 to ~0.3.2 * feat: Add PrintPmLocks method to SystemInfo class - Introduced PrintPmLocks method to display power management locks using esp_pm_dump_locks. - Updated system_info.h to declare the new method. * refactor: Streamline audio codec initialization and enablement - Removed redundant channel enable checks from AudioCodec::Start. - Added channel enablement in CreateDuplexChannels for various audio codecs. - Implemented EnableInput and EnableOutput methods in NoAudioCodec for better control over input/output states. * refactor: Delay audio success sound playback until after activation completion - Moved the success sound playback to a scheduled task to ensure it occurs after the activation process is complete. - This change improves the responsiveness of the application during activation events. * refactor: Update camera integration from EspVideo to Esp32Camera - Replaced EspVideo with Esp32Camera for improved camera configuration and initialization. - Streamlined camera setup by utilizing a new configuration structure for better clarity and maintainability. - Updated README.md to remove outdated camera sensor configuration instructions. * refactor: Update audio demuxing process in AudioService - Replaced the existing demuxer instance with a local unique pointer in the PlaySound method for better memory management. - Moved the OnDemuxerFinished callback setup into the PlaySound method to ensure it is correctly associated with the new demuxer instance. - Removed the member variable demuxer_ from AudioService to streamline the class structure.
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include "audio_codec.h"
|
|
#include "board.h"
|
|
#include "settings.h"
|
|
|
|
#include <esp_log.h>
|
|
#include <cstring>
|
|
#include <driver/i2s_common.h>
|
|
|
|
#define TAG "AudioCodec"
|
|
|
|
AudioCodec::AudioCodec() {
|
|
}
|
|
|
|
AudioCodec::~AudioCodec() {
|
|
}
|
|
|
|
void AudioCodec::OutputData(std::vector<int16_t>& data) {
|
|
Write(data.data(), data.size());
|
|
}
|
|
|
|
bool AudioCodec::InputData(std::vector<int16_t>& data) {
|
|
int samples = Read(data.data(), data.size());
|
|
if (samples > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void AudioCodec::Start() {
|
|
Settings settings("audio", false);
|
|
output_volume_ = settings.GetInt("output_volume", output_volume_);
|
|
if (output_volume_ <= 0) {
|
|
ESP_LOGW(TAG, "Output volume value (%d) is too small, setting to default (10)", output_volume_);
|
|
output_volume_ = 10;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Audio codec started");
|
|
}
|
|
|
|
void AudioCodec::SetOutputVolume(int volume) {
|
|
output_volume_ = volume;
|
|
ESP_LOGI(TAG, "Set output volume to %d", output_volume_);
|
|
|
|
Settings settings("audio", true);
|
|
settings.SetInt("output_volume", output_volume_);
|
|
}
|
|
|
|
void AudioCodec::SetInputGain(float gain) {
|
|
input_gain_ = gain;
|
|
ESP_LOGI(TAG, "Set input gain to %.1f", input_gain_);
|
|
}
|
|
|
|
void AudioCodec::EnableInput(bool enable) {
|
|
if (enable == input_enabled_) {
|
|
return;
|
|
}
|
|
input_enabled_ = enable;
|
|
ESP_LOGI(TAG, "Set input enable to %s", enable ? "true" : "false");
|
|
}
|
|
|
|
void AudioCodec::EnableOutput(bool enable) {
|
|
if (enable == output_enabled_) {
|
|
return;
|
|
}
|
|
output_enabled_ = enable;
|
|
ESP_LOGI(TAG, "Set output enable to %s", enable ? "true" : "false");
|
|
}
|