]> git.tdb.fi Git - libs/al.git/blobdiff - source/sounddecoder.h
Add dedicated exception classes for decoding sounds
[libs/al.git] / source / sounddecoder.h
index ad56646b30dc149c9bfe48ef3fb243f3d811121f..ee5b07d5f33abea2410dc95076f026c0586a1ffc 100644 (file)
@@ -1,13 +1,21 @@
-#ifndef MSP_AL_SOUND_H_
-#define MSP_AL_SOUND_H_
+#ifndef MSP_AL_SOUNDDECODER_H_
+#define MSP_AL_SOUNDDECODER_H_
 
 #include <string>
-#include <vorbis/vorbisfile.h>
+#include <msp/io/seekable.h>
 #include "format.h"
 
 namespace Msp {
 namespace AL {
 
+class unsupported_sound: public std::runtime_error
+{
+public:
+       unsupported_sound(const std::string &);
+       virtual ~unsupported_sound() throw() { }
+};
+
+
 /**
 This class facilitates loading sound files.  Currently only Ogg Vorbis is
 supported.
@@ -15,24 +23,22 @@ supported.
 class SoundDecoder
 {
 private:
-       OggVorbis_File ovfile;
+       IO::Seekable *source;
+protected:
        unsigned freq;
        unsigned size;
        Format format;
        bool eof_flag;
 
-public:
        SoundDecoder();
-       ~SoundDecoder();
-
-       void open_file(const std::string &);
-       void open_memory(const void *, unsigned);
-private:
-       void open_common();
 public:
-       void close();
-       void rewind();
-       unsigned read(char *, unsigned);
+       virtual ~SoundDecoder();
+
+       static SoundDecoder *open_file(const std::string &);
+       static SoundDecoder *open_io(IO::Seekable &);
+
+       virtual void rewind() = 0;
+       virtual unsigned read(char *, unsigned) = 0;
        bool eof() const { return eof_flag; }
 
        Format get_format() const { return format; }