@@ -19,6 +19,8 @@ struct java_context {
1919 jfieldID fid_height ;
2020 jmethodID fixSize ;
2121 jmethodID notifyCallbacks ;
22+ jint * pixels ;
23+ int pixelsize ;
2224 } typedef java_context_t ;
2325
2426static JavaVM * jvm ;
@@ -69,23 +71,14 @@ void error(JNIEnv * env, int exception_code, const char *inmsg, ...)
6971 (* env )-> DeleteLocalRef (env , cls );
7072}
7173
72- JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_init (JNIEnv * env , jobject obj ) {
74+ JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_init (JNIEnv * env , jobject obj , jstring path ) {
7375 (* env )-> GetJavaVM (env , & jvm );
7476 javaversion = (* env )-> GetVersion (env );
75- }
76-
77- JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeLoadPlugin (JNIEnv * env , jobject obj , jstring path ) {
7877 const char * npath = (* env )-> GetStringUTFChars (env , path , 0 );
7978 THROW (tsdr_loadplugin (& tsdr_instance , npath ));
8079 (* env )-> ReleaseStringUTFChars (env , path , npath );
8180}
8281
83- JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_pluginParams (JNIEnv * env , jobject obj , jstring params ) {
84- const char * nparams = (* env )-> GetStringUTFChars (env , params , 0 );
85- THROW (tsdr_pluginparams (& tsdr_instance , nparams ));
86- (* env )-> ReleaseStringUTFChars (env , params , nparams );
87- }
88-
8982JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setSampleRate (JNIEnv * env , jobject obj , jlong rate ) {
9083 THROW (tsdr_setsamplerate (& tsdr_instance , (uint32_t ) rate ));
9184}
@@ -107,27 +100,27 @@ void read_async(float *buf, int width, int height, void *ctx) {
107100 if (i_width != width || i_height != height ) {
108101 // fixSize(200, 200);
109102 (* env )-> CallVoidMethod (env , context -> obj , context -> fixSize , width , height );
103+
104+ context -> pixelsize = width * height ;
105+ context -> pixels = (jint * ) realloc ((void * ) context -> pixels , sizeof (jint ) * context -> pixelsize );
110106 }
111107
112- jintArray pixels_obj = (* env )-> GetObjectField (env , context -> obj , context -> fid_pixels );
113- jint * pixels = (* env )-> GetIntArrayElements (env ,pixels_obj ,0 );
114- jint * data = pixels ;
108+ jint * data = context -> pixels ;
115109
116110 int i ;
117- const int size = width * height ;
118- for (i = 0 ; i < size ; i ++ ) {
111+ for (i = 0 ; i < context -> pixelsize ; i ++ ) {
119112 const int col = (int ) (* (buf ++ ) * 255.0f );
120113 * (data ++ ) = col | (col << 8 ) | (col << 16 );
121114 }
122115
123116 // release elements
124- (* env )-> ReleaseIntArrayElements (env ,pixels_obj , pixels , 0 );
117+ (* env )-> SetIntArrayRegion (env , ( * env ) -> GetObjectField ( env , context -> obj , context -> fid_pixels ), 0 , context -> pixelsize , context -> pixels );
125118
126119 // notifyCallbacks();
127120 (* env )-> CallVoidMethod (env , context -> obj , context -> notifyCallbacks );
128121}
129122
130- JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeStart (JNIEnv * env , jobject obj ) {
123+ JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeStart (JNIEnv * env , jobject obj , jstring params ) {
131124
132125 java_context_t * context = (java_context_t * ) malloc (sizeof (java_context_t ));
133126
@@ -140,11 +133,22 @@ JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeStart (JNIEnv
140133 context -> fixSize = (* env )-> GetMethodID (env , context -> cls , "fixSize" , "(II)V" );
141134 context -> notifyCallbacks = (* env )-> GetMethodID (env , context -> cls , "notifyCallbacks" , "()V" );
142135
143- THROW (tsdr_readasync (& tsdr_instance , read_async , (void * ) context ));
136+ jint i_width = (* env )-> GetIntField (env , context -> obj , context -> fid_width );
137+ jint i_height = (* env )-> GetIntField (env , context -> obj , context -> fid_height );
138+
139+ context -> pixelsize = i_width * i_height ;
140+ context -> pixels = (jint * ) malloc (sizeof (jint ) * context -> pixelsize );
141+
142+ const char * nparams = (* env )-> GetStringUTFChars (env , params , 0 );
144143
144+ THROW (tsdr_readasync (& tsdr_instance , read_async , (void * ) context , nparams ));
145+
146+
147+ (* env )-> ReleaseStringUTFChars (env , params , nparams );
145148 (* env )-> DeleteGlobalRef (env , context -> obj );
146149 (* env )-> DeleteGlobalRef (env , context -> cls );
147150 free (context );
151+ free (context -> pixels );
148152}
149153
150154JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_stop (JNIEnv * env , jobject obj ) {
0 commit comments