#pragma once #include #include #include #include #include "miniwin/miniwin.h" #include "utils/stdcompat/shared_ptr_array.hpp" namespace devilution { class SoundSample final { public: SoundSample() = default; SoundSample(SoundSample &&) noexcept = default; SoundSample &operator=(SoundSample &&) noexcept = default; void Release(); bool IsPlaying(); void Play(int lVolume, int lPan, int channel = -1); void Stop(); int SetChunkStream(std::string filePath); /** * @brief Sets the sample's WAV, FLAC, or Ogg/Vorbis data. * @param fileData Buffer containing the data * @param dwBytes Length of buffer * @return 0 on success, -1 otherwise */ int SetChunk(ArraySharedPtr file_data, std::size_t dwBytes); [[nodiscard]] bool IsStreaming() const { return file_data_ == nullptr; } int DuplicateFrom(const SoundSample &other) { if (other.IsStreaming()) return SetChunkStream(other.file_path_); return SetChunk(other.file_data_, other.file_data_size_); } int GetLength() const; private: // Non-streaming audio fields: ArraySharedPtr file_data_; std::size_t file_data_size_; // Set for streaming audio to allow for duplicating it: std::string file_path_; std::unique_ptr stream_; }; } // namespace devilution