Mercurial > hg > audiodb
comparison common.cpp @ 324:c93be2f3a674
Merge of branches/large_adb -r 514:524 onto the trunk. No conflicts. Added LARGE_ADB support. Turn on with --ntracks 20001 or greater. Use --adb_feature_root to locate feature files at QUERY time. A bug fix in LSH indexing that was incorrectly thresholding large numbers of shingles.
author | mas01mc |
---|---|
date | Thu, 21 Aug 2008 21:28:33 +0000 |
parents | d9a88cfd4ab6 |
children | 94c18f128ce8 |
comparison
equal
deleted
inserted
replaced
315:d2c56d4f841e | 324:c93be2f3a674 |
---|---|
124 powerTableLength = dbH->l2normTableOffset - dbH->powerTableOffset; | 124 powerTableLength = dbH->l2normTableOffset - dbH->powerTableOffset; |
125 l2normTableLength = dbH->dbSize - dbH->l2normTableOffset; | 125 l2normTableLength = dbH->dbSize - dbH->l2normTableOffset; |
126 } else { | 126 } else { |
127 fileTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_FILETABLE_ENTRY_SIZE); | 127 fileTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_FILETABLE_ENTRY_SIZE); |
128 trackTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_TRACKTABLE_ENTRY_SIZE); | 128 trackTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_TRACKTABLE_ENTRY_SIZE); |
129 dataBufLength = ALIGN_PAGE_UP(dbH->length); | 129 if( dbH->flags & O2_FLAG_LARGE_ADB ){ |
130 timesTableLength = ALIGN_PAGE_UP(2*(dbH->length / dbH->dim)); | 130 dataBufLength = ALIGN_PAGE_UP(dbH->numFiles * O2_FILETABLE_ENTRY_SIZE); |
131 powerTableLength = ALIGN_PAGE_UP(dbH->length / dbH->dim); | 131 timesTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_FILETABLE_ENTRY_SIZE); |
132 l2normTableLength = ALIGN_PAGE_UP(dbH->length / dbH->dim); | 132 powerTableLength = ALIGN_PAGE_UP(dbH->numFiles * O2_FILETABLE_ENTRY_SIZE); |
133 l2normTableLength = 0; | |
134 } | |
135 else{ | |
136 dataBufLength = ALIGN_PAGE_UP(dbH->length); | |
137 timesTableLength = ALIGN_PAGE_UP(2*(dbH->length / dbH->dim)); | |
138 powerTableLength = ALIGN_PAGE_UP(dbH->length / dbH->dim); | |
139 l2normTableLength = ALIGN_PAGE_UP(dbH->length / dbH->dim); | |
140 } | |
133 } | 141 } |
134 CHECKED_MMAP(char *, fileTable, dbH->fileTableOffset, fileTableLength); | 142 CHECKED_MMAP(char *, fileTable, dbH->fileTableOffset, fileTableLength); |
135 CHECKED_MMAP(unsigned *, trackTable, dbH->trackTableOffset, trackTableLength); | 143 CHECKED_MMAP(unsigned *, trackTable, dbH->trackTableOffset, trackTableLength); |
136 /* | 144 /* |
137 * No more mmap() for dataBuf | 145 * No more mmap() for dataBuf |
141 * non-zero. Removing those cases too (and deleting the dataBuf | 149 * non-zero. Removing those cases too (and deleting the dataBuf |
142 * variable completely) would be cool. -- CSR, 2007-11-19 | 150 * variable completely) would be cool. -- CSR, 2007-11-19 |
143 * | 151 * |
144 * CHECKED_MMAP(double *, dataBuf, dbH->dataOffset, dataBufLength); | 152 * CHECKED_MMAP(double *, dataBuf, dbH->dataOffset, dataBufLength); |
145 */ | 153 */ |
146 CHECKED_MMAP(double *, timesTable, dbH->timesTableOffset, timesTableLength); | 154 if( dbH->flags & O2_FLAG_LARGE_ADB ){ |
147 CHECKED_MMAP(double *, powerTable, dbH->powerTableOffset, powerTableLength); | 155 CHECKED_MMAP(char *, featureFileNameTable, dbH->dataOffset, fileTableLength); |
148 CHECKED_MMAP(double *, l2normTable, dbH->l2normTableOffset, l2normTableLength); | 156 if( dbH->flags & O2_FLAG_TIMES ) |
157 CHECKED_MMAP(char *, timesFileNameTable, dbH->timesTableOffset, fileTableLength); | |
158 if( dbH->flags & O2_FLAG_POWER ) | |
159 CHECKED_MMAP(char *, powerFileNameTable, dbH->powerTableOffset, fileTableLength); | |
160 } | |
161 else{ | |
162 CHECKED_MMAP(double *, timesTable, dbH->timesTableOffset, timesTableLength); | |
163 CHECKED_MMAP(double *, powerTable, dbH->powerTableOffset, powerTableLength); | |
164 CHECKED_MMAP(double *, l2normTable, dbH->l2normTableOffset, l2normTableLength); | |
165 } | |
149 } | 166 } |
150 | 167 |
151 // build track offset table | 168 // build track offset table |
152 trackOffsetTable = new off_t[dbH->numFiles]; | 169 trackOffsetTable = new off_t[dbH->numFiles]; |
153 Uns32T cumTrack=0; | 170 Uns32T cumTrack=0; |
154 for(Uns32T k = 0; k < dbH->numFiles; k++){ | 171 for(Uns32T k = 0; k < dbH->numFiles; k++){ |
155 trackOffsetTable[k] = cumTrack; | 172 trackOffsetTable[k] = cumTrack; |
156 cumTrack += trackTable[k] * dbH->dim; | 173 cumTrack += trackTable[k] * dbH->dim; |
157 } | 174 } |
158 } | 175 |
159 | 176 // Assign correct number of point bits per track in LSH indexing / retrieval |
160 void audioDB::initInputFile (const char *inFile) { | 177 lsh_n_point_bits = dbH->flags >> 28; |
178 if( !lsh_n_point_bits ) | |
179 lsh_n_point_bits = O2_DEFAULT_LSH_N_POINT_BITS; | |
180 } | |
181 | |
182 void audioDB::initInputFile (const char *inFile, bool loadData) { | |
161 if (inFile) { | 183 if (inFile) { |
162 if ((infid = open(inFile, O_RDONLY)) < 0) { | 184 if ((infid = open(inFile, O_RDONLY)) < 0) { |
163 error("can't open input file for reading", inFile, "open"); | 185 error("can't open input file for reading", inFile, "open"); |
164 } | 186 } |
165 | 187 |
187 std::cerr << "error: expected dimension: " << dbH->dim << ", got : " << test <<std::endl; | 209 std::cerr << "error: expected dimension: " << dbH->dim << ", got : " << test <<std::endl; |
188 error("feature dimensions do not match database table dimensions", inFile); | 210 error("feature dimensions do not match database table dimensions", inFile); |
189 } | 211 } |
190 } | 212 } |
191 | 213 |
192 if ((indata = (char *) mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, infid, 0)) == (caddr_t) -1) { | 214 if (loadData && ((indata = (char *) mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, infid, 0)) == (caddr_t) -1)) { |
193 error("mmap error for input", inFile, "mmap"); | 215 error("mmap error for input", inFile, "mmap"); |
194 } | 216 } |
195 } | 217 } |
196 } | 218 } |
197 | 219 |
206 initDBHeader(dbName); | 228 initDBHeader(dbName); |
207 if(inFile) | 229 if(inFile) |
208 initInputFile(inFile); | 230 initInputFile(inFile); |
209 } | 231 } |
210 | 232 |
233 // If name is relative path, side effect name with prefix/name | |
234 // Do not free original pointer | |
235 void audioDB::prefix_name(char** const name, const char* prefix){ | |
236 // No prefix if prefix is empty | |
237 if(!prefix) | |
238 return; | |
239 // Allocate new memory, keep old memory | |
240 assert(name && *name); | |
241 if (strlen(*name) + strlen(prefix) + 1 > O2_MAXFILESTR) | |
242 error("error: path prefix + filename too long",prefix); | |
243 // Do not prefix absolute path+filename | |
244 if(**name=='/') | |
245 return; | |
246 // OK to prefix relative path+filename | |
247 char* prefixedName = (char*) malloc(O2_MAXFILESTR); | |
248 sprintf(prefixedName, "%s/%s", prefix, *name); | |
249 *name = prefixedName; // side effect new name to old name | |
250 } |