ScummVM API documentation
voc.h
Go to the documentation of this file.
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
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 3 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 
33 #ifndef AUDIO_VOC_H
34 #define AUDIO_VOC_H
35 
36 #include "audio/audiostream.h"
37 
38 #include "common/list.h"
39 #include "common/scummsys.h"
40 #include "common/types.h"
41 
42 namespace Common {
43 class ReadStream;
44 class SeekableReadStream;
45 }
46 
47 namespace Audio {
48 
49 class AudioStream;
50 class SeekableAudioStream;
51 
52 
53 #include "common/pack-start.h" // START STRUCT PACKING
54 
55 struct VocFileHeader {
56  uint8 desc[20];
57  uint16 datablock_offset;
58  uint16 version;
59  uint16 id;
60 } PACKED_STRUCT;
61 
63  uint8 blocktype;
64  uint8 size[3];
65  uint8 sr;
66  uint8 pack;
67 } PACKED_STRUCT;
68 
69 #include "common/pack-end.h" // END STRUCT PACKING
70 
72 public:
73  VocStream(Common::SeekableReadStream *stream, bool isUnsigned, DisposeAfterUse::Flag disposeAfterUse);
74  virtual ~VocStream();
75 
76  int readBuffer(int16 *buffer, const int numSamples) override;
77 
78  bool isStereo() const override { return false; }
79 
80  int getRate() const override { return _rate; }
81 
82  bool endOfData() const override { return (_curBlock == _blocks.end()) && (_blockLeft == 0); }
83 
84  bool seek(const Timestamp &where) override;
85 
86  Timestamp getLength() const override { return _length; }
87 
88 protected:
89  void preProcess();
90 
91  Common::SeekableReadStream *const _stream;
92  const DisposeAfterUse::Flag _disposeAfterUse;
93 
94  const bool _isUnsigned;
95 
96  int _rate;
97  Timestamp _length;
98 
99  struct Block {
100  uint8 code;
101  uint32 length;
102 
103  union {
104  struct {
105  uint32 offset;
106  int rate;
107  int samples;
108  } sampleBlock;
109 
110  struct {
111  int count;
112  } loopBlock;
113  };
114  };
115 
117  BlockList _blocks;
118 
119  BlockList::const_iterator _curBlock;
120  uint32 _blockLeft;
121 
126  void updateBlockIfNeeded();
127 
128  // Do some internal buffering for systems with really slow slow disk i/o
129  enum {
136  kSampleBufferLength = 2048
137  };
138  byte _buffer[kSampleBufferLength];
139 
146  int fillBuffer(int maxSamples);
147 };
148 
159 extern int getSampleRateFromVOCRate(int vocSR);
160 
168 SeekableAudioStream *makeVOCStream(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO);
169 
170 } // End of namespace Audio
171 
172 #endif
Timestamp getLength() const override
Definition: voc.h:86
Definition: voc.h:71
Definition: timestamp.h:83
Definition: stream.h:745
Definition: audiostream.h:212
bool endOfData() const override
Definition: voc.h:82
SeekableAudioStream * makeVOCStream(Common::SeekableReadStream *stream, byte flags, DisposeAfterUse::Flag disposeAfterUse=DisposeAfterUse::NO)
Definition: voc.h:62
int getRate() const override
Definition: voc.h:80
int getSampleRateFromVOCRate(int vocSR)
Definition: algorithm.h:29
Definition: voc.h:55
Definition: voc.h:99
Definition: list_intern.h:48
bool isStereo() const override
Definition: voc.h:78
Definition: system.h:38