From 4e27de21e49900963ffa61cc9c0a676bb028f992 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 16 Aug 2023 10:57:55 +1000 Subject: clean up a bunch of obselete audio code --- src/audio/include/stream_info.hpp | 174 -------------------------------------- 1 file changed, 174 deletions(-) delete mode 100644 src/audio/include/stream_info.hpp (limited to 'src/audio/include/stream_info.hpp') diff --git a/src/audio/include/stream_info.hpp b/src/audio/include/stream_info.hpp deleted file mode 100644 index 01dd282a..00000000 --- a/src/audio/include/stream_info.hpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "esp_heap_caps.h" -#include "freertos/FreeRTOS.h" -#include "freertos/ringbuf.h" -#include "freertos/stream_buffer.h" - -#include "result.hpp" -#include "span.hpp" -#include "types.hpp" - -namespace audio { - -class StreamInfo { - public: - StreamInfo() : bytes_in_stream_(0), total_length_bytes_(), format_() {} - - // The number of bytes that are available for consumption within this - // stream's buffer. - auto bytes_in_stream() -> std::size_t& { return bytes_in_stream_; } - auto bytes_in_stream() const -> std::size_t { return bytes_in_stream_; } - - auto total_length_bytes() -> std::optional& { - return total_length_bytes_; - } - auto total_length_bytes() const -> std::optional { - return total_length_bytes_; - } - - auto total_length_seconds() -> std::optional& { - return total_length_seconds_; - } - auto total_length_seconds() const -> std::optional { - return total_length_seconds_; - } - - struct Encoded { - // The codec that this stream is associated with. - codecs::StreamType type; - - bool operator==(const Encoded&) const = default; - }; - - /* - * Two-channel, interleaved, 32-bit floating point pcm samples. - */ - struct FloatingPointPcm { - // Number of channels in this stream. - uint8_t channels; - // The sample rate. - uint32_t sample_rate; - - bool operator==(const FloatingPointPcm&) const = default; - }; - - struct Pcm { - // Number of channels in this stream. - uint8_t channels; - // Number of bits per sample. - uint8_t bits_per_sample; - // The sample rate. - uint32_t sample_rate; - - auto bytes_per_sample() const -> uint8_t { - return bits_per_sample == 16 ? 2 : 4; - } - - bool operator==(const Pcm&) const = default; - }; - - typedef std::variant Format; - auto format() const -> const Format& { return format_; } - auto set_format(Format f) -> void { format_ = f; } - - template - auto format_as() const -> std::optional { - if (std::holds_alternative(format_)) { - return std::get(format_); - } - return {}; - } - - bool operator==(const StreamInfo&) const = default; - - private: - std::size_t bytes_in_stream_; - std::optional total_length_bytes_; - std::optional total_length_seconds_; - Format format_{}; -}; - -class InputStream; -class OutputStream; - -class RawStream { - public: - explicit RawStream(std::size_t size); - RawStream(std::size_t size, uint32_t); - ~RawStream(); - - auto info() -> StreamInfo& { return info_; } - auto data() -> cpp::span; - template - auto data_as() -> cpp::span { - auto orig = data(); - return {reinterpret_cast(orig.data()), orig.size_bytes() / sizeof(T)}; - } - auto empty() const -> bool { return info_.bytes_in_stream() == 0; } - - private: - StreamInfo info_; - std::size_t buffer_size_; - std::byte* buffer_; -}; - -class InputStream { - public: - explicit InputStream(RawStream* s) : raw_(s) {} - - void consume(std::size_t bytes) const; - - const StreamInfo& info() const; - - cpp::span data() const; - template - auto data_as() const -> cpp::span { - auto orig = data(); - return {reinterpret_cast(orig.data()), - orig.size_bytes() / sizeof(T)}; - } - - private: - RawStream* raw_; -}; - -class OutputStream { - public: - explicit OutputStream(RawStream* s) : raw_(s) {} - - void add(std::size_t bytes) const; - - void prepare(const StreamInfo::Format& new_format, - std::optional length); - - const StreamInfo& info() const; - - cpp::span data() const; - template - auto data_as() const -> cpp::span { - auto orig = data(); - return {reinterpret_cast(orig.data()), orig.size_bytes() / sizeof(T)}; - } - - private: - RawStream* raw_; -}; - -} // namespace audio -- cgit v1.2.3