summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBe <be.0@gmx.com>2025-04-09 22:52:42 -0500
committerBe <be.0@gmx.com>2025-04-11 10:20:48 -0500
commitc4c6c9df7bb5721ed695667a7f6b6b918330e2e8 (patch)
treebc05e76f1485e028e9e70061a0071402adda122e
parent71ac67bad3a694b2cd11450bf7bfec76a8293393 (diff)
downloadtangara-fw-c4c6c9df7bb5721ed695667a7f6b6b918330e2e8.tar.gz
fix premature pause at end of last track of queue
The SetTrack event is sent when *decoding* finishes, not when *playback* finishes so the decoder can start buffering the next track in advance of its playback to ensure gapless playback. Clearing StreamCues causes Playback::react(const internal::StreamHeartbeat& ev) to transit the Playback FSM to Standby, which sets the IAudioOutput to stop reading from the output buffer. Thus, clearing StreamCues in response to the SetTrack event paused playback with the end of the track stuck waiting in the output buffer. When a new queue was loaded and started playing, the end of the previous track would be played before the new track was played. Fixes https://codeberg.org/cool-tech-zone/tangara-fw/issues/313
-rw-r--r--src/tangara/audio/audio_fsm.cpp3
-rw-r--r--src/tangara/audio/stream_cues.cpp5
-rw-r--r--src/tangara/audio/stream_cues.hpp2
3 files changed, 1 insertions, 9 deletions
diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp
index 1e8e0cf6..7c1b010d 100644
--- a/src/tangara/audio/audio_fsm.cpp
+++ b/src/tangara/audio/audio_fsm.cpp
@@ -148,9 +148,7 @@ void AudioState::react(const QueueUpdate& ev) {
void AudioState::react(const SetTrack& ev) {
if (std::holds_alternative<std::monostate>(ev.new_track)) {
- ESP_LOGI(kTag, "playback finished, awaiting drain");
sDecoder->open({});
- sStreamCues.clear();
return;
}
@@ -212,6 +210,7 @@ void AudioState::react(const TtsPlaybackChanged& ev) {
}
void AudioState::react(const internal::DecodingFinished& ev) {
+ ESP_LOGD(kTag, "end of file decoded; awaiting playback of buffered audio");
// If we just finished playing whatever's at the front of the queue, then we
// need to advanve and start playing the next one ASAP in order to continue
// gaplessly.
diff --git a/src/tangara/audio/stream_cues.cpp b/src/tangara/audio/stream_cues.cpp
index 611138c6..6a9a7674 100644
--- a/src/tangara/audio/stream_cues.cpp
+++ b/src/tangara/audio/stream_cues.cpp
@@ -43,11 +43,6 @@ auto StreamCues::addCue(std::shared_ptr<TrackInfo> track, uint32_t sample)
}
}
-auto StreamCues::clear() -> void {
- upcoming_.clear();
- current_ = {};
-}
-
auto StreamCues::current() -> std::pair<std::shared_ptr<TrackInfo>, uint32_t> {
if (!current_) {
return {};
diff --git a/src/tangara/audio/stream_cues.hpp b/src/tangara/audio/stream_cues.hpp
index 70ad49a7..cd0782b0 100644
--- a/src/tangara/audio/stream_cues.hpp
+++ b/src/tangara/audio/stream_cues.hpp
@@ -34,8 +34,6 @@ class StreamCues {
auto addCue(std::shared_ptr<TrackInfo>, uint32_t start_at) -> void;
- auto clear() -> void;
-
private:
uint32_t now_;