diff options
author | Ori Avtalion | 2016-05-21 13:44:27 +0300 |
---|---|---|
committer | Ori Avtalion | 2016-05-21 13:44:27 +0300 |
commit | 21753098e1e30fbb4f845e3f56eaad0cdf2eaa35 (patch) | |
tree | dcf996f2d48354960429c4db9ac72eced94e1759 /engines/neverhood/sound.cpp | |
parent | 10cbeb1ac6be299c06297c0f2c69e7cc8a5cb7cc (diff) | |
download | scummvm-rg350-21753098e1e30fbb4f845e3f56eaad0cdf2eaa35.tar.gz scummvm-rg350-21753098e1e30fbb4f845e3f56eaad0cdf2eaa35.tar.bz2 scummvm-rg350-21753098e1e30fbb4f845e3f56eaad0cdf2eaa35.zip |
NEVERHOOD: Reduce audio header dependencies
Diffstat (limited to 'engines/neverhood/sound.cpp')
-rw-r--r-- | engines/neverhood/sound.cpp | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/engines/neverhood/sound.cpp b/engines/neverhood/sound.cpp index b15bea4a64..db22b72289 100644 --- a/engines/neverhood/sound.cpp +++ b/engines/neverhood/sound.cpp @@ -21,10 +21,17 @@ */ #include "common/memstream.h" -#include "graphics/palette.h" +#include "audio/mixer.h" #include "neverhood/sound.h" +#include "neverhood/resource.h" #include "neverhood/resourceman.h" +// Convert volume from percent to 0..255 +#define VOLUME(volume) (Audio::Mixer::kMaxChannelVolume / 100 * (volume)) + +// Convert panning from percent (50% equals center) to -127..0..+127 +#define PANNING(panning) (254 / 100 * (panning) - 127) + namespace Neverhood { SoundResource::SoundResource(NeverhoodEngine *vm) @@ -583,6 +590,11 @@ AudioResourceManSoundItem::AudioResourceManSoundItem(NeverhoodEngine *vm, uint32 _volume(100), _panning(50) { _vm->_res->queryResource(_fileHash, _resourceHandle); + _soundHandle = new Audio::SoundHandle(); +} + +AudioResourceManSoundItem::~AudioResourceManSoundItem() { + delete _soundHandle; } void AudioResourceManSoundItem::loadSound() { @@ -594,22 +606,22 @@ void AudioResourceManSoundItem::loadSound() { } void AudioResourceManSoundItem::unloadSound() { - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->stopHandle(_soundHandle); + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); _vm->_res->unloadResource(_resourceHandle); _data = NULL; } void AudioResourceManSoundItem::setVolume(int16 volume) { _volume = MIN<int16>(volume, 100); - if (_isPlaying && _vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->setChannelVolume(_soundHandle, VOLUME(_volume)); + if (_isPlaying && _vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->setChannelVolume(*_soundHandle, VOLUME(_volume)); } void AudioResourceManSoundItem::setPan(int16 pan) { _panning = MIN<int16>(pan, 100); - if (_isPlaying && _vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->setChannelVolume(_soundHandle, PANNING(_panning)); + if (_isPlaying && _vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->setChannelVolume(*_soundHandle, PANNING(_panning)); } void AudioResourceManSoundItem::playSound(bool looping) { @@ -619,7 +631,7 @@ void AudioResourceManSoundItem::playSound(bool looping) { const byte *shiftValue = _resourceHandle.extData(); Common::MemoryReadStream *stream = new Common::MemoryReadStream(_data, _resourceHandle.size(), DisposeAfterUse::NO); NeverhoodAudioStream *audioStream = new NeverhoodAudioStream(22050, *shiftValue, looping, DisposeAfterUse::YES, stream); - _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, _soundHandle, audioStream, -1, VOLUME(_volume), PANNING(_panning)); debug(1, "playing sound %08X", _fileHash); _isPlaying = true; @@ -627,13 +639,13 @@ void AudioResourceManSoundItem::playSound(bool looping) { } void AudioResourceManSoundItem::stopSound() { - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->stopHandle(_soundHandle); + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); _isPlaying = false; } bool AudioResourceManSoundItem::isPlaying() { - return _vm->_mixer->isSoundHandleActive(_soundHandle); + return _vm->_mixer->isSoundHandleActive(*_soundHandle); } AudioResourceManMusicItem::AudioResourceManMusicItem(NeverhoodEngine *vm, uint32 fileHash) @@ -641,6 +653,11 @@ AudioResourceManMusicItem::AudioResourceManMusicItem(NeverhoodEngine *vm, uint32 _volume(100), _panning(50), _start(false), _isFadingIn(false), _isFadingOut(false), _isPlaying(false), _fadeVolume(0), _fadeVolumeStep(0) { + _soundHandle = new Audio::SoundHandle(); +} + +AudioResourceManMusicItem::~AudioResourceManMusicItem() { + delete _soundHandle; } void AudioResourceManMusicItem::playMusic(int16 fadeVolumeStep) { @@ -658,7 +675,7 @@ void AudioResourceManMusicItem::playMusic(int16 fadeVolumeStep) { } void AudioResourceManMusicItem::stopMusic(int16 fadeVolumeStep) { - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) { + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) { if (fadeVolumeStep != 0) { if (_isFadingIn) _isFadingIn = false; @@ -667,7 +684,7 @@ void AudioResourceManMusicItem::stopMusic(int16 fadeVolumeStep) { _isFadingOut = true; _fadeVolumeStep = fadeVolumeStep; } else { - _vm->_mixer->stopHandle(_soundHandle); + _vm->_mixer->stopHandle(*_soundHandle); } _isPlaying = false; } @@ -677,8 +694,8 @@ void AudioResourceManMusicItem::unloadMusic() { if (_isFadingOut) { _canRestart = true; } else { - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->stopHandle(_soundHandle); + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->stopHandle(*_soundHandle); _isPlaying = false; _terminate = true; } @@ -686,8 +703,8 @@ void AudioResourceManMusicItem::unloadMusic() { void AudioResourceManMusicItem::setVolume(int16 volume) { _volume = MIN<int16>(volume, 100); - if (_isPlaying && _vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->setChannelVolume(_soundHandle, VOLUME(_volume)); + if (_isPlaying && _vm->_mixer->isSoundHandleActive(*_soundHandle)) + _vm->_mixer->setChannelVolume(*_soundHandle, VOLUME(_volume)); } void AudioResourceManMusicItem::restart() { @@ -698,33 +715,33 @@ void AudioResourceManMusicItem::restart() { void AudioResourceManMusicItem::update() { - if (_start && !_vm->_mixer->isSoundHandleActive(_soundHandle)) { + if (_start && !_vm->_mixer->isSoundHandleActive(*_soundHandle)) { ResourceHandle resourceHandle; _vm->_res->queryResource(_fileHash, resourceHandle); Common::SeekableReadStream *stream = _vm->_res->createStream(_fileHash); const byte *shiftValue = resourceHandle.extData(); NeverhoodAudioStream *audioStream = new NeverhoodAudioStream(22050, *shiftValue, true, DisposeAfterUse::YES, stream); - _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_soundHandle, + _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, _soundHandle, audioStream, -1, VOLUME(_isFadingIn ? _fadeVolume : _volume), PANNING(_panning)); _start = false; _isPlaying = true; } - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) { + if (_vm->_mixer->isSoundHandleActive(*_soundHandle)) { if (_isFadingIn) { _fadeVolume += _fadeVolumeStep; if (_fadeVolume >= _volume) { _fadeVolume = _volume; _isFadingIn = false; } - _vm->_mixer->setChannelVolume(_soundHandle, VOLUME(_fadeVolume)); + _vm->_mixer->setChannelVolume(*_soundHandle, VOLUME(_fadeVolume)); } if (_isFadingOut) { _fadeVolume -= _fadeVolumeStep; if (_fadeVolume < 0) _fadeVolume = 0; - _vm->_mixer->setChannelVolume(_soundHandle, VOLUME(_fadeVolume)); + _vm->_mixer->setChannelVolume(*_soundHandle, VOLUME(_fadeVolume)); if (_fadeVolume == 0) { _isFadingOut = false; stopMusic(0); |