Skip to content

Commit

Permalink
SHERLOCK: Implement sound priority
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke authored and wjp committed May 13, 2015
1 parent 3a74cb7 commit 72c9b9f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 41 deletions.
2 changes: 1 addition & 1 deletion engines/sherlock/animation.cpp
Expand Up @@ -111,7 +111,7 @@ bool Animation::play(const Common::String &filename, int minDelay, int fade,
Common::String::format("%s%02d", filename.c_str(), soundNumber);

if (sound._voices)
sound.playSound(fname);
sound.playSound(fname, WAIT_RETURN_IMMEDIATELY);
}

events.wait(speed);
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/objects.cpp
Expand Up @@ -613,7 +613,7 @@ void Object::checkObject() {

if (sound._soundOn && !_countCAnimFrames) {
if (!scene._sounds[v - 1]._name.empty() && sound._digitized)
sound.playLoadedSound(v - 1, 0);
sound.playLoadedSound(v - 1, WAIT_RETURN_IMMEDIATELY);
}
} else if (v >= FLIP_CODE && v <= (FLIP_CODE + 2)) {
// Flip code
Expand Down
9 changes: 2 additions & 7 deletions engines/sherlock/scene.cpp
Expand Up @@ -378,13 +378,8 @@ bool Scene::loadScene(const Common::String &filename) {
for (int idx = 0; idx < numSounds; ++idx)
_sounds[idx].synchronize(*rrmStream);

// If sound is turned on, load the sounds into memory
if (sound._soundOn) {
for (int idx = 0; idx < numSounds; ++idx) {
sound.loadSound(_sounds[idx]._name, _sounds[idx]._priority);
_sounds[idx]._name = "";
}
}
for (int idx = 0; idx < numSounds; ++idx)
sound.loadSound(_sounds[idx]._name, _sounds[idx]._priority);

// Read in palette
rrmStream->read(screen._cMap, PALETTE_SIZE);
Expand Down
41 changes: 16 additions & 25 deletions engines/sherlock/sound.cpp
Expand Up @@ -38,6 +38,7 @@ Sound::Sound(SherlockEngine *vm, Audio::Mixer *mixer): _vm(vm), _mixer(mixer) {
_diskSoundPlaying = false;
_soundPlaying = false;
_soundIsOn = &_soundPlaying;
_curPriority = 0;

_soundOn = true;
_musicOn = true;
Expand All @@ -57,8 +58,7 @@ void Sound::syncSoundSettings() {
}

void Sound::loadSound(const Common::String &name, int priority) {
// TODO
warning("TODO: Sound::loadSound");
// No implementation required in ScummVM
}

char Sound::decodeSample(char sample, byte& prediction, int& step) {
Expand Down Expand Up @@ -86,8 +86,8 @@ char Sound::decodeSample(char sample, byte& prediction, int& step) {
return prediction;
}

bool Sound::playSound(const Common::String &name, WaitType waitType) {
_mixer->stopHandle(_effectsHandle);
bool Sound::playSound(const Common::String &name, WaitType waitType, int priority) {
stopSound();

Common::String filename = name;
if (!filename.contains('.'))
Expand All @@ -103,7 +103,7 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {

byte *decoded = (byte *)malloc((size - 1) * 2);

// +127 to eliminate the pop when the sound starts (signed vs unsignded PCM). Still does not help with the pop at the end
// +127 to eliminate the pop when the sound starts (signed vs unsigned PCM). Still does not help with the pop at the end
byte prediction = (ptr[0] & 0x0f) + 127;
int step = 0;
int counter = 0;
Expand All @@ -118,6 +118,7 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {
Audio::AudioStream *audioStream = Audio::makeRawStream(decoded, (size - 2) * 2, rate, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
_mixer->playStream(Audio::Mixer::kPlainSoundType, &_effectsHandle, audioStream, -1, Audio::Mixer::kMaxChannelVolume);
_soundPlaying = true;
_curPriority = priority;

if (waitType == WAIT_RETURN_IMMEDIATELY) {
_diskSoundPlaying = true;
Expand Down Expand Up @@ -148,34 +149,24 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {
return retval;
}

void Sound::cacheSound(const Common::String &name, int index) {
// TODO
warning("TODO: Sound::cacheSound");
}
void Sound::playLoadedSound(int bufNum, WaitType waitType) {
if (_mixer->isSoundHandleActive(_effectsHandle) && (_curPriority > _vm->_scene->_sounds[bufNum]._priority))
return;

void Sound::playLoadedSound(int bufNum, int waitMode) {
// TODO
warning("TODO: Sound::playLoadedSound");
}
stopSound();
playSound(_vm->_scene->_sounds[bufNum]._name, waitType, _vm->_scene->_sounds[bufNum]._priority);

void Sound::playCachedSound(int index) {
// TODO
warning("TODO: Sound::playCachedSound");
return;
}

void Sound::freeLoadedSounds() {
// TODO
warning("TODO: Sound::clearLoadedSound");
}

void Sound::clearCache() {
// TODO
warning("TODO: Sound::clearCache");
// As sounds are played with DisposeAfterUse::YES, stopping the sounds also
// frees them
stopSound();
}

void Sound::stopSound() {
// TODO
warning("TODO: Sound::stopSound");
_mixer->stopHandle(_effectsHandle);
}

void Sound::playMusic(const Common::String &name) {
Expand Down
9 changes: 4 additions & 5 deletions engines/sherlock/sound.h
Expand Up @@ -44,6 +44,7 @@ class Sound {
SherlockEngine *_vm;
Audio::Mixer *_mixer;
Audio::SoundHandle _effectsHandle;
int _curPriority;

char decodeSample(char sample, byte& prediction, int& step);
public:
Expand All @@ -63,13 +64,11 @@ class Sound {

void syncSoundSettings();
void loadSound(const Common::String &name, int priority);
bool playSound(const Common::String &name, WaitType waitType = WAIT_RETURN_IMMEDIATELY);
void cacheSound(const Common::String &name, int index);
void playLoadedSound(int bufNum, int waitMode);
void playCachedSound(int index);
bool playSound(const Common::String &name, WaitType waitType, int priority = 100);
void playLoadedSound(int bufNum, WaitType waitType);
void freeLoadedSounds();
void clearCache();
void stopSound();

int loadSong(int songNumber);
void startSong();
void freeSong();
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/talk.cpp
Expand Up @@ -1278,7 +1278,7 @@ void Talk::doScript(const Common::String &script) {
if (sound._voices) {
for (int idx = 0; idx < 8 && str[idx] != '~'; ++idx)
tempString += str[idx];
sound.playSound(tempString);
sound.playSound(tempString, WAIT_RETURN_IMMEDIATELY);

// Set voices to wait for more
sound._voices = 2;
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/user_interface.cpp
Expand Up @@ -1683,7 +1683,7 @@ void UserInterface::doTalkControl() {
people.setTalking(0);

if (!talk._statements[_selector]._voiceFile.empty() && sound._voices) {
sound.playSound(talk._statements[_selector]._voiceFile);
sound.playSound(talk._statements[_selector]._voiceFile, WAIT_RETURN_IMMEDIATELY);

// Set voices as an indicator for waiting
sound._voices = 2;
Expand Down

0 comments on commit 72c9b9f

Please sign in to comment.