]> git.tdb.fi Git - libs/al.git/blobdiff - source/sounddecoder.cpp
Make sound format support optional
[libs/al.git] / source / sounddecoder.cpp
index e0a56d3a4fc1513d21e6b99eada7f26c262903db..ed9de800ffef84345faf133260080a9aa9eb6b96 100644 (file)
@@ -1,8 +1,12 @@
 #include <msp/core/refptr.h>
 #include <msp/io/file.h>
 #include <msp/strings/format.h>
-#include "mp3decoder.h"
-#include "oggdecoder.h"
+#ifdef WITH_LIBMAD
+#include "mad/mp3decoder.h"
+#endif
+#ifdef WITH_LIBVORBIS
+#include "vorbis/oggdecoder.h"
+#endif
 #include "sounddecoder.h"
 
 using namespace std;
@@ -42,21 +46,25 @@ SoundDecoder *SoundDecoder::open_io(IO::Seekable &io)
        io.read(sig_buf, sizeof(sig_buf));
        io.seek(0, IO::S_BEG);
        string signature(sig_buf, sizeof(sig_buf));
+
+#ifdef WITH_LIBVORBIS
        if(OggDecoder::detect(signature))
                return new OggDecoder(io);
-       else if(Mp3Decoder::detect(signature))
+#endif
+
+#ifdef WITH_LIBMAD
+       if(Mp3Decoder::detect(signature))
                return new Mp3Decoder(io);
-       else
+#endif
+
+       string sig_hex;
+       for(unsigned i=0; i<sizeof(sig_buf); ++i)
        {
-               string sig_hex;
-               for(unsigned i=0; i<sizeof(sig_buf); ++i)
-               {
-                       if(i)
-                               sig_hex += ' ';
-                       sig_hex += Msp::format("%02X", static_cast<unsigned char>(sig_buf[i]));
-               }
-               throw unsupported_sound(sig_hex);
+               if(i)
+                       sig_hex += ' ';
+               sig_hex += Msp::format("%02X", static_cast<unsigned char>(sig_buf[i]));
        }
+       throw unsupported_sound(sig_hex);
 }
 
 } // namespace AL