I'm working on an Android Studio project that involves JNI to run some signal processing functions on arrays created in Java. I need to be able to feed C an array of double from Java, run the filter, and send Java back the array. The filtering function works fine in the Android environment via CMake. Conducting tests, I am able to get arrays of type double from C to Java with no issue. I have a function to send the array from Java to C. My problem is, I am not quite sure how to get that array to my filtering function to send it back to Java.
The method, public static native double addArray(double []arr) in java, is coded accordingly in my algorithm.c file:
jdouble JNICALL
Java_com_example_covid19_MainActivity_addArray(JNIEnv *env, jclass clazz, jdoubleArray jarr) {
static double dv[2890080];
static double y_fil[2890080];
jdouble *arr = (*env)->GetDoubleArrayElements(env, jarr, NULL);
double res=0;
int size = (*env)->GetArrayLength(env, jarr);
for(int i=0;i<size;i++)
dv[i] = arr[i];
(*env)->ReleaseDoubleArrayElements(env, jarr, arr, 0);
filtering(dv, y_fil);
return res;
}
At the point in the function above when I call filtering(dv, y_fil), if I was able to send the dv array back to Java, I would be golden. But sending an array back to Java requires a separate JNICALL. I'm perplexed from here and though I have seen many, many examples online of handling data from C to Java, I've not seen one that involves getting data from Java first. Any insight would be greatly appreciated.