how do i pass void *data from oboe onAudioReady c++ function to kotlin main activity

55 views
Skip to first unread message

nivilwilsonp

unread,
Feb 9, 2023, 1:52:58 AM2/9/23
to android-ndk
//code is here


DataCallbackResult AudioEngine::onAudioReady(AudioStream *audioStream, void *audioData, int32_t numFrames) {
if (audioStream->getState() == StreamState::Started) {




auto data=static_cast<char*>(audioData);
waveFIleEngine.writeAudioData(data,numFrames*4);
auto sData= static_cast<short*>(audioData);

JNIEnv *env=AttachJava();
jclass cls=env->FindClass("com/universe/studio/MainActivity$AudioSetter");
jmethodID mid1=env->GetMethodID(cls,"setAudioData1","()V");
jmethodID mid2=env->GetMethodID(cls,"<init>", "()V");







env->SetShortArrayRegion(aData, 0, numFrames, reinterpret_cast<const jshort *>(sData));
jvm->DetachCurrentThread();


















}

return DataCallbackResult::Continue;
}

Phil Burk

unread,
Apr 12, 2023, 2:12:34 PM4/12/23
to andro...@googlegroups.com
You could pass the data from the callback to Kotlin through a ByteBuffer acting as a FIFO.
That will let you use a low-latency callback.

Another approach is to just setup Oboe with no callback and then use blocking read or write through JNI.
That is easier but may have higher latency.

Phil Burk



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c5051314-b77a-46cd-a0c5-78900fa1c615n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages