annotate audioDB_API.h @ 496:8fb85fbcaba6 api-inversion

Mostly disentangle API from command-line binary. Now audioDB.cpp doesn't need to be included in the library, because nothing the library does creates an audioDB instance. Hooray. We can't disentangle the other way, because there's still plenty in the command-line binary that isn't implemented in terms of the API, so the audioDB binary code needs to know naughty stuff about the library's internals (e.g. what the file header looks like). Remove liszt.o and sample.o from the library, even though they'll probably make a reapparance soon (for scare-quoted values of "soon") Remove cmdline.o and common.o from the library, not scheduled to make a reapparence ever (hooray!). Separate out the bits that are used in the library -- locks and PointPairs -- into their own files.
author mas01cr
date Sat, 10 Jan 2009 15:33:25 +0000
parents b2fd8113d8bc
children
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@496 14 int divest_lock(int);
mas01cr@388 15
mas01cr@400 16
mas01cr@401 17 /*******************************************************************/
mas01cr@401 18 /* Data types for API */
mas01cr@400 19
mas01ik@355 20 /* The main struct that stores the name of the database, and in future will hold all
mas01ik@355 21 * kinds of other interesting information */
mas01ik@355 22 /* This basically gets passed around to all of the other functions */
mas01cr@388 23
mas01cr@388 24 /* FIXME: it might be that "adb_" isn't such a good prefix to use, and
mas01cr@419 25 that we should prefer "audiodb_". Or else maybe we should be
mas01cr@419 26 calling ourselves libadb? */
mas01ik@355 27 typedef struct adb adb_t, *adb_ptr;
mas01ik@355 28
mas01cr@404 29 struct adb_datum {
mas01cr@404 30 uint32_t nvectors;
mas01cr@404 31 uint32_t dim;
mas01cr@404 32 const char *key;
mas01cr@404 33 double *data;
mas01cr@404 34 double *power;
mas01cr@404 35 double *times;
mas01cr@404 36 };
mas01cr@404 37 typedef struct adb_datum adb_datum_t;
mas01cr@404 38
mas01ik@355 39 //used for both insert and batchinsert
mas01ik@355 40 struct adbinsert {
mas01cr@405 41 const char *features;
mas01cr@405 42 const char *power;
mas01cr@405 43 const char *key;
mas01cr@405 44 const char *times;
mas01ik@355 45 };
mas01cr@441 46 typedef struct adbinsert adb_insert_t, adb_reference_t, *adb_insert_ptr;
mas01ik@355 47
mas01ik@355 48 /* struct for returning status results */
mas01ik@355 49 struct adbstatus {
mas01ik@355 50 unsigned int numFiles;
mas01ik@355 51 unsigned int dim;
mas01ik@355 52 unsigned int dudCount;
mas01ik@355 53 unsigned int nullCount;
mas01ik@355 54 unsigned int flags;
mas01cr@398 55 uint64_t length;
mas01cr@398 56 uint64_t data_region_size;
mas01ik@355 57 };
mas01ik@355 58 typedef struct adbstatus adb_status_t, *adb_status_ptr;
mas01ik@355 59
mas01ik@355 60 /* needed for constructing a query */
mas01ik@355 61 struct adbquery {
mas01ik@355 62
mas01ik@355 63 char * querytype;
mas01ik@355 64 char * feature; //usually a file of some kind
mas01ik@355 65 char * power; //also a file
mas01ik@355 66 char * keylist; //also a file
mas01ik@355 67 char * qpoint; //position
mas01ik@355 68 char * numpoints;
mas01ik@355 69 char * radius;
mas01ik@355 70 char * resultlength; //how many results to make
mas01ik@355 71 char * sequencelength;
mas01ik@355 72 char * sequencehop;
mas01ik@355 73 double absolute_threshold;
mas01ik@355 74 double relative_threshold;
mas01ik@355 75 int exhaustive; //hidden option in gengetopt
mas01ik@355 76 double expandfactor; //hidden
mas01ik@355 77 int rotate; //hidden
mas01ik@355 78
mas01ik@355 79 };
mas01ik@355 80 typedef struct adbquery adb_query_t,*adb_query_ptr;
mas01ik@355 81
mas01ik@355 82 /* ... and for getting query results back */
mas01ik@355 83 struct adbqueryresult {
mas01ik@355 84
mas01ik@355 85 int sizeRlist; /* do I really need to return all 4 sizes here */
mas01ik@355 86 int sizeDist;
mas01ik@355 87 int sizeQpos;
mas01ik@355 88 int sizeSpos;
mas01ik@355 89 char **Rlist;
mas01ik@355 90 double *Dist;
mas01ik@355 91 unsigned int *Qpos;
mas01ik@355 92 unsigned int *Spos;
mas01ik@355 93
mas01ik@355 94 };
mas01ik@355 95 typedef struct adbqueryresult adb_queryresult_t, *adb_queryresult_ptr;
mas01ik@355 96
mas01cr@419 97 /* New ("new" == December 2008) query API */
mas01cr@419 98
mas01cr@419 99 typedef struct adbresult {
mas01cr@419 100 const char *key;
mas01cr@419 101 double dist;
mas01cr@419 102 uint32_t qpos;
mas01cr@419 103 uint32_t ipos;
mas01cr@419 104 } adb_result_t;
mas01cr@419 105
mas01cr@453 106 #define ADB_REFINE_INCLUDE_KEYLIST 1
mas01cr@453 107 #define ADB_REFINE_EXCLUDE_KEYLIST 2
mas01cr@453 108 #define ADB_REFINE_RADIUS 4
mas01cr@453 109 #define ADB_REFINE_ABSOLUTE_THRESHOLD 8
mas01cr@453 110 #define ADB_REFINE_RELATIVE_THRESHOLD 16
mas01cr@453 111 #define ADB_REFINE_DURATION_RATIO 32
mas01cr@453 112 #define ADB_REFINE_HOP_SIZE 64
mas01cr@453 113
mas01cr@453 114 typedef struct adbkeylist {
mas01cr@453 115 uint32_t nkeys;
mas01cr@453 116 const char **keys;
mas01cr@453 117 } adb_keylist_t;
mas01cr@419 118
mas01cr@419 119 typedef struct adbqueryrefine {
mas01cr@419 120 uint32_t flags;
mas01cr@453 121 adb_keylist_t include;
mas01cr@453 122 adb_keylist_t exclude;
mas01cr@419 123 double radius;
mas01cr@419 124 double absolute_threshold;
mas01cr@419 125 double relative_threshold;
mas01cr@419 126 double duration_ratio; /* expandfactor */
mas01cr@419 127 uint32_t hopsize;
mas01cr@419 128 } adb_query_refine_t;
mas01cr@419 129
mas01cr@419 130 #define ADB_ACCUMULATION_DB 1
mas01cr@419 131 #define ADB_ACCUMULATION_PER_TRACK 2
mas01cr@419 132 #define ADB_ACCUMULATION_ONE_TO_ONE 3
mas01cr@419 133
mas01cr@419 134 #define ADB_DISTANCE_DOT_PRODUCT 1
mas01cr@419 135 #define ADB_DISTANCE_EUCLIDEAN_NORMED 2
mas01cr@419 136 #define ADB_DISTANCE_EUCLIDEAN 3
mas01cr@419 137
mas01cr@419 138 typedef struct adbqueryparameters {
mas01cr@419 139 uint32_t accumulation;
mas01cr@419 140 uint32_t distance;
mas01cr@419 141 uint32_t npoints;
mas01cr@419 142 uint32_t ntracks;
mas01cr@419 143 } adb_query_parameters_t;
mas01cr@419 144
mas01cr@419 145 typedef struct adbqueryresults {
mas01cr@419 146 uint32_t nresults;
mas01cr@419 147 adb_result_t *results;
mas01cr@419 148 } adb_query_results_t;
mas01cr@419 149
mas01cr@468 150 #define ADB_QID_FLAG_EXHAUSTIVE 1
mas01cr@468 151 #define ADB_QID_FLAG_ALLOW_FALSE_POSITIVES 2
mas01cr@434 152
mas01cr@419 153 typedef struct adbqueryid {
mas01cr@419 154 adb_datum_t *datum;
mas01cr@419 155 uint32_t sequence_length;
mas01cr@434 156 uint32_t flags;
mas01cr@419 157 uint32_t sequence_start;
mas01cr@419 158 } adb_query_id_t;
mas01cr@419 159
mas01cr@419 160 typedef struct adbqueryspec {
mas01cr@419 161 adb_query_id_t qid;
mas01cr@435 162 adb_query_parameters_t params;
mas01cr@435 163 adb_query_refine_t refine;
mas01cr@419 164 } adb_query_spec_t;
mas01ik@355 165
mas01ik@355 166 /*******************************************************************/
mas01ik@355 167 /* Function prototypes for API */
mas01ik@355 168
mas01ik@355 169 /* open an existing database */
mas01ik@355 170 /* returns a struct or NULL on failure */
mas01cr@392 171 adb_ptr audiodb_open(const char *path, int flags);
mas01ik@355 172
mas01ik@355 173 /* create a new database */
mas01ik@355 174 /* returns a struct or NULL on failure */
mas01cr@381 175 adb_ptr audiodb_create(const char *path, unsigned datasize, unsigned ntracks, unsigned datadim);
mas01ik@355 176
mas01ik@355 177 /* close a database */
mas01ik@355 178 void audiodb_close(adb_ptr db);
mas01ik@355 179
mas01ik@355 180 /* You'll need to turn both of these on to do anything useful */
mas01ik@355 181 int audiodb_l2norm(adb_ptr mydb);
mas01ik@355 182 int audiodb_power(adb_ptr mydb);
mas01ik@355 183
mas01ik@355 184 /* insert functions */
mas01cr@473 185 int audiodb_insert_datum(adb_t *, const adb_datum_t *);
mas01cr@473 186 int audiodb_insert_reference(adb_t *, const adb_reference_t *);
mas01ik@355 187 int audiodb_insert(adb_ptr mydb, adb_insert_ptr ins);
mas01ik@355 188 int audiodb_batchinsert(adb_ptr mydb, adb_insert_ptr ins, unsigned int size);
mas01ik@355 189
mas01ik@355 190 /* query function */
mas01ik@355 191 int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqres);
mas01cr@473 192 adb_query_results_t *audiodb_query_spec(adb_t *, const adb_query_spec_t *);
mas01cr@473 193 int audiodb_query_free_results(adb_t *, const adb_query_spec_t *, adb_query_results_t *);
mas01cr@419 194
mas01ik@355 195 /* database status */
mas01ik@355 196 int audiodb_status(adb_ptr mydb, adb_status_ptr status);
mas01ik@355 197
mas01ik@355 198 /* varoius dump formats */
mas01cr@399 199 int audiodb_dump(adb_ptr mydb, const char *outputdir);
mas01cr@421 200
mas01cr@421 201 #endif