Chris@37
|
1 /*
|
Chris@37
|
2 jVamp
|
Chris@37
|
3
|
Chris@37
|
4 A Java host interface for Vamp audio analysis plugins
|
Chris@37
|
5
|
Chris@37
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@37
|
7 Copyright 2012 Chris Cannam and QMUL.
|
Chris@37
|
8
|
Chris@37
|
9 Permission is hereby granted, free of charge, to any person
|
Chris@37
|
10 obtaining a copy of this software and associated documentation
|
Chris@37
|
11 files (the "Software"), to deal in the Software without
|
Chris@37
|
12 restriction, including without limitation the rights to use, copy,
|
Chris@37
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@37
|
14 of the Software, and to permit persons to whom the Software is
|
Chris@37
|
15 furnished to do so, subject to the following conditions:
|
Chris@37
|
16
|
Chris@37
|
17 The above copyright notice and this permission notice shall be
|
Chris@37
|
18 included in all copies or substantial portions of the Software.
|
Chris@37
|
19
|
Chris@37
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@37
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@37
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@37
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@37
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@37
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@37
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@37
|
27
|
Chris@37
|
28 Except as contained in this notice, the names of the Centre for
|
Chris@37
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
Chris@37
|
30 shall not be used in advertising or otherwise to promote the sale,
|
Chris@37
|
31 use or other dealings in this Software without prior written
|
Chris@37
|
32 authorization.
|
Chris@37
|
33 */
|
Chris@37
|
34
|
Chris@20
|
35 #include "org_vamp_plugins_RealTime.h"
|
Chris@20
|
36
|
Chris@20
|
37 #include <vamp-hostsdk/RealTime.h>
|
Chris@20
|
38
|
Chris@20
|
39 #include "handle.h"
|
Chris@20
|
40
|
Chris@20
|
41 using Vamp::RealTime;
|
Chris@20
|
42 using std::string;
|
Chris@20
|
43
|
Chris@30
|
44 JNIEXPORT void JNICALL
|
Chris@20
|
45 Java_org_vamp_1plugins_RealTime_dispose(JNIEnv *env, jobject obj)
|
Chris@20
|
46 {
|
Chris@20
|
47 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
48 setHandle<RealTime>(env, obj, 0);
|
Chris@20
|
49 delete rt;
|
Chris@20
|
50 }
|
Chris@20
|
51
|
Chris@30
|
52 JNIEXPORT jint JNICALL
|
Chris@20
|
53 Java_org_vamp_1plugins_RealTime_sec(JNIEnv *env, jobject obj)
|
Chris@20
|
54 {
|
Chris@20
|
55 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
56 return rt->sec;
|
Chris@20
|
57 }
|
Chris@20
|
58
|
Chris@30
|
59 JNIEXPORT jint JNICALL
|
Chris@20
|
60 Java_org_vamp_1plugins_RealTime_nsec(JNIEnv *env, jobject obj)
|
Chris@20
|
61 {
|
Chris@20
|
62 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
63 return rt->nsec;
|
Chris@20
|
64 }
|
Chris@20
|
65
|
Chris@30
|
66 JNIEXPORT jint JNICALL
|
Chris@20
|
67 Java_org_vamp_1plugins_RealTime_usec(JNIEnv *env, jobject obj)
|
Chris@20
|
68 {
|
Chris@20
|
69 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
70 return rt->usec();
|
Chris@20
|
71 }
|
Chris@20
|
72
|
Chris@30
|
73 JNIEXPORT jint JNICALL
|
Chris@20
|
74 Java_org_vamp_1plugins_RealTime_msec(JNIEnv *env, jobject obj)
|
Chris@20
|
75 {
|
Chris@20
|
76 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
77 return rt->msec();
|
Chris@20
|
78 }
|
Chris@20
|
79
|
Chris@30
|
80 JNIEXPORT jstring JNICALL
|
Chris@20
|
81 Java_org_vamp_1plugins_RealTime_toString(JNIEnv *env, jobject obj)
|
Chris@20
|
82 {
|
Chris@20
|
83 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
84 return env->NewStringUTF(rt->toString().c_str());
|
Chris@20
|
85 }
|
Chris@20
|
86
|
Chris@30
|
87 JNIEXPORT jstring JNICALL
|
Chris@20
|
88 Java_org_vamp_1plugins_RealTime_toText(JNIEnv *env, jobject obj)
|
Chris@20
|
89 {
|
Chris@20
|
90 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@20
|
91 return env->NewStringUTF(rt->toText().c_str());
|
Chris@20
|
92 }
|
Chris@20
|
93
|
Chris@30
|
94 JNIEXPORT jobject JNICALL
|
Chris@20
|
95 Java_org_vamp_1plugins_RealTime_fromSeconds(JNIEnv *env, jclass cls, jdouble s)
|
Chris@20
|
96 {
|
Chris@21
|
97 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
98 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@21
|
99 RealTime rt = RealTime::fromSeconds(s);
|
Chris@21
|
100 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@20
|
101 }
|
Chris@20
|
102
|
Chris@30
|
103 JNIEXPORT jobject JNICALL
|
Chris@30
|
104 Java_org_vamp_1plugins_RealTime_fromMilliseconds(JNIEnv *env, jclass cls, jint ms)
|
Chris@20
|
105 {
|
Chris@21
|
106 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
107 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@21
|
108 RealTime rt = RealTime::fromMilliseconds(ms);
|
Chris@21
|
109 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@20
|
110 }
|
Chris@20
|
111
|
Chris@30
|
112 JNIEXPORT jobject JNICALL
|
Chris@30
|
113 Java_org_vamp_1plugins_RealTime_frame2RealTime(JNIEnv *env, jclass cls, jlong frame, jint sampleRate)
|
Chris@21
|
114 {
|
Chris@21
|
115 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
116 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@21
|
117 RealTime rt = RealTime::frame2RealTime(frame, sampleRate);
|
Chris@21
|
118 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@21
|
119 }
|
Chris@20
|
120
|
Chris@30
|
121 JNIEXPORT jlong JNICALL
|
Chris@30
|
122 Java_org_vamp_1plugins_RealTime_realTime2Frame(JNIEnv *env, jclass cls, jobject obj, jint sampleRate)
|
Chris@21
|
123 {
|
Chris@21
|
124 RealTime *rt = getHandle<RealTime>(env, obj);
|
Chris@21
|
125 return RealTime::realTime2Frame(*rt, sampleRate);
|
Chris@21
|
126 }
|
Chris@20
|
127
|
Chris@30
|
128 JNIEXPORT void JNICALL
|
Chris@30
|
129 Java_org_vamp_1plugins_RealTime_initialise(JNIEnv *env, jobject obj, jint sec, jint nsec)
|
Chris@21
|
130 {
|
Chris@21
|
131 RealTime *rt = new RealTime(sec, nsec);
|
Chris@21
|
132 setHandle(env, obj, rt);
|
Chris@21
|
133 }
|
Chris@21
|
134
|
Chris@21
|
135
|
Chris@21
|
136
|