Start on audio FSM playback. needs more thought.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "audio_fsm.hpp"
|
||||
#include "audio_decoder.hpp"
|
||||
#include "audio_events.hpp"
|
||||
#include "audio_task.hpp"
|
||||
#include "dac.hpp"
|
||||
#include "fatfs_audio_input.hpp"
|
||||
@@ -50,6 +51,12 @@ void Uninitialised::react(const system_fsm::BootComplete&) {
|
||||
});
|
||||
}
|
||||
|
||||
void Standby::react(const PlayFile &ev) {
|
||||
if (sFileSource->OpenFile(ev.filename)) {
|
||||
transit<Playback>();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace states
|
||||
|
||||
} // namespace audio
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "event_queue.hpp"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "freertos/queue.h"
|
||||
@@ -44,10 +45,14 @@ static const char* kTag = "task";
|
||||
|
||||
void AudioTaskMain(std::unique_ptr<Pipeline> pipeline, IAudioSink* sink) {
|
||||
std::optional<StreamInfo::Format> output_format;
|
||||
uint_fast16_t delay_ticks = pdMS_TO_TICKS(5);
|
||||
|
||||
std::vector<Pipeline*> elements = pipeline->GetIterationOrder();
|
||||
|
||||
events::EventQueue &event_queue = events::EventQueue::GetInstance();
|
||||
while (1) {
|
||||
event_queue.ServiceAudio(delay_ticks);
|
||||
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
std::vector<RawStream> raw_in_streams;
|
||||
elements.at(i)->InStreams(&raw_in_streams);
|
||||
|
||||
@@ -35,7 +35,7 @@ FatfsAudioInput::FatfsAudioInput()
|
||||
|
||||
FatfsAudioInput::~FatfsAudioInput() {}
|
||||
|
||||
auto FatfsAudioInput::OpenFile(const std::string& path) -> void {
|
||||
auto FatfsAudioInput::OpenFile(const std::string& path) -> bool {
|
||||
if (is_file_open_) {
|
||||
f_close(¤t_file_);
|
||||
is_file_open_ = false;
|
||||
@@ -44,11 +44,11 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> void {
|
||||
FRESULT res = f_open(¤t_file_, path.c_str(), FA_READ);
|
||||
if (res != FR_OK) {
|
||||
ESP_LOGE(kTag, "failed to open file! res: %i", res);
|
||||
// TODO(jacqueline): Handle errors.
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
is_file_open_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto FatfsAudioInput::Process(const std::vector<InputStream>& inputs,
|
||||
|
||||
@@ -6,14 +6,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "tinyfsm.hpp"
|
||||
|
||||
#include "song.hpp"
|
||||
|
||||
namespace audio {
|
||||
|
||||
struct PlayFile : tinyfsm::Event {
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
struct PlaySong : tinyfsm::Event {
|
||||
database::SongId id;
|
||||
std::optional<database::SongData> data;
|
||||
std::optional<database::SongTags> tags;
|
||||
};
|
||||
|
||||
} // namespace audio
|
||||
|
||||
@@ -37,6 +37,7 @@ class AudioState : public tinyfsm::Fsm<AudioState> {
|
||||
|
||||
virtual void react(const system_fsm::BootComplete&) {}
|
||||
virtual void react(const PlaySong&) {}
|
||||
virtual void react(const PlayFile&) {}
|
||||
|
||||
protected:
|
||||
static drivers::GpioExpander* sGpioExpander;
|
||||
@@ -59,6 +60,12 @@ class Uninitialised : public AudioState {
|
||||
class Standby : public AudioState {
|
||||
public:
|
||||
void react(const PlaySong&) override {}
|
||||
void react(const PlayFile&) override;
|
||||
using AudioState::react;
|
||||
};
|
||||
|
||||
class Playback : public AudioState {
|
||||
public:
|
||||
using AudioState::react;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace audio {
|
||||
|
||||
class FatfsAudioInput : public IAudioElement {
|
||||
public:
|
||||
explicit FatfsAudioInput();
|
||||
FatfsAudioInput();
|
||||
~FatfsAudioInput();
|
||||
|
||||
auto OpenFile(const std::string& path) -> void;
|
||||
auto OpenFile(const std::string& path) -> bool;
|
||||
|
||||
auto Process(const std::vector<InputStream>& inputs, OutputStream* output)
|
||||
-> void override;
|
||||
|
||||
Reference in New Issue
Block a user