Mercurial > hg > svcore
comparison base/View.cpp @ 33:51e158b505da
* Rearrange spectrogram cacheing so that gain, normalization, instantaneous
frequency calculations etc can be done from the cached data (increasing the
size of the cache, but also the usability).
author | Chris Cannam |
---|---|
date | Thu, 23 Feb 2006 18:01:31 +0000 |
parents | 4afaf0df4d51 |
children | aaf73f7309f2 |
comparison
equal
deleted
inserted
replaced
32:5e28cbb431d0 | 33:51e158b505da |
---|---|
251 | 251 |
252 long | 252 long |
253 View::getFrameForX(int x) const | 253 View::getFrameForX(int x) const |
254 { | 254 { |
255 return (long(x) * long(m_zoomLevel)) + getStartFrame(); | 255 return (long(x) * long(m_zoomLevel)) + getStartFrame(); |
256 } | |
257 | |
258 float | |
259 View::getYForFrequency(float frequency, | |
260 float minf, | |
261 float maxf, | |
262 bool logarithmic) const | |
263 { | |
264 int h = height(); | |
265 | |
266 if (logarithmic) { | |
267 | |
268 static float lastminf = 0.0, lastmaxf = 0.0; | |
269 static float logminf = 0.0, logmaxf = 0.0; | |
270 | |
271 if (lastminf != minf) { | |
272 lastminf = (minf == 0.0 ? 1.0 : minf); | |
273 logminf = log10f(minf); | |
274 } | |
275 if (lastmaxf != maxf) { | |
276 lastmaxf = (maxf < lastminf ? lastminf : maxf); | |
277 logmaxf = log10f(maxf); | |
278 } | |
279 | |
280 if (logminf == logmaxf) return 0; | |
281 return h - (h * (log10f(frequency) - logminf)) / (logmaxf - logminf); | |
282 | |
283 } else { | |
284 | |
285 if (minf == maxf) return 0; | |
286 return h - (h * (frequency - minf)) / (maxf - minf); | |
287 } | |
288 } | |
289 | |
290 float | |
291 View::getFrequencyForY(int y, | |
292 float minf, | |
293 float maxf, | |
294 bool logarithmic) const | |
295 { | |
296 int h = height(); | |
297 | |
298 if (logarithmic) { | |
299 | |
300 static float lastminf = 0.0, lastmaxf = 0.0; | |
301 static float logminf = 0.0, logmaxf = 0.0; | |
302 | |
303 if (lastminf != minf) { | |
304 lastminf = (minf == 0.0 ? 1.0 : minf); | |
305 logminf = log10f(minf); | |
306 } | |
307 if (lastmaxf != maxf) { | |
308 lastmaxf = (maxf < lastminf ? lastminf : maxf); | |
309 logmaxf = log10f(maxf); | |
310 } | |
311 | |
312 if (logminf == logmaxf) return 0; | |
313 return pow(10.f, logminf + ((logmaxf - logminf) * (h - y)) / h); | |
314 | |
315 } else { | |
316 | |
317 if (minf == maxf) return 0; | |
318 return minf + ((h - y) * (maxf - minf)) / h; | |
319 } | |
256 } | 320 } |
257 | 321 |
258 int | 322 int |
259 View::getZoomLevel() const | 323 View::getZoomLevel() const |
260 { | 324 { |