Skip to content

Commit

Permalink
Fix connection signal debugging display
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 10, 2025
1 parent 25c8850 commit c3c8385
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Source/Components/ConnectionMessageDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class ConnectionMessageDisplay final
continue;
}

while (approximatelyEqual(peakAmplitude, valleyAmplitude)) {
while (peakAmplitude < valleyAmplitude || approximatelyEqual(peakAmplitude, valleyAmplitude)) {
peakAmplitude += peakAmplitude * 0.001f;
valleyAmplitude -= valleyAmplitude * 0.001f;
}
Expand All @@ -304,6 +304,7 @@ class ConnectionMessageDisplay final
peakFreqIndex = i;
}
}
peakFreqIndex = std::max(peakFreqIndex, 1);

auto samplesPerCycle = std::clamp<int>(round(static_cast<float>(signalBlockSize * 2) / peakFreqIndex), 8, signalBlockSize);
// Keep a short average of cycle length over time to prevent sudden changes
Expand All @@ -319,9 +320,9 @@ class ConnectionMessageDisplay final
auto roundedIndex = static_cast<int>(index);
auto currentSample = lastSamples[ch][roundedIndex];
auto nextSample = roundedIndex == 1023 ? lastSamples[ch][roundedIndex] : lastSamples[ch][roundedIndex + 1];
auto interpolatedSample = jmap<float>(index - roundedIndex, currentSample, nextSample) * -1.0f;
auto interpolatedSample = jmap<float>(index - roundedIndex, currentSample, nextSample);

auto y = jmap<float>(interpolatedSample, valleyAmplitude, peakAmplitude, channelBounds.getY(), channelBounds.getBottom());
auto y = jmap<float>(interpolatedSample, valleyAmplitude, peakAmplitude, channelBounds.getBottom(), channelBounds.getY());
auto newPoint = Point<float>(x, y);
if (newPoint.isFinite()) {
auto segment = Line(lastPoint, newPoint);
Expand Down

0 comments on commit c3c8385

Please sign in to comment.