2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:40:49 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-07-21 19:15:28 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
|
|
|
#include "saga/saga.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sound.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-11-15 03:03:48 +00:00
|
|
|
#include "sound/audiostream.h"
|
2004-04-29 01:24:18 +00:00
|
|
|
#include "sound/mixer.h"
|
2005-05-03 20:36:07 +00:00
|
|
|
#include "sound/adpcm.h"
|
2010-01-19 11:22:14 +00:00
|
|
|
#include "sound/raw.h"
|
2004-04-29 01:24:18 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
|
|
|
|
2008-07-21 19:15:28 +00:00
|
|
|
Sound::Sound(SagaEngine *vm, Audio::Mixer *mixer) :
|
2005-09-02 20:17:52 +00:00
|
|
|
_vm(vm), _mixer(mixer), _voxStream(0) {
|
2005-08-15 23:26:50 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
_handles[i].type = kFreeHandle;
|
2005-09-02 20:17:52 +00:00
|
|
|
|
2008-07-21 19:15:28 +00:00
|
|
|
setVolume();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-04-28 23:54:40 +00:00
|
|
|
Sound::~Sound() {
|
2005-05-03 20:36:07 +00:00
|
|
|
delete _voxStream;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-15 23:26:50 +00:00
|
|
|
SndHandle *Sound::getHandle() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++) {
|
|
|
|
if (_handles[i].type == kFreeHandle)
|
|
|
|
return &_handles[i];
|
|
|
|
|
|
|
|
if (!_mixer->isSoundHandleActive(_handles[i].handle)) {
|
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
return &_handles[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error("Sound::getHandle(): Too many sound handles");
|
|
|
|
|
2009-09-24 17:52:53 +00:00
|
|
|
return NULL; // for compilers that don't support NORETURN
|
2005-08-15 23:26:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 23:50:33 +00:00
|
|
|
void Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundBuffer &buffer, int volume,
|
2008-07-21 19:15:28 +00:00
|
|
|
sndHandleType handleType, bool loop) {
|
2004-10-19 17:12:53 +00:00
|
|
|
|
2010-01-20 12:43:59 +00:00
|
|
|
Audio::RewindableAudioStream *stream = 0;
|
2010-01-19 11:21:25 +00:00
|
|
|
|
2009-08-17 11:49:07 +00:00
|
|
|
Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
|
|
|
|
Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2009-01-04 14:38:03 +00:00
|
|
|
if (!buffer.isCompressed) {
|
2010-01-23 23:55:35 +00:00
|
|
|
stream = Audio::makeRawMemoryStream(buffer.buffer, buffer.size, buffer.frequency, buffer.flags);
|
2007-06-25 18:23:01 +00:00
|
|
|
} else {
|
2010-01-20 12:43:59 +00:00
|
|
|
Common::SeekableReadStream *memStream = new Common::MemoryReadStream(buffer.buffer, buffer.size, DisposeAfterUse::YES);
|
2007-06-25 18:23:01 +00:00
|
|
|
|
|
|
|
switch (buffer.soundType) {
|
|
|
|
#ifdef USE_MAD
|
2010-01-20 12:43:59 +00:00
|
|
|
case kSoundMP3:
|
|
|
|
stream = Audio::makeMP3Stream(memStream, DisposeAfterUse::YES);
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
2010-01-20 12:43:59 +00:00
|
|
|
case kSoundOGG:
|
|
|
|
stream = Audio::makeVorbisStream(memStream, DisposeAfterUse::YES);
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_FLAC
|
2010-01-20 12:43:59 +00:00
|
|
|
case kSoundFLAC:
|
|
|
|
stream = Audio::makeFlacStream(memStream, DisposeAfterUse::YES);
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
#endif
|
2010-01-20 12:43:59 +00:00
|
|
|
default:
|
|
|
|
// Unknown compression, ignore sample
|
|
|
|
delete memStream;
|
|
|
|
warning("Unknown compression, ignoring sound");
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-19 11:21:25 +00:00
|
|
|
|
|
|
|
if (stream != NULL)
|
2010-01-20 12:43:59 +00:00
|
|
|
_mixer->playInputStream(soundType, handle, Audio::makeLoopingAudioStream(stream, loop ? 0 : 1), -1, volume);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::playSound(SoundBuffer &buffer, int volume, bool loop) {
|
2005-08-15 23:26:50 +00:00
|
|
|
SndHandle *handle = getHandle();
|
|
|
|
|
|
|
|
handle->type = kEffectHandle;
|
2008-07-21 19:15:28 +00:00
|
|
|
playSoundBuffer(&handle->handle, buffer, 2 * volume, handle->type, loop);
|
2004-10-19 17:12:53 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::pauseSound() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, true);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::resumeSound() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, false);
|
2004-10-19 17:12:53 +00:00
|
|
|
}
|
2004-05-17 16:11:04 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::stopSound() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle) {
|
|
|
|
_mixer->stopHandle(_handles[i].handle);
|
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::playVoice(SoundBuffer &buffer) {
|
2005-08-15 23:26:50 +00:00
|
|
|
SndHandle *handle = getHandle();
|
|
|
|
|
|
|
|
handle->type = kVoiceHandle;
|
2008-07-21 19:15:28 +00:00
|
|
|
playSoundBuffer(&handle->handle, buffer, 255, handle->type, false);
|
2004-10-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::pauseVoice() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, true);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::resumeVoice() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, false);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Sound::stopVoice() {
|
2005-08-15 23:26:50 +00:00
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle) {
|
|
|
|
_mixer->stopHandle(_handles[i].handle);
|
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 01:35:52 +00:00
|
|
|
void Sound::stopAll() {
|
2005-08-15 23:26:50 +00:00
|
|
|
stopVoice();
|
|
|
|
stopSound();
|
2005-08-13 01:35:52 +00:00
|
|
|
}
|
|
|
|
|
2008-07-21 19:15:28 +00:00
|
|
|
void Sound::setVolume() {
|
2008-12-19 12:03:22 +00:00
|
|
|
_vm->_soundVolume = ConfMan.getInt("sfx_volume");
|
|
|
|
_vm->_speechVolume = ConfMan.getInt("speech_volume");
|
2008-07-21 19:15:28 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_soundVolume);
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, _vm->_speechVolume);
|
2005-09-02 20:17:52 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
} // End of namespace Saga
|