Skip to content

shift0ogg/mididriver

 
 

Repository files navigation

Midi Driver

This branch (OpenSLES) contains a purely native version of the driver using OpenSLES. This is an attempt to resolve the choppy sound issue reported by smarek. Now merged to master.

I have added a jhindin branch to this repository which is a merge of jhindin/mididriver. He has made these changes:

  1. The source file tree has been rearranged to fit Android Studio/Gradle integration structure
  2. Linking with SoniVox library deferred to the launch time - in this way, there is no need to pull sonivox libraries from all potential platforms just to build the system

Android midi driver using Sonivox EAS library. The app and library are available here.

I have removed the event queue as per the comment by akdmia because it is not necessary. Contention is handled by using a mutex in the native code. I have only tested this with this app, not with an extended event stream. The app just has a couple of buttons that play a couple of piano notes when touched. I've added two more buttons that play and stop a midi file using the MediaPlayer to check that there is no interaction problem. Added a listener for sending initial midi messages when the midi driver has started. Removed the handler for the listener as the callback is not on a driver thread. This project may be compiled as a library by changing the setting in project.properties to android.library=true. The MainActivity.java source file will be moved to a temporary folder so it is not compiled into in the library jar file. I have made the changes in jhindin/mididriver without changing the project structure. Copies of the libsonivox.so library are no longer required.

To use this driver you need to:

  • Get and install the Android NDK toolkit.
  • Get the documentation and include files from android/platform_external_sonivox.
  • Adjust the ~jni/Application.mk to build the architecture(s) you want.
  • Don't build 64 bit versions as Google have included broken 64 bit versions of libsonivox.so in devices and at least one emulator.

Or you can just copy the libmidi.so file from here, but it has

Java_org_billthefarmer_mididriver_MidiDriver

embedded in the native method names.

The windows NDK toolkit doesn't appear to use anything other than standard windows shell commands and it's own tools, so you don't need Cygwin, despite what the docs say.

Methods

void start()  Start the driver. Call from onResume().

void stop()  Stop the driver. Call from onPause();

void addOnMidiStartListener(OnMidiStartListener l);

void queueEvent(byte[]) Send a midi message. This method now just
calls write()

Listener

void onMidiStart() This is called when the driver has started so
that program change messages, etc may be sent. Uses a handler so
it does not run on the driver thread.

Native Methods

int init()  Return buffer size in shorts, or 0 on failure.

int[] config()  Return a four element array of ints with part of
the EAS onfig:

  config[0] = pLibConfig->maxVoices;
  config[1] = pLibConfig->numChannels;
  config[2] = pLibConfig->sampleRate;
  config[3] = pLibConfig->mixBufferSize;

boolean write(byte buffer[])  Writes midi data to the Sonivox
synthesizer. The length of the array should be the exact length of
the message or messages. Returns true on success, false on
failure.

boolean shutdown()  Shut down the synthesizer. Returns true on
success, false on failure.

About

Android midi driver using Sonivox EAS library

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C 66.2%
  • C++ 22.6%
  • Java 10.0%
  • Makefile 1.2%