comparison layer/SpectrumLayer.cpp @ 199:45e995ed84d9

* Flesh out feature descriptions for spectrum
author Chris Cannam
date Mon, 05 Feb 2007 16:11:49 +0000
parents 4a3bdde1ef13
children 34bbbcb3c01f
comparison
equal deleted inserted replaced
198:c2ed5014d4ff 199:45e995ed84d9
268 QString &units) const 268 QString &units) const
269 { 269 {
270 return false; 270 return false;
271 } 271 }
272 272
273 QString
274 SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const
275 {
276 if (!m_sliceableModel) return "";
277
278 int minbin = 0, maxbin = 0, range = 0;
279 QString genericDesc = SliceLayer::getFeatureDescription
280 (v, p, false, minbin, maxbin, range);
281
282 if (genericDesc == "") return "";
283
284 float minvalue = 0.f;
285 if (minbin < m_values.size()) minvalue = m_values[minbin];
286
287 float maxvalue = minvalue;
288 if (maxbin < m_values.size()) maxvalue = m_values[maxbin];
289
290 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
291
292 QString binstr;
293 QString hzstr;
294 int minfreq = lrintf((minbin * m_sliceableModel->getSampleRate()) /
295 m_windowSize);
296 int maxfreq = lrintf((std::max(maxbin, minbin+1)
297 * m_sliceableModel->getSampleRate()) /
298 m_windowSize);
299
300 if (maxbin != minbin) {
301 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
302 } else {
303 binstr = QString("%1").arg(minbin+1);
304 }
305 if (minfreq != maxfreq) {
306 hzstr = tr("%1 - %2 Hz").arg(minfreq).arg(maxfreq);
307 } else {
308 hzstr = tr("%1 Hz").arg(minfreq);
309 }
310
311 QString valuestr;
312 if (maxvalue != minvalue) {
313 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
314 } else {
315 valuestr = QString("%1").arg(minvalue);
316 }
317
318 QString dbstr;
319 float mindb = AudioLevel::multiplier_to_dB(minvalue);
320 float maxdb = AudioLevel::multiplier_to_dB(maxvalue);
321 QString mindbstr;
322 QString maxdbstr;
323 if (mindb == AudioLevel::DB_FLOOR) {
324 mindbstr = tr("-Inf");
325 } else {
326 mindbstr = QString("%1").arg(lrintf(mindb));
327 }
328 if (maxdb == AudioLevel::DB_FLOOR) {
329 maxdbstr = tr("-Inf");
330 } else {
331 maxdbstr = QString("%1").arg(lrintf(maxdb));
332 }
333 if (lrintf(mindb) != lrintf(maxdb)) {
334 dbstr = tr("%1 - %2").arg(mindbstr).arg(maxdbstr);
335 } else {
336 dbstr = tr("%1").arg(mindbstr);
337 }
338
339 QString description;
340
341 if (range > m_sliceableModel->getResolution()) {
342 description = tr("%1\nBin:\t%2 (%3)\n%4 value:\t%5\ndB:\t%6")
343 .arg(genericDesc)
344 .arg(binstr)
345 .arg(hzstr)
346 .arg(m_samplingMode == NearestSample ? tr("First") :
347 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
348 .arg(valuestr)
349 .arg(dbstr);
350 } else {
351 description = tr("%1\nBin:\t%2 (%3)\nValue:\t%4\ndB:\t%5")
352 .arg(genericDesc)
353 .arg(binstr)
354 .arg(hzstr)
355 .arg(valuestr)
356 .arg(dbstr);
357 }
358
359 return description;
360 }
361
362
363