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; }