Game Development Community

Playing midi

by Jari · in Torque Game Engine · 06/21/2006 (8:03 am) · 17 replies

Hi,
I'm new in audio programming and after searching for possible midi playing solutions I decided to just ask here about this. So my question is where should I start in order to implement midi support for torque? Currently the engine can only play ogg and wav.

Thanks, any tips are welcome.

#1
06/21/2006 (8:14 am)
You might find this resource handy.

Add Tracker Support to Torque (IT, S3M, XM and MOD)

As the title suggests it adds tracker support to Torque (IT, S3M, XM and MOD). It should serve as a good guide on how and where to get started.
#2
06/21/2006 (8:55 am)
For some reason, that link leads back to this page. Using the advanced search, I found it here.

Edit: Although this enables playback of Impulse Tracker (IT), Scream Tracker 3 (S3M), Fast Tracker 2 (XM) and Amiga Module (MOD) files, it still does not allow Torque to play MIDI files.
#3
06/21/2006 (9:57 am)
Sorry about the link, it's fixed now. Yeah, no midi but for someone who wanted to program midi support into the engine the resource could serve as a good guide.
#4
06/21/2006 (6:39 pm)
Thank you for the link, it helps some but I still need a midi code/library and I cannot find one with google.

Except perhaps fmod, what do you think about this? It seems to be quite heavy solution.
#5
06/21/2006 (8:07 pm)
Using google, I came across PortMidi.

http://www.cs.cmu.edu/~music/portmusic/

It seems to be cross-platform, but may need a lot of work to tie into Torque.
#6
06/21/2006 (9:19 pm)
I discovered that one earlier too, but as it's based upon PortAudio I wasn't sure if it would "play nicely" with the existing OpenAL routines (which have similar functionality).

I just found another project based upon PortAudio and OpenAL, so there is some hope. It's called OpenAL++. Unfortunately, it doesn't appear to have been updated since late 2004, so it might not work with the lastest version of OpenAL.
#7
06/22/2006 (1:53 am)
Thanks for the links and info! Hmm OpenAL++ does not seem to support midi? I cannot find any indication from it's source that it would...
#8
06/22/2006 (8:56 am)
I don't think the existing version of OpenAL++ does support MIDI.

Its code may be useful to look at though, as it allows PortAudio (which PortMusic uses) to work with OpenAL (which TGE uses).

If nothing else, it shows that they have already been used together in a single API without major conflicts.
#9
06/22/2006 (6:23 pm)
I just found another related project which might be useful to someone more experienced with C/C++ than myself: wxMidi.
#10
06/22/2006 (8:56 pm)
Thanks Wysardry, wxMidi uses the PortAudio, I see. Well there sure is plenty of source for midi playing but not from file, I quess you just have to learn how to load them your self. :)
#11
06/22/2006 (11:04 pm)
No problem. Adding MIDI support to Torque is something I would like to do too at some point, mainly because the files would be so much smaller than digital versions.

It isn't a very high priority for me right now, so I tend to search for options on an irregular basis. This thread merely prompted me to take another look.

As for reading MIDI data from files, I believe there are several different formats (and different MIDI standards), but documentation on them shouldn't be too hard to find. It might be possible to cannibalise the necessary parts from Allegro or a similar library.
#12
07/04/2006 (12:58 pm)
Sometimes the word midi may be confusing to some. We can speak of a code for use in a midi interface (hardware) or maybe use code to play midi files (software) like org and wav. I have a feeling that members here are not talking about the same thing. With that said, I am interest also in support that torque can play midi files and agree that these files are a lot smaller than the binary. There is an execelent software called "Harmony Assistant" that plays midi files but also allows voices to sing along with the music score. The words, lyrics, in the music score is translated to music along with the notes on the music score. Imagine if torque has this capability. Dreaming - I know, but is it not how game designers create. Yet I am willing to convert the midi files I create to some binary like org or wav. Besides using binary files seem a better way to protect music arrangements than someone stilling them even though the binary files are large. Jesse.
#13
07/04/2006 (2:03 pm)
Doesn't midi traditionally have problems with consistent notes across hardware? I would think you have to provide the instrument definitions and note samples to define the instruments. I am not sure if there is a standard way to do that. I would have to take a hard look at the issues midi music would cause. However, I did have another thought. How hard would it be to generate music on the fly from midi style definitions? We are just talking about playing notes here? Could a music stream be generated realtime?
#14
07/04/2006 (2:29 pm)
@Frank

Defining tones for instruments goes back a long way.... MacPlus I think, 1982. Today most platforms read midi files just like wav files...without problems. Although I had mentioned org files but they are actually ogg files. I say org files without saying why because I simply perfer wav. Try using "Harmony Assistant" and download some irish midi files and have some fun. My favorite is "Red is the Rose".
#15
07/04/2006 (2:49 pm)
Another genre for game play if midi files could be used is a musical adventure game.
Jesse. Creating Games is Fun.
#16
07/05/2006 (5:56 am)
Here's a real world example of the difference in file sizes. The music files for jHexen are 538 Kb in MIDI format or 167 Mb (171,088 Kb) in .ogg format, making the latter over 300 times larger than the former.

The MIDI files could also be reduced by about 50% if placed in a .zip archive, but the .ogg file size would stay about the same.

Apparently, the .ogg files were produced from the original MIDI files, so this is about as direct a comparison as you could hope for.
#17
07/05/2006 (12:23 pm)
Trackers are also still a very viable option... they produce song files with a much smaller file-size than straight recordings like oggs, but are a bit bigger than MIDI. That said, you embed your samples directly into the file so you can ensure the song will always sound the same (which is still an issue, not everyone is using Windows and even Windows users can change the default MIDI GM instrument set) and also use instruments that are not a built in part of the MIDI set, or lyrics, or any such.

Now, this would require implementing a playback lib into Torque, but this shouldn't be terribly hard. I've been thinking about trying to get them implemented for smaller songfiles... I may also look into what the licensing issues are on Kb's softsynth, which would allow for songs approximately the same size as a MIDI file but MUCH higher quality.