]> git.tdb.fi Git - libs/al.git/blob - source/sounddecoder.h
Improve documentation of SoundDecoder
[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 Base class for sound decoders.
21 */
22 class SoundDecoder
23 {
24 private:
25         IO::Seekable *source;
26 protected:
27         unsigned freq;
28         unsigned size;
29         Format format;
30         bool eof_flag;
31
32         SoundDecoder();
33 public:
34         virtual ~SoundDecoder();
35
36         /** Opens a file and creates a decoder of an appropriate type for it. */
37         static SoundDecoder *open_file(const std::string &);
38
39         /** Creates a decoder for an already-opened audio file. */
40         static SoundDecoder *open_io(IO::Seekable &);
41
42         /** Restarts decoding from the beginning of the file. */
43         virtual void rewind() { seek(0); }
44
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;
48
49         /** Reads decoded sound data.  Length is specified in bytes. */
50         virtual unsigned read(char *, unsigned) = 0;
51
52         bool eof() const { return eof_flag; }
53
54         Format get_format() const { return format; }
55         unsigned get_frequency() const { return freq; }
56
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; }
60 };
61
62 } // namespace AL
63 } // namespace Msp
64
65 #endif