Added Audio module

Fixed examples resources not being commited
Temporary removed static build configurations
This commit is contained in:
Lynix
2012-08-21 15:04:00 +02:00
parent 71b777e732
commit 40ec2003b4
28 changed files with 1541 additions and 13 deletions

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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_HPP
#define NAZARA_AUDIO_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
class NAZARA_API NzAudio
{
friend class NzMusic;
friend class NzSoundBuffer;
public:
NzAudio() = delete;
~NzAudio() = delete;
static nzAudioFormat GetAudioFormat(unsigned int channelCount);
static float GetDopplerFactor();
static float GetGlobalVolume();
static NzVector3f GetListenerDirection();
static NzVector3f GetListenerPosition();
//static NzQuaternionf GetListenerRotation();
static NzVector3f GetListenerVelocity();
static float GetSpeedOfSound();
static bool Initialize();
static bool IsFormatSupported(nzAudioFormat format);
static bool IsInitialized();
static void SetDopplerFactor(float dopplerFactor);
static void SetGlobalVolume(float volume);
static void SetListenerDirection(const NzVector3f& direction);
static void SetListenerDirection(float dirX, float dirY, float dirZ);
static void SetListenerPosition(const NzVector3f& position);
static void SetListenerPosition(float x, float y, float z);
//static void SetListenerRotation(const NzQuaternionf& rotation);
static void SetListenerVelocity(const NzVector3f& velocity);
static void SetListenerVelocity(float velX, float velY, float velZ);
static void SetSpeedOfSound(float speed);
static void Uninitialize();
private:
static unsigned int GetOpenALFormat(nzAudioFormat format);
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_AUDIO_HPP

View File

@@ -0,0 +1,41 @@
/*
Nazara Engine - Audio module
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_AUDIO_HPP
#define NAZARA_CONFIG_AUDIO_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_AUDIO_SAFE 1
// Le nombre de buffers utilisés lors du streaming d'objets audio (Au moins deux)
#define NAZARA_AUDIO_STREAMEDBUFFERCOUNT 2
#endif // NAZARA_CONFIG_AUDIO_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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/Config.hpp>
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Audio module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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_ENUMS_HPP
#define NAZARA_ENUMS_HPP
enum nzAudioFormat
{
nzAudioFormat_Unknown = -1,
// La valeur entière est le nombre de canaux possédés par ce format
nzAudioFormat_Mono = 1,
nzAudioFormat_Stereo = 2,
nzAudioFormat_Quad = 4,
nzAudioFormat_5_1 = 6,
nzAudioFormat_6_1 = 7,
nzAudioFormat_7_1 = 8,
nzAudioFormat_Max = nzAudioFormat_7_1
};
enum nzSoundStatus
{
nzSoundStatus_Playing,
nzSoundStatus_Paused,
nzSoundStatus_Stopped
};
#endif // NAZARA_ENUMS_HPP

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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_SOUND_HPP
#define NAZARA_SOUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundEmitter.hpp>
class NAZARA_API NzSound : public NzSoundEmitter
{
public:
NzSound() = default;
NzSound(const NzSoundBuffer* soundBuffer);
NzSound(const NzSound& sound);
~NzSound();
void EnableLooping(bool loop);
const NzSoundBuffer* GetBuffer() const;
nzUInt32 GetDuration() const;
nzUInt32 GetPlayingOffset() const;
nzSoundStatus GetStatus() const;
bool IsLooping() const;
bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams());
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams());
void Pause();
bool Play();
void SetBuffer(const NzSoundBuffer* buffer);
void SetPlayingOffset(nzUInt32 offset);
void Stop();
private:
const NzSoundBuffer* m_buffer = nullptr;
};
#endif // NAZARA_SOUND_HPP

View File

@@ -0,0 +1,64 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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_SOUNDBUFFER_HPP
#define NAZARA_SOUNDBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
struct NzSoundBufferParams
{
bool IsValid() const;
};
class NzSound;
class NzSoundBuffer;
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
struct NzSoundBufferImpl;
class NAZARA_API NzSoundBuffer : public NzResource, public NzNonCopyable
{
friend NzSound;
friend NzSoundBufferLoader;
public:
NzSoundBuffer() = default;
NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples);
~NzSoundBuffer();
bool Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples);
void Destroy();
nzUInt32 GetDuration() const;
nzAudioFormat GetFormat() const;
const nzInt16* GetSamples() const;
unsigned int GetSampleCount() const;
unsigned int GetSampleRate() const;
bool IsValid() const;
bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams());
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams());
static bool IsFormatSupported(nzAudioFormat format);
private:
unsigned int GetOpenALBuffer() const;
NzSoundBufferImpl* m_impl = nullptr;
static NzSoundBufferLoader::LoaderList s_loaders;
};
#endif // NAZARA_SOUNDBUFFER_HPP

View File

@@ -0,0 +1,60 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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_SOUNDEMITTER_HPP
#define NAZARA_SOUNDEMITTER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Math/Vector3.hpp>
class NAZARA_API NzSoundEmitter
{
public:
virtual ~NzSoundEmitter();
virtual void EnableLooping(bool loop) = 0;
void EnableSpatialization(bool spatialization);
float GetAttenuation() const;
virtual nzUInt32 GetDuration() const = 0;
float GetMinDistance() const;
float GetPitch() const;
virtual nzUInt32 GetPlayingOffset() const = 0;
NzVector3f GetPosition() const;
NzVector3f GetVelocity() const;
virtual nzSoundStatus GetStatus() const = 0;
float GetVolume() const;
virtual bool IsLooping() const = 0;
bool IsSpatialized() const;
virtual void Pause() = 0;
virtual bool Play() = 0;
void SetAttenuation(float attenuation);
void SetMinDistance(float minDistance);
void SetPitch(float pitch);
void SetPosition(const NzVector3f& position);
void SetPosition(float x, float y, float z);
void SetVelocity(const NzVector3f& velocity);
void SetVelocity(float velX, float velY, float velZ);
void SetVolume(float volume);
virtual void Stop() = 0;
protected:
NzSoundEmitter();
NzSoundEmitter(const NzSoundEmitter& emitter);
nzSoundStatus GetInternalStatus() const;
unsigned int m_source;
};
#endif // NAZARA_SOUNDEMITTER_HPP