I'm very new to C++ and I'm working with the Superpowered FrequencyDomain example here: https://github.com/superpoweredSDK/Low-Latency-Android-Audio-iOS-Audio-Engine/blob/master/Examples_Android/FrequencyDomain/app/src/main/jni/FrequencyDomain.cpp
I want to continuously update a TextView with the loudest frequency being received from inside this while loop:
static bool audioProcessing(void * __unused clientdata, short int *audioInputOutput, int numberOfSamples, int __unused samplerate) {
SuperpoweredShortIntToFloat(audioInputOutput, inputBufferFloat, (unsigned int)numberOfSamples); // Converting the 16-bit integer samples to 32-bit floating point.
frequencyDomain->addInput(inputBufferFloat, numberOfSamples); // Input goes to the frequency domain.
// In the frequency domain we are working with 1024 magnitudes and phases for every channel (left, right), if the fft size is 2048.
while (frequencyDomain->timeDomainToFrequencyDomain(magnitudeLeft, magnitudeRight, phaseLeft, phaseRight)) {
I think I need to do something like this:
jclass classs = env->FindClass("com/superpowered/frequencydomain/MainActivity");
jmethodID method = env->GetMethodID(classs, "updateTextViewFromJNI","(I)V");
env->CallVoidMethod(thiz, method, myJavaInt);
but those are the only lines in a example C++ function which already has access to env and thiz:
void callJavaMethod(JNIEnv* env,jobject thiz) {...previous 3 lines...}
Calling a Java function like this:
public void updateTextViewFromJNI(int i) {
txtLoudestFreq.setText(Integer.toString(i));
}
I've been trying different ways to getting to JNIEnv and jobject, but I haven't succeeded yet. I see they're unused here:
extern "C" JNIEXPORT void Java_com_superpowered_frequencydomain_MainActivity_FrequencyDomain(JNIEnv * __unused javaEnvironment, jobject __unused obj, jint samplerate, jint buffersize)
but I'm not sure how to get access to them in:
audioProcessing
I've tried making them global. From what I've read, I'm trying to get a reference to them, but missing how to do it. What steps do I need to do in order to be able to call something like this:
env->CallVoidMethod(thiz, method, myJavaInt);
from inside audioProcessing? Thank you very much!