Mercurial > hg > audiodb
changeset 697:2741bbda39d7
actually implement the sampling functionality requested
The -f flag at the audioDB command line when sampling causes a datum x db
sampling to occur, using the feature file's information. At present, no
support for thresholding based on power or duration information.
author | mas01cr |
---|---|
date | Thu, 22 Apr 2010 21:04:10 +0000 |
parents | bb9478d5b57e |
children | 10d3692e0b06 |
files | audioDB.cpp audioDB.h |
diffstat | 2 files changed, 59 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/audioDB.cpp Thu Apr 22 21:04:04 2010 +0000 +++ b/audioDB.cpp Thu Apr 22 21:04:10 2010 +0000 @@ -1,6 +1,8 @@ #include "audioDB.h" #include "reporter.h" +#include <gsl/gsl_sf.h> + char* SERVER_ADB_ROOT; char* SERVER_ADB_FEATURE_ROOT; @@ -340,6 +342,8 @@ if(args_info.key_given) { query_from_key = true; key = args_info.key_arg; + } else if (args_info.features_given) { + inFile = args_info.features_arg; } if(!args_info.exhaustive_flag){ queryPoint = args_info.qpoint_arg; @@ -779,6 +783,44 @@ status(dbName); } +void audioDB::datumFromFiles(adb_datum_t *datum) { + int fd; + struct stat st; + + /* FIXME: around here error conditions will cause all sorts of + hideous leaks. */ + fd = open(inFile, O_RDONLY); + if(fd < 0) { + error("failed to open feature file", inFile); + } + fstat(fd, &st); + read(fd, &(datum->dim), sizeof(uint32_t)); + datum->nvectors = (st.st_size - sizeof(uint32_t)) / (datum->dim * sizeof(double)); + datum->data = (double *) malloc(st.st_size - sizeof(uint32_t)); + read(fd, datum->data, st.st_size - sizeof(uint32_t)); + close(fd); + if(usingPower) { + uint32_t one; + fd = open(powerFileName, O_RDONLY); + if(fd < 0) { + error("failed to open power file", powerFileName); + } + read(fd, &one, sizeof(uint32_t)); + if(one != 1) { + error("malformed power file dimensionality", powerFileName); + } + datum->power = (double *) malloc(datum->nvectors * sizeof(double)); + if(read(fd, datum->power, datum->nvectors * sizeof(double)) != (ssize_t) (datum->nvectors * sizeof(double))) { + error("malformed power file", powerFileName); + } + close(fd); + } + if(usingTimes) { + datum->times = (double *) malloc(2 * datum->nvectors * sizeof(double)); + insertTimeStamps(datum->nvectors, timesFile, datum->times); + } +} + void audioDB::query(const char* dbName, const char* inFile, struct soap *soap, adb__queryResponse *adbQueryResponse) { if(!adb) { @@ -847,41 +889,7 @@ if(query_from_key) { datum.key = key; } else { - int fd; - struct stat st; - - /* FIXME: around here error conditions will cause all sorts of - hideous leaks. */ - fd = open(inFile, O_RDONLY); - if(fd < 0) { - error("failed to open feature file", inFile); - } - fstat(fd, &st); - read(fd, &datum.dim, sizeof(uint32_t)); - datum.nvectors = (st.st_size - sizeof(uint32_t)) / (datum.dim * sizeof(double)); - datum.data = (double *) malloc(st.st_size - sizeof(uint32_t)); - read(fd, datum.data, st.st_size - sizeof(uint32_t)); - close(fd); - if(usingPower) { - uint32_t one; - fd = open(powerFileName, O_RDONLY); - if(fd < 0) { - error("failed to open power file", powerFileName); - } - read(fd, &one, sizeof(uint32_t)); - if(one != 1) { - error("malformed power file dimensionality", powerFileName); - } - datum.power = (double *) malloc(datum.nvectors * sizeof(double)); - if(read(fd, datum.power, datum.nvectors * sizeof(double)) != (ssize_t) (datum.nvectors * sizeof(double))) { - error("malformed power file", powerFileName); - } - close(fd); - } - if(usingTimes) { - datum.times = (double *) malloc(2 * datum.nvectors * sizeof(double)); - insertTimeStamps(datum.nvectors, timesFile, datum.times); - } + datumFromFiles(&datum); } qspec.qid.datum = &datum; @@ -1015,8 +1023,6 @@ audiodb_liszt_free_results(adb, results); } -#include <gsl/gsl_sf.h> - static double yfun(double d) { return gsl_sf_log(d) - gsl_sf_psi(d); @@ -1082,7 +1088,8 @@ spec.refine.exclude.nkeys = 1; spec.refine.exclude.keys = &key; } else if(inFile) { - error("sample from feature file not supported (yet)"); + datumFromFiles(&datum); + spec.qid.datum = &datum; } else { spec.qid.datum = NULL; /* full db sample */ } @@ -1098,6 +1105,19 @@ error("error in audiodb_sample_spec"); } + if(datum.data) { + free(datum.data); + datum.data = NULL; + } + if(datum.power) { + free(datum.power); + datum.power = NULL; + } + if(datum.times) { + free(datum.times); + datum.times = NULL; + } + if(results->nresults != nsamples) { error("mismatch in sample count"); }
--- a/audioDB.h Thu Apr 22 21:04:04 2010 +0000 +++ b/audioDB.h Thu Apr 22 21:04:10 2010 +0000 @@ -279,6 +279,7 @@ void create(const char* dbName); void insert(const char* dbName, const char* inFile); void batchinsert(const char* dbName, const char* inFile); + void datumFromFiles(adb_datum_t *datum); void query(const char* dbName, const char* inFile, struct soap *soap=0, adb__queryResponse *adbQueryResponse=0); void status(const char* dbName, adb__statusResponse *adbStatusResponse=0);