[DEV] 2.4 tools

This commit is contained in:
2015-09-19 10:52:26 +02:00
commit b6ae08bd22
945 changed files with 186828 additions and 0 deletions

47
java/cpp_version/Makefile Normal file
View File

@@ -0,0 +1,47 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
TOP=../..
DIRNAME=java/cpp_version
FILES = Makefile Makefile.version
BUILD_DIRS=cstr
NEED_JAVA=true
ALL = .sub_directories .javalib
include $(TOP)/config/common_make_rules
-include Makefile.version

View File

@@ -0,0 +1,42 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
## Suplimental make information for this version
CODE_VERSION=cpp
LOCAL_JAVA_CLASS_LIBRARY=$(TOP)/lib/est_$(CODE_VERSION).jar
LOCAL_JAVA_CLASSPATH=$(EST_HOME)/speech_tools/lib/est_$(CODE_VERSION).jar
JAVA_TOP_PACK=cstr
LOCAL_JAVA_ROOT=$(TOP)/java/$(CODE_VERSION)_version_build

View File

@@ -0,0 +1,51 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
TOP=../../..
DIRNAME=java/cpp_version/cstr
ALL_DIRS = est
BUILD_DIRS = awt est util testPrograms
NEED_JAVA = true
FILES = Makefile
ALL = .sub_directories
-include ../../../Makefile.version
include $(TOP)/config/common_make_rules

View File

