1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
From f93a8aa68bcef9f649ab62b825e00c1eebe787c5 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Sat, 14 Nov 2020 04:35:26 +0100
Subject: [PATCH 03/31] fix(spectrogramplot): Avoid infinite loop at extremely
high sample rates
---
spectrogramplot.cpp | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/spectrogramplot.cpp b/spectrogramplot.cpp
index 975c69b..4567a09 100644
--- a/spectrogramplot.cpp
+++ b/spectrogramplot.cpp
@@ -70,6 +70,14 @@ void SpectrogramPlot::paintFront(QPainter &painter, QRect &rect, range_t<size_t>
void SpectrogramPlot::paintFrequencyScale(QPainter &painter, QRect &rect)
{
+ if (sampleRate == 0) {
+ return;
+ }
+
+ if (sampleRate / 2 > UINT64_MAX) {
+ return;
+ }
+
// At which pixel is F_+sampleRate/2
int y = rect.y();
@@ -80,7 +88,7 @@ void SpectrogramPlot::paintFrequencyScale(QPainter &painter, QRect &rect)
double bwPerPixel = (double)sampleRate / plotHeight;
int tickHeight = 50;
- int bwPerTick = 10 * pow(10, floor(log(bwPerPixel * tickHeight) / log(10)));
+ uint64_t bwPerTick = 10 * pow(10, floor(log(bwPerPixel * tickHeight) / log(10)));
if (bwPerTick < 1) {
return;
@@ -93,7 +101,7 @@ void SpectrogramPlot::paintFrequencyScale(QPainter &painter, QRect &rect)
QFontMetrics fm(painter.font());
- int tick = 0;
+ uint64_t tick = 0;
while (tick <= sampleRate / 2) {
@@ -107,12 +115,14 @@ void SpectrogramPlot::paintFrequencyScale(QPainter &painter, QRect &rect)
if (tick != 0) {
char buf[128];
- if (bwPerTick % 1000000 == 0) {
- snprintf(buf, sizeof(buf), "-%d MHz", (int)tick / 1000000);
+ if (bwPerTick % 1000000000 == 0) {
+ snprintf(buf, sizeof(buf), "-%lu GHz", tick / 1000000000);
+ } else if (bwPerTick % 1000000 == 0) {
+ snprintf(buf, sizeof(buf), "-%lu MHz", tick / 1000000);
} else if(bwPerTick % 1000 == 0) {
- snprintf(buf, sizeof(buf), "-%d kHz", tick / 1000);
+ snprintf(buf, sizeof(buf), "-%lu kHz", tick / 1000);
} else {
- snprintf(buf, sizeof(buf), "-%d Hz", tick);
+ snprintf(buf, sizeof(buf), "-%lu Hz", tick);
}
if (!inputSource->realSignal())
--
2.35.1
|