From 14d0b8a483a6dfc594862bbc7db25aec5954ef8d Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Tue, 6 Apr 2010 20:48:37 +0000 Subject: [PATCH] Fixed a possible bug in the calculation of sf::SoundStream playing offset git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1495 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Audio/AudioDevice.cpp | 2 +- src/SFML/Audio/Music.cpp | 4 ++-- src/SFML/Audio/SoundStream.cpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index 2e7bccf21..39d5b9075 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -79,7 +79,7 @@ AudioDevice::~AudioDevice() alcMakeContextCurrent(NULL); if (audioContext) alcDestroyContext(audioContext); - + // Destroy the device if (audioDevice) alcCloseDevice(audioDevice); diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 8ec0deb4e..2e89b8217 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -71,7 +71,7 @@ bool Music::OpenFromFile(const std::string& filename) myDuration = static_cast(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); // Resize the internal buffer so that it can contain 1 second of audio samples - mySamples.resize(myFile->GetSampleRate()); + mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount()); // Initialize the stream Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate()); @@ -97,7 +97,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes) myDuration = static_cast(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); // Resize the internal buffer so that it can contain 1 second of audio samples - mySamples.resize(myFile->GetSampleRate()); + mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount()); // Initialize the stream Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate()); diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index abcc69172..ee47ca436 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -243,9 +243,10 @@ void SoundStream::Run() } else { - ALint size; + ALint size, bits; ALCheck(alGetBufferi(buffer, AL_SIZE, &size)); - mySamplesProcessed += size / sizeof(Int16); + ALCheck(alGetBufferi(buffer, AL_BITS, &bits)); + mySamplesProcessed += size / (bits / 8); } // Fill it and push it back into the playing queue