]> git.tdb.fi Git - libs/al.git/blob - source/sounddecoder.h
Implement seeking in sound decoders
[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() { seek(0); }
41         virtual void seek(unsigned) = 0;
42         virtual unsigned read(char *, unsigned) = 0;
43         bool eof() const { return eof_flag; }
44
45         Format get_format() const { return format; }
46         unsigned get_frequency() const { return freq; }
47         unsigned get_size() const { return size; }
48 };
49
50 } // namespace AL
51 } // namespace Msp
52
53 #endif