[Scummvm-git-logs] scummvm master -> fef2d2f366daa4676ed3feaef896416808d0117f
moralrecordings
code at moral.net.au
Wed Jun 3 15:09:25 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
fef2d2f366 DIRECTOR: Implement kTheVolume
Commit: fef2d2f366daa4676ed3feaef896416808d0117f
https://github.com/scummvm/scummvm/commit/fef2d2f366daa4676ed3feaef896416808d0117f
Author: Scott Percival (code at moral.net.au)
Date: 2020-06-03T23:09:00+08:00
Commit Message:
DIRECTOR: Implement kTheVolume
Changed paths:
engines/director/lingo/lingo-the.cpp
engines/director/score.cpp
engines/director/sound.cpp
engines/director/sound.h
diff --git a/engines/director/lingo/lingo-the.cpp b/engines/director/lingo/lingo-the.cpp
index 93fbd4a66d..a74c331fda 100644
--- a/engines/director/lingo/lingo-the.cpp
+++ b/engines/director/lingo/lingo-the.cpp
@@ -26,6 +26,7 @@
#include "director/director.h"
#include "director/cast.h"
#include "director/frame.h"
+#include "director/sound.h"
#include "director/sprite.h"
#include "director/score.h"
#include "director/lingo/lingo.h"
@@ -477,6 +478,24 @@ Datum Lingo::getTheEntity(int entity, Datum &id, int field) {
d.type = INT;
d.u.i = 1;
break;
+ case kTheSoundEntity:
+ {
+ switch (field) {
+ case kTheVolume:
+ {
+ SoundChannel *chan = _vm->getSoundManager()->getChannel(id.asInt());
+ if (chan) {
+ d.type = INT;
+ d.u.i = (int)chan->volume;
+ }
+ }
+ break;
+ default:
+ warning("Lingo::getTheEntity(): Unprocessed getting field \"%s\" of entity %s", field2str(field), entity2str(entity));
+ break;
+ }
+ }
+ break;
case kTheSprite:
d = getTheSprite(id, field);
break;
@@ -506,7 +525,7 @@ Datum Lingo::getTheEntity(int entity, Datum &id, int field) {
break;
default:
warning("Lingo::getTheEntity(): Unprocessed getting field \"%s\" of entity %s", field2str(field), entity2str(entity));
- d.type = VOID;
+ break;
}
return d;
@@ -535,6 +554,23 @@ void Lingo::setTheEntity(int entity, Datum &id, int field, Datum &d) {
case kThePerFrameHook:
warning("STUB: Lingo::setTheEntity(): setting the perframehook");
break;
+ case kTheSoundEntity:
+ {
+ switch (field) {
+ case kTheVolume:
+ {
+ SoundChannel *chan = _vm->getSoundManager()->getChannel(id.asInt());
+ if (chan) {
+ chan->volume = (byte)d.asInt();
+ }
+ }
+ break;
+ default:
+ warning("Lingo::setTheEntity(): Unprocessed getting field \"%s\" of entity %s", field2str(field), entity2str(entity));
+ break;
+ }
+ }
+ break;
case kTheSprite:
setTheSprite(id, field, d);
break;
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index b12b944bcb..dc8edfbe33 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -2213,7 +2213,7 @@ Sprite *Score::getSpriteById(uint16 id) {
void Score::playSoundChannel(uint16 frameId) {
Frame *frame = _frames[frameId];
- debugC(5, kDebugLoading, "playSoundChannel(), Sound1 %d Sound2 %d", frame->_sound1, frame->_sound2);
+ debugC(5, kDebugLoading, "playSoundChannel(): Sound1 %d Sound2 %d", frame->_sound1, frame->_sound2);
DirectorSound *sound = _vm->getSoundManager();
sound->playCastMember(frame->_sound1, 1, false);
sound->playCastMember(frame->_sound2, 2, false);
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index 933b0a2723..8cd5b0b3d2 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -42,8 +42,7 @@ DirectorSound::DirectorSound(DirectorEngine *vm) : _vm(vm) {
}
for (uint i = 0; i < numChannels; i++) {
- _channels.push_back(new Audio::SoundHandle());
- _lastPlayingCasts.push_back(0);
+ _channels.push_back(SoundChannel());
}
_scriptSound = new Audio::SoundHandle();
@@ -56,12 +55,17 @@ DirectorSound::DirectorSound(DirectorEngine *vm) : _vm(vm) {
}
DirectorSound::~DirectorSound() {
- for (uint i = 0; i < _channels.size(); i++) {
- delete _channels[i];
- }
delete _scriptSound;
}
+SoundChannel *DirectorSound::getChannel(uint8 soundChannel) {
+ if (soundChannel == 0 || soundChannel > _channels.size()) {
+ warning("Invalid sound channel %d", soundChannel);
+ return nullptr;
+ }
+ return &_channels[soundChannel - 1];
+}
+
void DirectorSound::playFile(Common::String filename, uint8 soundChannel) {
if (debugChannelSet(-1, kDebugFast))
return;
@@ -98,7 +102,7 @@ void DirectorSound::playWAV(Common::String filename, uint8 soundChannel) {
return;
}
- _lastPlayingCasts[soundChannel - 1] = 0;
+ _channels[soundChannel - 1].lastPlayingCast = 0;
Common::File *file = new Common::File();
@@ -112,8 +116,8 @@ void DirectorSound::playWAV(Common::String filename, uint8 soundChannel) {
Audio::RewindableAudioStream *sound = Audio::makeWAVStream(file, DisposeAfterUse::YES);
- _mixer->stopHandle(*_channels[soundChannel - 1]);
- _mixer->playStream(Audio::Mixer::kSFXSoundType, _channels[soundChannel - 1], sound);
+ _mixer->stopHandle(_channels[soundChannel - 1].handle);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_channels[soundChannel - 1].handle, sound, -1, _channels[soundChannel - 1].volume);
}
void DirectorSound::playAIFF(Common::String filename, uint8 soundChannel) {
@@ -121,7 +125,7 @@ void DirectorSound::playAIFF(Common::String filename, uint8 soundChannel) {
warning("Invalid sound channel %d", soundChannel);
return;
}
- _lastPlayingCasts[soundChannel - 1] = 0;
+ _channels[soundChannel - 1].lastPlayingCast = 0;
Common::File *file = new Common::File();
@@ -133,8 +137,8 @@ void DirectorSound::playAIFF(Common::String filename, uint8 soundChannel) {
Audio::RewindableAudioStream *sound = Audio::makeAIFFStream(file, DisposeAfterUse::YES);
- _mixer->stopHandle(*_channels[soundChannel - 1]);
- _mixer->playStream(Audio::Mixer::kSFXSoundType, _channels[soundChannel - 1], sound);
+ _mixer->stopHandle(_channels[soundChannel - 1].handle);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_channels[soundChannel - 1].handle, sound, -1, _channels[soundChannel - 1].volume);
}
void DirectorSound::playMCI(Audio::AudioStream &stream, uint32 from, uint32 to) {
@@ -151,8 +155,8 @@ void DirectorSound::playStream(Audio::AudioStream &stream, uint8 soundChannel) {
return;
}
- _mixer->stopHandle(*_channels[soundChannel - 1]);
- _mixer->playStream(Audio::Mixer::kSFXSoundType, _channels[soundChannel - 1], &stream);
+ _mixer->stopHandle(_channels[soundChannel - 1].handle);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_channels[soundChannel - 1].handle, &stream, -1, _channels[soundChannel - 1].volume);
}
void DirectorSound::playCastMember(int castId, uint8 soundChannel, bool allowRepeat) {
@@ -176,7 +180,7 @@ void DirectorSound::playCastMember(int castId, uint8 soundChannel, bool allowRep
playStream(*sd->getLoopingAudioStream(), soundChannel);
else
playStream(*sd->getAudioStream(), soundChannel);
- _lastPlayingCasts[soundChannel - 1] = castId;
+ _channels[soundChannel - 1].lastPlayingCast = castId;
}
} else {
warning("DirectorSound::playCastMember: couldn't find cast member %d", castId);
@@ -190,7 +194,7 @@ bool DirectorSound::isChannelActive(uint8 soundChannel) {
return false;
}
- return _mixer->isSoundHandleActive(*_channels[soundChannel - 1]);
+ return _mixer->isSoundHandleActive(_channels[soundChannel - 1].handle);
}
int DirectorSound::lastPlayingCast(uint8 soundChannel) {
@@ -199,7 +203,7 @@ int DirectorSound::lastPlayingCast(uint8 soundChannel) {
return false;
}
- return _lastPlayingCasts[soundChannel - 1];
+ return _channels[soundChannel - 1].lastPlayingCast;
}
void DirectorSound::stopSound(uint8 soundChannel) {
@@ -208,15 +212,15 @@ void DirectorSound::stopSound(uint8 soundChannel) {
return;
}
- _mixer->stopHandle(*_channels[soundChannel - 1]);
- _lastPlayingCasts[soundChannel - 1] = 0;
+ _mixer->stopHandle(_channels[soundChannel - 1].handle);
+ _channels[soundChannel - 1].lastPlayingCast = 0;
return;
}
void DirectorSound::stopSound() {
for (uint i = 0; i < _channels.size(); i++) {
- _mixer->stopHandle(*_channels[i]);
- _lastPlayingCasts[i] = 0;
+ _mixer->stopHandle(_channels[i].handle);
+ _channels[i].lastPlayingCast = 0;
}
_mixer->stopHandle(*_scriptSound);
_mixer->stopHandle(*_pcSpeakerHandle);
diff --git a/engines/director/sound.h b/engines/director/sound.h
index 88c3514dcb..5591fa329b 100644
--- a/engines/director/sound.h
+++ b/engines/director/sound.h
@@ -23,6 +23,8 @@
#ifndef DIRECTOR_SOUND_H
#define DIRECTOR_SOUND_H
+#include "audio/mixer.h"
+
namespace Audio {
class AudioStream;
class SoundHandle;
@@ -32,12 +34,19 @@ namespace Audio {
namespace Director {
+struct SoundChannel {
+ Audio::SoundHandle handle;
+ int lastPlayingCast;
+ byte volume;
+
+ SoundChannel(): handle(), lastPlayingCast(0), volume(255) {}
+};
+
class DirectorSound {
private:
DirectorEngine *_vm;
- Common::Array<Audio::SoundHandle *> _channels;
- Common::Array<int> _lastPlayingCasts;
+ Common::Array<SoundChannel> _channels;
Audio::SoundHandle *_scriptSound;
Audio::Mixer *_mixer;
Audio::PCSpeaker *_speaker;
@@ -47,6 +56,7 @@ public:
DirectorSound(DirectorEngine *vm);
~DirectorSound();
+ SoundChannel *getChannel(uint8 soundChannel);
void playWAV(Common::String filename, uint8 soundChannel);
void playAIFF(Common::String filename, uint8 soundChannel);
void playFile(Common::String filename, uint8 soundChannel);
More information about the Scummvm-git-logs
mailing list