From 8e12e7c9f65632342a8f370ea2de6b029cb564ec Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 6 Jun 2019 14:07:44 +0300 Subject: [PATCH] Make sound format support optional Since there are now two different decoders, it makes sense to allow selecting only one of them. --- Build | 29 ++++++++++++++++++++++++--- source/{ => mad}/mp3decoder.cpp | 0 source/{ => mad}/mp3decoder.h | 2 +- source/sounddecoder.cpp | 32 +++++++++++++++++++----------- source/{ => vorbis}/oggdecoder.cpp | 0 source/{ => vorbis}/oggdecoder.h | 2 +- 6 files changed, 48 insertions(+), 17 deletions(-) rename source/{ => mad}/mp3decoder.cpp (100%) rename source/{ => mad}/mp3decoder.h (96%) rename source/{ => vorbis}/oggdecoder.cpp (100%) rename source/{ => vorbis}/oggdecoder.h (95%) diff --git a/Build b/Build index 02ebe32..0f79322 100644 --- a/Build +++ b/Build @@ -3,17 +3,40 @@ package "mspal" version "0.10"; description "C++ wrapper for OpenAL"; - // TODO make these features - require "vorbisfile"; - require "mad"; require "openal"; require "sigc++-2.0"; require "mspcore"; require "mspdatafile"; + feature "libvorbis" "Include libvorbis support for decoding OGG files" + { + default "yes"; + }; + if_feature "libvorbis" + { + require "vorbisfile"; + }; + + feature "libmad" "Include libmad support for decoding MP3 files" + { + default "yes"; + }; + if_feature "libmad" + { + require "mad"; + }; + library "mspal" { source "source"; + if_feature "libvorbis" + { + source "source/vorbis"; + }; + if_feature "libmad" + { + source "source/mad"; + }; install true; install_map { diff --git a/source/mp3decoder.cpp b/source/mad/mp3decoder.cpp similarity index 100% rename from source/mp3decoder.cpp rename to source/mad/mp3decoder.cpp diff --git a/source/mp3decoder.h b/source/mad/mp3decoder.h similarity index 96% rename from source/mp3decoder.h rename to source/mad/mp3decoder.h index 01fba63..ce0c468 100644 --- a/source/mp3decoder.h +++ b/source/mad/mp3decoder.h @@ -2,7 +2,7 @@ #define MSP_AL_MP3DECODER_H_ #include -#include "sounddecoder.h" +#include namespace Msp { namespace AL { diff --git a/source/sounddecoder.cpp b/source/sounddecoder.cpp index e0a56d3..ed9de80 100644 --- a/source/sounddecoder.cpp +++ b/source/sounddecoder.cpp @@ -1,8 +1,12 @@ #include #include #include -#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(sig_buf[i])); - } - throw unsupported_sound(sig_hex); + if(i) + sig_hex += ' '; + sig_hex += Msp::format("%02X", static_cast(sig_buf[i])); } + throw unsupported_sound(sig_hex); } } // namespace AL diff --git a/source/oggdecoder.cpp b/source/vorbis/oggdecoder.cpp similarity index 100% rename from source/oggdecoder.cpp rename to source/vorbis/oggdecoder.cpp diff --git a/source/oggdecoder.h b/source/vorbis/oggdecoder.h similarity index 95% rename from source/oggdecoder.h rename to source/vorbis/oggdecoder.h index e194736..0d19d45 100644 --- a/source/oggdecoder.h +++ b/source/vorbis/oggdecoder.h @@ -2,7 +2,7 @@ #define MSP_AL_OGGDECODER_H_ #include -#include "sounddecoder.h" +#include namespace Msp { namespace AL { -- 2.43.0