Question on SDL Mixer

Hi, I was wondering if anyone else has the same problem I do, or it is
something I’m doing wrong. On my action game I have, for each stage, a
regular stage song, a boss rush and a stage clear song. As expected, the
boss is part of the stage, so when the player gets near the boss, the
music changes. When the boss is defeated, the stage clear song plays and
everyone is happy. Well, not quite.

I'm using .it files (MOD) for the music and if I try to load the three 

musics at the same time time in memory, using three Mix_Music pointers,
the game will crash when unloading the musics. It does not happen on all
combinations, which is what puzzles me, some musics will unload just
fine when loaded in memory with other musics, but for most of them,
having more than one music in memory at the same time is a prelude to
doomsday.

I known that the bug is not somewhere in the game logic, I changed the 

game to unload the current music and load the new music “on the fly” and
it works fine. No crash, no matter which music was played during the
stage. That is good when using a fast hard disk on a desktop, but when
playing the game from a CD or on a notebook, this is just awful.

I thought a very simple solution, which was to load the .it data in 

memory and use SDL_Rwops to read the music from there, which would be
almost instantaneous and would solve my problem. Problem is that
SDL_Mixer does not support SDL_Rwops for music, just for samples. Or is
it an undocumented feature?

I know, in the end I can use ogg files for my music as well and handle 

myself the “music playing as a sample”, but everything is so nicely
organized on (small) .it files that it seems a waste to include another
lib just to be able to play (larger) ogg files.

Best Regards,

Paulo V W Radtke

http://blog.chienloco.com
http://www.chienloco.com

Paulo V W Radtke wrote:

I thought a very simple solution, which was to load the .it data in 

memory and use SDL_Rwops to read the music from there, which would be
almost instantaneous and would solve my problem. Problem is that
SDL_Mixer does not support SDL_Rwops for music, just for samples. Or is
it an undocumented feature?

Mix_LoadMUS_RW(), in the fresh SDL_mixer 1.2.6

Gautier.

I thought a very simple solution, which was to load the .it data 

in memory and use SDL_Rwops to read the music from there, which would
be almost instantaneous and would solve my problem. Problem is that
SDL_Mixer does not support SDL_Rwops for music, just for samples. Or
is it an undocumented feature?

Mix_LoadMUS_RW(), in the fresh SDL_mixer 1.2.6

Thanks Gautier, this will solve my problems once and for all.

Also, I made a small app to load some .it musics and toy around and I 

found what most likely is the problem. I don’t know how things are
implemented in SDL_Mixer to handle MOD music files, what I will say from
now on is based on practical experiments, but it seems that when loading
multiple music files, some data structures are shared musics - at least
for .it (MOD files).

The problem arises when multiple songs with different channel number 

are loaded in memory. If I load a music with 10 channels and another
with 12 in sequence, the second music will play only the first 10
channels (it will ignore channels 11 and 12), and one of the two will
happen. Either the effects on the available channels will be messed up
in the second music, which is bad, or the available channels will play
fine but freeing the memory with Mix_FreeMusic will cause a segmentation
fault, which is even worse.

I'm sorry for not being able to help with further than this to fix the 

problem. I don’t know if there are many people using tracked music
nowadays, but the SDL_Rwops will fix this for me, and others as well, as
I will be able to load music files from memory. In the event there’s no
need for a bug fix, it would be interesting if the documentation
mentioned, somewhere, that you should avoid loading multiple MOD files
at once to avoid problems.

If someone is interested, I can send a small source code (very 

quick’n’dirty stuff) to show some offending files examples and their
effects.

Best regards,

Paulo V W Radtke

http://blog.chienloco.com
http://www.chienloco.com

I’d interested in a demo program with two songs.
this may also be a bug in mikmod…and not SDL_mixer perhaps.

-LIM-

I have sent Jonathan the files as he requested, if someone else wants
to take a look, just ask me and I will send them by e-mail. It’s quite
large, about 1MB, so I won’t post all this on the list.

Best regards,

Paulo V W Radtke

http://blog.chienloco.com
http://www.chienloco.com

Jonathan Atkins escreveu:> I’d interested in a demo program with two songs.

this may also be a bug in mikmod…and not SDL_mixer perhaps.

-LIM-