Skip to content

Commit ba63f74

Browse files
committed
Animation
1 parent 654e233 commit ba63f74

11 files changed

Lines changed: 226 additions & 12 deletions

File tree

JavaGUI/jni/TSDRLibraryNDK.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void error_translate (int exception_code, char * exceptionclass) {
3131
case TSDR_WRONG_WIDTHHEIGHT:
3232
strcpy(exceptionclass, "martin/tempest/core/exceptions/TSDRWrongWidthHeightException");
3333
return;
34+
case TSDR_ALREADY_RUNNING:
35+
strcpy(exceptionclass, "martin/tempest/core/exceptions/TSDRAlreadyRunningException");
36+
return;
3437
default:
3538
strcpy(exceptionclass, "java/lang/Exception");
3639
return;
@@ -117,7 +120,7 @@ void read_async(float *buf, int width, int height, void *ctx) {
117120
(*env)->CallVoidMethod(env, context->obj, notifyCallbacks);
118121
}
119122

120-
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_start (JNIEnv * env, jobject obj) {
123+
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_nativeStart (JNIEnv * env, jobject obj) {
121124

122125
java_context_t * context = (java_context_t *) malloc(sizeof(java_context_t));
123126
context->obj = (*env)->NewGlobalRef(env, obj);

JavaGUI/jni/TSDRLibraryNDK.h

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaGUI/jni/include/TSDRCodes.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _TSDRCodes
2+
#define _TSDRCodes
3+
4+
#define TSDR_OK (0)
5+
#define TSDR_ERR_PLUGIN (1)
6+
#define TSDR_WRONG_WIDTHHEIGHT (2)
7+
#define TSDR_ALREADY_RUNNING (3)
8+
#define TSDR_NOT_IMPLEMENTED (404)
9+
10+
#endif

JavaGUI/jni/include/TSDRLibrary.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef _TSDRLibrary
2+
#define _TSDRLibrary
3+
4+
#include <stdint.h>
5+
6+
struct tsdr_lib {
7+
void * plugin;
8+
uint32_t samplerate;
9+
int width;
10+
int height;
11+
float vf;
12+
float hf;
13+
volatile int running;
14+
} typedef tsdr_lib_t;
15+
16+
typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx);
17+
18+
int tsdr_loadplugin(tsdr_lib_t * tsdr, char * filepath);
19+
int tsdr_pluginparams(tsdr_lib_t * tsdr, char * params);
20+
int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate);
21+
int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq);
22+
int tsdr_stop(tsdr_lib_t * tsdr);
23+
int tsdr_setgain(tsdr_lib_t * tsdr, float gain);
24+
int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void *ctx);
25+
int tsdr_unloadplugin(tsdr_lib_t * tsdr);
26+
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height);
27+
int tsdr_setvfreq(tsdr_lib_t * tsdr, float freq);
28+
int tsdr_sethfreq(tsdr_lib_t * tsdr, float freq);
29+
30+
#endif

JavaGUI/src/martin/tempest/Main.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,22 @@ public Main() throws TSDRException {
3636
TSDRLibrary sdrlib = new TSDRLibrary(WIDTH, HEIGHT);
3737
sdrlib.loadSource(TSDRLibrary.getAllSources()[0]);
3838
sdrlib.registerFrameReadyCallback(this);
39-
sdrlib.start();
40-
39+
sdrlib.startAsync();
4140
}
4241

4342
@Override
4443
public void onFrameReady(TSDRLibrary lib, BufferedImage frame) {
4544
viz.drawImage(frame);
4645
}
4746

47+
@Override
48+
public void onException(TSDRLibrary lib, Exception e) {
49+
e.printStackTrace();
50+
}
51+
52+
@Override
53+
public void onClosed(TSDRLibrary lib) {
54+
System.out.println("Closed");
55+
}
56+
4857
}

