annotate audioDB_API.h @ 468:4dbd7917bf9e api-inversion

YAY! audioDB::index_query_loop is now disentangled. Hardwired lsh_in_core to true, and invented a new QID flag for !lsh_exact. All tests continue to pass. The plans now: - extract the audiodb_query_spec() function from inside audioDB::query, and move audioDB::query (and the timestamps function) to audioDB.cpp; - write libtests/0036 and libtests/0037 in terms of audiodb_query_spec(); - rewrite all the other libtests in terms of audiodb_query_spec(); - delete audiodb_query() [ and maybe rename audiodb_query_spec(), I dunno]; - implement example bindings (probably to Lisp, because that's what I know best); - see if anyone other than me can work out how the API works. If not, provide documentation; - revise API in the light of user feedback.
author mas01cr
date Wed, 31 Dec 2008 15:44:12 +0000
parents fcc6f7c4856b
children d3afc91d205d
rev   line source
mas01cr@421 1 #ifndef AUDIODB_API_H
mas01cr@421 2 #define AUDIODB_API_H
mas01cr@421 3
mas01cr@392 4 #include <stdbool.h>
mas01cr@398 5 #include <stdint.h>
mas01cr@398 6
mas01ik@355 7 /* for API questions contact
mas01ik@355 8 * Christophe Rhodes c.rhodes@gold.ac.uk
mas01ik@355 9 * Ian Knopke mas01ik@gold.ac.uk, ian.knopke@gmail.com */
mas01ik@355 10
mas01cr@392 11 /* Temporary workarounds */
mas01cr@388 12 typedef struct dbTableHeader adb_header_t;
mas01cr@392 13 int acquire_lock(int, bool);
mas01cr@388 14
mas01cr@400 15
mas01cr@401 16 /*******************************************************************/
mas01cr@401 17 /* Data types for API */
mas01cr@400 18
mas01ik@355 19 /* The main struct that stores the name of the database, and in future will hold all
mas01ik@355 20 * kinds of other interesting information */
mas01ik@355 21 /* This basically gets passed around to all of the other functions */
mas01cr@388 22
mas01cr@388 23 /* FIXME: it might be that "adb_" isn't such a good prefix to use, and
mas01cr@419 24 that we should prefer "audiodb_". Or else maybe we should be
mas01cr@419 25 calling ourselves libadb? */
mas01ik@355 26 typedef struct adb adb_t, *adb_ptr;
mas01ik@355 27
mas01cr@404 28 struct adb_datum {
mas01cr@404 29 uint32_t nvectors;
mas01cr@404 30 uint32_t dim;
mas01cr@404 31 const char *key;
mas01cr@404 32 double *data;
mas01cr@404 33 double *power;
mas01cr@404 34 double *times;
mas01cr@404 35 };
mas01cr@404 36 typedef struct adb_datum adb_datum_t;
mas01cr@404 37
mas01ik@355 38 //used for both insert and batchinsert
mas01ik@355 39 struct adbinsert {
mas01cr@405 40 const char *features;
mas01cr@405 41 const char *power;
mas01cr@405 42 const char *key;
mas01cr@405 43 const char *times;
mas01ik@355 44 };
mas01cr@441 45 typedef struct adbinsert adb_insert_t, adb_reference_t, *adb_insert_ptr;
mas01ik@355 46
mas01ik@355 47 /* struct for returning status results */
mas01ik@355 48 struct adbstatus {
mas01ik@355 49 unsigned int numFiles;
mas01ik@355 50 unsigned int dim;
mas01ik@355 51 unsigned int dudCount;
mas01ik@355 52 unsigned int nullCount;
mas01ik@355 53 unsigned int flags;
mas01cr@398 54 uint64_t length;
mas01cr@398 55 uint64_t data_region_size;
mas01ik@355 56 };
mas01ik@355 57 typedef struct adbstatus adb_status_t, *adb_status_ptr;
mas01ik@355 58
mas01ik@355 59 /* needed for constructing a query */
mas01ik@355 60 struct adbquery {
mas01ik@355 61
mas01ik@355 62 char * querytype;
mas01ik@355 63 char * feature; //usually a file of some kind
mas01ik@355 64 char * power; //also a file
mas01ik@355 65 char * keylist; //also a file
mas01ik@355 66 char * qpoint; //position
mas01ik@355 67 char * numpoints;
mas01ik@355 68 char * radius;
mas01ik@355 69 char * resultlength; //how many results to make
mas01ik@355 70 char * sequencelength;
mas01ik@355 71 char * sequencehop;
mas01ik@355 72 double absolute_threshold;
mas01ik@355 73 double relative_threshold;
mas01ik@355 74 int exhaustive; //hidden option in gengetopt
mas01ik@355 75 double expandfactor; //hidden
mas01ik@355 76 int rotate; //hidden
mas01ik@355 77
mas01ik@355 78 };
mas01ik@355 79 typedef struct adbquery adb_query_t,*adb_query_ptr;
mas01ik@355 80
mas01ik@355 81 /* ... and for getting query results back */
mas01ik@355 82 struct adbqueryresult {
mas01ik@355 83
mas01ik@355 84 int sizeRlist; /* do I really need to return all 4 sizes here */
mas01ik@355 85 int sizeDist;
mas01ik@355 86 int sizeQpos;
mas01ik@355 87 int sizeSpos;
mas01ik@355 88 char **Rlist;
mas01ik@355 89 double *Dist;
mas01ik@355 90 unsigned int *Qpos;
mas01ik@355 91 unsigned int *Spos;
mas01ik@355 92
mas01ik@355 93 };
mas01ik@355 94 typedef struct adbqueryresult adb_queryresult_t, *adb_queryresult_ptr;
mas01ik@355 95
mas01cr@419 96 /* New ("new" == December 2008) query API */
mas01cr@419 97
mas01cr@419 98 typedef struct adbresult {
mas01cr@419 99 const char *key;
mas01cr@419 100 double dist;
mas01cr@419 101 uint32_t qpos;
mas01cr@419 102 uint32_t ipos;
mas01cr@419 103 } adb_result_t;
mas01cr@419 104
mas01cr@453 105 #define ADB_REFINE_INCLUDE_KEYLIST 1
mas01cr@453 106 #define ADB_REFINE_EXCLUDE_KEYLIST 2
mas01cr@453 107 #define ADB_REFINE_RADIUS 4
mas01cr@453 108 #define ADB_REFINE_ABSOLUTE_THRESHOLD 8
mas01cr@453 109 #define ADB_REFINE_RELATIVE_THRESHOLD 16
mas01cr@453 110 #define ADB_REFINE_DURATION_RATIO 32
mas01cr@453 111 #define ADB_REFINE_HOP_SIZE 64
mas01cr@453 112
mas01cr@453 113 typedef struct adbkeylist {
mas01cr@453 114 uint32_t nkeys;
mas01cr@453 115 const char **keys;
mas01cr@453 116 } adb_keylist_t;
mas01cr@419 117
mas01cr@419 118 typedef struct adbqueryrefine {
mas01cr@419 119 uint32_t flags;
mas01cr@453 120 adb_keylist_t include;
mas01cr@453 121 adb_keylist_t exclude;
mas01cr@419 122 double radius;
mas01cr@419 123 double absolute_threshold;
mas01cr@419 124 double relative_threshold;
mas01cr@419 125 double duration_ratio; /* expandfactor */
mas01cr@419 126 uint32_t hopsize;
mas01cr@419 127 } adb_query_refine_t;
mas01cr@419 128
mas01cr@419 129 #define ADB_ACCUMULATION_DB 1
mas01cr@419 130 #define ADB_ACCUMULATION_PER_TRACK 2
mas01cr@419 131 #define ADB_ACCUMULATION_ONE_TO_ONE 3
mas01cr@419 132
mas01cr@419 133 #define ADB_DISTANCE_DOT_PRODUCT 1
mas01cr@419 134 #define ADB_DISTANCE_EUCLIDEAN_NORMED 2
mas01cr@419 135 #define ADB_DISTANCE_EUCLIDEAN 3
mas01cr@419 136
mas01cr@419 137 typedef struct adbqueryparameters {
mas01cr@419 138 uint32_t accumulation;
mas01cr@419 139 uint32_t distance;
mas01cr@419 140 uint32_t npoints;
mas01cr@419 141 uint32_t ntracks;
mas01cr@419 142 } adb_query_parameters_t;
mas01cr@419 143
mas01cr@419 144 typedef struct adbqueryresults {
mas01cr@419 145 uint32_t nresults;
mas01cr@419 146 adb_result_t *results;
mas01cr@419 147 } adb_query_results_t;
mas01cr@419 148
mas01cr@468 149 #define ADB_QID_FLAG_EXHAUSTIVE 1
mas01cr@468 150 #define ADB_QID_FLAG_ALLOW_FALSE_POSITIVES 2
mas01cr@434 151
mas01cr@419 152 typedef struct adbqueryid {
mas01cr@419 153 adb_datum_t *datum;
mas01cr@419 154 uint32_t sequence_length;
mas01cr@434 155 uint32_t flags;
mas01cr@419 156 uint32_t sequence_start;
mas01cr@419 157 } adb_query_id_t;
mas01cr@419 158
mas01cr@419 159 typedef struct adbqueryspec {
mas01cr@419 160 adb_query_id_t qid;
mas01cr@435 161 adb_query_parameters_t params;
mas01cr@435 162 adb_query_refine_t refine;
mas01cr@419 163 } adb_query_spec_t;
mas01ik@355 164
mas01ik@355 165 /*******************************************************************/
mas01ik@355 166 /* Function prototypes for API */
mas01ik@355 167
mas01ik@355 168 /* open an existing database */
mas01ik@355 169 /* returns a struct or NULL on failure */
mas01cr@392 170 adb_ptr audiodb_open(const char *path, int flags);
mas01ik@355 171
mas01ik@355 172 /* create a new database */
mas01ik@355 173 /* returns a struct or NULL on failure */
mas01cr@381 174 adb_ptr audiodb_create(const char *path, unsigned datasize, unsigned ntracks, unsigned datadim);
mas01ik@355 175
mas01ik@355 176 /* close a database */
mas01ik@355 177 void audiodb_close(adb_ptr db);
mas01ik@355 178
mas01ik@355 179 /* You'll need to turn both of these on to do anything useful */
mas01ik@355 180 int audiodb_l2norm(adb_ptr mydb);
mas01ik@355 181 int audiodb_power(adb_ptr mydb);
mas01ik@355 182
mas01ik@355 183 /* insert functions */
mas01cr@404 184 int audiodb_insert_datum(adb_t *, adb_datum_t *);
mas01cr@441 185 int audiodb_insert_reference(adb_t *, adb_reference_t *);
mas01ik@355 186 int audiodb_insert(adb_ptr mydb, adb_insert_ptr ins);
mas01ik@355 187 int audiodb_batchinsert(adb_ptr mydb, adb_insert_ptr ins, unsigned int size);
mas01ik@355 188
mas01ik@355 189 /* query function */
mas01ik@355 190 int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqres);
mas01cr@455 191 int audiodb_query_spec(adb_t *, adb_query_spec_t *, adb_query_results_t *);
mas01cr@459 192 int audiodb_query_free_results(adb_t *, adb_query_spec_t *, adb_query_results_t *);
mas01cr@419 193
mas01ik@355 194 /* database status */
mas01ik@355 195 int audiodb_status(adb_ptr mydb, adb_status_ptr status);
mas01ik@355 196
mas01ik@355 197 /* varoius dump formats */
mas01cr@399 198 int audiodb_dump(adb_ptr mydb, const char *outputdir);
mas01cr@421 199
mas01cr@421 200 #endif