// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2022-2023 by Ronald "Eidolon" Kinard // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- #ifndef __SRB2_AUDIO_OGG_HPP__ #define __SRB2_AUDIO_OGG_HPP__ #include #include #include #include #include #include "../io/streams.hpp" #include "source.hpp" namespace srb2::audio { class StbVorbisException final : public std::exception { int code_; public: explicit StbVorbisException(int code) noexcept; virtual const char* what() const noexcept; }; struct OggComment { std::string vendor; std::vector comments; }; class Ogg final { std::vector memory_data_; stb_vorbis* instance_; public: Ogg() noexcept; explicit Ogg(std::vector data); explicit Ogg(tcb::span data); Ogg(const Ogg&) = delete; Ogg(Ogg&& rhs) noexcept; Ogg& operator=(const Ogg&) = delete; Ogg& operator=(Ogg&& rhs) noexcept; ~Ogg(); std::size_t get_samples(tcb::span> buffer); std::size_t get_samples(tcb::span> buffer); void seek(std::size_t sample); std::size_t position() const; float position_seconds() const; OggComment comment() const; std::size_t sample_rate() const; std::size_t channels() const; std::size_t duration_samples() const; float duration_seconds() const; private: void _init_with_data(); }; template , int> = 0> inline Ogg load_ogg(I& stream) { std::vector data = srb2::io::read_to_vec(stream); return Ogg {std::move(data)}; } } // namespace srb2::audio #endif // __SRB2_AUDIO_OGG_HPP__