mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 17:00:21 +00:00
[audio_dac] Add a hook that runs once the I2S clocks are running (#19900)
This commit is contained in:
@@ -14,6 +14,10 @@ class AudioDac {
|
||||
virtual bool is_muted() = 0;
|
||||
virtual float volume() = 0;
|
||||
|
||||
/// Called from the main loop by the speaker driving this DAC once its audio clocks are running.
|
||||
/// DACs that can only be configured while clocked (e.g. DSP state lost across clock stops) override this.
|
||||
virtual void on_audio_started() {}
|
||||
|
||||
protected:
|
||||
bool is_muted_{false};
|
||||
};
|
||||
|
||||
@@ -77,6 +77,12 @@ void I2SAudioSpeakerBase::loop() {
|
||||
ESP_LOGV(TAG, "Started");
|
||||
xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::TASK_RUNNING);
|
||||
this->state_ = speaker::STATE_RUNNING;
|
||||
#ifdef USE_AUDIO_DAC
|
||||
// The task raises TASK_RUNNING only after enabling the channel, so the clocks are already running
|
||||
if (this->audio_dac_ != nullptr) {
|
||||
this->audio_dac_->on_audio_started();
|
||||
}
|
||||
#endif // USE_AUDIO_DAC
|
||||
}
|
||||
if (event_group_bits & SpeakerEventGroupBits::TASK_STOPPING) {
|
||||
ESP_LOGV(TAG, "Stopping");
|
||||
|
||||
Reference in New Issue
Block a user