AlisterT / openjazz

OpenJazz
GNU General Public License v2.0
275 stars 49 forks source link

music stutters during "planet" animation #101

Closed fabiangreffrath closed 11 months ago

fabiangreffrath commented 11 months ago

As the title says, the music stutters by repeating the last played frame during the "planet" animation which occurs between levels.

fabiangreffrath commented 11 months ago

The fix is "interesting":

--- a/src/io/sound.cpp
+++ b/src/io/sound.cpp
@@ -312,7 +312,7 @@ void stopMusic () {

        }

-       SDL_PauseAudio(0);
+//     SDL_PauseAudio(0);

 }
carstene1ns commented 11 months ago

I noticed this as well, it seems SDL2 is not clearing the audio buffer, so the last fragment of psm data keeps getting repeated. I want to revamp the audio code to get more logging and use the newer SDL2 Api there where possible. Let's see how it goes.

Btw. your fix will just keep the audio paused until next music starts it again, not really what we want here.

fabiangreffrath commented 11 months ago

Right, that's why I called it "interesting". 😉

carstene1ns commented 11 months ago

This fixes it for me. Will apply as part of the rewrite in dev branch later.

Just for reference:

diff --git a/src/io/sound.cpp b/src/io/sound.cpp
index 2c341cb..9ac78f7 100644
--- a/src/io/sound.cpp
+++ b/src/io/sound.cpp
@@ -74,6 +74,9 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {

    int count;

+   // Clear audio buffer
+   memset(stream, '\0', len * sizeof(unsigned char));
+
    if (!musicPaused) {

        // Read the next portion of music into the audio stream