-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsweepparameters.h
138 lines (116 loc) · 2.74 KB
/
sweepparameters.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef SWEEPPARAMETERS_H
#define SWEEPPARAMETERS_H
#include <QDebug>
#include <cmath>
struct SweepParameters
{
friend class ScopeWidget;
friend class Plotter;
double triggerTolerance{0.01};
double triggerLevel{0.0};
double slope{1.0};
bool sweepUnused{false};
bool triggerEnabled{true};
int horizontalDivisions;
int verticalDivisions;
public:
double getDuration_ms() const
{
return duration_ms;
}
double getDuration() const
{
return duration_ms / 1000.0;
}
void setDuration(double newDuration_s)
{
duration_ms = 1000.0 * newDuration_s;
calcSweepAdvance();
}
void setDuration_ms(double newDuration_ms)
{
duration_ms = newDuration_ms;
calcSweepAdvance();
}
double getSamplesPerSweep() const
{
return duration_ms * inputFrames_per_ms;
}
double getUpsampleFactor() const;
static QString formatMeasurementUnits(double duration_s, const QString& units, int precision = 2)
{
// constexpr int m = 999;
static QMap<int, QString> prefixMap
{
{-30, "q"},
{-27, "r"},
{-24, "y"},
{-21, "z"},
{-18, "a"},
{-15, "f"},
{-12, "p"},
{-9, "n"},
{-6, "μ"},
{-3, "m"},
{0, ""},
{3, "k"},
{6, "M"},
{9, "G"},
{12, "T"},
{15, "P"},
{18, "E"},
{21, "Z"},
{24, "Y"},
{27, "R"},
{30, "Q"},
};
double m = 0.0;
int p = 0;
if(std::fpclassify(duration_s) != FP_ZERO) {
p = 3 * std::floor(std::log10(std::abs(duration_s)) / 3.0);
m = static_cast<double>(duration_s / std::pow(10, p));
}
return QStringLiteral("%1 %2%3")
.arg(m, 0, 'f', precision)
.arg(prefixMap.value(p), units);
}
void setUpsampleFactor(double newUpsampleFactor);
double getInputFrames_per_ms() const;
void setInputFrames_per_ms(double newInputFrames_per_ms);
private:
double duration_ms{10.0};
int width_pixels{640};
double inputFrames_per_ms{44.1};
double upsampleFactor{1.0};
qreal sweepAdvance; // pixels per input frame
double triggerMin{triggerLevel - triggerTolerance};
double triggerMax{triggerLevel + triggerTolerance};
void setWidthFrameRate(int width_pixels, double inputFrames_per_ms)
{
this->width_pixels = width_pixels;
this->inputFrames_per_ms = inputFrames_per_ms;
calcSweepAdvance();
}
void calcSweepAdvance()
{
sweepAdvance = width_pixels / inputFrames_per_ms / duration_ms / upsampleFactor;
}
};
inline double SweepParameters::getUpsampleFactor() const
{
return upsampleFactor;
}
inline void SweepParameters::setUpsampleFactor(double newUpsampleFactor)
{
upsampleFactor = newUpsampleFactor;
calcSweepAdvance();
}
inline double SweepParameters::getInputFrames_per_ms() const
{
return inputFrames_per_ms;
}
inline void SweepParameters::setInputFrames_per_ms(double newInputFrames_per_ms)
{
inputFrames_per_ms = newInputFrames_per_ms;
}
#endif // SWEEPPARAMETERS_H