Strange behaviour of Mix_FadeInMusic (1.2.5) on mods

+++++ Synopsis:
Mix_FadeInMusic(Music, 0, chunksize) following Mix_VolumeMusic(0) doesn’t take
into account the latter for low values of “chunksize” when “Music” is a mod.

+++++ How to reproduce the problem:#####
$ cat testmusic.c
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
if (argc != 4) {
fprintf(stderr, “Usage: %s \n”, argv[0]);
return 1;
}

if (SDL_Init(SDL_INIT_AUDIO) >= 0) {
if (Mix_OpenAudio(44100, AUDIO_S16, 1, atoi(argv[2])) >= 0) {
Mix_Music* Music = Mix_LoadMUS(argv[1]);
if (Music) {
Mix_VolumeMusic(0);
Mix_FadeInMusic(Music, 0, atoi(argv[3]));
printf(“Now playing\n”);
SDL_Delay(2000);
Mix_FreeMusic(Music);
}
}
}
SDL_Quit();
return 0;
};

$ cc -g -O2 -Wall -I/usr/include/SDL -D_REENTRANT -L/usr/lib -lSDL
-lpthread -lSDL_mixer testmusic.c -o testmusic

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 512 10
Now playing
[ I hear the music => BAD ]

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 512 11
Now playing
[ I don’t hear the music => GOOD ]

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 1024 22
Now playing
[ I hear the music => BAD ]

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 1024 23
Now playing
[ I don’t hear the music => GOOD ]

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 2048 45
Now playing
[ I hear the music => BAD ]

$ ./testmusic /usr/local/share/heroes/mod/heroes01.xm 2048 46
Now playing
[ I don’t hear the music => GOOD ]

+++++ Comments
heroes01.xm comes from
http://prdownloads.sourceforge.net/heroes/heroes-sound-tracks-1.0.tar.bz2.
All the other modules I’ve tested show the same behaviour.

+++++ Analysis (using SDL_mixer source code):
It appears that the lowest value of chunksize for which the volume is taken
into account is equal to ms_per_step = (int) (((float)mixer->samples *
1000.0) / mixer->freq) [file music.c, function open_music()].
This also means that music->fade_steps [function Mix_FadeInMusicPos()] = 0
when and only when the volume isn’t taken into account.
In this case, note that music_internal_volume() is never called from
music_mixer(), since (music_playing->fade_step++ < music_playing->fade_steps)
is never verified. This might explain the bug.

+++++ Testing environment:

  • Mandrake Linux 9.1 i386
  • SDL_mixer 1.2.4 (Mandrake package), 1.2.5 or CVS (both built from scratch)
  • Athlon XP 1500+
  • SB Live!

More details upon request. Thanks for your time.


Fingerprint: 8741 62F1 586D D440 C5CA D1CA CBE5 669A 7EA5 D9F9