[speaker, i2s_audio] I2S Speaker implementation using a ring buffer - #7605
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #7605 +/- ##
==========================================
+ Coverage 53.70% 54.05% +0.34%
==========================================
Files 50 50
Lines 9408 9698 +290
Branches 1654 1344 -310
==========================================
+ Hits 5053 5242 +189
- Misses 4056 4130 +74
- Partials 299 326 +27 ☔ View full report in Codecov by Sentry. |
c43a2c3 to
9ce705d
Compare
|
Hey there @kahrendt, CODEOWNERS = ["@kahrendt"]And run (message by NeedsCodeownersLabel) |
|
@kahrendt could you show how to use the new futures in CPP components as well? |
I don't have an easy example readily available, but the nabu component in the Thanks for all the feedback! |
|
Hey there @jesserockz, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Keven, about the speaker_task(), what you could do is the following: class i2s_audio_speaker .... {
static void speaker_task(void *params);
protected:
void run_speaker_task_();
}
}
static void i2s_audio_speaker::speaker_task(void *params) {
I2SAudioSpeaker *this_speaker = (I2SAudioSpeaker *) params;
this_speaker->run_speaker_task_();
}
This work very well on my espnow component. |
I actually think it is better to keep the task running code in the static function, it reminds you that by using |
Okay, then i will update my espnow component as well. |
What does this implement/fix?
This is a near complete rewrite of the
i2s_audiospeaker component with improvements for simplification, stability, and supporting different audio sample rates and bits per sample. It adds to thespeakerplatform to support these new features while avoiding breaking changes. It adds a newaudiocomponent that is auto-loaded to handle passing different audio stream settings. Other audio components can auto-load it in the future if needed. Closes #7137, as this implements the core changes (the ESPHome ring buffer uses xStreamBuffers).ticks_to_waitparameter for flexibility when using a separate task to write to the speaker.i2s_audiospeaker component implements this in software.stop()ends it immediately,finish()ends the task after the ring buffer is emptied, and it will end the task with the configured timeout if no audio has been read after that time.i2s_write_expandfor converting between lower bits per sample to higher bits per sample.i2s_set_clkfor handling mono and stereo audioset_audio_stream_infofunction.The component should be much more resilient to errors and should hopefully avoid ever getting in a stuck state that locks the device. It should stop the task and unlock the I2S port if it can't recover, but future playback should work without needing to reboot. My ATOM Echo is much more reliable and stable with this implementation. I additionally tested the changes to the parent speaker component with an S3 Box Lite using the
esp_adfspeaker with no issues. I would appreciate anyone able to test this on other hardware!I'm keeping as a draft until I add documentation for the
speaker.volume_setaction.Types of changes
Related issue or feature (if applicable): not applicable
Pull request in esphome-docs with documentation (if applicable): esphome/esphome.io#4343
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: