10#include <smk/Audio.hpp>
17ALCdevice* g_audio_device =
nullptr;
18ALCcontext* g_audio_context =
nullptr;
20void GetDevices(std::vector<std::string>& devices) {
22 const ALCchar* device_list = alcGetString(
nullptr, ALC_DEVICE_SPECIFIER);
27 while (std::strlen(device_list) > 0) {
28 devices.emplace_back(device_list);
29 device_list += std::strlen(device_list) + 1;
39 std::vector<std::string> devices;
41 std::cout <<
"Audio devices found " << devices.size() <<
":" << std::endl;
43 for (
auto& it : devices) {
44 std::cout <<
"* " << it << std::endl;
47 std::cout << std::endl;
49 g_audio_device = alcOpenDevice(devices[0].c_str());
51 if (!g_audio_device) {
52 std::cerr <<
"Failed to get an OpenAL device. Please check you have some "
53 "backend configured while building your application. For "
54 "instance PulseAudio with libpulse-dev"
59 g_audio_context = alcCreateContext(g_audio_device,
nullptr);
60 if (!g_audio_context) {
61 std::cerr <<
"Failed to get an OpenAL context" << std::endl;
65 if (!alcMakeContextCurrent(g_audio_context)) {
66 std::cerr <<
"Failed to make the OpenAL context active" << std::endl;
76 alcMakeContextCurrent(
nullptr);
77 if (g_audio_context) {
78 alcDestroyContext(g_audio_context);
79 g_audio_context =
nullptr;
84 alcCloseDevice(g_audio_device);
85 g_audio_device =
nullptr;
static bool Initialized()