aboutsummaryrefslogtreecommitdiff
path: root/engines/fullpipe/sound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/fullpipe/sound.cpp')
-rw-r--r--engines/fullpipe/sound.cpp50
1 files changed, 32 insertions, 18 deletions
diff --git a/engines/fullpipe/sound.cpp b/engines/fullpipe/sound.cpp
index 230d6c39a9..cd6647177e 100644
--- a/engines/fullpipe/sound.cpp
+++ b/engines/fullpipe/sound.cpp
@@ -29,7 +29,9 @@
#include "fullpipe/messages.h"
#include "fullpipe/statics.h"
+#include "common/config-manager.h"
#include "common/memstream.h"
+#include "audio/mixer.h"
#include "audio/audiostream.h"
#include "audio/decoders/vorbis.h"
#include "audio/decoders/wave.h"
@@ -42,8 +44,14 @@ SoundList::SoundList() {
_libHandle = 0;
}
+SoundList::~SoundList() {
+ for (int i = 0; i < _soundItemsCount; i++)
+ delete _soundItems[i];
+ free(_soundItems);
+}
+
bool SoundList::load(MfcArchive &file, char *fname) {
- debug(5, "SoundList::load()");
+ debugC(5, kDebugLoading, "SoundList::load()");
_soundItemsCount = file.readUint32LE();
_soundItems = (Sound **)calloc(_soundItemsCount, sizeof(Sound *));
@@ -96,16 +104,17 @@ Sound::Sound() {
memset(_directSoundBuffers, 0, sizeof(_directSoundBuffers));
_description = 0;
_volume = 100;
+ _handle = new Audio::SoundHandle();
}
Sound::~Sound() {
freeSound();
-
free(_description);
+ delete _handle;
}
bool Sound::load(MfcArchive &file, NGIArchive *archive) {
- debug(5, "Sound::load()");
+ debugC(5, kDebugLoading, "Sound::load()");
MemoryObject::load(file);
@@ -130,7 +139,7 @@ bool Sound::load(MfcArchive &file, NGIArchive *archive) {
}
void Sound::updateVolume() {
- debug(3, "STUB Sound::updateVolume()");
+ // not needed in our implementation
}
void Sound::setPanAndVolumeByStaticAni() {
@@ -160,7 +169,7 @@ void Sound::setPanAndVolumeByStaticAni() {
dx = ani->_oy - g_fp->_sceneRect.bottom;
}
- par = 0;
+ par = 0;
if (dx > 800) {
setPanAndVolume(-3500, 0);
@@ -206,14 +215,14 @@ void Sound::setPanAndVolumeByStaticAni() {
}
void Sound::setPanAndVolume(int vol, int pan) {
- g_fp->_mixer->setChannelVolume(_handle, vol / 39); // 0..10000
- g_fp->_mixer->setChannelBalance(_handle, pan / 78); // -10000..10000
+ g_fp->_mixer->setChannelVolume(*_handle, MIN((vol + 10000) / 39, 255)); // -10000..0
+ g_fp->_mixer->setChannelBalance(*_handle, CLIP(pan / 78, -127, 127)); // -10000..10000
}
void Sound::play(int flag) {
- Audio::SoundHandle handle = getHandle();
+ Audio::SoundHandle *handle = getHandle();
- if (g_fp->_mixer->isSoundHandleActive(handle))
+ if (g_fp->_mixer->isSoundHandleActive(*handle))
return;
byte *soundData = loadData();
@@ -221,7 +230,7 @@ void Sound::play(int flag) {
Audio::RewindableAudioStream *wav = Audio::makeWAVStream(dataStream, DisposeAfterUse::YES);
Audio::AudioStream *audioStream = new Audio::LoopingAudioStream(wav, (flag == 1) ? 0 : 1);
- g_fp->_mixer->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream);
+ g_fp->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, audioStream);
}
void Sound::freeSound() {
@@ -231,11 +240,11 @@ void Sound::freeSound() {
}
int Sound::getVolume() {
- return g_fp->_mixer->getChannelVolume(_handle) * 39; // 0..10000
+ return g_fp->_mixer->getChannelVolume(*_handle) * 39; // 0..10000
}
void Sound::stop() {
- g_fp->_mixer->stopHandle(_handle);
+ g_fp->_mixer->stopHandle(*_handle);
}
void FullpipeEngine::setSceneMusicParameters(GameVar *gvar) {
@@ -353,7 +362,7 @@ void FullpipeEngine::startSoundStream1(char *trackName) {
stopAllSoundStreams();
#ifdef USE_VORBIS
- if (_mixer->isSoundHandleActive(_sceneTrackHandle))
+ if (_mixer->isSoundHandleActive(*_sceneTrackHandle))
return;
Common::File *track = new Common::File();
@@ -363,7 +372,7 @@ void FullpipeEngine::startSoundStream1(char *trackName) {
return;
}
Audio::RewindableAudioStream *ogg = Audio::makeVorbisStream(track, DisposeAfterUse::YES);
- _mixer->playStream(Audio::Mixer::kMusicSoundType, &_sceneTrackHandle, ogg);
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, _sceneTrackHandle, ogg);
#endif
}
@@ -470,7 +479,8 @@ void global_messageHandler_handleSound(ExCommand *cmd) {
Sound *snd = 0;
for (int i = 0; i < g_fp->_currSoundListCount; i++)
- snd = g_fp->_currSoundList1[i]->getSoundItemById(cmd->_messageNum);
+ if ((snd = g_fp->_currSoundList1[i]->getSoundItemById(cmd->_messageNum)) != NULL)
+ break;
if (!snd)
return;
@@ -487,7 +497,7 @@ void global_messageHandler_handleSound(ExCommand *cmd) {
snd->setPanAndVolume(g_fp->_sfxVolume, 0);
if (snd->getVolume() > -3500)
- snd->play(cmd->_keyCode);
+ snd->play(cmd->_param);
} else if (cmd->_field_14 & 2) {
snd->stop();
}
@@ -512,8 +522,11 @@ void FullpipeEngine::stopAllSoundInstances(int id) {
}
void FullpipeEngine::updateSoundVolume() {
+ ConfMan.setInt("sfx_volume", MAX((_sfxVolume + 10000) / 39, 255));
+ syncSoundSettings();
+
for (int i = 0; i < _currSoundListCount; i++)
- for (int j = 0; i < _currSoundList1[i]->getCount(); j++) {
+ for (int j = 0; j < _currSoundList1[i]->getCount(); j++) {
_currSoundList1[i]->getSoundByIndex(j)->setPanAndVolume(_sfxVolume, 0);
}
}
@@ -521,7 +534,8 @@ void FullpipeEngine::updateSoundVolume() {
void FullpipeEngine::setMusicVolume(int vol) {
_musicVolume = vol;
- g_fp->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, vol);
+ ConfMan.setInt("music_volume", _musicVolume);
+ syncSoundSettings();
}
} // End of namespace Fullpipe