1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "sound/iff_sound.h"
27 #include "sound/audiostream.h"
28 #include "sound/mixer.h"
29 #include "common/func.h"
33 void Voice8Header::load(Common::ReadStream
&stream
) {
34 stream
.read(this, sizeof(Voice8Header
));
35 oneShotHiSamples
= FROM_BE_32(oneShotHiSamples
);
36 repeatHiSamples
= FROM_BE_32(repeatHiSamples
);
37 samplesPerHiCycle
= FROM_BE_32(samplesPerHiCycle
);
38 samplesPerSec
= FROM_BE_16(samplesPerSec
);
39 volume
= FROM_BE_32(volume
);
49 void load(Common::ReadStream
&input
) {
50 Common::IFFParser
parser(&input
);
51 Common::Functor1Mem
< Common::IFFChunk
&, bool, A8SVXLoader
> c(this, &A8SVXLoader::callback
);
55 bool callback(Common::IFFChunk
&chunk
) {
56 switch (chunk
._type
) {
58 _header
.load(*chunk
._stream
);
62 _dataSize
= chunk
._size
;
63 _data
= (int8
*)malloc(_dataSize
);
65 loadData(chunk
._stream
);
72 void loadData(Common::ReadStream
*stream
) {
73 switch (_header
.compression
) {
75 stream
->read(_data
, _dataSize
);
79 // implement other formats here
80 error("compressed IFF audio is not supported");
88 AudioStream
*make8SVXStream(Common::ReadStream
&input
, bool loop
) {
92 uint32 loopStart
= 0, loopEnd
= 0, flags
= 0;
94 // the standard way to loop 8SVX audio implies use of the oneShotHiSamples and
95 // repeatHiSamples fields
97 loopEnd
= loader
._header
.oneShotHiSamples
+ loader
._header
.repeatHiSamples
;
98 flags
|= Audio::Mixer::FLAG_LOOP
;
101 flags
|= Audio::Mixer::FLAG_AUTOFREE
;
103 return Audio::makeLinearInputStream((byte
*)loader
._data
, loader
._dataSize
, loader
._header
.samplesPerSec
, flags
, loopStart
, loopEnd
);