JavaGUI/src/martin/tempest/core/TSDRLibrary.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public TSDRLibrary(int width, int height) throws TSDRException {
136136
public native void pluginParams(String params) throws TSDRException;
137137
public native void setSampleRate(long rate) throws TSDRException;
138138
public native void setBaseFreq(long freq) throws TSDRException;
139-
public native void start() throws TSDRException;
139+
private native void nativeStart() throws TSDRException;
140140
public native void stop() throws TSDRException;
141141
public native void setGain(float gain) throws TSDRException;
142142
public native void unloadPlugin() throws TSDRException;
@@ -148,6 +148,19 @@ public void loadSource(final TSDRSource plugin) throws TSDRException {
148148
nativeLoadPlugin(extractLibrary(plugin.libname).getAbsolutePath());
149149
}
150150

151+
public void startAsync() {
152+
new Thread() {
153+
public void run() {
154+
try {
155+
nativeStart();
156+
} catch (TSDRException e) {
157+
for (final FrameReadyCallback callback : callbacks) callback.onException(TSDRLibrary.this, e);
158+
}
159+
for (final FrameReadyCallback callback : callbacks) callback.onClosed(TSDRLibrary.this);
160+
};
161+
}.start();
162+
}
163+
151164
public static TSDRSource[] getAllSources() {
152165
return PLUGINS;
153166
}
@@ -167,6 +180,8 @@ protected void finalize() throws Throwable {
167180

168181
public interface FrameReadyCallback {
169182
void onFrameReady(final TSDRLibrary lib, final BufferedImage frame);
183+
void onException(final TSDRLibrary lib, final Exception e);
184+
void onClosed(final TSDRLibrary lib);
170185
}
171186

172187
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package martin.tempest.core.exceptions;
2+
3+
public class TSDRAlreadyRunningException extends TSDRException {
4+
5+
private static final long serialVersionUID = 5365909402344178885L;
6+
7+
public TSDRAlreadyRunningException(final Exception e) {
8+
super(e);
9+
}
10+
11+
public TSDRAlreadyRunningException(final String msg) {
12+
super(msg);
13+
}
14+
}

TSDRPlugin_RawFile/src/TSDRCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define TSDR_OK (0)
55
#define TSDR_ERR_PLUGIN (1)
66
#define TSDR_WRONG_WIDTHHEIGHT (2)
7+
#define TSDR_ALREADY_RUNNING (3)
78
#define TSDR_NOT_IMPLEMENTED (404)
89

910
#endif

TempestSDR/src/TSDRLibrary.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define MAX_ARR_SIZE (4000*4000)
1616

1717
int tsdr_loadplugin(tsdr_lib_t * tsdr, char * filepath) {
18+
tsdr->running = 0;
1819
tsdr->plugin = malloc(sizeof(pluginsource_t));
1920
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
2021
return tsdrplug_load(plugin, filepath);
@@ -44,6 +45,7 @@ int tsdr_unloadplugin(tsdr_lib_t * tsdr) {
4445

4546
int tsdr_stop(tsdr_lib_t * tsdr) {
4647
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
48+
tsdr->running = 0;
4749
return plugin->tsdrplugin_stop();
4850
}
4951

@@ -53,6 +55,10 @@ int tsdr_setgain(tsdr_lib_t * tsdr, float gain) {
5355
}
5456

5557
int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void *ctx) {
58+
if (tsdr->running)
59+
return TSDR_ALREADY_RUNNING;
60+
tsdr->running = 1;
61+
5662
const int width = tsdr->width;
5763
const int height = tsdr->height;
5864
const int size = width * height;
@@ -62,16 +68,20 @@ int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void *ctx) {
6268

6369
float * buffer = (float *) malloc(sizeof(float) * size);
6470

65-
int i;
66-
for (i = 0; i < size; i++) {
67-
const int x = i % width;
68-
const int y = i / width;
71+
uint32_t frames = 0;
72+
while (tsdr->running) {
73+
frames++;
74+
int i;
75+
for (i = 0; i < size; i++) {
76+
const int x = i % width;
77+
const int y = ((i / width) + frames) % height;
6978

70-
const float rat = (x > width/2) ? (y / (float) height) : (1.0f - y / (float) height);
71-
buffer[i] = rat;
72-
}
79+
const float rat = (x > width/2) ? (y / (float) height) : (1.0f - y / (float) height);
80+
buffer[i] = rat;
81+
}
7382

74-
cb(buffer, width, height, ctx);
83+
cb(buffer, width, height, ctx);
84+
}
7585

7686
free(buffer);
7787
return TSDR_OK;

TempestSDR/src/include/TSDRCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define TSDR_OK (0)
55
#define TSDR_ERR_PLUGIN (1)
66
#define TSDR_WRONG_WIDTHHEIGHT (2)
7+
#define TSDR_ALREADY_RUNNING (3)
78
#define TSDR_NOT_IMPLEMENTED (404)
89

910
#endif

0 commit comments

Comments
 (0)