comparison audioDB.cpp @ 153:00928c833187 powertable

dump/restore support for the power table.
author mas01cr
date Wed, 31 Oct 2007 18:22:23 +0000
parents b1cbd2b78a18
children 97f704a32bf2
comparison
equal deleted inserted replaced
152:b1cbd2b78a18 153:00928c833187
993 993
994 if((chdir(output)) < 0) { 994 if((chdir(output)) < 0) {
995 error("error changing working directory", output, "chdir"); 995 error("error changing working directory", output, "chdir");
996 } 996 }
997 997
998 int fLfd, tLfd = 0, kLfd; 998 int fLfd, tLfd = 0, pLfd = 0, kLfd;
999 FILE *fLFile, *tLFile = 0, *kLFile; 999 FILE *fLFile, *tLFile = 0, *pLFile = 0, *kLFile;
1000 1000
1001 if ((fLfd = open("featureList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 1001 if ((fLfd = open("featureList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
1002 error("error creating featureList file", "featureList.txt", "open"); 1002 error("error creating featureList file", "featureList.txt", "open");
1003 } 1003 }
1004
1004 int times = dbH->flags & O2_FLAG_TIMES; 1005 int times = dbH->flags & O2_FLAG_TIMES;
1005 if (times) { 1006 if (times) {
1006 if ((tLfd = open("timesList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 1007 if ((tLfd = open("timesList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
1007 error("error creating timesList file", "timesList.txt", "open"); 1008 error("error creating timesList file", "timesList.txt", "open");
1008 } 1009 }
1009 } 1010 }
1011
1012 int power = dbH->flags & O2_FLAG_POWER;
1013 if (power) {
1014 if ((pLfd = open("powerList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
1015 error("error creating powerList file", "powerList.txt", "open");
1016 }
1017 }
1018
1010 if ((kLfd = open("keyList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) { 1019 if ((kLfd = open("keyList.txt", O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
1011 error("error creating keyList file", "keyList.txt", "open"); 1020 error("error creating keyList file", "keyList.txt", "open");
1012 } 1021 }
1013 1022
1014 /* can these fail? I sincerely hope not. */ 1023 /* can these fail? I sincerely hope not. */
1015 fLFile = fdopen(fLfd, "w"); 1024 fLFile = fdopen(fLfd, "w");
1016 if (times) { 1025 if (times) {
1017 tLFile = fdopen(tLfd, "w"); 1026 tLFile = fdopen(tLfd, "w");
1018 } 1027 }
1028 if (power) {
1029 pLFile = fdopen(pLfd, "w");
1030 }
1019 kLFile = fdopen(kLfd, "w"); 1031 kLFile = fdopen(kLfd, "w");
1020 1032
1021 char *fName = new char[256]; 1033 char *fName = new char[256];
1022 int ffd; 1034 int ffd, pfd;
1023 FILE *tFile; 1035 FILE *tFile;
1024 unsigned pos = 0; 1036 unsigned pos = 0;
1025 for(unsigned k = 0; k < dbH->numFiles; k++) { 1037 for(unsigned k = 0; k < dbH->numFiles; k++) {
1026 fprintf(kLFile, "%s\n", fileTable + k*O2_FILETABLESIZE); 1038 fprintf(kLFile, "%s\n", fileTable + k*O2_FILETABLESIZE);
1027 snprintf(fName, 256, "%05d.features", k); 1039 snprintf(fName, 256, "%05d.features", k);
1050 // -- CSR, 2007-10-19 1062 // -- CSR, 2007-10-19
1051 fprintf(tFile, "%.16e\n", *(timesTable + pos + i)); 1063 fprintf(tFile, "%.16e\n", *(timesTable + pos + i));
1052 } 1064 }
1053 fprintf(tLFile, "%s\n", fName); 1065 fprintf(tLFile, "%s\n", fName);
1054 } 1066 }
1067
1068 if (power) {
1069 uint32_t one = 1;
1070 snprintf(fName, 256, "%05d.power", k);
1071 if ((pfd = open(fName, O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) {
1072 error("error creating power file", fName, "open");
1073 }
1074 if ((write(pfd, &one, sizeof(uint32_t))) < 0) {
1075 error("error writing one", fName, "write");
1076 }
1077 if ((write(pfd, powerTable + pos, trackTable[k] * sizeof(double))) < 0) {
1078 error("error writing data", fName, "write");
1079 }
1080 fprintf(pLFile, "%s\n", fName);
1081 close(pfd);
1082 }
1055 1083
1056 pos += trackTable[k]; 1084 pos += trackTable[k];
1057 cout << fileTable+k*O2_FILETABLESIZE << " " << trackTable[k] << endl; 1085 cout << fileTable+k*O2_FILETABLESIZE << " " << trackTable[k] << endl;
1058 } 1086 }
1059 1087
1068 if [ -z \"$1\" ]; then echo usage: $0 newdb; exit 1; fi\n\n\ 1096 if [ -z \"$1\" ]; then echo usage: $0 newdb; exit 1; fi\n\n\
1069 \"${AUDIODB}\" -d \"$1\" -N --size=%d\n", dbH->dbSize / 1000000); 1097 \"${AUDIODB}\" -d \"$1\" -N --size=%d\n", dbH->dbSize / 1000000);
1070 if(dbH->flags & O2_FLAG_L2NORM) { 1098 if(dbH->flags & O2_FLAG_L2NORM) {
1071 fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -L\n"); 1099 fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -L\n");
1072 } 1100 }
1101 if(power) {
1102 fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -P\n");
1103 }
1073 fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -B -F featureList.txt -K keyList.txt"); 1104 fprintf(scriptFile, "\"${AUDIODB}\" -d \"$1\" -B -F featureList.txt -K keyList.txt");
1074 if(times) { 1105 if(times) {
1075 fprintf(scriptFile, " -T timesList.txt"); 1106 fprintf(scriptFile, " -T timesList.txt");
1076 } 1107 }
1108 if(power) {
1109 fprintf(scriptFile, " -W powerList.txt");
1110 }
1077 fprintf(scriptFile, "\n"); 1111 fprintf(scriptFile, "\n");
1078 fclose(scriptFile); 1112 fclose(scriptFile);
1079 1113
1080 if((chdir(cwd)) < 0) { 1114 if((chdir(cwd)) < 0) {
1081 error("error changing working directory", cwd, "chdir"); 1115 error("error changing working directory", cwd, "chdir");
1082 } 1116 }
1083 1117
1084 fclose(fLFile); 1118 fclose(fLFile);
1085 if(times) { 1119 if(times) {
1086 fclose(tLFile); 1120 fclose(tLFile);
1121 }
1122 if(power) {
1123 fclose(pLFile);
1087 } 1124 }
1088 fclose(kLFile); 1125 fclose(kLFile);
1089 delete[] fName; 1126 delete[] fName;
1090 1127
1091 status(dbName); 1128 status(dbName);