aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25')
-rw-r--r--engines/sword25/sfx/soundengine.cpp93
-rw-r--r--engines/sword25/sfx/soundengine.h22
2 files changed, 96 insertions, 19 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;
}
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index 2bc29cdd1e..153caaf445 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -48,10 +48,6 @@
#ifndef SWORD25_SOUNDENGINE_H
#define SWORD25_SOUNDENGINE_H
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
#include "sword25/kernel/common.h"
#include "sword25/kernel/resservice.h"
#include "sword25/kernel/persistable.h"
@@ -61,9 +57,19 @@
namespace Sword25 {
-// -----------------------------------------------------------------------------
-// Class definitions
-// -----------------------------------------------------------------------------
+#define SOUND_HANDLES 32
+
+enum sndHandleType {
+ kFreeHandle,
+ kEffectHandle,
+ kVoiceHandle
+};
+
+struct SndHandle {
+ Audio::SoundHandle handle;
+ sndHandleType type;
+};
+
class SoundEngine : public ResourceService, public Persistable {
public:
@@ -277,9 +283,11 @@ public:
private:
bool _RegisterScriptBindings();
+ SndHandle *getHandle(uint *id);
private:
Audio::Mixer *_mixer;
+ SndHandle _handles[SOUND_HANDLES];
};
} // End of namespace Sword25