[haiku-commits] haiku: hrev54762 - src/kits/game

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 7 Dec 2020 23:33:00 -0500 (EST)

hrev54762 adds 2 changesets to branch 'master'
old head: 9293eadbdac802eba0aa782c08d5dd9972e5b4c1
new head: 8e9d64f0d6b36b9fab92272b981ffce617094934
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=8e9d64f0d6b3+%5E9293eadbdac8

----------------------------------------------------------------------------

15de111dcf54: FileGameSound: fix buffer advance accounting
  
  Change-Id: I15bb2b1e703cad955544a1151adc6a1277b077a8
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3467
  Reviewed-by: Jérôme Duval <jerome.duval@xxxxxxxxx>

8e9d64f0d6b3: 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 <jerome.duval@xxxxxxxxx>

                                    [ Máximo Castañeda <antiswen@xxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 56 insertions(+), 139 deletions(-)
src/kits/game/FileGameSound.cpp | 195 +++++++++++-------------------------

############################################################################

Commit:      15de111dcf542b27344dad9f4eb81f079a329fe6
URL:         https://git.haiku-os.org/haiku/commit/?id=15de111dcf54
Author:      Máximo Castañeda <antiswen@xxxxxxxx>
Date:        Fri Dec  4 20:26:40 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Tue Dec  8 04:32:56 2020 UTC

FileGameSound: fix buffer advance accounting

Change-Id: I15bb2b1e703cad955544a1151adc6a1277b077a8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3467
Reviewed-by: Jérôme Duval <jerome.duval@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/game/FileGameSound.cpp b/src/kits/game/FileGameSound.cpp
index 7749467025..dae021e98a 100644
--- a/src/kits/game/FileGameSound.cpp
+++ b/src/kits/game/FileGameSound.cpp
@@ -32,17 +32,18 @@ struct _gs_media_tracker {
 
 
 // Local utility functions -----------------------------------------------
+template<typename T>
 bool
-FillBuffer(_gs_ramp* ramp, uint8* data, uint8* buffer, size_t* bytes)
+FillBuffer(_gs_ramp* ramp, T* dest, const T* src, size_t* bytes)
 {
-       int32 samples = *bytes / sizeof(uint8);
+       size_t samples = *bytes / sizeof(T);
 
-       for (int32 byte = 0; byte < samples; byte++) {
+       for (size_t sample = 0; sample < samples; sample++) {
                float gain = *ramp->value;
-               data[byte] = uint8(float(buffer[byte]) * gain);
+               dest[sample] = T(float(src[sample]) * gain);
 
                if (ChangeRamp(ramp)) {
-                       *bytes = byte * sizeof(uint8);
+                       *bytes = sample * sizeof(T);
                        return true;
                }
        }
@@ -51,71 +52,6 @@ FillBuffer(_gs_ramp* ramp, uint8* data, uint8* buffer, 
size_t* bytes)
 }
 
 
-bool
-FillBuffer(_gs_ramp* ramp, int16* data, int16* buffer, size_t* bytes)
-{
-       int32 samples = *bytes / sizeof(int16);
-
-       for (int32 byte = 0; byte < samples; byte++) {
-               float gain = *ramp->value;
-               data[byte] = int16(float(buffer[byte]) * gain);
-
-               if (ChangeRamp(ramp)) {
-                       *bytes = byte * sizeof(int16);
-                       return true;
-               }
-       }
-
-       return false;
-}
-
-
-bool
-FillBuffer(_gs_ramp* ramp, int32* data, int32* buffer, size_t* bytes)
-{
-       size_t byte = 0;
-       bool bytesAreReady = (*bytes > 0);
-
-       while (bytesAreReady) {
-               float gain = *ramp->value;
-               data[byte] = int32(float(buffer[byte]) * gain);
-
-               if (ChangeRamp(ramp)) {
-                       *bytes = byte;
-                       return true;
-               }
-
-               byte++;
-               bytesAreReady = (byte >= *bytes);
-       }
-
-       return false;
-}
-
-
-bool
-FillBuffer(_gs_ramp* ramp, float* data, float* buffer, size_t* bytes)
-{
-       size_t byte = 0;
-       bool bytesAreReady = (*bytes > 0);
-
-       while (bytesAreReady) {
-               float gain = *ramp->value;
-               data[byte] = buffer[byte] * gain;
-
-               if (ChangeRamp(ramp)) {
-                       *bytes = byte;
-                       return true;
-               }
-
-               byte++;
-               bytesAreReady = (byte >= *bytes);
-       }
-
-       return false;
-}
-
-
 // BFileGameSound -------------------------------------------------------
 BFileGameSound::BFileGameSound(const entry_ref* file, bool looping,
        BGameSoundDevice* device)
@@ -273,25 +209,25 @@ BFileGameSound::FillBuffer(void* inBuffer, size_t 
inByteCount)
 
                                switch(Format().format) {
                                        case gs_audio_format::B_GS_U8:
-                                               rampDone = 
::FillBuffer(fPausing,
+                                               rampDone = 
::FillBuffer<uint8>(fPausing,
                                                        
(uint8*)&buffer[out_offset],
                                                        
(uint8*)&fBuffer[fPlayPosition], &bytes);
                                                break;
 
                                        case gs_audio_format::B_GS_S16:
-                                               rampDone = 
::FillBuffer(fPausing,
+                                               rampDone = 
::FillBuffer<int16>(fPausing,
                                                        
(int16*)&buffer[out_offset],
                                                        
(int16*)&fBuffer[fPlayPosition], &bytes);
                                                break;
 
                                        case gs_audio_format::B_GS_S32:
-                                               rampDone = 
::FillBuffer(fPausing,
+                                               rampDone = 
::FillBuffer<int32>(fPausing,
                                                        
(int32*)&buffer[out_offset],
                                                        
(int32*)&fBuffer[fPlayPosition], &bytes);
                                                break;
 
                                        case gs_audio_format::B_GS_F:
-                                               rampDone = 
::FillBuffer(fPausing,
+                                               rampDone = 
::FillBuffer<float>(fPausing,
                                                        
(float*)&buffer[out_offset],
                                                        
(float*)&fBuffer[fPlayPosition], &bytes);
                                                break;

############################################################################

Revision:    hrev54762
Commit:      8e9d64f0d6b36b9fab92272b981ffce617094934
URL:         https://git.haiku-os.org/haiku/commit/?id=8e9d64f0d6b3
Author:      Máximo Castañeda <antiswen@xxxxxxxx>
Date:        Sat Dec  5 18:54:53 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Tue Dec  8 04:32:56 2020 UTC

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 <jerome.duval@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/game/FileGameSound.cpp b/src/kits/game/FileGameSound.cpp
index dae021e98a..4fcae04cfa 100644
--- a/src/kits/game/FileGameSound.cpp
+++ b/src/kits/game/FileGameSound.cpp
@@ -188,79 +188,60 @@ BFileGameSound::FillBuffer(void* inBuffer, size_t 
inByteCount)
        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<uint8>(fPausing,
+                                               (uint8*)&buffer[out_offset],
+                                               
(uint8*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_S16:
+                                       rampDone = ::FillBuffer<int16>(fPausing,
+                                               (int16*)&buffer[out_offset],
+                                               
(int16*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_S32:
+                                       rampDone = ::FillBuffer<int32>(fPausing,
+                                               (int32*)&buffer[out_offset],
+                                               
(int32*)&fBuffer[fPlayPosition], &bytes);
+                                       break;
+
+                               case gs_audio_format::B_GS_F:
+                                       rampDone = ::FillBuffer<float>(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<uint8>(fPausing,
-                                                       
(uint8*)&buffer[out_offset],
-                                                       
(uint8*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_S16:
-                                               rampDone = 
::FillBuffer<int16>(fPausing,
-                                                       
(int16*)&buffer[out_offset],
-                                                       
(int16*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_S32:
-                                               rampDone = 
::FillBuffer<int32>(fPausing,
-                                                       
(int32*)&buffer[out_offset],
-                                                       
(int32*)&fBuffer[fPlayPosition], &bytes);
-                                               break;
-
-                                       case gs_audio_format::B_GS_F:
-                                               rampDone = 
::FillBuffer<float>(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


Other related posts:

  • » [haiku-commits] haiku: hrev54762 - src/kits/game - waddlesplash