From: Erik Hofman <erik@ehofman.com>
Date: Wed, 20 Jul 2016 06:37:07 +0000 (+0200)
Subject: Be more specific about what audio type is detected and for which file if it is not... 
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d2ce8e04573bff2beaa5b1d1b6ab102456d9e6b;p=simgear.git

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

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 <cassert>
 #include <cstdlib>
 
+#include <stdio.h> // snprintf
 #include <zlib.h> // for gzXXX functions
 
 #include <simgear/misc/sg_path.hxx>
@@ -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");