diff options
author | Chris Robinson <[email protected]> | 2018-02-01 21:07:55 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-02-01 21:07:55 -0800 |
commit | 3acd2a55addecf646475bbf45aed03927c7d84e6 (patch) | |
tree | 4abe4eede604d891d0b62d6a90c9e24f8fb2e837 | |
parent | 3a90fd575146a61d199014fda6b6420161575f41 (diff) |
Don't generate Buffer Completed events for static sources
-rw-r--r-- | Alc/mixer.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index c34284d5..11b721f1 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -698,21 +698,45 @@ ALboolean MixSource(ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsize Counter = maxi(DstBufferSize, Counter) - DstBufferSize; firstpass = false; - /* Handle looping source position */ - if(isstatic && BufferLoopItem) + if(isstatic) { - const ALbuffer *Buffer = BufferListItem->buffers[0]; - ALsizei LoopStart = Buffer->LoopStart; - ALsizei LoopEnd = Buffer->LoopEnd; - if(DataPosInt >= LoopEnd) + if(BufferLoopItem) { - assert(LoopEnd > LoopStart); - DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart; + /* Handle looping static source */ + const ALbuffer *Buffer = BufferListItem->buffers[0]; + ALsizei LoopStart = Buffer->LoopStart; + ALsizei LoopEnd = Buffer->LoopEnd; + if(DataPosInt >= LoopEnd) + { + assert(LoopEnd > LoopStart); + DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart; + } + } + else + { + /* Handle non-looping static source */ + ALsizei CompLen = 0; + ALsizei i; + + for(i = 0;i < BufferListItem->num_buffers;i++) + { + const ALbuffer *buffer = BufferListItem->buffers[i]; + if(buffer) CompLen = maxi(CompLen, buffer->SampleLen); + } + + if(DataPosInt >= CompLen) + { + isplaying = false; + BufferListItem = NULL; + DataPosInt = 0; + DataPosFrac = 0; + break; + } } } else while(1) { - /* Handle non-looping or buffer queue source position */ + /* Handle streaming source */ ALsizei CompLen = 0; ALsizei i; @@ -746,6 +770,7 @@ ALboolean MixSource(ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsize ATOMIC_STORE(&voice->position_fraction, DataPosFrac, almemory_order_relaxed); ATOMIC_STORE(&voice->current_buffer, BufferListItem, almemory_order_release); + /* Send any events now, after the position/buffer info was updated. */ enabledevt = ATOMIC_LOAD(&Context->EnabledEvts, almemory_order_acquire); if(buffers_done > 0 && (enabledevt&EventType_BufferCompleted)) { |