diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index c29ee291..43ec82c5 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -61,7 +61,7 @@ void SoundManager::terminate() m_musicEnabled = false; m_soundEnabled = false; - alcMakeContextCurrent(NULL); + alcMakeContextCurrent(nullptr); if(m_context) { alcDestroyContext(m_context); diff --git a/src/framework/sound/streamsoundsource.cpp b/src/framework/sound/streamsoundsource.cpp index 1cfa8dc1..ffffa1aa 100644 --- a/src/framework/sound/streamsoundsource.cpp +++ b/src/framework/sound/streamsoundsource.cpp @@ -108,37 +108,38 @@ void StreamSoundSource::update() bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) { // fill buffer - static DataBuffer bufferData(STREAM_FRAGMENT_SIZE); + static DataBuffer bufferData(2*STREAM_FRAGMENT_SIZE); ALenum format = m_soundFile->getSampleFormat(); + int maxRead = STREAM_FRAGMENT_SIZE; + if(m_downMix != NoDownMix) + maxRead *= 2; + int bytesRead = 0; do { - bytesRead += m_soundFile->read(&bufferData[bytesRead], STREAM_FRAGMENT_SIZE - bytesRead); + bytesRead += m_soundFile->read(&bufferData[bytesRead], maxRead - bytesRead); // end of sound file - if(bytesRead < STREAM_FRAGMENT_SIZE) { + if(bytesRead < maxRead) { if(m_looping) m_soundFile->reset(); else break; } - } while(bytesRead < STREAM_FRAGMENT_SIZE); - - bool done = bytesRead >= STREAM_FRAGMENT_SIZE; - - if(m_downMix != NoDownMix) { - if(format == AL_FORMAT_STEREO16) { - if(bytesRead > 0) { - uint16_t *data = (uint16_t*)bufferData.data(); - bytesRead /= 2; - for(int i=0;i 0) { + if(m_downMix != NoDownMix) { + if(format == AL_FORMAT_STEREO16) { + assert(bytesRead % 2 == 0); + bytesRead /= 2; + uint16_t *data = (uint16_t*)bufferData.data(); + for(int i=0;igetRate()); ALenum err = alGetError(); if(err != AL_NO_ERROR) @@ -151,7 +152,7 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) } // return false if there aren't more buffers to fill - return done; + return bytesRead >= STREAM_FRAGMENT_SIZE; } void StreamSoundSource::downMix(StreamSoundSource::DownMix downMix)