-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
audio_device.h
74 lines (60 loc) · 1.32 KB
/
audio_device.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
71
72
73
#pragma once
#include "util.h"
struct OggVorbis_File;
struct vorbis_info;
class FilePath;
typedef unsigned int OpenalId;
class SoundBuffer {
public:
SoundBuffer(const FilePath&);
~SoundBuffer();
SoundBuffer(SoundBuffer&&);
OpenalId getBufferId() const;
private:
optional<OpenalId> bufferId;
};
class SoundSource {
public:
SoundSource();
~SoundSource();
SoundSource& operator = (SoundSource&&);
SoundSource(SoundSource&&);
OpenalId getId() const;
void destroy();
private:
optional<OpenalId> id;
};
class AudioDevice;
class SoundStream {
public:
SoundStream(const FilePath&, double volume);
bool isPlaying() const;
~SoundStream();
void setVolume(double);
double getVolume() const;
private:
void loop();
void init(const FilePath&);
SoundSource source;
OpenalId buffers[2];
HeapAllocated<OggVorbis_File> file;
vorbis_info *info;
atomic<bool> startedPlaying;
AsyncLoop streamer;
atomic<float> volume;
};
class AudioDevice {
public:
AudioDevice();
optional<string> initialize();
~AudioDevice();
void play(const SoundBuffer&, double volume, double pitch = 1);
milliseconds getDuration(const SoundBuffer&);
private:
friend SoundStream;
optional<OpenalId> getFreeSource();
void *device;
void *context;
vector<SoundSource> sources;
recursive_mutex mutex;
};