Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 805:1d526ba11a24 warnfix_no_size_t
Remove size_t's and fix warnings in layer/
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 15:18:06 +0100 |
parents | 410816717c2c |
children | 4c8ca536b54f |
comparison
equal
deleted
inserted
replaced
782:ddae586bc47b | 805:1d526ba11a24 |
---|---|
139 if (!m_model || !m_model->isOK()) return; | 139 if (!m_model || !m_model->isOK()) return; |
140 | 140 |
141 connectSignals(m_model); | 141 connectSignals(m_model); |
142 | 142 |
143 connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid())); | 143 connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid())); |
144 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), | 144 connect(m_model, SIGNAL(modelChanged(int, int)), |
145 this, SLOT(cacheInvalid(size_t, size_t))); | 145 this, SLOT(cacheInvalid(int, int))); |
146 | 146 |
147 emit modelReplaced(); | 147 emit modelReplaced(); |
148 } | 148 } |
149 | 149 |
150 Layer::PropertyList | 150 Layer::PropertyList |
570 i->second.validArea = QRect(); | 570 i->second.validArea = QRect(); |
571 } | 571 } |
572 } | 572 } |
573 | 573 |
574 void | 574 void |
575 SpectrogramLayer::invalidateImageCaches(size_t startFrame, size_t endFrame) | 575 SpectrogramLayer::invalidateImageCaches(int startFrame, int endFrame) |
576 { | 576 { |
577 for (ViewImageCache::iterator i = m_imageCaches.begin(); | 577 for (ViewImageCache::iterator i = m_imageCaches.begin(); |
578 i != m_imageCaches.end(); ++i) { | 578 i != m_imageCaches.end(); ++i) { |
579 | 579 |
580 //!!! when are views removed from the map? on setLayerDormant? | 580 //!!! when are views removed from the map? on setLayerDormant? |
679 { | 679 { |
680 return m_channel; | 680 return m_channel; |
681 } | 681 } |
682 | 682 |
683 void | 683 void |
684 SpectrogramLayer::setWindowSize(size_t ws) | 684 SpectrogramLayer::setWindowSize(int ws) |
685 { | 685 { |
686 if (m_windowSize == ws) return; | 686 if (m_windowSize == ws) return; |
687 | 687 |
688 invalidateImageCaches(); | 688 invalidateImageCaches(); |
689 | 689 |
693 invalidateFFTModels(); | 693 invalidateFFTModels(); |
694 | 694 |
695 emit layerParametersChanged(); | 695 emit layerParametersChanged(); |
696 } | 696 } |
697 | 697 |
698 size_t | 698 int |
699 SpectrogramLayer::getWindowSize() const | 699 SpectrogramLayer::getWindowSize() const |
700 { | 700 { |
701 return m_windowSize; | 701 return m_windowSize; |
702 } | 702 } |
703 | 703 |
704 void | 704 void |
705 SpectrogramLayer::setWindowHopLevel(size_t v) | 705 SpectrogramLayer::setWindowHopLevel(int v) |
706 { | 706 { |
707 if (m_windowHopLevel == v) return; | 707 if (m_windowHopLevel == v) return; |
708 | 708 |
709 invalidateImageCaches(); | 709 invalidateImageCaches(); |
710 | 710 |
715 emit layerParametersChanged(); | 715 emit layerParametersChanged(); |
716 | 716 |
717 // fillCache(); | 717 // fillCache(); |
718 } | 718 } |
719 | 719 |
720 size_t | 720 int |
721 SpectrogramLayer::getWindowHopLevel() const | 721 SpectrogramLayer::getWindowHopLevel() const |
722 { | 722 { |
723 return m_windowHopLevel; | 723 return m_windowHopLevel; |
724 } | 724 } |
725 | 725 |
726 void | 726 void |
727 SpectrogramLayer::setZeroPadLevel(size_t v) | 727 SpectrogramLayer::setZeroPadLevel(int v) |
728 { | 728 { |
729 if (m_zeroPadLevel == v) return; | 729 if (m_zeroPadLevel == v) return; |
730 | 730 |
731 invalidateImageCaches(); | 731 invalidateImageCaches(); |
732 | 732 |
736 invalidateFFTModels(); | 736 invalidateFFTModels(); |
737 | 737 |
738 emit layerParametersChanged(); | 738 emit layerParametersChanged(); |
739 } | 739 } |
740 | 740 |
741 size_t | 741 int |
742 SpectrogramLayer::getZeroPadLevel() const | 742 SpectrogramLayer::getZeroPadLevel() const |
743 { | 743 { |
744 return m_zeroPadLevel; | 744 return m_zeroPadLevel; |
745 } | 745 } |
746 | 746 |
802 { | 802 { |
803 return m_threshold; | 803 return m_threshold; |
804 } | 804 } |
805 | 805 |
806 void | 806 void |
807 SpectrogramLayer::setMinFrequency(size_t mf) | 807 SpectrogramLayer::setMinFrequency(int mf) |
808 { | 808 { |
809 if (m_minFrequency == mf) return; | 809 if (m_minFrequency == mf) return; |
810 | 810 |
811 // SVDEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl; | 811 // SVDEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl; |
812 | 812 |
816 m_minFrequency = mf; | 816 m_minFrequency = mf; |
817 | 817 |
818 emit layerParametersChanged(); | 818 emit layerParametersChanged(); |
819 } | 819 } |
820 | 820 |
821 size_t | 821 int |
822 SpectrogramLayer::getMinFrequency() const | 822 SpectrogramLayer::getMinFrequency() const |
823 { | 823 { |
824 return m_minFrequency; | 824 return m_minFrequency; |
825 } | 825 } |
826 | 826 |
827 void | 827 void |
828 SpectrogramLayer::setMaxFrequency(size_t mf) | 828 SpectrogramLayer::setMaxFrequency(int mf) |
829 { | 829 { |
830 if (m_maxFrequency == mf) return; | 830 if (m_maxFrequency == mf) return; |
831 | 831 |
832 // SVDEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl; | 832 // SVDEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl; |
833 | 833 |
837 m_maxFrequency = mf; | 837 m_maxFrequency = mf; |
838 | 838 |
839 emit layerParametersChanged(); | 839 emit layerParametersChanged(); |
840 } | 840 } |
841 | 841 |
842 size_t | 842 int |
843 SpectrogramLayer::getMaxFrequency() const | 843 SpectrogramLayer::getMaxFrequency() const |
844 { | 844 { |
845 return m_maxFrequency; | 845 return m_maxFrequency; |
846 } | 846 } |
847 | 847 |
1047 invalidateImageCaches(); | 1047 invalidateImageCaches(); |
1048 invalidateMagnitudes(); | 1048 invalidateMagnitudes(); |
1049 } | 1049 } |
1050 | 1050 |
1051 void | 1051 void |
1052 SpectrogramLayer::cacheInvalid(size_t from, size_t to) | 1052 SpectrogramLayer::cacheInvalid(int from, int to) |
1053 { | 1053 { |
1054 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1054 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1055 SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; | 1055 SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; |
1056 #endif | 1056 #endif |
1057 | 1057 |
1072 | 1072 |
1073 for (ViewFFTMap::iterator i = m_fftModels.begin(); | 1073 for (ViewFFTMap::iterator i = m_fftModels.begin(); |
1074 i != m_fftModels.end(); ++i) { | 1074 i != m_fftModels.end(); ++i) { |
1075 | 1075 |
1076 const FFTModel *model = i->second.first; | 1076 const FFTModel *model = i->second.first; |
1077 size_t lastFill = i->second.second; | 1077 int lastFill = i->second.second; |
1078 | 1078 |
1079 if (model) { | 1079 if (model) { |
1080 | 1080 |
1081 size_t fill = model->getFillExtent(); | 1081 int fill = model->getFillExtent(); |
1082 | 1082 |
1083 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1083 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1084 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; | 1084 SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; |
1085 #endif | 1085 #endif |
1086 | 1086 |
1268 { | 1268 { |
1269 int sr = m_model->getSampleRate(); | 1269 int sr = m_model->getSampleRate(); |
1270 float minf = float(sr) / m_fftSize; | 1270 float minf = float(sr) / m_fftSize; |
1271 | 1271 |
1272 if (m_minFrequency > 0.0) { | 1272 if (m_minFrequency > 0.0) { |
1273 size_t minbin = size_t((double(m_minFrequency) * m_fftSize) / sr + 0.01); | 1273 int minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.01); |
1274 if (minbin < 1) minbin = 1; | 1274 if (minbin < 1) minbin = 1; |
1275 minf = minbin * sr / m_fftSize; | 1275 minf = minbin * sr / m_fftSize; |
1276 } | 1276 } |
1277 | 1277 |
1278 return minf; | 1278 return minf; |
1283 { | 1283 { |
1284 int sr = m_model->getSampleRate(); | 1284 int sr = m_model->getSampleRate(); |
1285 float maxf = float(sr) / 2; | 1285 float maxf = float(sr) / 2; |
1286 | 1286 |
1287 if (m_maxFrequency > 0.0) { | 1287 if (m_maxFrequency > 0.0) { |
1288 size_t maxbin = size_t((double(m_maxFrequency) * m_fftSize) / sr + 0.1); | 1288 int maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); |
1289 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; | 1289 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; |
1290 maxf = maxbin * sr / m_fftSize; | 1290 maxf = maxbin * sr / m_fftSize; |
1291 } | 1291 } |
1292 | 1292 |
1293 return maxf; | 1293 return maxf; |
1346 } | 1346 } |
1347 | 1347 |
1348 bool | 1348 bool |
1349 SpectrogramLayer::getXBinRange(View *v, int x, float &s0, float &s1) const | 1349 SpectrogramLayer::getXBinRange(View *v, int x, float &s0, float &s1) const |
1350 { | 1350 { |
1351 size_t modelStart = m_model->getStartFrame(); | 1351 int modelStart = m_model->getStartFrame(); |
1352 size_t modelEnd = m_model->getEndFrame(); | 1352 int modelEnd = m_model->getEndFrame(); |
1353 | 1353 |
1354 // Each pixel column covers an exact range of sample frames: | 1354 // Each pixel column covers an exact range of sample frames: |
1355 int f0 = v->getFrameForX(x) - modelStart; | 1355 int f0 = v->getFrameForX(x) - modelStart; |
1356 int f1 = v->getFrameForX(x + 1) - modelStart - 1; | 1356 int f1 = v->getFrameForX(x + 1) - modelStart - 1; |
1357 | 1357 |
1360 } | 1360 } |
1361 | 1361 |
1362 // And that range may be drawn from a possibly non-integral | 1362 // And that range may be drawn from a possibly non-integral |
1363 // range of spectrogram windows: | 1363 // range of spectrogram windows: |
1364 | 1364 |
1365 size_t windowIncrement = getWindowIncrement(); | 1365 int windowIncrement = getWindowIncrement(); |
1366 s0 = float(f0) / windowIncrement; | 1366 s0 = float(f0) / windowIncrement; |
1367 s1 = float(f1) / windowIncrement; | 1367 s1 = float(f1) / windowIncrement; |
1368 | 1368 |
1369 return true; | 1369 return true; |
1370 } | 1370 } |
1432 int q0i = int(q0 + 0.001); | 1432 int q0i = int(q0 + 0.001); |
1433 int q1i = int(q1); | 1433 int q1i = int(q1); |
1434 | 1434 |
1435 int sr = m_model->getSampleRate(); | 1435 int sr = m_model->getSampleRate(); |
1436 | 1436 |
1437 size_t windowSize = m_windowSize; | |
1438 size_t windowIncrement = getWindowIncrement(); | |
1439 | |
1440 bool haveAdj = false; | 1437 bool haveAdj = false; |
1441 | 1438 |
1442 bool peaksOnly = (m_binDisplay == PeakBins || | 1439 bool peaksOnly = (m_binDisplay == PeakBins || |
1443 m_binDisplay == PeakFrequencies); | 1440 m_binDisplay == PeakFrequencies); |
1444 | 1441 |
1455 if (peaksOnly && !fft->isLocalPeak(s, q)) continue; | 1452 if (peaksOnly && !fft->isLocalPeak(s, q)) continue; |
1456 | 1453 |
1457 if (!fft->isOverThreshold(s, q, m_threshold * (m_fftSize/2))) continue; | 1454 if (!fft->isOverThreshold(s, q, m_threshold * (m_fftSize/2))) continue; |
1458 | 1455 |
1459 float freq = binfreq; | 1456 float freq = binfreq; |
1460 bool steady = false; | |
1461 | 1457 |
1462 if (s < int(fft->getWidth()) - 1) { | 1458 if (s < int(fft->getWidth()) - 1) { |
1463 | 1459 |
1464 fft->estimateStableFrequency(s, q, freq); | 1460 fft->estimateStableFrequency(s, q, freq); |
1465 | 1461 |
1499 int s0i = int(s0 + 0.001); | 1495 int s0i = int(s0 + 0.001); |
1500 int s1i = int(s1); | 1496 int s1i = int(s1); |
1501 | 1497 |
1502 bool rv = false; | 1498 bool rv = false; |
1503 | 1499 |
1504 size_t zp = getZeroPadLevel(v); | 1500 int zp = getZeroPadLevel(v); |
1505 q0i *= zp + 1; | 1501 q0i *= zp + 1; |
1506 q1i *= zp + 1; | 1502 q1i *= zp + 1; |
1507 | 1503 |
1508 FFTModel *fft = getFFTModel(v); | 1504 FFTModel *fft = getFFTModel(v); |
1509 | 1505 |
1545 } | 1541 } |
1546 | 1542 |
1547 return rv; | 1543 return rv; |
1548 } | 1544 } |
1549 | 1545 |
1550 size_t | 1546 int |
1551 SpectrogramLayer::getZeroPadLevel(const View *v) const | 1547 SpectrogramLayer::getZeroPadLevel(const View *v) const |
1552 { | 1548 { |
1553 //!!! tidy all this stuff | 1549 //!!! tidy all this stuff |
1554 | 1550 |
1555 if (m_binDisplay != AllBins) return 0; | 1551 if (m_binDisplay != AllBins) return 0; |
1562 | 1558 |
1563 if (m_frequencyScale == LogFrequencyScale) return 3; | 1559 if (m_frequencyScale == LogFrequencyScale) return 3; |
1564 | 1560 |
1565 int sr = m_model->getSampleRate(); | 1561 int sr = m_model->getSampleRate(); |
1566 | 1562 |
1567 size_t maxbin = m_fftSize / 2; | 1563 int maxbin = m_fftSize / 2; |
1568 if (m_maxFrequency > 0) { | 1564 if (m_maxFrequency > 0) { |
1569 maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); | 1565 maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); |
1570 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; | 1566 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; |
1571 } | 1567 } |
1572 | 1568 |
1573 size_t minbin = 1; | 1569 int minbin = 1; |
1574 if (m_minFrequency > 0) { | 1570 if (m_minFrequency > 0) { |
1575 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.1); | 1571 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.1); |
1576 if (minbin < 1) minbin = 1; | 1572 if (minbin < 1) minbin = 1; |
1577 if (minbin >= maxbin) minbin = maxbin - 1; | 1573 if (minbin >= maxbin) minbin = maxbin - 1; |
1578 } | 1574 } |
1588 } else { | 1584 } else { |
1589 return 0; // 1x | 1585 return 0; // 1x |
1590 } | 1586 } |
1591 } | 1587 } |
1592 | 1588 |
1593 size_t | 1589 int |
1594 SpectrogramLayer::getFFTSize(const View *v) const | 1590 SpectrogramLayer::getFFTSize(const View *v) const |
1595 { | 1591 { |
1596 return m_fftSize * (getZeroPadLevel(v) + 1); | 1592 return m_fftSize * (getZeroPadLevel(v) + 1); |
1597 } | 1593 } |
1598 | 1594 |
1599 FFTModel * | 1595 FFTModel * |
1600 SpectrogramLayer::getFFTModel(const View *v) const | 1596 SpectrogramLayer::getFFTModel(const View *v) const |
1601 { | 1597 { |
1602 if (!m_model) return 0; | 1598 if (!m_model) return 0; |
1603 | 1599 |
1604 size_t fftSize = getFFTSize(v); | 1600 int fftSize = getFFTSize(v); |
1605 | 1601 |
1606 if (m_fftModels.find(v) != m_fftModels.end()) { | 1602 if (m_fftModels.find(v) != m_fftModels.end()) { |
1607 if (m_fftModels[v].first == 0) { | 1603 if (m_fftModels[v].first == 0) { |
1608 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1604 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1609 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; | 1605 SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; |
1801 // and accountable for when determining whether we need the cache | 1797 // and accountable for when determining whether we need the cache |
1802 // in the cache-fill thread above. | 1798 // in the cache-fill thread above. |
1803 //!!! no longer use cache-fill thread | 1799 //!!! no longer use cache-fill thread |
1804 const_cast<SpectrogramLayer *>(this)->Layer::setLayerDormant(v, false); | 1800 const_cast<SpectrogramLayer *>(this)->Layer::setLayerDormant(v, false); |
1805 | 1801 |
1806 size_t fftSize = getFFTSize(v); | 1802 int fftSize = getFFTSize(v); |
1807 /* | 1803 /* |
1808 FFTModel *fft = getFFTModel(v); | 1804 FFTModel *fft = getFFTModel(v); |
1809 if (!fft) { | 1805 if (!fft) { |
1810 cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << endl; | 1806 cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << endl; |
1811 return; | 1807 return; |
2121 // padded, to avoid spaces at the top and bottom of the display. | 2117 // padded, to avoid spaces at the top and bottom of the display. |
2122 | 2118 |
2123 // Note fftSize is the actual zero-padded fft size, m_fftSize the | 2119 // Note fftSize is the actual zero-padded fft size, m_fftSize the |
2124 // nominal fft size. | 2120 // nominal fft size. |
2125 | 2121 |
2126 size_t maxbin = m_fftSize / 2; | 2122 int maxbin = m_fftSize / 2; |
2127 if (m_maxFrequency > 0) { | 2123 if (m_maxFrequency > 0) { |
2128 maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.001); | 2124 maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.001); |
2129 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; | 2125 if (maxbin > m_fftSize / 2) maxbin = m_fftSize / 2; |
2130 } | 2126 } |
2131 | 2127 |
2132 size_t minbin = 1; | 2128 int minbin = 1; |
2133 if (m_minFrequency > 0) { | 2129 if (m_minFrequency > 0) { |
2134 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.001); | 2130 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.001); |
2135 // cerr << "m_minFrequency = " << m_minFrequency << " -> minbin = " << minbin << endl; | 2131 // cerr << "m_minFrequency = " << m_minFrequency << " -> minbin = " << minbin << endl; |
2136 if (minbin < 1) minbin = 1; | 2132 if (minbin < 1) minbin = 1; |
2137 if (minbin >= maxbin) minbin = maxbin - 1; | 2133 if (minbin >= maxbin) minbin = maxbin - 1; |
2158 | 2154 |
2159 bool logarithmic = (m_frequencyScale == LogFrequencyScale); | 2155 bool logarithmic = (m_frequencyScale == LogFrequencyScale); |
2160 /* | 2156 /* |
2161 float yforbin[maxbin - minbin + 1]; | 2157 float yforbin[maxbin - minbin + 1]; |
2162 | 2158 |
2163 for (size_t q = minbin; q <= maxbin; ++q) { | 2159 for (int q = minbin; q <= maxbin; ++q) { |
2164 float f0 = (float(q) * sr) / fftSize; | 2160 float f0 = (float(q) * sr) / fftSize; |
2165 yforbin[q - minbin] = | 2161 yforbin[q - minbin] = |
2166 v->getYForFrequency(f0, displayMinFreq, displayMaxFreq, | 2162 v->getYForFrequency(f0, displayMinFreq, displayMaxFreq, |
2167 logarithmic); | 2163 logarithmic); |
2168 } | 2164 } |
2169 */ | 2165 */ |
2170 MagnitudeRange overallMag = m_viewMags[v]; | 2166 MagnitudeRange overallMag = m_viewMags[v]; |
2171 bool overallMagChanged = false; | 2167 bool overallMagChanged = false; |
2172 | 2168 |
2173 bool fftSuspended = false; | |
2174 | |
2175 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2169 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2176 cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl; | 2170 cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl; |
2177 #endif | 2171 #endif |
2178 | |
2179 bool runOutOfData = false; | |
2180 | 2172 |
2181 if (w == 0) { | 2173 if (w == 0) { |
2182 SVDEBUG << "*** NOTE: w == 0" << endl; | 2174 SVDEBUG << "*** NOTE: w == 0" << endl; |
2183 } | 2175 } |
2184 | 2176 |
2185 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2177 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2186 size_t pixels = 0; | 2178 int pixels = 0; |
2187 #endif | 2179 #endif |
2188 | 2180 |
2189 Profiler outerprof("SpectrogramLayer::paint: all cols"); | 2181 Profiler outerprof("SpectrogramLayer::paint: all cols"); |
2190 | 2182 |
2191 // The draw buffer contains a fragment at either our pixel | 2183 // The draw buffer contains a fragment at either our pixel |
2496 #endif | 2488 #endif |
2497 | 2489 |
2498 for (int x = 0; x < w; ++x) { | 2490 for (int x = 0; x < w; ++x) { |
2499 | 2491 |
2500 if (binforx[x] < 0) continue; | 2492 if (binforx[x] < 0) continue; |
2501 | |
2502 float columnMax = 0.f; | |
2503 | 2493 |
2504 int sx0 = binforx[x]; | 2494 int sx0 = binforx[x]; |
2505 int sx1 = sx0; | 2495 int sx1 = sx0; |
2506 if (x+1 < w) sx1 = binforx[x+1]; | 2496 if (x+1 < w) sx1 = binforx[x+1]; |
2507 if (sx0 < 0) sx0 = sx1 - 1; | 2497 if (sx0 < 0) sx0 = sx1 - 1; |
2892 SpectrogramLayer::getCompletion(View *v) const | 2882 SpectrogramLayer::getCompletion(View *v) const |
2893 { | 2883 { |
2894 if (m_updateTimer == 0) return 100; | 2884 if (m_updateTimer == 0) return 100; |
2895 if (m_fftModels.find(v) == m_fftModels.end()) return 100; | 2885 if (m_fftModels.find(v) == m_fftModels.end()) return 100; |
2896 | 2886 |
2897 size_t completion = m_fftModels[v].first->getCompletion(); | 2887 int completion = m_fftModels[v].first->getCompletion(); |
2898 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2888 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2899 SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; | 2889 SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; |
2900 #endif | 2890 #endif |
2901 return completion; | 2891 return completion; |
2902 } | 2892 } |
2941 // SVDEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl; | 2931 // SVDEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl; |
2942 | 2932 |
2943 if (min < 0) min = 0; | 2933 if (min < 0) min = 0; |
2944 if (max > m_model->getSampleRate()/2) max = m_model->getSampleRate()/2; | 2934 if (max > m_model->getSampleRate()/2) max = m_model->getSampleRate()/2; |
2945 | 2935 |
2946 size_t minf = lrintf(min); | 2936 int minf = lrintf(min); |
2947 size_t maxf = lrintf(max); | 2937 int maxf = lrintf(max); |
2948 | 2938 |
2949 if (m_minFrequency == minf && m_maxFrequency == maxf) return true; | 2939 if (m_minFrequency == minf && m_maxFrequency == maxf) return true; |
2950 | 2940 |
2951 invalidateImageCaches(); | 2941 invalidateImageCaches(); |
2952 invalidateMagnitudes(); | 2942 invalidateMagnitudes(); |
2974 return true; | 2964 return true; |
2975 } | 2965 } |
2976 | 2966 |
2977 bool | 2967 bool |
2978 SpectrogramLayer::snapToFeatureFrame(View *, int &frame, | 2968 SpectrogramLayer::snapToFeatureFrame(View *, int &frame, |
2979 size_t &resolution, | 2969 int &resolution, |
2980 SnapType snap) const | 2970 SnapType snap) const |
2981 { | 2971 { |
2982 resolution = getWindowIncrement(); | 2972 resolution = getWindowIncrement(); |
2983 int left = (frame / resolution) * resolution; | 2973 int left = (frame / resolution) * resolution; |
2984 int right = left + resolution; | 2974 int right = left + resolution; |
3290 int h = rect.height(), w = rect.width(); | 3280 int h = rect.height(), w = rect.width(); |
3291 | 3281 |
3292 int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); | 3282 int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); |
3293 int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); | 3283 int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); |
3294 | 3284 |
3295 size_t bins = m_fftSize / 2; | 3285 int bins = m_fftSize / 2; |
3296 int sr = m_model->getSampleRate(); | 3286 int sr = m_model->getSampleRate(); |
3297 | 3287 |
3298 if (m_maxFrequency > 0) { | 3288 if (m_maxFrequency > 0) { |
3299 bins = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); | 3289 bins = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); |
3300 if (bins > m_fftSize / 2) bins = m_fftSize / 2; | 3290 if (bins > m_fftSize / 2) bins = m_fftSize / 2; |
3506 | 3496 |
3507 // int maxStep = mapper.getPositionForValue((float(sr) / m_fftSize) + 0.001); | 3497 // int maxStep = mapper.getPositionForValue((float(sr) / m_fftSize) + 0.001); |
3508 int maxStep = mapper.getPositionForValue(0); | 3498 int maxStep = mapper.getPositionForValue(0); |
3509 int minStep = mapper.getPositionForValue(float(sr) / 2); | 3499 int minStep = mapper.getPositionForValue(float(sr) / 2); |
3510 | 3500 |
3511 size_t initialMax = m_initialMaxFrequency; | 3501 int initialMax = m_initialMaxFrequency; |
3512 if (initialMax == 0) initialMax = sr / 2; | 3502 if (initialMax == 0) initialMax = sr / 2; |
3513 | 3503 |
3514 defaultStep = mapper.getPositionForValue(initialMax) - minStep; | 3504 defaultStep = mapper.getPositionForValue(initialMax) - minStep; |
3515 | 3505 |
3516 // SVDEBUG << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << initialMax << ")" << endl; | 3506 // SVDEBUG << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << initialMax << ")" << endl; |
3682 bool ok = false; | 3672 bool ok = false; |
3683 | 3673 |
3684 int channel = attributes.value("channel").toInt(&ok); | 3674 int channel = attributes.value("channel").toInt(&ok); |
3685 if (ok) setChannel(channel); | 3675 if (ok) setChannel(channel); |
3686 | 3676 |
3687 size_t windowSize = attributes.value("windowSize").toUInt(&ok); | 3677 int windowSize = attributes.value("windowSize").toUInt(&ok); |
3688 if (ok) setWindowSize(windowSize); | 3678 if (ok) setWindowSize(windowSize); |
3689 | 3679 |
3690 size_t windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok); | 3680 int windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok); |
3691 if (ok) setWindowHopLevel(windowHopLevel); | 3681 if (ok) setWindowHopLevel(windowHopLevel); |
3692 else { | 3682 else { |
3693 size_t windowOverlap = attributes.value("windowOverlap").toUInt(&ok); | 3683 int windowOverlap = attributes.value("windowOverlap").toUInt(&ok); |
3694 // a percentage value | 3684 // a percentage value |
3695 if (ok) { | 3685 if (ok) { |
3696 if (windowOverlap == 0) setWindowHopLevel(0); | 3686 if (windowOverlap == 0) setWindowHopLevel(0); |
3697 else if (windowOverlap == 25) setWindowHopLevel(1); | 3687 else if (windowOverlap == 25) setWindowHopLevel(1); |
3698 else if (windowOverlap == 50) setWindowHopLevel(2); | 3688 else if (windowOverlap == 50) setWindowHopLevel(2); |
3705 if (ok) setGain(gain); | 3695 if (ok) setGain(gain); |
3706 | 3696 |
3707 float threshold = attributes.value("threshold").toFloat(&ok); | 3697 float threshold = attributes.value("threshold").toFloat(&ok); |
3708 if (ok) setThreshold(threshold); | 3698 if (ok) setThreshold(threshold); |
3709 | 3699 |
3710 size_t minFrequency = attributes.value("minFrequency").toUInt(&ok); | 3700 int minFrequency = attributes.value("minFrequency").toUInt(&ok); |
3711 if (ok) { | 3701 if (ok) { |
3712 SVDEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl; | 3702 SVDEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl; |
3713 setMinFrequency(minFrequency); | 3703 setMinFrequency(minFrequency); |
3714 } | 3704 } |
3715 | 3705 |
3716 size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok); | 3706 int maxFrequency = attributes.value("maxFrequency").toUInt(&ok); |
3717 if (ok) { | 3707 if (ok) { |
3718 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; | 3708 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; |
3719 setMaxFrequency(maxFrequency); | 3709 setMaxFrequency(maxFrequency); |
3720 } | 3710 } |
3721 | 3711 |