Fix floating point exception in Spectrum Analyzer (#7018)

Fix a floating point exception in the Spectrum Analyzer which occurs if the amplitude is 0. The amplitude is used in the calculation of a logarithm which is not defined for values smaller or equal to 0.

The fix is to replace a value of 0 with the minimum positive float value. Negative values are not handled because it seems that only values greater or equal to 0 are fed into the method. This assumption is asserted in case this ever changes.
This commit is contained in:
Michael Gregorius
2023-12-10 11:42:02 +01:00
committed by GitHub
parent 67ce167775
commit 8136b7002c

View File

@@ -41,6 +41,9 @@
#include "LocklessRingBuffer.h"
#include "SaControls.h"
#include <cassert>
#include <limits>
namespace lmms
{
@@ -650,7 +653,8 @@ float SaProcessor::ampToYPixel(float amplitude, unsigned int height) const
if (m_controls->m_logYModel.value())
{
// logarithmic scale: convert linear amplitude to dB (relative to 1.0)
float amplitude_dB = 10 * log10(amplitude);
assert (amplitude >= 0);
float amplitude_dB = 10 * std::log10(std::max(amplitude, std::numeric_limits<float>::min()));
if (amplitude_dB < getAmpRangeMin())
{
return height;