diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-01-11 05:54:30 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-01-11 05:54:30 +0000 |
| commit | 0e04eb918ec976017276306181282769d8896c83 (patch) | |
| tree | 562da509df2ab03d3906cf3c0f56063f6acc9865 /src/codecs/include/wav.hpp | |
| parent | 55bde70b9651b411ac0135bd4704f5b6972ea799 (diff) | |
| download | tangara-fw-0e04eb918ec976017276306181282769d8896c83.tar.gz | |
wav-codec (#13)
here is a wav decoder, enjoy!
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/13
Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
Co-authored-by: ailurux <ailuruxx@gmail.com>
Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'src/codecs/include/wav.hpp')
| -rw-r--r-- | src/codecs/include/wav.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
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 <ailuruxx@gmail.com> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstddef> +#include <cstdint> +#include <memory> +#include <optional> +#include <string> +#include <utility> + +#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<IStream> input) + -> cpp::result<OutputFormat, Error> override; + + auto DecodeTo(cpp::span<sample::Sample> destination) + -> cpp::result<OutputInfo, Error> override; + + auto SeekTo(std::size_t target_sample) -> cpp::result<void, Error> override; + + WavDecoder(const WavDecoder&) = delete; + WavDecoder& operator=(const WavDecoder&) = delete; + + private: + std::shared_ptr<IStream> 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 |
