-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioDevice.h
60 lines (45 loc) · 1.24 KB
/
AudioDevice.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
#ifndef AUDIO_DEVICE_H
#define AUDIO_DEVICE_H
#include "AudioSequence.h"
#include "SdlGuard.h"
#define SDL_MAIN_HANDLED
#include "SDL2/SDL.h"
#include <chrono>
#include <cstdint>
namespace audio {
template<typename T>
struct DeviceCapture
{
DeviceCapture(const Metadata& metadata = Metadata());
DeviceCapture(const DeviceCapture&) = delete;
DeviceCapture(DeviceCapture&&) = delete;
~DeviceCapture();
Sequence<T> record(std::chrono::milliseconds length);
Sequence<T> record(uint32_t lengthMsec);
private:
static void deviceCallback(void* userdata, uint8_t* stream, int len);
void deviceCallback(uint8_t* stream, int len);
private:
SdlGuard guard_;
Sequence<T> seq_;
SDL_AudioDeviceID deviceId_;
};
template<typename T>
struct DevicePlayback
{
DevicePlayback(const Metadata& metadata = Metadata());
DevicePlayback(const DevicePlayback&) = delete;
DevicePlayback(DevicePlayback&&) = delete;
~DevicePlayback();
void play(Sequence<T> seq);
private:
static void deviceCallback(void* userdata, uint8_t* stream, int len);
void deviceCallback(uint8_t* stream, int len);
private:
SdlGuard guard_;
SDL_AudioDeviceID deviceId_;
Sequence<T> seq_;
};
} // namespace audio
#include "AudioDevice_impl.h"
#endif // AUDIO_DEVICE_H