-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundDevice.cpp
38 lines (32 loc) · 886 Bytes
/
SoundDevice.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
#include "SoundDevice.h"
#ifdef OPENAL
SoundDevice::SoundDevice(const ALCchar* deviceName) {
Init(deviceName);
}
SoundDevice::~SoundDevice() {
Delete();
}
void SoundDevice::Init(const ALCchar* deviceName) {
Init(deviceName, &device, &context);
}
void SoundDevice::Init(const ALCchar* deviceName, ALCdevice** device, ALCcontext** context) {
*device = alcOpenDevice(deviceName);
if (!*device) {
std::cout << "ERROR: Failed to get the device!\n";
return;
}
*context = alcCreateContext(*device, nullptr);
if (!alcMakeContextCurrent(*context)) {
std::cout << "ERROR: Failed to make the context current!\n";
return;
}
}
void SoundDevice::Delete() {
Delete(device, context);
}
void SoundDevice::Delete(ALCdevice* device, ALCcontext* context) {
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
alcCloseDevice(device);
}
#endif