If a sound effect fails to load, substitute silence.

pull/359/head
Chris Robinson 7 years ago
parent aecf74e7bb
commit 06ae61479a

@ -948,35 +948,42 @@ std::pair<Sound_Handle,size_t> OpenAL_Output::loadSound(const std::string &fname
DecoderPtr decoder = mManager.getDecoder(); DecoderPtr decoder = mManager.getDecoder();
// Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav. // Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.
bool succeeded;
if(decoder->mResourceMgr->exists(fname)) if(decoder->mResourceMgr->exists(fname))
{ succeeded = decoder->open(fname);
if(!decoder->open(fname))
return std::make_pair(nullptr, 0);
}
else else
{ {
std::string file = fname; std::string file = fname;
std::string::size_type pos = file.rfind('.'); std::string::size_type pos = file.rfind('.');
if(pos != std::string::npos) if(pos != std::string::npos)
file = file.substr(0, pos)+".mp3"; file = file.substr(0, pos)+".mp3";
if(!decoder->open(file)) succeeded = decoder->open(file);
return std::make_pair(nullptr, 0);
} }
std::vector<char> data; std::vector<char> data;
ChannelConfig chans;
SampleType type;
ALenum format; ALenum format;
int srate; int srate;
if(!decoder->getInfo(&srate, &chans, &type)) if(succeeded)
return std::make_pair(nullptr, 0); {
format = getALFormat(chans, type); ChannelConfig chans;
if(!format) return std::make_pair(nullptr, 0); SampleType type;
if(decoder->getInfo(&srate, &chans, &type))
decoder->readAll(data); {
format = getALFormat(chans, type);
if(format) decoder->readAll(data);
}
}
decoder->close(); decoder->close();
if(data.empty())
{
// If we failed to get any usable audio, substitute with silence.
format = AL_FORMAT_MONO8;
srate = 8000;
data.assign(8000, -128);
}
ALint size; ALint size;
ALuint buf = 0; ALuint buf = 0;
alGenBuffers(1, &buf); alGenBuffers(1, &buf);

Loading…
Cancel
Save