comparison layer/SpectrogramLayer.cpp @ 41:f2c416cbdaa9

* Add time/Hz description for waveform model to the bottom right of a pane containing a waveform (also tried this in the status bar, wasn't so good) * Further spectrogram fixes
author Chris Cannam
date Fri, 24 Feb 2006 17:26:11 +0000
parents 3be4438b186d
children 1bdf285c4eac
comparison
equal deleted inserted replaced
40:3be4438b186d 41:f2c416cbdaa9
68 setWindowOverlap(90); 68 setWindowOverlap(90);
69 setWindowType(BlackmanWindow); 69 setWindowType(BlackmanWindow);
70 setMaxFrequency(2000); 70 setMaxFrequency(2000);
71 setMinFrequency(40); 71 setMinFrequency(40);
72 setFrequencyScale(LogFrequencyScale); 72 setFrequencyScale(LogFrequencyScale);
73 setColourScale(dBColourScale); 73 setColourScale(MeterColourScale);
74 setBinDisplay(PeakFrequencies); 74 setBinDisplay(PeakFrequencies);
75 setNormalizeColumns(true); 75 setNormalizeColumns(true);
76 } 76 }
77 77
78 if (m_view) m_view->setLightBackground(false); 78 if (m_view) m_view->setLightBackground(false);
1219 1219
1220 m_factor = (float *)realloc(m_factor, width * sizeof(float)); 1220 m_factor = (float *)realloc(m_factor, width * sizeof(float));
1221 1221
1222 m_width = width; 1222 m_width = width;
1223 m_height = height; 1223 m_height = height;
1224
1225 std::cerr << "done, width = " << m_width << " height = " << m_height << std::endl;
1224 } 1226 }
1225 1227
1226 void 1228 void
1227 SpectrogramLayer::Cache::resize(uint16_t **&array, size_t width, size_t height) 1229 SpectrogramLayer::Cache::resize(uint16_t **&array, size_t width, size_t height)
1228 { 1230 {
1293 1295
1294 std::cerr << "SpectrogramLayer::CacheFillThread::run: model is ready" << std::endl; 1296 std::cerr << "SpectrogramLayer::CacheFillThread::run: model is ready" << std::endl;
1295 1297
1296 size_t start = m_layer.m_model->getStartFrame(); 1298 size_t start = m_layer.m_model->getStartFrame();
1297 size_t end = m_layer.m_model->getEndFrame(); 1299 size_t end = m_layer.m_model->getEndFrame();
1300
1301 std::cerr << "start = " << start << ", end = " << end << std::endl;
1298 1302
1299 WindowType windowType = m_layer.m_windowType; 1303 WindowType windowType = m_layer.m_windowType;
1300 size_t windowSize = m_layer.m_windowSize; 1304 size_t windowSize = m_layer.m_windowSize;
1301 size_t windowIncrement = m_layer.getWindowIncrement(); 1305 size_t windowIncrement = m_layer.getWindowIncrement();
1302 1306
1531 1535
1532 // Each pixel column covers an exact range of sample frames: 1536 // Each pixel column covers an exact range of sample frames:
1533 int f0 = getFrameForX(x) - modelStart; 1537 int f0 = getFrameForX(x) - modelStart;
1534 int f1 = getFrameForX(x + 1) - modelStart - 1; 1538 int f1 = getFrameForX(x + 1) - modelStart - 1;
1535 1539
1536 if (f1 < int(modelStart) || f0 > int(modelEnd)) return false; 1540 if (f1 < int(modelStart) || f0 > int(modelEnd)) {
1541 return false;
1542 }
1537 1543
1538 // And that range may be drawn from a possibly non-integral 1544 // And that range may be drawn from a possibly non-integral
1539 // range of spectrogram windows: 1545 // range of spectrogram windows:
1540 1546
1541 size_t windowIncrement = getWindowIncrement(); 1547 size_t windowIncrement = getWindowIncrement();
1862 int h = y1 - y0; 1868 int h = y1 - y0;
1863 1869
1864 // std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl; 1870 // std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl;
1865 1871
1866 QImage scaled(w, h, QImage::Format_RGB32); 1872 QImage scaled(w, h, QImage::Format_RGB32);
1867 scaled.fill(0); 1873 scaled.fill(m_cache->getColour(0).rgb());
1868 1874
1869 float ymag[h]; 1875 float ymag[h];
1870 float ydiv[h]; 1876 float ydiv[h];
1871 1877
1872 int sr = m_model->getSampleRate(); 1878 int sr = m_model->getSampleRate();
1908 1914
1909 float s0 = 0, s1 = 0; 1915 float s0 = 0, s1 = 0;
1910 1916
1911 if (!getXBinRange(x0 + x, s0, s1)) { 1917 if (!getXBinRange(x0 + x, s0, s1)) {
1912 assert(x <= scaled.width()); 1918 assert(x <= scaled.width());
1913 for (int y = 0; y < h; ++y) {
1914 scaled.setPixel(x, y, qRgb(0, 0, 0));
1915 }
1916 m_mutex.unlock(); 1919 m_mutex.unlock();
1917 continue; 1920 continue;
1918 } 1921 }
1919 1922
1920 int s0i = int(s0 + 0.001); 1923 int s0i = int(s0 + 0.001);
2336 int y = lrintf(m_view->getYForFrequency(f, minf, maxf, true)); 2339 int y = lrintf(m_view->getYForFrequency(f, minf, maxf, true));
2337 int n = (i % 12); 2340 int n = (i % 12);
2338 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { 2341 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) {
2339 // black notes 2342 // black notes
2340 paint.drawLine(w - pkw, y, w, y); 2343 paint.drawLine(w - pkw, y, w, y);
2341 paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, 2*((py-y)/4)); 2344 int rh = ((py - y) / 4) * 2;
2345 if (rh < 2) rh = 2;
2346 paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, rh);
2342 } else if (n == 0 || n == 5) { 2347 } else if (n == 0 || n == 5) {
2343 // C, A 2348 // C, A
2344 if (py < h) { 2349 if (py < h) {
2345 paint.drawLine(w - pkw, (y + py) / 2, w, (y + py) / 2); 2350 paint.drawLine(w - pkw, (y + py) / 2, w, (y + py) / 2);
2346 } 2351 }