Mercurial > hg > audiodb
comparison audioDB.h @ 509:cc2b97d020b1
Code rearrangements to tease apart library code from C++ audioDB code.
There should be precisely no functional changes in this commit.
Instead, the only thing that has happened is that all the abstraction
violation and other horribleness is concentrated in one place: the
include of "audioDB-internals.h" in audioDB.h -- the separation will be
complete once that include can be removed.
This include is necessary because the command-line binary / SOAP server
still does some things directly rather than through an API: not least of
which the operations that have not yet been integrated into the API yet,
but also some messing around with constants, flags and nominally
internal functions. The intent is to remove as many of these as
possible and think quite hard about the rest.
In the meantime, the library is now much more self-contained: the only
things it uses are in the audioDB_API.h and audioDB-internals.h headers;
thus there are fewer nasty surprises lurking for readers of the code.
The Makefile has been adjusted to take advantage of this rearrangement
in the dependencies.
author | mas01cr |
---|---|
date | Thu, 15 Jan 2009 13:57:33 +0000 |
parents | 23c47e118bc6 |
children | 06409b6e268f |
comparison
equal
deleted
inserted
replaced
508:23c47e118bc6 | 509:cc2b97d020b1 |
---|---|
22 | 22 |
23 // includes for LSH indexing | 23 // includes for LSH indexing |
24 extern "C" { | 24 extern "C" { |
25 #include "audioDB_API.h" | 25 #include "audioDB_API.h" |
26 } | 26 } |
27 #include "audioDB-internals.h" | |
27 #include "ReporterBase.h" | 28 #include "ReporterBase.h" |
28 #include "accumulator.h" | 29 #include "accumulator.h" |
29 #include "lshlib.h" | 30 #include "lshlib.h" |
30 | 31 |
31 // includes for web services | 32 // includes for web services |
32 #include "soapH.h" | 33 #include "soapH.h" |
33 #include "cmdline.h" | 34 #include "cmdline.h" |
34 | 35 |
35 // should probably be rewritten | 36 #define MAXSTR ADB_MAXSTR |
36 class PointPair{ | |
37 public: | |
38 Uns32T trackID; | |
39 Uns32T qpos; | |
40 Uns32T spos; | |
41 PointPair(Uns32T a, Uns32T b, Uns32T c); | |
42 }; | |
43 bool operator<(const PointPair& a, const PointPair& b); | |
44 | |
45 #define MAXSTR 512 | |
46 | 37 |
47 // Databse PRIMARY commands | 38 // Databse PRIMARY commands |
48 #define COM_CREATE "--NEW" | 39 #define COM_CREATE "--NEW" |
49 #define COM_INSERT "--INSERT" | 40 #define COM_INSERT "--INSERT" |
50 #define COM_BATCHINSERT "--BATCHINSERT" | 41 #define COM_BATCHINSERT "--BATCHINSERT" |
77 #define COM_ABSOLUTE_THRESH "--absolute-threshold" | 68 #define COM_ABSOLUTE_THRESH "--absolute-threshold" |
78 #define COM_EXHAUSTIVE "--exhaustive" | 69 #define COM_EXHAUSTIVE "--exhaustive" |
79 #define COM_LSH_EXACT "--lsh_exact" | 70 #define COM_LSH_EXACT "--lsh_exact" |
80 #define COM_NO_UNIT_NORMING "--no_unit_norming" | 71 #define COM_NO_UNIT_NORMING "--no_unit_norming" |
81 | 72 |
82 #define O2_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24) | |
83 #define O2_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24) | |
84 #define O2_FORMAT_VERSION (4U) | |
85 | |
86 #define O2_DEFAULT_POINTNN (10U) | 73 #define O2_DEFAULT_POINTNN (10U) |
87 #define O2_DEFAULT_TRACKNN (10U) | 74 #define O2_DEFAULT_TRACKNN (10U) |
88 | 75 |
89 //#define O2_DEFAULTDBSIZE (4000000000) // 4GB table size | 76 //#define O2_DEFAULTDBSIZE (4000000000) // 4GB table size |
90 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size | 77 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size |
91 | 78 |
92 // Bit masks for packing (trackID,pointID) into 32-bit unsigned int | 79 #define O2_DEFAULT_DATASIZE (1355U) /* in MB */ |
93 // This can be controlled at compile time | |
94 #define O2_DEFAULT_LSH_N_POINT_BITS 14 | |
95 | |
96 // Override the default point bit width for large database support | |
97 #ifndef LSH_N_POINT_BITS | |
98 #define LSH_N_POINT_BITS O2_DEFAULT_LSH_N_POINT_BITS | |
99 #endif | |
100 | |
101 // LIMIT PARAMETERS | |
102 #define O2_DEFAULT_DATASIZE (1355U) // in MB | |
103 #define O2_DEFAULT_NTRACKS (20000U) | 80 #define O2_DEFAULT_NTRACKS (20000U) |
104 #define O2_DEFAULT_DATADIM (9U) | 81 #define O2_DEFAULT_DATADIM (9U) |
82 | |
83 // LIMIT PARAMETERS | |
105 #define O2_REALTYPE (double) | 84 #define O2_REALTYPE (double) |
106 #define O2_MAXFILES (1000000U) | 85 #define O2_MAXFILES (1000000U) |
107 #define O2_MAXFILESTR (256U) | 86 #define O2_MAXFILESTR ADB_FILETABLE_ENTRY_SIZE |
108 #define O2_FILETABLE_ENTRY_SIZE (O2_MAXFILESTR) | 87 #define O2_FILETABLE_ENTRY_SIZE ADB_FILETABLE_ENTRY_SIZE |
109 #define O2_TRACKTABLE_ENTRY_SIZE (sizeof(unsigned)) | 88 #define O2_TRACKTABLE_ENTRY_SIZE ADB_TRACKTABLE_ENTRY_SIZE |
110 #define O2_HEADERSIZE (sizeof(dbTableHeaderT)) | 89 #define O2_HEADERSIZE (sizeof(dbTableHeaderT)) |
111 #define O2_MEANNUMVECTORS (1000U) | 90 #define O2_MEANNUMVECTORS (1000U) |
112 #define O2_MAXDIM (20000U) | 91 #define O2_MAXDIM (20000U) |
113 #define O2_MAXNN (1000000U) | 92 #define O2_MAXNN (1000000U) |
114 #define O2_MAXSEQLEN (8000U) // maximum feature vectors in a sequence | 93 #define O2_MAXSEQLEN (8000U) // maximum feature vectors in a sequence |
115 #define O2_MAXTRACKS (1000000U) // maximum number of tracks | 94 #define O2_MAXTRACKS (1000000U) // maximum number of tracks |
116 #define O2_MAXTRACKLEN (1<<LSH_N_POINT_BITS) // maximum shingles in a track | 95 #define O2_MAXTRACKLEN ADB_LSH_MAXTRACKLEN |
117 #define O2_MAXDOTPRODUCTMEMORY (sizeof(O2_REALTYPE)*O2_MAXSEQLEN*O2_MAXSEQLEN) // 512MB | 96 #define O2_MAXDOTPRODUCTMEMORY (sizeof(O2_REALTYPE)*O2_MAXSEQLEN*O2_MAXSEQLEN) // 512MB |
118 #define O2_DISTANCE_TOLERANCE (1e-6) | |
119 #define O2_SERIAL_MAX_TRACKBATCH (1000000) | 97 #define O2_SERIAL_MAX_TRACKBATCH (1000000) |
120 #define O2_LARGE_ADB_SIZE (O2_DEFAULT_DATASIZE+1) // datasize at which features are kept externally (in Mbytes) | 98 #define O2_LARGE_ADB_SIZE (O2_DEFAULT_DATASIZE+1) // datasize at which features are kept externally (in Mbytes) |
121 #define O2_LARGE_ADB_NTRACKS (O2_DEFAULT_NTRACKS+1) // ntracks at which features are kept externally | 99 #define O2_LARGE_ADB_NTRACKS (O2_DEFAULT_NTRACKS+1) // ntracks at which features are kept externally |
122 #define O2_MAX_VECTORS ( O2_MEANNUMVECTORS * O2_MAXTRACKS ) | 100 #define O2_MAX_VECTORS ( O2_MEANNUMVECTORS * O2_MAXTRACKS ) |
123 | 101 |
124 // Flags | 102 // Flags |
125 #define O2_FLAG_L2NORM (0x1U) | 103 #define O2_FLAG_L2NORM ADB_HEADER_FLAG_L2NORM |
126 #define O2_FLAG_MINMAX (0x2U) | 104 #define O2_FLAG_MINMAX (0x2U) |
127 #define O2_FLAG_POWER (0x4U) | 105 #define O2_FLAG_POWER ADB_HEADER_FLAG_POWER |
128 #define O2_FLAG_TIMES (0x20U) | 106 #define O2_FLAG_TIMES ADB_HEADER_FLAG_TIMES |
129 #define O2_FLAG_LARGE_ADB (0x40U) | 107 #define O2_FLAG_LARGE_ADB ADB_HEADER_FLAG_REFERENCES |
130 #define DISPLAY_FLAG(x) (x?"on":"off") | 108 #define DISPLAY_FLAG(x) (x?"on":"off") |
131 | 109 |
132 // Query types | 110 // Query types |
133 #define O2_POINT_QUERY (0x4U) | 111 #define O2_POINT_QUERY (0x4U) |
134 #define O2_SEQUENCE_QUERY (0x8U) | 112 #define O2_SEQUENCE_QUERY (0x8U) |
192 #define SAFE_DELETE(PTR) delete PTR; PTR=0; | 170 #define SAFE_DELETE(PTR) delete PTR; PTR=0; |
193 #define SAFE_DELETE_ARRAY(PTR) delete[] PTR; PTR=0; | 171 #define SAFE_DELETE_ARRAY(PTR) delete[] PTR; PTR=0; |
194 | 172 |
195 extern char* SERVER_ADB_ROOT; | 173 extern char* SERVER_ADB_ROOT; |
196 extern char* SERVER_ADB_FEATURE_ROOT; | 174 extern char* SERVER_ADB_FEATURE_ROOT; |
197 | |
198 typedef struct dbTableHeader { | |
199 uint32_t magic; | |
200 uint32_t version; | |
201 uint32_t numFiles; | |
202 uint32_t dim; | |
203 uint32_t flags; | |
204 uint32_t headerSize; | |
205 off_t length; | |
206 off_t fileTableOffset; | |
207 off_t trackTableOffset; | |
208 off_t dataOffset; | |
209 off_t l2normTableOffset; | |
210 off_t timesTableOffset; | |
211 off_t powerTableOffset; | |
212 off_t dbSize; | |
213 } dbTableHeaderT, *dbTableHeaderPtr; | |
214 | 175 |
215 class audioDB{ | 176 class audioDB{ |
216 private: | 177 private: |
217 gengetopt_args_info args_info; | 178 gengetopt_args_info args_info; |
218 unsigned dim; | 179 unsigned dim; |
235 int dbfid; | 196 int dbfid; |
236 int lshfid; | 197 int lshfid; |
237 bool forWrite; | 198 bool forWrite; |
238 int infid; | 199 int infid; |
239 struct stat statbuf; | 200 struct stat statbuf; |
240 dbTableHeaderPtr dbH; | 201 struct adbheader *dbH; |
241 struct adb *adb; | 202 struct adb *adb; |
242 | 203 |
243 gsl_rng *rng; | 204 gsl_rng *rng; |
244 | 205 |
245 char* fileTable; | 206 char* fileTable; |