forked from mirror/openmw-tes3mp
Finally "fix" --nosound
Expect degraded performance with it. Looping sounds are constantly checked to see if they're playing, and try to play it again when it's not.
This commit is contained in:
parent
7541e08909
commit
bfac946878
2 changed files with 26 additions and 20 deletions
|
@ -25,14 +25,20 @@ static void throwALCerror(ALCdevice *device)
|
||||||
{
|
{
|
||||||
ALCenum err = alcGetError(device);
|
ALCenum err = alcGetError(device);
|
||||||
if(err != ALC_NO_ERROR)
|
if(err != ALC_NO_ERROR)
|
||||||
fail(alcGetString(device, err));
|
{
|
||||||
|
const ALCchar *errstring = alcGetString(device, err);
|
||||||
|
fail(errstring ? errstring : "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void throwALerror()
|
static void throwALerror()
|
||||||
{
|
{
|
||||||
ALenum err = alGetError();
|
ALenum err = alGetError();
|
||||||
if(err != AL_NO_ERROR)
|
if(err != AL_NO_ERROR)
|
||||||
fail(alGetString(err));
|
{
|
||||||
|
const ALchar *errstring = alGetString(err);
|
||||||
|
fail(errstring ? errstring : "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -424,8 +430,7 @@ std::vector<std::string> OpenAL_Output::enumerate()
|
||||||
|
|
||||||
void OpenAL_Output::init(const std::string &devname)
|
void OpenAL_Output::init(const std::string &devname)
|
||||||
{
|
{
|
||||||
if(mDevice || mContext)
|
deinit();
|
||||||
fail("Device already open");
|
|
||||||
|
|
||||||
mDevice = alcOpenDevice(devname.c_str());
|
mDevice = alcOpenDevice(devname.c_str());
|
||||||
if(!mDevice)
|
if(!mDevice)
|
||||||
|
@ -442,7 +447,12 @@ void OpenAL_Output::init(const std::string &devname)
|
||||||
|
|
||||||
mContext = alcCreateContext(mDevice, NULL);
|
mContext = alcCreateContext(mDevice, NULL);
|
||||||
if(!mContext || alcMakeContextCurrent(mContext) == ALC_FALSE)
|
if(!mContext || alcMakeContextCurrent(mContext) == ALC_FALSE)
|
||||||
|
{
|
||||||
|
if(mContext)
|
||||||
|
alcDestroyContext(mContext);
|
||||||
|
mContext = 0;
|
||||||
fail(std::string("Failed to setup context: ")+alcGetString(mDevice, alcGetError(mDevice)));
|
fail(std::string("Failed to setup context: ")+alcGetString(mDevice, alcGetError(mDevice)));
|
||||||
|
}
|
||||||
|
|
||||||
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
|
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
@ -598,8 +608,6 @@ void OpenAL_Output::bufferFinished(ALuint buf)
|
||||||
|
|
||||||
SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float pitch, bool loop)
|
SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float pitch, bool loop)
|
||||||
{
|
{
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
boost::shared_ptr<OpenAL_Sound> sound;
|
boost::shared_ptr<OpenAL_Sound> sound;
|
||||||
ALuint src=0, buf=0;
|
ALuint src=0, buf=0;
|
||||||
|
|
||||||
|
@ -647,8 +655,6 @@ SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float
|
||||||
SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector3 &pos, float volume, float pitch,
|
SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector3 &pos, float volume, float pitch,
|
||||||
float min, float max, bool loop)
|
float min, float max, bool loop)
|
||||||
{
|
{
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
boost::shared_ptr<OpenAL_Sound> sound;
|
boost::shared_ptr<OpenAL_Sound> sound;
|
||||||
ALuint src=0, buf=0;
|
ALuint src=0, buf=0;
|
||||||
|
|
||||||
|
@ -697,8 +703,6 @@ SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector
|
||||||
|
|
||||||
SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, float pitch)
|
SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, float pitch)
|
||||||
{
|
{
|
||||||
throwALerror();
|
|
||||||
|
|
||||||
boost::shared_ptr<OpenAL_SoundStream> sound;
|
boost::shared_ptr<OpenAL_SoundStream> sound;
|
||||||
ALuint src;
|
ALuint src;
|
||||||
|
|
||||||
|
@ -741,15 +745,18 @@ SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, floa
|
||||||
|
|
||||||
void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir)
|
void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir)
|
||||||
{
|
{
|
||||||
|
mPos = pos;
|
||||||
|
|
||||||
|
if(mContext)
|
||||||
|
{
|
||||||
ALfloat orient[6] = {
|
ALfloat orient[6] = {
|
||||||
atdir.x, atdir.z, -atdir.y,
|
atdir.x, atdir.z, -atdir.y,
|
||||||
updir.x, updir.z, -updir.y
|
updir.x, updir.z, -updir.y
|
||||||
};
|
};
|
||||||
mPos = pos;
|
|
||||||
|
|
||||||
alListener3f(AL_POSITION, mPos.x, mPos.z, -mPos.y);
|
alListener3f(AL_POSITION, mPos.x, mPos.z, -mPos.y);
|
||||||
alListenerfv(AL_ORIENTATION, orient);
|
alListenerfv(AL_ORIENTATION, orient);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ namespace MWSound
|
||||||
SoundManager::SoundManager(bool useSound, MWWorld::Environment& environment)
|
SoundManager::SoundManager(bool useSound, MWWorld::Environment& environment)
|
||||||
: mResourceMgr(Ogre::ResourceGroupManager::getSingleton())
|
: mResourceMgr(Ogre::ResourceGroupManager::getSingleton())
|
||||||
, mEnvironment(environment)
|
, mEnvironment(environment)
|
||||||
|
, mOutput(new DEFAULT_OUTPUT(*this))
|
||||||
|
|
||||||
{
|
{
|
||||||
if(!useSound)
|
if(!useSound)
|
||||||
return;
|
return;
|
||||||
|
@ -50,8 +52,6 @@ namespace MWSound
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mOutput.reset(new DEFAULT_OUTPUT(*this));
|
|
||||||
|
|
||||||
std::vector<std::string> names = mOutput->enumerate();
|
std::vector<std::string> names = mOutput->enumerate();
|
||||||
std::cout <<"Enumerated output devices:"<< std::endl;
|
std::cout <<"Enumerated output devices:"<< std::endl;
|
||||||
for(size_t i = 0;i < names.size();i++)
|
for(size_t i = 0;i < names.size();i++)
|
||||||
|
@ -62,7 +62,6 @@ namespace MWSound
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
std::cout <<"Sound init failed: "<<e.what()<< std::endl;
|
std::cout <<"Sound init failed: "<<e.what()<< std::endl;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue