-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
235 lines (210 loc) · 7.01 KB
/
mainwindow.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/** ===========================================================
* @file
*
* This file is a part of pcro project
* <a href="https://github.com/maheshmhegade/pcro">https://github.com/maheshmhegade/pcro</a>
*
* @date 2010-03-03
* @brief pcro using pc as signal generator.
* @section DESCRIPTION
*
* Using ALSA to output digital data as analogue sound which is standard a mathematical function.
*
* @author Copyright (C) 2012-2013 by Mahesh Hegde
* <a href="mailto:maheshmhegade at gmail dot com">maheshmhegade at gmail dot com</a>
*
* @section LICENSE
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
liveVideoObject = new liveVideo();
facemodeltostore = 0;
allwaveObject = new alsaSoundcard();
ui->setupUi(this);
ui->FaceGV->hide();
wave = new outputWave();
//enable this option to start voice recognition on starting the application
//QtConcurrent::run(this,&MainWindow::recognizeVoice);
connect(this,SIGNAL(allValuesSet(VoiceRecognition *)),this,SLOT(setWaveValues(VoiceRecognition *)));
connect(this,SIGNAL(plotAndPlayNow()),this,SLOT(plotAndPlay()));
}
MainWindow::~MainWindow()
{
delete wave;
delete allwaveObject;
delete ui;
}
void MainWindow::on_applypushButton_clicked()
{
generateWave();
//run plotting and playing tasks in seperate threads to display waveform quickly
//TODO:find a way to stop playing sound,whenever needed.
QtConcurrent::run(this,&MainWindow::play_sound);
QtConcurrent::run(this,&MainWindow::plotWave);
}
void MainWindow::plotWave()
{
QVector<double> x(5000), y(5000);
ui->widget->addGraph();
// create graph and assign data to it:
// give the axes some labels:
ui->widget->xAxis->setLabel("x");
ui->widget->yAxis->setLabel("y");
// set axes ranges, so we see all data:
ui->widget->xAxis->setRange(0, 5000);
ui->widget->yAxis->setRange(-35000,35000);
for (int i=0; i<5000; ++i)
{
x[i] = (double)i; // x goes from -1 to 1
y[i] = wave->waveSamples[i];//*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
ui->widget->addGraph();
ui->widget->graph(0)->setData(x,y);
ui->widget->replot();
}
void MainWindow::play_sound()
{
allwaveObject = new alsaSoundcard(); //= alsaSoundcard();
allwaveObject->playBack(wave);
}
void MainWindow::setWaveValues(VoiceRecognition *voiceRecognizer)
{
/*
ui->wavecomboBox->setCurrentIndex(voiceRecognizer->waveType);
ui->voltagelineEdit->setText(QString(QString::number(voiceRecognizer->waveVoltage)));
ui->frequencylineEdit->setText(QString(QString::number(voiceRecognizer->waveFrequency)));
ui->durationlineEdit->setText(QString(QString::number(voiceRecognizer->waveDuration)));
*/
//transfer handle to plotAndPlay()
emit plotAndPlayNow();
}
void MainWindow::generateWave()
{
wave->samplingFrequency = 44100;
wave->waveDuration = ui->durationlineEdit->text().toInt();
wave->waveFrequency = ui->frequencylineEdit->text().toInt();
wave->waveAmplitude = ui->voltagelineEdit->text().toFloat();
switch (ui->wavecomboBox->currentIndex())
{
case 0:
{
allwaveObject->generateSin(wave);
break;
}
case 1:
{
allwaveObject->generateCos(wave);
break;
}
case 2:
{
allwaveObject->generateTriangular(wave);
break;
}
case 3:
{
allwaveObject->generateSquare(wave);
break;
}
case 4:
{
allwaveObject->generateRamp(wave);
break;
}
}
QVector<double> x(5000), y(5000);
ui->widget->addGraph();
// create graph and assign data to it:
// give the axes some labels:
ui->widget->xAxis->setLabel("x");
ui->widget->yAxis->setLabel("y");
// set axes ranges, so we see all data:
ui->widget->xAxis->setRange(0, 5000);
ui->widget->yAxis->setRange(-35000,35000);
for (int i=0; i<5000; ++i)
{
x[i] = (double)i; // x goes from -1 to 1
y[i] = wave->waveSamples[i];//*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
ui->widget->addGraph();
ui->widget->graph(0)->setData(x,y);
ui->widget->replot();
cout << "one" << endl;
return;
}
void MainWindow::plotAndPlay()
{
generateWave();
//execute plotting and playing sound in seperate threads
QtConcurrent::run(this,&MainWindow::play_sound);
QtConcurrent::run(this,&MainWindow::plotWave);
}
void MainWindow::recognizeVoice(QString personNmae)
{
VoiceRecognition *recognizer = new VoiceRecognition();
//select acoustic model belonging to perticular person by supplying person name in QString form
recognizer->SelectAcousticModel(personNmae);
recognizer->startVoiceRecognition(ui);
//tranfser handle to setWaveValues()
emit allValuesSet(recognizer);
}
void MainWindow::on_SaveFacePB_clicked()
{
Tlddatabase *tlddatabase = new Tlddatabase;
facemodeltostore = faceData.first;
facemodeltostore->Name = ui->FaceNameLE->text();
cout << qPrintable(facemodeltostore->Name) << endl;
tlddatabase->insertFaceModel(facemodeltostore);
ui->FaceNameLE->clear();
ui->FaceGV->hide();
delete tlddatabase;
}
void MainWindow::on_DetectFacePB_clicked()
{
Tldrecognition* const tmpTLD = new Tldrecognition;
faceData = tmpTLD->getModeltoStore();
//facemodeltostore = faceData.first;
ui->FaceGV->show();
liveVideoObject->displayVideo(faceData.second,ui->FaceGV);
delete tmpTLD;
}
void MainWindow::on_RecognizeFacePB_clicked()
{
liveVideoObject->togglePlayStatus();
if(liveVideoObject->playStatus == true)
{
Tlddatabase *tlddatabase = new Tlddatabase();
QList<unitFaceModel*> comparemodels;
for (int i = 1; i <= tlddatabase->queryNumfacesinDatabase();i++ )
{
comparemodels.push_back(tlddatabase->getFaceModel(i));
}
delete tlddatabase;
Tldrecognition* const tmpTLD = new Tldrecognition;
std::pair<IplImage*,QString> faceName = tmpTLD->getRecognitionConfidence(comparemodels);
ui->FaceGV->show();
ui->FaceNameLE->clear();
ui->FaceNameLE->setText(faceName.second);
liveVideoObject->displayVideo(faceName.first,ui->FaceGV);
qDebug() << "person "<< faceName.second << " recognized in front of the system";
delete tmpTLD;
}
QtConcurrent::run(this,&MainWindow::recognizeVoice,(QString)"mylm");
}