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"
|
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 10:15:50 +00:00
|
|
|
//return NULL;
|
2005-08-15 23:26:50 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume,
|
2008-07-21 19:15:28 +00:00
|
|
|
sndHandleType handleType, bool loop) {
|
2004-10-19 17:12:53 +00:00
|
|
|
|
2009-08-17 11:49:07 +00:00
|
|
|
buffer.flags |= Audio::Mixer::FLAG_AUTOFREE;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-19 17:12:53 +00:00
|
|
|
if (loop)
|
2009-08-17 11:49:07 +00:00
|
|
|
buffer.flags |= Audio::Mixer::FLAG_LOOP;
|
2004-04-12 21:40:49 +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) {
|
2009-08-17 11:11:38 +00:00
|
|
|
_mixer->playRaw(soundType, handle, buffer.buffer,
|
2009-08-17 11:49:07 +00:00
|
|
|
buffer.size, buffer.frequency, buffer.flags, -1, volume);
|
2007-06-25 18:23:01 +00:00
|
|
|
} else {
|
2009-08-17 11:06:27 +00:00
|
|
|
Audio::AudioStream *stream = 0;
|
2007-06-25 18:23:01 +00:00
|
|
|
|
|
|
|
switch (buffer.soundType) {
|
|
|
|
#ifdef USE_MAD
|
|
|
|
case kSoundMP3:
|
2009-08-17 11:06:27 +00:00
|
|
|
stream = Audio::makeMP3Stream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
2007-06-25 18:23:01 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
case kSoundOGG:
|
2009-08-17 11:06:27 +00:00
|
|
|
stream = Audio::makeVorbisStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
2007-06-25 18:23:01 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
case kSoundFLAC:
|
2009-08-17 11:06:27 +00:00
|
|
|
stream = Audio::makeFlacStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
|
2007-06-25 18:23:01 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2009-08-17 11:11:38 +00:00
|
|
|
// Unknown compression, ignore sample
|
|
|
|
warning("Unknown compression, ignoring sound");
|
2007-06-25 18:23:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:49:07 +00:00
|
|
|
if (stream != NULL)
|
|
|
|
_mixer->playInputStream(soundType, handle, stream, -1, volume, 0, true, false);
|
2007-06-25 18:23:01 +00:00
|
|
|
}
|
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
|