[audio_dac] Add a hook that runs once the I2S clocks are running (#19900)

This commit is contained in:
Remco van Essen
2026-09-30 09:45:15 -04:00
committed by GitHub
parent 3fac97867e
commit 52079dd3f3
2 changed files with 10 additions and 0 deletions
+4
View File
@@ -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");