1 #ifndef MSP_AL_SOUNDDECODER_H_
2 #define MSP_AL_SOUNDDECODER_H_
5 #include <msp/io/seekable.h>
11 class unsupported_sound: public std::runtime_error
14 unsupported_sound(const std::string &);
15 virtual ~unsupported_sound() throw() { }
20 Base class for sound decoders.
34 virtual ~SoundDecoder();
36 /** Opens a file and creates a decoder of an appropriate type for it. */
37 static SoundDecoder *open_file(const std::string &);
39 /** Creates a decoder for an already-opened audio file. */
40 static SoundDecoder *open_io(IO::Seekable &);
42 /** Restarts decoding from the beginning of the file. */
43 virtual void rewind() { seek(0); }
45 /** Sets decoding position expressed in PCM bytes. This may involve seeking
46 to the beginning and skipping until the desired position is reached.*/
47 virtual void seek(unsigned) = 0;
49 /** Reads decoded sound data. Length is specified in bytes. */
50 virtual unsigned read(char *, unsigned) = 0;
52 bool eof() const { return eof_flag; }
54 Format get_format() const { return format; }
55 unsigned get_frequency() const { return freq; }
57 /** Returns the total length of the sound data in bytes. Some decoders may
58 not be able to provide this information. */
59 unsigned get_size() const { return size; }