Try opening the default device fallback in OpenAL_Output

This commit is contained in:
Chris Robinson 2017-09-15 19:36:49 -07:00
parent f594eda574
commit acd6d9cd72
2 changed files with 23 additions and 32 deletions

View file

@ -595,23 +595,23 @@ bool OpenAL_Output::init(const std::string &devname, const std::string &hrtfname
deinit();
mDevice = alcOpenDevice(devname.c_str());
if(!mDevice && !devname.empty())
{
std::cerr<< "Failed to open \""<<devname<<"\", trying default" <<std::endl;
mDevice = alcOpenDevice(nullptr);
}
if(!mDevice)
{
if(devname.empty())
std::cerr<< "Failed to open default audio device" <<std::endl;
else
std::cerr<< "Failed to open \""<<devname<<"\"" <<std::endl;
std::cerr<< "Failed to open default audio device" <<std::endl;
return false;
}
else
{
const ALCchar *name = NULL;
if(alcIsExtensionPresent(mDevice, "ALC_ENUMERATE_ALL_EXT"))
name = alcGetString(mDevice, ALC_ALL_DEVICES_SPECIFIER);
if(alcGetError(mDevice) != AL_NO_ERROR || !name)
name = alcGetString(mDevice, ALC_DEVICE_SPECIFIER);
std::cout << "Opened \""<<name<<"\"" << std::endl;
}
const ALCchar *name = nullptr;
if(alcIsExtensionPresent(mDevice, "ALC_ENUMERATE_ALL_EXT"))
name = alcGetString(mDevice, ALC_ALL_DEVICES_SPECIFIER);
if(alcGetError(mDevice) != AL_NO_ERROR || !name)
name = alcGetString(mDevice, ALC_DEVICE_SPECIFIER);
std::cout<< "Opened \""<<name<<"\"" <<std::endl;
ALC.EXT_EFX = alcIsExtensionPresent(mDevice, "ALC_EXT_EFX");
ALC.SOFT_HRTF = alcIsExtensionPresent(mDevice, "ALC_SOFT_HRTF");
@ -643,7 +643,7 @@ bool OpenAL_Output::init(const std::string &devname, const std::string &hrtfname
}
if(index < 0)
std::cerr<< "Failed to find HRTF name \""<<hrtfname<<"\", using default" <<std::endl;
std::cerr<< "Failed to find HRTF \""<<hrtfname<<"\", using default" <<std::endl;
else
{
attrs.push_back(ALC_HRTF_ID_SOFT);
@ -698,7 +698,7 @@ bool OpenAL_Output::init(const std::string &devname, const std::string &hrtfname
{
ALuint src = 0;
alGenSources(1, &src);
if(getALError() != AL_NO_ERROR)
if(alGetError() != AL_NO_ERROR)
break;
mFreeSources.push_back(src);
}
@ -824,8 +824,10 @@ void OpenAL_Output::deinit()
{
mStreamThread->removeAll();
for(size_t i = 0;i < mFreeSources.size();i++)
alDeleteSources(1, &mFreeSources[i]);
std::for_each(mFreeSources.cbegin(), mFreeSources.cend(),
[](ALuint source) -> void
{ alDeleteSources(1, &source); }
);
mFreeSources.clear();
if(mEffectSlot)

View file

@ -26,11 +26,7 @@
#include "sound.hpp"
#include "openal_output.hpp"
#define SOUND_OUT "OpenAL"
#include "ffmpeg_decoder.hpp"
#ifndef SOUND_IN
#define SOUND_IN "FFmpeg"
#endif
namespace MWSound
@ -60,6 +56,8 @@ namespace MWSound
, mUnderwaterSound(nullptr)
, mNearWaterSound(nullptr)
{
std::cout<< "Initializing sound..." <<std::endl;
mMasterVolume = Settings::Manager::getFloat("master volume", "Sound");
mMasterVolume = std::min(std::max(mMasterVolume, 0.0f), 1.0f);
mSFXVolume = Settings::Manager::getFloat("sfx volume", "Sound");
@ -91,9 +89,6 @@ namespace MWSound
HrtfMode hrtfmode = hrtfstate < 0 ? HrtfMode::Auto :
hrtfstate > 0 ? HrtfMode::Enable : HrtfMode::Disable;
std::cout << "Sound output: " << SOUND_OUT << std::endl;
std::cout << "Sound decoder: " << SOUND_IN << std::endl;
std::vector<std::string> names = mOutput->enumerate();
std::cout <<"Enumerated output devices:\n";
std::for_each(names.cbegin(), names.cend(),
@ -103,15 +98,9 @@ namespace MWSound
std::cout.flush();
std::string devname = Settings::Manager::getString("device", "Sound");
bool inited = mOutput->init(devname, hrtfname, hrtfmode);
if(!inited && !devname.empty())
if(!mOutput->init(devname, hrtfname, hrtfmode))
{
std::cerr<< "Failed to initialize device \""<<devname<<"\", trying default" <<std::endl;
inited = mOutput->init(std::string(), hrtfname, hrtfmode);
}
if(!inited)
{
std::cerr<< "Failed to initialize default audio device, sound disabled" <<std::endl;
std::cerr<< "Failed to initialize audio output, sound disabled" <<std::endl;
return;
}