mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-09 23:35:33 -04:00
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:
committed by
GitHub
parent
67ce167775
commit
8136b7002c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user