aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb/sound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/dreamweb/sound.cpp')
-rw-r--r--engines/dreamweb/sound.cpp161
1 files changed, 81 insertions, 80 deletions
diff --git a/engines/dreamweb/sound.cpp b/engines/dreamweb/sound.cpp
index b51527a8cd..570f76f2f9 100644
--- a/engines/dreamweb/sound.cpp
+++ b/engines/dreamweb/sound.cpp
@@ -20,28 +20,51 @@
*
*/
-#include "dreamweb/dreamweb.h"
-
-#include "audio/mixer.h"
#include "audio/decoders/raw.h"
-
#include "common/config-manager.h"
+#include "common/debug.h"
+#include "common/file.h"
+
+#include "dreamweb/dreamweb.h"
+#include "dreamweb/sound.h"
namespace DreamWeb {
-bool DreamWebEngine::loadSpeech(byte type1, int idx1, byte type2, int idx2) {
+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;
+ _channel0Playing = 255;
+ _channel0Repeat = 0;
+ _channel0NewSound = false;
+ _channel1Playing = 255;
+ _channel1NewSound = false;
+
+ _volume = 0;
+ _volumeTo = 0;
+ _volumeDirection = 0;
+ _volumeCount = 0;
+}
+
+DreamWebSound::~DreamWebSound() {
+}
+
+bool DreamWebSound::loadSpeech(byte type1, int idx1, byte type2, int idx2) {
cancelCh1();
Common::String name = Common::String::format("%c%02d%c%04d.RAW", type1, idx1, type2, idx2);
- //debug("name = %s", name.c_str());
- bool result = loadSpeech(name);
-
- _speechLoaded = result;
- return result;
+ debug(2, "loadSpeech() name:%s", name.c_str());
+ return loadSpeech(name);
}
+void DreamWebSound::volumeChange(uint8 value, int8 direction) {
+ _volumeTo = value;
+ _volumeDirection = direction;
+}
-void DreamWebEngine::volumeAdjust() {
+void DreamWebSound::volumeAdjust() {
if (_volumeDirection == 0)
return;
if (_volume != _volumeTo) {
@@ -54,36 +77,38 @@ void DreamWebEngine::volumeAdjust() {
}
}
-void DreamWebEngine::playChannel0(uint8 index, uint8 repeat) {
- _channel0Playing = index;
- if (index >= 12)
- index -= 12;
+void DreamWebSound::playChannel0(uint8 index, uint8 repeat) {
+ debug(1, "playChannel0(index:%d, repeat:%d)", index, repeat);
+ _channel0Playing = index;
_channel0Repeat = repeat;
+ _channel0NewSound = true;
}
-void DreamWebEngine::playChannel1(uint8 index) {
+void DreamWebSound::playChannel1(uint8 index) {
+ debug(1, "playChannel1(index:%d)", index);
if (_channel1Playing == 7)
return;
_channel1Playing = index;
- if (index >= 12)
- index -= 12;
+ _channel1NewSound = true;
}
-void DreamWebEngine::cancelCh0() {
- _channel0Repeat = 0;
+void DreamWebSound::cancelCh0() {
+ debug(1, "cancelCh0()");
_channel0Playing = 255;
+ _channel0Repeat = 0;
stopSound(0);
}
-void DreamWebEngine::cancelCh1() {
+void DreamWebSound::cancelCh1() {
+ debug(1, "cancelCh1()");
_channel1Playing = 255;
stopSound(1);
}
-void DreamWebEngine::loadRoomsSample() {
- uint8 sample = _roomsSample;
+void DreamWebSound::loadRoomsSample(uint8 sample) {
+ debug(1, "loadRoomsSample(sample:%d)", sample);
if (sample == 255 || _currentSample == sample)
return; // loaded already
@@ -101,13 +126,8 @@ void DreamWebEngine::loadRoomsSample() {
loadSounds(1, sampleSuffix.c_str());
}
-} // End of namespace DreamWeb
-
-
-namespace DreamWeb {
-
-void DreamWebEngine::playSound(uint8 channel, uint8 id, uint8 loops) {
- debug(1, "playSound(%u, %u, %u)", channel, id, loops);
+void DreamWebSound::playSound(uint8 channel, uint8 id, uint8 loops) {
+ debug(1, "playSound(channel:%u, id:%u, loops:%u)", channel, id, loops);
int bank = 0;
bool speech = false;
@@ -137,47 +157,38 @@ void DreamWebEngine::playSound(uint8 channel, uint8 id, uint8 loops) {
error("out of memory: cannot allocate memory for sound(%u bytes)", sample.size);
memcpy(buffer, data.data.begin() + sample.offset, sample.size);
- raw = Audio::makeRawStream(
- buffer,
- sample.size, 22050, Audio::FLAG_UNSIGNED);
+ raw = Audio::makeRawStream(buffer, sample.size, 22050, Audio::FLAG_UNSIGNED);
} 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());
- raw = Audio::makeRawStream(
- buffer,
- _speechData.size(), 22050, Audio::FLAG_UNSIGNED);
-
+ raw = Audio::makeRawStream(buffer, _speechData.size(), 22050, Audio::FLAG_UNSIGNED);
}
Audio::AudioStream *stream;
if (loops > 1) {
- stream = new Audio::LoopingAudioStream(raw, loops < 255? loops: 0);
+ stream = new Audio::LoopingAudioStream(raw, (loops < 255) ? loops : 0);
} else
stream = raw;
- if (_mixer->isSoundHandleActive(_channelHandle[channel]))
- _mixer->stopHandle(_channelHandle[channel]);
- _mixer->playStream(type, &_channelHandle[channel], stream);
+ if (_vm->_mixer->isSoundHandleActive(_channelHandle[channel]))
+ _vm->_mixer->stopHandle(_channelHandle[channel]);
+ _vm->_mixer->playStream(type, &_channelHandle[channel], stream);
}
-void DreamWebEngine::stopSound(uint8 channel) {
+void DreamWebSound::stopSound(uint8 channel) {
debug(1, "stopSound(%u)", channel);
assert(channel == 0 || channel == 1);
- _mixer->stopHandle(_channelHandle[channel]);
- if (channel == 0)
- _channel0 = 0;
- else
- _channel1 = 0;
+ _vm->_mixer->stopHandle(_channelHandle[channel]);
}
-bool DreamWebEngine::loadSpeech(const Common::String &filename) {
- if (!hasSpeech())
+bool DreamWebSound::loadSpeech(const Common::String &filename) {
+ if (!_vm->hasSpeech())
return false;
Common::File file;
- if (!file.open("speech/" + filename))
+ if (!file.open(_vm->getSpeechDirName() + "/" + filename))
return false;
debug(1, "loadSpeech(%s)", filename.c_str());
@@ -189,8 +200,8 @@ bool DreamWebEngine::loadSpeech(const Common::String &filename) {
return true;
}
-void DreamWebEngine::soundHandler() {
- _subtitles = ConfMan.getBool("subtitles");
+void DreamWebSound::soundHandler() {
+ _vm->_subtitles = ConfMan.getBool("subtitles");
volumeAdjust();
uint volume = _volume;
@@ -207,41 +218,31 @@ void DreamWebEngine::soundHandler() {
if (volume >= 8)
volume = 7;
volume = (8 - volume) * Audio::Mixer::kMaxChannelVolume / 8;
- _mixer->setChannelVolume(_channelHandle[0], volume);
+ _vm->_mixer->setChannelVolume(_channelHandle[0], volume);
- uint8 ch0 = _channel0Playing;
- if (ch0 == 255)
- ch0 = 0;
- uint8 ch1 = _channel1Playing;
- if (ch1 == 255)
- ch1 = 0;
- uint8 ch0loop = _channel0Repeat;
-
- if (_channel0 != ch0) {
- _channel0 = ch0;
- if (ch0) {
- playSound(0, ch0, ch0loop);
+ if (_channel0NewSound) {
+ _channel0NewSound = false;
+ if (_channel0Playing != 255) {
+ playSound(0, _channel0Playing, _channel0Repeat);
}
}
- if (_channel1 != ch1) {
- _channel1 = ch1;
- if (ch1) {
- playSound(1, ch1, 1);
+ if (_channel1NewSound) {
+ _channel1NewSound = false;
+ if (_channel1Playing != 255) {
+ playSound(1, _channel1Playing, 1);
}
}
- if (!_mixer->isSoundHandleActive(_channelHandle[0])) {
+
+ if (!_vm->_mixer->isSoundHandleActive(_channelHandle[0])) {
_channel0Playing = 255;
- _channel0 = 0;
}
- if (!_mixer->isSoundHandleActive(_channelHandle[1])) {
+ if (!_vm->_mixer->isSoundHandleActive(_channelHandle[1])) {
_channel1Playing = 255;
- _channel1 = 0;
}
-
}
-void DreamWebEngine::loadSounds(uint bank, const Common::String &suffix) {
- Common::String filename = getDatafilePrefix() + suffix;
+void DreamWebSound::loadSounds(uint bank, const Common::String &suffix) {
+ Common::String filename = _vm->getDatafilePrefix() + suffix;
debug(1, "loadSounds(%u, %s)", bank, filename.c_str());
Common::File file;
if (!file.open(filename)) {
@@ -249,9 +250,9 @@ void DreamWebEngine::loadSounds(uint bank, const Common::String &suffix) {
return;
}
- uint8 header[0x60];
+ uint8 header[96];
file.read(header, sizeof(header));
- uint tablesize = READ_LE_UINT16(header + 0x32);
+ uint tablesize = READ_LE_UINT16(header + 50);
debug(1, "table size = %u", tablesize);
SoundData &soundData = _soundData[bank];
@@ -261,8 +262,8 @@ void DreamWebEngine::loadSounds(uint bank, const Common::String &suffix) {
uint8 entry[6];
Sample &sample = soundData.samples[i];
file.read(entry, sizeof(entry));
- sample.offset = entry[0] * 0x4000 + READ_LE_UINT16(entry + 1);
- sample.size = READ_LE_UINT16(entry + 3) * 0x800;
+ sample.offset = entry[0] * 16384 + READ_LE_UINT16(entry + 1);
+ sample.size = READ_LE_UINT16(entry + 3) * 2048;
total += sample.size;
debug(1, "offset: %08x, size: %u", sample.offset, sample.size);
}