Mercurial > hg > audiodb
comparison common.cpp @ 693:b1723ae7675e
begin work on sampling API
This is motivated by the need to be able to sample with arbitrary feature data
(e.g. from a feature file) against a database, for the JNMR "collections" paper
revisions or possible ISMIR paper revisions. That bit doesn't work yet, but
the C-ified version of the current functionality (sample db x db and
sample key x db) works to the level of anecdotal tests.
The general approach is to mirror the _query_spec() API, where a whole heap
of knobs and twiddles are available to the user. Unlike in the _query_spec()
API, not quite all of the knobs make sense (and even fewer are actually
implemented), but the basic idea is the same.
I pity the poor chump who will have to document all this.
author | mas01cr |
---|---|
date | Thu, 22 Apr 2010 21:03:47 +0000 |
parents | 4c4389325ae4 |
children |
comparison
equal
deleted
inserted
replaced
692:02756c5ca15a | 693:b1723ae7675e |
---|---|
29 if (sysFunc) { | 29 if (sysFunc) { |
30 perror(sysFunc); | 30 perror(sysFunc); |
31 } | 31 } |
32 exit(1); | 32 exit(1); |
33 } | 33 } |
34 } | |
35 | |
36 void audioDB::initRNG() { | |
37 rng = gsl_rng_alloc(gsl_rng_mt19937); | |
38 if(!rng) { | |
39 error("could not allocate Random Number Generator"); | |
40 } | |
41 /* FIXME: maybe we should use a real source of entropy? */ | |
42 uint32_t seed = 0; | |
43 #ifdef WIN32 | |
44 seed = time(NULL); | |
45 #else | |
46 struct timeval tv; | |
47 if(gettimeofday(&tv, NULL) == -1) { | |
48 error("failed to get time of day"); | |
49 } | |
50 /* usec field should be less than than 2^20. We want to mix the | |
51 usec field, highly-variable, into the high bits of the seconds | |
52 field, which will be static between closely-spaced runs. -- CSR, | |
53 2010-01-05 */ | |
54 seed = tv.tv_sec ^ (tv.tv_usec << 12); | |
55 #endif | |
56 gsl_rng_set(rng, seed); | |
57 } | 34 } |
58 | 35 |
59 void audioDB::initDBHeader(const char* dbName) { | 36 void audioDB::initDBHeader(const char* dbName) { |
60 if(!adb) { | 37 if(!adb) { |
61 adb = audiodb_open(dbName, forWrite ? O_RDWR : O_RDONLY); | 38 adb = audiodb_open(dbName, forWrite ? O_RDWR : O_RDONLY); |
138 } | 115 } |
139 } | 116 } |
140 } | 117 } |
141 | 118 |
142 void audioDB::initTables(const char* dbName, const char* inFile) { | 119 void audioDB::initTables(const char* dbName, const char* inFile) { |
143 /* FIXME: initRNG() really logically belongs in the audioDB | |
144 contructor. However, there are of the order of four constructors | |
145 at the moment, and more to come from API implementation. Given | |
146 that duplication, I think this is the least worst place to put | |
147 it; the assumption is that nothing which doesn't look at a | |
148 database will need an RNG. -- CSR, 2008-07-02 */ | |
149 initRNG(); | |
150 initDBHeader(dbName); | 120 initDBHeader(dbName); |
151 if(inFile) | 121 if(inFile) |
152 initInputFile(inFile); | 122 initInputFile(inFile); |
153 } | 123 } |
154 | 124 |