comparison layer/SpectrumLayer.cpp @ 1387:bca9870301b7 spectrogramparam

Small speedups
author Chris Cannam
date Mon, 12 Nov 2018 14:48:42 +0000
parents fc3d89f88690
children 1eb560b363e7
comparison
equal deleted inserted replaced
1386:fc3d89f88690 1387:bca9870301b7
703 ColourMapper(ColourMapper::WhiteOnBlack, m_colourInverted, 0, 1); 703 ColourMapper(ColourMapper::WhiteOnBlack, m_colourInverted, 0, 1);
704 704
705 int peakminbin = 0; 705 int peakminbin = 0;
706 int peakmaxbin = fft->getHeight() - 1; 706 int peakmaxbin = fft->getHeight() - 1;
707 double peakmaxfreq = Pitch::getFrequencyForPitch(128); 707 double peakmaxfreq = Pitch::getFrequencyForPitch(128);
708 peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / fft->getSampleRate())); 708 peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) /
709 fft->getSampleRate()));
709 710
710 FFTModel::PeakSet peaks = fft->getPeakFrequencies 711 FFTModel::PeakSet peaks = fft->getPeakFrequencies
711 (FFTModel::MajorPitchAdaptivePeaks, col, peakminbin, peakmaxbin); 712 (FFTModel::MajorPitchAdaptivePeaks, col, peakminbin, peakmaxbin);
712 713
713 BiasCurve curve; 714 BiasCurve curve;
714 getBiasCurve(curve); 715 getBiasCurve(curve);
715 int cs = int(curve.size()); 716 int cs = int(curve.size());
716 717
718 int px = -1;
719
717 for (FFTModel::PeakSet::iterator i = peaks.begin(); 720 for (FFTModel::PeakSet::iterator i = peaks.begin();
718 i != peaks.end(); ++i) { 721 i != peaks.end(); ++i) {
722
723 double freq = i->second;
724 int x = int(lrint(getXForFrequency(v, freq)));
725 if (x == px) {
726 continue;
727 }
719 728
720 int bin = i->first; 729 int bin = i->first;
721 730
722 // cerr << "bin = " << bin << ", thresh = " << thresh << ", value = " << fft->getMagnitudeAt(col, bin) << endl; 731 // cerr << "bin = " << bin << ", thresh = " << thresh << ", value = " << fft->getMagnitudeAt(col, bin) << endl;
723 732
724 double value = fft->getValueAt(col, bin); 733 double value = fft->getValueAt(col, bin);
725 if (value < thresh) continue; 734 if (value < thresh) continue;
726 if (bin < cs) value *= curve[bin]; 735 if (bin < cs) value *= curve[bin];
727 736
728 double freq = i->second;
729 int x = int(lrint(getXForFrequency(v, freq)));
730
731 double norm = 0.f; 737 double norm = 0.f;
732 // don't need return value, need norm: 738 // don't need return value, need norm:
733 (void)getYForValue(v, value, norm); 739 (void)getYForValue(v, value, norm);
734 740
735 paint.setPen(mapper.map(norm)); 741 paint.setPen(QPen(mapper.map(norm), 1));
736 paint.drawLine(x, 0, x, v->getPaintHeight() - scaleHeight - 1); 742 paint.drawLine(x, 0, x, v->getPaintHeight() - scaleHeight - 1);
743
744 px = x;
737 } 745 }
738 746
739 paint.restore(); 747 paint.restore();
740 } 748 }
741 749