diff --git a/mojoal.c b/mojoal.c index d8b1b6f..995f033 100644 --- a/mojoal.c +++ b/mojoal.c @@ -1432,12 +1432,15 @@ static ALboolean mix_source_buffer(ALCcontext *ctx, ALsource *src, BufferQueueIt if (src->stream) { /* resampling? */ int mixframes, mixlen, remainingmixframes; while ( (((mixlen = SDL_AudioStreamAvailable(src->stream)) / bufferframesize) < framesneeded) && (src->offset < buffer->len) ) { - const int framesput = (buffer->len - src->offset) / bufferframesize; - const int bytesput = SDL_min(framesput, 1024) * bufferframesize; + const int bytesleft = (buffer->len - src->offset); + /* workaround in case remains are less than bufferframesize */ + const int framesput = (bytesleft + (bufferframesize - 1)) / bufferframesize; + const int bytesput = SDL_min(SDL_min(framesput, 1024) * bufferframesize, bytesleft); FIXME("dynamically adjust frames here?"); /* we hardcode 1024 samples when opening the audio device, too. */ SDL_AudioStreamPut(src->stream, data, bytesput); src->offset += bytesput; - data += bytesput / sizeof (float); + /* workaround in case remains are not evenly divided by sizeof (float) */ + data += (bytesput + (sizeof (float) - 1)) / sizeof (float); } mixframes = SDL_min(mixlen / bufferframesize, framesneeded);