1 #include <msp/core/refptr.h>
2 #include <msp/io/file.h>
3 #include <msp/strings/format.h>
5 #include "mad/mp3decoder.h"
8 #include "vorbis/oggdecoder.h"
10 #include "sounddecoder.h"
17 unsupported_sound::unsupported_sound(const string &w):
22 SoundDecoder::SoundDecoder():
30 SoundDecoder::~SoundDecoder()
35 SoundDecoder *SoundDecoder::open_file(const string &fn)
37 RefPtr<IO::BufferedFile> file = new IO::BufferedFile(fn);
38 SoundDecoder *decoder = open_io(*file);
39 decoder->source = file.release();
43 SoundDecoder *SoundDecoder::open_io(IO::Seekable &io)
46 io.read(sig_buf, sizeof(sig_buf));
47 io.seek(0, IO::S_BEG);
48 string signature(sig_buf, sizeof(sig_buf));
51 if(OggDecoder::detect(signature))
52 return new OggDecoder(io);
56 if(Mp3Decoder::detect(signature))
57 return new Mp3Decoder(io);
61 for(unsigned i=0; i<sizeof(sig_buf); ++i)
65 sig_hex += Msp::format("%02X", static_cast<unsigned char>(sig_buf[i]));
67 throw unsupported_sound(sig_hex);