summaryrefslogtreecommitdiff
path: root/src/tangara/audio/audio_decoder.hpp
diff options
context:
space:
mode:
authorcooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
commit3ceb8025ee4330c177101ed30ec17dfb0002f41e (patch)
tree58350210f15df7d00d967cac6f30eeceeb031a3c /src/tangara/audio/audio_decoder.hpp
parent964da15a0b84f8e5f00e8abac2f7dfda0bf60488 (diff)
parent9fafd797a5504f458b5fcae4a1d28a68da936315 (diff)
downloadtangara-fw-3ceb8025ee4330c177101ed30ec17dfb0002f41e.tar.gz
Merge pull request 'Break dependency cycles with our components by merging co-dependent components together' (#68) from jqln/component-merge into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/68
Diffstat (limited to 'src/tangara/audio/audio_decoder.hpp')
-rw-r--r--src/tangara/audio/audio_decoder.hpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tangara/audio/audio_decoder.hpp b/src/tangara/audio/audio_decoder.hpp
new file mode 100644
index 00000000..dfd6f403
--- /dev/null
+++ b/src/tangara/audio/audio_decoder.hpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <memory>
+
+#include "audio/audio_converter.hpp"
+#include "audio/audio_events.hpp"
+#include "audio/audio_sink.hpp"
+#include "audio/audio_source.hpp"
+#include "codec.hpp"
+#include "database/track.hpp"
+#include "types.hpp"
+
+namespace audio {
+
+/*
+ * 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<TaggedStream>) -> 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::optional<codecs::ICodec::OutputFormat> current_format_;
+ std::optional<IAudioOutput::Format> current_sink_format_;
+
+ std::span<sample::Sample> codec_buffer_;
+};
+
+} // namespace audio