Skip to content

Commit

Permalink
fix: replace infinite points of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Oct 17, 2024
1 parent 40dbd36 commit 7cd9cf4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions source/dsp/fft_analyzer/multiple_fft_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ namespace zlFFT {
path.get().startNewSubPath(bound.getX(), bound.getBottom() + 10.f);
for (size_t idx = 0; idx < PointNum - cubicNum; ++idx) {
const auto x = static_cast<float>(idx) / static_cast<float>(PointNum - 1) * width;
const auto y = interplotDBs[i][idx].load() / minDB * height + boundY;
const auto y = replaceWithFinite(interplotDBs[i][idx].load() / minDB * height + boundY);
path.get().lineTo(x, y);
}
for (size_t idx = PointNum - cubicNum; idx < PointNum - 2; idx += 3) {
const auto x1 = static_cast<float>(idx) / static_cast<float>(PointNum - 1) * width;
const auto y1 = interplotDBs[i][idx].load() / minDB * height + boundY;\
const auto y1 = replaceWithFinite(interplotDBs[i][idx].load() / minDB * height + boundY);
const auto x2 = static_cast<float>(idx + 1) / static_cast<float>(PointNum - 1) * width;
const auto y2 = interplotDBs[i][idx + 1].load() / minDB * height + boundY;
const auto y2 = replaceWithFinite(interplotDBs[i][idx + 1].load() / minDB * height + boundY);
const auto x3 = static_cast<float>(idx + 2) / static_cast<float>(PointNum - 1) * width;
const auto y3 = interplotDBs[i][idx + 2].load() / minDB * height + boundY;
const auto y3 = replaceWithFinite(interplotDBs[i][idx + 2].load() / minDB * height + boundY);
path.get().cubicTo(x1, y1, x2, y2, x3, y3);
}
}
Expand Down Expand Up @@ -319,6 +319,10 @@ namespace zlFFT {
const auto db = juce::Decibels::gainToDecibels(bin, -240.f);
return bounds.getY() + (db / minDB) * bounds.getHeight();
}

static inline float replaceWithFinite(const float x) {
return std::isfinite(x) ? x : 100000.f;
}
};
}

Expand Down
6 changes: 2 additions & 4 deletions source/dsp/interpolation/seq_makima.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ namespace zlInterpolation {
endIdx -= 1;
}
for (size_t i = startIdx; i <= endIdx; ++i) {
if (currentPos + 2 < inputSize) {
while (currentPos + 2 < inputSize && x[i] >= xs[currentPos + 1]) {
currentPos += 1;
}
while (currentPos + 2 < inputSize && x[i] >= xs[currentPos + 1]) {
currentPos += 1;
}
const auto t = (x[i] - xs[currentPos]) / (xs[currentPos + 1] - xs[currentPos]);
y[i] = h00(t) * ys[currentPos] +
Expand Down
6 changes: 5 additions & 1 deletion source/panel/curve_panel/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ namespace zlPanel {
std::atomic<float> x{0.f}, y{0.f}, width{0.f}, height{0.f};
};

static inline float replaceWithFinite(const float x) {
return std::isfinite(x) ? x : 100000.f;
}

inline static float indexToX(const size_t i, const juce::Rectangle<float> bound) {
return static_cast<float>(i) /
static_cast<float>(zlFilter::frequencies.size() - 1) * bound.getWidth() + bound.getX();
Expand All @@ -257,7 +261,7 @@ namespace zlPanel {
}

inline static float dbToY(const float db, const float maxDB, const juce::Rectangle<float> bound) {
return -db / maxDB * bound.getHeight() * 0.5f + bound.getCentreY();
return replaceWithFinite(-db / maxDB * bound.getHeight() * 0.5f + bound.getCentreY());
}

inline static void drawCurve(juce::Path &path,
Expand Down

0 comments on commit 7cd9cf4

Please sign in to comment.