mas01mj@722
|
1 package org.omras2;
|
mas01mj@722
|
2
|
mas01mj@722
|
3 import java.io.File;
|
mas01mj@727
|
4 import java.util.Vector;
|
mas01mj@722
|
5
|
mas01mj@722
|
6 public class AudioDB
|
mas01mj@722
|
7 {
|
mas01mj@722
|
8 public native boolean audiodb_create(String path, int datasize, int ntracks, int datadim);
|
mas01mj@722
|
9 public native boolean audiodb_open(String path, Mode mode);
|
mas01mj@725
|
10 public native void audiodb_close();
|
mas01mj@724
|
11 public native Status audiodb_status();
|
mas01mj@725
|
12 public native boolean audiodb_insert_path(String key, String features, String power, String times);
|
mas01mj@727
|
13 public native Vector<Result> audiodb_query_by_key(String key, Query config);
|
mas01mj@722
|
14
|
mas01mj@725
|
15 public enum Mode { O_RDONLY, O_RDWR }
|
mas01mj@722
|
16
|
mas01mj@722
|
17 private File path;
|
mas01mj@724
|
18 private long adbHandle;
|
mas01mj@722
|
19
|
mas01mj@722
|
20 public AudioDB(File path)
|
mas01mj@722
|
21 {
|
mas01mj@722
|
22 this.path = path;
|
mas01mj@722
|
23 }
|
mas01mj@722
|
24
|
mas01mj@725
|
25 public void close()
|
mas01mj@725
|
26 {
|
mas01mj@725
|
27 audiodb_close();
|
mas01mj@725
|
28 }
|
mas01mj@725
|
29
|
mas01mj@725
|
30 public boolean insert(File features)
|
mas01mj@725
|
31 {
|
mas01mj@725
|
32 return audiodb_insert_path(null, features.getPath(), null, null);
|
mas01mj@725
|
33 }
|
mas01mj@725
|
34
|
mas01mj@725
|
35 public boolean insert(String key, File features)
|
mas01mj@725
|
36 {
|
mas01mj@725
|
37 return audiodb_insert_path(key, features.getPath(), null, null);
|
mas01mj@725
|
38 }
|
mas01mj@725
|
39
|
mas01mj@725
|
40 public boolean insert(String key, File features, File power, File times)
|
mas01mj@725
|
41 {
|
mas01mj@725
|
42 return audiodb_insert_path(key, features.getPath(), (power == null ? null : power.getPath()), (times == null ? null : times.getPath()));
|
mas01mj@725
|
43 }
|
mas01mj@725
|
44
|
mas01mj@722
|
45 public boolean create(int datasize, int ntracks, int datadim)
|
mas01mj@722
|
46 {
|
mas01mj@722
|
47 return audiodb_create(path.toString(), datasize, ntracks, datadim);
|
mas01mj@722
|
48 }
|
mas01mj@722
|
49
|
mas01mj@722
|
50 public boolean open(Mode mode)
|
mas01mj@722
|
51 {
|
mas01mj@722
|
52 return audiodb_open(path.toString(), mode);
|
mas01mj@722
|
53 }
|
mas01mj@722
|
54
|
mas01mj@727
|
55 public Vector<Result> query(String key, Query config)
|
mas01mj@726
|
56 {
|
mas01mj@727
|
57 return audiodb_query_by_key(key, config);
|
mas01mj@726
|
58 }
|
mas01mj@726
|
59
|
mas01mj@724
|
60 public Status getStatus()
|
mas01mj@722
|
61 {
|
mas01mj@724
|
62 return audiodb_status();
|
mas01mj@722
|
63 }
|
mas01mj@722
|
64
|
mas01mj@722
|
65 static {
|
mas01mj@722
|
66 System.loadLibrary("AudioDB_JNI");
|
mas01mj@722
|
67 }
|
mas01mj@722
|
68
|
mas01mj@722
|
69
|
mas01mj@722
|
70 public static void main(String args[])
|
mas01mj@722
|
71 {
|
mas01mj@722
|
72 AudioDB testDB = new AudioDB(new File("test.adb"));
|
mas01mj@722
|
73 testDB.create(5, 5, 12);
|
mas01mj@725
|
74 testDB.open(Mode.O_RDWR);
|
mas01mj@725
|
75 testDB.insert(new File("testfiles/testfeature"));
|
mas01mj@724
|
76 Status status = testDB.getStatus();
|
mas01mj@724
|
77 System.out.println("Num files: "+status.getNumFiles());
|
mas01mj@725
|
78 testDB.close();
|
mas01mj@722
|
79 }
|
mas01mj@722
|
80 }
|
mas01mj@722
|
81
|
mas01mj@722
|
82
|