From 4a500c77dda5592468f931db0c791236679157b4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 14 Jul 2017 10:50:28 -0400 Subject: [PATCH] Bug1636: fix Crash on OK selecting RIAA or Telephone Eq curve... ... Really two crashes, one in case Linear frequency scale is selected, the other if Logarithmic. Problem was introduced at commit 7d5e54e364fcccd630274f2658703543d8c596eb --- src/effects/Equalization.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 58de3986c..933bb9a45 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1680,12 +1680,20 @@ void EffectEqualization::setCurve(int currentCurve) break; } else { + // There are more points at higher freqs, + // so interpolate next one then stop. when = 1.0; - double lastF = mCurves[currentCurve].points[pointCount-1].Freq; - double nextF = mCurves[currentCurve].points[pointCount].Freq; - double lastDB = mCurves[currentCurve].points[pointCount-1].dB; double nextDB = mCurves[currentCurve].points[pointCount].dB; - value = lastDB + ((nextDB - lastDB) * ((mHiFreq - lastF) / (nextF - lastF))); + if (pointCount > 0) { + double nextF = mCurves[currentCurve].points[pointCount].Freq; + double lastF = mCurves[currentCurve].points[pointCount-1].Freq; + double lastDB = mCurves[currentCurve].points[pointCount-1].dB; + value = lastDB + + ((nextDB - lastDB) * + ((mHiFreq - lastF) / (nextF - lastF))); + } + else + value = nextDB; env->InsertOrReplace(when, value); break; } @@ -1751,9 +1759,14 @@ void EffectEqualization::setCurve(int currentCurve) // interpolate the final point instead when = 1.0; - double logLastF = log10(mCurves[currentCurve].points[pointCount-1].Freq); - double lastDB = mCurves[currentCurve].points[pointCount-1].dB; - value = lastDB + ((value - lastDB) * ((log10(mHiFreq) - logLastF) / (flog - logLastF))); + if (pointCount > 0) { + double lastDB = mCurves[currentCurve].points[pointCount-1].dB; + double logLastF = + log10(mCurves[currentCurve].points[pointCount-1].Freq); + value = lastDB + + ((value - lastDB) * + ((log10(mHiFreq) - logLastF) / (flog - logLastF))); + } env->InsertOrReplace(when, value); break; }