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

@@ -13,8 +13,6 @@
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
namespace Nz
{
@@ -32,35 +30,23 @@ namespace Nz
Audio(Audio&&) = delete;
~Audio();
float GetDopplerFactor() const;
float GetGlobalVolume() const;
Vector3f GetListenerDirection() const;
Vector3f GetListenerPosition() const;
Quaternionf GetListenerRotation() const;
Vector3f GetListenerVelocity() const;
const std::shared_ptr<AudioDevice>& GetDefaultDevice() const;
SoundBufferLoader& GetSoundBufferLoader();
const SoundBufferLoader& GetSoundBufferLoader() const;
SoundStreamLoader& GetSoundStreamLoader();
const SoundStreamLoader& GetSoundStreamLoader() const;
float GetSpeedOfSound() const;
bool IsFormatSupported(AudioFormat format) const;
std::shared_ptr<AudioDevice> OpenOutputDevice(const std::string& deviceName);
void SetDopplerFactor(float dopplerFactor);
void SetGlobalVolume(float volume);
void SetListenerDirection(const Vector3f& direction);
void SetListenerDirection(float dirX, float dirY, float dirZ);
void SetListenerPosition(const Vector3f& position);
void SetListenerPosition(float x, float y, float z);
void SetListenerRotation(const Quaternionf& rotation);
void SetListenerVelocity(const Vector3f& velocity);
void SetListenerVelocity(float velX, float velY, float velZ);
void SetSpeedOfSound(float speed);
std::vector<std::string> QueryInputDevices() const;
std::vector<std::string> QueryOutputDevices() const;
Audio& operator=(const Audio&) = delete;
Audio& operator=(Audio&&) = delete;
private:
std::shared_ptr<AudioDevice> m_defaultDevice;
SoundBufferLoader m_soundBufferLoader;
SoundStreamLoader m_soundStreamLoader;

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2022 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_AUDIOBUFFER_HPP
#define NAZARA_AUDIO_AUDIOBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <memory>
namespace Nz
{
class AudioDevice;
class NAZARA_AUDIO_API AudioBuffer
{
public:
inline AudioBuffer(std::shared_ptr<AudioDevice> device);
AudioBuffer(const AudioBuffer&) = default;
AudioBuffer(AudioBuffer&&) = default;
virtual ~AudioBuffer();
inline const std::shared_ptr<AudioDevice>& GetAudioDevice() const;
virtual UInt32 GetSampleCount() const = 0;
virtual UInt32 GetSize() const = 0;
virtual UInt32 GetSampleRate() const = 0;
virtual bool Reset(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const void* samples) = 0;
AudioBuffer& operator=(const AudioBuffer&) = default;
AudioBuffer& operator=(AudioBuffer&&) = default;
private:
std::shared_ptr<AudioDevice> m_device;
};
}
#include <Nazara/Audio/AudioBuffer.inl>
#endif // NAZARA_AUDIO_AUDIOBUFFER_HPP

View File

@@ -0,0 +1,21 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/AudioBuffer.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline AudioBuffer::AudioBuffer(std::shared_ptr<AudioDevice> device) :
m_device(std::move(device))
{
}
inline const std::shared_ptr<AudioDevice>& AudioBuffer::GetAudioDevice() const
{
return m_device;
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2022 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_AUDIODEVICE_HPP
#define NAZARA_AUDIO_AUDIODEVICE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <memory>
namespace Nz
{
class AudioBuffer;
class AudioSource;
class NAZARA_AUDIO_API AudioDevice : public std::enable_shared_from_this<AudioDevice>
{
public:
AudioDevice() = default;
AudioDevice(const AudioDevice&) = delete;
AudioDevice(AudioDevice&&) = default;
virtual ~AudioDevice();
virtual std::shared_ptr<AudioBuffer> CreateBuffer() = 0;
virtual std::shared_ptr<AudioSource> CreateSource() = 0;
virtual float GetDopplerFactor() const = 0;
virtual float GetGlobalVolume() const = 0;
virtual Vector3f GetListenerDirection(Vector3f* up = nullptr) const = 0;
virtual Vector3f GetListenerPosition() const = 0;
virtual Quaternionf GetListenerRotation(Vector3f* up = nullptr) const = 0;
virtual Vector3f GetListenerVelocity() const = 0;
virtual float GetSpeedOfSound() const = 0;
virtual bool IsFormatSupported(AudioFormat format) const = 0;
virtual void SetDopplerFactor(float dopplerFactor) = 0;
virtual void SetGlobalVolume(float volume) = 0;
virtual void SetListenerDirection(const Vector3f& direction, const Vector3f& up = Vector3f::Up()) = 0;
virtual void SetListenerPosition(const Vector3f& position) = 0;
inline void SetListenerRotation(const Quaternionf& rotation);
virtual void SetListenerVelocity(const Vector3f& velocity) = 0;
virtual void SetSpeedOfSound(float speed) = 0;
AudioDevice& operator=(const AudioDevice&) = delete;
AudioDevice& operator=(AudioDevice&&) = default;
NazaraSignal(OnAudioDeviceRelease, AudioDevice* /*audioDevice*/);
};
}
#include <Nazara/Audio/AudioDevice.inl>
#endif // NAZARA_AUDIO_AUDIODEVICE_HPP

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/AudioDevice.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline void AudioDevice::SetListenerRotation(const Quaternionf& rotation)
{
SetListenerDirection(rotation * Vector3f::Forward(), rotation * Vector3f::Up());
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2022 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_AUDIOSOURCE_HPP
#define NAZARA_AUDIO_AUDIOSOURCE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Math/Vector3.hpp>
namespace Nz
{
class AudioBuffer;
class AudioDevice;
class NAZARA_AUDIO_API AudioSource
{
public:
inline AudioSource(std::shared_ptr<AudioDevice> device);
AudioSource(const AudioSource&) = delete;
AudioSource(AudioSource&&) = delete;
virtual ~AudioSource();
virtual void EnableLooping(bool loop) = 0;
virtual void EnableSpatialization(bool spatialization) = 0;
inline const std::shared_ptr<AudioDevice>& GetAudioDevice() const;
virtual float GetAttenuation() const = 0;
virtual float GetMinDistance() const = 0;
virtual float GetPitch() const = 0;
virtual Vector3f GetPosition() const = 0;
virtual UInt32 GetSampleOffset() const = 0;
virtual Vector3f GetVelocity() const = 0;
virtual SoundStatus GetStatus() const = 0;
virtual float GetVolume() const = 0;
virtual bool IsLooping() const = 0;
virtual bool IsSpatializationEnabled() const = 0;
virtual void QueueBuffer(std::shared_ptr<AudioBuffer> audioBuffer) = 0;
virtual void Pause() = 0;
virtual void Play() = 0;
virtual void SetAttenuation(float attenuation) = 0;
virtual void SetBuffer(std::shared_ptr<AudioBuffer> audioBuffer) = 0;
virtual void SetMinDistance(float minDistance) = 0;
virtual void SetPitch(float pitch) = 0;
virtual void SetPosition(const Vector3f& position) = 0;
virtual void SetSampleOffset(UInt32 offset) = 0;
virtual void SetVelocity(const Vector3f& velocity) = 0;
virtual void SetVolume(float volume) = 0;
virtual void Stop() = 0;
virtual std::shared_ptr<AudioBuffer> TryUnqueueProcessedBuffer() = 0;
virtual void UnqueueAllBuffers() = 0;
AudioSource& operator=(const AudioSource&) = delete;
AudioSource& operator=(AudioSource&&) = delete;
private:
std::shared_ptr<AudioDevice> m_device;
};
}
#include <Nazara/Audio/AudioSource.inl>
#endif // NAZARA_AUDIO_AUDIOSOURCE_HPP

View File

@@ -0,0 +1,21 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/AudioSource.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline AudioSource::AudioSource(std::shared_ptr<AudioDevice> device) :
m_device(std::move(device))
{
}
inline const std::shared_ptr<AudioDevice>& AudioSource::GetAudioDevice() const
{
return m_device;
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -40,9 +40,6 @@
// Activate the security tests based on the code (Advised for development)
#define NAZARA_AUDIO_SAFE 1
// The number of buffers used for audio streaming (At least two)
#define NAZARA_AUDIO_STREAMED_BUFFER_COUNT 2
/// Checking the values and types of certain constants
#include <Nazara/Audio/ConfigCheck.hpp>

View File

@@ -18,8 +18,6 @@
#define NAZARA_AUDIO_MANAGE_MEMORY 0
#endif
NazaraCheckTypeAndVal(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, integral, >, 0, " shall be a strictly positive integer");
#undef NazaraCheckTypeAndVal
#endif // NAZARA_AUDIO_CONFIGCHECK_HPP

View File

@@ -7,6 +7,8 @@
#ifndef NAZARA_AUDIO_ENUMS_HPP
#define NAZARA_AUDIO_ENUMS_HPP
#include <cstdint>
namespace Nz
{
enum class AudioFormat

View File

@@ -11,20 +11,24 @@
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/SoundEmitter.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <atomic>
#include <condition_variable>
#include <exception>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
namespace Nz
{
struct MusicImpl;
class AudioBuffer;
class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
{
public:
Music();
Music(AudioDevice& device);
Music(const Music&) = delete;
Music(Music&&) noexcept;
Music(Music&&) noexcept = default;
~Music();
bool Create(std::shared_ptr<SoundStream> soundStream);
@@ -53,12 +57,22 @@ namespace Nz
void Stop() override;
Music& operator=(const Music&) = delete;
Music& operator=(Music&&) noexcept;
Music& operator=(Music&&) noexcept = default;
private:
std::unique_ptr<MusicImpl> m_impl;
AudioFormat m_audioFormat;
std::atomic_bool m_streaming;
std::atomic<UInt64> m_processedSamples;
mutable std::mutex m_bufferLock;
std::size_t m_bufferCount;
std::shared_ptr<SoundStream> m_stream;
std::thread m_thread;
std::vector<Int16> m_chunkSamples;
UInt32 m_sampleRate;
UInt64 m_streamOffset;
bool m_looping;
bool FillAndQueueBuffer(unsigned int buffer);
bool FillAndQueueBuffer(std::shared_ptr<AudioBuffer> buffer);
void MusicThread(std::condition_variable& cv, std::mutex& m, std::exception_ptr& err);
void StopThread();
};

View File

@@ -7,13 +7,9 @@
#ifndef NAZARA_AUDIO_OPENAL_HPP
#define NAZARA_AUDIO_OPENAL_HPP
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
// no include reordering
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <string>
#include <vector>
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
// Inclusion of OpenAL headers
@@ -57,135 +53,102 @@ using OpenALDetail::ALCuint;
using OpenALDetail::ALCushort;
using OpenALDetail::ALCvoid;
namespace Nz
{
using OpenALFunc = void(*)();
#define NAZARA_AUDIO_FOREACH_AL_FUNC(cb) \
cb(alBuffer3f, OpenALDetail::LPALBUFFER3F) \
cb(alBuffer3i, OpenALDetail::LPALBUFFER3I) \
cb(alBufferData, OpenALDetail::LPALBUFFERDATA) \
cb(alBufferf, OpenALDetail::LPALBUFFERF) \
cb(alBufferfv, OpenALDetail::LPALBUFFERFV) \
cb(alBufferi, OpenALDetail::LPALBUFFERI) \
cb(alBufferiv, OpenALDetail::LPALBUFFERIV) \
cb(alDeleteBuffers, OpenALDetail::LPALDELETEBUFFERS) \
cb(alDeleteSources, OpenALDetail::LPALDELETESOURCES) \
cb(alDisable, OpenALDetail::LPALDISABLE) \
cb(alDistanceModel, OpenALDetail::LPALDISTANCEMODEL) \
cb(alDopplerFactor, OpenALDetail::LPALDOPPLERFACTOR) \
cb(alDopplerVelocity, OpenALDetail::LPALDOPPLERVELOCITY) \
cb(alEnable, OpenALDetail::LPALENABLE) \
cb(alGenBuffers, OpenALDetail::LPALGENBUFFERS) \
cb(alGenSources, OpenALDetail::LPALGENSOURCES) \
cb(alGetBoolean, OpenALDetail::LPALGETBOOLEAN) \
cb(alGetBooleanv, OpenALDetail::LPALGETBOOLEANV) \
cb(alGetBuffer3f, OpenALDetail::LPALGETBUFFER3F) \
cb(alGetBuffer3i, OpenALDetail::LPALGETBUFFER3I) \
cb(alGetBufferf, OpenALDetail::LPALGETBUFFERF) \
cb(alGetBufferfv, OpenALDetail::LPALGETBUFFERFV) \
cb(alGetBufferi, OpenALDetail::LPALGETBUFFERI) \
cb(alGetBufferiv, OpenALDetail::LPALGETBUFFERIV) \
cb(alGetDouble, OpenALDetail::LPALGETDOUBLE) \
cb(alGetDoublev, OpenALDetail::LPALGETDOUBLEV) \
cb(alGetEnumValue, OpenALDetail::LPALGETENUMVALUE) \
cb(alGetError, OpenALDetail::LPALGETERROR) \
cb(alGetFloat, OpenALDetail::LPALGETFLOAT) \
cb(alGetFloatv, OpenALDetail::LPALGETFLOATV) \
cb(alGetInteger, OpenALDetail::LPALGETINTEGER) \
cb(alGetIntegerv, OpenALDetail::LPALGETINTEGERV) \
cb(alGetListener3f, OpenALDetail::LPALGETLISTENER3F) \
cb(alGetListener3i, OpenALDetail::LPALGETLISTENER3I) \
cb(alGetListenerf, OpenALDetail::LPALGETLISTENERF) \
cb(alGetListenerfv, OpenALDetail::LPALGETLISTENERFV) \
cb(alGetListeneri, OpenALDetail::LPALGETLISTENERI) \
cb(alGetListeneriv, OpenALDetail::LPALGETLISTENERIV) \
cb(alGetProcAddress, OpenALDetail::LPALGETPROCADDRESS) \
cb(alGetSource3f, OpenALDetail::LPALGETSOURCE3F) \
cb(alGetSource3i, OpenALDetail::LPALGETSOURCE3I) \
cb(alGetSourcef, OpenALDetail::LPALGETSOURCEF) \
cb(alGetSourcefv, OpenALDetail::LPALGETSOURCEFV) \
cb(alGetSourcei, OpenALDetail::LPALGETSOURCEI) \
cb(alGetSourceiv, OpenALDetail::LPALGETSOURCEIV) \
cb(alGetString, OpenALDetail::LPALGETSTRING) \
cb(alIsBuffer, OpenALDetail::LPALISBUFFER) \
cb(alIsEnabled, OpenALDetail::LPALISENABLED) \
cb(alIsExtensionPresent, OpenALDetail::LPALISEXTENSIONPRESENT) \
cb(alIsSource, OpenALDetail::LPALISSOURCE) \
cb(alListener3f, OpenALDetail::LPALLISTENER3F) \
cb(alListener3i, OpenALDetail::LPALLISTENER3I) \
cb(alListenerf, OpenALDetail::LPALLISTENERF) \
cb(alListenerfv, OpenALDetail::LPALLISTENERFV) \
cb(alListeneri, OpenALDetail::LPALLISTENERI) \
cb(alListeneriv, OpenALDetail::LPALLISTENERIV) \
cb(alSource3f, OpenALDetail::LPALSOURCE3F) \
cb(alSource3i, OpenALDetail::LPALSOURCE3I) \
cb(alSourcef, OpenALDetail::LPALSOURCEF) \
cb(alSourcefv, OpenALDetail::LPALSOURCEFV) \
cb(alSourcei, OpenALDetail::LPALSOURCEI) \
cb(alSourceiv, OpenALDetail::LPALSOURCEIV) \
cb(alSourcePause, OpenALDetail::LPALSOURCEPAUSE) \
cb(alSourcePausev, OpenALDetail::LPALSOURCEPAUSEV) \
cb(alSourcePlay, OpenALDetail::LPALSOURCEPLAY) \
cb(alSourcePlayv, OpenALDetail::LPALSOURCEPLAYV) \
cb(alSourceQueueBuffers, OpenALDetail::LPALSOURCEQUEUEBUFFERS) \
cb(alSourceRewind, OpenALDetail::LPALSOURCEREWIND) \
cb(alSourceRewindv, OpenALDetail::LPALSOURCEREWINDV) \
cb(alSourceStop, OpenALDetail::LPALSOURCESTOP) \
cb(alSourceStopv, OpenALDetail::LPALSOURCESTOPV) \
cb(alSourceUnqueueBuffers, OpenALDetail::LPALSOURCEUNQUEUEBUFFERS) \
cb(alSpeedOfSound, OpenALDetail::LPALSPEEDOFSOUND)
class NAZARA_AUDIO_API OpenAL
{
public:
static OpenALFunc GetEntry(const std::string& entryPoint);
static std::string GetRendererName();
static std::string GetVendorName();
static unsigned int GetVersion();
static bool Initialize(bool openDevice = true);
static bool IsInitialized();
static std::size_t QueryInputDevices(std::vector<std::string>& devices);
static std::size_t QueryOutputDevices(std::vector<std::string>& devices);
static bool SetDevice(const std::string& deviceName);
static void Uninitialize();
static ALenum AudioFormat[AudioFormatCount];
private:
static void CloseDevice();
static bool OpenDevice();
static OpenALFunc LoadEntry(const char* name, bool throwException = false);
};
// al
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3F alBuffer3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3I alBuffer3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERDATA alBufferData;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERF alBufferf;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERFV alBufferfv;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERI alBufferi;
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFERIV alBufferiv;
NAZARA_AUDIO_API extern OpenALDetail::LPALDELETEBUFFERS alDeleteBuffers;
NAZARA_AUDIO_API extern OpenALDetail::LPALDELETESOURCES alDeleteSources;
NAZARA_AUDIO_API extern OpenALDetail::LPALDISABLE alDisable;
NAZARA_AUDIO_API extern OpenALDetail::LPALDISTANCEMODEL alDistanceModel;
NAZARA_AUDIO_API extern OpenALDetail::LPALDOPPLERFACTOR alDopplerFactor;
NAZARA_AUDIO_API extern OpenALDetail::LPALDOPPLERVELOCITY alDopplerVelocity;
NAZARA_AUDIO_API extern OpenALDetail::LPALENABLE alEnable;
NAZARA_AUDIO_API extern OpenALDetail::LPALGENBUFFERS alGenBuffers;
NAZARA_AUDIO_API extern OpenALDetail::LPALGENSOURCES alGenSources;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBOOLEAN alGetBoolean;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBOOLEANV alGetBooleanv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFER3F alGetBuffer3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFER3I alGetBuffer3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERF alGetBufferf;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERFV alGetBufferfv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERI alGetBufferi;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETBUFFERIV alGetBufferiv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETDOUBLE alGetDouble;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETDOUBLEV alGetDoublev;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETENUMVALUE alGetEnumValue;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETERROR alGetError;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETFLOAT alGetFloat;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETFLOATV alGetFloatv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETINTEGER alGetInteger;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETINTEGERV alGetIntegerv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENER3F alGetListener3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENER3I alGetListener3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERF alGetListenerf;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERFV alGetListenerfv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERI alGetListeneri;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETLISTENERIV alGetListeneriv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETPROCADDRESS alGetProcAddress;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCE3F alGetSource3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCE3I alGetSource3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEF alGetSourcef;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEFV alGetSourcefv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEI alGetSourcei;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSOURCEIV alGetSourceiv;
NAZARA_AUDIO_API extern OpenALDetail::LPALGETSTRING alGetString;
NAZARA_AUDIO_API extern OpenALDetail::LPALISBUFFER alIsBuffer;
NAZARA_AUDIO_API extern OpenALDetail::LPALISENABLED alIsEnabled;
NAZARA_AUDIO_API extern OpenALDetail::LPALISEXTENSIONPRESENT alIsExtensionPresent;
NAZARA_AUDIO_API extern OpenALDetail::LPALISSOURCE alIsSource;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENER3F alListener3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENER3I alListener3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERF alListenerf;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERFV alListenerfv;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERI alListeneri;
NAZARA_AUDIO_API extern OpenALDetail::LPALLISTENERIV alListeneriv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCE3F alSource3f;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCE3I alSource3i;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEF alSourcef;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEFV alSourcefv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEI alSourcei;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEIV alSourceiv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPAUSE alSourcePause;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPAUSEV alSourcePausev;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPLAY alSourcePlay;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEPLAYV alSourcePlayv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEREWIND alSourceRewind;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEREWINDV alSourceRewindv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCESTOP alSourceStop;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCESTOPV alSourceStopv;
NAZARA_AUDIO_API extern OpenALDetail::LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers;
NAZARA_AUDIO_API extern OpenALDetail::LPALSPEEDOFSOUND alSpeedOfSound;
// alc
NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESAMPLES alcCaptureSamples;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESTART alcCaptureStart;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCAPTURESTOP alcCaptureStop;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCLOSEDEVICE alcCloseDevice;
NAZARA_AUDIO_API extern OpenALDetail::LPALCCREATECONTEXT alcCreateContext;
NAZARA_AUDIO_API extern OpenALDetail::LPALCDESTROYCONTEXT alcDestroyContext;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETCONTEXTSDEVICE alcGetContextsDevice;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETCURRENTCONTEXT alcGetCurrentContext;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETENUMVALUE alcGetEnumValue;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETERROR alcGetError;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETINTEGERV alcGetIntegerv;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETPROCADDRESS alcGetProcAddress;
NAZARA_AUDIO_API extern OpenALDetail::LPALCGETSTRING alcGetString;
NAZARA_AUDIO_API extern OpenALDetail::LPALCISEXTENSIONPRESENT alcIsExtensionPresent;
NAZARA_AUDIO_API extern OpenALDetail::LPALCMAKECONTEXTCURRENT alcMakeContextCurrent;
NAZARA_AUDIO_API extern OpenALDetail::LPALCOPENDEVICE alcOpenDevice;
NAZARA_AUDIO_API extern OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext;
NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext;
}
#define NAZARA_AUDIO_FOREACH_ALC_FUNC(cb) \
cb(alcCaptureCloseDevice, OpenALDetail::LPALCCAPTURECLOSEDEVICE) \
cb(alcCaptureOpenDevice, OpenALDetail::LPALCCAPTUREOPENDEVICE) \
cb(alcCaptureSamples, OpenALDetail::LPALCCAPTURESAMPLES) \
cb(alcCaptureStart, OpenALDetail::LPALCCAPTURESTART) \
cb(alcCaptureStop, OpenALDetail::LPALCCAPTURESTOP) \
cb(alcCloseDevice, OpenALDetail::LPALCCLOSEDEVICE) \
cb(alcCreateContext, OpenALDetail::LPALCCREATECONTEXT) \
cb(alcDestroyContext, OpenALDetail::LPALCDESTROYCONTEXT) \
cb(alcGetContextsDevice, OpenALDetail::LPALCGETCONTEXTSDEVICE) \
cb(alcGetCurrentContext, OpenALDetail::LPALCGETCURRENTCONTEXT) \
cb(alcGetEnumValue, OpenALDetail::LPALCGETENUMVALUE) \
cb(alcGetError, OpenALDetail::LPALCGETERROR) \
cb(alcGetIntegerv, OpenALDetail::LPALCGETINTEGERV) \
cb(alcGetProcAddress, OpenALDetail::LPALCGETPROCADDRESS) \
cb(alcGetString, OpenALDetail::LPALCGETSTRING) \
cb(alcIsExtensionPresent, OpenALDetail::LPALCISEXTENSIONPRESENT) \
cb(alcMakeContextCurrent, OpenALDetail::LPALCMAKECONTEXTCURRENT) \
cb(alcOpenDevice, OpenALDetail::LPALCOPENDEVICE) \
cb(alcProcessContext, OpenALDetail::LPALCPROCESSCONTEXT) \
cb(alcSuspendContext, OpenALDetail::LPALCSUSPENDCONTEXT) \
#endif // NAZARA_AUDIO_OPENAL

View File

@@ -0,0 +1,53 @@
// Copyright (C) 2022 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_OPENALBUFFER_HPP
#define NAZARA_AUDIO_OPENALBUFFER_HPP
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/AudioBuffer.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/OpenAL.hpp>
namespace Nz
{
class OpenALDevice;
class OpenALLibrary;
class NAZARA_AUDIO_API OpenALBuffer final : public AudioBuffer
{
public:
inline OpenALBuffer(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint bufferId);
OpenALBuffer(const OpenALBuffer&) = delete;
OpenALBuffer(OpenALBuffer&&) = delete;
~OpenALBuffer();
inline ALuint GetBufferId() const;
UInt32 GetSampleCount() const override;
UInt32 GetSize() const override;
UInt32 GetSampleRate() const override;
bool Reset(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const void* samples) override;
OpenALBuffer& operator=(const OpenALBuffer&) = delete;
OpenALBuffer& operator=(OpenALBuffer&&) = delete;
private:
OpenALDevice& GetDevice();
const OpenALDevice& GetDevice() const;
ALuint m_bufferId;
OpenALLibrary& m_library;
};
}
#include <Nazara/Audio/OpenALBuffer.inl>
#endif // NAZARA_AUDIO_OPENAL
#endif // NAZARA_AUDIO_OPENALBUFFER_HPP

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/OpenALBuffer.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline OpenALBuffer::OpenALBuffer(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint bufferId) :
AudioBuffer(std::move(device)),
m_bufferId(bufferId),
m_library(library)
{
}
inline ALuint OpenALBuffer::GetBufferId() const
{
return m_bufferId;
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -0,0 +1,76 @@
// Copyright (C) 2022 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_OPENALDEVICE_HPP
#define NAZARA_AUDIO_OPENALDEVICE_HPP
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/AudioDevice.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/OpenAL.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <array>
#include <string>
namespace Nz
{
class OpenALLibrary;
class NAZARA_AUDIO_API OpenALDevice : public AudioDevice
{
friend OpenALLibrary;
public:
OpenALDevice(OpenALLibrary& library, ALCdevice* device);
OpenALDevice(const OpenALDevice&) = delete;
OpenALDevice(OpenALDevice&&) = default;
~OpenALDevice();
std::shared_ptr<AudioBuffer> CreateBuffer() override;
std::shared_ptr<AudioSource> CreateSource() override;
float GetDopplerFactor() const override;
float GetGlobalVolume() const override;
Vector3f GetListenerDirection(Vector3f* up = nullptr) const override;
Vector3f GetListenerPosition() const override;
Quaternionf GetListenerRotation(Vector3f* up = nullptr) const override;
Vector3f GetListenerVelocity() const override;
float GetSpeedOfSound() const override;
bool IsFormatSupported(AudioFormat format) const override;
void MakeContextCurrent() const;
void SetDopplerFactor(float dopplerFactor) override;
void SetGlobalVolume(float volume) override;
void SetListenerDirection(const Vector3f& direction, const Vector3f& up = Vector3f::Up()) override;
void SetListenerPosition(const Vector3f& position) override;
void SetListenerVelocity(const Vector3f& velocity) override;
void SetSpeedOfSound(float speed) override;
inline ALenum TranslateAudioFormat(AudioFormat format) const;
OpenALDevice& operator=(const OpenALDevice&) = delete;
OpenALDevice& operator=(OpenALDevice&&) = default;
private:
std::array<ALenum, AudioFormatCount> m_audioFormatValues;
std::string m_renderer;
std::string m_vendor;
OpenALLibrary& m_library;
MovablePtr<ALCcontext> m_context;
MovablePtr<ALCdevice> m_device;
};
}
#include <Nazara/Audio/OpenALDevice.inl>
#endif // NAZARA_AUDIO_OPENAL
#endif // NAZARA_AUDIO_OPENALDEVICE_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/OpenALDevice.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline ALenum OpenALDevice::TranslateAudioFormat(AudioFormat format) const
{
return m_audioFormatValues[UnderlyingCast(format)];
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2022 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_OPENALLIBRARY_HPP
#define NAZARA_AUDIO_OPENALLIBRARY_HPP
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/OpenAL.hpp>
#include <Nazara/Audio/OpenALDevice.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <string>
#include <vector>
namespace Nz
{
class NAZARA_AUDIO_API OpenALLibrary
{
public:
OpenALLibrary() = default;
OpenALLibrary(const OpenALLibrary&) = delete;
OpenALLibrary(OpenALLibrary&&) = delete;
inline ~OpenALLibrary();
bool Load();
std::vector<std::string> QueryInputDevices();
std::vector<std::string> QueryOutputDevices();
std::shared_ptr<OpenALDevice> OpenDevice(const char* name = nullptr);
void Unload();
OpenALLibrary& operator=(const OpenALLibrary&) = delete;
OpenALLibrary& operator=(OpenALLibrary&&) = delete;
#define NAZARA_AUDIO_FUNC(name, sig) sig name;
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC)
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC)
#undef NAZARA_AUDIO_FUNC
private:
std::vector<std::string> ParseDevices(const char* deviceString);
DynLib m_library;
};
}
#include <Nazara/Audio/OpenALLibrary.inl>
#endif // NAZARA_AUDIO_OPENAL
#endif // NAZARA_AUDIO_OPENALLIBRARY_HPP

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/OpenALLibrary.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline OpenALLibrary::~OpenALLibrary()
{
Unload();
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -0,0 +1,84 @@
// Copyright (C) 2022 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_OPENALSOURCE_HPP
#define NAZARA_AUDIO_OPENALSOURCE_HPP
#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD)
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/AudioSource.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/OpenAL.hpp>
namespace Nz
{
class OpenALBuffer;
class OpenALDevice;
class OpenALLibrary;
class NAZARA_AUDIO_API OpenALSource final : public AudioSource
{
public:
inline OpenALSource(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint sourceId);
OpenALSource(const OpenALSource&) = delete;
OpenALSource(OpenALSource&&) = delete;
~OpenALSource();
void EnableLooping(bool loop) override;
void EnableSpatialization(bool spatialization) override;
float GetAttenuation() const override;
float GetMinDistance() const override;
float GetPitch() const override;
Vector3f GetPosition() const override;
UInt32 GetSampleOffset() const override;
Vector3f GetVelocity() const override;
SoundStatus GetStatus() const override;
float GetVolume() const override;
bool IsLooping() const override;
bool IsSpatializationEnabled() const override;
void QueueBuffer(std::shared_ptr<AudioBuffer> audioBuffer) override;
void Pause() override;
void Play() override;
void SetAttenuation(float attenuation) override;
void SetBuffer(std::shared_ptr<AudioBuffer> audioBuffer) override;
void SetMinDistance(float minDistance) override;
void SetPitch(float pitch) override;
void SetPosition(const Vector3f& position) override;
void SetSampleOffset(UInt32 offset) override;
void SetVelocity(const Vector3f& velocity) override;
void SetVolume(float volume) override;
void Stop() override;
std::shared_ptr<AudioBuffer> TryUnqueueProcessedBuffer() override;
void UnqueueAllBuffers() override;
OpenALSource& operator=(const OpenALSource&) = delete;
OpenALSource& operator=(OpenALSource&&) = delete;
private:
OpenALDevice& GetDevice();
const OpenALDevice& GetDevice() const;
std::shared_ptr<OpenALBuffer> m_currentBuffer;
std::vector<std::shared_ptr<OpenALBuffer>> m_queuedBuffers;
ALuint m_sourceId;
OpenALLibrary& m_library;
};
}
#include <Nazara/Audio/OpenALSource.inl>
#endif // NAZARA_AUDIO_OPENAL
#endif // NAZARA_AUDIO_OPENALSOURCE_HPP

View File

@@ -0,0 +1,18 @@
// Copyright (C) 2022 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
#include <Nazara/Audio/OpenALSource.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
inline OpenALSource::OpenALSource(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint sourceId) :
AudioSource(std::move(device)),
m_sourceId(sourceId),
m_library(library)
{
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -17,15 +17,16 @@ namespace Nz
class NAZARA_AUDIO_API Sound : public SoundEmitter
{
public:
Sound() = default;
Sound(std::shared_ptr<const SoundBuffer> soundBuffer);
using SoundEmitter::SoundEmitter;
Sound();
Sound(AudioDevice& audioDevice, std::shared_ptr<SoundBuffer> soundBuffer);
Sound(const Sound&) = default;
Sound(Sound&&) noexcept = default;
Sound(Sound&&) = default;
~Sound();
void EnableLooping(bool loop) override;
const std::shared_ptr<const SoundBuffer>& GetBuffer() const;
const std::shared_ptr<SoundBuffer>& GetBuffer() const;
UInt32 GetDuration() const override;
UInt32 GetPlayingOffset() const override;
SoundStatus GetStatus() const override;
@@ -40,16 +41,16 @@ namespace Nz
void Pause() override;
void Play() override;
void SetBuffer(std::shared_ptr<const SoundBuffer> soundBuffer);
void SetBuffer(std::shared_ptr<SoundBuffer> soundBuffer);
void SetPlayingOffset(UInt32 offset);
void Stop() override;
Sound& operator=(const Sound&) = delete; ///TODO?
Sound& operator=(Sound&&) noexcept = default;
Sound& operator=(const Sound&) = default;
Sound& operator=(Sound&&) = default;
private:
std::shared_ptr<const SoundBuffer> m_buffer;
std::shared_ptr<SoundBuffer> m_buffer;
};
}

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;
};
}

View File

@@ -3,11 +3,64 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/SoundBuffer.hpp>
#include <memory>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
{
/*!
* \brief Gets the duration of the sound buffer
* \return Duration of the sound buffer in milliseconds
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
inline UInt32 SoundBuffer::GetDuration() const
{
return m_duration;
}
/*!
* \brief Gets the format of the sound buffer
* \return Enumeration of type AudioFormat (mono, stereo, ...)
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
inline AudioFormat SoundBuffer::GetFormat() const
{
return m_format;
}
/*!
* \brief Gets the internal raw samples
* \return Pointer to raw data
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
inline const Int16* SoundBuffer::GetSamples() const
{
return m_samples.get();
}
/*!
* \brief Gets the number of samples in the sound buffer
* \return Count of samples (number of seconds * sample rate * channel count)
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
inline UInt64 SoundBuffer::GetSampleCount() const
{
return m_sampleCount;
}
/*!
* \brief Gets the rates of sample in the sound buffer
* \return Rate of sample in Hertz (Hz)
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
inline UInt32 SoundBuffer::GetSampleRate() const
{
return m_sampleRate;
}
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -17,10 +17,15 @@
namespace Nz
{
class AudioDevice;
class AudioSource;
class NAZARA_AUDIO_API SoundEmitter
{
public:
SoundEmitter(SoundEmitter&& emitter) noexcept;
SoundEmitter(AudioDevice& audioDevice);
SoundEmitter(const SoundEmitter&) = delete;
SoundEmitter(SoundEmitter&&) noexcept = default;
virtual ~SoundEmitter();
virtual void EnableLooping(bool loop) = 0;
@@ -38,7 +43,7 @@ namespace Nz
virtual bool IsLooping() const = 0;
inline bool IsPlaying() const;
bool IsSpatialized() const;
bool IsSpatializationEnabled() const;
virtual void Pause() = 0;
virtual void Play() = 0;
@@ -47,25 +52,16 @@ namespace Nz
void SetMinDistance(float minDistance);
void SetPitch(float pitch);
void SetPosition(const Vector3f& position);
void SetPosition(float x, float y, float z);
void SetVelocity(const Vector3f& velocity);
void SetVelocity(float velX, float velY, float velZ);
void SetVolume(float volume);
virtual void Stop() = 0;
SoundEmitter& operator=(const SoundEmitter&) = delete;
SoundEmitter& operator=(SoundEmitter&&) noexcept;
SoundEmitter& operator=(SoundEmitter&&) noexcept = default;
protected:
SoundEmitter();
SoundEmitter(const SoundEmitter& emitter);
SoundStatus GetInternalStatus() const;
static constexpr unsigned int InvalidSource = std::numeric_limits<unsigned int>::max();
unsigned int m_source;
std::shared_ptr<AudioSource> m_source;
};
}