Work around occasional pops in streaming sources on iOS, by making the streaming source update code more like what was there in 0.10.x.

This commit is contained in:
Alex Szpakowski
2019-04-24 20:13:07 -03:00
parent 8f0686c204
commit 8b51dc831d
+27 -24
View File
@@ -396,36 +396,39 @@ bool Source::update()
case TYPE_STREAM: case TYPE_STREAM:
if (!isFinished()) if (!isFinished())
{ {
ALint processed;
ALuint buffers[MAX_BUFFERS];
float curOffsetSamples, curOffsetSecs, newOffsetSamples, newOffsetSecs;
int freq = decoder->getSampleRate(); int freq = decoder->getSampleRate();
alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples); ALint processed;
curOffsetSecs = curOffsetSamples / freq;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
alSourceUnqueueBuffers(source, processed, buffers);
alGetSourcef(source, AL_SAMPLE_OFFSET, &newOffsetSamples); // It would theoretically be better to unqueue all processed
newOffsetSecs = newOffsetSamples / freq; // buffers in a single call to alSourceUnqueueBuffers, but on
// iOS I observed occasional (every ~5-10 seconds) pops in the
offsetSamples += (curOffsetSamples - newOffsetSamples); // streaming source test I was using, when doing that. Perhaps
offsetSeconds += (curOffsetSecs - newOffsetSecs); // there was a bug in this code when I was testing, or maybe
// this code runs into the same problem but now it's much harder
for (int i = 0; i < processed; i++) // to reproduce. The test I used is the play-stop-play .love
unusedBuffers.push(buffers[i]); // from https://bitbucket.org/rude/love/issues/1484/
while (processed--)
while (!unusedBuffers.empty())
{ {
auto b = unusedBuffers.top(); float curOffsetSamples, curOffsetSecs;
if (streamAtomic(b, decoder.get()) > 0) alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples);
{ curOffsetSecs = curOffsetSamples / freq;
alSourceQueueBuffers(source, 1, &b);
unusedBuffers.pop(); ALuint buffer;
} alSourceUnqueueBuffers(source, 1, &buffer);
float newOffsetSamples, newOffsetSecs;
alGetSourcef(source, AL_SAMPLE_OFFSET, &newOffsetSamples);
newOffsetSecs = newOffsetSamples / freq;
offsetSamples += (curOffsetSamples - newOffsetSamples);
offsetSeconds += (curOffsetSecs - newOffsetSecs);
if (streamAtomic(buffer, decoder.get()) > 0)
alSourceQueueBuffers(source, 1, &buffer);
else else
break; unusedBuffers.push(buffer);
} }
return true; return true;