Using Libmikmod And Sdl_mixer In Parallel


Alex.

Retired
Joined
Aug 24, 2005
Messages
4,616
I want to use libmikmod for mod music playback and SDL_mixer to play wave sound effects. Both libs work fine when used separately, but if I initialize both of them in the same program, I get the black screen. There's obviously a bit of conflict going on there.

The reason why I still want to use SDL_mixer for wav sfx is because libmikmod plays wav sounds with a consistent delay, similar to the one SDL_mixer has if you set the buffer too large. However, I don't know how to tweak libmikmod to avoid this issue. If anyone could help me fix this, I'd fully ditch SDL_mixer. :)

Cheers!
 
Forgot SDL_mixer and use exclusively mikmod !
mikmod lib rox ! :)
you just need to change the default oss driver parameter.

i've made some test. A game on gp32 in 8bits video mode @67MHz is faster on gp2x in 16bits video @60MHz with mikmod but with sdl_mixer ........ it's incredible slowwwww ;)

If you're interested I can post a link of my little glouton game which work @ 66MHz. It use SDL for gfx and MIKMOD for sound.

And finally you save around 600KB of your gpe space, because you dont load lot of unused library in your gpe.
 
So, JyCet, how do you deal with delays in playing sound effects?
 
Alex. said:
So, JyCet, how do you deal with delays in playing sound effects?
Your sample is write at the end of buffer, I dont know how is configured the oss driver by default, but the buffer is too big if you use MikMod_Update(); on each frame, more bigger is the buffer and most cpu time you need and more count you have = more delay you have.

For a simple amiga mod (and his family) I use these oss driver configuration:
drv_oss.CommandLine("buffer=11,count=2");
If my memory is good buffer is the size and count is the number of buffer

This is my real example of what you can do with mikmod @ 66 MHz:
http://jycet.perso.cegetel.net/programmes/glouton_c.gpe

If you use more complexe module like s3m or it you probably need to increase buffer size otherwise you will have some crappy sound (but it depend directly of your cpu speed too), count parameter play directly in the delay.
Put 2 test after put 255 and test you will ear a big big difference

Only 2 things to remember is
buffer parameter high = more cpu time needed
count parameter high = more delay you have

Dont hesitate to post some questions, because I've searched long time to have a good speed in a game with music and sound :D

MIKMOD rox ! ;)
 
Last edited by a moderator:
I am not sure I understand what I'm supposed to do. I put the line drv_oss.CommandLine("buffer=11,count=2"); with your parameters as well as with other like (256, 1), and I get the same result, the same delay. I couldn't find docs on this on the LibMikMod site, the buffer size is in bytes, right? I am unsure what count is. The delay of playing a sound effect is roughly 1 second regardless of the parameters. Here's the code I use:

CODE

MikMod_RegisterAllDrivers();
MikMod_RegisterAllLoaders();
md_mode |= DMODE_SOFT_MUSIC;
MikMod_Init("");
drv_oss.CommandLine("buffer=11,count=2");
MikMod_SetNumVoices(-1, 3);

SAMPLE* s1 = Sample_Load("s1.wav");
SAMPLE* s2 = Sample_Load("s2.wav");
SAMPLE* s3 = Sample_Load("s3.wav");

MikMod_EnableOutput();

// simplified loop
while(1) {
if( must play a sound ) {
Sample_Play(s1, 0, 0);
}
MikMod_Update();
}

MikMod_DisableOutput();

Sample_Free(s1);
Sample_Free(s2);
Sample_Free(s3);

MikMod_Exit();



Your game performs very well, and is very fun, it's a wonderful mix of snake and pacman :)

I have a question though: I saw the code you posted on how to load a module from memory into libmikmod, and I was able to find it on google, but I am stumped on how I would go on loading a single sample from memory. Is the process similar to loading a module?

Thanks a lot for helping me out JyCet :)
 
Well, if you accept I'll suggess you to dont load all drivers, only one is usefull for GP2X it's oss driver.
In the same way dont load all loaders if you dont use it :D

here a sample code based on yours:
CODE

// configure OSS driver
drv_oss.CommandLine("buffer=11,count=2");
//register OSS driver
MikMod_RegisterDriver(&drv_oss);
//load some loaders
MikMod_RegisterLoader(&load_mod);
MikMod_RegisterLoader(&load_s3m);
//configure the mixer
md_mode |= DMODE_SOFT_MUSIC;
MikMod_Init("");

MikMod_SetNumVoices(-1, 3);
...


Another way to increase the speed, you can down mixer frequency to 22100Hz (not 22050Hz :) )
With module music and GP2X speakers you dont hear the difference with 44100Hz
For the sample it's the same way as module from memory ;)
 
You're a wizard man :) That did it! I upped the buffer to 64, and everything is working nicely. It seems though that libmikmod likes some waves more than others, I think it likes 16-bit mono ones best, I'll see to it to convert everything. Thank you very much again, you saved me a great deal of time and stress.

PS: regarding Glouton, I suggest making the wall borders white to improve visibility.
 
I came upon an issue: samples only play in one of the earphones, if using earphones. If using speakers, one of the speakers will play them much lower than the other (or possibly no sound at all, and the little sound I hear comes form the other speaker)

I suppose you can't have it all hmm :)
 
Oh a quick question, did you set certain parameters in a special way to get such a clean music playback in Glouton? When I play mod music, it feels kind of wrong, I can't quite describe it :-/ I'm using .it and .s3m
 
Alex. said:
Oh a quick question, did you set certain parameters in a special way to get such a clean music playback in Glouton? When I play mod music, it feels kind of wrong, I can't quite describe it :-/ I'm using .it and .s3m
I've reduced sample mixer sample rate to 22100Hz and force all mixer parameter which gave me the best result
CODE

drv_oss.CommandLine("buffer=11,count=2");
MikMod_RegisterDriver(&drv_oss);
MikMod_RegisterLoader(&load_mod);
md_mixfreq = 22100;
md_mode = DMODE_16BITS | DMODE_STEREO | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
MikMod_Init("");



Ah and I use only one chanel for sfx because my samples are very short and it dont need more chanel :)
 
Last edited by a moderator:
Thanks for sharing all that JyCet :)

By the way, here's the way to play a mono sfx on both speakers:

Voice_SetPanning(Sample_Play(sfx, 0, 0), PAN_CENTER);
 
Alex. said:
I came upon an issue: samples only play in one of the earphones, if using earphones. If using speakers, one of the speakers will play them much lower than the other (or possibly no sound at all, and the little sound I hear comes form the other speaker)

I suppose you can't have it all hmm :)
This happens with every program afaik
 
Last edited by a moderator:
An issue: sound quality for large (~300kb) music files is horrible with a small buffer; increasing the buffer's size betters playback quality, but also increases the time delay in playing sound effects. Is there a work-around this issue, or can it be considered an awesome limitation? :)
 
Alex. said:
An issue: sound quality for large (~300kb) music files is horrible with a small buffer; increasing the buffer's size betters playback quality, but also increases the time delay in playing sound effects. Is there a work-around this issue, or can it be considered an awesome limitation? :)
I use a mod file 380KB and I dont have any sound pb, but it's a "simple" mod with 4 chanels.
 
Last edited by a moderator:
Ah, that may be the problem too, I tried .it's and .srm's, with 16 or so channels.
 
Back
Top