Any chance to use Android audio and MIDI using a standard library?

Is there a way to use a standard audio/MIDI library (low level) that can work both on the Processing for Android and Processing desktop versions?

Or what is the best (and easiest) way to use audio/MIDI on Processing for Android?
(if it’s possible). Any reference?

I made a few searches, but didn’t find too much.
Thank you in advance!

Hi @Algoritmarte!

the official Processing Sound library is designed to be fully compatible with both ‘normal’ Java Processing as well as Android mode. The library basically abstracts away from the audio input/output specifics of the different platforms, so any sketch you write for Java mode should run just the same on Android. The library documentation is here, you can install the library as usual through Processing’s Contribution Manager: Sound / Libraries /

(We’re actually working on a brand new release that should come out at the end of the month, if you’re interested to try out some experimental features you can also get a release preview from here: Release v2.4.0-preview · processing/processing-sound · GitHub)

I’m afraid the situation with MIDI is trickier, I’m not sure if there are any libraries that can handle MIDI on both desktops and Android…

Thanks! For the desktop version I usually use minim (and use only the low level functions, but with an audio output stream you can do whatever you want), so I must try the official library.

For the MIDI implementation, I suspect that scheduling/timing MIDI messages is not so easy/reliable; but beginning with a low level, limited basic set of functions for

  • enumerating the input/output available MIDI devices (description and number of channels) and selecting one of them
  • a sendRawMIDIMessage( byte data[ ] ) that sends a MIDI message as soon as possible
  • and a listener for receiveRawMIDIMessage( byte data[ ], long timestamp )

should be enough for a lot of applications even if the latency is bad (generative, algorithmic stuff for example). For the desktop version I usually use themidibus, which has a very basic set of functions.

Hi @Algoritmarte. Android MIDI and Java MIDI are different code bases and not compatible. So to my knowledge there isn’t a universal library that supports both interchangeably.
My audio library Pd4P3 does have sketches for both Android MIDI and Java MIDI. GitHub - robertesler/Pd4P3: A real-time audio synthesis library for Processing 3. Pd4P3 implements Pure Data's signal processing objects via Pd++ native code. Pd4P3 stands for "Pd++ for Processing 3".
If you really want to use the Processing sound you could just use the Android MIDI examples there. You can also look at Phil Burk’s examples GitHub - philburk/android-midisuite: Android MIDI test programs and examples. which are what I used as well.
In my experience Android MIDI is similar in concept to its pure Java counterpart but uses a different API. Since Android 13 I believe it also supports MIDI 2.0 but I haven’t used it yet.
Good luck!