From 3ca6e0f34698fdc5f1be73b3bbf3b3dbf7a4ea26 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Sat, 21 Mar 2015 13:45:54 +0100 Subject: [PATCH] Added support for 32-bits samples in WAV files --- src/SFML/Audio/SoundFileReaderWav.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SFML/Audio/SoundFileReaderWav.cpp b/src/SFML/Audio/SoundFileReaderWav.cpp index df8fb98b1..730f841d9 100644 --- a/src/SFML/Audio/SoundFileReaderWav.cpp +++ b/src/SFML/Audio/SoundFileReaderWav.cpp @@ -65,6 +65,17 @@ namespace return true; } + bool decode(sf::InputStream& stream, sf::Int32& value) + { + unsigned char bytes[sizeof(value)]; + if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes)) + return false; + + value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); + + return true; + } + bool decode(sf::InputStream& stream, sf::Uint32& value) { unsigned char bytes[sizeof(value)]; @@ -157,6 +168,16 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount) return count; break; } + + case 4: + { + Int32 sample = 0; + if (decode(*m_stream, sample)) + *samples++ = sample >> 16; + else + return count; + break; + } } ++count;