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/audio_decoder.hpp | |
| parent | c635d5011c37c02246135fe0df404631ec111bd6 (diff) | |
| download | tangara-fw-f3c5eec0251ec98f90d324c88d3519de2e6ee5e0.tar.gz | |
Rename the main audio tasks to be more sensible
Diffstat (limited to 'src/audio/include/audio_decoder.hpp')
| -rw-r--r-- | src/audio/include/audio_decoder.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/audio/include/audio_decoder.hpp b/src/audio/include/audio_decoder.hpp new file mode 100644 index 00000000..1759f6e4 --- /dev/null +++ b/src/audio/include/audio_decoder.hpp @@ -0,0 +1,73 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> +#include <memory> + +#include "audio_converter.hpp" +#include "audio_sink.hpp" +#include "audio_source.hpp" +#include "codec.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); + + auto AddSamples(std::size_t) -> void; + + private: + uint32_t current_seconds_; + uint32_t current_sample_in_second_; + uint32_t samples_per_second_; + + uint32_t total_duration_seconds_; +}; + +/* + * 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<SampleConverter> converter) -> Decoder*; + + auto Main() -> void; + + Decoder(const Decoder&) = delete; + Decoder& operator=(const Decoder&) = delete; + + private: + 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<SampleConverter> converter_; + + std::shared_ptr<codecs::IStream> stream_; + std::unique_ptr<codecs::ICodec> codec_; + std::unique_ptr<Timer> timer_; + + std::optional<codecs::ICodec::OutputFormat> current_format_; + std::optional<IAudioOutput::Format> current_sink_format_; + + cpp::span<sample::Sample> codec_buffer_; +}; + +} // namespace audio |
