Debian Codegraph @

src/game/audio/openaldevice.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2013 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "openaldevice.hpp"
17 #include "simple_logger.hpp"
18
19 OpenALDevice::OpenALDevice()
20 : m_device(nullptr)
21 , m_context(nullptr)
22 {
23 }
24
25 void OpenALDevice::initialize()
26 {
27 m_device = alcOpenDevice(alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER));
28 if (!m_device)
29 {
30 throw std::runtime_error("Failed to open default sound device");
31 }
32
33 juzzlin::L().info() << "Sound device: " << alcGetString(m_device, ALC_DEVICE_SPECIFIER);
34
35 m_context = alcCreateContext(m_device, nullptr);
36 if (!alcMakeContextCurrent(m_context))
37 {
38 throw std::runtime_error("Failed to create default sound context");
39 }
40 }
41
42 void OpenALDevice::shutDown()
43 {
44 alcMakeContextCurrent(nullptr);
45 alcDestroyContext(m_context);
46 alcCloseDevice(m_device);
47 }
48
49 OpenALDevice::~OpenALDevice()
50 {
51 shutDown();
52 }