From 62f6179abe24339c2e5b7350528afbcad4c52067 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 15 Feb 2024 16:12:07 +1100 Subject: Added offset for track seeking, wav impl. only rn --- src/audio/include/audio_events.hpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/audio/include/audio_events.hpp') diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index 03584062..8459333f 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -45,6 +45,11 @@ struct PlayFile : tinyfsm::Event { std::string filename; }; +struct SeekFile : tinyfsm::Event { + std::string filename; + uint32_t offset; +}; + struct StepUpVolume : tinyfsm::Event {}; struct StepDownVolume : tinyfsm::Event {}; struct SetVolume : tinyfsm::Event { -- cgit v1.2.3 From 665679b8854d34c13d8eb92167aa8a4691619d8b Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 16 Feb 2024 12:55:11 +1100 Subject: WIP: seeking in lua example --- src/audio/include/audio_events.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/audio/include/audio_events.hpp') 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 {}; -- cgit v1.2.3 From 173b09b0151ae765b1a8e69dfb60d14d502801f6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 29 Feb 2024 15:47:21 +1100 Subject: Clear the drain buffer when skipping between tracks --- src/audio/include/audio_events.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/audio/include/audio_events.hpp') diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index 03584062..a79ca4ec 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -14,7 +14,6 @@ #include "tinyfsm.hpp" #include "track.hpp" -#include "track_queue.hpp" #include "types.hpp" namespace audio { @@ -39,6 +38,13 @@ struct PlaybackStopped : tinyfsm::Event {}; struct QueueUpdate : tinyfsm::Event { bool current_changed; + + enum Reason { + kExplicitUpdate, + kRepeatingLastTrack, + kTrackFinished, + }; + Reason reason; }; struct PlayFile : tinyfsm::Event { -- cgit v1.2.3 From 14552881900bb3ed0e9ed2d4a732e4104b32ccfa Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 6 Mar 2024 13:59:33 +1100 Subject: Restore the previous track position when booting --- src/audio/include/audio_events.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/audio/include/audio_events.hpp') diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index d55e4e0d..a8533646 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -44,6 +44,7 @@ struct QueueUpdate : tinyfsm::Event { kExplicitUpdate, kRepeatingLastTrack, kTrackFinished, + kDeserialised, }; Reason reason; }; -- cgit v1.2.3 From 175bfc4e3e9f7aa39e084d3f1625347f1d5711ec Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 25 Mar 2024 17:34:41 +1100 Subject: WIP rewrie audio pipeline+fsm guts for more reliability --- src/audio/include/audio_events.hpp | 108 ++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 25 deletions(-) (limited to 'src/audio/include/audio_events.hpp') diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index a8533646..9af30467 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -9,8 +9,10 @@ #include #include #include +#include #include +#include "audio_sink.hpp" #include "tinyfsm.hpp" #include "track.hpp" @@ -18,24 +20,80 @@ namespace audio { -struct Track { +/* + * Struct encapsulating information about the decoder's current track. + */ +struct TrackInfo { + /* + * Audio tags extracted from the file. May be absent for files without any + * parseable tags. + */ std::shared_ptr tags; - std::shared_ptr db_info; - uint32_t duration; - uint32_t bitrate_kbps; + /* + * URI that the current track was retrieved from. This is currently always a + * file path on the SD card. + */ + std::string uri; + + /* + * The length of this track in seconds. This is either retrieved from the + * track's tags, or sometimes computed. It may therefore sometimes be + * inaccurate or missing. + */ + std::optional duration; + + /* The offset in seconds that this file's decoding started from. */ + std::optional start_offset; + + /* The approximate bitrate of this track in its original encoded form. */ + std::optional bitrate_kbps; + + /* The encoded format of the this track. */ codecs::StreamType encoding; - std::string filepath; }; -struct PlaybackStarted : tinyfsm::Event {}; - +/* + * Event emitted by the audio FSM when the state of the audio pipeline has + * changed. This is usually once per second while a track is playing, plus one + * event each when a track starts or finishes. + */ struct PlaybackUpdate : tinyfsm::Event { - uint32_t seconds_elapsed; - std::shared_ptr track; + /* + * The track that is currently being decoded by the audio pipeline. May be + * absent if there is no current track. + */ + std::shared_ptr current_track; + + /* + * How long the current track has been playing for, in seconds. Will always + * be present if current_track is present. + */ + std::optional track_position; + + /* Whether or not the current track is currently being output to a sink. */ + bool paused; +}; + +/* + * Sets a new track to be decoded by the audio pipeline, replacing any + * currently playing track. + */ +struct SetTrack : tinyfsm::Event { + std::variant new_track; + std::optional seek_to_second; + + enum Transition { + kHardCut, + kGapless, + // TODO: kCrossFade + }; + Transition transition; }; -struct PlaybackStopped : tinyfsm::Event {}; +struct TogglePlayPause : tinyfsm::Event { + std::optional set_to; +}; struct QueueUpdate : tinyfsm::Event { bool current_changed; @@ -49,15 +107,6 @@ struct QueueUpdate : tinyfsm::Event { Reason reason; }; -struct PlayFile : tinyfsm::Event { - std::string filename; -}; - -struct SeekFile : tinyfsm::Event { - uint32_t offset; - std::string filename; -}; - struct StepUpVolume : tinyfsm::Event {}; struct StepDownVolume : tinyfsm::Event {}; struct SetVolume : tinyfsm::Event { @@ -83,17 +132,26 @@ struct SetVolumeLimit : tinyfsm::Event { int limit_db; }; -struct TogglePlayPause : tinyfsm::Event {}; - struct OutputModeChanged : tinyfsm::Event {}; namespace internal { -struct InputFileOpened : tinyfsm::Event {}; -struct InputFileClosed : tinyfsm::Event {}; -struct InputFileFinished : tinyfsm::Event {}; +struct DecoderOpened : tinyfsm::Event { + std::shared_ptr track; +}; + +struct DecoderClosed : tinyfsm::Event {}; + +struct DecoderError : tinyfsm::Event {}; -struct AudioPipelineIdle : tinyfsm::Event {}; +struct ConverterConfigurationChanged : tinyfsm::Event { + IAudioOutput::Format src_format; + IAudioOutput::Format dst_format; +}; + +struct ConverterProgress : tinyfsm::Event { + uint32_t samples_sunk; +}; } // namespace internal -- cgit v1.2.3 From 078b77d0f796be3c787f62b9b830512e38d3b076 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 26 Mar 2024 12:12:42 +1100 Subject: pass stream start/update/end events through the whole pipeline --- src/audio/include/audio_events.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/audio/include/audio_events.hpp') diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp index 9af30467..b8a0dba6 100644 --- a/src/audio/include/audio_events.hpp +++ b/src/audio/include/audio_events.hpp @@ -51,6 +51,8 @@ struct TrackInfo { /* The encoded format of the this track. */ codecs::StreamType encoding; + + IAudioOutput::Format format; }; /* @@ -136,23 +138,18 @@ struct OutputModeChanged : tinyfsm::Event {}; namespace internal { -struct DecoderOpened : tinyfsm::Event { +struct StreamStarted : tinyfsm::Event { std::shared_ptr track; -}; - -struct DecoderClosed : tinyfsm::Event {}; - -struct DecoderError : tinyfsm::Event {}; - -struct ConverterConfigurationChanged : tinyfsm::Event { IAudioOutput::Format src_format; IAudioOutput::Format dst_format; }; -struct ConverterProgress : tinyfsm::Event { +struct StreamUpdate : tinyfsm::Event { uint32_t samples_sunk; }; +struct StreamEnded : tinyfsm::Event {}; + } // namespace internal } // namespace audio -- cgit v1.2.3