-
Notifications
You must be signed in to change notification settings - Fork 586
/
audio-logger.h
70 lines (51 loc) · 1.56 KB
/
audio-logger.h
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
/*! \file audio-logger.h
* \brief Audio capture helper class
*
* Used by all kbd-audio tools.
* It provides a stream of captured audio via a provided callback.
*
* \author Georgi Gerganov
*/
#pragma once
#include "constants.h"
#include "common.h"
#include <memory>
#include <array>
#include <vector>
#include <functional>
class AudioLogger {
public:
using Sample = TSampleF;
using Frame = std::array<Sample, kSamplesPerFrame>;
using Record = std::vector<Frame>;
using Callback = std::function<void(const Record & frames)>;
struct Parameters {
Callback callback;
int32_t captureId = -1;
int32_t nChannels = -1;
int64_t sampleRate = -1;
// Sample Type
// todo : support for other sample types
enum ESampleType {
F32SYS,
};
ESampleType sampleType = F32SYS;
// Audio Filter
EAudioFilter filter = FirstOrderHighPass;
float freqCutoff_Hz = 1000.0f;
};
AudioLogger();
~AudioLogger();
bool install(Parameters && parameters);
bool terminate();
bool addFrame(const Sample * stream);
bool record(float bufferSize_s, int32_t nPrevFrames);
bool pause();
bool resume();
bool isValidBufferSize(float bufferSize_s) const;
private:
struct Data;
std::unique_ptr<Data> data_;
Data & getData() { return *data_; }
const Data & getData() const { return *data_; }
};