Audio: Fix some type warning
Former-commit-id: 9ed6d64e771e77d03b91060823efb4236739914b [formerly 0efc1b14cd61f3d33fc642dbe4eb6bf05d58ec7e] [formerly dbc079525b48a2efb8a7917b4b376a318f8d5fae [formerly 7c202e02ac2a8b745208e1b852ff44d2169ebaf0]] Former-commit-id: 27a65bcbd5e499dcc741f76a5c0a31bc9ae09e60 [formerly 97ed7176fd1f0f906229d19e68aedc335a7ca420] Former-commit-id: 1779855a4f20dc4216648aaed59542fd8c6d7bc8
This commit is contained in:
parent
cfba75812d
commit
aabf10cc61
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
template<typename T> void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount);
|
template<typename T> void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Audio/Algorithm.inl>
|
#include <Nazara/Audio/Algorithm.inl>
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,16 @@ namespace Nz
|
||||||
* \remark The input buffer may be the same as the output one
|
* \remark The input buffer may be the same as the output one
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void MixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount)
|
void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount)
|
||||||
{
|
{
|
||||||
// To avoid overflow, we use, as an accumulator, a type which is large enough: (u)int 64 bits for integers, double for floatings
|
// To avoid overflow, we use, as an accumulator, a type which is large enough: (u)int 64 bits for integers, double for floatings
|
||||||
typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt;
|
typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt;
|
||||||
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
|
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < frameCount; ++i)
|
for (UInt64 i = 0; i < frameCount; ++i)
|
||||||
{
|
{
|
||||||
Biggest acc = Biggest(0);
|
Biggest acc = Biggest(0);
|
||||||
for (unsigned int j = 0; j < channelCount; ++j)
|
for (UInt32 j = 0; j < channelCount; ++j)
|
||||||
acc += input[i * channelCount + j];
|
acc += input[i * channelCount + j];
|
||||||
|
|
||||||
output[i] = static_cast<T>(acc / channelCount);
|
output[i] = static_cast<T>(acc / channelCount);
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Nz
|
||||||
UInt32 GetDuration() const;
|
UInt32 GetDuration() const;
|
||||||
AudioFormat GetFormat() const;
|
AudioFormat GetFormat() const;
|
||||||
UInt32 GetPlayingOffset() const;
|
UInt32 GetPlayingOffset() const;
|
||||||
UInt32 GetSampleCount() const;
|
UInt64 GetSampleCount() const;
|
||||||
UInt32 GetSampleRate() const;
|
UInt32 GetSampleRate() const;
|
||||||
SoundStatus GetStatus() const;
|
SoundStatus GetStatus() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,18 +50,18 @@ namespace Nz
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SoundBuffer() = default;
|
SoundBuffer() = default;
|
||||||
SoundBuffer(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
|
SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples);
|
||||||
SoundBuffer(const SoundBuffer&) = delete;
|
SoundBuffer(const SoundBuffer&) = delete;
|
||||||
SoundBuffer(SoundBuffer&&) = delete;
|
SoundBuffer(SoundBuffer&&) = delete;
|
||||||
~SoundBuffer();
|
~SoundBuffer();
|
||||||
|
|
||||||
bool Create(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples);
|
bool Create(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
UInt32 GetDuration() const;
|
UInt32 GetDuration() const;
|
||||||
AudioFormat GetFormat() const;
|
AudioFormat GetFormat() const;
|
||||||
const Int16* GetSamples() const;
|
const Int16* GetSamples() const;
|
||||||
UInt32 GetSampleCount() const;
|
UInt64 GetSampleCount() const;
|
||||||
UInt32 GetSampleRate() const;
|
UInt32 GetSampleRate() const;
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ namespace Nz
|
||||||
|
|
||||||
virtual UInt32 GetDuration() const = 0;
|
virtual UInt32 GetDuration() const = 0;
|
||||||
virtual AudioFormat GetFormat() const = 0;
|
virtual AudioFormat GetFormat() const = 0;
|
||||||
virtual UInt32 GetSampleCount() const = 0;
|
virtual UInt64 GetSampleCount() const = 0;
|
||||||
virtual UInt32 GetSampleRate() const = 0;
|
virtual UInt32 GetSampleRate() const = 0;
|
||||||
|
|
||||||
virtual unsigned int Read(void* buffer, unsigned int sampleCount) = 0;
|
virtual UInt64 Read(void* buffer, UInt64 sampleCount) = 0;
|
||||||
virtual void Seek(UInt32 offset) = 0;
|
virtual void Seek(UInt64 offset) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ namespace Nz
|
||||||
return m_format;
|
return m_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 GetSampleCount() const override
|
UInt64 GetSampleCount() const override
|
||||||
{
|
{
|
||||||
return m_sampleCount;
|
return m_sampleCount;
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ namespace Nz
|
||||||
bool Open(Stream& stream, bool forceMono)
|
bool Open(Stream& stream, bool forceMono)
|
||||||
{
|
{
|
||||||
SF_INFO infos;
|
SF_INFO infos;
|
||||||
infos.format = 0; // Format inconnu
|
infos.format = 0; // Unknown format
|
||||||
|
|
||||||
m_handle = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream);
|
m_handle = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream);
|
||||||
if (!m_handle)
|
if (!m_handle)
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sampleCount = static_cast<UInt32>(infos.channels*infos.frames);
|
m_sampleCount = infos.channels*infos.frames;
|
||||||
m_sampleRate = infos.samplerate;
|
m_sampleRate = infos.samplerate;
|
||||||
|
|
||||||
// Durée de la musique (s) = samples / channels*rate
|
// Durée de la musique (s) = samples / channels*rate
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Read(void* buffer, unsigned int sampleCount) override
|
UInt64 Read(void* buffer, UInt64 sampleCount) override
|
||||||
{
|
{
|
||||||
// Si la musique a été demandée en mono, nous devons la convertir à la volée lors de la lecture
|
// Si la musique a été demandée en mono, nous devons la convertir à la volée lors de la lecture
|
||||||
if (m_mixToMono)
|
if (m_mixToMono)
|
||||||
|
|
@ -190,13 +190,13 @@ namespace Nz
|
||||||
sf_count_t readSampleCount = sf_read_short(m_handle, m_mixBuffer.data(), m_format * sampleCount);
|
sf_count_t readSampleCount = sf_read_short(m_handle, m_mixBuffer.data(), m_format * sampleCount);
|
||||||
MixToMono(m_mixBuffer.data(), static_cast<Int16*>(buffer), m_format, sampleCount);
|
MixToMono(m_mixBuffer.data(), static_cast<Int16*>(buffer), m_format, sampleCount);
|
||||||
|
|
||||||
return static_cast<unsigned int>(readSampleCount / m_format);
|
return readSampleCount / m_format;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return static_cast<unsigned int>(sf_read_short(m_handle, static_cast<Int16*>(buffer), sampleCount));
|
return sf_read_short(m_handle, static_cast<Int16*>(buffer), sampleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Seek(UInt32 offset) override
|
void Seek(UInt64 offset) override
|
||||||
{
|
{
|
||||||
sf_seek(m_handle, offset*m_sampleRate / 1000, SEEK_SET);
|
sf_seek(m_handle, offset*m_sampleRate / 1000, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
@ -208,8 +208,8 @@ namespace Nz
|
||||||
SNDFILE* m_handle;
|
SNDFILE* m_handle;
|
||||||
bool m_mixToMono;
|
bool m_mixToMono;
|
||||||
UInt32 m_duration;
|
UInt32 m_duration;
|
||||||
unsigned int m_sampleCount;
|
UInt32 m_sampleRate;
|
||||||
unsigned int m_sampleRate;
|
UInt64 m_sampleCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsSupported(const String& extension)
|
bool IsSupported(const String& extension)
|
||||||
|
|
|
||||||
|
|
@ -166,16 +166,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UInt32 Music::GetPlayingOffset() const
|
UInt32 Music::GetPlayingOffset() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Music not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Music not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Prevent music thread from enqueing new buffers while we're getting the count
|
// Prevent music thread from enqueing new buffers while we're getting the count
|
||||||
Nz::LockGuard lock(m_impl->bufferLock);
|
Nz::LockGuard lock(m_impl->bufferLock);
|
||||||
|
|
@ -192,16 +185,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
UInt64 Music::GetSampleCount() const
|
||||||
UInt32 Music::GetSampleCount() const
|
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Music not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Music not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->stream->GetSampleCount();
|
return m_impl->stream->GetSampleCount();
|
||||||
}
|
}
|
||||||
|
|
@ -212,16 +198,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UInt32 Music::GetSampleRate() const
|
UInt32 Music::GetSampleRate() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Music not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Music not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->sampleRate;
|
return m_impl->sampleRate;
|
||||||
}
|
}
|
||||||
|
|
@ -233,16 +212,9 @@ namespace Nz
|
||||||
* \remark If the music is not playing, Stopped is returned
|
* \remark If the music is not playing, Stopped is returned
|
||||||
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SoundStatus Music::GetStatus() const
|
SoundStatus Music::GetStatus() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Music not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Music not created");
|
|
||||||
return SoundStatus_Stopped;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SoundStatus status = GetInternalStatus();
|
SoundStatus status = GetInternalStatus();
|
||||||
|
|
||||||
|
|
@ -425,8 +397,8 @@ namespace Nz
|
||||||
|
|
||||||
bool Music::FillAndQueueBuffer(unsigned int buffer)
|
bool Music::FillAndQueueBuffer(unsigned int buffer)
|
||||||
{
|
{
|
||||||
unsigned int sampleCount = m_impl->chunkSamples.size();
|
std::size_t sampleCount = m_impl->chunkSamples.size();
|
||||||
unsigned int sampleRead = 0;
|
std::size_t sampleRead = 0;
|
||||||
|
|
||||||
// Fill the buffer by reading from the stream
|
// Fill the buffer by reading from the stream
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|
@ -446,7 +418,7 @@ namespace Nz
|
||||||
// Update the buffer (send it to OpenAL) and queue it if we got any data
|
// Update the buffer (send it to OpenAL) and queue it if we got any data
|
||||||
if (sampleRead > 0)
|
if (sampleRead > 0)
|
||||||
{
|
{
|
||||||
alBufferData(buffer, m_impl->audioFormat, &m_impl->chunkSamples[0], sampleRead*sizeof(Int16), m_impl->sampleRate);
|
alBufferData(buffer, m_impl->audioFormat, &m_impl->chunkSamples[0], static_cast<ALsizei>(sampleRead*sizeof(Int16)), static_cast<ALsizei>(m_impl->sampleRate));
|
||||||
alSourceQueueBuffers(m_source, 1, &buffer);
|
alSourceQueueBuffers(m_source, 1, &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \param soundBuffer Buffer to read sound from
|
* \param soundBuffer Buffer to read sound from
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Sound::Sound(const SoundBuffer* soundBuffer)
|
Sound::Sound(const SoundBuffer* soundBuffer)
|
||||||
{
|
{
|
||||||
SetBuffer(soundBuffer);
|
SetBuffer(soundBuffer);
|
||||||
|
|
@ -38,7 +37,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \param sound Sound to copy
|
* \param sound Sound to copy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Sound::Sound(const Sound& sound) :
|
Sound::Sound(const Sound& sound) :
|
||||||
SoundEmitter(sound)
|
SoundEmitter(sound)
|
||||||
{
|
{
|
||||||
|
|
@ -50,7 +48,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \see Stop
|
* \see Stop
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Sound::~Sound()
|
Sound::~Sound()
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
|
|
@ -61,7 +58,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \param loop Should sound loop
|
* \param loop Should sound loop
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::EnableLooping(bool loop)
|
void Sound::EnableLooping(bool loop)
|
||||||
{
|
{
|
||||||
alSourcei(m_source, AL_LOOPING, loop);
|
alSourcei(m_source, AL_LOOPING, loop);
|
||||||
|
|
@ -71,7 +67,6 @@ namespace Nz
|
||||||
* \brief Gets the internal buffer
|
* \brief Gets the internal buffer
|
||||||
* \return Internal buffer
|
* \return Internal buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const SoundBuffer* Sound::GetBuffer() const
|
const SoundBuffer* Sound::GetBuffer() const
|
||||||
{
|
{
|
||||||
return m_buffer;
|
return m_buffer;
|
||||||
|
|
@ -83,7 +78,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no buffer
|
* \remark Produces a NazaraError if there is no buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UInt32 Sound::GetDuration() const
|
UInt32 Sound::GetDuration() const
|
||||||
{
|
{
|
||||||
NazaraAssert(m_buffer, "Invalid sound buffer");
|
NazaraAssert(m_buffer, "Invalid sound buffer");
|
||||||
|
|
@ -95,7 +89,6 @@ namespace Nz
|
||||||
* \brief Gets the current offset in the sound
|
* \brief Gets the current offset in the sound
|
||||||
* \return Offset in milliseconds (works with entire seconds)
|
* \return Offset in milliseconds (works with entire seconds)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UInt32 Sound::GetPlayingOffset() const
|
UInt32 Sound::GetPlayingOffset() const
|
||||||
{
|
{
|
||||||
ALint samples = 0;
|
ALint samples = 0;
|
||||||
|
|
@ -108,7 +101,6 @@ namespace Nz
|
||||||
* \brief Gets the status of the music
|
* \brief Gets the status of the music
|
||||||
* \return Enumeration of type SoundStatus (Playing, Stopped, ...)
|
* \return Enumeration of type SoundStatus (Playing, Stopped, ...)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SoundStatus Sound::GetStatus() const
|
SoundStatus Sound::GetStatus() const
|
||||||
{
|
{
|
||||||
return GetInternalStatus();
|
return GetInternalStatus();
|
||||||
|
|
@ -118,7 +110,6 @@ namespace Nz
|
||||||
* \brief Checks whether the sound is looping
|
* \brief Checks whether the sound is looping
|
||||||
* \return true if it is the case
|
* \return true if it is the case
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Sound::IsLooping() const
|
bool Sound::IsLooping() const
|
||||||
{
|
{
|
||||||
ALint loop;
|
ALint loop;
|
||||||
|
|
@ -141,7 +132,6 @@ namespace Nz
|
||||||
* \brief Checks whether the sound is playing
|
* \brief Checks whether the sound is playing
|
||||||
* \return true if it is the case
|
* \return true if it is the case
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Sound::IsPlaying() const
|
bool Sound::IsPlaying() const
|
||||||
{
|
{
|
||||||
return GetStatus() == SoundStatus_Playing;
|
return GetStatus() == SoundStatus_Playing;
|
||||||
|
|
@ -156,7 +146,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Sound::LoadFromFile(const String& filePath, const SoundBufferParams& params)
|
bool Sound::LoadFromFile(const String& filePath, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
SoundBufferRef buffer = SoundBuffer::New();
|
SoundBufferRef buffer = SoundBuffer::New();
|
||||||
|
|
@ -180,7 +169,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
|
bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
SoundBufferRef buffer = SoundBuffer::New();
|
SoundBufferRef buffer = SoundBuffer::New();
|
||||||
|
|
@ -203,7 +191,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if loading failed
|
* \remark Produces a NazaraError if loading failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params)
|
bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
SoundBufferRef buffer = SoundBuffer::New();
|
SoundBufferRef buffer = SoundBuffer::New();
|
||||||
|
|
@ -220,7 +207,6 @@ namespace Nz
|
||||||
/*!
|
/*!
|
||||||
* \brief Pauses the sound
|
* \brief Pauses the sound
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::Pause()
|
void Sound::Pause()
|
||||||
{
|
{
|
||||||
alSourcePause(m_source);
|
alSourcePause(m_source);
|
||||||
|
|
@ -231,16 +217,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if the sound is not playable with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if the sound is not playable with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::Play()
|
void Sound::Play()
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(IsPlayable(), "Music is not playable");
|
||||||
if (!IsPlayable())
|
|
||||||
{
|
|
||||||
NazaraError("Invalid sound buffer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
alSourcePlay(m_source);
|
alSourcePlay(m_source);
|
||||||
}
|
}
|
||||||
|
|
@ -252,16 +231,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if buffer is invalid with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if buffer is invalid with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::SetBuffer(const SoundBuffer* buffer)
|
void Sound::SetBuffer(const SoundBuffer* buffer)
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(!buffer || buffer->IsValid(), "Invalid sound buffer");
|
||||||
if (buffer && !buffer->IsValid())
|
|
||||||
{
|
|
||||||
NazaraError("Invalid sound buffer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (m_buffer == buffer)
|
if (m_buffer == buffer)
|
||||||
return;
|
return;
|
||||||
|
|
@ -281,7 +253,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \param offset Offset in the sound in milliseconds
|
* \param offset Offset in the sound in milliseconds
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::SetPlayingOffset(UInt32 offset)
|
void Sound::SetPlayingOffset(UInt32 offset)
|
||||||
{
|
{
|
||||||
alSourcei(m_source, AL_SAMPLE_OFFSET, static_cast<ALint>(offset/1000.f * m_buffer->GetSampleRate()));
|
alSourcei(m_source, AL_SAMPLE_OFFSET, static_cast<ALint>(offset/1000.f * m_buffer->GetSampleRate()));
|
||||||
|
|
@ -290,7 +261,6 @@ namespace Nz
|
||||||
/*!
|
/*!
|
||||||
* \brief Stops the sound
|
* \brief Stops the sound
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sound::Stop()
|
void Sound::Stop()
|
||||||
{
|
{
|
||||||
alSourceStop(m_source);
|
alSourceStop(m_source);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <Nazara/Audio/Audio.hpp>
|
#include <Nazara/Audio/Audio.hpp>
|
||||||
#include <Nazara/Audio/Config.hpp>
|
#include <Nazara/Audio/Config.hpp>
|
||||||
#include <Nazara/Audio/OpenAL.hpp>
|
#include <Nazara/Audio/OpenAL.hpp>
|
||||||
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -40,7 +41,7 @@ namespace Nz
|
||||||
AudioFormat format;
|
AudioFormat format;
|
||||||
UInt32 duration;
|
UInt32 duration;
|
||||||
std::unique_ptr<Int16[]> samples;
|
std::unique_ptr<Int16[]> samples;
|
||||||
UInt32 sampleCount;
|
UInt64 sampleCount;
|
||||||
UInt32 sampleRate;
|
UInt32 sampleRate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -57,8 +58,7 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \see Create
|
* \see Create
|
||||||
*/
|
*/
|
||||||
|
SoundBuffer::SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples)
|
||||||
SoundBuffer::SoundBuffer(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples)
|
|
||||||
{
|
{
|
||||||
Create(format, sampleCount, sampleRate, samples);
|
Create(format, sampleCount, sampleRate, samples);
|
||||||
|
|
||||||
|
|
@ -76,7 +76,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \see Destroy
|
* \see Destroy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SoundBuffer::~SoundBuffer()
|
SoundBuffer::~SoundBuffer()
|
||||||
{
|
{
|
||||||
OnSoundBufferRelease(this);
|
OnSoundBufferRelease(this);
|
||||||
|
|
@ -96,8 +95,7 @@ namespace Nz
|
||||||
* \remark Produces a NazaraError if creation went wrong with NAZARA_AUDIO_SAFE defined,
|
* \remark Produces a NazaraError if creation went wrong with NAZARA_AUDIO_SAFE defined,
|
||||||
* this could happen if parameters are invalid or creation of OpenAL buffers failed
|
* this could happen if parameters are invalid or creation of OpenAL buffers failed
|
||||||
*/
|
*/
|
||||||
|
bool SoundBuffer::Create(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples)
|
||||||
bool SoundBuffer::Create(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples)
|
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
|
|
@ -132,19 +130,18 @@ namespace Nz
|
||||||
|
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
|
|
||||||
if (alGetError() != AL_NO_ERROR)
|
if (alGetError() != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create OpenAL buffer");
|
NazaraError("Failed to create OpenAL buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
alBufferData(buffer, OpenAL::AudioFormat[format], samples, sampleCount*sizeof(Int16), sampleRate);
|
CallOnExit clearBufferOnExit([buffer] () { alDeleteBuffers(1, &buffer); });
|
||||||
|
|
||||||
|
alBufferData(buffer, OpenAL::AudioFormat[format], samples, static_cast<ALsizei>(sampleCount*sizeof(Int16)), static_cast<ALsizei>(sampleRate));
|
||||||
|
|
||||||
if (alGetError() != AL_NO_ERROR)
|
if (alGetError() != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
alDeleteBuffers(1, &buffer);
|
|
||||||
|
|
||||||
NazaraError("Failed to set OpenAL buffer");
|
NazaraError("Failed to set OpenAL buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -158,6 +155,8 @@ namespace Nz
|
||||||
m_impl->samples.reset(new Int16[sampleCount]);
|
m_impl->samples.reset(new Int16[sampleCount]);
|
||||||
std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(Int16));
|
std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(Int16));
|
||||||
|
|
||||||
|
clearBufferOnExit.Reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,16 +181,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UInt32 SoundBuffer::GetDuration() const
|
UInt32 SoundBuffer::GetDuration() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Sound buffer not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Sound buffer not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->duration;
|
return m_impl->duration;
|
||||||
}
|
}
|
||||||
|
|
@ -205,13 +197,7 @@ namespace Nz
|
||||||
|
|
||||||
AudioFormat SoundBuffer::GetFormat() const
|
AudioFormat SoundBuffer::GetFormat() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Sound buffer not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Sound buffer not created");
|
|
||||||
return AudioFormat_Unknown;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->format;
|
return m_impl->format;
|
||||||
}
|
}
|
||||||
|
|
@ -222,16 +208,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Int16* SoundBuffer::GetSamples() const
|
const Int16* SoundBuffer::GetSamples() const
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Sound buffer not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Sound buffer not created");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->samples.get();
|
return m_impl->samples.get();
|
||||||
}
|
}
|
||||||
|
|
@ -242,16 +221,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
UInt64 SoundBuffer::GetSampleCount() const
|
||||||
unsigned int SoundBuffer::GetSampleCount() const
|
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Sound buffer not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Sound buffer not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->sampleCount;
|
return m_impl->sampleCount;
|
||||||
}
|
}
|
||||||
|
|
@ -262,16 +234,9 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
UInt32 SoundBuffer::GetSampleRate() const
|
||||||
unsigned int SoundBuffer::GetSampleRate() const
|
|
||||||
{
|
{
|
||||||
#if NAZARA_AUDIO_SAFE
|
NazaraAssert(m_impl, "Sound buffer not created");
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Sound buffer not created");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_impl->sampleRate;
|
return m_impl->sampleRate;
|
||||||
}
|
}
|
||||||
|
|
@ -293,7 +258,6 @@ namespace Nz
|
||||||
* \param filePath Path to the file
|
* \param filePath Path to the file
|
||||||
* \param params Parameters for the sound buffer
|
* \param params Parameters for the sound buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool SoundBuffer::LoadFromFile(const String& filePath, const SoundBufferParams& params)
|
bool SoundBuffer::LoadFromFile(const String& filePath, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
return SoundBufferLoader::LoadFromFile(this, filePath, params);
|
return SoundBufferLoader::LoadFromFile(this, filePath, params);
|
||||||
|
|
@ -307,7 +271,6 @@ namespace Nz
|
||||||
* \param size Size of the memory
|
* \param size Size of the memory
|
||||||
* \param params Parameters for the sound buffer
|
* \param params Parameters for the sound buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool SoundBuffer::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
|
bool SoundBuffer::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
return SoundBufferLoader::LoadFromMemory(this, data, size, params);
|
return SoundBufferLoader::LoadFromMemory(this, data, size, params);
|
||||||
|
|
@ -320,7 +283,6 @@ namespace Nz
|
||||||
* \param stream Stream to the sound buffer
|
* \param stream Stream to the sound buffer
|
||||||
* \param params Parameters for the sound buffer
|
* \param params Parameters for the sound buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool SoundBuffer::LoadFromStream(Stream& stream, const SoundBufferParams& params)
|
bool SoundBuffer::LoadFromStream(Stream& stream, const SoundBufferParams& params)
|
||||||
{
|
{
|
||||||
return SoundBufferLoader::LoadFromStream(this, stream, params);
|
return SoundBufferLoader::LoadFromStream(this, stream, params);
|
||||||
|
|
@ -332,7 +294,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \param format Format to check
|
* \param format Format to check
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool SoundBuffer::IsFormatSupported(AudioFormat format)
|
bool SoundBuffer::IsFormatSupported(AudioFormat format)
|
||||||
{
|
{
|
||||||
return Audio::IsFormatSupported(format);
|
return Audio::IsFormatSupported(format);
|
||||||
|
|
@ -344,7 +305,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int SoundBuffer::GetOpenALBuffer() const
|
unsigned int SoundBuffer::GetOpenALBuffer() const
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_DEBUG
|
#ifdef NAZARA_DEBUG
|
||||||
|
|
@ -364,7 +324,6 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraError if sub-initialization failed
|
* \remark Produces a NazaraError if sub-initialization failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool SoundBuffer::Initialize()
|
bool SoundBuffer::Initialize()
|
||||||
{
|
{
|
||||||
if (!SoundBufferLibrary::Initialize())
|
if (!SoundBufferLibrary::Initialize())
|
||||||
|
|
@ -385,7 +344,6 @@ namespace Nz
|
||||||
/*!
|
/*!
|
||||||
* \brief Uninitializes the libraries and managers
|
* \brief Uninitializes the libraries and managers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void SoundBuffer::Uninitialize()
|
void SoundBuffer::Uninitialize()
|
||||||
{
|
{
|
||||||
SoundBufferManager::Uninitialize();
|
SoundBufferManager::Uninitialize();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue