Skip to content

Commit

Permalink
Covert jni to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
billthefarmer committed Dec 7, 2014
1 parent dd4751e commit 8620610
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
Binary file modified bin/classes.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := midi
LOCAL_SRC_FILES := midi.c
LOCAL_SRC_FILES := midi.cpp
# for EAS midi
LOCAL_LDLIBS += -lsonivox

Expand Down
30 changes: 16 additions & 14 deletions jni/midi.c → jni/midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <jni.h>

#include "org_billthefarmer_mididriver_MidiDriver.h"

// for EAS midi
#include "eas.h"
#include "eas_reverb.h"
Expand All @@ -40,7 +42,7 @@ static EAS_HANDLE midiHandle;
// init EAS midi
jint
Java_org_billthefarmer_mididriver_MidiDriver_init(JNIEnv *env,
jobject clazz)
jobject obj)
{
EAS_RESULT result;

Expand Down Expand Up @@ -77,31 +79,31 @@ Java_org_billthefarmer_mididriver_MidiDriver_init(JNIEnv *env,
// midi config
jintArray
Java_org_billthefarmer_mididriver_MidiDriver_config(JNIEnv *env,
jobject clazz)
jobject obj)
{
jboolean isCopy;

if (pLibConfig == NULL)
return NULL;

jintArray configArray = (*env)->NewIntArray(env, 4);
jintArray configArray = env->NewIntArray(4);

jint *config = (*env)->GetIntArrayElements(env, configArray, &isCopy);
jint *config = env->GetIntArrayElements(configArray, &isCopy);

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

(*env)->ReleaseIntArrayElements(env, configArray, config, 0);
env->ReleaseIntArrayElements(configArray, config, 0);

return configArray;
}

// midi render
jint
Java_org_billthefarmer_mididriver_MidiDriver_render(JNIEnv *env,
jobject clazz,
jobject obj,
jshortArray shortArray)
{
jboolean isCopy;
Expand All @@ -120,9 +122,9 @@ Java_org_billthefarmer_mididriver_MidiDriver_render(JNIEnv *env,
return 0;

buffer =
(EAS_PCM *)(*env)->GetShortArrayElements(env, shortArray, &isCopy);
(EAS_PCM *)env->GetShortArrayElements(shortArray, &isCopy);

size = (*env)->GetArrayLength(env, shortArray);
size = env->GetArrayLength(shortArray);

count = 0;
while (count < size)
Expand All @@ -135,15 +137,15 @@ Java_org_billthefarmer_mididriver_MidiDriver_render(JNIEnv *env,
count += numGenerated * pLibConfig->numChannels;
}

(*env)->ReleaseShortArrayElements(env, shortArray, buffer, 0);
env->ReleaseShortArrayElements(shortArray, buffer, 0);

return count;
}

// midi write
jboolean
Java_org_billthefarmer_mididriver_MidiDriver_write(JNIEnv *env,
jobject clazz,
jobject obj,
jbyteArray byteArray)
{
jboolean isCopy;
Expand All @@ -154,12 +156,12 @@ Java_org_billthefarmer_mididriver_MidiDriver_write(JNIEnv *env,
if (pEASData == NULL || midiHandle == NULL)
return JNI_FALSE;

buf = (EAS_U8 *)(*env)->GetByteArrayElements(env, byteArray, &isCopy);
length = (*env)->GetArrayLength(env, byteArray);
buf = (EAS_U8 *)env->GetByteArrayElements(byteArray, &isCopy);
length = env->GetArrayLength(byteArray);

result = EAS_WriteMIDIStream(pEASData, midiHandle, buf, length);

(*env)->ReleaseByteArrayElements(env, byteArray, buf, 0);
env->ReleaseByteArrayElements(byteArray, (jbyte *)buf, 0);

if (result != EAS_SUCCESS)
return JNI_FALSE;
Expand All @@ -170,7 +172,7 @@ Java_org_billthefarmer_mididriver_MidiDriver_write(JNIEnv *env,
// shutdown EAS midi
jboolean
Java_org_billthefarmer_mididriver_MidiDriver_shutdown(JNIEnv *env,
jobject clazz)
jobject obj)
{
EAS_RESULT result;

Expand Down
57 changes: 57 additions & 0 deletions jni/org_billthefarmer_mididriver_MidiDriver.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified libs/mips/libmidi.so
Binary file not shown.
Binary file modified libs/x86/libmidi.so
Binary file not shown.

0 comments on commit 8620610

Please sign in to comment.