mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 15:12:21 +01:00
[i2s_audio, mixer, resampler, speaker] Simplify duration played callback (#8703)
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace i2s_audio {
|
||||
|
||||
@@ -366,25 +368,15 @@ void I2SAudioSpeaker::speaker_task(void *params) {
|
||||
bytes_to_write, &bytes_written, pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS * 5));
|
||||
#endif
|
||||
|
||||
uint32_t write_timestamp = micros();
|
||||
int64_t now = esp_timer_get_time();
|
||||
|
||||
if (bytes_written != bytes_to_write) {
|
||||
xEventGroupSetBits(this_speaker->event_group_, SpeakerEventGroupBits::ERR_ESP_INVALID_SIZE);
|
||||
}
|
||||
|
||||
bytes_read -= bytes_written;
|
||||
|
||||
this_speaker->accumulated_frames_written_ += audio_stream_info.bytes_to_frames(bytes_written);
|
||||
const uint32_t new_playback_ms =
|
||||
audio_stream_info.frames_to_milliseconds_with_remainder(&this_speaker->accumulated_frames_written_);
|
||||
const uint32_t remainder_us =
|
||||
audio_stream_info.frames_to_microseconds(this_speaker->accumulated_frames_written_);
|
||||
|
||||
uint32_t pending_frames =
|
||||
audio_stream_info.bytes_to_frames(bytes_read + this_speaker->audio_ring_buffer_->available());
|
||||
const uint32_t pending_ms = audio_stream_info.frames_to_milliseconds_with_remainder(&pending_frames);
|
||||
|
||||
this_speaker->audio_output_callback_(new_playback_ms, remainder_us, pending_ms, write_timestamp);
|
||||
this_speaker->audio_output_callback_(audio_stream_info.bytes_to_frames(bytes_written),
|
||||
now + dma_buffers_duration_ms * 1000);
|
||||
|
||||
tx_dma_underflow = false;
|
||||
last_data_received_time = millis();
|
||||
|
Reference in New Issue
Block a user