Improve spectrum analyzer performance by caching most used computations (#6003)

This commit is contained in:
Martin Pavelek
2022-01-06 04:09:46 +01:00
committed by GitHub
parent 13e17496dc
commit 13e55101f0
3 changed files with 50 additions and 13 deletions

View File

@@ -225,12 +225,9 @@ void SaProcessor::analyze(LocklessRingBuffer<sampleFrame> &ring_buffer)
if (band_end - band_start > 1.0)
{
// band spans multiple pixels: draw all pixels it covers
for (target = (int)band_start; target < (int)band_end; target++)
for (target = std::max((int)band_start, 0); target < band_end && target < waterfallWidth(); target++)
{
if (target >= 0 && target < waterfallWidth())
{
pixel[target] = makePixel(m_normSpectrumL[i], m_normSpectrumR[i]);
}
pixel[target] = makePixel(m_normSpectrumL[i], m_normSpectrumR[i]);
}
// save remaining portion of the band for the following band / pixel
// (in case the next band uses sub-pixel drawing)
@@ -265,12 +262,9 @@ void SaProcessor::analyze(LocklessRingBuffer<sampleFrame> &ring_buffer)
else
{
// Linear: always draws one or more pixels per band
for (target = (int)band_start; target < band_end; target++)
for (target = std::max((int)band_start, 0); target < band_end && target < waterfallWidth(); target++)
{
if (target >= 0 && target < waterfallWidth())
{
pixel[target] = makePixel(m_normSpectrumL[i], m_normSpectrumR[i]);
}
pixel[target] = makePixel(m_normSpectrumL[i], m_normSpectrumR[i]);
}
}
}
@@ -573,6 +567,9 @@ float SaProcessor::getFreqRangeMax() const
// Map frequency to pixel x position on a display of given width.
// NOTE: Results of this function may be cached by SaSpectrumView. If you use
// a new function call or variable that can affect results of this function,
// make sure to also add it as a trigger for cache update in SaSpectrumView.
float SaProcessor::freqToXPixel(float freq, unsigned int width) const
{
if (m_controls->m_logXModel.value())