1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  * WavStream
4  *
5  * Copyright 2010 Unavowed <unavowed@vexillium.org>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef WAV_STREAM_H
23 #define WAV_STREAM_H
24 
25 #include <audio_stream.h>
26 #include <input_stream.h>
27 
28 class WavStream: public AudioStream
29 {
30 private:
31    InputStream *in;
32    int32_t fram_rate;    /* in PCM frames per second */
33    uint32_t data_length; /* in PCM frames */
34    uint32_t data_left;   /* in PCM frames */
35    long data_offset;     /* in bytes from beginning of file */
36    uint8_t bytes;        /* bytes per sample */
37    int chans;            /* number of channels */
38    bool good;
39 
40 private:
41    void clear();
42    bool advance_to_chunk(const char *name, uint32_t *sizep);
43 
44 public:
45    WavStream();
46    ~WavStream();
47    bool open(InputStream *in);
48    bool open(const char *file_name);
49    void close();
50    long read(void *buffer, size_t frame_count);
51    bool seek(size_t frame_no);
52    int32_t frame_rate() const;
53    int channels() const;
54    int sample_size() const;
55 };
56 
57 #endif
58