-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetlm.cpp
More file actions
65 lines (57 loc) · 1.94 KB
/
getlm.cpp
File metadata and controls
65 lines (57 loc) · 1.94 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
// cl /EHsc /O2 /openmp getlm.cpp Landmark.cpp Database.cpp lib/WavReader.cpp lib/Timing.cpp lib/ReadAudio.cpp lib/BmpReader.cpp lib/Signal.cpp lib/utils.cpp lib/Sound.cpp PeakFinder.cpp PeakFinderDejavu.cpp Analyzer.cpp
#include <cstring>
#include <fstream>
#include <stdio.h>
#include "Analyzer.hpp"
#include "Landmark.hpp"
#include "PeakFinderDejavu.hpp"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: ./getlm file out [REPEAT_COUNT]\n");
return 1;
}
std::string outname;
if (argc < 3) outname = argv[1] + std::string(".lm");
else outname = argv[2];
Analyzer analyzer;
PeakFinder *peakfinder = new PeakFinderDejavu;
LandmarkBuilder *lmbuilder = new LandmarkBuilder;
int extractpeak = 0;
if (argc > 3) {
if (sscanf(argv[3], "%d", &analyzer.REPEAT_COUNT) == 1) {
if (analyzer.REPEAT_COUNT > 10 || analyzer.REPEAT_COUNT < 1) {
printf("REPEAT_COUNT must be 1 ~ 10\n");
return 1;
}
}
else if (argv[3] == std::string("peaks")) {
extractpeak = 1;
}
}
analyzer.peak_finder = peakfinder;
analyzer.landmark_builder = lmbuilder;
std::ofstream fout(outname, std::ios::binary);
if (!fout) {
printf("Cannot write to file %s\n", argv[2]);
return 1;
}
try {
std::vector<Landmark> lms = analyzer.fingerprint_file(argv[1]);
printf("File contains %zd landmarks and %zd peaks\n", lms.size(), analyzer.peaks.size());
if (extractpeak) {
fout.write((const char *)analyzer.peaks.data(), analyzer.peaks.size() * sizeof(Peak));
}
else {
fout.write((const char *)lms.data(), lms.size() * sizeof(lms[0]));
}
}
catch (std::runtime_error &err) {
printf("%s\n", err.what());
}
fout.close();
// output spectrogram for demonstration
fout.open("test", std::ios::binary);
fout.write(reinterpret_cast<char*>(peakfinder->spec.data()), peakfinder->spec.size() * sizeof(double));
delete peakfinder;
delete lmbuilder;
}