Only set interface palette when painting backdrop. (This fixes movie palette.)
[scummvm-innocent.git] / sound / iff_sound.cpp
blob60a1486ed57b6f4e70ddcc5815d9e742c573eb7c
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.
21 * $URL$
22 * $Id$
26 #include "sound/iff_sound.h"
27 #include "sound/audiostream.h"
28 #include "sound/mixer.h"
29 #include "common/func.h"
31 namespace Audio {
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);
44 struct A8SVXLoader {
45 Voice8Header _header;
46 int8 *_data;
47 uint32 _dataSize;
49 void load(Common::ReadStream &input) {
50 Common::IFFParser parser(&input);
51 Common::Functor1Mem< Common::IFFChunk&, bool, A8SVXLoader > c(this, &A8SVXLoader::callback);
52 parser.parse(c);
55 bool callback(Common::IFFChunk &chunk) {
56 switch (chunk._type) {
57 case ID_VHDR:
58 _header.load(*chunk._stream);
59 break;
61 case ID_BODY:
62 _dataSize = chunk._size;
63 _data = (int8*)malloc(_dataSize);
64 assert(_data);
65 loadData(chunk._stream);
66 return true;
69 return false;
72 void loadData(Common::ReadStream *stream) {
73 switch (_header.compression) {
74 case 0:
75 stream->read(_data, _dataSize);
76 break;
78 case 1:
79 // implement other formats here
80 error("compressed IFF audio is not supported");
81 break;
88 AudioStream *make8SVXStream(Common::ReadStream &input, bool loop) {
89 A8SVXLoader loader;
90 loader.load(input);
92 uint32 loopStart = 0, loopEnd = 0, flags = 0;
93 if (loop) {
94 // the standard way to loop 8SVX audio implies use of the oneShotHiSamples and
95 // repeatHiSamples fields
96 loopStart = 0;
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);