comparison layer/SpectrogramLayer.cpp @ 134:13949a6970ab

* Use peaks instead of means for calculating display values in pixels that cover more than one bin
author Chris Cannam
date Wed, 16 Aug 2006 14:57:47 +0000
parents 9e6b3e239b9d
children e98130764635
comparison
equal deleted inserted replaced
133:9e6b3e239b9d 134:13949a6970ab
1951 if (fftSize != m_fftSize) { 1951 if (fftSize != m_fftSize) {
1952 displayMinFreq = getEffectiveMinFrequency(); 1952 displayMinFreq = getEffectiveMinFrequency();
1953 displayMaxFreq = getEffectiveMaxFrequency(); 1953 displayMaxFreq = getEffectiveMaxFrequency();
1954 } 1954 }
1955 1955
1956 //!!! we will probably only want one of "ymag+ydiv" and "ypeak",
1957 //but we leave them both calculated here for test purposes
1956 float ymag[h]; 1958 float ymag[h];
1957 float ydiv[h]; 1959 float ydiv[h];
1960 float ypeak[h];
1958 float yval[bins + 1]; //!!! cache this? 1961 float yval[bins + 1]; //!!! cache this?
1959 1962
1960 size_t increment = getWindowIncrement(); 1963 size_t increment = getWindowIncrement();
1961 1964
1962 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 1965 bool logarithmic = (m_frequencyScale == LogFrequencyScale);
1974 fft->suspendWrites(); 1977 fft->suspendWrites();
1975 1978
1976 for (int x = 0; x < w; ++x) { 1979 for (int x = 0; x < w; ++x) {
1977 1980
1978 for (int y = 0; y < h; ++y) { 1981 for (int y = 0; y < h; ++y) {
1979 ymag[y] = 0.0; 1982 ymag[y] = 0.f;
1980 ydiv[y] = 0.0; 1983 ydiv[y] = 0.f;
1984 ypeak[y] = 0.f;
1981 } 1985 }
1982 1986
1983 float s0 = 0, s1 = 0; 1987 float s0 = 0, s1 = 0;
1984 1988
1985 if (!getXBinRange(v, x0 + x, s0, s1)) { 1989 if (!getXBinRange(v, x0 + x, s0, s1)) {
2062 float yprop = sprop; 2066 float yprop = sprop;
2063 if (y == y0i) yprop *= (y + 1) - y0; 2067 if (y == y0i) yprop *= (y + 1) - y0;
2064 if (y == y1i) yprop *= y1 - y; 2068 if (y == y1i) yprop *= y1 - y;
2065 ymag[y] += yprop * value; 2069 ymag[y] += yprop * value;
2066 ydiv[y] += yprop; 2070 ydiv[y] += yprop;
2071 if (value > ypeak[y]) ypeak[y] = value;
2067 } 2072 }
2068 } 2073 }
2069 2074
2070 if (mag.isSet()) { 2075 if (mag.isSet()) {
2071 2076
2084 if (ydiv[y] > 0.0) { 2089 if (ydiv[y] > 0.0) {
2085 2090
2086 unsigned char pixel = 0; 2091 unsigned char pixel = 0;
2087 2092
2088 float avg = ymag[y] / ydiv[y]; 2093 float avg = ymag[y] / ydiv[y];
2089 pixel = getDisplayValue(v, avg); 2094 //!!! pixel = getDisplayValue(v, avg);
2095 pixel = getDisplayValue(v, ypeak[y]);
2090 2096
2091 assert(x <= m_drawBuffer.width()); 2097 assert(x <= m_drawBuffer.width());
2092 QColor c = m_colourMap.getColour(pixel); 2098 QColor c = m_colourMap.getColour(pixel);
2093 m_drawBuffer.setPixel(x, y, 2099 m_drawBuffer.setPixel(x, y,
2094 qRgb(c.red(), c.green(), c.blue())); 2100 qRgb(c.red(), c.green(), c.blue()));