1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-09 20:32:43 +01:00

De-initialize OpenAL

This commit is contained in:
darkf 2016-08-02 04:00:36 -07:00
parent a574649dce
commit 77ca9054c6
2 changed files with 42 additions and 29 deletions

View File

@ -14,6 +14,7 @@ class SoundManager
{ {
public: public:
SoundManager(); SoundManager();
~SoundManager();
bool loadSound(const std::string& name, const std::string& fileName); bool loadSound(const std::string& name, const std::string& fileName);
bool isLoaded(const std::string& name); bool isLoaded(const std::string& name);
@ -63,8 +64,8 @@ private:
bool initializeOpenAL(); bool initializeOpenAL();
ALCcontext* alContext; ALCcontext* alContext = nullptr;
ALCdevice* alDevice; ALCdevice* alDevice = nullptr;
std::map<std::string, Sound> sounds; std::map<std::string, Sound> sounds;
std::map<std::string, MADStream> musics; std::map<std::string, MADStream> musics;

View File

@ -7,6 +7,45 @@
#include <array> #include <array>
#include <iostream> #include <iostream>
SoundManager::SoundManager()
{
initializeOpenAL();
}
SoundManager::~SoundManager()
{
// De-initialize OpenAL
if(alContext) {
alcMakeContextCurrent(NULL);
alcDestroyContext(alContext);
}
if(alDevice)
alcCloseDevice(alDevice);
}
bool SoundManager::initializeOpenAL()
{
alDevice = alcOpenDevice(NULL);
if ( ! alDevice) {
std::cerr << "Could not find OpenAL device!" << std::endl;
return false;
}
alContext = alcCreateContext(alDevice, NULL);
if ( ! alContext) {
std::cerr << "Could not create OpenAL context!" << std::endl;
return false;
}
if ( ! alcMakeContextCurrent(alContext)) {
std::cerr << "Unable to make OpenAL context current!" << std::endl;
return false;
}
return true;
}
void SoundManager::SoundSource::loadFromFile(const std::string& filename) void SoundManager::SoundSource::loadFromFile(const std::string& filename)
{ {
fileInfo.format = 0; fileInfo.format = 0;
@ -50,33 +89,6 @@ bool SoundManager::SoundBuffer::bufferData(SoundSource& soundSource)
return true; return true;
} }
SoundManager::SoundManager()
{
initializeOpenAL();
}
bool SoundManager::initializeOpenAL()
{
alDevice = alcOpenDevice(NULL);
if ( ! alDevice) {
std::cerr << "Could not find OpenAL device!" << std::endl;
return false;
}
alContext = alcCreateContext(alDevice, NULL);
if ( ! alContext) {
std::cerr << "Could not create OpenAL context!" << std::endl;
return false;
}
if ( ! alcMakeContextCurrent(alContext)) {
std::cerr << "Unable to make OpenAL context current!" << std::endl;
return false;
}
return true;
}
bool SoundManager::loadSound(const std::string& name, const std::string& fileName) bool SoundManager::loadSound(const std::string& name, const std::string& fileName)
{ {
Sound* sound = nullptr; Sound* sound = nullptr;