1 /* ScummVM - Graphic Adventure Engine
2 *
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.
6 *
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.
11 *
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.
16 *
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.
20 *
21 */
22
23 #ifdef ENABLE_EOB
24
25 #include "kyra/sound/sound_intern.h"
26 #include "kyra/resource/resource.h"
27 #include "kyra/sound/drivers/mlalf98.h"
28
29 #include "common/config-manager.h"
30
31 namespace Kyra {
32
SoundPC98_EoB(KyraEngine_v1 * vm,Audio::Mixer * mixer)33 SoundPC98_EoB::SoundPC98_EoB(KyraEngine_v1 *vm, Audio::Mixer *mixer) : Sound(vm, mixer),
34 _vm(vm), _driver(0), _currentResourceSet(-1), _sfxDelay(0), _ready(false) {
35 memset(_resInfo, 0, sizeof(_resInfo));
36 }
37
~SoundPC98_EoB()38 SoundPC98_EoB::~SoundPC98_EoB() {
39 delete _driver;
40
41 for (int i = 0; i < 3; i++)
42 initAudioResourceInfo(i, 0);
43 }
44
getMusicType() const45 Sound::kType SoundPC98_EoB::getMusicType() const {
46 return kPC98;
47 }
48
init()49 bool SoundPC98_EoB::init() {
50 _driver = new MLALF98(_mixer, MLALF98::kType9801_86);
51 _ready = true;
52 return true;
53 }
54
initAudioResourceInfo(int set,void * info)55 void SoundPC98_EoB::initAudioResourceInfo(int set, void *info) {
56 delete _resInfo[set];
57 _resInfo[set] = info ? new SoundResourceInfo_PC(*(SoundResourceInfo_PC*)info) : 0;
58 }
59
selectAudioResourceSet(int set)60 void SoundPC98_EoB::selectAudioResourceSet(int set) {
61 if (set == _currentResourceSet || !_ready)
62 return;
63
64 if (!_resInfo[set])
65 return;
66
67 _currentResourceSet = set;
68 }
69
loadSoundFile(uint file)70 void SoundPC98_EoB::loadSoundFile(uint file) {
71 if (!_ready)
72 return;
73
74 if (file >= _resInfo[_currentResourceSet]->fileListSize)
75 return;
76
77 Common::SeekableReadStream *s = _vm->resource()->createReadStream(_resInfo[_currentResourceSet]->fileList[file]);
78 _driver->loadMusicData(s);
79 delete s;
80 }
81
loadSfxFile(Common::String file)82 void SoundPC98_EoB::loadSfxFile(Common::String file) {
83 if (!_ready)
84 return;
85
86 Common::SeekableReadStream *s = _vm->resource()->createReadStream(file);
87 _driver->loadSoundEffectData(s);
88 delete s;
89 }
90
playTrack(uint8 track)91 void SoundPC98_EoB::playTrack(uint8 track) {
92 if (!_musicEnabled || !_ready)
93 return;
94
95 _driver->allChannelsOff();
96 loadSoundFile(track);
97 _driver->startMusic(0);
98 }
99
haltTrack()100 void SoundPC98_EoB::haltTrack() {
101 if (!_musicEnabled || !_ready)
102 return;
103 playTrack(0);
104 }
105
playSoundEffect(uint16 track,uint8)106 void SoundPC98_EoB::playSoundEffect(uint16 track, uint8) {
107 if (_currentResourceSet != kMusicIngame || !_sfxEnabled || !_ready || track >= 120 || (track != 28 && _sfxDelay > _vm->_system->getMillis()))
108 return;
109 _driver->startSoundEffect(track);
110 if (track == 28)
111 _sfxDelay = _vm->_system->getMillis() + 1440;
112 }
113
updateVolumeSettings()114 void SoundPC98_EoB::updateVolumeSettings() {
115 if (!_driver || !_ready)
116 return;
117
118 bool mute = false;
119 if (ConfMan.hasKey("mute"))
120 mute = ConfMan.getBool("mute");
121
122 _driver->setMusicVolume((mute ? 0 : ConfMan.getInt("music_volume")));
123 _driver->setSoundEffectVolume((mute ? 0 : ConfMan.getInt("sfx_volume")));
124 }
125
126 } // End of namespace Kyra
127
128 #endif
129