summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-02-16 12:55:11 +1100
committerailurux <ailuruxx@gmail.com>2024-02-16 12:55:11 +1100
commit665679b8854d34c13d8eb92167aa8a4691619d8b (patch)
treedd2edb34f09f198357efb1e0a7e6f5e81443c022 /src
parenta49d754da6c293445be16ac643d10849c01ea96b (diff)
downloadtangara-fw-665679b8854d34c13d8eb92167aa8a4691619d8b.tar.gz
WIP: seeking in lua example
Diffstat (limited to 'src')
-rw-r--r--src/audio/audio_decoder.cpp3
-rw-r--r--src/audio/audio_fsm.cpp6
-rw-r--r--src/audio/audio_source.cpp7
-rw-r--r--src/audio/fatfs_audio_input.cpp2
-rw-r--r--src/audio/include/audio_events.hpp3
-rw-r--r--src/audio/include/audio_source.hpp7
-rw-r--r--src/codecs/wav.cpp5
-rw-r--r--src/ui/ui_fsm.cpp16
8 files changed, 35 insertions, 14 deletions
diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp
index eaa9ff9c..68a8a86b 100644
--- a/src/audio/audio_decoder.cpp
+++ b/src/audio/audio_decoder.cpp
@@ -148,16 +148,15 @@ auto Decoder::BeginDecoding(std::shared_ptr<TaggedStream> stream) -> bool {
ESP_LOGI(kTag, "stream started ok");
events::Audio().Dispatch(internal::InputFileOpened{});
- // TODO: How does this need to change?
auto tags = std::make_shared<Track>(Track{
.tags = stream->tags(),
.db_info = {},
.bitrate_kbps = open_res->sample_rate_hz,
.encoding = stream->type(),
+ .filepath = stream->Filepath(),
});
timer_.reset(new Timer(tags, open_res.value(), stream->Offset()));
- // TODO: How does *this?* need to change?
PlaybackUpdate ev{.seconds_elapsed = stream->Offset(), .track = tags};
events::Audio().Dispatch(ev);
events::Ui().Dispatch(ev);
diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp
index 75e3c24a..0e213b6e 100644
--- a/src/audio/audio_fsm.cpp
+++ b/src/audio/audio_fsm.cpp
@@ -246,14 +246,16 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) {
void Standby::react(const PlayFile& ev) {
sCurrentTrack = 0;
sIsPlaybackAllowed = true;
- sFileSource->SetPath(ev.filename, 10);
+ sFileSource->SetPath(ev.filename);
}
void Playback::react(const PlayFile& ev) {
- sFileSource->SetPath(ev.filename, 10);
+ sFileSource->SetPath(ev.filename);
}
void Standby::react(const SeekFile& ev) {
+ sCurrentTrack = 0;
+ sIsPlaybackAllowed = true;
sFileSource->SetPath(ev.filename, ev.offset);
}
diff --git a/src/audio/audio_source.cpp b/src/audio/audio_source.cpp
index 2543db44..d9e8e04a 100644
--- a/src/audio/audio_source.cpp
+++ b/src/audio/audio_source.cpp
@@ -12,8 +12,9 @@ namespace audio {
TaggedStream::TaggedStream(std::shared_ptr<database::TrackTags> t,
std::unique_ptr<codecs::IStream> w,
+ std::string filepath,
uint32_t offset)
- : codecs::IStream(w->type()), tags_(t), wrapped_(std::move(w)), offset_(offset) {}
+ : codecs::IStream(w->type()), tags_(t), wrapped_(std::move(w)), filepath_(filepath), offset_(offset) {}
auto TaggedStream::tags() -> std::shared_ptr<database::TrackTags> {
return tags_;
@@ -43,6 +44,10 @@ auto TaggedStream::Offset() -> uint32_t {
return offset_;
}
+auto TaggedStream::Filepath() -> std::string {
+ return filepath_;
+}
+
auto TaggedStream::SetPreambleFinished() -> void {
wrapped_->SetPreambleFinished();
}
diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp
index 665e8c1d..74c1154b 100644
--- a/src/audio/fatfs_audio_input.cpp
+++ b/src/audio/fatfs_audio_input.cpp
@@ -136,7 +136,7 @@ auto FatfsAudioInput::OpenFile(const std::string& path,uint32_t offset) -> bool
auto source =
std::make_unique<FatfsSource>(stream_type.value(), std::move(file));
- new_stream_.reset(new TaggedStream(tags, std::move(source), offset));
+ new_stream_.reset(new TaggedStream(tags, std::move(source), path, offset));
return true;
}
diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp
index 8459333f..96e77987 100644
--- a/src/audio/include/audio_events.hpp
+++ b/src/audio/include/audio_events.hpp
@@ -26,6 +26,7 @@ struct Track {
uint32_t duration;
uint32_t bitrate_kbps;
codecs::StreamType encoding;
+ std::string filepath;
};
struct PlaybackStarted : tinyfsm::Event {};
@@ -46,8 +47,8 @@ struct PlayFile : tinyfsm::Event {
};
struct SeekFile : tinyfsm::Event {
+ uint32_t offset;
std::string filename;
- uint32_t offset;
};
struct StepUpVolume : tinyfsm::Event {};
diff --git a/src/audio/include/audio_source.hpp b/src/audio/include/audio_source.hpp
index b2fd173d..b38acd7a 100644
--- a/src/audio/include/audio_source.hpp
+++ b/src/audio/include/audio_source.hpp
@@ -17,7 +17,9 @@ class TaggedStream : public codecs::IStream {
public:
TaggedStream(std::shared_ptr<database::TrackTags>,
std::unique_ptr<codecs::IStream> wrapped,
- uint32_t offset = 0);
+ std::string path,
+ uint32_t offset = 0
+ );
auto tags() -> std::shared_ptr<database::TrackTags>;
@@ -33,11 +35,14 @@ class TaggedStream : public codecs::IStream {
auto Offset() -> uint32_t;
+ auto Filepath() -> std::string;
+
auto SetPreambleFinished() -> void override;
private:
std::shared_ptr<database::TrackTags> tags_;
std::unique_ptr<codecs::IStream> wrapped_;
+ std::string filepath_;
int32_t offset_;
};
diff --git a/src/codecs/wav.cpp b/src/codecs/wav.cpp
index 22cbd49c..5dd6f031 100644
--- a/src/codecs/wav.cpp
+++ b/src/codecs/wav.cpp
@@ -218,7 +218,6 @@ auto WavDecoder::DecodeTo(cpp::span<sample::Sample> output)
buffer_.ConsumeBytes([&](cpp::span<std::byte> buf) -> size_t {
size_t bytes_read = buf.size_bytes();
- ESP_LOGI(kTag, "Bytes read: %d", bytes_read);
size_t frames_read =
bytes_read / bytes_per_sample_ / output_format_.num_channels;
@@ -244,10 +243,6 @@ auto WavDecoder::DecodeTo(cpp::span<sample::Sample> output)
return samples_written * bytes_per_sample_;
});
- ESP_LOGI(kTag, "Samples written %d", samples_written);
- if (is_eof) {
- ESP_LOGI(kTag, "EOF");
- }
return OutputInfo{.samples_written = samples_written,
.is_stream_finished = samples_written == 0 && is_eof};
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index 24145ead..3e85c36e 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -123,7 +123,21 @@ lua::Property UiState::sPlaybackPlaying{
}};
lua::Property UiState::sPlaybackTrack{};
-lua::Property UiState::sPlaybackPosition{0};
+lua::Property UiState::sPlaybackPosition{0, [](const lua::LuaValue& val) {
+ int current_val = std::get<int>(sPlaybackPosition.Get());
+ if (!std::holds_alternative<int>(val)) {
+ return false;
+ }
+ int new_val = std::get<int>(val);
+ if (current_val != new_val) {
+ auto track = sPlaybackTrack.Get();
+ if (!std::holds_alternative<audio::Track>(track)) {
+ return false;
+ }
+ events::Audio().Dispatch(audio::SeekFile{.offset = (uint32_t)new_val, .filename = std::get<audio::Track>(track).filepath});
+ }
+ return true;
+}};
lua::Property UiState::sQueuePosition{0};
lua::Property UiState::sQueueSize{0};