-#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.
+Base class for sound decoders.
*/
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();
+
+ /** Opens a file and creates a decoder of an appropriate type for it. */
+ static SoundDecoder *open_file(const std::string &);
+
+ /** Creates a decoder for an already-opened audio file. */
+ static SoundDecoder *open_io(IO::Seekable &);
+
+ /** Restarts decoding from the beginning of the file. */
+ virtual void rewind() { seek(0); }
+
+ /** Sets decoding position expressed in PCM bytes. This may involve seeking
+ to the beginning and skipping until the desired position is reached.*/
+ virtual void seek(unsigned) = 0;
+
+ /** Reads decoded sound data. Length is specified in bytes. */
+ virtual unsigned read(char *, unsigned) = 0;
+
bool eof() const { return eof_flag; }
Format get_format() const { return format; }
unsigned get_frequency() const { return freq; }
+
+ /** Returns the total length of the sound data in bytes. Some decoders may
+ not be able to provide this information. */
unsigned get_size() const { return size; }
};