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:
parent
a574649dce
commit
77ca9054c6
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user