Audio: Rewrite audio module

This commit is contained in:
Jérôme Leclercq
2022-03-17 09:07:52 +01:00
parent eb4629947e
commit 6165b3a101
43 changed files with 1898 additions and 1611 deletions

View File

@@ -8,6 +8,7 @@
#define NAZARA_AUDIO_SOUNDBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/AudioDevice.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
@@ -15,7 +16,8 @@
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Core/Signal.hpp>
#include <memory>
#include <unordered_map>
namespace Nz
{
@@ -26,6 +28,8 @@ namespace Nz
bool IsValid() const;
};
class AudioBuffer;
class AudioDevice;
class Sound;
class SoundBuffer;
@@ -40,36 +44,41 @@ namespace Nz
friend Sound;
public:
SoundBuffer();
SoundBuffer() = default;
SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples);
SoundBuffer(const SoundBuffer&) = delete;
SoundBuffer(SoundBuffer&&) = delete;
~SoundBuffer();
~SoundBuffer() = default;
bool Create(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples);
void Destroy();
const std::shared_ptr<AudioBuffer>& GetBuffer(AudioDevice* device);
UInt32 GetDuration() const;
AudioFormat GetFormat() const;
const Int16* GetSamples() const;
UInt64 GetSampleCount() const;
UInt32 GetSampleRate() const;
bool IsValid() const;
inline UInt32 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 bool IsFormatSupported(AudioFormat format);
static std::shared_ptr<SoundBuffer> LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams());
static std::shared_ptr<SoundBuffer> LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
static std::shared_ptr<SoundBuffer> LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
private:
unsigned int GetOpenALBuffer() const;
struct AudioDeviceEntry
{
std::shared_ptr<AudioBuffer> audioBuffer;
std::unique_ptr<SoundBufferImpl> m_impl;
NazaraSlot(AudioDevice, OnAudioDeviceRelease, audioDeviceReleaseSlot);
};
std::unordered_map<AudioDevice*, AudioDeviceEntry> m_audioBufferByDevice;
std::unique_ptr<Int16[]> m_samples;
AudioFormat m_format;
UInt32 m_duration;
UInt32 m_sampleRate;
UInt64 m_sampleCount;
};
}