@@ -0,0 +1,278 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Features. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Features.h"
#include "EST_Features.h"
static jclass features_class;
static jmethodID features_cons;
static jclass string_class;
static jclass float_class;
static jmethodID float_cons;
static jclass int_class;
static jmethodID int_cons;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Features_initialise_1cpp (JNIEnv *env, jclass myclass)
{
features_class = (jclass)env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
features_cons = env->GetMethodID(features_class, "<init>", "(J)V");
if (!features_cons)
{
printf("can't find features_cons!\n");
return 0;
}
string_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/String"));
float_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Float"));
float_cons = env->GetMethodID(float_class, "<init>", "(F)V");
if (!float_cons)
{
printf("can't find float_cons!\n");
return 0;
}
int_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Integer"));
int_cons = env->GetMethodID(int_class, "<init>", "(I)V");
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Features_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Features_create_1cpp_1features(JNIEnv *env,
jobject self,
jlong handle
)
{
EST_Features *features = (handle==0L
? (new EST_Features)
: (EST_Features *)handle
);
// printf("create features %p\n", features);
env->SetLongField(self, handle_field, (jlong)features);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Features_destroy_1cpp_1features (JNIEnv *env, jobject self)
{
EST_Features *features = (EST_Features *) env->GetLongField(self, handle_field);
// printf("destroy features %p\n", features);
delete features;
return 1;
}
JNIEXPORT jobjectArray JNICALL
Java_cstr_est_Features_cpp_1featureNames (JNIEnv *env, jobject self)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
int n;
EST_Features::Entries p;
n=0;
for (p.begin(*f); p != 0; ++p)
n++;
jobjectArray names = env->NewObjectArray(n, string_class, NULL);
p.beginning();
for(int i=0; i<n; i++)
{
jstring fn = env->NewStringUTF(p->k);
env->SetObjectArrayElement(names, i, fn);
++p;
}
return names;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Features_cpp_1getS(JNIEnv *env,
jobject self,
jstring jname,
jstring jdef)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
EST_Val def;
const EST_Val &val = f->val_path(name, def);
env->ReleaseStringUTFChars(jname, name);
if (&def == &val)
return jdef;
return env->NewStringUTF(val.S());
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Features_cpp_1getF(JNIEnv *env,
jobject self,
jstring jname,
jfloat def)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
float val = f->F(name, def);
env->ReleaseStringUTFChars(jname, name);
return val;
}
JNIEXPORT jobject JNICALL
Java_cstr_est_Features_cpp_1get(JNIEnv *env,
jobject self,
jstring jname,
jobject jdef)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
EST_Val def("hidden");
const EST_Val &val = f->val(name, def);
env->ReleaseStringUTFChars(jname, name);
if (&def == &val)
{
//fprintf(stderr, "get %s =%s\n", name, "def");
return jdef;
}
jobject jval;
val_type t = val.type();
//fprintf(stderr, "get %s =%s (%s)\n", name, (const char *)val.S(), t);
if (t==val_type_feats)
{
jval = env->NewObject(features_class, features_cons, (jlong)feats(val));
}
else if (t==val_float)
{
jval = env->NewObject(float_class, float_cons, (jfloat)val.F());
}
else if (t==val_int)
{
jval = env->NewObject(int_class, int_cons, (jint)val.I());
}
else
{
jval = env->NewStringUTF(val.S());
}
return jval;
}
JNIEXPORT void JNICALL
Java_cstr_est_Features_cpp_1set__Ljava_lang_String_2F(JNIEnv *env, jobject self, jstring jname, jfloat val)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
f->set(name, val);
env->ReleaseStringUTFChars(jname, name);
}
JNIEXPORT void JNICALL
Java_cstr_est_Features_cpp_1set__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject self, jstring jname, jstring jval)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
const char *val = env->GetStringUTFChars(jval, 0);
f->set(name, val);
env->ReleaseStringUTFChars(jname, name);
env->ReleaseStringUTFChars(jval, val);
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Features_cpp_1present(JNIEnv *env, jobject self, jstring jname)
{
EST_Features *f = (EST_Features *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
int val = f->present(name);
env->ReleaseStringUTFChars(jname, name);
return val;
}

View File

@@ -0,0 +1,216 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// -------------------------------------------------------------------- \\
// EST Features mapped to Java. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.lang.*;
import java.util.*;
import cstr.util.*;
public class Features
implements Featured
{
private long cpp_handle;
private boolean mine;
private String [] cachedFeatureNames;
public Features()
{
this(0L, true);
}
public Features(long handle)
{
this(handle, false);
}
Features(long handle, boolean m)
{
// System.out.println("create "+handle+":"+m);
create_cpp_features(handle);
mine=m;
}
protected void finalize() throws Throwable
{
if (mine)
destroy_cpp_features();
super.finalize();
}
private native String [] cpp_featureNames();
public String [] names()
{
if (cachedFeatureNames ==null)
cachedFeatureNames = cpp_featureNames();
return cachedFeatureNames;
}
public void getPaths(String prefix, Vector names, boolean nodes, boolean leaves)
{
String [] fns = names();
// System.err.println("getFeatureNames:"+fns.length);
for(int i=0; i<fns.length; i++)
{
Object v = get(fns[i]);
// System.err.println("="+fns[i]+":"+v+":"+v.getClass());
if (v==null)
continue;
else if (v instanceof cstr.est.Features)
{
//System.err.println("Features");
if ( prefix==null )
{
if (nodes)
names.addElement(fns[i]);
((Features)v).getPaths(fns[i], names, nodes, leaves);
}
else
{
if (nodes)
names.addElement(prefix + "." + fns[i]);
((Features)v).getPaths(prefix + "." + fns[i], names, nodes, leaves);
}
}
else
{
// System.err.println("Other:"+v.getClass());
if ( prefix==null )
{
if (leaves)
names.addElement(fns[i]);
}
else
{
if (leaves)
names.addElement(prefix + "." + fns[i]);
}
}
}
}
private native boolean cpp_present(String n);
public boolean present(String n)
{
return cpp_present(n);
}
private native String cpp_getS(String n, String def);
public String getS(String n)
{
return cpp_getS(n, "");
}
public String getS(String n, String def)
{
return cpp_getS(n, def);
}
public String getFeature(String n)
{
return cpp_getS(n, "");
}
private native float cpp_getF(String n, float def);
public float getF(String n)
{
return cpp_getF(n,(float)0.0);
}
public float getF(String n, float def)
{
return cpp_getF(n,def);
}
private native Object cpp_get(String n, Object def);
public Object get(String n)
{
return cpp_get(n,null);
}
public Object get(String n, Object def)
{
return cpp_get(n,def);
}
private native void cpp_set(String n, float val);
public void set(String n, float val)
{
cpp_set(n, val);
}
private native void cpp_set(String n, String val);
public void set(String n, String val)
{
cpp_set(n, val);
}
public final int hashCode()
{
return (int)cpp_handle;
}
public boolean equals(Object i)
{
return i instanceof Features && ((Features)i).cpp_handle == cpp_handle;
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_features(long handle);
private native boolean destroy_cpp_features();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Features C++ fails");
}
}

View File

@@ -0,0 +1,281 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Item. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Item.h"
#include "ling_class/EST_Item.h"
#include "ling_class/EST_item_aux.h"
static jobject item_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_initialise_1cpp (JNIEnv *env, jclass myclass)
{
item_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_create_1cpp_1item(JNIEnv *env,
jobject self,
jlong handle
)
{
EST_Item *item =(handle == 0L
? (new EST_Item)
: (EST_Item *)handle
);
// printf("create item %p\n", item);
env->SetLongField(self, handle_field, (jlong)item);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_destroy_1cpp_1item (JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
// printf("destroy item %p\n", item);
delete item;
return 1;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Item_cpp_1name(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
EST_String name = item->name();
return env->NewStringUTF(name);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Item_cpp_1getS(JNIEnv *env, jobject self, jstring jname, jstring jdef)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
EST_feat_status status=efs_ok;
// cout << "GetS " << name << "\n";
EST_String val= "";
val = getString(*item, name, EST_String::Empty, status);
// cout << "<GetS " << name << "=" << val << "\n";
env->ReleaseStringUTFChars(jname, name);
if (status != efs_ok)
return jdef;
// cout << "return\n";
return env->NewStringUTF(val);
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_cpp_1getF(JNIEnv *env, jobject self, jstring jname, jfloat def)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
EST_feat_status status=efs_ok;
float val = getFloat(*item, name, def, status);
env->ReleaseStringUTFChars(jname, name);
return val;
}
JNIEXPORT void JNICALL
Java_cstr_est_Item_cpp_1set__Ljava_lang_String_2F(JNIEnv *env, jobject self, jstring jname, jfloat val)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
item->set(name, val);
env->ReleaseStringUTFChars(jname, name);
}
JNIEXPORT void JNICALL
Java_cstr_est_Item_cpp_1set__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject self, jstring jname, jstring jval)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
const char *val = env->GetStringUTFChars(jval, 0);
item->set(name, val);
env->ReleaseStringUTFChars(jname, name);
env->ReleaseStringUTFChars(jval, val);
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_cpp_1getStartTime(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return item?start(*item):0.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_cpp_1getMidTime(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return item?mid(*item):0.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_cpp_1getTime(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return item?time(*item):0.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_cpp_1getEndTime(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return item?end(*item):0.0;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1getContent(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
EST_Item_Content *itemc = item->contents();
return (long)itemc;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Item_cpp_1type(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
const char *type;
if (parent(item) != NULL || daughter1(item) != NULL)
type = "tree";
else
type = "linear";
return env->NewStringUTF(type);
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1next(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->next();
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1prev(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->prev();
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1up(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->up();
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1down(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->down();
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1insert_1after(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->insert_after();
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_cpp_1insert_1before(JNIEnv *env, jobject self)
{
EST_Item *item = (EST_Item *) env->GetLongField(self, handle_field);
return (long)item->insert_before();
}

View File

@@ -0,0 +1,298 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Tue Mar 31 1998 \\
// -------------------------------------------------------------------- \\
// Java wrapper around items. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.lang.*;
import java.util.*;
import java.awt.*;
import cstr.util.*;
import java.io.*;
public class Item
implements Named, Keyed, Featured
{
private long cpp_handle;
private boolean mine;
private Utterance utterance;
private Item_Content contents;
public Item()
{
this(0L, true, null);
}
public Item(long handle)
{
this(handle, false, null);
}
public Item(long handle, Utterance utterance)
{
this(handle, false, utterance);
}
Item(long handle, boolean m, Utterance from_utterance)
{
utterance = from_utterance;
create_cpp_item(handle);
mine=m;
}
protected void finalize() throws Throwable
{
if (mine)
destroy_cpp_item();
super.finalize();
}
protected final Item getItem(long handle)
{
Item i;
if (utterance != null)
i = utterance.getItem(handle);
else
i = new Item(handle);
return i;
}
public long getHandle()
{
return cpp_handle;
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
public String getName()
{
return cpp_name();
}
private native void cpp_setName(String name);
public void setName(String name)
{
cpp_setName(name);
}
private native long cpp_getContent();
public final Item_Content getContent()
{
if (contents==null)
contents = new Item_Content(cpp_getContent());
return contents;
}
public final Object getKey()
{
return getContent();
}
public final int hashCode()
{
return (int)cpp_getContent();
}
public final boolean equals(Object i)
{
return i instanceof Item && ((Item)i).cpp_handle == cpp_handle;
}
private native String cpp_getS(String n, String def);
public String getS(String n, String def)
{
return cpp_getS(n, def);
}
public String getS(String n)
{
return cpp_getS(n, "");
}
public String getFeature(String n)
{
return cpp_getS(n, "");
}
private native float cpp_getF(String n, float def);
public float getF(String n, float def)
{
return cpp_getF(n, def);
}
public float getF(String n)
{
return cpp_getF(n, 0);
}
private native void cpp_set(String n, float val);
public void set(String n, float val)
{
cpp_set(n, val);
}
private native void cpp_set(String n, String val);
public void set(String n, String val)
{
cpp_set(n, val);
}
private native String cpp_type();
public String type()
{
return cpp_type();
}
private native float cpp_getStartTime();
public float getStartTime()
{
return cpp_getStartTime();
}
private native float cpp_getMidTime();
public float getMidTime()
{
return cpp_getMidTime();
}
private native float cpp_getTime();
public float getTime()
{
return cpp_getTime();
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
private native long cpp_next();
public Item next()
{
long h = cpp_next();
if (h==0)
return null;
else
return getItem(h);
}
private native long cpp_prev();
public Item prev()
{
long h = cpp_prev();
if (h==0)
return null;
else
return getItem(h);
}
private native long cpp_up();
public Item up()
{
long h = cpp_up();
if (h==0)
return null;
else
return getItem(h);
}
private native long cpp_down();
public Item down()
{
long h = cpp_down();
if (h==0)
return null;
else
return getItem(h);
}
private native long cpp_insert_after();
public Item insert_after()
{
long h = cpp_insert_after();
if (h==0)
return null;
else
return getItem(h);
}
private native long cpp_insert_before();
public Item insert_before()
{
long h = cpp_insert_before();
if (h==0)
return null;
else
return getItem(h);
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_item(long handle);
private native boolean destroy_cpp_item();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Item C++ fails");
}
}

View File

@@ -0,0 +1,402 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Item_Content. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Item_Content.h"
#include "ling_class/EST_Item_Content.h"
#include "ling_class/EST_item_content_aux.h"
#include "ling_class/EST_item_aux.h"
#include "ling_class/EST_Relation.h"
static jclass features_class;
static jmethodID features_cons;
static jclass string_class;
static jclass float_class;
static jmethodID float_cons;
static jclass int_class;
static jmethodID int_cons;
static jobject itemContent_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_1Content_initialise_1cpp (JNIEnv *env, jclass myclass)
{
itemContent_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
features_class = (jclass)env->NewGlobalRef(env->FindClass("cstr/est/Features"));
features_cons = env->GetMethodID(features_class, "<init>", "(J)V");
if (!features_cons)
{
printf("can't find features_cons!\n");
return 0;
}
string_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/String"));
float_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Float"));
float_cons = env->GetMethodID(float_class, "<init>", "(F)V");
if (!float_cons)
{
printf("can't find float_cons!\n");
return 0;
}
int_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Integer"));
int_cons = env->GetMethodID(int_class, "<init>", "(I)V");
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_1Content_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_1Content_create_1cpp_1itemContent(JNIEnv *env,
jobject self,
jlong handle
)
{
EST_Item_Content *itemContent = (handle==0L
? (new EST_Item_Content)
: (EST_Item_Content *)handle
);
// printf("create itemContent %p\n", itemContent);
env->SetLongField(self, handle_field, (jlong)itemContent);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_1Content_destroy_1cpp_1itemContent (JNIEnv *env, jobject self)
{
EST_Item_Content *itemContent = (EST_Item_Content *) env->GetLongField(self, handle_field);
// printf("destroy itemContent %p\n", itemContent);
delete itemContent;
return 1;
}
JNIEXPORT jobjectArray JNICALL
Java_cstr_est_Item_1Content_cpp_1featureNames (JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
int n;
EST_Features::Entries p;
n=0;
for (p.begin(item->f); p != 0; ++p)
n++;
jobjectArray names = env->NewObjectArray(n, string_class, NULL);
p.beginning();
for(int i=0; i<n; i++)
{
jstring fn = env->NewStringUTF(p->k);
env->SetObjectArrayElement(names, i, fn);
++p;
}
return names;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_1Content_cpp_1getItem__(JNIEnv *env,
jobject self)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
if (item_c->relations.length() == 0)
return 0L;
EST_Litem *p;
p = item_c->relations.list.head();
EST_Item *i = item(item_c->relations.list(p).v);
return (long)i;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_1Content_cpp_1getItem__Ljava_lang_String_2(JNIEnv *env,
jobject self,
jstring jrelName)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
const char * relName = env->GetStringUTFChars(jrelName, 0);
EST_Item *i = item_c->Relation(relName);
env->ReleaseStringUTFChars(jrelName, relName);
return (long)i;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_1Content_cpp_1getItem__J(JNIEnv *env,
jobject self,
jlong relh)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
EST_Relation *rel = (EST_Relation *)relh;
EST_Item *i = item_c->Relation(rel->name());
return (long)i;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Item_1Content_cpp_1getS(JNIEnv *env,
jobject self,
jstring jname,
jstring jdef,
jlong relHandle)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
EST_Relation *rel = (EST_Relation *)relHandle;
const char *name = env->GetStringUTFChars(jname, 0);
EST_String val;
EST_feat_status stat=efs_ok;
if (rel != NULL)
{
// cout << "getS " << name << " in " << rel->name() << "\n";
EST_Item *item = item_c->Relation(rel->name());
val = getString(*item, name, EST_String::Empty, stat);
}
else
{
// cout << "getS " << name << " in no relation \n";
val = getString(*item_c, name, EST_String::Empty, stat);
}
env->ReleaseStringUTFChars(jname, name);
if (stat != efs_ok)
return jdef;
return env->NewStringUTF(val);
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_1Content_cpp_1getF(JNIEnv *env,
jobject self,
jstring jname,
jfloat def,
jlong relHandle)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
EST_Relation *rel = (EST_Relation *)relHandle;
const char *name = env->GetStringUTFChars(jname, 0);
float val;
EST_feat_status stat=efs_ok;
if (rel != NULL)
{
EST_Item *item = item_c->Relation(rel->name());
val = getFloat(*item, name, def, stat);
}
else
val = getFloat(*item_c, name, def, stat);
env->ReleaseStringUTFChars(jname, name);
return val;
}
JNIEXPORT jobject JNICALL
Java_cstr_est_Item_1Content_cpp_1get(JNIEnv *env,
jobject self,
jstring jname,
jobject jdef,
jlong relHandle)
{
EST_Item_Content *item_c = (EST_Item_Content *) env->GetLongField(self, handle_field);
EST_Relation *rel = (EST_Relation *)relHandle;
const char *name = env->GetStringUTFChars(jname, 0);
EST_Val def("hidden");
const EST_Val *val;
if (rel != NULL)
{
EST_Item *item = item_c->Relation(rel->name());
val = &(item->f(name, def));
}
else
val = &(item_c)->f(name, def);
env->ReleaseStringUTFChars(jname, name);
if (&def == val)
{
//fprintf(stderr, "get %s =%s\n", name, "def");
return jdef;
}
jobject jval;
val_type t = val->type();
//fprintf(stderr, "get %s =%s (%s)\n", name, (const char *)val->S(), t);
if (t==val_type_feats)
{
jval = env->NewObject(features_class, features_cons, (jlong)feats(*val));
}
else if (t==val_float)
{
jval = env->NewObject(float_class, float_cons, (jfloat)val->F());
}
else if (t==val_int)
{
jval = env->NewObject(int_class, int_cons, (jint)val->I());
}
else
{
jval = env->NewStringUTF(val->S());
}
return jval;
}
JNIEXPORT void JNICALL
Java_cstr_est_Item_1Content_cpp_1set__Ljava_lang_String_2F(JNIEnv *env, jobject self, jstring jname, jfloat val)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
item->f.set(name, val);
env->ReleaseStringUTFChars(jname, name);
}
JNIEXPORT void JNICALL
Java_cstr_est_Item_1Content_cpp_1set__Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject self, jstring jname, jstring jval)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
const char *val = env->GetStringUTFChars(jval, 0);
item->f.set(name, val);
env->ReleaseStringUTFChars(jname, name);
env->ReleaseStringUTFChars(jval, val);
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Item_1Content_cpp_1featurePresent(JNIEnv *env, jobject self, jstring jname)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
int val = item->f.present(name);
env->ReleaseStringUTFChars(jname, name);
return val;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Item_1Content_cpp_1getFeatures(JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
return item?(long)(EST_Features *)&(item->f):0L;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_1Content_cpp_1getTime(JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
return item?time(*item):-1.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_1Content_cpp_1getMidTime(JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
return item?mid(*item):-1.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_1Content_cpp_1getStartTime(JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
return item?start(*item):-1.0;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Item_1Content_cpp_1getEndTime(JNIEnv *env, jobject self)
{
EST_Item_Content *item = (EST_Item_Content *) env->GetLongField(self, handle_field);
return item?end(*item):-1.0;
}

View File

@@ -0,0 +1,256 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Wed Feb 25 1998 \\
// -------------------------------------------------------------------- \\
// Items in a stream. Wrapper around EST_StreamItem. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.lang.*;
import java.util.*;
import java.awt.*;
import cstr.util.*;
public class Item_Content
implements Featured
{
private long cpp_handle;
private boolean mine;
private String [] cachedFeatureNames;
public Item_Content()
{
this(0L, true);
}
public Item_Content(long handle)
{
this(handle, false);
}
Item_Content(long handle, boolean m)
{
create_cpp_itemContent(handle);
mine=m;
}
protected void finalize() throws Throwable
{
if (mine)
destroy_cpp_itemContent();
super.finalize();
}
private native long cpp_getItem();
public Item getItem()
{
return new Item(cpp_getItem());
}
private native long cpp_getItem(String relName);
public Item getItem(String relName)
{
long h = cpp_getItem(relName);
return h==0L?null:new Item(h);
}
private native long cpp_getItem(long relh);
public Item getItem(Relation rel)
{
long h = cpp_getItem(rel.getHandle());
return h==0L?null:new Item(h);
}
private native String [] cpp_featureNames();
public String [] featureNames()
{
if (cachedFeatureNames ==null)
cachedFeatureNames = cpp_featureNames();
return cachedFeatureNames;
}
private native boolean cpp_featurePresent(String n);
public boolean featurePresent(String n)
{
return cpp_featurePresent(n);
}
private native String cpp_getS(String n, String def, long r);
public String getS(String n, Relation r)
{
return cpp_getS(n, "", r.getHandle());
}
public String getSdef(String n, String def, Relation r)
{
return cpp_getS(n, def, r.getHandle());
}
public String getS(String n)
{
return cpp_getS(n, "", 0L);
}
public String getFeature(String n)
{
return cpp_getS(n, "", 0L);
}
private native float cpp_getF(String n, float def, long r);
public float getF(String n, Relation r)
{
return cpp_getF(n,(float)0.0,r.getHandle());
}
public float getF(String n, float def, Relation r)
{
return cpp_getF(n,def,r.getHandle());
}
public float getF(String n)
{
return cpp_getF(n,(float)0.0,0L);
}
private native Object cpp_get(String n, Object def, long r);
public Object get(String n, Relation r)
{
return cpp_get(n,null,r.getHandle());
}
public Object get(String n, Object def, Relation r)
{
return cpp_get(n,def,r.getHandle());
}
public Object get(String n)
{
return cpp_get(n,null,0L);
}
private native void cpp_set(String n, float val);
public void set(String n, float val)
{
cpp_set(n, val);
}
private native void cpp_set(String n, String val);
public void set(String n, String val)
{
cpp_set(n, val);
}
public String name()
{
return cpp_getS("name", "<NONAME>", 0L);
}
public String getName()
{
return cpp_getS("name", "<NONAME>", 0L);
}
private native long cpp_getFeatures();
public Features getFeatures()
{
long fh = cpp_getFeatures();
return new Features(fh);
}
private native float cpp_getStartTime();
public float getStartTime()
{
return cpp_getStartTime();
}
private native float cpp_getMidTime();
public float getMidTime()
{
return cpp_getMidTime();
}
private native float cpp_getTime();
public float getTime()
{
return cpp_getTime();
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
public final int hashCode()
{
return (int)cpp_handle;
}
public boolean equals(Object i)
{
return i instanceof Item_Content && ((Item_Content)i).cpp_handle == cpp_handle;
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_itemContent(long handle);
private native boolean destroy_cpp_itemContent();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Item_Content C++ fails");
}
}

View File

@@ -0,0 +1,69 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
TOP=../../../..
DIRNAME = java/cpp_version/cstr/est
JUST_BUILD_DIRS = awt
ALL_DIRS =
LOCAL_JAVA_NATIVE_CLASSES = Wave Track \
Utterance Relation Item Item_Content \
Sigpr Features
JAVA_NATIVE_CLASSES = $(LOCAL_JAVA_NATIVE_CLASSES)
LOCAL_JAVA_CLASSES = $(LOCAL_JAVA_NATIVE_CLASSES) \
TrackFileFormat UtteranceFileFormat
JAVA_CLASSES = $(LOCAL_JAVA_CLASSES) \
ServerConnection SocketsFile
NEED_JAVA=true
NO_DEPEND=1
CPPSRCS = $(JAVA_NATIVE_CLASSES:=.cc)
SRCS = $(CPPSRCS)
OBJS_estjava = $(SRCS:.cc=.o)
FILES = $(LOCAL_JAVA_NATIVE_CLASSES:=.cc) $(LOCAL_JAVA_CLASSES:%=%.java) Makefile skeleton.cc skeleton.java
ALL = .java .buildlib
-include ../../Makefile.version
include $(TOP)/config/common_make_rules
foo:
: $(PROJECT_LIBRARIES)

View File

@@ -0,0 +1,256 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Relation. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Relation.h"
#include "ling_class/EST_Relation.h"
#include "ling_class/EST_Item.h"
static jobject relation_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Relation_initialise_1cpp (JNIEnv *env, jclass myclass)
{
relation_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Relation_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Relation_create_1cpp_1relation(JNIEnv *env,
jobject self,
jlong handle
)
{
EST_Relation *relation =(handle == 0L
? (new EST_Relation)
: (EST_Relation *)handle
);
// printf("create relation %p\n", relation);
env->SetLongField(self, handle_field, (jlong)relation);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Relation_destroy_1cpp_1relation (JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
// printf("destroy relation %p\n", relation);
delete relation;
return 1;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Relation_cpp_1name(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
return env->NewStringUTF(relation->name());
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Relation_cpp_1getFeature (JNIEnv *env, jobject self,
jstring jn)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
const char *n = env->GetStringUTFChars(jn, 0);
const char *v = (relation->f.present(n)
? (const char *)relation->f.S(n)
: "");
env->ReleaseStringUTFChars(jn, n);
return env->NewStringUTF(v);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Relation_cpp_1type(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item * hd = relation->head();
const char *type;
if (!hd)
type = "empty";
else
{
type = "linear";
while (hd)
{
if (hd->up() || hd->down())
{
type = "tree";
break;
}
hd=hd->next();
}
}
return env->NewStringUTF(type);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Relation_cpp_1load (JNIEnv *env, jobject self, jstring jfilename)
{
EST_Relation *stream = (EST_Relation *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *res = "";
EST_read_status stat = stream->load(filename);
env->ReleaseStringUTFChars(jfilename, filename);
if (stat == read_format_error)
res = "stream format error";
else if (stat == read_error)
res = "stream load error";
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Relation_cpp_1save (JNIEnv *env, jobject self, jstring jfilename, jstring jformat)
{
EST_Relation *stream = (EST_Relation *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *format = env->GetStringUTFChars(jformat, 0);
const char *res = "";
EST_write_status stat = stream->save(filename);
env->ReleaseStringUTFChars(jfilename, filename);
env->ReleaseStringUTFChars(jformat, format);
if (stat == write_error)
res = "stream save error";
return env->NewStringUTF(res);
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Relation_cpp_1head(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item *item = relation->head();
return (long)item;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Relation_cpp_1tail(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item * item = relation->tail();
return (long)item;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Relation_cpp_1append(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item * item = relation->append();
return (long)item;
}
JNIEXPORT void JNICALL
Java_cstr_est_Relation_cpp_1removeItemList(JNIEnv *env,
jobject self,
jlong ihandle
)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item * item = (EST_Item *)ihandle;
remove_item_list(relation, item);
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Relation_cpp_1findItem(JNIEnv *env, jobject self, jfloat time)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item * item = relation->head();
while (item!=NULL && item->F("end", 0.0) < time)
item = item->next();
return (long)item;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Relation_cpp_1getEndTime(JNIEnv *env, jobject self)
{
EST_Relation *relation = (EST_Relation *) env->GetLongField(self, handle_field);
EST_Item *item = relation->tail();
return item?item->F("end",0.0):0.0;
}

View File

@@ -0,0 +1,365 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Tue Mar 31 1998 \\
// -------------------------------------------------------------------- \\
// Java wrapper around relations. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est ;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import cstr.util.*;
public class Relation
implements Featured
{
private long cpp_handle;
private Utterance utterance;
private boolean mine;
public Relation()
{
this(0L, null, true);
}
public Relation(long handle)
{
this(handle, null, false);
}
public Relation(long handle, Utterance u)
{
this(handle, u, false);
}
Relation(long handle, Utterance u, boolean m)
{
create_cpp_relation(handle);
utterance=u;
mine=m;
}
protected void finalize() throws Throwable
{
if (mine)
destroy_cpp_relation();
super.finalize();
}
protected final Item getItem(long handle)
{
Item i;
if (utterance != null)
i = utterance.getItem(handle);
else
i = new Item(handle);
return i;
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
public String getName()
{
return cpp_name();
}
public long getHandle()
{
return cpp_handle;
}
public boolean equals(Object o)
{
return o instanceof Relation && ((Relation)o).cpp_handle == cpp_handle;
}
private native String cpp_type();
public String type()
{
return cpp_type();
}
private native String cpp_getFeature(String n);
public String getFeature(String n)
{
if (n.equals("_NAME_"))
return getName();
else
return cpp_getFeature(n);
}
public String getS(String n)
{
if (n.equals("_NAME_"))
return getName();
else
return cpp_getFeature(n);
}
public String [] featureNames()
{
return featureNames(false, true);
}
public String [] featureNames(boolean nodes, boolean leaves)
{
Vector names = new Vector();
Hashtable found = new Hashtable();
Enumeration is = getElements();
while (is.hasMoreElements())
{
Item item = (Item)is.nextElement();
Item_Content cont = item.getContent();
Vector paths = new Vector();
cont.getFeatures().getPaths(null, paths, nodes, leaves);
for(int i=0; i< paths.size(); i++)
{
String name = (String)paths.elementAt(i);
if (found.get(name) != null)
continue;
for(int p=0; p<names.size(); p++)
{
int cmp = name.compareTo((String)names.elementAt(p));
if (cmp>0)
continue;
if (cmp< 0)
{
names.insertElementAt(name, p);
found.put(name,name);
}
name=null;
break;
}
if (name != null)
{
names.addElement(name);
found.put(name, name);
}
}
}
String [] ns = new String[names.size()];
for(int i=0; i<names.size(); i++)
ns[i] = (String)names.elementAt(i);
return ns;
}
public void setUtterance(Utterance u)
{
utterance=u;
}
public Utterance getUtterance()
{
return utterance;
}
private native String cpp_load(String filename);
public void load(String filename) throws FileNotFoundException
{
String res = cpp_load(filename);
if (!res.equals(""))
throw new FileNotFoundException(res);
// findTimePoints();
}
private native String cpp_save(String filename, String format);
public void save(String filename, String format) throws IOException
{
String res = cpp_save(filename, format);
if (!res.equals(""))
throw new IOException(res);
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
public Enumeration getElements()
{
return new RelationEnumeration(this);
}
public Enumeration getElements(float from, float to)
{
return new RelationEnumeration(this, from, to);
}
private native long cpp_head();
public Item head()
{
long h = cpp_head();
if (h != 0)
return getItem(h);
else
return null;
}
private native long cpp_tail();
public Item tail()
{
long h = cpp_tail();
if (h != 0)
return getItem(h);
else
return null;
}
private native long cpp_append();
public Item append()
{
long h = cpp_append();
if (h != 0)
return getItem(h);
else
return null;
}
private native void cpp_removeItemList(long itemh);
public void removeItemList(Item i)
{
cpp_removeItemList(i.getHandle());
}
private native long cpp_findItem(float time);
public Item findItem(float time)
{
long p = cpp_findItem(time);
return p==0L?null:getItem(p);
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_relation(long handle);
private native boolean destroy_cpp_relation();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Relation C++ fails");
}
static class RelationEnumeration implements Enumeration
{
private Relation relation;
private Item current;
private float endTime;
public RelationEnumeration(Relation st)
{
relation = st;
current = st.head();
endTime = (float)-1.0;
}
public RelationEnumeration(Relation st, float from, float to)
{
relation = st;
current = st.findItem(from);
endTime = to;
}
public boolean hasMoreElements()
{
return current != null;
}
public Object nextElement()
{
Item n = current;
current = n.down();
if (current == null)
current = n.next();
if (current == null)
{
current=n;
while (current.prev()!=null)
current=current.prev();
current = current.up();
while (current != null && current.next()==null)
{
while (current.prev()!=null)
current=current.prev();
current=current.up();
}
if (current != null)
current = current.next();
}
if (current != null && endTime >= 0 && current.getEndTime() > endTime)
current = null;
return n;
}
}
}

View File

@@ -0,0 +1,68 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* -------------------------------------------------------------------- */
/* Interface to signal processing code. */
/* */
/*************************************************************************/
#include <stdio.h>
#include <signal.h>
#include "jni_Sigpr.h"
#include "sigpr/EST_spectrogram.h"
#include "sigpr/EST_misc_sigpr.h"
JNIEXPORT void JNICALL
Java_cstr_est_Sigpr_cpp_1spectrogram(JNIEnv *env, jclass myclass,
jlong waveh, jlong trackh,
jfloat shift,
jfloat length,
jint order,
jfloat floor,
jfloat ceil)
{
(void)env;
(void)myclass;
EST_Wave *wave = (EST_Wave *)waveh;
EST_Track *sg = (EST_Track *)trackh;
EST_Wave pwave;
EST_pre_emphasis(*wave, pwave, 0.94);
raw_spectrogram(*sg, pwave, length, shift, order);
scale_spectrogram(*sg, 1.0, floor, ceil);
}

View File

@@ -0,0 +1,70 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// -------------------------------------------------------------------- \\
// Signal Processing Tools \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.lang.*;
import java.util.*;
import java.awt.*;
public class Sigpr
{
private native static void cpp_spectrogram(long whandle,
long thandle,
float shift,
float length,
int order,
float floor,
float ceil);
public static Track spectrogram(Wave wv,
float shift,
float length,
int order,
float floor,
float ceil)
{
Track sg = new Track();
cpp_spectrogram(wv.getHandle(), sg.getHandle(),
shift, length, order, floor, ceil);
return sg;
}
}

View File

@@ -0,0 +1,319 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface Between Java And C++ For Est_Track. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Track.h"
#include "EST_Track.h"
#include "EST_track_aux.h"
static jobject track_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
static jint frame_before(EST_Track *track, jfloat t)
{
if (track->equal_space())
{
float s = track->shift();
int f = (int)(t/s)-1;
if (f<0)
f=0;
// fprintf(stderr, "fb t=%f s=%f f=%d\n", t, s, f);
return f;
}
else
{
int f=0;
for(int i=0; i<track->num_frames(); f=i++)
if (track->t(i)>=t)
break;
return f;
}
}
static jint frame_after(EST_Track *track, jfloat t)
{
if (track->equal_space())
{
float s = track->shift();
int f = (int)(t/s)+1;
if (f>track->num_frames())
f=track->num_frames();
// fprintf(stderr, "fa t=%f s=%f f=%d\n", t, s, f);
return f;
}
else
{
int i;
for(i=0; i<track->num_frames(); i++)
if (track->t(i)>=t)
break;
return i;
}
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Track_initialise_1cpp (JNIEnv *env, jclass myclass)
{
track_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Track_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Track_create_1cpp_1track(JNIEnv *env, jobject self)
{
EST_Track *track = new EST_Track;
// printf("create track %p\n", track);
env->SetLongField(self, handle_field, (jlong)track);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Track_destroy_1cpp_1track (JNIEnv *env, jobject self)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
// printf("destroy track %p\n", track);
delete track;
return 1;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Track_cpp_1name (JNIEnv *env, jobject self)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return env->NewStringUTF(track->name());
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Track_cpp_1load (JNIEnv *env, jobject self, jstring jfilename)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *res = "";
EST_read_status stat = track->load(filename);
env->ReleaseStringUTFChars(jfilename, filename);
if (stat == read_format_error)
res = "track format error";
else if (stat == read_error)
res = "track load error";
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Track_cpp_1save (JNIEnv *env, jobject self,
jstring jfilename, jstring jformat,
jfloat start,
jfloat end)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *format = env->GetStringUTFChars(jformat, 0);
const char *res = "";
int sframe = frame_before(track, start);
int eframe = frame_after(track, end);
EST_Track segment;
track->sub_track(segment,
sframe, eframe-sframe,
0, EST_ALL);
EST_write_status stat = segment.save(filename, format);
env->ReleaseStringUTFChars(jfilename, filename);
env->ReleaseStringUTFChars(jformat, format);
if (stat == write_error)
res = "track save error";
return env->NewStringUTF(res);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1num_1frames(JNIEnv *env, jobject self)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->num_frames();
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1num_1channels(JNIEnv *env, jobject self)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->num_channels();
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Track_cpp_1getEndTime(JNIEnv *env, jobject self)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
int f = track->num_frames()-1;
return f>=0?track->t(f):0.0;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Track_cpp_1channelName(JNIEnv *env, jobject self,
jint i)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
EST_String cname(i>=0 && i < track->num_channels()
?track->channel_name(i)
:EST_String::Empty);
return env->NewStringUTF(cname);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1channelPosition(JNIEnv *env, jobject self,
jstring jname)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
int p = track->channel_position(name);
env->ReleaseStringUTFChars(jname, name);
return p;
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Track_a__II(JNIEnv *env, jobject self,
jint f, jint c)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->a((int)f,(int)c);
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Track_a__FI(JNIEnv *env, jobject self,
jfloat t, jint c)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->a((float)t,(int)c);
}
JNIEXPORT jfloat JNICALL
Java_cstr_est_Track_cpp_1t(JNIEnv *env, jobject self,
jint f)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->t((int)f);
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Track_cpp_1val(JNIEnv *env, jobject self,
jint f)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->val((int)f);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1frameBefore(JNIEnv *env, jobject self,
jfloat t)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return frame_before(track, t);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1frameAfter(JNIEnv *env, jobject self,
jfloat t)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return frame_after(track, t);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Track_cpp_1frameNearest(JNIEnv *env, jobject self,
jfloat t)
{
EST_Track *track = (EST_Track *) env->GetLongField(self, handle_field);
return track->index(t);
}

View File

@@ -0,0 +1,188 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Friday 12th September 1997 \\
// -------------------------------------------------------------------- \\
// Wrapper around the EST_Track class. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Track
{
private long cpp_handle;
public Track()
{
create_cpp_track();
}
protected void finalize() throws Throwable
{
destroy_cpp_track();
super.finalize();
}
public long getHandle()
{
return cpp_handle;
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
private native String cpp_load(String filename);
public void load(File filename) throws FileNotFoundException
{
String res = cpp_load(filename.getPath());
if (!res.equals(""))
throw new FileNotFoundException(res);
}
private native String cpp_save(String filename, String format, float start, float end);
public void save(File filename, TrackFileFormat format, float start, float end)
throws IOException
{
String res = cpp_save(filename.getPath(), format.toString(), start, end);
if (!res.equals(""))
throw new IOException(res);
}
public void save(File filename, float start, float end)
throws IOException
{
String res = cpp_save(filename.getPath(),
TrackFileFormat.EST_BINARY.toString(),
start, end);
if (!res.equals(""))
throw new IOException(res);
}
private native int cpp_num_frames();
public int num_frames()
{
return cpp_num_frames();
}
private native int cpp_num_channels();
public int num_channels()
{
return cpp_num_channels();
}
private native String cpp_channelName(int i);
public String channelName(int i)
{
return cpp_channelName(i);
}
private native int cpp_channelPosition(String n);
public int channelPosition(String n)
{
return cpp_channelPosition(n);
}
public native float a(int i, int c);
public native float a(float t, int c);
private native float cpp_t(int i);
public float t(int i)
{
return cpp_t(i);
}
private native boolean cpp_val(int i);
public boolean val(int i)
{
return cpp_val(i);
}
private native int cpp_frameBefore(float time);
public int frameBefore(float time)
{
return cpp_frameBefore(time);
}
private native int cpp_frameAfter(float time);
public int frameAfter(float time)
{
return cpp_frameAfter(time);
}
private native int cpp_frameNearest(float time);
public int frameNearest(float time)
{
return cpp_frameNearest(time);
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_track();
private native boolean destroy_cpp_track();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Track C++ fails");
}
}

View File

@@ -0,0 +1,95 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// -------------------------------------------------------------------- \\
// Enumerated type of track file formats. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est ;
import java.lang.*;
import java.util.*;
import java.awt.*;
import cstr.util.*;
public class TrackFileFormat extends Enum
{
static EnumValues values = init("TrackFileFormat");
public static TrackFileFormat DUMMY = new TrackFileFormat("dummy", "Dummy TrackFileFormat Value Fnord", false);
public static TrackFileFormat UNKNOWN = new TrackFileFormat("unknown", "Unknown TrackFileFormat Value Fnord", false);
public static TrackFileFormat EST_BINARY = new TrackFileFormat("est_binary", "Est (binary)");
public static TrackFileFormat EST_ASCII = new TrackFileFormat("est", "Est (ascii)");
public static TrackFileFormat ESPS = new TrackFileFormat("esps", "Entropic FEA");
public static TrackFileFormat HTK = new TrackFileFormat("htk", "HTK");
public static TrackFileFormat HTK_FBANK = new TrackFileFormat("htk_fbank", "HTK (Filter Bank)");
public static TrackFileFormat HTK_MFCC = new TrackFileFormat("htk_mfcc", "HTK (MFCC)");
public static TrackFileFormat HTK_USER= new TrackFileFormat("htk_user", "HTK (user defined)");
public static TrackFileFormat HTK_DISCRETE = new TrackFileFormat("htk_discrete", "HTK (discrete)");
public static TrackFileFormat XMG = new TrackFileFormat("xmg", "Xmg");
public static TrackFileFormat EMA = new TrackFileFormat("ema", "EMA");
public static TrackFileFormat EMA_SWAPPED = new TrackFileFormat("ema_swapped", "EMA (swapped)");
public static TrackFileFormat ASCII = new TrackFileFormat("ascii", "ASCII");
public TrackFileFormat(String s, String ls)
{
super(s, ls, null);
}
public TrackFileFormat(String s, String ls, boolean real)
{
super(s, ls, real);
}
public EnumValues getValuesTable()
{
return values;
}
public static TrackFileFormat getValue(String s)
throws IllegalArgumentException
{
return (TrackFileFormat)getValue(s, values);
}
public static Enum [] getValues()
{
return (Enum [])getValues(values);
}
}

View File

@@ -0,0 +1,233 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Utterance. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Utterance.h"
#include "ling_class/EST_Utterance.h"
static jobject utterance_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Utterance_initialise_1cpp (JNIEnv *env, jclass myclass)
{
utterance_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Utterance_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Utterance_create_1cpp_1utterance(JNIEnv *env, jobject self)
{
EST_Utterance *utterance = new EST_Utterance;
// printf("create utterance %p\n", utterance);
env->SetLongField(self, handle_field, (jlong)utterance);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Utterance_destroy_1cpp_1utterance (JNIEnv *env, jobject self)
{
EST_Utterance *utterance = (EST_Utterance *) env->GetLongField(self, handle_field);
// printf("destroy utterance %p\n", utterance);
if (utterance)
delete utterance;
return 1;
}
JNIEXPORT jint JNICALL
Java_cstr_est_Utterance_cpp_1num_1relations(JNIEnv *env, jobject self)
{
EST_Utterance *utterance = (EST_Utterance *)env->GetLongField(self, handle_field);
return utterance->num_relations();
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Utterance_cpp_1has_1relation(JNIEnv *env,
jobject self,
jstring jname)
{
EST_Utterance *utterance = (EST_Utterance *)env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
bool has = utterance->relation_present(name);
env->ReleaseStringUTFChars(jname, name);
return has;
}
JNIEXPORT jlong JNICALL Java_cstr_est_Utterance_cpp_1relation_1n(JNIEnv *env,
jobject self,
jint n)
{
EST_Utterance *utterance = (EST_Utterance *)env->GetLongField(self, handle_field);
EST_Relation * rel=NULL;
EST_Features::Entries p;
for(p.begin(utterance->relations); p && n>0; ++p,n--)
;
if (n==0)
rel = relation(p->v);
return (jlong)rel;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Utterance_cpp_1relation(JNIEnv *env,
jobject self,
jstring jname)
{
EST_Utterance *utterance = (EST_Utterance *)env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
if (!utterance->relation_present(name))
return (jlong)0l;
EST_Relation * rel = utterance->relation(name);
env->ReleaseStringUTFChars(jname, name);
return (jlong)rel;
}
JNIEXPORT jlong JNICALL
Java_cstr_est_Utterance_cpp_1create_1relation(JNIEnv *env,
jobject self,
jstring jname)
{
EST_Utterance *utterance = (EST_Utterance *)env->GetLongField(self, handle_field);
const char *name = env->GetStringUTFChars(jname, 0);
if (utterance->relation_present(name))
return (jlong)0l;
EST_Relation * rel = utterance->create_relation(name);
env->ReleaseStringUTFChars(jname, name);
return (jlong)rel;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Utterance_cpp_1load (JNIEnv *env, jobject self, jstring jfilename)
{
EST_Utterance *utterance = (EST_Utterance *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
EST_String fn(filename);
EST_read_status stat = read_ok;
CATCH_ERRORS()
{
env->ReleaseStringUTFChars(jfilename, filename);
return env->NewStringUTF(EST_error_message);
}
stat = utterance->load(fn);
END_CATCH_ERRORS();
env->ReleaseStringUTFChars(jfilename, filename);
const char *res = "";
if (stat == read_format_error)
res = "utterance format error";
else if (stat != read_ok)
res = "utterance load error";
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Utterance_cpp_1save (JNIEnv *env, jobject self, jstring jfilename, jstring jformat)
{
const EST_Utterance *utterance = (EST_Utterance *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *format = env->GetStringUTFChars(jformat, 0);
const char *res = "";
EST_write_status stat = format[0]=='\0'
? utterance->save(filename)
: utterance->save(filename,format);
env->ReleaseStringUTFChars(jfilename, filename);
env->ReleaseStringUTFChars(jformat, format);
if (stat == write_error)
res = "utterance save error";
return env->NewStringUTF(res);
}

View File

@@ -0,0 +1,169 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Friday 12th September 1997 \\
// -------------------------------------------------------------------- \\
// Wrapper around the EST_Utterance class. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.util.*;
import java.lang.*;
import java.io.*;
import cstr.util.*;
public class Utterance
{
private long cpp_handle;
private LongHash cache;
public Utterance()
{
create_cpp_utterance();
cache = new LongHash(200);
}
protected void finalize() throws Throwable
{
destroy_cpp_utterance();
super.finalize();
}
final Item getItem(long handle)
{
Item i;
i = (Item)cache.get(handle);
if (i==null)
{
i = new Item(handle, this);
cache.put(handle, i);
}
return i;
}
private native int cpp_num_relations();
public int num_relations()
{
return cpp_num_relations();
}
private native boolean cpp_has_relation(String name);
public boolean has_relation(String n)
{
return cpp_has_relation(n);
}
private native long cpp_relation_n(int n);
public Relation relation(int n)
{
return new Relation(cpp_relation_n(n), this);
}
private native long cpp_relation(String name);
public Relation relation(String n)
{
long rel_h = cpp_relation(n);
if (rel_h==0)
return null;
else
return new Relation(rel_h, this);
}
private native long cpp_create_relation(String name);
public Relation create_relation(String name)
{
long rel_h = cpp_create_relation(name);
if (rel_h==0)
return null;
else
return new Relation(rel_h, this);
}
private native String cpp_load(String filename);
public void load(String filename) throws FileNotFoundException
{
String res = cpp_load(filename);
if (!res.equals(""))
throw new FileNotFoundException(res);
}
private native String cpp_save(String filename, String format);
public void save(String filename, UtteranceFileFormat format) throws IOException
{
String res = cpp_save(filename, format.toString());
if (!res.equals(""))
throw new IOException(res);
}
public void save(String filename) throws IOException
{
save(filename, UtteranceFileFormat.EST_ASCII);
}
private native int cpp_findItem(float time);
public int findItem(float time)
{
return cpp_findItem(time);
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_utterance();
private native boolean destroy_cpp_utterance();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Utterance C++ fails");
}
}

View File

@@ -0,0 +1,88 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// -------------------------------------------------------------------- \\
// Enumerated type of utterance file formats. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est ;
import java.lang.*;
import java.util.*;
import java.awt.*;
import cstr.util.*;
public class UtteranceFileFormat extends Enum
{
static EnumValues values = init("UtteranceFileFormat");
public static UtteranceFileFormat DUMMY = new UtteranceFileFormat("dummy", "Dummy UtteranceFileFormat Value", false);
public static UtteranceFileFormat UNKNOWN = new UtteranceFileFormat("unknown", "Unknown UtteranceFileFormat Value", false);
public static UtteranceFileFormat EST_ASCII = new UtteranceFileFormat("est", "Est (ascii)");
public static UtteranceFileFormat XLABEL = new UtteranceFileFormat("xlabel", "Xwaves Label File");
public static UtteranceFileFormat GENXML = new UtteranceFileFormat("genxml", "Generic XML");
public UtteranceFileFormat(String s, String ls)
{
super(s, ls, null);
}
public UtteranceFileFormat(String s, String ls, boolean real)
{
super(s, ls, real);
}
public EnumValues getValuesTable()
{
return values;
}
public static UtteranceFileFormat getValue(String s)
throws IllegalArgumentException
{
return (UtteranceFileFormat)getValue(s, values);
}
public static Enum [] getValues()
{
return (Enum [])getValues(values);
}
}

View File

@@ -0,0 +1,355 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* */
/* Author: Richard Caley <rjc@cstr.ed.ac.uk> */
/* ------------------------------------------------------------------- */
/* Interface between java and C++ for EST_Wave. */
/* */
/*************************************************************************/
#include <stdio.h>
#include <signal.h>
#include "jni_Wave.h"
#include "EST_Wave.h"
#include "EST_wave_aux.h"
#include "EST_audio.h"
#include "EST_inline_utils.h"
static jobject wave_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>=0?s:-s; }
static EST_Option wave_play_ops;
JNIEXPORT jboolean JNICALL
Java_cstr_est_Wave_initialise_1cpp (JNIEnv *env, jclass myclass)
{
wave_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "cpp_handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Wave_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Wave_create_1cpp_1wave(JNIEnv *env, jobject self)
{
EST_Wave *wave = new EST_Wave;
env->SetLongField(self, handle_field, (jlong)wave);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Wave_destroy_1cpp_1wave (JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
delete wave;
return 1;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Wave_cpp_1name (JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return env->NewStringUTF(wave->name());
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1setName (JNIEnv *env, jobject self, jstring jname)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
const char *name=env->GetStringUTFChars(jname, 0);
wave->set_name(name);
env->ReleaseStringUTFChars(jname, name);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Wave_cpp_1load (JNIEnv *env, jobject self, jstring jfilename)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *res = "";
EST_read_status stat = wave->load(filename);
env->ReleaseStringUTFChars(jfilename, filename);
if (stat == read_format_error)
res = "wave format error";
else if (stat == read_error)
res = "wave load error";
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Wave_cpp_1save (JNIEnv *env, jobject self, jstring jfilename, jstring jformat)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *format = env->GetStringUTFChars(jformat, 0);
const char *res = "";
EST_write_status stat = wave->save(filename, format);
env->ReleaseStringUTFChars(jfilename, filename);
env->ReleaseStringUTFChars(jformat, format);
if (stat == write_error)
res = "wave save error";
return env->NewStringUTF(res);
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1resample (JNIEnv *env, jobject self, jint rate)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
wave->resample(rate);
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1set_1play_1ops(JNIEnv *env, jclass myclass,
jstring jprotocol,
jstring jcommand,
jstring jserver
)
{
(void)myclass;
const char *protocol = env->GetStringUTFChars(jprotocol, 0);
const char *command = env->GetStringUTFChars(jcommand, 0);
const char *server = env->GetStringUTFChars(jserver, 0);
if (*protocol)
wave_play_ops.add_item("-p",protocol);
if (*command)
wave_play_ops.add_item("-command",command);
if (*server)
wave_play_ops.add_item("-display",server);
wave_play_ops.add_item("-otype","riff");
env->ReleaseStringUTFChars(jprotocol, protocol);
env->ReleaseStringUTFChars(jcommand, command);
env->ReleaseStringUTFChars(jserver, server);
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1play (JNIEnv *env, jobject self,
jfloat start_t, jfloat end_t)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
EST_Wave wv;
int start = (int)(start_t * wave->sample_rate() + 0.5);
int end = (int)(end_t * wave->sample_rate() + 0.5);
wave_subwave(wv, *wave, start, end-start);
// EST_write_status st = wv.save("/tmp/est_java_wave", "nist");
play_wave(wv, wave_play_ops);
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1play_1all (JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
play_wave(*wave, wave_play_ops);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1num_1channels(JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return wave->num_channels();
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1num_1samples(JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return wave->num_samples();
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1sample_1rate(JNIEnv *env, jobject self)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return wave->sample_rate();
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1amplitude(JNIEnv *env, jobject self,
jint c)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
short a=0;
for(int i=0; i<wave->num_samples(); i++)
{
short p = wave->a(i,c);
if (abs(p) > a)
a=abs(p);
}
return a;
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_a__II(JNIEnv *env, jobject self,
jint x,
jint c)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return wave->a(x,c);
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_a__FI(JNIEnv *env, jobject self,
jfloat t,
jint c)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
return wave->a(irint(t*wave->sample_rate()),c);
}
JNIEXPORT void JNICALL
Java_cstr_est_Wave_cpp_1getScanlines(JNIEnv *env, jobject self,
jint c,
jbyteArray line,
jint lstart, jint lnum,
jint xoff, jint chunk,
jint width, jint height,
jint amp)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
jbyte *pixels = env->GetByteArrayElements(line, 0);
int num_samples = wave->num_samples();
short *data = wave->values().memory();
int channels = wave->num_channels();
for(int l=lstart; l<lstart+lnum; l++)
{
int min = (int)((float)(height - l)*amp*2.0/height-amp+0.5);
int max = (int)((float)(height - l+1)*amp*2.0/height-amp+0.5);
jbyte *lpixels = pixels + (l-lstart)*chunk;
short la=0;
int from=(int)((float)xoff*num_samples/width+0.5);
for(int i=xoff; i<xoff+chunk; i++)
{
int fl=0;
int to = (int)((i+1.0)*num_samples/width+0.5);
for(int j=from; j<to; j++)
{
short a = data[j*channels + c];
if ((a>min && la <=max)|| (la > min && a <=max))
fl++;
la=a;
}
lpixels[i-xoff] = fl<5?fl:4;
from=to;
}
}
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1getMin(JNIEnv *env, jobject self,
jint c, jint x1, jint x2)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
int minv=64000;
if (x1<0) x1 = 0;
if (x2>wave->num_samples()) x2 = wave->num_samples();
for(int x=x1; x<x2; x++)
{
short v = wave->a(x,c);
if (v<minv)
minv=v;
}
return minv;
}
JNIEXPORT jint JNICALL
Java_cstr_est_Wave_cpp_1getMax(JNIEnv *env, jobject self,
jint c, jint x1, jint x2)
{
EST_Wave *wave = (EST_Wave *) env->GetLongField(self, handle_field);
int maxv=-64000;
if (x1<0) x1 = 0;
if (x2>wave->num_samples()) x2 = wave->num_samples();
for(int x=x1; x<x2; x++)
{
short v = wave->a(x, c);
if (v>maxv)
maxv=v;
}
return maxv;
}

View File

@@ -0,0 +1,227 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Friday 12th September 1997 \\
// -------------------------------------------------------------------- \\
// Wrapper around the EST_Wave class. This is pretty horrible in that \\
// it uses a long to hold a pointer to a wave. There must be a better \\
// way. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Wave
{
long cpp_handle;
int [] amplitudes;
public Wave()
{
create_cpp_wave();
}
public Wave(byte [] bytes)
throws UnsupportedEncodingException
{
if (!parse(bytes))
{
throw new UnsupportedEncodingException("Can't create Wave from this bytestream");
}
}
public Wave(File file)
throws UnsupportedEncodingException, IOException
{
throw new IOException("Can't load from files yet");
}
protected void finalize() throws Throwable
{
destroy_cpp_wave();
super.finalize();
}
public long getHandle()
{
return cpp_handle;
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
private native void cpp_setName(String name);
public void setName(String name)
{
cpp_setName(name);
}
public String getName()
{
return cpp_name();
}
private native String cpp_load(String filename);
public void load(String filename) throws FileNotFoundException
{
String res = cpp_load(filename);
if (!res.equals(""))
throw new FileNotFoundException(res);
amplitudes = new int[num_channels()];
}
private native String cpp_save(String filename, String format);
public void save(String filename, String format) throws IOException
{
String res = cpp_save(filename, format);
if (!res.equals(""))
throw new IOException(res);
}
private native void cpp_resample(int rate);
public void resample(int rate)
{
cpp_resample(rate);
}
private static native void cpp_set_play_ops(String protocol,
String command,
String server);
public static void set_play_ops(String protocol,
String command,
String server)
{
cpp_set_play_ops(protocol, command, server);
}
private native void cpp_play(float start, float end);
public void play(float start, float end)
{
System.out.println("play st");
if (end > start)
cpp_play(start, end);
System.out.println("play end");
}
private native void cpp_play_all();
public void play()
{
cpp_play_all();
}
private native int cpp_num_samples();
public int num_samples()
{
return cpp_num_samples();
}
private native int cpp_num_channels();
public int num_channels()
{
return cpp_num_channels();
}
private native int cpp_sample_rate();
public int sample_rate()
{
return cpp_sample_rate();
}
private native int cpp_amplitude(int c);
public int amplitude(int c)
{
if (amplitudes[c] > 0)
return amplitudes[c];
int a = cpp_amplitude(c);
amplitudes[c] = a;
return a;
}
public native int a(int x, int c);
public native int a(float t, int c);
native public void cpp_getScanlines(int c,
byte[] line,
int lstart, int lnum,
int x, int chunk,
int width, int height,
int amplitude
);
public boolean parse(byte[] bytes)
{
return false;
}
native public final int cpp_getMin(int c, int x1, int x2);
native public final int cpp_getMax(int c, int x1, int x2);
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_wave();
private native boolean destroy_cpp_wave();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Wave C++ fails");
}
}

View File

@@ -0,0 +1,135 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
#include <stdio.h>
#include "jni_Skeleton.h"
#include "ling_class/EST_Skeleton.h"
static jobject skeleton_class;
static jfieldID handle_field;
static inline short abs(short s) { return s>0?s:-s; }
JNIEXPORT jboolean JNICALL
Java_cstr_est_Skeleton_initialise_1cpp (JNIEnv *env, jclass myclass)
{
skeleton_class = env->NewGlobalRef(myclass);
handle_field = env->GetFieldID(myclass, "handle", "J");
if (!handle_field)
{
printf("can't find handle!\n");
return 0;
}
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Skeleton_finalise_1cpp (JNIEnv *env, jclass myclass)
{
(void)env;
(void)myclass;
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Skeleton_create_11skeleton(JNIEnv *env, jobject self)
{
EST_Skeleton *skeleton = new EST_Skeleton;
// printf("create skeleton %p\n", skeleton);
env->SetLongField(self, handle_field, (jlong)skeleton);
return 1;
}
JNIEXPORT jboolean JNICALL
Java_cstr_est_Skeleton_destroy_11skeleton (JNIEnv *env, jobject self)
{
EST_Skeleton *skeleton = (EST_Skeleton *) env->GetLongField(self, handle_field);
// printf("destroy skeleton %p\n", skeleton);
delete skeleton;
return 1;
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Skeleton_1name(JNIEnv *env, jobject self)
{
EST_Skeleton *skeleton = (EST_Skeleton *) env->GetLongField(self, handle_field);
return env->NewStringUTF(skeleton->name());
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Skeleton_1load (JNIEnv *env, jobject self, jstring jfilename)
{
EST_Skeleton *skeleton = (EST_Skeleton *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *res = "";
EST_read_status stat = skeleton->load(filename);
env->ReleaseStringUTFChars(jfilename, filename);
if (stat == read_format_error)
res = "skeleton format error";
else if (stat == read_error)
res = "skeleton load error";
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL
Java_cstr_est_Skeleton_1save (JNIEnv *env, jobject self, jstring jfilename, jstring jformat)
{
const EST_Skeleton *skeleton = (EST_Skeleton *) env->GetLongField(self, handle_field);
const char *filename = env->GetStringUTFChars(jfilename, 0);
const char *format = env->GetStringUTFChars(jformat, 0);
const char *res = "";
EST_write_status stat = skeleton->save(filename,format);
env->ReleaseStringUTFChars(jfilename, filename);
env->ReleaseStringUTFChars(jformat, format);
if (stat == write_error)
res = "skeleton save error";
return env->NewStringUTF(res);
}

View File

@@ -0,0 +1,105 @@
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Tue Mar 31 1998 \\
// -------------------------------------------------------------------- \\
// Java wrapper around relations. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est.cpp ;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.io.*;
public class skeleton
{
private long cpp_handle;
public Skeleton()
{
create_cpp_utterance();
}
protected void finalize() throws Throwable
{
destroy_cpp_utterance();
super.finalize();
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
private native String cpp_load(String filename);
public void load(String filename) throws FileNotFoundException
{
String res = cpp_load(filename);
if (!res.equals(""))
throw new FileNotFoundException(res);
}
private native int cpp_findItem(float time);
public int findItem(float time)
{
return cpp_findItem(time);
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_utterance();
private native boolean destroy_cpp_utterance();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Skeleton C++ fails");
}
}