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@49
|
39 #include "getset.h"
|
Chris@20
|
40
|
Chris@20
|
41 using Vamp::RealTime;
|
Chris@20
|
42 using std::string;
|
Chris@20
|
43
|
Chris@30
|
44 JNIEXPORT jint JNICALL
|
Chris@20
|
45 Java_org_vamp_1plugins_RealTime_sec(JNIEnv *env, jobject obj)
|
Chris@20
|
46 {
|
Chris@49
|
47 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
48 return rt.sec;
|
Chris@20
|
49 }
|
Chris@20
|
50
|
Chris@30
|
51 JNIEXPORT jint JNICALL
|
Chris@20
|
52 Java_org_vamp_1plugins_RealTime_nsec(JNIEnv *env, jobject obj)
|
Chris@20
|
53 {
|
Chris@49
|
54 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
55 return rt.nsec;
|
Chris@20
|
56 }
|
Chris@20
|
57
|
Chris@30
|
58 JNIEXPORT jint JNICALL
|
Chris@20
|
59 Java_org_vamp_1plugins_RealTime_usec(JNIEnv *env, jobject obj)
|
Chris@20
|
60 {
|
Chris@49
|
61 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
62 return rt.usec();
|
Chris@20
|
63 }
|
Chris@20
|
64
|
Chris@30
|
65 JNIEXPORT jint JNICALL
|
Chris@20
|
66 Java_org_vamp_1plugins_RealTime_msec(JNIEnv *env, jobject obj)
|
Chris@20
|
67 {
|
Chris@49
|
68 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
69 return rt.msec();
|
Chris@20
|
70 }
|
Chris@20
|
71
|
Chris@30
|
72 JNIEXPORT jstring JNICALL
|
Chris@20
|
73 Java_org_vamp_1plugins_RealTime_toString(JNIEnv *env, jobject obj)
|
Chris@20
|
74 {
|
Chris@49
|
75 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
76 return env->NewStringUTF(rt.toString().c_str());
|
Chris@20
|
77 }
|
Chris@20
|
78
|
Chris@30
|
79 JNIEXPORT jstring JNICALL
|
Chris@20
|
80 Java_org_vamp_1plugins_RealTime_toText(JNIEnv *env, jobject obj)
|
Chris@20
|
81 {
|
Chris@49
|
82 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
83 return env->NewStringUTF(rt.toText().c_str());
|
Chris@20
|
84 }
|
Chris@20
|
85
|
Chris@30
|
86 JNIEXPORT jobject JNICALL
|
Chris@20
|
87 Java_org_vamp_1plugins_RealTime_fromSeconds(JNIEnv *env, jclass cls, jdouble s)
|
Chris@20
|
88 {
|
Chris@21
|
89 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
90 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@21
|
91 RealTime rt = RealTime::fromSeconds(s);
|
Chris@21
|
92 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@20
|
93 }
|
Chris@20
|
94
|
Chris@30
|
95 JNIEXPORT jobject JNICALL
|
Chris@30
|
96 Java_org_vamp_1plugins_RealTime_fromMilliseconds(JNIEnv *env, jclass cls, jint ms)
|
Chris@20
|
97 {
|
Chris@21
|
98 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
99 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@21
|
100 RealTime rt = RealTime::fromMilliseconds(ms);
|
Chris@21
|
101 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@20
|
102 }
|
Chris@20
|
103
|
Chris@30
|
104 JNIEXPORT jobject JNICALL
|
Chris@30
|
105 Java_org_vamp_1plugins_RealTime_frame2RealTime(JNIEnv *env, jclass cls, jlong frame, jint sampleRate)
|
Chris@21
|
106 {
|
Chris@21
|
107 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
|
Chris@21
|
108 jmethodID rtCtor = env->GetMethodID(rtClass, "<init>", "(II)V");
|
Chris@52
|
109 RealTime rt = RealTime::frame2RealTime(long(frame), sampleRate);
|
Chris@21
|
110 return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec);
|
Chris@21
|
111 }
|
Chris@20
|
112
|
Chris@30
|
113 JNIEXPORT jlong JNICALL
|
Chris@30
|
114 Java_org_vamp_1plugins_RealTime_realTime2Frame(JNIEnv *env, jclass cls, jobject obj, jint sampleRate)
|
Chris@21
|
115 {
|
Chris@49
|
116 RealTime rt = getRealTime(env, obj);
|
Chris@49
|
117 return RealTime::realTime2Frame(rt, sampleRate);
|
Chris@21
|
118 }
|
Chris@20
|
119
|
Chris@30
|
120 JNIEXPORT void JNICALL
|
Chris@30
|
121 Java_org_vamp_1plugins_RealTime_initialise(JNIEnv *env, jobject obj, jint sec, jint nsec)
|
Chris@21
|
122 {
|
Chris@49
|
123 setIntField(env, obj, "m_s", sec);
|
Chris@49
|
124 setIntField(env, obj, "m_n", nsec);
|
Chris@21
|
125 }
|
Chris@21
|
126
|