SoundEmitter: Only detach/attach buffer if necessary

This commit is contained in:
Jonas Kulla 2014-08-25 05:35:46 +02:00
parent b1ebc655f9
commit 18c74e0f24
1 changed files with 10 additions and 3 deletions

View File

@ -144,12 +144,18 @@ void SoundEmitter::play(const std::string &filename,
if (i == srcCount)
i = 0;
/* Push the used source to the back of the priority list */
size_t srcIndex = srcPrio[i];
/* Only detach/reattach if it's actually a different buffer */
bool switchBuffer = (atchBufs[srcIndex] != buffer);
/* Push the used source to the back of the priority list */
arrayPushBack(srcPrio, srcCount, i);
AL::Source::ID src = alSrcs[srcIndex];
AL::Source::stop(src);
if (switchBuffer)
AL::Source::detachBuffer(src);
SoundBuffer *old = atchBufs[srcIndex];
@ -159,6 +165,7 @@ void SoundEmitter::play(const std::string &filename,
atchBufs[srcIndex] = SoundBuffer::ref(buffer);
if (switchBuffer)
AL::Source::attachBuffer(src, buffer->alBuffer);
AL::Source::setVolume(src, _volume);