1

I'm in the process of creating an app that involves playing music notes, and my presumption was that it should most likely (and simply) be done using MIDI. But I can't find any example of this being executed in Android Studio without some old GitHub libraries.

I know that Android natively supports MIDI and its playback, so perhaps the proper way to do this can be found in this android.com documentation, but I haven't found one actual tutorial demonstrating this so I can't quite put it all together.

As I'm aiming to use Kotlin, it being Google's recommendation, I did look for official Kotlin resources as well but while there is a YouTube video about MIDI from a Kotlin conference just a few weeks ago, it seems to use JDK libraries that aren't available in Android.

I planned on developing this app a long while ago, so any help is appreciated.

TLSO
  • 322
  • 3
  • 17
  • If you are talking about connecting to MIDI hardware, see: https://source.android.com/docs/core/audio/midi_test Otherwise if the "old GitHub libraries" are https://github.com/billthefarmer/mididriver and/or https://github.com/philburk/android-midisuite have been updated in the past year or two. An old project to check is https://github.com/google/music-synthesizer-for-android – Morrison Chang Jun 03 '23 at 16:41
  • Do realize that Android's real-time audio history has been challenging at best, resulting in a library like [Oboe](https://github.com/google/oboe) to avoid specific platform/device issues. https://developer.android.com/games/sdk/oboe – Morrison Chang Jun 03 '23 at 16:56
  • @MorrisonChang I mostly refer to internal MIDI, as in generating a note stream, either in real-time or from an existing MIDI file, and sending it to the internal Android player or possibly to a more advanced player which can play samples. So this can't be done solely with the existing Android SDK? – TLSO Jun 03 '23 at 19:36
  • If you want to play a MIDI file, the list of supported types are show on the [Media Formats page](https://developer.android.com/guide/topics/media/media-formats). If you want to custom/dynamically generate then [Android 6.0 (Marshmallow): How to play midi notes?](https://stackoverflow.com/q/36193250/295004) is appropriate. – Morrison Chang Jun 03 '23 at 20:04
  • @MorrisonChang This earlier question is one of the few results that come up in search so I've actually read it, but it also refers to the same mididriver GitHub project. Because Android Studio does have an official MIDI library and the android.com documentation page defines them, it seems logical the SDK would provide a way of doing this simple task – even if the documentation is not clear enough for me without an actual tutorial. – TLSO Jun 03 '23 at 20:13
  • Your [doc link](https://developer.android.com/reference/kotlin/android/media/midi/package-summary) is for MIDI device connectivity for Android. Android requires some hoops to play MIDI notes with the existing built-in synthesizer through the audio output of Android. Realize that the SONiVOX dates back to Android 1.0 and will never be updated. Modern audio apps should be using Oboe (OpenSL ES/AAudio) due to a lack of [audio-latency requirements](https://source.android.com/docs/core/audio/latency/latency) in older Android. See vid: [Android high-performance audio](https://youtu.be/F2ZDp-eNrh4) – Morrison Chang Jun 03 '23 at 20:26
  • @MorrisonChang Doesn't this part refer to an ability to internally invoke a sound engine? "... virtual (inter-app) transports"; "Support creation of virtual MIDI devices that can be connected to other devices. An example might be a synthesizer app that can be controlled by a composing app". Or is the problem about invoking the internal sound engine for MIDI (the SONiVOX I presume)? Frankly, if I could have my app use higher quality soundfonts it would have been even better but that: a. Still requires understanding MIDI usage and b. Possibly even more complicated. – TLSO Jun 03 '23 at 22:51
  • @MorrisonChang Hey Morrison, I got that MIDIdriver library working, but I still have some questions about the other libraries. I can't see in neither Oboe, MIDIsuite or even AMidi with NDK any reference to invoking a native synthesizer. I suppose Google isn't interested in providing any simple access to General MIDI synthesis other than when playing actual MIDI files. [This library](https://github.com/LeffelMania/android-midi-lib) supports saving MIDI files, but it mentions real-time playback doesn't produce audio. I suppose creating a temporary file for any event is an (inefficient?) option? – TLSO Jun 05 '23 at 11:06
  • @MorrisonChang And as I didn't delve into MIDIdriver I don't quite understand – is it a standalone implementation of the SONiVOX synthesizer or does it just provide the "hoops" required to play real-time MIDI events internally, which in Android by default uses SONiVOX? – TLSO Jun 05 '23 at 11:10

0 Answers0