diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index 1b48fe5d5..7d7f60efb 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -86,9 +86,7 @@ bool SoundFileWriterWav::check(const std::string& filename) //////////////////////////////////////////////////////////// SoundFileWriterWav::SoundFileWriterWav() : -m_file (), -m_sampleCount (0), -m_channelCount(0) +m_file() { } @@ -118,9 +116,6 @@ bool SoundFileWriterWav::open(const std::string& filename, unsigned int sampleRa return false; } - // Save the channel count - m_channelCount = channelCount; - return true; } @@ -130,8 +125,6 @@ void SoundFileWriterWav::write(const Int16* samples, Uint64 count) { assert(m_file.good()); - m_sampleCount += count; - while (count--) encode(m_file, *samples++); } @@ -191,8 +184,9 @@ void SoundFileWriterWav::close() m_file.flush(); // Update the main chunk size and data sub-chunk size - Uint32 dataChunkSize = static_cast(m_sampleCount * m_channelCount * 2); - Uint32 mainChunkSize = dataChunkSize + 36; + Uint32 fileSize = static_cast(m_file.tellp()); + Uint32 mainChunkSize = fileSize - 8; // 8 bytes RIFF header + Uint32 dataChunkSize = fileSize - 44; // 44 bytes RIFF + WAVE headers m_file.seekp(4); encode(m_file, mainChunkSize); m_file.seekp(40); diff --git a/src/SFML/Audio/SoundFileWriterWav.hpp b/src/SFML/Audio/SoundFileWriterWav.hpp index b37a970cc..98983786a 100644 --- a/src/SFML/Audio/SoundFileWriterWav.hpp +++ b/src/SFML/Audio/SoundFileWriterWav.hpp @@ -113,8 +113,6 @@ private: // Member data //////////////////////////////////////////////////////////// std::ofstream m_file; ///< File stream to write to - Uint64 m_sampleCount; ///< Total number of samples written to the file - unsigned int m_channelCount; ///< Number of channels of the sound }; } // namespace priv