From 5d2ce8e04573bff2beaa5b1d1b6ab102456d9e6b Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 20 Jul 2016 08:37:07 +0200 Subject: [PATCH] Be more specific about what audio type is detected and for which file if it is not supported. --- simgear/sound/readwav.cxx | 20 +++++++++++++++++--- simgear/sound/soundmgr_openal.cxx | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/simgear/sound/readwav.cxx b/simgear/sound/readwav.cxx index 9026e7fc..fa892d23 100644 --- a/simgear/sound/readwav.cxx +++ b/simgear/sound/readwav.cxx @@ -23,6 +23,7 @@ #include #include +#include // snprintf #include // for gzXXX functions #include @@ -61,11 +62,19 @@ namespace 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 == 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 { if (numChannels == 1 && bitsPerSample == 4) rv = SG_SAMPLE_ADPCM; 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; } @@ -382,7 +391,12 @@ ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, 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; b.data = NULL; // don't free when Buffer does out of scope format = b.format; diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 6064a0be..ec1646af 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -588,9 +588,11 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) break; case SG_SAMPLE_STEREO16: + SG_LOG(SG_SOUND, SG_ALERT, "Stereo sound detected: " << sample->get_sample_name()); format = AL_FORMAT_STEREO16; break; case SG_SAMPLE_STEREO8: + SG_LOG(SG_SOUND, SG_ALERT, "Stereo sound detected: " << sample->get_sample_name()); format = AL_FORMAT_STEREO8; default: SG_LOG(SG_SOUND, SG_ALERT, "unsupported audio format"); -- 2.39.5