Mercurial > hg > audiodb
diff create.cpp @ 256:4dcb09f5fe85
Commit patch deprecating the --size argument, replacing it with
--ntracks, --datadims and --datasize.
These names are not ideal, but will serve for now.
author | mas01cr |
---|---|
date | Wed, 16 Apr 2008 09:59:43 +0000 |
parents | 2cc06e5b05a5 |
children | 896679d8cc39 |
line wrap: on
line diff
--- a/create.cpp Sat Apr 12 13:28:30 2008 +0000 +++ b/create.cpp Wed Apr 16 09:59:43 2008 +0000 @@ -24,7 +24,7 @@ dbH = new dbTableHeaderT(); assert(dbH); - unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE); + //unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE); // Initialize header dbH->magic = O2_MAGIC; @@ -35,17 +35,21 @@ dbH->headerSize = O2_HEADERSIZE; dbH->length = 0; dbH->fileTableOffset = ALIGN_PAGE_UP(O2_HEADERSIZE); - dbH->trackTableOffset = ALIGN_PAGE_UP(dbH->fileTableOffset + O2_FILETABLESIZE*maxfiles); - dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles); - dbH->l2normTableOffset = ALIGN_PAGE_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double)); - dbH->powerTableOffset = ALIGN_PAGE_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double)); - dbH->timesTableOffset = ALIGN_PAGE_DOWN(dbH->powerTableOffset - 2*maxfiles*O2_MEANNUMVECTORS*sizeof(double)); - dbH->dbSize = size; + dbH->trackTableOffset = ALIGN_PAGE_UP(dbH->fileTableOffset + O2_FILETABLE_ENTRY_SIZE*ntracks); + dbH->dataOffset = ALIGN_PAGE_UP(dbH->trackTableOffset + O2_TRACKTABLE_ENTRY_SIZE*ntracks); + + off_t databytes = ((off_t) datasize) * 1024 * 1024; + off_t auxbytes = databytes / datadim; + + dbH->timesTableOffset = ALIGN_PAGE_UP(dbH->dataOffset + databytes); + dbH->powerTableOffset = ALIGN_PAGE_UP(dbH->timesTableOffset + 2*auxbytes); + dbH->l2normTableOffset = ALIGN_PAGE_UP(dbH->powerTableOffset + auxbytes); + dbH->dbSize = ALIGN_PAGE_UP(dbH->l2normTableOffset + auxbytes); write(dbfid, dbH, O2_HEADERSIZE); // go to the location corresponding to the last byte - if (lseek (dbfid, size - 1, SEEK_SET) == -1) + if (lseek (dbfid, dbH->dbSize - 1, SEEK_SET) == -1) error("lseek error in db file", "", "lseek"); // write a dummy byte at the last location