]> git.tdb.fi Git - libs/al.git/blob - source/sounddecoder.h
Add dedicated exception classes for decoding sounds
[libs/al.git] / source / sounddecoder.h
1 #ifndef MSP_AL_SOUNDDECODER_H_
2 #define MSP_AL_SOUNDDECODER_H_
3
4 #include <string>
5 #include <msp/io/seekable.h>
6 #include "format.h"
7
8 namespace Msp {
9 namespace AL {
10
11 class unsupported_sound: public std::runtime_error
12 {
13 public:
14         unsupported_sound(const std::string &);
15         virtual ~unsupported_sound() throw() { }
16 };
17
18
19 /**
20 This class facilitates loading sound files.  Currently only Ogg Vorbis is
21 supported.
22 */
23 class SoundDecoder
24 {
25 private:
26         IO::Seekable *source;
27 protected:
28         unsigned freq;
29         unsigned size;
30         Format format;
31         bool eof_flag;
32
33         SoundDecoder();
34 public:
35         virtual ~SoundDecoder();
36
37         static SoundDecoder *open_file(const std::string &);
38         static SoundDecoder *open_io(IO::Seekable &);
39
40         virtual void rewind() = 0;
41         virtual unsigned read(char *, unsigned) = 0;
42         bool eof() const { return eof_flag; }
43
44         Format get_format() const { return format; }
45         unsigned get_frequency() const { return freq; }
46         unsigned get_size() const { return size; }
47 };
48
49 } // namespace AL
50 } // namespace Msp
51
52 #endif