Skip to content

The state of MIDI support on Android

by peterdk on May 7th, 2010

The current state of Midi support on Android is depressing. They ripped out javax.sound.midi, so all libraries that depend on this are not working. (Things like JFugue for example).

Fortunately the MediaPlayer does support the playback of midi files. So if you want to have dynamic audio, you need to create your own midi file writing library, or find an existing one. Midi is quite an old beast, so it takes some effort to learn this. Fortunately there are lot of examples and info for the MIDI file format.

Android seems to use Sonivox for MIDI handling in the MediaPlayer. From what I understand it’s a embedded synthesizer that is integrated in Android. One of the things it support is the Jet file format. It’s some kind of wrapper around midi that you can use to “dynamically” playback music. It’s however totally depended on manually generated midi input that you need to edit on your PC to turn into the Jet format. So no pushing midi events to a stream or something like that. The only thing you can do is repeat sections and turn tracks on and off. Bummer.

So, currently on Android there is no way to dynamically generate realtime MIDI. We can’t simple send midi-commands to a synthesizer that then realtime plays it back.

However…. According to  the Sonivox EAS (Embedded Audio Synthesis) API Reference (found in the git tree of android), Sonivox does support Midi Streaming! That means that the low-level software stack of android does have the support for it. But it’s not exposed to us poor developers. I also don’t know if it’s possible to use the NDK to just use these C(++) API’s. I don’t have the C knowledge for that, and the NDK docs don’t mention them as supported/stable.

So, there may be a change that you can indeed use the C API’s, but that means you need to learn C/C++. Could be usefull, but well, why can’t we get it in Java in the SDK?

To resolve this I have opened a feature request on the google issue tracker to request for exposing these API’s in Java. If you are in any way interested in this feature, please leave a comment, star it, rate it, whatever it takes to let Google know that we need better MIDI support!

Now back to hacking.

Update
Personally I solved the dynamic midi generation issue as follows: programmatically generate a midi file, write it to the device storage, initiate a mediaplayer with the file and let it play. This is fast enough if you just need to play a dynamic midi sound. I doubt it’s useful for creating user controlled midi stuff like sequencers, but for other cases it’s great.

From → Android, Java

13 Comments
  1. byron permalink

    Yes, I have faced the same issue. I want to create an app involving midi control. In the previous version of Android SDK, it can have J2ME standard midi interface. So we can send the midi messages to Android’s embedded synthesizer at anytime. But the recent releases of SDK have removed this interface. Instead, they create the Jetplayer APIs to java programmer. Jetplayer is not really suitable to be used to build the musical game. Now I will try to build on NDK layer.

  2. peterdk permalink

    You do realize that the NDK support for this is non-existing? I mean, it’s not stable.
    For me it’s too hard now, but I would really love to know if you indeed succeeded to implement it!

  3. Paul permalink

    Would you be willing to share the code you created for dynamically creating the midi file?

    Thx

  4. peterdk permalink

    Hi Paul,

    I am not willing to share the final code, but I did try to find the online example for generating midi files that I used to create my own. Unfortunately I can’t find it anymore. Just search the internet for java and midi, it will probably give some usefull results and examples.

    Peter

  5. Paul permalink

    Thanks for the response.

    Regards,
    Paul

  6. Vasos Panagiotopoulos permalink

    I tried running my midi files on Android’s sound player and it thinks they are karaoke and fails. I am trying to find a midi player that is downloadable as an apk file off the web because I don’t have the ability to log in my android tablet just yet.

  7. All the android apps look and sound great but are just toys. all apps lack midi clock – to be useful to a musician in a live situation, you must be able to share master midi clock! pleaseeee sort it

  8. I just got my first android tablet and I haven’t heard the synthesizer. What about its quality?

  9. peterdk permalink

    Try my app Mini Piano Lite to hear the standard midi sounds.

  10. This page still turns up high on google, when looking for android and midi. So I thought this might be useful: http://midisheetmusic.sourceforge.net/download.html

    It’s an open source implementation of a midi player, with visualisation by keyboard and sheet music. The code for android is free for download.

  11. tsukihuu permalink

    http://midisheetmusic.sourceforge.net/download.html
    this page can not open in my conputer. can you send me a copy of the code?

Trackbacks & Pingbacks

  1. Control MIDI with an Android device | CisforComputers

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS