From 0e04eb918ec976017276306181282769d8896c83 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 11 Jan 2024 05:54:30 +0000 Subject: wav-codec (#13) here is a wav decoder, enjoy! Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/13 Reviewed-by: cooljqln Co-authored-by: ailurux Co-committed-by: ailurux --- src/codecs/include/wav.hpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/codecs/include/wav.hpp (limited to 'src/codecs/include/wav.hpp') diff --git a/src/codecs/include/wav.hpp b/src/codecs/include/wav.hpp new file mode 100644 index 00000000..896976dd --- /dev/null +++ b/src/codecs/include/wav.hpp @@ -0,0 +1,57 @@ +/* + * Copyright 2023 Daniel + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "sample.hpp" +#include "source_buffer.hpp" + +#include "codec.hpp" + +namespace codecs { + +static const uint16_t kWaveFormatPCM = 0x0001; +static const uint16_t kWaveFormatIEEEFloat = 0x0003; +static const uint16_t kWaveFormatAlaw = 0x0006; +static const uint16_t kWaveFormatMulaw = 0x0007; +static const uint16_t kWaveFormatExtensible = 0xFFFE; + +class WavDecoder : public ICodec { + public: + WavDecoder(); + ~WavDecoder(); + + auto OpenStream(std::shared_ptr input) + -> cpp::result override; + + auto DecodeTo(cpp::span destination) + -> cpp::result override; + + auto SeekTo(std::size_t target_sample) -> cpp::result override; + + WavDecoder(const WavDecoder&) = delete; + WavDecoder& operator=(const WavDecoder&) = delete; + + private: + std::shared_ptr input_; + SourceBuffer buffer_; + uint16_t wave_format_; + uint16_t subformat_; + OutputFormat output_format_; + uint16_t bytes_per_sample_; + uint16_t num_channels_; + + auto GetFormat() const -> uint16_t; +}; + +} // namespace codecs -- cgit v1.2.3