2011-12-07 15:06:34 +00:00
|
|
|
/* 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.
|
2014-02-18 01:34:19 +00:00
|
|
|
*
|
2011-12-07 15:06:34 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:19 +00:00
|
|
|
*
|
2011-12-07 15:06:34 +00:00
|
|
|
* 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 "audio/decoders/raw.h"
|
|
|
|
#include "common/config-manager.h"
|
2012-05-31 04:16:10 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
|
|
|
|
#include "dreamweb/dreamweb.h"
|
|
|
|
#include "dreamweb/sound.h"
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2011-12-28 13:07:17 +00:00
|
|
|
namespace DreamWeb {
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
DreamWebSound::DreamWebSound(DreamWebEngine *vm) : _vm(vm) {
|
|
|
|
_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
|
|
|
|
|
|
|
_currentSample = 0xff;
|
2012-06-05 00:00:01 +00:00
|
|
|
_channel0Playing = 255;
|
2012-05-31 04:16:10 +00:00
|
|
|
_channel0Repeat = 0;
|
2012-06-02 21:28:34 +00:00
|
|
|
_channel0NewSound = false;
|
2012-05-31 04:16:10 +00:00
|
|
|
_channel1Playing = 255;
|
2012-06-05 00:00:01 +00:00
|
|
|
_channel1NewSound = false;
|
2012-05-31 04:16:10 +00:00
|
|
|
|
|
|
|
_volume = 0;
|
|
|
|
_volumeTo = 0;
|
|
|
|
_volumeDirection = 0;
|
|
|
|
_volumeCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DreamWebSound::~DreamWebSound() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DreamWebSound::loadSpeech(byte type1, int idx1, byte type2, int idx2) {
|
2011-12-07 15:06:34 +00:00
|
|
|
cancelCh1();
|
2011-12-12 11:39:06 +00:00
|
|
|
|
|
|
|
Common::String name = Common::String::format("%c%02d%c%04d.RAW", type1, idx1, type2, idx2);
|
2012-05-31 04:16:10 +00:00
|
|
|
debug(2, "loadSpeech() name:%s", name.c_str());
|
|
|
|
return loadSpeech(name);
|
|
|
|
}
|
2011-12-12 11:39:06 +00:00
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::volumeChange(uint8 value, int8 direction) {
|
|
|
|
_volumeTo = value;
|
|
|
|
_volumeDirection = direction;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::volumeAdjust() {
|
2011-12-28 01:31:24 +00:00
|
|
|
if (_volumeDirection == 0)
|
2011-12-07 15:06:34 +00:00
|
|
|
return;
|
2011-12-28 01:31:24 +00:00
|
|
|
if (_volume != _volumeTo) {
|
|
|
|
_volumeCount += 64;
|
2011-12-07 15:06:34 +00:00
|
|
|
// Only modify the volume every 256/64 = 4th time around
|
2011-12-28 01:31:24 +00:00
|
|
|
if (_volumeCount == 0)
|
|
|
|
_volume += _volumeDirection;
|
2011-12-07 15:06:34 +00:00
|
|
|
} else {
|
2011-12-28 01:31:24 +00:00
|
|
|
_volumeDirection = 0;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::playChannel0(uint8 index, uint8 repeat) {
|
2012-05-22 15:31:23 +00:00
|
|
|
debug(1, "playChannel0(index:%d, repeat:%d)", index, repeat);
|
2012-06-02 21:28:34 +00:00
|
|
|
|
2011-12-27 23:49:35 +00:00
|
|
|
_channel0Playing = index;
|
|
|
|
_channel0Repeat = repeat;
|
2012-06-05 00:00:01 +00:00
|
|
|
_channel0NewSound = true;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::playChannel1(uint8 index) {
|
2012-06-02 06:03:40 +00:00
|
|
|
debug(1, "playChannel1(index:%d)", index);
|
2011-12-27 23:49:35 +00:00
|
|
|
if (_channel1Playing == 7)
|
2011-12-07 15:06:34 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-27 23:49:35 +00:00
|
|
|
_channel1Playing = index;
|
2012-06-05 00:00:01 +00:00
|
|
|
_channel1NewSound = true;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::cancelCh0() {
|
2012-05-22 15:31:23 +00:00
|
|
|
debug(1, "cancelCh0()");
|
2011-12-27 23:49:35 +00:00
|
|
|
_channel0Playing = 255;
|
2012-05-30 02:53:52 +00:00
|
|
|
_channel0Repeat = 0;
|
2011-12-28 13:07:17 +00:00
|
|
|
stopSound(0);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::cancelCh1() {
|
2012-06-02 06:03:40 +00:00
|
|
|
debug(1, "cancelCh1()");
|
2011-12-27 23:49:35 +00:00
|
|
|
_channel1Playing = 255;
|
2011-12-28 13:07:17 +00:00
|
|
|
stopSound(1);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::loadRoomsSample(uint8 sample) {
|
|
|
|
debug(1, "loadRoomsSample(sample:%d)", sample);
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2011-12-27 04:59:56 +00:00
|
|
|
if (sample == 255 || _currentSample == sample)
|
2011-12-07 15:06:34 +00:00
|
|
|
return; // loaded already
|
|
|
|
|
|
|
|
assert(sample < 100);
|
2012-02-24 05:29:01 +00:00
|
|
|
Common::String sampleSuffix = Common::String::format("V%02d", sample);
|
2011-12-27 04:59:56 +00:00
|
|
|
_currentSample = sample;
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2011-12-27 23:49:35 +00:00
|
|
|
uint8 ch0 = _channel0Playing;
|
2011-12-07 15:06:34 +00:00
|
|
|
if (ch0 >= 12 && ch0 != 255)
|
|
|
|
cancelCh0();
|
2011-12-27 23:49:35 +00:00
|
|
|
uint8 ch1 = _channel1Playing;
|
2011-12-07 15:06:34 +00:00
|
|
|
if (ch1 >= 12)
|
|
|
|
cancelCh1();
|
2012-02-24 05:29:01 +00:00
|
|
|
loadSounds(1, sampleSuffix.c_str());
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::playSound(uint8 channel, uint8 id, uint8 loops) {
|
2012-06-02 06:03:40 +00:00
|
|
|
debug(1, "playSound(channel:%u, id:%u, loops:%u)", channel, id, loops);
|
2011-12-07 15:06:34 +00:00
|
|
|
|
|
|
|
int bank = 0;
|
|
|
|
bool speech = false;
|
|
|
|
Audio::Mixer::SoundType type = channel == 0?
|
|
|
|
Audio::Mixer::kMusicSoundType: Audio::Mixer::kSFXSoundType;
|
|
|
|
|
|
|
|
if (id >= 12) {
|
|
|
|
id -= 12;
|
|
|
|
bank = 1;
|
|
|
|
if (id == 50) {
|
|
|
|
speech = true;
|
|
|
|
type = Audio::Mixer::kSpeechSoundType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const SoundData &data = _soundData[bank];
|
|
|
|
|
|
|
|
Audio::SeekableAudioStream *raw;
|
|
|
|
if (!speech) {
|
|
|
|
if (id >= data.samples.size() || data.samples[id].size == 0) {
|
|
|
|
warning("invalid sample #%u played", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Sample &sample = data.samples[id];
|
|
|
|
uint8 *buffer = (uint8 *)malloc(sample.size);
|
|
|
|
if (!buffer)
|
|
|
|
error("out of memory: cannot allocate memory for sound(%u bytes)", sample.size);
|
|
|
|
memcpy(buffer, data.data.begin() + sample.offset, sample.size);
|
|
|
|
|
2012-06-02 06:03:40 +00:00
|
|
|
raw = Audio::makeRawStream(buffer, sample.size, 22050, Audio::FLAG_UNSIGNED);
|
2011-12-07 15:06:34 +00:00
|
|
|
} else {
|
|
|
|
uint8 *buffer = (uint8 *)malloc(_speechData.size());
|
|
|
|
if (!buffer)
|
|
|
|
error("out of memory: cannot allocate memory for sound(%u bytes)", _speechData.size());
|
|
|
|
memcpy(buffer, _speechData.begin(), _speechData.size());
|
2012-06-02 06:03:40 +00:00
|
|
|
raw = Audio::makeRawStream(buffer, _speechData.size(), 22050, Audio::FLAG_UNSIGNED);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Audio::AudioStream *stream;
|
|
|
|
if (loops > 1) {
|
2012-06-02 06:03:40 +00:00
|
|
|
stream = new Audio::LoopingAudioStream(raw, (loops < 255) ? loops : 0);
|
2011-12-07 15:06:34 +00:00
|
|
|
} else
|
|
|
|
stream = raw;
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
if (_vm->_mixer->isSoundHandleActive(_channelHandle[channel]))
|
|
|
|
_vm->_mixer->stopHandle(_channelHandle[channel]);
|
|
|
|
_vm->_mixer->playStream(type, &_channelHandle[channel], stream);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::stopSound(uint8 channel) {
|
2011-12-07 15:06:34 +00:00
|
|
|
debug(1, "stopSound(%u)", channel);
|
|
|
|
assert(channel == 0 || channel == 1);
|
2012-05-31 04:16:10 +00:00
|
|
|
_vm->_mixer->stopHandle(_channelHandle[channel]);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
bool DreamWebSound::loadSpeech(const Common::String &filename) {
|
|
|
|
if (!_vm->hasSpeech())
|
2011-12-07 15:06:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Common::File file;
|
2012-05-31 04:16:10 +00:00
|
|
|
if (!file.open(_vm->getSpeechDirName() + "/" + filename))
|
2011-12-07 15:06:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
debug(1, "loadSpeech(%s)", filename.c_str());
|
|
|
|
|
|
|
|
uint size = file.size();
|
|
|
|
_speechData.resize(size);
|
|
|
|
file.read(_speechData.begin(), size);
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::soundHandler() {
|
|
|
|
_vm->_subtitles = ConfMan.getBool("subtitles");
|
2011-12-28 13:07:17 +00:00
|
|
|
volumeAdjust();
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2011-12-28 13:07:17 +00:00
|
|
|
uint volume = _volume;
|
2011-12-07 15:06:34 +00:00
|
|
|
//.vol file loaded into soundbuf:0x4000
|
|
|
|
//volume table at (volume * 0x100 + 0x3f00)
|
|
|
|
//volume value could be from 1 to 7
|
|
|
|
//1 - 0x10-0xff
|
|
|
|
//2 - 0x1f-0xdf
|
|
|
|
//3 - 0x2f-0xd0
|
|
|
|
//4 - 0x3e-0xc1
|
|
|
|
//5 - 0x4d-0xb2
|
|
|
|
//6 - 0x5d-0xa2
|
|
|
|
//7 - 0x6f-0x91
|
|
|
|
if (volume >= 8)
|
|
|
|
volume = 7;
|
|
|
|
volume = (8 - volume) * Audio::Mixer::kMaxChannelVolume / 8;
|
2012-05-31 04:16:10 +00:00
|
|
|
_vm->_mixer->setChannelVolume(_channelHandle[0], volume);
|
2011-12-07 15:06:34 +00:00
|
|
|
|
2012-06-05 00:00:01 +00:00
|
|
|
if (_channel0NewSound) {
|
2012-06-02 21:28:34 +00:00
|
|
|
_channel0NewSound = false;
|
2012-06-05 00:00:01 +00:00
|
|
|
if (_channel0Playing != 255) {
|
|
|
|
playSound(0, _channel0Playing, _channel0Repeat);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-05 00:00:01 +00:00
|
|
|
if (_channel1NewSound) {
|
|
|
|
_channel1NewSound = false;
|
|
|
|
if (_channel1Playing != 255) {
|
|
|
|
playSound(1, _channel1Playing, 1);
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-02 06:03:40 +00:00
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
if (!_vm->_mixer->isSoundHandleActive(_channelHandle[0])) {
|
2011-12-28 13:07:17 +00:00
|
|
|
_channel0Playing = 255;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
2012-05-31 04:16:10 +00:00
|
|
|
if (!_vm->_mixer->isSoundHandleActive(_channelHandle[1])) {
|
2011-12-28 13:07:17 +00:00
|
|
|
_channel1Playing = 255;
|
2011-12-07 15:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 04:16:10 +00:00
|
|
|
void DreamWebSound::loadSounds(uint bank, const Common::String &suffix) {
|
|
|
|
Common::String filename = _vm->getDatafilePrefix() + suffix;
|
2011-12-07 15:06:34 +00:00
|
|
|
debug(1, "loadSounds(%u, %s)", bank, filename.c_str());
|
|
|
|
Common::File file;
|
|
|
|
if (!file.open(filename)) {
|
|
|
|
warning("cannot open %s", filename.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-02 06:03:40 +00:00
|
|
|
uint8 header[96];
|
2011-12-07 15:06:34 +00:00
|
|
|
file.read(header, sizeof(header));
|
2012-06-02 06:03:40 +00:00
|
|
|
uint tablesize = READ_LE_UINT16(header + 50);
|
2011-12-07 15:06:34 +00:00
|
|
|
debug(1, "table size = %u", tablesize);
|
|
|
|
|
|
|
|
SoundData &soundData = _soundData[bank];
|
|
|
|
soundData.samples.resize(tablesize / 6);
|
|
|
|
uint total = 0;
|
2011-12-08 09:02:51 +00:00
|
|
|
for (uint i = 0; i < tablesize / 6; ++i) {
|
2011-12-07 15:06:34 +00:00
|
|
|
uint8 entry[6];
|
|
|
|
Sample &sample = soundData.samples[i];
|
|
|
|
file.read(entry, sizeof(entry));
|
2012-06-02 06:03:40 +00:00
|
|
|
sample.offset = entry[0] * 16384 + READ_LE_UINT16(entry + 1);
|
|
|
|
sample.size = READ_LE_UINT16(entry + 3) * 2048;
|
2011-12-07 15:06:34 +00:00
|
|
|
total += sample.size;
|
|
|
|
debug(1, "offset: %08x, size: %u", sample.offset, sample.size);
|
|
|
|
}
|
|
|
|
soundData.data.resize(total);
|
|
|
|
file.read(soundData.data.begin(), total);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace DreamWeb
|