// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Audio module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_AUDIO_SOUNDBUFFER_HPP #define NAZARA_AUDIO_SOUNDBUFFER_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace Nz { struct SoundBufferParams : ResourceParameters { bool forceMono = false; bool IsValid() const; }; class AudioBuffer; class AudioDevice; class Sound; class SoundBuffer; using SoundBufferLibrary = ObjectLibrary; using SoundBufferLoader = ResourceLoader; using SoundBufferManager = ResourceManager; struct SoundBufferImpl; class NAZARA_AUDIO_API SoundBuffer : public Resource { friend Sound; public: using Params = SoundBufferParams; SoundBuffer() = default; SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples); SoundBuffer(const SoundBuffer&) = delete; SoundBuffer(SoundBuffer&&) = delete; ~SoundBuffer() = default; const std::shared_ptr& GetAudioBuffer(AudioDevice* device); inline Time GetDuration() const; inline AudioFormat GetFormat() const; inline const Int16* GetSamples() const; inline UInt64 GetSampleCount() const; inline UInt32 GetSampleRate() const; SoundBuffer& operator=(const SoundBuffer&) = delete; SoundBuffer& operator=(SoundBuffer&&) = delete; static std::shared_ptr LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams()); static std::shared_ptr LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams()); static std::shared_ptr LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams()); private: struct AudioDeviceEntry { std::shared_ptr audioBuffer; NazaraSlot(AudioDevice, OnAudioDeviceRelease, audioDeviceReleaseSlot); }; std::unordered_map m_audioBufferByDevice; std::unique_ptr m_samples; AudioFormat m_format; Time m_duration; UInt32 m_sampleRate; UInt64 m_sampleCount; }; } #include #endif // NAZARA_AUDIO_SOUNDBUFFER_HPP