35 {
36 if (g_ref_count++) {
37 return;
38 }
39 std::vector<std::string> devices;
40 GetDevices(devices);
41 std::cout << "Audio devices found " << devices.size() << ":" << std::endl;
42
43 for (auto& it : devices) {
44 std::cout << "* " << it << std::endl;
45 }
46
47 std::cout << std::endl;
48
49 g_audio_device = alcOpenDevice(devices[0].c_str());
50
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"
55 << std::endl;
56 return;
57 }
58
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;
62 return;
63 }
64
65 if (!alcMakeContextCurrent(g_audio_context)) {
66 std::cerr << "Failed to make the OpenAL context active" << std::endl;
67 return;
68 }
69}