FileGameSound: fix stuck in pause when ramped

Change-Id: I346d7b93fa8507451ee46856ad6618acd6e2d609
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3469
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
Máximo Castañeda
2020-12-08 04:32:56 +00:00
committed by waddlesplash
parent 15de111dcf
commit 8e9d64f0d6
+12 -31
View File
@@ -188,24 +188,21 @@ BFileGameSound::FillBuffer(void* inBuffer, size_t inByteCount)
char* buffer = (char*)inBuffer; char* buffer = (char*)inBuffer;
size_t out_offset = 0; size_t out_offset = 0;
while (inByteCount > 0 && !fPaused) { while (inByteCount > 0 && (!fPaused || fPausing != NULL)) {
if (!fPaused || fPausing) {
if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) { if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) {
if (!Load()) if (!Load())
break; break;
} }
if (fPausing) { size_t bytes = fBufferSize - fPlayPosition;
if (bytes > inByteCount)
bytes = inByteCount;
if (fPausing != NULL) {
Lock(); Lock();
bool rampDone = false; bool rampDone = false;
size_t bytes = fBufferSize - fPlayPosition;
if (bytes > inByteCount) {
bytes = inByteCount;
}
// Fill the requested buffer, stopping if the paused flag is set
switch(Format().format) { switch(Format().format) {
case gs_audio_format::B_GS_U8: case gs_audio_format::B_GS_U8:
@@ -233,34 +230,18 @@ BFileGameSound::FillBuffer(void* inBuffer, size_t inByteCount)
break; break;
} }
inByteCount -= bytes;
out_offset += bytes;
fPlayPosition += bytes;
// We finished ramping
if (rampDone) { if (rampDone) {
// Need to be able to stop asap when pause flag is flipped.
while (fPlayPosition < fBufferSize && (inByteCount > 0)) {
buffer[out_offset++] = fBuffer[fPlayPosition++];
inByteCount--;
}
delete fPausing; delete fPausing;
fPausing = NULL; fPausing = NULL;
} }
Unlock(); Unlock();
} else { } else
memcpy(&buffer[out_offset], &fBuffer[fPlayPosition], bytes);
// Need to be able to stop asap when the pause flag is flipped. inByteCount -= bytes;
while (fPlayPosition < fBufferSize && (!fPaused || fPausing) out_offset += bytes;
&& (inByteCount > 0)) { fPlayPosition += bytes;
buffer[out_offset++] = fBuffer[fPlayPosition++];
inByteCount--;
}
}
}
} }
// Fill the rest with silence // Fill the rest with silence