-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformraw.cpp
More file actions
173 lines (152 loc) · 5.88 KB
/
formraw.cpp
File metadata and controls
173 lines (152 loc) · 5.88 KB
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
#include <QDebug>
#include "formraw.h"
#include "ui_formraw.h"
#include "devices/tonegenerator.h"
#include "devices/audioinputdevice.h"
#include "widgets/oscilloscopeengine.h"
#include "common_types.h"
#include "devices/audioinputdevice.h"
extern bool g_verboseOutput;
FormRaw::FormRaw(ToneGenerator *gen, AudioInputThread *capture, QWidget *parent) :
QWidget(parent),
ui(new Ui::FormRaw)
{
ui->setupUi(this);
// Tone generation
m_gen = gen;
connect(m_gen, SIGNAL(deviceReady(bool)), this, SLOT(switchOutputFrequency()));
connect(m_gen, SIGNAL(deviceReady(bool)), this, SLOT(switchOutputWaveForm()));
ui->boxWaveForm->addItem(QIcon(":/icons/oscillator_sine.png"), "Sine", QVariant(ToneWaveForm::WAVE_SINE));
ui->boxWaveForm->addItem(QIcon(":/icons/oscillator_square.png"), "Square", QVariant(ToneWaveForm::WAVE_SQUARE));
ui->boxWaveForm->addItem(QIcon(":/icons/oscillator_saw.png"), "Sawtooth", QVariant(ToneWaveForm::WAVE_SAWTOOTH));
ui->boxWaveForm->addItem(QIcon(":/icons/oscillator_triangle.png"), "Triangle", QVariant(ToneWaveForm::WAVE_TRIANGLE));
// Audio capture
m_capture = capture;
connect(m_capture, SIGNAL(initiated(int)),
SLOT(captureDeviceInitiated(int)), Qt::QueuedConnection); // wait while main window initiated
// Oscilloscope
ui->oscilloscope->showTimeMeasureGuides(true);
ui->oscilloscope->showVoltageMeasureGuides(false, true);
ui->oscilloscope->showSampleValueUnderMouse(true);
m_oscEngine = new OscilloscopeEngine(ui->oscilloscope);
connect(m_capture, SIGNAL(dataForOscilloscope(SamplesList, SamplesList)),
m_oscEngine, SLOT(processOscilloscopeData(SamplesList, SamplesList)));
changeTriggerSettings();
connect(ui->boxTriggerAuto, SIGNAL(clicked()), this, SLOT(changeTriggerSettings()));
connect(ui->boxTriggerNormal, SIGNAL(clicked()), this, SLOT(changeTriggerSettings()));
connect(ui->boxTriggerSingle, SIGNAL(clicked()), this, SLOT(changeTriggerSettings()));
connect(ui->boxSlopeRising, SIGNAL(clicked()), this, SLOT(changeTriggerSettings()));
connect(ui->boxSlopeFalling, SIGNAL(clicked()), this, SLOT(changeTriggerSettings()));
connect(ui->boxTriggerChannel, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTriggerSettings()));
connect(ui->buttonGenerate, SIGNAL(toggled(bool)), this, SLOT(startToneGenerator(bool)));
connect(ui->boxFrequency, SIGNAL(valueChanged(int)), this, SLOT(switchOutputFrequency()));
connect(ui->boxWaveForm, SIGNAL(currentIndexChanged(int)), this, SLOT(switchOutputWaveForm()));
connect(ui->buttonCapture, SIGNAL(toggled(bool)), this, SLOT(startAudioCapture(bool)));
connect(ui->boxChannelLeft, SIGNAL(toggled(bool)), this, SLOT(changeCapturedChannels()));
connect(ui->boxChannelRight, SIGNAL(toggled(bool)), this, SLOT(changeCapturedChannels()));
}
FormRaw::~FormRaw()
{
delete ui;
}
void FormRaw::enterForm()
{
QString inputName = m_capture->getDeviceName();
QString outputName = m_gen->getDeviceName();
ui->labelAudioInputDevice->setText(inputName);
ui->labelAudioOutputDevice->setText(outputName);
qreal max = m_gen->getMaxVoltageAmplitude();
m_oscEngine->setMaximumAmplitude(max);
}
void FormRaw::leaveForm()
{
qDebug() << "Leave form \"Raw\"";
startToneGenerator(false);
startAudioCapture(false);
ui->buttonGenerate->setChecked(false);
ui->buttonCapture->setChecked(false);
m_oscEngine->stop();
}
void FormRaw::startToneGenerator(bool start)
{
if (start) {
switchOutputWaveForm();
switchOutputFrequency();
m_gen->setActiveChannels(CHANNEL_BOTH);
m_gen->setCurVoltageAmplitude(m_gen->getMaxVoltageAmplitude());
}
m_gen->runGenerator(start);
}
void FormRaw::captureDeviceInitiated(int samplingRate)
{
if (!ui->buttonCapture->isChecked()) {
return;
}
// Audio device ready to capture - display this
Q_ASSERT(m_capture);
m_oscEngine->prepareToStart(samplingRate);
changeCapturedChannels(); // Start receive data from input device
}
void FormRaw::startAudioCapture(bool start)
{
m_capture->startCapturing(start);
if (start == false) {
m_oscEngine->stop();
}
}
void FormRaw::switchOutputWaveForm()
{
int index = ui->boxWaveForm->currentIndex();
QVariant waveType = ui->boxWaveForm->itemData(index);
ToneWaveForm form((ToneWaveForm::Id)waveType.toInt());
if (ui->buttonGenerate->isChecked()) {
m_gen->switchWaveForm(form);
}
}
void FormRaw::switchOutputFrequency()
{
int freq = ui->boxFrequency->value();
if (ui->buttonGenerate->isChecked()) {
m_gen->changeFrequency(freq);
}
}
void FormRaw::changeTriggerSettings()
{
OscTriggerMode mode = TRIG_AUTO;
if (ui->boxTriggerAuto->isChecked()) {
mode = TRIG_AUTO;
} else if (ui->boxTriggerNormal->isChecked()) {
mode = TRIG_NORMAL;
} else {
mode = TRIG_SINGLE;
}
m_oscEngine->setTriggerMode(mode);
OscTriggerSlope slope;
if (ui->boxSlopeRising->isChecked())
slope = TRIG_RISING;
else
slope = TRIG_FALLING;
m_oscEngine->setTriggerSlope(slope);
AudioChannels channel = CHANNEL_NONE;
if (ui->boxTriggerChannel->currentIndex() == 0) {
channel = CHANNEL_LEFT;
} else if (ui->boxTriggerChannel->currentIndex() == 1) {
channel = CHANNEL_RIGHT;
} else {
qWarning() << "Incorrect channel selected for tracking:" << ui->boxTriggerChannel->currentIndex();
Q_ASSERT(false);
}
m_oscEngine->setTriggerChannel(channel);
}
void FormRaw::changeCapturedChannels()
{
int channels = CHANNEL_NONE;
if (ui->boxChannelLeft->isChecked()) {
channels |= CHANNEL_LEFT;
}
if (ui->boxChannelRight->isChecked()) {
channels |= CHANNEL_RIGHT;
}
m_oscEngine->setDisplayedChannels((AudioChannels)channels);
m_capture->setCapturedChannels((AudioChannels)channels);
}