Mercurial > hg > audiodb
comparison common.cpp @ 284:cacad987d785
Really finish with the sampling branch, this time merging all of it,
yes, even the last revision. (The last revision was one that seeded the
RNG with the current time, which is helpful when trying to get multiple
independent-ish samples from the same database...)
author | mas01cr |
---|---|
date | Mon, 07 Jul 2008 08:57:06 +0000 |
parents | 4dcb09f5fe85 |
children | d9a88cfd4ab6 |
comparison
equal
deleted
inserted
replaced
283:0e44de38d675 | 284:cacad987d785 |
---|---|
68 } | 68 } |
69 exit(1); | 69 exit(1); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 void audioDB::initRNG() { | |
74 rng = gsl_rng_alloc(gsl_rng_mt19937); | |
75 if(!rng) { | |
76 error("could not allocate Random Number Generator"); | |
77 } | |
78 /* FIXME: maybe we should use a real source of entropy? */ | |
79 gsl_rng_set(rng, time(NULL)); | |
80 } | |
81 | |
73 void audioDB::initDBHeader(const char* dbName) { | 82 void audioDB::initDBHeader(const char* dbName) { |
74 if ((dbfid = open(dbName, forWrite ? O_RDWR : O_RDONLY)) < 0) { | 83 if ((dbfid = open(dbName, forWrite ? O_RDWR : O_RDONLY)) < 0) { |
75 error("Can't open database file", dbName, "open"); | 84 error("Can't open database file", dbName, "open"); |
76 } | 85 } |
77 | 86 |
177 } | 186 } |
178 } | 187 } |
179 } | 188 } |
180 | 189 |
181 void audioDB::initTables(const char* dbName, const char* inFile = 0) { | 190 void audioDB::initTables(const char* dbName, const char* inFile = 0) { |
191 /* FIXME: initRNG() really logically belongs in the audioDB | |
192 contructor. However, there are of the order of four constructors | |
193 at the moment, and more to come from API implementation. Given | |
194 that duplication, I think this is the least worst place to put | |
195 it; the assumption is that nothing which doesn't look at a | |
196 database will need an RNG. -- CSR, 2008-07-02 */ | |
197 initRNG(); | |
182 initDBHeader(dbName); | 198 initDBHeader(dbName); |
183 initInputFile(inFile); | 199 initInputFile(inFile); |
184 } | 200 } |