-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspectrumwindow.cpp
198 lines (168 loc) · 4.57 KB
/
spectrumwindow.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
Spectrum display window
Copyright 2006-2016
Niels A. Moseley
Pieter-Tjerk de Boer
License: GPLv2
*/
#include "spectrumwindow.h"
#include "ui_spectrumwindow.h"
SpectrumWindow::SpectrumWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::SpectrumWindow)
{
setWindowFlags(Qt::Tool);
ui->setupUi(this);
// setup spectrum display
m_spectrum = new SpectrumWidget(this);
ui->mainLayout->addWidget(m_spectrum);
// setup channel boxes
m_hsizer = new QHBoxLayout();
ui->mainLayout->addLayout(m_hsizer);
m_chan1 = new QLineEdit(this);
m_chan2 = new QLineEdit(this);
QLabel *m_chan1Label = new QLabel(this);
QLabel *m_chan2Label = new QLabel(this);
m_chan1Label->setText(" CH1 ");
m_chan2Label->setText(" CH2 ");
m_chan1Label->setStyleSheet("background-color: green");
m_chan2Label->setStyleSheet("background-color: yellow");
m_hsizer->addWidget(m_chan1Label);
m_hsizer->addWidget(m_chan1);
m_hsizer->addWidget(m_chan2Label);
m_hsizer->addWidget(m_chan2);
connect(m_chan1, SIGNAL(textChanged(QString)), this, SLOT(chan1Changed()));
connect(m_chan2, SIGNAL(textChanged(QString)), this, SLOT(chan2Changed()));
//populate window options
ui->windowTypeBox->addItem("None", 0);
ui->windowTypeBox->addItem("Hann", 1);
ui->windowTypeBox->addItem("Hamming", 2);
ui->windowTypeBox->addItem("Blackman", 3);
ui->windowTypeBox->addItem("Flattop", 4);
fft::windowType wt = m_spectrum->getWindow();
uint32_t idx = 0;
switch(wt)
{
case fft::WIN_NONE:
idx = 0;
break;
case fft::WIN_HANN:
idx = 1;
break;
case fft::WIN_HAMMING:
idx = 2;
break;
case fft::WIN_BLACKMAN:
idx = 3;
break;
case fft::WIN_FLATTOP:
idx = 4;
break;
default:
break;
}
ui->windowTypeBox->setCurrentIndex(idx);
// populate smoothing options
ui->smoothingBox->addItem("None",0);
ui->smoothingBox->addItem("10 frames",1);
ui->smoothingBox->addItem("20 frames",2);
ui->smoothingBox->addItem("50 frames",3);
ui->smoothingBox->addItem("100 frames",4);
ui->smoothingBox->setCurrentIndex(0);
ui->modeBox->addItem("2 channel",0);
ui->modeBox->addItem("IQ mode",1);
// populate vertical axis range box
ui->verticalRangeBox->addItem("60 dB",0);
ui->verticalRangeBox->addItem("80 dB",1);
ui->verticalRangeBox->addItem("100 dB",2);
ui->verticalRangeBox->addItem("120 dB",3);
}
SpectrumWindow::~SpectrumWindow()
{
delete ui;
}
void SpectrumWindow::setSampleRate(float rate)
{
m_spectrum->setSampleRate(rate);
}
void SpectrumWindow::submit256Samples(const VirtualMachine::ring_buffer_data_t *samples)
{
m_spectrum->submit256Samples(samples);
}
std::string SpectrumWindow::getChannelName(uint32_t channel)
{
if (channel == 0)
return m_chan1->text().toStdString();
if (channel == 1)
return m_chan2->text().toStdString();
return std::string("");
}
void SpectrumWindow::chan1Changed()
{
emit channelChanged(0);
}
void SpectrumWindow::chan2Changed()
{
emit channelChanged(1);
}
void SpectrumWindow::on_windowTypeBox_activated(int index)
{
QVariant data = ui->windowTypeBox->itemData(index);
if (!data.isNull())
{
switch(data.toInt())
{
case 0:
m_spectrum->setWindow(fft::WIN_NONE);
break;
case 1:
m_spectrum->setWindow(fft::WIN_HANN);
break;
case 2:
m_spectrum->setWindow(fft::WIN_HAMMING);
break;
case 3:
m_spectrum->setWindow(fft::WIN_BLACKMAN);
break;
case 4:
m_spectrum->setWindow(fft::WIN_FLATTOP);
break;
}
}
}
void SpectrumWindow::on_smoothingBox_activated(int index)
{
m_spectrum->setSmoothingLevel(index);
}
void SpectrumWindow::on_modeBox_activated(int index)
{
switch(index)
{
default:
case 0: // regular 2-channel spectrum mode
m_spectrum->setMode(fft::MODE_NORMAL);
break;
case 1: // IQ mode
m_spectrum->setMode(fft::MODE_IQ);
break;
}
}
void SpectrumWindow::on_verticalRangeBox_activated(int index)
{
switch(index)
{
default:
case 0: // 60 dB
m_spectrum->setVerticalRange(60.0f);
break;
case 1: // 80 dB
m_spectrum->setVerticalRange(80.0f);
break;
case 2: // 100 dB
m_spectrum->setVerticalRange(100.0f);
break;
case 3: // 120 dB
m_spectrum->setVerticalRange(120.0f);
break;
}
}