aboutsummaryrefslogtreecommitdiff
path: root/engines/illusions/resources/soundresource.cpp
blob: 030a4cc3a9373b4ccd9034406b77d958f419ccd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "illusions/illusions.h"
#include "illusions/resources/soundresource.h"
#include "illusions/sound.h"

namespace Illusions {

// SoundGroupResourceLoader

void SoundGroupResourceLoader::load(Resource *resource) {
	SoundGroupInstance *soundGroupInstance = new SoundGroupInstance(_vm);
	soundGroupInstance->load(resource);
	resource->_instance = soundGroupInstance;
}

bool SoundGroupResourceLoader::isFlag(int flag) {
	return
		flag == kRlfLoadFile/* ||
		flag == kRlfFreeDataAfterLoad*/;
}

// SoundEffect

void SoundEffect::load(Common::SeekableReadStream &stream) {
	_soundEffectId = stream.readUint32LE();
	_looping = stream.readUint16LE() != 0;
	_field6 = stream.readUint16LE();
	_volume = stream.readUint16LE();
	_frequency = stream.readUint16LE();
	stream.skip(32 + 4); // Skip name
	debug(1, "SoundEffect::load() _soundEffectId: %08X, _looping: %d, _field6: %d, _volume: %d, _frequency: %d",
		_soundEffectId, _looping, _field6, _volume, _frequency);
}

// SoundGroupResource

SoundGroupResource::SoundGroupResource()
	: _soundEffects(0) {
}

SoundGroupResource::~SoundGroupResource() {
	delete[] _soundEffects;
}

void SoundGroupResource::load(byte *data, uint32 dataSize) {
	Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO);

	stream.skip(4);
	_soundEffectsCount = stream.readUint16LE();
	stream.skip(2);
	uint32 soundEffectsOffs = stream.readUint32LE();
	debug(1, "_soundEffectsCount: %d; soundEffectsOffs: %08X", _soundEffectsCount, soundEffectsOffs);
	_soundEffects = new SoundEffect[_soundEffectsCount];
	stream.seek(soundEffectsOffs);
	for (uint i = 0; i < _soundEffectsCount; ++i) {
		_soundEffects[i].load(stream);
	}

}

// SoundGroupInstance

SoundGroupInstance::SoundGroupInstance(IllusionsEngine *vm)
	: _vm(vm), _soundGroupResource(0) {
}

void SoundGroupInstance::load(Resource *resource) {
	_soundGroupResource = new SoundGroupResource();
	_soundGroupResource->load(resource->_data, resource->_dataSize);
	for (uint i = 0; i < _soundGroupResource->_soundEffectsCount; ++i) {
		SoundEffect *soundEffect = &_soundGroupResource->_soundEffects[i];
		_vm->_soundMan->loadSound(soundEffect->_soundEffectId, resource->_resId, soundEffect->_looping);
	}
	_resId = resource->_resId;
}

void SoundGroupInstance::unload() {
	_vm->_soundMan->unloadSounds(_resId);
	delete _soundGroupResource;
}

} // End of namespace Illusions