SDL_mixer and Mix_PausMusic() and midi?

I downloade SDL_mixer today, and may I say, great stuff!

I ran in to one problem thou. When Atempting so Play midi-files i only get
sound from the left sound-channel and Mix_PauseMusic() doesn’t seam to
work.

I’s there any way around this problem?

/Jakob Eklund

Jakob Eklund wrote:

I downloade SDL_mixer today, and may I say, great stuff!

I ran in to one problem thou. When Atempting so Play midi-files i only
get sound from the left sound-channel and Mix_PauseMusic() doesn’t seam
to work.

I’s there any way around this problem?

Mix_PauseMusic() can be tested using the sample application “playmus”.
Use the “-i” flag: "playmus -i " and press “p” when
the music is playing to pause it. Using the timidity library, I just
tried that and it worked ok. Are you using the timidity library
with SDL_mixer? The alternative in native_midi_gpl is not currently
fully functional (because of a mistake in the code that I’ve pointed
out 3 times now).

I haven’t noticed any problems with the right channel using the
timidity library and the Alsa driver on Linux. It plays on both
left and right channels.

Greg

Jakob Eklund wrote:

Are you using the timidity library
with SDL_mixer? The alternative in native_midi_gpl is not currently
fully functional (because of a mistake in the code that I’ve pointed
out 3 times now).

I haven’t noticed any problems with the right channel using the
timidity library and the Alsa driver on Linux. It plays on both
left and right channels.

Greg

If I use Timidy, doesn’t that mean eveyone who is using my program is
going to have to install Timidy to(If they want sound in both speakers
that is ^^)? I like to avoid that sort of thing.

I’m considdering using Mod instead, althou i’m not shure what the exact
differens is (but… but… It works ^^;;).On Tue, 13 Jul 2004 08:00:47 -1000, Greg Lee wrote:

Jakob Eklund wrote:

If I use Timidy, doesn’t that mean eveyone who is using my program is
going to have to install Timidy to(If they want sound in both speakers
that is ^^)? I like to avoid that sort of thing.

No, it doesn’t mean that. If your program plays midis by calling
SDL_mixer to play them, then users of your program will need an
SDL_mixer installed that can somehow play midis. That’s all.
SDL_mixer has various means of playing midis, depending on the
operating system and how it’s been installed. One of those
ways uses SDL_mixer’s timidity library.

I wasn’t suggesting that you start timidity if you’re not using
it now. I was just trying to understand where your problem is.

I’m considdering using Mod instead, althou i’m not shure what the exact
differens is (but… but… It works ^^;;).

Both mods and midis use instrument samples to make musical notes. Mods
incorporate the samples they use into the mod file, but midi files
don’t contain samples. Midis depend on a synthesizer which can
can use its own samples, commonly from the standard General Midi
set of instrument samples.

Mods are more flexible in the sounds they use – they don’t have
to stick to imitations of ordinary musical instruments. Mods
tend to be musically less conventional and less sophisticated
than midis.

Greg> On Tue, 13 Jul 2004 08:00:47 -1000, Greg Lee <@Greg_Lee> wrote:

Recently made midi files created with MS tools are
sometimes (often? always?) in the RMID format, which
embeds an ordinary midi file structure inside a
RIFF chunk. SDL_mixer cannot play RMID files, though
the other midi players I have on my system do play
them: pmidi, playmidi, Timidity++.

One reason SDL_mixer can’t play RMID files is that
Mix_LoadMUS() misidentifies them as WAVE files.
It sees the magic RIFF at the beginning of the
file and decides because of that to pass the
file on to WAVStream_LoadSong(), which then
realizes it’s not a WAVE file and rejects it.
This happens even if the filename extension is
".mid".

What Mix_LoadMUS() should do is read on past
the RIFF magic to see whether the next magic
is WAVE, in which case it should be passed on
to WAVStream_LoadSong(), or RMID, in which case
it should be passed on to a midi player.

Here is example replacement code for music.c.
At the beginning of Mix_LoadMUS():


Uint8 magic[5], moremagic[9];
Mix_Music *music;

/* Figure out what kind of file this is */
fp = fopen(file, "rb");
if ( (fp == NULL) || !fread(magic, 4, 1, fp) ) {
	if ( fp != NULL ) {
		fclose(fp);
	}
	Mix_SetError("Couldn't read from '%s'", file);
	return(NULL);
}
if (!fread(moremagic, 8, 1, fp)) {
	Mix_SetError("Couldn't read from '%s'", file);
	return(NULL);
}
magic[4] = '\0';
moremagic[8] = '\0';
fclose(fp);

Then to call WAVStream_LoadSong():

/* WAVE files have the magic four bytes "RIFF"
AIFF files have the magic 12 bytes “FORM” XXXX “AIFF”
*/
if ( (ext && MIX_string_equals(ext, “WAV”)) ||
((strcmp((char *)magic, “RIFF”) == 0) &&
(strcmp((char *)(moremagic+4), “WAVE”) == 0)) ||
(strcmp((char *)magic, “FORM”) == 0) ) {
music->type = MUS_WAV;
music->data.wave = WAVStream_LoadSong(file,
(char )magic);

and to call a midi player:

/
MIDI files have the magic four bytes “MThd” */
if ( (ext && MIX_string_equals(ext, “MID”)) ||
(ext && MIX_string_equals(ext, “MIDI”)) ||
strcmp((char *)magic, “MThd”) == 0 ||
( strcmp((char *)magic, “RIFF”) == 0 &&
strcmp((char *)(moremagic+4), “RMID”) == 0 ) ) {
music->type = MUS_MID;

And now RMID files get routed to the right players. Since
Nathan Laredo’s playmidi already knows about RMID files,
there is no change necessary to the code in
native_midi_gpl/. I don’t know about native_midi/. Timidity
needs a small change in readmidi.c, near the beginning
of read_midi_file():


past_riff:

if ((fread(tmp,1,4,fp) != 4) || (fread(&len,4,1,fp) != 1))
{
if (ferror(fp))
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, “%s: %s”,current_filename,
strerror(errno));
}
else
ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
"%s: Not a MIDI file!", current_filename);
return 0;
}
len=BE_LONG(len);

if (!memcmp(tmp, “RIFF”, 4))
{
fread(tmp,1,12,fp);
goto past_riff;
}

will do it.

I’ve verified these changes by using playmus to play WAVE files with
and without the .wav extension, RMID files with and without the .mid
extension, and ordinary midi files, with and without the .mid
extension.

Patches for these changes, as well as for the bugs in native_midi_gpl
and in SDL_audiocvt.c which I’ve mentioned previously, are in
the archive file ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz,
along with, of course, the surround sound patches.

Greg

Patches for these changes, as well as for the bugs in native_midi_gpl
and in SDL_audiocvt.c which I’ve mentioned previously, are in
the archive file ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz,
along with, of course, the surround sound patches.

Thanks! I’ve applied your SDL surround sound patches, they look pretty good.
Please let me know if there are any bugs or if I’ve missed any patches.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment