-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
138 lines (107 loc) · 3.99 KB
/
main.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
#ifdef _MSC_VER
#define NOMINMAX
#include <algorithm>
#endif
#include "config.h"
#include "DataPrep.h"
#include "SpecMath.h"
#include "ServiceFunc.h"
using namespace std;
/** Options *************************************************************************************/
bool option_CreateTrainDataFile = false;
bool option_Recognize = true;
bool option_SilentMode = false;
bool option_WriteLog = true;
bool option_ResultsToFile = true;
bool option_WriteSplittedSounds = false;
/** Settings*************************************************************************************/
std::string setting_TrainDataFileFolder ("training/");
std::string setting_InputDataFolder("input");
std::string setting_ResultsFileName("results.delmtd.csv");
std::string setting_LogFileName("log.txt");
ofstream res_file;
ofstream log_file;
int main(int argc, char** argv) {
bool isOk;
int decision;
std::vector<svMFCC> etalonframes;
/** (Optional) Creation of train data file ******************************************************/
if (option_CreateTrainDataFile)
{
std::string trainInputFolder(setting_TrainDataFileFolder);
std::string trainDataFile("trainData.dat");
isOk = makeTrainDataFile(trainInputFolder, trainDataFile);
if (!isOk) {cerr << "Something went wrong during creation of Train Data File" << endl; return EXIT_FAILURE;}
}
/** Reading of train data file ******************************************************************/
isOk = readTrainDataFile("trainData.dat", &etalonframes);
if (!isOk) {cerr << "Something went wrong during reading of Train Data File" << endl; return EXIT_FAILURE;}
/** Initialize output files *********************************************************************/
if (option_ResultsToFile)
{
res_file.open (setting_ResultsFileName);
}
if (option_WriteLog)
{
log_file.open (setting_LogFileName);
}
/** Reading of input data files in folder and recognize it **************************************/
DIR *inputDIR;
struct dirent *DIRent;
std::string inputFile ("");
int numberOfFilesTotal = 0, numberOfFilesPositive = 0, numberOfFilesNegative = 0;
setting_InputDataFolder = setting_InputDataFolder + SEPARATOR;
if (!option_SilentMode) {cout << "Reading and analysis of files in folder " << setting_InputDataFolder << " is started:" << endl;}
if ((inputDIR = opendir (setting_InputDataFolder.c_str())) != NULL)
{
while ((DIRent = readdir (inputDIR)) != NULL)
{
if (DIRent->d_name[0]!='.' && strcmp(DIRent->d_name, "splitted")!=0)
{
inputFile.assign(DIRent->d_name);
cout << inputFile << ": " << flush;
decision = makeDecision (inputFile, etalonframes);
++numberOfFilesTotal;
if (option_Recognize)
{
if (decision==1)
{ cout << "Detected" << endl; ++numberOfFilesPositive; }
else if (decision==0)
{ cout << "Not detected" << endl; ++numberOfFilesNegative; }
else if (decision==-2)
{ cout << "Something went wrong during writing splitted sounds."<< endl << "Check the availability of folder named splitted" << endl; }
else
{ cout << "Something went wrong during making decision" << endl;}
if (option_ResultsToFile)
{
res_file << inputFile << "," << decision << endl;
}
}
}
}
}
else
{
cerr << "Something went wrong while opening folder with input data files" << endl;
return EXIT_FAILURE;
}
if (!option_SilentMode) {cout << "Completed. " << endl;}
cout << endl << "Summary:" << endl;
cout << "Total number of files processed: "<< numberOfFilesTotal << endl;
cout << "Sneezing sound detected: "<< numberOfFilesPositive << endl;
cout << "Sneezing sound NOT detected: "<< numberOfFilesNegative << endl << endl;
if (option_ResultsToFile)
{
cout << "Results were exported to CSV file " << setting_ResultsFileName << endl;
res_file.close();
}
if (option_WriteLog)
{
cout << "Log of analysis process was saved to file" << setting_LogFileName << endl;
log_file.close();
}
#ifdef _MSC_VER
system("pause");
#endif
return EXIT_SUCCESS;
}