Skip to content

Commit

Permalink
SCUMM: Reduce audio header dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
salty-horse committed May 21, 2016
1 parent 10cbeb1 commit 3ad6af9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 28 deletions.
2 changes: 2 additions & 0 deletions engines/scumm/he/sound_he.cpp
Expand Up @@ -51,10 +51,12 @@ SoundHE::SoundHE(ScummEngine *parent, Audio::Mixer *mixer)
_heMusicTracks(0) {

memset(_heChannel, 0, sizeof(_heChannel));
_heSoundChannels = new Audio::SoundHandle[8]();
}

SoundHE::~SoundHE() {
free(_heMusic);
delete[] _heSoundChannels;
}

void SoundHE::addSoundToQueue(int sound, int heOffset, int heChannel, int heFlags) {
Expand Down
2 changes: 1 addition & 1 deletion engines/scumm/he/sound_he.h
Expand Up @@ -44,7 +44,7 @@ class SoundHE : public Sound {
HEMusic *_heMusic;
int16 _heMusicTracks;

Audio::SoundHandle _heSoundChannels[8];
Audio::SoundHandle *_heSoundChannels;

public: // Used by createSound()
struct {
Expand Down
1 change: 1 addition & 0 deletions engines/scumm/input.cpp
Expand Up @@ -24,6 +24,7 @@
#include "common/events.h"
#include "common/system.h"
#include "common/translation.h"
#include "audio/mixer.h"

#include "scumm/debugger.h"
#include "scumm/dialogs.h"
Expand Down
32 changes: 20 additions & 12 deletions engines/scumm/smush/smush_player.cpp
Expand Up @@ -25,6 +25,8 @@
#include "common/system.h"
#include "common/util.h"

#include "audio/mixer.h"

#include "graphics/cursorman.h"
#include "graphics/palette.h"

Expand Down Expand Up @@ -242,9 +244,15 @@ SmushPlayer::SmushPlayer(ScummEngine_v7 *scumm) {
_paused = false;
_pauseStartTime = 0;
_pauseTime = 0;


_IACTchannel = new Audio::SoundHandle();
_compressedFileSoundHandle = new Audio::SoundHandle();
}

SmushPlayer::~SmushPlayer() {
delete _IACTchannel;
delete _compressedFileSoundHandle;
}

void SmushPlayer::init(int32 speed) {
Expand All @@ -271,8 +279,8 @@ void SmushPlayer::init(int32 speed) {
vs->pitch = vs->w;
_vm->_gdi->_numStrips = vs->w / 8;

_vm->_mixer->stopHandle(_compressedFileSoundHandle);
_vm->_mixer->stopHandle(_IACTchannel);
_vm->_mixer->stopHandle(*_compressedFileSoundHandle);
_vm->_mixer->stopHandle(*_IACTchannel);
_IACTpos = 0;
_vm->_smixer->stop();
}
Expand Down Expand Up @@ -470,7 +478,7 @@ void SmushPlayer::handleIACT(int32 subSize, Common::SeekableReadStream &b) {

if (!_IACTstream) {
_IACTstream = Audio::makeQueuingAudioStream(22050, true);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_IACTchannel, _IACTstream);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _IACTchannel, _IACTstream);
}
_IACTstream->queueBuffer(output_data, 0x1000, DisposeAfterUse::YES, Audio::FLAG_STEREO | Audio::FLAG_16BITS);

Expand Down Expand Up @@ -1091,7 +1099,7 @@ void SmushPlayer::seekSan(const char *file, int32 pos, int32 contFrame) {
}

void SmushPlayer::tryCmpFile(const char *filename) {
_vm->_mixer->stopHandle(_compressedFileSoundHandle);
_vm->_mixer->stopHandle(*_compressedFileSoundHandle);

_compressedFileMode = false;
const char *i = strrchr(filename, '.');
Expand All @@ -1110,7 +1118,7 @@ void SmushPlayer::tryCmpFile(const char *filename) {
strcpy(fname + (i - filename), ".ogg");
if (file->open(fname)) {
_compressedFileMode = true;
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_compressedFileSoundHandle, Audio::makeVorbisStream(file, DisposeAfterUse::YES));
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _compressedFileSoundHandle, Audio::makeVorbisStream(file, DisposeAfterUse::YES));
return;
}
#endif
Expand All @@ -1119,7 +1127,7 @@ void SmushPlayer::tryCmpFile(const char *filename) {
strcpy(fname + (i - filename), ".mp3");
if (file->open(fname)) {
_compressedFileMode = true;
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_compressedFileSoundHandle, Audio::makeMP3Stream(file, DisposeAfterUse::YES));
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _compressedFileSoundHandle, Audio::makeMP3Stream(file, DisposeAfterUse::YES));
return;
}
#endif
Expand Down Expand Up @@ -1185,12 +1193,12 @@ void SmushPlayer::play(const char *filename, int32 speed, int32 offset, int32 st
// the sound. Synt to time instead.
now = _vm->_system->getMillis() - _pauseTime;
elapsed = now - _startTime;
} else if (_vm->_mixer->isSoundHandleActive(_compressedFileSoundHandle)) {
} else if (_vm->_mixer->isSoundHandleActive(*_compressedFileSoundHandle)) {
// Compressed SMUSH files.
elapsed = _vm->_mixer->getSoundElapsedTime(_compressedFileSoundHandle);
} else if (_vm->_mixer->isSoundHandleActive(_IACTchannel)) {
elapsed = _vm->_mixer->getSoundElapsedTime(*_compressedFileSoundHandle);
} else if (_vm->_mixer->isSoundHandleActive(*_IACTchannel)) {
// Curse of Monkey Island SMUSH files.
elapsed = _vm->_mixer->getSoundElapsedTime(_IACTchannel);
elapsed = _vm->_mixer->getSoundElapsedTime(*_IACTchannel);
} else {
// For other SMUSH files, we don't necessarily have any
// one channel to sync against, so we have to use
Expand Down Expand Up @@ -1245,8 +1253,8 @@ void SmushPlayer::play(const char *filename, int32 speed, int32 offset, int32 st
break;
if (_vm->shouldQuit() || _vm->_saveLoadFlag || _vm->_smushVideoShouldFinish) {
_smixer->stop();
_vm->_mixer->stopHandle(_compressedFileSoundHandle);
_vm->_mixer->stopHandle(_IACTchannel);
_vm->_mixer->stopHandle(*_compressedFileSoundHandle);
_vm->_mixer->stopHandle(*_IACTchannel);
_IACTpos = 0;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions engines/scumm/smush/smush_player.h
Expand Up @@ -24,9 +24,9 @@
#define SCUMM_SMUSH_PLAYER_H

#include "common/util.h"
#include "scumm/sound.h"

namespace Audio {
class SoundHandle;
class QueuingAudioStream;
}

Expand Down Expand Up @@ -65,10 +65,10 @@ class SmushPlayer {
bool _skipNext;
uint32 _frame;

Audio::SoundHandle _IACTchannel;
Audio::SoundHandle *_IACTchannel;
Audio::QueuingAudioStream *_IACTstream;

Audio::SoundHandle _compressedFileSoundHandle;
Audio::SoundHandle *_compressedFileSoundHandle;
bool _compressedFileMode;
byte _IACToutput[4096];
int32 _IACTpos;
Expand Down
21 changes: 13 additions & 8 deletions engines/scumm/sound.cpp
Expand Up @@ -97,12 +97,17 @@ Sound::Sound(ScummEngine *parent, Audio::Mixer *mixer)
_loomSteamCD.balance = 0;

_isLoomSteam = _vm->_game.id == GID_LOOM && Common::File::exists("CDDA.SOU");

_loomSteamCDAudioHandle = new Audio::SoundHandle();
_talkChannelHandle = new Audio::SoundHandle();
}

Sound::~Sound() {
stopCDTimer();
stopCD();
free(_offsetTable);
delete _loomSteamCDAudioHandle;
delete _talkChannelHandle;
}

void Sound::addSoundToQueue(int sound, int heOffset, int heChannel, int heFlags) {
Expand Down Expand Up @@ -425,7 +430,7 @@ void Sound::processSfxQueues() {
if (_talk_sound_mode & 1)
startTalkSound(_talk_sound_a1, _talk_sound_b1, 1);
if (_talk_sound_mode & 2)
startTalkSound(_talk_sound_a2, _talk_sound_b2, 2, &_talkChannelHandle);
startTalkSound(_talk_sound_a2, _talk_sound_b2, 2, _talkChannelHandle);
_talk_sound_mode = 0;
}

Expand All @@ -439,7 +444,7 @@ void Sound::processSfxQueues() {
} else if (_vm->_game.heversion >= 60) {
finished = !isSoundRunning(1);
} else {
finished = !_mixer->isSoundHandleActive(_talkChannelHandle);
finished = !_mixer->isSoundHandleActive(*_talkChannelHandle);
}

if ((uint) act < 0x80 && ((_vm->_game.version == 8) || (_vm->_game.version <= 7 && !_vm->_string[0].no_talk_anim))) {
Expand Down Expand Up @@ -675,7 +680,7 @@ void Sound::stopTalkSound() {
} else if (_vm->_game.heversion >= 60) {
stopSound(1);
} else {
_mixer->stopHandle(_talkChannelHandle);
_mixer->stopHandle(*_talkChannelHandle);
}
_sfxMode &= ~2;
}
Expand Down Expand Up @@ -1060,15 +1065,15 @@ void Sound::playCDTrackInternal(int track, int numLoops, int startFrame, int dur
g_system->getAudioCDManager()->play(track, numLoops, startFrame, duration);
} else {
// Stop any currently playing track
_mixer->stopHandle(_loomSteamCDAudioHandle);
_mixer->stopHandle(*_loomSteamCDAudioHandle);

Common::File *cddaFile = new Common::File();
if (cddaFile->open("CDDA.SOU")) {
Audio::Timestamp start = Audio::Timestamp(0, startFrame, 75);
Audio::Timestamp end = Audio::Timestamp(0, startFrame + duration, 75);
Audio::SeekableAudioStream *stream = makeCDDAStream(cddaFile, DisposeAfterUse::YES);

_mixer->playStream(Audio::Mixer::kMusicSoundType, &_loomSteamCDAudioHandle,
_mixer->playStream(Audio::Mixer::kMusicSoundType, _loomSteamCDAudioHandle,
Audio::makeLoopingAudioStream(stream, start, end, (numLoops < 1) ? numLoops + 1 : numLoops));
} else {
delete cddaFile;
Expand All @@ -1080,14 +1085,14 @@ void Sound::stopCD() {
if (!_isLoomSteam)
g_system->getAudioCDManager()->stop();
else
_mixer->stopHandle(_loomSteamCDAudioHandle);
_mixer->stopHandle(*_loomSteamCDAudioHandle);
}

int Sound::pollCD() const {
if (!_isLoomSteam)
return g_system->getAudioCDManager()->isPlaying();
else
return _mixer->isSoundHandleActive(_loomSteamCDAudioHandle);
return _mixer->isSoundHandleActive(*_loomSteamCDAudioHandle);
}

void Sound::updateCD() {
Expand All @@ -1100,7 +1105,7 @@ AudioCDManager::Status Sound::getCDStatus() {
return g_system->getAudioCDManager()->getStatus();
else {
AudioCDManager::Status info = _loomSteamCD;
info.playing = _mixer->isSoundHandleActive(_loomSteamCDAudioHandle);
info.playing = _mixer->isSoundHandleActive(*_loomSteamCDAudioHandle);
return info;
}
}
Expand Down
10 changes: 7 additions & 3 deletions engines/scumm/sound.h
Expand Up @@ -26,10 +26,14 @@
#include "common/scummsys.h"
#include "common/str.h"
#include "audio/mididrv.h"
#include "audio/mixer.h"
#include "backends/audiocd/audiocd.h"
#include "scumm/saveload.h"

namespace Audio {
class Mixer;
class SoundHandle;
}

namespace Scumm {

class ScummEngine;
Expand Down Expand Up @@ -81,12 +85,12 @@ class Sound : public Serializable {
int16 _currentCDSound;
int16 _currentMusic;

Audio::SoundHandle _loomSteamCDAudioHandle;
Audio::SoundHandle *_loomSteamCDAudioHandle;
bool _isLoomSteam;
AudioCDManager::Status _loomSteamCD;

public:
Audio::SoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on
Audio::SoundHandle *_talkChannelHandle; // Handle of mixer channel actor is talking on

bool _soundsPaused;
byte _sfxMode;
Expand Down
3 changes: 2 additions & 1 deletion engines/scumm/string.cpp
Expand Up @@ -23,6 +23,7 @@


#include "common/config-manager.h"
#include "audio/mixer.h"

#include "scumm/actor.h"
#include "scumm/charset.h"
Expand Down Expand Up @@ -662,7 +663,7 @@ void ScummEngine::CHARSET_1() {
// Special case for HE games
} else if (_game.id == GID_LOOM && !ConfMan.getBool("subtitles") && (_sound->pollCD())) {
// Special case for Loom (CD), since it only uses CD audio.for sound
} else if (!ConfMan.getBool("subtitles") && (!_haveActorSpeechMsg || _mixer->isSoundHandleActive(_sound->_talkChannelHandle))) {
} else if (!ConfMan.getBool("subtitles") && (!_haveActorSpeechMsg || _mixer->isSoundHandleActive(*_sound->_talkChannelHandle))) {
// Subtitles are turned off, and there is a voice version
// of this message -> don't print it.
} else {
Expand Down

0 comments on commit 3ad6af9

Please sign in to comment.