From ce3bbf6c78dd16d18151f27c491243d5706a5add Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 24 Sep 2015 00:39:48 +0200 Subject: [PATCH] Audio: Uniformize SampleCount/SampleRate type Former-commit-id: a67b0f10a4aeb1399834221d32859ab0e376813e --- include/Nazara/Audio/Music.hpp | 4 ++-- include/Nazara/Audio/SoundBuffer.hpp | 4 ++-- include/Nazara/Audio/SoundStream.hpp | 2 +- src/Nazara/Audio/Formats/sndfileLoader.cpp | 12 +++++----- src/Nazara/Audio/Music.cpp | 26 ++++++++++++++++++++++ src/Nazara/Audio/SoundBuffer.cpp | 4 ++-- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/include/Nazara/Audio/Music.hpp b/include/Nazara/Audio/Music.hpp index 0777052d3..98aafa0d2 100644 --- a/include/Nazara/Audio/Music.hpp +++ b/include/Nazara/Audio/Music.hpp @@ -45,8 +45,8 @@ class NAZARA_AUDIO_API NzMusic : public NzResource, public NzSoundEmitter nzUInt32 GetDuration() const; nzAudioFormat GetFormat() const; nzUInt32 GetPlayingOffset() const; - unsigned int GetSampleCount() const; - unsigned int GetSampleRate() const; + nzUInt32 GetSampleCount() const; + nzUInt32 GetSampleRate() const; nzSoundStatus GetStatus() const; bool IsLooping() const; diff --git a/include/Nazara/Audio/SoundBuffer.hpp b/include/Nazara/Audio/SoundBuffer.hpp index 8b773c5c6..ba66911db 100644 --- a/include/Nazara/Audio/SoundBuffer.hpp +++ b/include/Nazara/Audio/SoundBuffer.hpp @@ -58,8 +58,8 @@ class NAZARA_AUDIO_API NzSoundBuffer : public NzRefCounted, public NzResource nzUInt32 GetDuration() const; nzAudioFormat GetFormat() const; const nzInt16* GetSamples() const; - unsigned int GetSampleCount() const; - unsigned int GetSampleRate() const; + nzUInt32 GetSampleCount() const; + nzUInt32 GetSampleRate() const; bool IsValid() const; diff --git a/include/Nazara/Audio/SoundStream.hpp b/include/Nazara/Audio/SoundStream.hpp index 13def198d..f59a7dd8f 100644 --- a/include/Nazara/Audio/SoundStream.hpp +++ b/include/Nazara/Audio/SoundStream.hpp @@ -19,7 +19,7 @@ class NAZARA_AUDIO_API NzSoundStream virtual nzUInt32 GetDuration() const = 0; virtual nzAudioFormat GetFormat() const = 0; - virtual nzUInt64 GetSampleCount() const = 0; + virtual nzUInt32 GetSampleCount() const = 0; virtual nzUInt32 GetSampleRate() const = 0; virtual unsigned int Read(void* buffer, unsigned int sampleCount) = 0; diff --git a/src/Nazara/Audio/Formats/sndfileLoader.cpp b/src/Nazara/Audio/Formats/sndfileLoader.cpp index 3bc449d61..1b3100d40 100644 --- a/src/Nazara/Audio/Formats/sndfileLoader.cpp +++ b/src/Nazara/Audio/Formats/sndfileLoader.cpp @@ -95,7 +95,7 @@ namespace return m_format; } - nzUInt64 GetSampleCount() const override + nzUInt32 GetSampleCount() const override { return m_sampleCount; } @@ -152,11 +152,11 @@ namespace return false; } - m_sampleCount = infos.channels*infos.frames; + m_sampleCount = static_cast(infos.channels*infos.frames); m_sampleRate = infos.samplerate; // Durée de la musique (s) = samples / channels*rate - m_duration = static_cast(1000*m_sampleCount / (m_format*m_sampleRate)); + m_duration = static_cast(1000ULL*m_sampleCount / (m_format*m_sampleRate)); // https://github.com/LaurentGomila/SFML/issues/271 // http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_SCALE_FLOAT_INT_READ @@ -168,7 +168,7 @@ namespace if (forceMono && m_format != nzAudioFormat_Mono) { m_mixToMono = true; - m_sampleCount = infos.frames; + m_sampleCount = static_cast(infos.frames); } else m_mixToMono = false; @@ -206,8 +206,8 @@ namespace SNDFILE* m_handle; bool m_mixToMono; nzUInt32 m_duration; - nzUInt64 m_sampleCount; - nzUInt32 m_sampleRate; + unsigned int m_sampleCount; + unsigned int m_sampleRate; }; bool IsSupported(const NzString& extension) diff --git a/src/Nazara/Audio/Music.cpp b/src/Nazara/Audio/Music.cpp index 59e551e2a..0d3bd757e 100644 --- a/src/Nazara/Audio/Music.cpp +++ b/src/Nazara/Audio/Music.cpp @@ -119,6 +119,32 @@ nzUInt32 NzMusic::GetPlayingOffset() const return 0; } +nzUInt32 NzMusic::GetSampleCount() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Music not created"); + return 0; + } + #endif + + return m_impl->stream->GetSampleCount(); +} + +nzUInt32 NzMusic::GetSampleRate() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Music not created"); + return 0; + } + #endif + + return m_impl->stream->GetSampleRate(); +} + nzSoundStatus NzMusic::GetStatus() const { #if NAZARA_AUDIO_SAFE diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp index d1d02cd65..d55a973cd 100644 --- a/src/Nazara/Audio/SoundBuffer.cpp +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -25,8 +25,8 @@ struct NzSoundBufferImpl nzAudioFormat format; nzUInt32 duration; std::unique_ptr samples; - unsigned int sampleCount; - unsigned int sampleRate; + nzUInt32 sampleCount; + nzUInt32 sampleRate; }; NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples)