AlisterT/openjazz

music stutters during "planet" animation

Closed this issue · 4 comments

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

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);
 
 }
 

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.

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

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