diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-08-16 15:11:30 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-08-16 15:11:44 +1000 |
| commit | f3c5eec0251ec98f90d324c88d3519de2e6ee5e0 (patch) | |
| tree | 90cd471dd980c77440e1b901dd5c6c91492d27d6 /src/audio/include | |
| parent | c635d5011c37c02246135fe0df404631ec111bd6 (diff) | |
| download | tangara-fw-f3c5eec0251ec98f90d324c88d3519de2e6ee5e0.tar.gz | |
Rename the main audio tasks to be more sensible
Diffstat (limited to 'src/audio/include')
| -rw-r--r-- | src/audio/include/audio_converter.hpp (renamed from src/audio/include/sink_mixer.hpp) | 18 | ||||
| -rw-r--r-- | src/audio/include/audio_decoder.hpp (renamed from src/audio/include/audio_task.hpp) | 24 | ||||
| -rw-r--r-- | src/audio/include/audio_fsm.hpp | 6 |
3 files changed, 29 insertions, 19 deletions
diff --git a/src/audio/include/sink_mixer.hpp b/src/audio/include/audio_converter.hpp index d046f835..81532969 100644 --- a/src/audio/include/sink_mixer.hpp +++ b/src/audio/include/audio_converter.hpp @@ -18,19 +18,21 @@ namespace audio { /* - * Handles the final downmix + resample + quantisation stage of audio, - * generation sending the result directly to an IAudioOutput. + * Handle to a persistent task that converts samples between formats (sample + * rate, channels, bits per sample), in order to put samples in the preferred + * format of the current output device. The resulting samples are forwarded + * to the output device's sink stream. */ -class SinkMixer { +class SampleConverter { public: - SinkMixer(); - ~SinkMixer(); + SampleConverter(); + ~SampleConverter(); auto SetOutput(std::shared_ptr<IAudioOutput>) -> void; - auto MixAndSend(cpp::span<sample::Sample>, - const IAudioOutput::Format& format, - bool is_eos) -> void; + auto ConvertSamples(cpp::span<sample::Sample>, + const IAudioOutput::Format& format, + bool is_eos) -> void; private: auto Main() -> void; diff --git a/src/audio/include/audio_task.hpp b/src/audio/include/audio_decoder.hpp index 08c5769c..1759f6e4 100644 --- a/src/audio/include/audio_task.hpp +++ b/src/audio/include/audio_decoder.hpp @@ -9,15 +9,18 @@ #include <cstdint> #include <memory> +#include "audio_converter.hpp" #include "audio_sink.hpp" #include "audio_source.hpp" #include "codec.hpp" -#include "sink_mixer.hpp" #include "track.hpp" #include "types.hpp" namespace audio { +/* + * Sample-based timer for the current elapsed playback time. + */ class Timer { public: Timer(const codecs::ICodec::OutputFormat& format); @@ -32,25 +35,30 @@ class Timer { uint32_t total_duration_seconds_; }; -class AudioTask { +/* + * Handle to a persistent task that takes bytes from the given source, decodes + * them into sample::Sample (normalised to 16 bit signed PCM), and then + * forwards the resulting stream to the given converter. + */ +class Decoder { public: static auto Start(std::shared_ptr<IAudioSource> source, - std::shared_ptr<SinkMixer> mixer) -> AudioTask*; + std::shared_ptr<SampleConverter> converter) -> Decoder*; auto Main() -> void; - AudioTask(const AudioTask&) = delete; - AudioTask& operator=(const AudioTask&) = delete; + Decoder(const Decoder&) = delete; + Decoder& operator=(const Decoder&) = delete; private: - AudioTask(std::shared_ptr<IAudioSource> source, - std::shared_ptr<SinkMixer> mixer); + Decoder(std::shared_ptr<IAudioSource> source, + std::shared_ptr<SampleConverter> converter); auto BeginDecoding(std::shared_ptr<codecs::IStream>) -> bool; auto ContinueDecoding() -> bool; std::shared_ptr<IAudioSource> source_; - std::shared_ptr<SinkMixer> mixer_; + std::shared_ptr<SampleConverter> converter_; std::shared_ptr<codecs::IStream> stream_; std::unique_ptr<codecs::ICodec> codec_; diff --git a/src/audio/include/audio_fsm.hpp b/src/audio/include/audio_fsm.hpp index 6c785426..430bc298 100644 --- a/src/audio/include/audio_fsm.hpp +++ b/src/audio/include/audio_fsm.hpp @@ -13,8 +13,8 @@ #include "audio_sink.hpp" #include "tinyfsm.hpp" +#include "audio_decoder.hpp" #include "audio_events.hpp" -#include "audio_task.hpp" #include "bt_audio_output.hpp" #include "database.hpp" #include "display.hpp" @@ -68,9 +68,9 @@ class AudioState : public tinyfsm::Fsm<AudioState> { static std::shared_ptr<drivers::I2SDac> sDac; static std::weak_ptr<database::Database> sDatabase; - static std::unique_ptr<AudioTask> sTask; static std::shared_ptr<FatfsAudioInput> sFileSource; - static std::shared_ptr<SinkMixer> sMixer; + static std::unique_ptr<Decoder> sDecoder; + static std::shared_ptr<SampleConverter> sSampleConverter; static std::shared_ptr<IAudioOutput> sOutput; static TrackQueue* sTrackQueue; |
