diff options
author | Eugene Sandulenko | 2010-09-15 14:48:53 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 23:56:07 +0000 |
commit | 3e637a8341694e8aa7bce5c5e12b9bc506865b8b (patch) | |
tree | 77216e692ee6e22b44aca4710fa0522e2b4ef018 /engines/sword25/sfx/soundengine.cpp | |
parent | 951549a29884bee204aa3b9d67d7c868cb3bcce8 (diff) | |
download | scummvm-rg350-3e637a8341694e8aa7bce5c5e12b9bc506865b8b.tar.gz scummvm-rg350-3e637a8341694e8aa7bce5c5e12b9bc506865b8b.tar.bz2 scummvm-rg350-3e637a8341694e8aa7bce5c5e12b9bc506865b8b.zip |
SWORD25: Initial work on sound
svn-id: r53366
Diffstat (limited to 'engines/sword25/sfx/soundengine.cpp')
-rw-r--r-- | engines/sword25/sfx/soundengine.cpp | 93 |
1 files changed, 81 insertions, 12 deletions
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp index 78d543f59c..33d09a2fe1 100644 --- a/engines/sword25/sfx/soundengine.cpp +++ b/engines/sword25/sfx/soundengine.cpp @@ -35,6 +35,9 @@ #define BS_LOG_PREFIX "SOUNDENGINE" #include "sword25/sfx/soundengine.h" +#include "sword25/package/packagemanager.h" + +#include "sound/decoders/vorbis.h" namespace Sword25 { @@ -45,6 +48,9 @@ SoundEngine::SoundEngine(Kernel *pKernel) : ResourceService(pKernel) { BS_LOGLN("Script bindings registered."); _mixer = g_system->getMixer(); + + for (int i = 0; i < SOUND_HANDLES; i++) + _handles[i].type = kFreeHandle; } Service *SoundEngine_CreateObject(Kernel *pKernel) { @@ -77,46 +83,109 @@ void SoundEngine::PauseLayer(uint Layer) { void SoundEngine::ResumeLayer(uint Layer) { } -bool SoundEngine::PlaySound(const Common::String &FileName, SOUND_TYPES Type, float Volume, float Pan, bool Loop, int LoopStart, int LoopEnd, uint Layer) { +SndHandle *SoundEngine::getHandle(uint *id) { + for (uint i = 0; i < SOUND_HANDLES; i++) { + if (_handles[i].type != kFreeHandle && !_mixer->isSoundHandleActive(_handles[i].handle)) { + debug(5, "Handle %d has finished playing", i); + _handles[i].type = kFreeHandle; + } + } + + for (uint i = 0; i < SOUND_HANDLES; i++) { + if (_handles[i].type == kFreeHandle) { + debug(5, "Allocated handle %d", i); + if (id) + *id = i; + return &_handles[i]; + } + } + + error("Sound::getHandle(): Too many sound handles"); + + return NULL; +} + +Audio::Mixer::SoundType getType(SoundEngine::SOUND_TYPES type) { + switch (type) { + case SoundEngine::MUSIC: + return Audio::Mixer::kMusicSoundType; + case SoundEngine::SPEECH: + return Audio::Mixer::kSpeechSoundType; + case SoundEngine::SFX: + return Audio::Mixer::kSFXSoundType; + default: + error("Unknown SOUND_TYPE"); + } + + return Audio::Mixer::kPlainSoundType; +} + +bool SoundEngine::PlaySound(const Common::String &fileName, SOUND_TYPES type, float volume, float pan, bool loop, int loopStart, int loopEnd, uint layer) { + //PlaySoundEx(fileName, type, volume, pan, loop, loopStart, loopEnd, layer); + return true; } -uint SoundEngine::PlaySoundEx(const Common::String &FileName, SOUND_TYPES Type, float Volume, float Pan, bool Loop, int LoopStart, int LoopEnd, uint Layer) { +uint SoundEngine::PlaySoundEx(const Common::String &fileName, SOUND_TYPES type, float volume, float pan, bool loop, int loopStart, int loopEnd, uint layer) { return true; + + Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(fileName); + Audio::SeekableAudioStream *stream = Audio::makeVorbisStream(in, DisposeAfterUse::YES); + uint id; + SndHandle *handle = getHandle(&id); + + _mixer->playStream(getType(type), &(handle->handle), stream, -1, (byte)(volume * 255), (int8)(pan * 127)); + + return id; } -void SoundEngine::SetSoundVolume(uint Handle, float Volume) { +void SoundEngine::SetSoundVolume(uint handle, float volume) { + assert(handle < SOUND_HANDLES); + + _mixer->setChannelVolume(_handles[handle].handle, (byte)(volume * 255)); } -void SoundEngine::SetSoundPanning(uint Handle, float Pan) { +void SoundEngine::SetSoundPanning(uint handle, float pan) { + assert(handle < SOUND_HANDLES); + + _mixer->setChannelBalance(_handles[handle].handle, (int8)(pan * 127)); } -void SoundEngine::PauseSound(uint Handle) { +void SoundEngine::PauseSound(uint handle) { + assert(handle < SOUND_HANDLES); + + _mixer->pauseHandle(_handles[handle].handle, true); } -void SoundEngine::ResumeSound(uint Handle) { +void SoundEngine::ResumeSound(uint handle) { + assert(handle < SOUND_HANDLES); + + _mixer->pauseHandle(_handles[handle].handle, false); } -void SoundEngine::StopSound(uint Handle) { +void SoundEngine::StopSound(uint handle) { + assert(handle < SOUND_HANDLES); + + _mixer->stopHandle(_handles[handle].handle); } -bool SoundEngine::IsSoundPaused(uint Handle) { +bool SoundEngine::IsSoundPaused(uint handle) { return false; } -bool SoundEngine::IsSoundPlaying(uint Handle) { +bool SoundEngine::IsSoundPlaying(uint handle) { return false; } -float SoundEngine::GetSoundVolume(uint Handle) { +float SoundEngine::GetSoundVolume(uint handle) { return 0; } -float SoundEngine::GetSoundPanning(uint Handle) { +float SoundEngine::GetSoundPanning(uint handle) { return 0; } -float SoundEngine::GetSoundTime(uint Handle) { +float SoundEngine::GetSoundTime(uint handle) { return 0; } |