build: reorg jni files
This commit is contained in:
43
app/src/main/cpp/jni_lockstep.cpp
Normal file
43
app/src/main/cpp/jni_lockstep.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "PlaybackEngine.h"
|
||||
#include <jni.h>
|
||||
#include <oboe/Oboe.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* Creates the audio engine
|
||||
*
|
||||
* @return a pointer to the audio engine. This should be passed to other methods
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_at_lockstep_pb_PlaybackEngine_native_1createEngine(
|
||||
JNIEnv *env,
|
||||
jclass /*unused*/, jstring filesDir, jint resid) {
|
||||
const char* filesDirTemp = env->GetStringUTFChars(filesDir, NULL);
|
||||
std::string filesDirString(filesDirTemp);
|
||||
env->ReleaseStringUTFChars(filesDir, filesDirTemp);
|
||||
|
||||
// We use std::nothrow so `new` returns a nullptr if the engine creation fails
|
||||
auto *engine = new(std::nothrow) PlaybackEngine(filesDirString, resid);
|
||||
return reinterpret_cast<jlong>(engine);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_at_lockstep_pb_PlaybackEngine_native_1deleteEngine(
|
||||
JNIEnv *env,
|
||||
jclass,
|
||||
jlong engineHandle) {
|
||||
|
||||
delete reinterpret_cast<PlaybackEngine *>(engineHandle);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_at_lockstep_pb_PlaybackEngine_native_1setDefaultStreamValues(JNIEnv *env,
|
||||
jclass type,
|
||||
jint sampleRate,
|
||||
jint framesPerBurst) {
|
||||
oboe::DefaultStreamValues::SampleRate = (int32_t) sampleRate;
|
||||
oboe::DefaultStreamValues::FramesPerBurst = (int32_t) framesPerBurst;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user