Mercurial > hg > svgui
comparison layer/SliceLayer.cpp @ 284:1284955856ab
* threshold, show-peaks properties in spectrum
author | Chris Cannam |
---|---|
date | Fri, 06 Jul 2007 15:17:35 +0000 |
parents | 3c402c6052f6 |
children | 9dd432665059 |
comparison
equal
deleted
inserted
replaced
283:86a112b5b319 | 284:1284955856ab |
---|---|
34 m_energyScale(dBScale), | 34 m_energyScale(dBScale), |
35 m_samplingMode(SampleMean), | 35 m_samplingMode(SampleMean), |
36 m_plotStyle(PlotSteps), | 36 m_plotStyle(PlotSteps), |
37 m_binScale(LinearBins), | 37 m_binScale(LinearBins), |
38 m_normalize(false), | 38 m_normalize(false), |
39 m_threshold(0.0), | |
40 m_initialThreshold(0.0), | |
39 m_gain(1.0), | 41 m_gain(1.0), |
40 m_currentf0(0), | 42 m_currentf0(0), |
41 m_currentf1(0) | 43 m_currentf1(0) |
42 { | 44 { |
43 } | 45 } |
238 | 240 |
239 value *= m_gain; | 241 value *= m_gain; |
240 | 242 |
241 int yorigin = m_yorigins[v]; | 243 int yorigin = m_yorigins[v]; |
242 int h = m_heights[v]; | 244 int h = m_heights[v]; |
243 float thresh = -80.f; | 245 float thresh = getThresholdDb(); |
244 | 246 |
245 float y = 0.f; | 247 float y = 0.f; |
246 | 248 |
247 if (h <= 0) return y; | 249 if (h <= 0) return y; |
248 | 250 |
263 norm = float(y) / float(h); | 265 norm = float(y) / float(h); |
264 y = yorigin - y; | 266 y = yorigin - y; |
265 break; | 267 break; |
266 | 268 |
267 default: | 269 default: |
268 norm = value; | 270 std::cerr << "thresh = " << m_threshold << std::endl; |
269 y = yorigin - (float(h) * value); | 271 norm = (fabsf(value) - m_threshold); |
272 if (norm < 0) norm = 0; | |
273 y = yorigin - (float(h) * norm); | |
270 break; | 274 break; |
271 } | 275 } |
272 | 276 |
273 return y; | 277 return y; |
274 } | 278 } |
280 | 284 |
281 if (m_yorigins.find(v) == m_yorigins.end()) return value; | 285 if (m_yorigins.find(v) == m_yorigins.end()) return value; |
282 | 286 |
283 int yorigin = m_yorigins[v]; | 287 int yorigin = m_yorigins[v]; |
284 int h = m_heights[v]; | 288 int h = m_heights[v]; |
285 float thresh = -80.f; | 289 float thresh = getThresholdDb(); |
286 | 290 |
287 if (h <= 0) return value; | 291 if (h <= 0) return value; |
288 | 292 |
289 y = yorigin - y; | 293 y = yorigin - y; |
290 | 294 |
300 case MeterScale: | 304 case MeterScale: |
301 value = AudioLevel::preview_to_multiplier(lrintf(y), h); | 305 value = AudioLevel::preview_to_multiplier(lrintf(y), h); |
302 break; | 306 break; |
303 | 307 |
304 default: | 308 default: |
305 value = y / h; | 309 value = y / h + m_threshold; |
306 } | 310 } |
307 | 311 |
308 return value / m_gain; | 312 return value / m_gain; |
309 } | 313 } |
310 | 314 |
356 int f0x = v->getXForFrame(f0); | 360 int f0x = v->getXForFrame(f0); |
357 f0 = v->getFrameForX(f0x); | 361 f0 = v->getFrameForX(f0x); |
358 size_t f1 = v->getFrameForX(f0x + 1); | 362 size_t f1 = v->getFrameForX(f0x + 1); |
359 if (f1 > f0) --f1; | 363 if (f1 > f0) --f1; |
360 | 364 |
361 std::cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << std::endl; | 365 // std::cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << std::endl; |
362 | 366 |
363 size_t res = m_sliceableModel->getResolution(); | 367 size_t res = m_sliceableModel->getResolution(); |
364 size_t col0 = f0 / res; | 368 size_t col0 = f0 / res; |
365 size_t col1 = col0; | 369 size_t col1 = col0; |
366 if (m_samplingMode != NearestSample) col1 = f1 / res; | 370 if (m_samplingMode != NearestSample) col1 = f1 / res; |
367 f0 = col0 * res; | 371 f0 = col0 * res; |
368 f1 = (col1 + 1) * res - 1; | 372 f1 = (col1 + 1) * res - 1; |
369 | 373 |
370 std::cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << std::endl; | 374 // std::cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << std::endl; |
371 | 375 |
372 m_currentf0 = f0; | 376 m_currentf0 = f0; |
373 m_currentf1 = f1; | 377 m_currentf1 = f1; |
374 | 378 |
375 BiasCurve curve; | 379 BiasCurve curve; |
508 } | 512 } |
509 | 513 |
510 void | 514 void |
511 SliceLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const | 515 SliceLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const |
512 { | 516 { |
513 float thresh = 0; | 517 float thresh = m_threshold; |
514 if (m_energyScale != LinearScale) { | 518 if (m_energyScale != LinearScale) { |
515 thresh = AudioLevel::dB_to_multiplier(-80); //!!! thresh | 519 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); |
516 } | 520 } |
517 | 521 |
518 // int h = (rect.height() * 3) / 4; | 522 // int h = (rect.height() * 3) / 4; |
519 // int y = (rect.height() / 2) - (h / 2); | 523 // int y = (rect.height() / 2) - (h / 2); |
520 | 524 |
549 list.push_back("Colour"); | 553 list.push_back("Colour"); |
550 list.push_back("Plot Type"); | 554 list.push_back("Plot Type"); |
551 // list.push_back("Sampling Mode"); | 555 // list.push_back("Sampling Mode"); |
552 list.push_back("Scale"); | 556 list.push_back("Scale"); |
553 list.push_back("Normalize"); | 557 list.push_back("Normalize"); |
558 list.push_back("Threshold"); | |
554 list.push_back("Gain"); | 559 list.push_back("Gain"); |
555 list.push_back("Bin Scale"); | 560 list.push_back("Bin Scale"); |
556 | 561 |
557 return list; | 562 return list; |
558 } | 563 } |
562 { | 567 { |
563 if (name == "Colour") return tr("Colour"); | 568 if (name == "Colour") return tr("Colour"); |
564 if (name == "Plot Type") return tr("Plot Type"); | 569 if (name == "Plot Type") return tr("Plot Type"); |
565 if (name == "Energy Scale") return tr("Scale"); | 570 if (name == "Energy Scale") return tr("Scale"); |
566 if (name == "Normalize") return tr("Normalize"); | 571 if (name == "Normalize") return tr("Normalize"); |
572 if (name == "Threshold") return tr("Threshold"); | |
567 if (name == "Gain") return tr("Gain"); | 573 if (name == "Gain") return tr("Gain"); |
568 if (name == "Sampling Mode") return tr("Sampling Mode"); | 574 if (name == "Sampling Mode") return tr("Sampling Mode"); |
569 if (name == "Bin Scale") return tr("Plot X Scale"); | 575 if (name == "Bin Scale") return tr("Plot X Scale"); |
570 return ""; | 576 return ""; |
571 } | 577 } |
573 Layer::PropertyType | 579 Layer::PropertyType |
574 SliceLayer::getPropertyType(const PropertyName &name) const | 580 SliceLayer::getPropertyType(const PropertyName &name) const |
575 { | 581 { |
576 if (name == "Gain") return RangeProperty; | 582 if (name == "Gain") return RangeProperty; |
577 if (name == "Normalize") return ToggleProperty; | 583 if (name == "Normalize") return ToggleProperty; |
584 if (name == "Threshold") return RangeProperty; | |
578 return ValueProperty; | 585 return ValueProperty; |
579 } | 586 } |
580 | 587 |
581 QString | 588 QString |
582 SliceLayer::getPropertyGroupName(const PropertyName &name) const | 589 SliceLayer::getPropertyGroupName(const PropertyName &name) const |
583 { | 590 { |
584 if (name == "Scale" || | 591 if (name == "Scale" || |
585 name == "Normalize" || | 592 name == "Normalize" || |
586 name == "Sampling Mode" || | 593 name == "Sampling Mode" || |
594 name == "Threshold" || | |
587 name == "Gain") return tr("Scale"); | 595 name == "Gain") return tr("Scale"); |
588 if (name == "Plot Type" || | 596 if (name == "Plot Type" || |
589 name == "Bin Scale") return tr("Plot Type"); | 597 name == "Bin Scale") return tr("Plot Type"); |
590 return QString(); | 598 return QString(); |
591 } | 599 } |
608 *deflt = 0; | 616 *deflt = 0; |
609 | 617 |
610 std::cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << std::endl; | 618 std::cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << std::endl; |
611 | 619 |
612 val = lrint(log10(m_gain) * 20.0); | 620 val = lrint(log10(m_gain) * 20.0); |
621 if (val < *min) val = *min; | |
622 if (val > *max) val = *max; | |
623 | |
624 } else if (name == "Threshold") { | |
625 | |
626 *min = -80; | |
627 *max = 0; | |
628 | |
629 *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold)); | |
630 if (*deflt < *min) *deflt = *min; | |
631 if (*deflt > *max) *deflt = *max; | |
632 | |
633 val = lrintf(AudioLevel::multiplier_to_dB(m_threshold)); | |
613 if (val < *min) val = *min; | 634 if (val < *min) val = *min; |
614 if (val > *max) val = *max; | 635 if (val > *max) val = *max; |
615 | 636 |
616 } else if (name == "Normalize") { | 637 } else if (name == "Normalize") { |
617 | 638 |
741 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const | 762 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const |
742 { | 763 { |
743 if (name == "Gain") { | 764 if (name == "Gain") { |
744 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); | 765 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); |
745 } | 766 } |
767 if (name == "Threshold") { | |
768 return new LinearRangeMapper(-80, 0, -80, 0, tr("dB")); | |
769 } | |
746 return 0; | 770 return 0; |
747 } | 771 } |
748 | 772 |
749 void | 773 void |
750 SliceLayer::setProperty(const PropertyName &name, int value) | 774 SliceLayer::setProperty(const PropertyName &name, int value) |
751 { | 775 { |
752 if (name == "Gain") { | 776 if (name == "Gain") { |
753 setGain(pow(10, float(value)/20.0)); | 777 setGain(pow(10, float(value)/20.0)); |
778 } else if (name == "Threshold") { | |
779 if (value == -80) setThreshold(0.0); | |
780 else setThreshold(AudioLevel::dB_to_multiplier(value)); | |
754 } else if (name == "Colour") { | 781 } else if (name == "Colour") { |
755 if (m_plotStyle == PlotFilledBlocks) { | 782 if (m_plotStyle == PlotFilledBlocks) { |
756 setFillColourMap(value); | 783 setFillColourMap(value); |
757 } else { | 784 } else { |
758 switch (value) { | 785 switch (value) { |
853 m_normalize = n; | 880 m_normalize = n; |
854 emit layerParametersChanged(); | 881 emit layerParametersChanged(); |
855 } | 882 } |
856 | 883 |
857 void | 884 void |
885 SliceLayer::setThreshold(float thresh) | |
886 { | |
887 if (m_threshold == thresh) return; | |
888 m_threshold = thresh; | |
889 emit layerParametersChanged(); | |
890 } | |
891 | |
892 void | |
858 SliceLayer::setGain(float gain) | 893 SliceLayer::setGain(float gain) |
859 { | 894 { |
860 if (m_gain == gain) return; | 895 if (m_gain == gain) return; |
861 m_gain = gain; | 896 m_gain = gain; |
862 emit layerParametersChanged(); | 897 emit layerParametersChanged(); |
898 } | |
899 | |
900 float | |
901 SliceLayer::getThresholdDb() const | |
902 { | |
903 if (m_threshold == 0.0) return -80.f; | |
904 float db = AudioLevel::multiplier_to_dB(m_threshold); | |
905 return db; | |
863 } | 906 } |
864 | 907 |
865 QString | 908 QString |
866 SliceLayer::toXmlString(QString indent, QString extraAttributes) const | 909 SliceLayer::toXmlString(QString indent, QString extraAttributes) const |
867 { | 910 { |