Make audio asset decoding failures non-fatal
Matches RMXP behavior. This is also useful in case midi files are to be played, but fluidsynth isn't available.
This commit is contained in:
parent
0f91bdefea
commit
531441d4e3
|
@ -25,9 +25,11 @@
|
|||
#include "sharedmidistate.h"
|
||||
#include "eventthread.h"
|
||||
#include "filesystem.h"
|
||||
#include "exception.h"
|
||||
#include "aldatasource.h"
|
||||
#include "fluid-fun.h"
|
||||
#include "sdl-util.h"
|
||||
#include "debugwriter.h"
|
||||
|
||||
#include <SDL_mutex.h>
|
||||
#include <SDL_thread.h>
|
||||
|
@ -123,6 +125,9 @@ void ALStream::stop()
|
|||
|
||||
void ALStream::play(float offset)
|
||||
{
|
||||
if (!source)
|
||||
return;
|
||||
|
||||
checkStopped();
|
||||
|
||||
switch (state)
|
||||
|
@ -205,24 +210,36 @@ void ALStream::openSource(const std::string &filename)
|
|||
SDL_RWread(&srcOps, sig, 1, 4);
|
||||
SDL_RWseek(&srcOps, 0, RW_SEEK_SET);
|
||||
|
||||
if (!strcmp(sig, "OggS"))
|
||||
try
|
||||
{
|
||||
source = createVorbisSource(srcOps, looped);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strcmp(sig, "MThd"))
|
||||
{
|
||||
shState->midiState().initIfNeeded(shState->config());
|
||||
|
||||
if (HAVE_FLUID)
|
||||
if (!strcmp(sig, "OggS"))
|
||||
{
|
||||
source = createMidiSource(srcOps, looped);
|
||||
source = createVorbisSource(srcOps, looped);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
source = createSDLSource(srcOps, ext, STREAM_BUF_SIZE, looped);
|
||||
if (!strcmp(sig, "MThd"))
|
||||
{
|
||||
shState->midiState().initIfNeeded(shState->config());
|
||||
|
||||
if (HAVE_FLUID)
|
||||
{
|
||||
source = createMidiSource(srcOps, looped);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
source = createSDLSource(srcOps, ext, STREAM_BUF_SIZE, looped);
|
||||
}
|
||||
catch (const Exception &e)
|
||||
{
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s.%s: %s",
|
||||
filename.c_str(), ext, e.msg.c_str());
|
||||
buf[sizeof(buf)-1] = '\0';
|
||||
|
||||
Debug() << buf;
|
||||
}
|
||||
}
|
||||
|
||||
void ALStream::stopStream()
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "exception.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "debugwriter.h"
|
||||
|
||||
#include <SDL_sound.h>
|
||||
|
||||
|
@ -127,6 +128,9 @@ void SoundEmitter::play(const std::string &filename,
|
|||
|
||||
SoundBuffer *buffer = allocateBuffer(filename);
|
||||
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
/* Try to find first free source */
|
||||
size_t i;
|
||||
for (i = 0; i < srcCount; ++i)
|
||||
|
@ -206,9 +210,13 @@ SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename)
|
|||
|
||||
if (!sampleHandle)
|
||||
{
|
||||
SDL_RWclose(&dataSource);
|
||||
throw Exception(Exception::SDLError, "%s.%s: %s",
|
||||
filename.c_str(), extension, Sound_GetError());
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof(buf), "Unable to decode sound: %s.%s: %s",
|
||||
filename.c_str(), ext, Sound_GetError());
|
||||
buf[sizeof(buf)-1] = '\0';
|
||||
Debug() << buf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t decBytes = Sound_DecodeAll(sampleHandle);
|
||||
|
|
Loading…
Reference in New Issue