release 0.1.15
[liba.git] / java / src / lpf.c
blob4c60ab7aabd8b8ef14e7ef43d97724e7e9e924fb
1 #include "a.h"
2 #include "a/lpf.h"
3 #include "liba_lpf.h"
5 #undef L
6 #define L Java_liba_lpf
7 static struct
9 jmethodID New;
10 jfieldID ctx;
11 } L = {NULL, NULL};
13 JNIEXPORT void JNICALL Java_liba_lpf_clinit(JNIEnv *Env, jclass Cls)
15 jclass Nbb = (*Env)->FindClass(Env, "Ljava/nio/ByteBuffer;");
16 L.New = (*Env)->GetStaticMethodID(Env, Nbb, "allocateDirect", "(I)Ljava/nio/ByteBuffer;");
17 L.ctx = (*Env)->GetFieldID(Env, Cls, "ctx", "Ljava/nio/ByteBuffer;");
20 JNIEXPORT void JNICALL Java_liba_lpf_init(JNIEnv *Env, jobject Obj, jdouble fc, jdouble ts)
22 jobject Ctx = (*Env)->CallObjectMethod(Env, Obj, L.New, (jint)sizeof(a_lpf));
23 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
24 (*Env)->SetObjectField(Env, Obj, L.ctx, Ctx);
25 a_lpf_init(ctx, A_LPF_GEN(fc, ts));
28 JNIEXPORT jdouble JNICALL Java_liba_lpf_alpha(JNIEnv *Env, jobject Obj)
30 jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
31 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
32 return ctx->alpha;
35 JNIEXPORT jdouble JNICALL Java_liba_lpf_output(JNIEnv *Env, jobject Obj)
37 jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
38 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
39 return ctx->output;
42 JNIEXPORT jobject JNICALL Java_liba_lpf_gen(JNIEnv *Env, jobject Obj, jdouble fc, jdouble ts)
44 jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
45 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
46 ctx->alpha = A_LPF_GEN(fc, ts);
47 return Obj;
50 JNIEXPORT jdouble JNICALL Java_liba_lpf_iter(JNIEnv *Env, jobject Obj, jdouble x)
52 jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
53 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
54 return a_lpf_iter(ctx, x);
57 JNIEXPORT jobject JNICALL Java_liba_lpf_zero(JNIEnv *Env, jobject Obj)
59 jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
60 a_lpf *ctx = (a_lpf *)(*Env)->GetDirectBufferAddress(Env, Ctx);
61 a_lpf_zero(ctx);
62 return Obj;