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
This commit is contained in:
LaurentGom 2010-04-06 20:48:37 +00:00
parent 007db7d39a
commit 14d0b8a483
3 changed files with 6 additions and 5 deletions

View File

@ -79,7 +79,7 @@ AudioDevice::~AudioDevice()
alcMakeContextCurrent(NULL); alcMakeContextCurrent(NULL);
if (audioContext) if (audioContext)
alcDestroyContext(audioContext); alcDestroyContext(audioContext);
// Destroy the device // Destroy the device
if (audioDevice) if (audioDevice)
alcCloseDevice(audioDevice); alcCloseDevice(audioDevice);

View File

@ -71,7 +71,7 @@ bool Music::OpenFromFile(const std::string& filename)
myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount();
// Resize the internal buffer so that it can contain 1 second of audio samples // 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 the stream
Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate()); Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate());
@ -97,7 +97,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes)
myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount(); myDuration = static_cast<float>(myFile->GetSamplesCount()) / myFile->GetSampleRate() / myFile->GetChannelsCount();
// Resize the internal buffer so that it can contain 1 second of audio samples // 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 the stream
Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate()); Initialize(myFile->GetChannelsCount(), myFile->GetSampleRate());

View File

@ -243,9 +243,10 @@ void SoundStream::Run()
} }
else else
{ {
ALint size; ALint size, bits;
ALCheck(alGetBufferi(buffer, AL_SIZE, &size)); 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 // Fill it and push it back into the playing queue