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@728
|
13 public native boolean audiodb_insert_data(String key, int nvectors, int dim, double[] features, double[] power, double[] times);
|
mas01mj@729
|
14 public native Vector<Result> audiodb_query(String key, Query config);
|
mas01mj@722
|
15
|
mas01mj@725
|
16 public enum Mode { O_RDONLY, O_RDWR }
|
mas01mj@722
|
17
|
mas01mj@722
|
18 private File path;
|
mas01mj@724
|
19 private long adbHandle;
|
mas01mj@722
|
20
|
mas01mj@722
|
21 public AudioDB(File path)
|
mas01mj@722
|
22 {
|
mas01mj@722
|
23 this.path = path;
|
mas01mj@722
|
24 }
|
mas01mj@722
|
25
|
mas01mj@725
|
26 public void close()
|
mas01mj@725
|
27 {
|
mas01mj@725
|
28 audiodb_close();
|
mas01mj@725
|
29 }
|
mas01mj@725
|
30
|
mas01mj@725
|
31 public boolean insert(File features)
|
mas01mj@725
|
32 {
|
mas01mj@728
|
33 return insert(null, features, null, null);
|
mas01mj@725
|
34 }
|
mas01mj@725
|
35
|
mas01mj@725
|
36 public boolean insert(String key, File features)
|
mas01mj@725
|
37 {
|
mas01mj@728
|
38 return insert(key, features, null, null);
|
mas01mj@728
|
39 }
|
mas01mj@728
|
40
|
mas01mj@728
|
41 public boolean insert(String key, File features, File power)
|
mas01mj@728
|
42 {
|
mas01mj@728
|
43 return insert(key, features, power, null);
|
mas01mj@725
|
44 }
|
mas01mj@725
|
45
|
mas01mj@725
|
46 public boolean insert(String key, File features, File power, File times)
|
mas01mj@725
|
47 {
|
mas01mj@725
|
48 return audiodb_insert_path(key, features.getPath(), (power == null ? null : power.getPath()), (times == null ? null : times.getPath()));
|
mas01mj@725
|
49 }
|
mas01mj@728
|
50
|
mas01mj@728
|
51 public boolean insert(String key, int nvectors, int dim, double[] features)
|
mas01mj@728
|
52 {
|
mas01mj@728
|
53 return insert(key, nvectors, dim, features, null, null);
|
mas01mj@728
|
54 }
|
mas01mj@725
|
55
|
mas01mj@728
|
56 public boolean insert(String key, int nvectors, int dim, double[] features, double[] power)
|
mas01mj@728
|
57 {
|
mas01mj@728
|
58 return insert(key, nvectors, dim, features, power, null);
|
mas01mj@728
|
59 }
|
mas01mj@728
|
60
|
mas01mj@728
|
61 public boolean insert(String key, int nvectors, int dim, double[] features, double[] power, double[] times)
|
mas01mj@728
|
62 {
|
mas01mj@728
|
63 return audiodb_insert_data(key, nvectors, dim, features, power, times);
|
mas01mj@728
|
64 }
|
mas01mj@728
|
65
|
mas01mj@722
|
66 public boolean create(int datasize, int ntracks, int datadim)
|
mas01mj@722
|
67 {
|
mas01mj@722
|
68 return audiodb_create(path.toString(), datasize, ntracks, datadim);
|
mas01mj@722
|
69 }
|
mas01mj@722
|
70
|
mas01mj@722
|
71 public boolean open(Mode mode)
|
mas01mj@722
|
72 {
|
mas01mj@722
|
73 return audiodb_open(path.toString(), mode);
|
mas01mj@722
|
74 }
|
mas01mj@729
|
75
|
mas01mj@729
|
76 public Vector<Result> query(Query config)
|
mas01mj@729
|
77 {
|
mas01mj@729
|
78 return audiodb_query(null, config);
|
mas01mj@729
|
79 }
|
mas01mj@722
|
80
|
mas01mj@727
|
81 public Vector<Result> query(String key, Query config)
|
mas01mj@726
|
82 {
|
mas01mj@729
|
83 return audiodb_query(key, config);
|
mas01mj@726
|
84 }
|
mas01mj@726
|
85
|
mas01mj@724
|
86 public Status getStatus()
|
mas01mj@722
|
87 {
|
mas01mj@724
|
88 return audiodb_status();
|
mas01mj@722
|
89 }
|
mas01mj@722
|
90
|
mas01mj@722
|
91 static {
|
mas01mj@722
|
92 System.loadLibrary("AudioDB_JNI");
|
mas01mj@722
|
93 }
|
mas01mj@722
|
94
|
mas01mj@722
|
95
|
mas01mj@722
|
96 public static void main(String args[])
|
mas01mj@722
|
97 {
|
mas01mj@722
|
98 AudioDB testDB = new AudioDB(new File("test.adb"));
|
mas01mj@722
|
99 testDB.create(5, 5, 12);
|
mas01mj@725
|
100 testDB.open(Mode.O_RDWR);
|
mas01mj@725
|
101 testDB.insert(new File("testfiles/testfeature"));
|
mas01mj@724
|
102 Status status = testDB.getStatus();
|
mas01mj@724
|
103 System.out.println("Num files: "+status.getNumFiles());
|
mas01mj@725
|
104 testDB.close();
|
mas01mj@722
|
105 }
|
mas01mj@722
|
106 }
|
mas01mj@722
|
107
|
mas01mj@722
|
108
|