SDL_mixer Midi patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
MikeG
Engineer
Engineer
Posts: 8
Joined: 26 Jan 2005 12:49

SDL_mixer Midi patch

Post by MikeG »

Hi there,

first many thanks, I love to play this game out of my linux box!

I got a fault, game crashed, but music was playing on and on. I analyzed source and learned that you used a fork to timidity executable to play music. Nice idea, but it would better to play music using the mixer extension of SDL. So I decided to write a patch.

My current problem is, that SDL_OpenAudio is casted, and an audio device will open for FX. Ok, but I need Mix_OpenAudio, which is casted after SDL'ed once. Mix_GetError() returns, that an Audiodevice is allready open.

I wrote a little bit in sdl.c in function SdlSoundStart(), so it looks like this:

Code: Select all


        spec.samples = 512;
        spec.callback = fill_sound_buffer;
#if defined(WITH_SDLMIXER)
        SDL_CALL Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 4096);
#else
        SDL_CALL SDL_OpenAudio(&spec, &spec);
        SDL_CALL SDL_PauseAudio(0);
#endif
        return NULL;
}
Now I have the problem, that the sound-fx can't start, because its the same with *OpenAudio but vice versa. I need to write a new sound driver to, also with SDL but with Mix*-ext.

My question here is, can someone tell me, if there's a simple way to put this type of sound-bank with Mix-ext?

If you want to try my code, here is a patch and add the line

musicdriver = sdlmidi

to your config file in [misc]
Last edited by MikeG on 27 Jan 2005 20:57, edited 3 times in total.
User avatar
orudge
Administrator
Administrator
Posts: 25225
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Post by orudge »

I've not really looked into your code, but it would be a good idea to make sure your code still runs by doing:

ttd -m sdl -s null

[ie, with SDL music but no sound]. Perhaps a strange thing for people to want to do, but it wouldn't hurt to make sure that the midi driver doesn't rely on the sound driver. A common "StartSDL" type function which maintains a static variable noting whether SDL has been initialised should suffice... if such a thing isn't already there. I know such a thing exists in my unreleased Allegro driver (which should work on *NIX, Mac OS X, etc, although I just tested it on DOS and Win32).

Well, anyway, good luck with it. ;)
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

I'm not using SDL but 2 things :)

1. attach the diff file not the .c file
2. make it work as ./openttd -m SDLMIDI or something, not through the config file.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
MikeG
Engineer
Engineer
Posts: 8
Joined: 26 Jan 2005 12:49

Post by MikeG »

Ok, I attached the patch, but not removed the .c.

The game works, if -m sdlmidi is appended. If the default driver (extmidi) is loaded, the soundfx are playing. If my driver is loaded, soundfx are not playing.

I will work on my own sound driver. Many thanks for the tipps, it is my first time, that I offer a patch for a project and may I do many stupid things ;-)

BTW: sorry for the bad written english, I'm german.

Here is the right diff attached
MikeG
Engineer
Engineer
Posts: 8
Joined: 26 Jan 2005 12:49

Post by MikeG »

Now it is all in one file :)

sdlmix.c is now included in patch.

Is it true, that svn is writeable for world?

$ svn add sdlmix.c

worked for me.

If it is writeable, I can commit my changes directly.

Thanks
Mike
Attachments
sdlmixer-cvs.patch
(7.25 KiB) Downloaded 312 times
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

svn add != svn commit :)
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests