LWJGL Forum

Programming => General Java Game Development => Topic started by: Ciardhubh on June 10, 2010, 11:18:04

Title: Anybody know a Java MIDI library?
Post by: Ciardhubh on June 10, 2010, 11:18:04
Does anybody know a Java library that can synthesise MIDI audio files to something sampled (like Wav/Ogg/etc.), so you can pass it to OpenAL? License is also an issue. It shouldn't be "infectious" like the GPL, e.g. BSD, LGPL, Apache.

I looked around but didn't find anything suitable.

javax.sound.midi appears to use hardcoded ouput via the OS' audio system. It's unstable (doesn't work together with other audio apps) and AFAIK there's no way to capture output.
JFugue is buillt on top of javax.sound.midi and suffers from the same limitations.
Gervill and Frinika are published under the GPL.
Title: Re: Anybody know a Java MIDI library?
Post by: kappa on June 10, 2010, 12:09:14
Not found a good java midi library however their is a really good java library for playing mod/xm/s3m called IBXM (http://sites.google.com/site/mumart/).

Slick2D  (http://slick.cokeandcode.com/)already uses this to play sound files, so if you need a quick implementation for LWJGL just rip it out from there as its coded nicely and easily separable.

Next if you go to the Slick2D HomePage (http://slick.cokeandcode.com/) on the side bar you'll find an old tool called G2Mid2Mod (you can also try see if you can find it on google if you want). This will convert midi to xm allowing you to play them with IBXM.

P.S Thanks for your lwjgl tutorials on your website, i've found them most useful.
Title: Re: Anybody know a Java MIDI library?
Post by: Ciardhubh on June 10, 2010, 17:12:51
Thanks, I already integrated IBXM into my audio system (with a few tweaks; mono output for 3D sources and a fixed endianness issue on Linux). It's a nice decoder. Too bad the new version has no licensing info available, so I'm still using a slightly older one.

If converting from MIDI to a tracker format would work at runtime, that would be nice. I already thought about command line, non-Java synthesisers to do it at runtime but then I'd have the rather annoying overhead of maintining natives for all OSs (plus the non-Java crowd seems to be rather taken by the GPL). Midi probably isn't worth the trouble. I wonder what's better - performance-wise - convert to Ogg or a tracker format and decode that at runtime.

Anyway ... always glad when those tutorials I put up are of some use to someone :)
Title: Re: Anybody know a Java MIDI library?
Post by: bobjob on June 12, 2010, 00:51:01
I found this, but havnt tried it yet
http://sites.google.com/site/mumart/home/liquinth-polyphonicanalogue-stylemusicsynthesizerforjava (http://sites.google.com/site/mumart/home/liquinth-polyphonicanalogue-stylemusicsynthesizerforjava)
Title: Re: Anybody know a Java MIDI library?
Post by: Ciardhubh on June 12, 2010, 09:28:56
I found this, but havnt tried it yet
http://sites.google.com/site/mumart/home/liquinth-polyphonicanalogue-stylemusicsynthesizerforjava (http://sites.google.com/site/mumart/home/liquinth-polyphonicanalogue-stylemusicsynthesizerforjava)

From the looks of it (comments are a bit ... non-existent) it's a virtual keyboard/instrument. It does synthesise single notes to PCM audio data when you press a key. Unfortunately it doesn't look like it supports predefined sequences like MIDI files.
Title: Re: Anybody know a Java MIDI library?
Post by: bobjob on June 12, 2010, 19:54:56
From the looks of it (comments are a bit ... non-existent) it's a virtual keyboard/instrument. It does synthesise single notes to PCM audio data when you press a key. Unfortunately it doesn't look like it supports predefined sequences like MIDI files.
Damn,
I tried to find another solution and I'm actually surprised that MIDI is such a head ache in java.
Title: Re: Anybody know a Java MIDI library?
Post by: Matthias on June 13, 2010, 09:53:42
Java has a MIDI playback API - but it will output it via the sound card and not to PCM data
Title: Re: Anybody know a Java MIDI library?
Post by: Ciardhubh on June 15, 2010, 11:03:21
Java has a MIDI playback API - but it will output it via the sound card and not to PCM data

javax.sound.midi? I don't get what the point of that API is supposed to be. No access to PCM data and it requires exclusive access to the OS's audio system, i.e. it prevents other (VLC, OpenAL, etc.) apps from playing audio and won't play if others are playing. Either I'm missing something or javax.sound.midi is useless for any non-trivial application.