comparison dump.cpp @ 432:62a0515f59be api-inversion

Include track_lengths data structure in struct adb. Remove mapping of trackTable where I can...
author mas01cr
date Wed, 24 Dec 2008 10:55:44 +0000
parents d7e590d58c85
children
comparison
equal deleted inserted replaced
431:8632cd387e24 432:62a0515f59be
4 #include "audioDB-internals.h" 4 #include "audioDB-internals.h"
5 } 5 }
6 6
7 int audiodb_dump(adb_t *adb, const char *output) { 7 int audiodb_dump(adb_t *adb, const char *output) {
8 char *fileTable = 0; /* key_table */ 8 char *fileTable = 0; /* key_table */
9 unsigned *trackTable = 0; /* track_size_table */
10 double *timesTable = 0; /* timestamps_table */ 9 double *timesTable = 0; /* timestamps_table */
11 double *powerTable = 0; /* power_table */ 10 double *powerTable = 0; /* power_table */
12 11
13 size_t fileTableLength = 0; 12 size_t fileTableLength = 0;
14 size_t trackTableLength = 0;
15 size_t timesTableLength = 0; 13 size_t timesTableLength = 0;
16 size_t powerTableLength = 0; 14 size_t powerTableLength = 0;
17 15
18 char *featureFileNameTable = 0; 16 char *featureFileNameTable = 0;
19 char *powerFileNameTable = 0; 17 char *powerFileNameTable = 0;
37 35
38 unsigned nfiles = adb->header->numFiles; 36 unsigned nfiles = adb->header->numFiles;
39 37
40 if(adb->header->length > 0) { 38 if(adb->header->length > 0) {
41 fileTableLength = ALIGN_PAGE_UP(nfiles * O2_FILETABLE_ENTRY_SIZE); 39 fileTableLength = ALIGN_PAGE_UP(nfiles * O2_FILETABLE_ENTRY_SIZE);
42 trackTableLength = ALIGN_PAGE_UP(nfiles * O2_TRACKTABLE_ENTRY_SIZE);
43 if(!(adb->header->flags & O2_FLAG_LARGE_ADB)) { 40 if(!(adb->header->flags & O2_FLAG_LARGE_ADB)) {
44 off_t length = adb->header->length; 41 off_t length = adb->header->length;
45 unsigned dim = adb->header->dim; 42 unsigned dim = adb->header->dim;
46 timesTableLength = ALIGN_PAGE_UP(2*length/dim); 43 timesTableLength = ALIGN_PAGE_UP(2*length/dim);
47 powerTableLength = ALIGN_PAGE_UP(length/dim); 44 powerTableLength = ALIGN_PAGE_UP(length/dim);
48 } 45 }
49 46
50 mmap_or_goto_error(char *, fileTable, adb->header->fileTableOffset, fileTableLength); 47 mmap_or_goto_error(char *, fileTable, adb->header->fileTableOffset, fileTableLength);
51 mmap_or_goto_error(unsigned *, trackTable, adb->header->trackTableOffset, trackTableLength);
52 if (adb->header->flags & O2_FLAG_LARGE_ADB) { 48 if (adb->header->flags & O2_FLAG_LARGE_ADB) {
53 mmap_or_goto_error(char *, featureFileNameTable, adb->header->dataOffset, fileTableLength); 49 mmap_or_goto_error(char *, featureFileNameTable, adb->header->dataOffset, fileTableLength);
54 mmap_or_goto_error(char *, powerFileNameTable, adb->header->powerTableOffset, fileTableLength); 50 mmap_or_goto_error(char *, powerFileNameTable, adb->header->powerTableOffset, fileTableLength);
55 mmap_or_goto_error(char *, timesFileNameTable, adb->header->timesTableOffset, fileTableLength); 51 mmap_or_goto_error(char *, timesFileNameTable, adb->header->timesTableOffset, fileTableLength);
56 } else { 52 } else {
137 } 133 }
138 write_or_goto_error(ffd, &(adb->header->dim), sizeof(uint32_t)); 134 write_or_goto_error(ffd, &(adb->header->dim), sizeof(uint32_t));
139 135
140 /* FIXME: this repeated malloc()/free() of data buffers is 136 /* FIXME: this repeated malloc()/free() of data buffers is
141 inefficient. */ 137 inefficient. */
142 data_buffer_size = trackTable[k] * adb->header->dim * sizeof(double); 138 data_buffer_size = (*adb->track_lengths)[k] * adb->header->dim * sizeof(double);
143 139
144 { 140 {
145 void *tmp = malloc(data_buffer_size); 141 void *tmp = malloc(data_buffer_size);
146 if (tmp == NULL) { 142 if (tmp == NULL) {
147 goto error; 143 goto error;
162 ffd = 0; 158 ffd = 0;
163 159
164 if (times) { 160 if (times) {
165 snprintf(fName, 256, "%05d.times", k); 161 snprintf(fName, 256, "%05d.times", k);
166 tFile = fopen(fName, "w"); 162 tFile = fopen(fName, "w");
167 for(unsigned i = 0; i < trackTable[k]; i++) { 163 for(unsigned i = 0; i < (*adb->track_lengths)[k]; i++) {
168 // KLUDGE: specifying 16 digits of precision after the decimal 164 // KLUDGE: specifying 16 digits of precision after the decimal
169 // point is (but check this!) sufficient to uniquely identify 165 // point is (but check this!) sufficient to uniquely identify
170 // doubles; however, that will cause ugliness, as that's 166 // doubles; however, that will cause ugliness, as that's
171 // vastly too many for most values of interest. Moving to %a 167 // vastly too many for most values of interest. Moving to %a
172 // here and scanf() in the timesFile reading might fix this. 168 // here and scanf() in the timesFile reading might fix this.
173 // -- CSR, 2007-10-19 169 // -- CSR, 2007-10-19
174 fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*i)); 170 fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*i));
175 } 171 }
176 fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*trackTable[k]-1)); 172 fprintf(tFile, "%.16e\n", *(timesTable + 2*pos + 2*(*adb->track_lengths)[k]-1));
177 fclose(tFile); 173 fclose(tFile);
178 174
179 fprintf(tLFile, "%s\n", fName); 175 fprintf(tLFile, "%s\n", fName);
180 } 176 }
181 177
184 snprintf(fName, 256, "%05d.power", k); 180 snprintf(fName, 256, "%05d.power", k);
185 if ((pfd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 181 if ((pfd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
186 goto error; 182 goto error;
187 } 183 }
188 write_or_goto_error(pfd, &one, sizeof(uint32_t)); 184 write_or_goto_error(pfd, &one, sizeof(uint32_t));
189 write_or_goto_error(pfd, powerTable + pos, trackTable[k] * sizeof(double)); 185 write_or_goto_error(pfd, powerTable + pos, (*adb->track_lengths)[k] * sizeof(double));
190 fprintf(pLFile, "%s\n", fName); 186 fprintf(pLFile, "%s\n", fName);
191 close(pfd); 187 close(pfd);
192 pfd = 0; 188 pfd = 0;
193 } 189 }
194 190
195 pos += trackTable[k]; 191 pos += (*adb->track_lengths)[k];
196 std::cout << fileTable+k*O2_FILETABLE_ENTRY_SIZE << " " << trackTable[k] << std::endl; 192 std::cout << fileTable+k*O2_FILETABLE_ENTRY_SIZE << " " << (*adb->track_lengths)[k] << std::endl;
197 } 193 }
198 } 194 }
199 195
200 scriptFile = fopen("restore.sh", "w"); 196 scriptFile = fopen("restore.sh", "w");
201 fprintf(scriptFile, "\ 197 fprintf(scriptFile, "\
235 fclose(pLFile); 231 fclose(pLFile);
236 } 232 }
237 fclose(kLFile); 233 fclose(kLFile);
238 234
239 maybe_munmap(fileTable, fileTableLength); 235 maybe_munmap(fileTable, fileTableLength);
240 maybe_munmap(trackTable, trackTableLength);
241 maybe_munmap(timesTable, timesTableLength); 236 maybe_munmap(timesTable, timesTableLength);
242 maybe_munmap(powerTable, powerTableLength); 237 maybe_munmap(powerTable, powerTableLength);
243 maybe_munmap(featureFileNameTable, fileTableLength); 238 maybe_munmap(featureFileNameTable, fileTableLength);
244 maybe_munmap(timesFileNameTable, fileTableLength); 239 maybe_munmap(timesFileNameTable, fileTableLength);
245 maybe_munmap(powerFileNameTable, fileTableLength); 240 maybe_munmap(powerFileNameTable, fileTableLength);
276 if(scriptFile) { 271 if(scriptFile) {
277 fclose(scriptFile); 272 fclose(scriptFile);
278 } 273 }
279 274
280 maybe_munmap(fileTable, fileTableLength); 275 maybe_munmap(fileTable, fileTableLength);
281 maybe_munmap(trackTable, trackTableLength);
282 maybe_munmap(timesTable, timesTableLength); 276 maybe_munmap(timesTable, timesTableLength);
283 maybe_munmap(powerTable, powerTableLength); 277 maybe_munmap(powerTable, powerTableLength);
284 maybe_munmap(featureFileNameTable, fileTableLength); 278 maybe_munmap(featureFileNameTable, fileTableLength);
285 maybe_munmap(timesFileNameTable, fileTableLength); 279 maybe_munmap(timesFileNameTable, fileTableLength);
286 maybe_munmap(powerFileNameTable, fileTableLength); 280 maybe_munmap(powerFileNameTable, fileTableLength);