|
|
|
@ -17,6 +17,8 @@ |
|
|
|
|
|
|
|
|
|
struct fields_t { |
|
|
|
|
jfieldID context; |
|
|
|
|
jclass visual_class; |
|
|
|
|
jmethodID fft_method; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static fields_t fields; |
|
|
|
@ -41,11 +43,9 @@ FrankVisualizer *getCustomVisualizer(JNIEnv *env, jobject thiz) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fft_callback(JNIEnv *jniEnv, int8_t * arg, int samples) { |
|
|
|
|
jclass visual_class = jniEnv->FindClass(className); |
|
|
|
|
jmethodID fft_method = jniEnv->GetStaticMethodID(visual_class, "onFftCallback", "([B)V"); |
|
|
|
|
jbyteArray dataArray = jniEnv->NewByteArray(samples); |
|
|
|
|
jniEnv->SetByteArrayRegion(dataArray, 0, samples, arg); |
|
|
|
|
jniEnv->CallStaticVoidMethod(visual_class, fft_method, dataArray); |
|
|
|
|
jniEnv->CallStaticVoidMethod(fields.visual_class, fields.fft_method, dataArray); |
|
|
|
|
jniEnv->DeleteLocalRef(dataArray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -53,6 +53,9 @@ VISUALIZER_FUNC(int, nativeInitVisualizer) { |
|
|
|
|
setCustomVisualizer(env, thiz); |
|
|
|
|
FrankVisualizer *mVisualizer = getCustomVisualizer(env, thiz); |
|
|
|
|
if (!mVisualizer) return -2; |
|
|
|
|
jclass mVisualClass = env->FindClass(className); |
|
|
|
|
fields.visual_class = (jclass) env->NewGlobalRef(mVisualClass); |
|
|
|
|
fields.fft_method = env->GetStaticMethodID(fields.visual_class, "onFftCallback", "([B)V"); |
|
|
|
|
return mVisualizer->init_visualizer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -76,5 +79,6 @@ VISUALIZER_FUNC(void, nativeReleaseVisualizer) { |
|
|
|
|
if (!mVisualizer) return; |
|
|
|
|
mVisualizer->release_visualizer(); |
|
|
|
|
delete mVisualizer; |
|
|
|
|
env->DeleteGlobalRef(fields.visual_class); |
|
|
|
|
env->SetLongField(thiz, fields.context, 0); |
|
|
|
|
} |