Hitches when switch music in SDL_Mixer

For one part of our project we have an intro song that (should) seamlessly
transition into a loop song without a gap in the audio playback. What we’re
experiencing, though, is that there is around a 300ms gap when switching
songs.

Our implementation checks if the intro song has finished playing at about
60Hz and starts the loop song the frame it ends. Is there anything I can do
to prevent or shorten these gaps?–
Collin Arnold
Software Developer
Zachtronics Industries http://www.zachtronicsindustries.com/

For one part of our project we have an intro song that (should)
seamlessly transition into a loop song without a gap in the audio
playback. What we’re experiencing, though, is that there is around a
300ms gap when switching songs.

Our implementation checks if the intro song has finished playing at
about 60Hz and starts the loop song the frame it ends. Is there anything
I can do to prevent or shorten these gaps?

Don’t check if it’s finished, use Mix_HookMusicFinished() instead. We’ll
call a function you specify as soon as we process the last sample in the
song. If you start a new track during this function, there should be no
gap, since we’re literally still in the middle of SDL’s audio callback,
and will just fill the rest of the audio buffer with the new track.

We spent time on SDL_mixer to make this exact use case work for Dungeons
of Dredmor.

–ryan.

Ah sweet, that totally fixed the problem! Thanks!On Thu, Aug 15, 2013 at 5:18 PM, Ryan C. Gordon wrote:

For one part of our project we have an intro song that (should)

seamlessly transition into a loop song without a gap in the audio
playback. What we’re experiencing, though, is that there is around a
300ms gap when switching songs.

Our implementation checks if the intro song has finished playing at
about 60Hz and starts the loop song the frame it ends. Is there anything
I can do to prevent or shorten these gaps?

Don’t check if it’s finished, use Mix_HookMusicFinished() instead. We’ll
call a function you specify as soon as we process the last sample in the
song. If you start a new track during this function, there should be no
gap, since we’re literally still in the middle of SDL’s audio callback, and
will just fill the rest of the audio buffer with the new track.

We spent time on SDL_mixer to make this exact use case work for Dungeons
of Dredmor.

–ryan.

_____________**
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Collin Arnold
Software Developer
Zachtronics Industries http://www.zachtronicsindustries.com/