[haiku-commits] Change in haiku[master]: FileGameSound: fix stuck in pause when ramped

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 6 Dec 2020 16:53:35 +0000

From Máximo Castañeda <antiswen@xxxxxxxx>:

Máximo Castañeda has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3469 ;)


Change subject: FileGameSound: fix stuck in pause when ramped
......................................................................

FileGameSound: fix stuck in pause when ramped

Change-Id: I346d7b93fa8507451ee46856ad6618acd6e2d609
---
M src/kits/game/FileGameSound.cpp
1 file changed, 51 insertions(+), 68 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/69/3469/1

diff --git a/src/kits/game/FileGameSound.cpp b/src/kits/game/FileGameSound.cpp
index 7749467..d3531aa 100644
--- a/src/kits/game/FileGameSound.cpp
+++ b/src/kits/game/FileGameSound.cpp
@@ -252,79 +252,62 @@
        char* buffer = (char*)inBuffer;
        size_t out_offset = 0;

-       while (inByteCount > 0 && !fPaused) {
-               if (!fPaused || fPausing) {
-                       if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) 
{
-                               if (!Load())
+       while (inByteCount > 0 && (!fPaused || fPausing != NULL)) {
+               if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) {
+                       if (!Load())
+                               break;
+               }
+
+               size_t bytes = fBufferSize - fPlayPosition;
+
+               if (bytes > inByteCount) {
+                       bytes = inByteCount;
+               }
+
+               if (fPausing != NULL) {
+                       Lock();
+
+                       bool rampDone = false;
+
+                       switch(Format().format) {
+                               case gs_audio_format::B_GS_U8:
+                                       rampDone = ::FillBuffer(fPausing,
+                                               (uint8*)&buffer[out_offset],
+                                               
(uint8*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_S16:
+                                       rampDone = ::FillBuffer(fPausing,
+                                               (int16*)&buffer[out_offset],
+                                               
(int16*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_S32:
+                                       rampDone = ::FillBuffer(fPausing,
+                                               (int32*)&buffer[out_offset],
+                                               
(int32*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_F:
+                                       rampDone = ::FillBuffer(fPausing,
+                                               (float*)&buffer[out_offset],
+                                               
(float*)&fBuffer[fPlayPosition], &bytes);
                                        break;
                        }

-                       if (fPausing) {
-                               Lock();
-
-                               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) {
-                                       case gs_audio_format::B_GS_U8:
-                                               rampDone = 
::FillBuffer(fPausing,
-                                                       
(uint8*)&buffer[out_offset],
-                                                       
(uint8*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_S16:
-                                               rampDone = 
::FillBuffer(fPausing,
-                                                       
(int16*)&buffer[out_offset],
-                                                       
(int16*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_S32:
-                                               rampDone = 
::FillBuffer(fPausing,
-                                                       
(int32*)&buffer[out_offset],
-                                                       
(int32*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_F:
-                                               rampDone = 
::FillBuffer(fPausing,
-                                                       
(float*)&buffer[out_offset],
-                                                       
(float*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-                               }
-
-                               inByteCount -= bytes;
-                               out_offset += bytes;
-                               fPlayPosition += bytes;
-
-                               // We finished ramping
-                               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;
-                                       fPausing = NULL;
-                               }
-
-                               Unlock();
-                       } else {
-
-                               // Need to be able to stop asap when the pause 
flag is flipped.
-                               while (fPlayPosition < fBufferSize && (!fPaused 
|| fPausing)
-                                       && (inByteCount > 0)) {
-                                       buffer[out_offset++] = 
fBuffer[fPlayPosition++];
-                                       inByteCount--;
-                               }
+                       if (rampDone) {
+                               delete fPausing;
+                               fPausing = NULL;
                        }
+
+                       Unlock();
+               } else {
+                       memcpy(&buffer[out_offset], &fBuffer[fPlayPosition], 
bytes);
                }
+
+               inByteCount -= bytes;
+               out_offset += bytes;
+               fPlayPosition += bytes;
        }

        // Fill the rest with silence

--
To view, visit https://review.haiku-os.org/c/haiku/+/3469
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I346d7b93fa8507451ee46856ad6618acd6e2d609
Gerrit-Change-Number: 3469
Gerrit-PatchSet: 1
Gerrit-Owner: Máximo Castañeda <antiswen@xxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: FileGameSound: fix stuck in pause when ramped - Gerrit