mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Improve stop and rewind logic for openal
This commit is contained in:
@@ -89,6 +89,7 @@ namespace openal
|
|||||||
if(!i->first->update())
|
if(!i->first->update())
|
||||||
{
|
{
|
||||||
i->first->stopAtomic();
|
i->first->stopAtomic();
|
||||||
|
i->first->rewindAtomic();
|
||||||
i->first->release();
|
i->first->release();
|
||||||
available.push(i->second);
|
available.push(i->second);
|
||||||
playing.erase(i);
|
playing.erase(i);
|
||||||
|
|||||||
@@ -153,55 +153,42 @@ namespace openal
|
|||||||
alSourcei(source, AL_LOOPING, isLooping() ? AL_TRUE : AL_FALSE);
|
alSourcei(source, AL_LOOPING, isLooping() ? AL_TRUE : AL_FALSE);
|
||||||
return !isStopped();
|
return !isStopped();
|
||||||
}
|
}
|
||||||
else if (type == TYPE_STREAM)
|
else if (type == TYPE_STREAM && (isLooping() || !isFinished()))
|
||||||
{
|
{
|
||||||
if (isLooping() || !isFinished())
|
// Number of processed buffers.
|
||||||
|
ALint processed;
|
||||||
|
|
||||||
|
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
|
|
||||||
|
while(processed--)
|
||||||
{
|
{
|
||||||
// Number of processed buffers.
|
ALuint buffer;
|
||||||
ALint processed;
|
|
||||||
|
|
||||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
float curOffsetSamples, curOffsetSecs;
|
||||||
|
|
||||||
while(processed--)
|
alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples);
|
||||||
{
|
|
||||||
ALuint buffer;
|
|
||||||
|
|
||||||
float curOffsetSamples, curOffsetSecs;
|
ALint b;
|
||||||
|
alGetSourcei(source, AL_BUFFER, &b);
|
||||||
|
int freq;
|
||||||
|
alGetBufferi(b, AL_FREQUENCY, &freq);
|
||||||
|
curOffsetSecs = curOffsetSamples / freq;
|
||||||
|
|
||||||
alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples);
|
// Get a free buffer.
|
||||||
|
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||||
|
|
||||||
ALint b;
|
float newOffsetSamples, newOffsetSecs;
|
||||||
alGetSourcei(source, AL_BUFFER, &b);
|
|
||||||
int freq;
|
|
||||||
alGetBufferi(b, AL_FREQUENCY, &freq);
|
|
||||||
curOffsetSecs = curOffsetSamples / freq;
|
|
||||||
|
|
||||||
// Get a free buffer.
|
alGetSourcef(source, AL_SAMPLE_OFFSET, &newOffsetSamples);
|
||||||
alSourceUnqueueBuffers(source, 1, &buffer);
|
newOffsetSecs = newOffsetSamples / freq;
|
||||||
|
|
||||||
float newOffsetSamples, newOffsetSecs;
|
offsetSamples += (curOffsetSamples - newOffsetSamples);
|
||||||
|
offsetSeconds += (curOffsetSecs - newOffsetSecs);
|
||||||
|
|
||||||
alGetSourcef(source, AL_SAMPLE_OFFSET, &newOffsetSamples);
|
streamAtomic(buffer, decoder);
|
||||||
newOffsetSecs = newOffsetSamples / freq;
|
alSourceQueueBuffers(source, 1, &buffer);
|
||||||
|
|
||||||
offsetSamples += (curOffsetSamples - newOffsetSamples);
|
|
||||||
offsetSeconds += (curOffsetSecs - newOffsetSecs);
|
|
||||||
|
|
||||||
streamAtomic(buffer, decoder);
|
|
||||||
alSourceQueueBuffers(source, 1, &buffer);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Actually stop the source,
|
|
||||||
// 'just running out' is bad
|
|
||||||
// practice, and prevents
|
|
||||||
// rewinds.
|
|
||||||
stopAtomic();
|
|
||||||
rewindAtomic();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user