comparison layer/SpectrogramLayer.cpp @ 166:48182241f594

* Add spectrum icon * Start range mapper class for use in mapping between e.g. dial positions and underlying values
author Chris Cannam
date Mon, 16 Oct 2006 13:13:57 +0000
parents f32212631b9c
children 53b9c7656798
comparison
equal deleted inserted replaced
165:793df5f0c6cb 166:48182241f594
1934 if (fftSize != m_fftSize) { 1934 if (fftSize != m_fftSize) {
1935 displayMinFreq = getEffectiveMinFrequency(); 1935 displayMinFreq = getEffectiveMinFrequency();
1936 displayMaxFreq = getEffectiveMaxFrequency(); 1936 displayMaxFreq = getEffectiveMaxFrequency();
1937 } 1937 }
1938 1938
1939 //!!! we will probably only want one of "ymag+ydiv" and "ypeak",
1940 //but we leave them both calculated here for test purposes
1941 float ymag[h]; 1939 float ymag[h];
1942 float ydiv[h]; 1940 float ydiv[h];
1943 float ypeak[h];
1944 float yval[bins + 1]; //!!! cache this? 1941 float yval[bins + 1]; //!!! cache this?
1945 1942
1946 size_t increment = getWindowIncrement(); 1943 size_t increment = getWindowIncrement();
1947 1944
1948 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 1945 bool logarithmic = (m_frequencyScale == LogFrequencyScale);
1966 for (int x = 0; x < w; ++x) { 1963 for (int x = 0; x < w; ++x) {
1967 1964
1968 for (int y = 0; y < h; ++y) { 1965 for (int y = 0; y < h; ++y) {
1969 ymag[y] = 0.f; 1966 ymag[y] = 0.f;
1970 ydiv[y] = 0.f; 1967 ydiv[y] = 0.f;
1971 ypeak[y] = 0.f;
1972 } 1968 }
1973 1969
1974 float s0 = 0, s1 = 0; 1970 float s0 = 0, s1 = 0;
1975 1971
1976 if (!getXBinRange(v, x0 + x, s0, s1)) { 1972 if (!getXBinRange(v, x0 + x, s0, s1)) {
2059 float yprop = sprop; 2055 float yprop = sprop;
2060 if (y == y0i) yprop *= (y + 1) - y0; 2056 if (y == y0i) yprop *= (y + 1) - y0;
2061 if (y == y1i) yprop *= y1 - y; 2057 if (y == y1i) yprop *= y1 - y;
2062 ymag[y] += yprop * value; 2058 ymag[y] += yprop * value;
2063 ydiv[y] += yprop; 2059 ydiv[y] += yprop;
2064 if (value > ypeak[y]) ypeak[y] = value;
2065 } 2060 }
2066 } 2061 }
2067 2062
2068 if (mag.isSet()) { 2063 if (mag.isSet()) {
2069 2064
2083 2078
2084 unsigned char pixel = 0; 2079 unsigned char pixel = 0;
2085 2080
2086 float avg = ymag[y] / ydiv[y]; 2081 float avg = ymag[y] / ydiv[y];
2087 pixel = getDisplayValue(v, avg); 2082 pixel = getDisplayValue(v, avg);
2088 //!!! pixel = getDisplayValue(v, ypeak[y]);
2089 2083
2090 assert(x <= m_drawBuffer.width()); 2084 assert(x <= m_drawBuffer.width());
2091 QColor c = m_colourMap.getColour(pixel); 2085 QColor c = m_colourMap.getColour(pixel);
2092 m_drawBuffer.setPixel(x, y, 2086 m_drawBuffer.setPixel(x, y,
2093 qRgb(c.red(), c.green(), c.blue())); 2087 qRgb(c.red(), c.green(), c.blue()));