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
30 #include "DataStream.h"
32 #ifdef HAS_VORBIS_SUPPORT
33 #include <vorbis/vorbisfile.h>
36 #define INIT_NO_ERROR_MSG 0
37 #define INIT_NEED_ERROR_MSG 1
39 // Abstract Sound Reader class
42 int samples
; // total count of sound samples
43 // one sample consists of
44 // channels * (is16bit ? 2 : 1) bytes
47 int samples_left
; // count of unread samples
48 int is16bit
; // 1 - if 16 bit file, 0 - otherwise
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
) {
76 virtual int init_reader() = 0; // initializes the sound reader
81 } // returns the total samples count
82 int get_samples_left()
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
97 stream
->Seek(0, GEM_STREAM_START
);
103 class CRawPCMReader
: public CSoundReader
{
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 );
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" );
122 class CWavPCMReader
: public CRawPCMReader
{
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()
135 #ifdef HAS_VORBIS_SUPPORT
136 class COGGReader
: public CSoundReader
{
138 OggVorbis_File OggStream
;
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()
154 virtual int read_samples(short* buffer
, int count
);
156 #endif //HAS_VORBIS_SUPPORT
159 class CACMReader
: public CSoundReader
{
161 int levels
, subblocks
;
163 int* block
, * values
;
165 CValueUnpacker
* unpacker
; // ACM-stream unpacker
166 CSubbandDecoder
* decoder
; // IP's subband decoder
168 int make_new_samples();
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()
189 virtual int init_reader();
190 virtual const char* get_file_type()
194 virtual int read_samples(short* buffer
, int count
);
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) */
224 const unsigned char RIFF_4cc
[] = {
227 const unsigned char WAVE_4cc
[] = {
230 const unsigned char fmt_4cc
[] = {
233 const unsigned char fact_4cc
[] = {
236 const unsigned char data_4cc
[] = {
241 // File open routine.
242 CSoundReader
* CreateSoundReader(DataStream
* stream
, int open_mode
,
243 int samples
, bool autoFree
= true);
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