#pragma once #include "./frame_stream2.hpp" #include #include #include #include // raw audio // channels make samples interleaved, // planar channels are not supported struct AudioFrame { // sequence number, to detect gaps uint32_t seq {0}; // TODO: maybe use ts instead to discard old? // since buffer size is variable, some timestamp would be needed to estimate the lost time // samples per second uint32_t sample_rate {48'000}; size_t channels {0}; std::variant< std::vector, // S16, platform endianess Span, // non owning variant, for direct consumption std::vector, // f32 Span // non owning variant, for direct consumption > buffer; // helpers bool isS16(void) const { return std::holds_alternative>(buffer) || std::holds_alternative>(buffer) ; } bool isF32(void) const { return std::holds_alternative>(buffer) || std::holds_alternative>(buffer) ; } template Span getSpan(void) const { static_assert(std::is_same_v || std::is_same_v); if constexpr (std::is_same_v) { assert(isS16()); if (std::holds_alternative>(buffer)) { return Span{std::get>(buffer)}; } else { return std::get>(buffer); } } else if constexpr (std::is_same_v) { assert(isF32()); if (std::holds_alternative>(buffer)) { return Span{std::get>(buffer)}; } else { return std::get>(buffer); } } return {}; } }; using AudioFrameStream2I = FrameStream2I;