X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsounddecoder.cpp;h=38ae8fa15b77635e360ee50d313345eee6edb37b;hb=0e266d73f9aab89410c736e969eaa51ef914acf1;hp=138117f730a9210545b807a0338bd8887861fa1d;hpb=35b092aaa718dcb12933effd33324bda5d3b5cce;p=libs%2Fal.git diff --git a/source/sounddecoder.cpp b/source/sounddecoder.cpp index 138117f..38ae8fa 100644 --- a/source/sounddecoder.cpp +++ b/source/sounddecoder.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include "mp3decoder.h" #include "oggdecoder.h" #include "sounddecoder.h" @@ -29,14 +31,31 @@ SoundDecoder::~SoundDecoder() SoundDecoder *SoundDecoder::open_file(const string &fn) { RefPtr file = new IO::BufferedFile(fn); - SoundDecoder *decoder = new OggDecoder(*file); + SoundDecoder *decoder = open_io(*file); decoder->source = file.release(); return decoder; } SoundDecoder *SoundDecoder::open_io(IO::Seekable &io) { - return new OggDecoder(io); + char sig_buf[8]; + io.read(sig_buf, sizeof(sig_buf)); + string signature(sig_buf, sizeof(sig_buf)); + if(OggDecoder::detect(signature)) + return new OggDecoder(io); + else if(Mp3Decoder::detect(signature)) + return new Mp3Decoder(io); + else + { + string sig_hex; + for(unsigned i=0; i(sig_buf[i])); + } + throw unsupported_sound(sig_hex); + } } } // namespace AL