From 1f903accd95361735c841c87fdc6494ad3331b40 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 7 Jun 2023 13:19:45 +1000 Subject: Flesh out audio state machine for playback Also fix mono playback --- src/audio/audio_fsm.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/audio/audio_fsm.cpp') diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index 3ab8b6e8..6c974905 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -6,6 +6,7 @@ #include "audio_fsm.hpp" #include +#include #include "audio_decoder.hpp" #include "audio_events.hpp" #include "audio_task.hpp" @@ -16,6 +17,8 @@ namespace audio { +static const char kTag[] = "audio_fsm"; + drivers::GpioExpander* AudioState::sGpioExpander; std::shared_ptr AudioState::sDac; std::shared_ptr AudioState::sPots; @@ -25,6 +28,8 @@ std::unique_ptr AudioState::sFileSource; std::unique_ptr AudioState::sI2SOutput; std::vector> AudioState::sPipeline; +std::deque AudioState::sSongQueue; + auto AudioState::Init(drivers::GpioExpander* gpio_expander, std::weak_ptr database) -> bool { sGpioExpander = gpio_expander; @@ -66,6 +71,33 @@ void Standby::react(const PlayFile& ev) { } } +void Playback::entry() { + ESP_LOGI(kTag, "beginning playback"); + sI2SOutput->SetInUse(true); +} + +void Playback::exit() { + ESP_LOGI(kTag, "finishing playback"); + sI2SOutput->SetInUse(false); +} + +void Playback::react(const InputFileFinished& ev) { + ESP_LOGI(kTag, "finished file"); + if (sSongQueue.empty()) { + return; + } + EnqueuedItem next_item = sSongQueue.front(); + sSongQueue.pop_front(); + + if (std::holds_alternative(next_item)) { + sFileSource->OpenFile(std::get(next_item)); + } +} + +void Playback::react(const AudioPipelineIdle& ev) { + transit(); +} + } // namespace states } // namespace audio -- cgit v1.2.3