From 517ccbefb5de8c35c4cae464a59915d06a2b80b6 Mon Sep 17 00:00:00 2001 From: Bim Overbohm Date: Wed, 15 May 2013 10:12:51 +0200 Subject: [PATCH] Fix that Sounds can't restart Sounds now restart when e.g. scrolling up/down repeatedly. --- src/Sound.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index ee93d8067..ec1166b1b 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -82,8 +82,18 @@ void Sound::play() if(mSampleData == NULL) return; - //flag our sample as playing - playing = true; + if (playing) + { + //replay from start. rewind the sample to the beginning + SDL_LockAudio(); + mSamplePos = 0; + SDL_UnlockAudio(); + } + else + { + //flag our sample as playing + playing = true; + } //tell the AudioManager to start playing samples AudioManager::play(); } @@ -96,8 +106,10 @@ bool Sound::isPlaying() const void Sound::stop() { //flag our sample as playing and rewind its position + SDL_LockAudio(); playing = false; mSamplePos = 0; + SDL_UnlockAudio(); } const Uint8 * Sound::getData() const