Browse Source

delayed stream reset

dmuratshin 9 years ago
parent
commit
d2fddec451

+ 4 - 0
src/sound/SoundInstance.h

@@ -10,6 +10,7 @@ namespace oxygine
 
     class SoundHandle;
 
+
     DECLARE_SMART(SoundInstance, spSoundInstance);
     class SoundInstance: public Object
     {
@@ -110,4 +111,7 @@ namespace oxygine
 
         State _state;
     };
+
+
+    const char* state2str(SoundInstance::State s);
 }

+ 4 - 1
src/sound/SoundPlayer.cpp

@@ -10,7 +10,7 @@
 
 #include "ResSound.h"
 #include "oal/StaticSoundHandleOAL.h"
-
+#include "DebugActor.h"
 #include <algorithm>
 
 namespace oxygine
@@ -247,6 +247,9 @@ namespace oxygine
                 spSoundInstance s = _sounds[i];
                 s->update();
                 end = s->getState() == SoundInstance::Ended;
+
+                if (DebugActor::instance)
+                    DebugActor::instance->addDebugString("%s '%s'", s->getName().c_str(), state2str(s->getState()));
             }
             if (end)
                 _sounds.erase(_sounds.begin() + i);

+ 7 - 0
src/sound/oal/StreamingSoundHandleOAL.cpp

@@ -244,6 +244,11 @@ namespace oxygine
     void StreamingSoundHandleOAL::_xresume()
     {
         checkNoAsync();
+        if (_reset)
+        {
+            _reset = false;
+            _stream->reset();
+        }
         alSourcei(_alSource, AL_LOOPING, AL_FALSE);
         decode(_buffers, STREAM_BUFFERS);
         ALint nump;
@@ -313,6 +318,8 @@ namespace oxygine
     void StreamingSoundHandleOAL::_xstop()
     {
         stopAsyncDecode();
+        _reset = true;
+        //_stream->reset();
 
         alSourceStop(_alSource);
 

+ 1 - 0
src/sound/oal/StreamingSoundHandleOAL.h

@@ -47,6 +47,7 @@ namespace oxygine
         ALuint _format;
         ALuint _rate;
         ALuint _buffers[STREAM_BUFFERS];
+        bool _reset;
     };