1 #include <msp/core/refptr.h>
2 #include <msp/io/file.h>
3 #include <msp/strings/format.h>
4 #include "mp3decoder.h"
5 #include "oggdecoder.h"
6 #include "sounddecoder.h"
13 unsupported_sound::unsupported_sound(const string &w):
18 SoundDecoder::SoundDecoder():
26 SoundDecoder::~SoundDecoder()
31 SoundDecoder *SoundDecoder::open_file(const string &fn)
33 RefPtr<IO::BufferedFile> file = new IO::BufferedFile(fn);
34 SoundDecoder *decoder = open_io(*file);
35 decoder->source = file.release();
39 SoundDecoder *SoundDecoder::open_io(IO::Seekable &io)
42 io.read(sig_buf, sizeof(sig_buf));
43 string signature(sig_buf, sizeof(sig_buf));
44 if(OggDecoder::detect(signature))
45 return new OggDecoder(io);
46 else if(Mp3Decoder::detect(signature))
47 return new Mp3Decoder(io);
51 for(unsigned i=0; i<sizeof(sig_buf); ++i)
55 sig_hex += Msp::format("%02X", static_cast<unsigned char>(sig_buf[i]));
57 throw unsupported_sound(sig_hex);