-
Notifications
You must be signed in to change notification settings - Fork 588
/
record-full.cpp
75 lines (60 loc) · 1.99 KB
/
record-full.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
/*! \file record-full.cpp
* \brief Enter description here.
* \author Georgi Gerganov
*/
#include "constants.h"
#include "common.h"
#include "audio-logger.h"
#include <fstream>
#include <chrono>
#include <thread>
bool g_terminate = false;
int main(int argc, char ** argv) {
printf("Usage: %s output.kbd [-cN]\n", argv[0]);
printf(" -cN - select capture device N\n");
printf(" -CN - number N of capture channels N\n");
printf("\n");
if (argc < 2) {
return -127;
}
auto argm = parseCmdArguments(argc, argv);
int captureId = argm["c"].empty() ? 0 : std::stoi(argm["c"]);
int nChannels = argm["C"].empty() ? 0 : std::stoi(argm["C"]);
bool doRecord = true;
size_t totalSize_bytes = 0;
std::ofstream fout(argv[1], std::ios::binary);
if (fout.good() == false) {
fprintf(stderr, "Failed to open file '%s'\n", argv[1]);
return -1;
}
AudioLogger audioLogger;
AudioLogger::Callback cbAudio = [&](const auto & frames) {
doRecord = true;
for (const auto & frame : frames) {
totalSize_bytes += sizeof(frame[0])*frame.size();
fout.write((char *)(frame.data()), sizeof(frame[0])*frame.size());
fout.flush();
}
printf("Total data saved: %g MB\n", ((float)(totalSize_bytes)/1024.0f/1024.0f));
};
AudioLogger::Parameters parameters;
parameters.callback = std::move(cbAudio);
parameters.captureId = captureId;
parameters.nChannels = nChannels;
parameters.sampleRate = kSampleRate;
parameters.filter = EAudioFilter::None;
parameters.freqCutoff_Hz = kFreqCutoff_Hz;
if (audioLogger.install(std::move(parameters)) == false) {
fprintf(stderr, "Failed to install audio logger\n");
return -1;
}
while (true) {
if (doRecord) {
doRecord = false;
audioLogger.record(0.5f, 0);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
return 0;
}