Oggs as music, gap/static when looping

I recently started playing game music using Mix_PlayMusic(). Previously
I was loading the whole .ogg and playing it as a sample. You may
remember the discussion here a few weeks ago.

Now I started noticing that when the music loops, there’s a short
silence or static between the end of the loop and the restart. This
happens at least in Windows and Linux. I confirmed this goes away when I
reduce the buffer size (4096 to 512 at 44 KHz) but this would cause
other problems.

Looking at the code, it looks like the ogg streaming loads the ogg until
it’s over, then it sets the music as finished, and then the mixer asks
for more data, instead of filling the requested buffer restarting from
the beginning if needed.

Has anyone run into this before? I “know” the SDL code a lot more than
the SDL_mixer code so I’m not even sure I’m understanding it correctly.

Thanks,
–Gabriel–
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com

Gabriel,

I had exactly the same problem - in my case the .OGG
files in question were more sound effects than music
so I switched them to use Mix_LoadWAV and
Mix_PlayChannel instead using .WAV files. I’m still
using OGG files for the music. I’ve not had the chance
to look back at the problem since then but would like
to use OGG files rather than WAVs.

Guilherme

— Gabriel wrote:> I recently started playing game music using

Mix_PlayMusic(). Previously
I was loading the whole .ogg and playing it as a
sample. You may
remember the discussion here a few weeks ago.

Now I started noticing that when the music loops,
there’s a short
silence or static between the end of the loop and
the restart. This
happens at least in Windows and Linux. I confirmed
this goes away when I
reduce the buffer size (4096 to 512 at 44 KHz) but
this would cause
other problems.

Looking at the code, it looks like the ogg streaming
loads the ogg until
it’s over, then it sets the music as finished, and
then the mixer asks
for more data, instead of filling the requested
buffer restarting from
the beginning if needed.

Has anyone run into this before? I “know” the SDL
code a lot more than
the SDL_mixer code so I’m not even sure I’m
understanding it correctly.

Thanks,
–Gabriel


Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics -
http://gabrielongraphics.blogspot.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


To help you stay safe and secure online, we’ve developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

I had exactly the same problem - in my case the .OGG
files in question were more sound effects than music
so I switched them to use Mix_LoadWAV and
Mix_PlayChannel instead using .WAV files. I’m still
using OGG files for the music.

The problem I’m talking about only happens to music, apparently because
of this :

mixer.c, line 221 :

/* If looping the sample and we are at its end, make sure
we will still return a full buffer */
while ( mix_channel[i].looping && index < len ) {

But with the music there’s no similar code, because the looping starts
when music_internal_playing() returns false, but this happens when ogg
tries to read past the end of the stream, not when the buffer is almost
empty. I think this causes the gap.

Anyway, I’ll try to fix it and submit a patch.

--Gabriel-- 

Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com