Be more specific about what audio type is detected and for which file if it is not supported.

This commit is contained in:
Erik Hofman 2016-07-20 08:37:07 +02:00
parent 9b4f1b0ff8
commit 5f54388ed9
2 changed files with 19 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <stdio.h> // snprintf
#include <zlib.h> // for gzXXX functions #include <zlib.h> // for gzXXX functions
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
@ -61,11 +62,19 @@ namespace
else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8; else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8;
else if (numChannels == 2 && bitsPerSample == 16) rv = SG_SAMPLE_STEREO16; else if (numChannels == 2 && bitsPerSample == 16) rv = SG_SAMPLE_STEREO16;
else if (numChannels == 2 && bitsPerSample == 8) rv = SG_SAMPLE_STEREO8; else if (numChannels == 2 && bitsPerSample == 8) rv = SG_SAMPLE_STEREO8;
else throw sg_exception("Unsupported audio format"); else {
char msg[65];
snprintf(msg, 64, "Unsupported audio format: tracks: %i, bits/sample: %i", numChannels, bitsPerSample);
throw sg_exception(msg);
}
} else { } else {
if (numChannels == 1 && bitsPerSample == 4) rv = SG_SAMPLE_ADPCM; if (numChannels == 1 && bitsPerSample == 4) rv = SG_SAMPLE_ADPCM;
else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MULAW; else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MULAW;
else throw sg_exception("Unsupported audio format"); else {
char msg[65];
snprintf(msg, 64, "Unsupported compressed audio format: tracks: %i, bits/sample: %i", numChannels, bitsPerSample);
throw sg_exception(msg);
}
} }
return rv; return rv;
} }
@ -382,7 +391,12 @@ ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size,
throw sg_io_exception("loadWAVFromFile: unable to open file", path); throw sg_io_exception("loadWAVFromFile: unable to open file", path);
} }
loadWavFile(fd, &b); try {
loadWavFile(fd, &b);
} catch (sg_exception& e) {
throw sg_io_exception(e.getFormattedMessage() + " for " + path.str());
}
ALvoid* data = b.data; ALvoid* data = b.data;
b.data = NULL; // don't free when Buffer does out of scope b.data = NULL; // don't free when Buffer does out of scope
format = b.format; format = b.format;

View File

@ -588,9 +588,11 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
break; break;
case SG_SAMPLE_STEREO16: case SG_SAMPLE_STEREO16:
SG_LOG(SG_SOUND, SG_ALERT, "Stereo sound detected: " << sample->get_sample_name());
format = AL_FORMAT_STEREO16; format = AL_FORMAT_STEREO16;
break; break;
case SG_SAMPLE_STEREO8: case SG_SAMPLE_STEREO8:
SG_LOG(SG_SOUND, SG_ALERT, "Stereo sound detected: " << sample->get_sample_name());
format = AL_FORMAT_STEREO8; format = AL_FORMAT_STEREO8;
default: default:
SG_LOG(SG_SOUND, SG_ALERT, "unsupported audio format"); SG_LOG(SG_SOUND, SG_ALERT, "unsupported audio format");