aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mohawk/myst.cpp5
-rw-r--r--engines/mohawk/sound.cpp39
-rw-r--r--engines/mohawk/sound.h6
3 files changed, 32 insertions, 18 deletions
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index 6c4623027f..8c610d9574 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -397,7 +397,10 @@ void MohawkEngine_Myst::changeToCard(uint16 card) {
_sound->stopSound();
// TODO: Need to keep sound handle and add function to change volume of
// looped running sound for kMystSoundActionChangeVolume type
- _sound->playSound(soundAction, true, soundActionVolume);
+
+ // NOTE: All sounds are looped when played via the sound section of the
+ // VIEW resources.
+ _sound->playSound(soundAction, true, soundActionVolume, true);
} else {
error("Unknown sound action %d", soundAction);
}
diff --git a/engines/mohawk/sound.cpp b/engines/mohawk/sound.cpp
index 6df7cba758..c2954358fd 100644
--- a/engines/mohawk/sound.cpp
+++ b/engines/mohawk/sound.cpp
@@ -87,13 +87,13 @@ void Sound::initMidi() {
_midiParser->setTimerRate(_midiDriver->getBaseTempo());
}
-Audio::SoundHandle *Sound::playSound(uint16 id, bool mainSoundFile, byte volume) {
+Audio::SoundHandle *Sound::playSound(uint16 id, bool mainSoundFile, byte volume, bool loop) {
debug (0, "Playing sound %d", id);
SndHandle *handle = getHandle();
handle->type = kUsedHandle;
- Audio::AudioStream* audStream = NULL;
+ Audio::AudioStream *audStream = NULL;
switch (_vm->getGameType()) {
case GType_MYST:
@@ -136,6 +136,10 @@ Audio::SoundHandle *Sound::playSound(uint16 id, bool mainSoundFile, byte volume)
}
if (audStream) {
+ // Set the stream to loop here if it's requested
+ if (loop)
+ audStream = Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audStream, 0);
+
_vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &handle->handle, audStream, -1, volume);
return &handle->handle;
}
@@ -292,7 +296,11 @@ void Sound::playSLSTSound(uint16 id, bool fade, bool loop, uint16 volume, int16
sndHandle.id = id;
_currentSLSTSounds.push_back(sndHandle);
- Audio::AudioStream *audStream = makeMohawkWaveStream(_rivenSoundFile->getRawData(ID_TWAV, id), loop);
+ Audio::AudioStream *audStream = makeMohawkWaveStream(_rivenSoundFile->getRawData(ID_TWAV, id));
+
+ // Loop here if necessary
+ if (loop)
+ audStream = Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audStream, 0);
// The max mixer volume is 255 and the max Riven volume is 256. Just change it to 255.
if (volume == 256)
@@ -329,7 +337,7 @@ Audio::AudioStream *Sound::getCSAmtrakMusic(uint16 id) {
return audStream;
}
-Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stream, bool loop) {
+Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stream) {
bool foundData = false;
uint32 tag = 0;
ADPC_Chunk adpc;
@@ -419,6 +427,12 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
data_chunk.loopStart = stream->readUint32BE();
data_chunk.loopEnd = stream->readUint32BE();
+ // NOTE: We currently ignore all of the loop parameters here. Myst uses the loop
+ // variable but the loopStart and loopEnd are always 0 and the size of the sample.
+ // Myst ME doesn't use the Mohawk Sound format and just standard WAVE files and
+ // therefore does not contain any of this metadata and we have to specify whether
+ // or not to loop elsewhere.
+
data_chunk.audio_data = (byte *)malloc(data_chunk.size);
stream->read(data_chunk.audio_data, data_chunk.size);
foundData = true;
@@ -436,20 +450,19 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
// The sound in the DVD version of Riven is encoded in MPEG-2 Layer II or Intel DVI ADPCM
if (data_chunk.encoding == kCodecRaw) {
byte flags = Audio::FLAG_UNSIGNED;
+
if (data_chunk.channels == 2)
flags |= Audio::FLAG_STEREO;
- if (data_chunk.loop == 0xFFFF || loop)
- flags |= Audio::FLAG_LOOP;
- return Audio::makeRawMemoryStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES, data_chunk.sample_rate, flags, data_chunk.loopStart, data_chunk.loopEnd);
+
+ return Audio::makeRawMemoryStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES, data_chunk.sample_rate, flags);
} else if (data_chunk.encoding == kCodecADPCM) {
Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
uint32 blockAlign = data_chunk.channels * data_chunk.bitsPerSample / 8;
-
- return makeLoopingAudioStream(Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign), loop ? 0 : 1);
+ return Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
} else if (data_chunk.encoding == kCodecMPEG2) {
#ifdef USE_MAD
Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
- return Audio::makeLoopingAudioStream(Audio::makeMP3Stream(dataStream, DisposeAfterUse::YES), loop ? 0 : 1);
+ return Audio::makeMP3Stream(dataStream, DisposeAfterUse::YES);
#else
warning ("MAD library not included - unable to play MP2 audio");
#endif
@@ -460,7 +473,7 @@ Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stre
return NULL;
}
-Audio::AudioStream *Sound::makeOldMohawkWaveStream(Common::SeekableReadStream *stream, bool loop) {
+Audio::AudioStream *Sound::makeOldMohawkWaveStream(Common::SeekableReadStream *stream) {
uint16 header = stream->readUint16BE();
uint16 rate = 0;
uint32 size = 0;
@@ -481,9 +494,7 @@ Audio::AudioStream *Sound::makeOldMohawkWaveStream(Common::SeekableReadStream *s
stream->read(data, size);
delete stream;
- return Audio::makeLoopingAudioStream(
- Audio::makeRawMemoryStream(data, size, DisposeAfterUse::YES, rate, Audio::FLAG_UNSIGNED),
- loop ? 0 : 1);
+ return Audio::makeRawMemoryStream(data, size, DisposeAfterUse::YES, rate, Audio::FLAG_UNSIGNED);
}
SndHandle *Sound::getHandle() {
diff --git a/engines/mohawk/sound.h b/engines/mohawk/sound.h
index 400eb646a5..e2234e7c30 100644
--- a/engines/mohawk/sound.h
+++ b/engines/mohawk/sound.h
@@ -121,7 +121,7 @@ public:
~Sound();
void loadRivenSounds(uint16 stack);
- Audio::SoundHandle *playSound(uint16 id, bool mainSoundFile = true, byte volume = Audio::Mixer::kMaxChannelVolume);
+ Audio::SoundHandle *playSound(uint16 id, bool mainSoundFile = true, byte volume = Audio::Mixer::kMaxChannelVolume, bool loop = false);
void playMidi(uint16 id);
void stopSound();
void pauseSound();
@@ -139,8 +139,8 @@ private:
MidiParser *_midiParser;
static Audio::AudioStream *getCSAmtrakMusic(uint16 id);
- static Audio::AudioStream *makeMohawkWaveStream(Common::SeekableReadStream *stream, bool loop = false);
- static Audio::AudioStream *makeOldMohawkWaveStream(Common::SeekableReadStream *stream, bool loop = false);
+ static Audio::AudioStream *makeMohawkWaveStream(Common::SeekableReadStream *stream);
+ static Audio::AudioStream *makeOldMohawkWaveStream(Common::SeekableReadStream *stream);
void initMidi();
Common::Array<SndHandle> _handles;