Switch to using -I to find includes, rather than relative paths.
[gemrb.git] / gemrb / plugins / ACMImporter / readers.h
blob7f156c4de55d9894dc1cbaf4806655762d70b413
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef _ACM_LAB_SOUND_READER_H
22 #define _ACM_LAB_SOUND_READER_H
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include "unpacker.h"
28 #include "decoder.h"
29 #include "general.h"
30 #include "DataStream.h"
32 #ifdef HAS_VORBIS_SUPPORT
33 #include <vorbis/vorbisfile.h>
34 #endif
36 #define INIT_NO_ERROR_MSG 0
37 #define INIT_NEED_ERROR_MSG 1
39 // Abstract Sound Reader class
40 class CSoundReader {
41 protected:
42 int samples; // total count of sound samples
43 // one sample consists of
44 // channels * (is16bit ? 2 : 1) bytes
45 int channels;
46 int samplerate;
47 int samples_left; // count of unread samples
48 int is16bit; // 1 - if 16 bit file, 0 - otherwise
49 DataStream* stream;
50 bool autoFree;
52 public:
53 CSoundReader(DataStream* stream, bool autoFree = true)
55 : samples( 0 ), channels( 0 ), samples_left( 0 ), is16bit( 1 )
57 this->stream = stream;
58 this->autoFree = autoFree;
61 virtual ~CSoundReader()
63 if (stream && autoFree) {
64 delete( stream );
68 int get_channels()
70 return channels;
72 int get_samplerate()
74 return samplerate;
76 virtual int init_reader() = 0; // initializes the sound reader
78 int get_length()
80 return samples;
81 } // returns the total samples count
82 int get_samples_left()
84 return samples_left;
86 int get_bits()
88 return ( is16bit ) ? 16 : 8;
91 virtual const char* get_file_type() = 0;
93 virtual int read_samples(short* buffer, int count) = 0; // returns actual count of read samples
94 // virtual short read_one_sample(); // returns next sound sample
95 void rewind()
97 stream->Seek(0, GEM_STREAM_START );
98 init_reader() ;
102 // RAW file reader
103 class CRawPCMReader : public CSoundReader {
104 public:
105 CRawPCMReader(DataStream* stream, int bits, int len, bool autoFree = true)//int fhandle, int bits, int len)
107 : CSoundReader( stream, autoFree )
109 is16bit = ( bits == 16 );
110 samples = len;
113 virtual int init_reader();
114 virtual int read_samples(short* buffer, int count);
115 virtual const char* get_file_type()
117 return ( is16bit ? "RAW16" : "RAW8" );
121 // WAV files
122 class CWavPCMReader : public CRawPCMReader {
123 public:
124 CWavPCMReader(DataStream* stream, int len, bool autoFree = true)
125 : CRawPCMReader( stream, 16, len, autoFree )
128 virtual int init_reader();
129 virtual const char* get_file_type()
131 return "WAV";
135 #ifdef HAS_VORBIS_SUPPORT
136 class COGGReader : public CSoundReader {
137 private:
138 OggVorbis_File OggStream;
139 public:
140 COGGReader(DataStream* stream, bool autoFree = true)
141 : CSoundReader( stream, autoFree)
143 memset(&OggStream, 0, sizeof(OggStream) );
145 virtual ~COGGReader()
147 ov_clear(&OggStream);
149 virtual int init_reader();
150 virtual const char* get_file_type()
152 return "OGG";
154 virtual int read_samples(short* buffer, int count);
156 #endif //HAS_VORBIS_SUPPORT
158 // IP's ACM files
159 class CACMReader : public CSoundReader {
160 private:
161 int levels, subblocks;
162 int block_size;
163 int* block, * values;
164 int samples_ready;
165 CValueUnpacker* unpacker; // ACM-stream unpacker
166 CSubbandDecoder* decoder; // IP's subband decoder
168 int make_new_samples();
169 public:
170 CACMReader(DataStream* stream, bool autoFree = true)
172 : CSoundReader( stream, autoFree ), block( NULL ), values( NULL ),
173 samples_ready( 0 ), unpacker( NULL ), decoder( NULL )
176 virtual ~CACMReader()
178 if (block) {
179 free(block);
181 if (unpacker) {
182 delete unpacker;
184 if (decoder) {
185 delete decoder;
189 virtual int init_reader();
190 virtual const char* get_file_type()
192 return "ACM";
194 virtual int read_samples(short* buffer, int count);
196 int get_levels()
198 return levels;
200 int get_subblocks()
202 return subblocks;
207 // WAVEFORMATEX structure (from MS SDK)
208 struct cWAVEFORMATEX {
209 unsigned short wFormatTag; /* format type */
210 unsigned short nChannels; /* number of channels (i.e. mono, stereo...) */
211 unsigned int nSamplesPerSec; /* sample rate */
212 unsigned int nAvgBytesPerSec; /* for buffer estimation */
213 unsigned short nBlockAlign; /* block size of data */
214 unsigned short wBitsPerSample; /* number of bits per sample of mono data */
215 unsigned short cbSize; /* the count in bytes of the size of */
216 /* extra information (after cbSize) */
219 struct RIFF_CHUNK {
220 unsigned int fourcc;
221 unsigned int length;
224 const unsigned char RIFF_4cc[] = {
225 'R', 'I', 'F', 'F'
227 const unsigned char WAVE_4cc[] = {
228 'W', 'A', 'V', 'E'
230 const unsigned char fmt_4cc[] = {
231 'f', 'm', 't', ' '
233 const unsigned char fact_4cc[] = {
234 'f', 'a', 'c', 't'
236 const unsigned char data_4cc[] = {
237 'd', 'a', 't', 'a'
241 // File open routine.
242 CSoundReader* CreateSoundReader(DataStream* stream, int open_mode,
243 int samples, bool autoFree = true);
245 // Open modes:
246 #define SND_READER_AUTO 0
247 #define SND_READER_RAW8 1
248 #define SND_READER_RAW16 2
249 #define SND_READER_WAV 3
250 #define SND_READER_ACM 4
251 #define SND_READER_OGG 5
253 #endif