aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sword25/sfx/soundengine.cpp77
-rw-r--r--engines/sword25/sfx/soundengine.h33
-rw-r--r--engines/sword25/sfx/soundengine_script.cpp39
3 files changed, 67 insertions, 82 deletions
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 33d09a2fe1..b37013e98a 100644
--- a/engines/sword25/sfx/soundengine.cpp
+++ b/engines/sword25/sfx/soundengine.cpp
@@ -36,11 +36,24 @@
#include "sword25/sfx/soundengine.h"
#include "sword25/package/packagemanager.h"
+#include "sword25/kernel/resource.h"
#include "sound/decoders/vorbis.h"
namespace Sword25 {
+class SoundResource : public Resource {
+public:
+ SoundResource(const Common::String &fileName) : Resource(fileName, Resource::TYPE_SOUND), _fname(fileName) {}
+ virtual ~SoundResource() {
+ debug(1, "Unloading file %s", _fname.c_str());
+ }
+
+private:
+ Common::String _fname;
+};
+
+
SoundEngine::SoundEngine(Kernel *pKernel) : ResourceService(pKernel) {
if (!_RegisterScriptBindings())
BS_LOG_ERRORLN("Script bindings could not be registered.");
@@ -57,30 +70,42 @@ Service *SoundEngine_CreateObject(Kernel *pKernel) {
return new SoundEngine(pKernel);
}
-bool SoundEngine::Init(uint SampleRate, uint Channels) {
+bool SoundEngine::Init(uint sampleRate, uint channels) {
+ warning("STUB: SoundEngine::Init(%d, %d)", sampleRate, channels);
+
return true;
}
void SoundEngine::Update() {
}
-void SoundEngine::SetVolume(float Volume, SOUND_TYPES Type) {
+void SoundEngine::SetVolume(float volume, SOUND_TYPES type) {
+ warning("STUB: SoundEngine::SetVolume(%f, %d)", volume, type);
}
-float SoundEngine::GetVolume(SOUND_TYPES Type) {
+float SoundEngine::GetVolume(SOUND_TYPES type) {
+ warning("STUB: SoundEngine::GetVolume(%d)", type);
return 0;
}
void SoundEngine::PauseAll() {
+ debug(1, "SoundEngine::PauseAll()");
+
+ _mixer->pauseAll(true);
}
void SoundEngine::ResumeAll() {
+ debug(1, "SoundEngine::ResumeAll()");
+
+ _mixer->pauseAll(false);
}
-void SoundEngine::PauseLayer(uint Layer) {
+void SoundEngine::PauseLayer(uint layer) {
+ warning("STUB: SoundEngine::PauseLayer(%d)", layer);
}
-void SoundEngine::ResumeLayer(uint Layer) {
+void SoundEngine::ResumeLayer(uint layer) {
+ warning("STUB: SoundEngine::ResumeLayer(%d)", layer);
}
SndHandle *SoundEngine::getHandle(uint *id) {
@@ -121,19 +146,23 @@ Audio::Mixer::SoundType getType(SoundEngine::SOUND_TYPES type) {
}
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);
+ debug(1, "SoundEngine::PlaySound(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, 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) {
- return true;
-
Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(fileName);
Audio::SeekableAudioStream *stream = Audio::makeVorbisStream(in, DisposeAfterUse::YES);
uint id;
SndHandle *handle = getHandle(&id);
+ Resource *ResourcePtr = Kernel::GetInstance()->GetResourceManager()->RequestResource(fileName);
+
+ debug(1, "SoundEngine::PlaySoundEx(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, layer);
+
_mixer->playStream(getType(type), &(handle->handle), stream, -1, (byte)(volume * 255), (int8)(pan * 127));
return id;
@@ -142,60 +171,86 @@ uint SoundEngine::PlaySoundEx(const Common::String &fileName, SOUND_TYPES type,
void SoundEngine::SetSoundVolume(uint handle, float volume) {
assert(handle < SOUND_HANDLES);
+ debug(1, "SoundEngine::SetSoundVolume(%d, %f)", handle, volume);
+
_mixer->setChannelVolume(_handles[handle].handle, (byte)(volume * 255));
}
void SoundEngine::SetSoundPanning(uint handle, float pan) {
assert(handle < SOUND_HANDLES);
+ debug(1, "SoundEngine::SetSoundPanning(%d, %f)", handle, pan);
+
_mixer->setChannelBalance(_handles[handle].handle, (int8)(pan * 127));
}
void SoundEngine::PauseSound(uint handle) {
assert(handle < SOUND_HANDLES);
+ debug(1, "SoundEngine::PauseSound(%d)", handle);
+
_mixer->pauseHandle(_handles[handle].handle, true);
}
void SoundEngine::ResumeSound(uint handle) {
assert(handle < SOUND_HANDLES);
+ debug(1, "SoundEngine::ResumeSound(%d)", handle);
+
_mixer->pauseHandle(_handles[handle].handle, false);
}
void SoundEngine::StopSound(uint handle) {
assert(handle < SOUND_HANDLES);
+ debug(1, "SoundEngine::StopSound(%d)", handle);
+
_mixer->stopHandle(_handles[handle].handle);
}
bool SoundEngine::IsSoundPaused(uint handle) {
+ warning("STUB: SoundEngine::IsSoundPaused(%d)", handle);
+
return false;
}
bool SoundEngine::IsSoundPlaying(uint handle) {
- return false;
+ assert(handle < SOUND_HANDLES);
+
+ debug(1, "SoundEngine::IsSoundPlaying(%d)", handle);
+
+ return _mixer->isSoundHandleActive(_handles[handle].handle);
}
float SoundEngine::GetSoundVolume(uint handle) {
+ warning("STUB: SoundEngine::GetSoundVolume(%d)", handle);
+
return 0;
}
float SoundEngine::GetSoundPanning(uint handle) {
+ warning("STUB: SoundEngine::GetSoundPanning(%d)", handle);
+
return 0;
}
float SoundEngine::GetSoundTime(uint handle) {
+ warning("STUB: SoundEngine::GetSoundTime(%d)", handle);
+
return 0;
}
-Resource *SoundEngine::LoadResource(const Common::String &FileName) {
- return 0;
+Resource *SoundEngine::LoadResource(const Common::String &fileName) {
+ warning("STUB: SoundEngine::LoadResource(%s)", fileName.c_str());
+
+ return new SoundResource(fileName);
}
bool SoundEngine::CanLoadResource(const Common::String &fileName) {
Common::String fname = fileName;
+ debug(1, "SoundEngine::CanLoadResource(%s)", fileName.c_str());
+
fname.toLowercase();
return fname.hasSuffix(".ogg");
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index 153caaf445..23913b4e1f 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -73,10 +73,6 @@ struct SndHandle {
class SoundEngine : public ResourceService, public Persistable {
public:
- // -----------------------------------------------------------------------------
- // Enums and Types
- // -----------------------------------------------------------------------------
-
enum SOUND_TYPES {
MUSIC = 0,
SPEECH = 1,
@@ -91,17 +87,9 @@ public:
*/
typedef void (*DynamicSoundReadCallback)(void *UserData, void *Data, uint DataLength);
- // -----------------------------------------------------------------------------
- // Constructor / destructor
- // -----------------------------------------------------------------------------
-
SoundEngine(Kernel *pKernel);
~SoundEngine() {};
- // --------------------------------------------------------------
- // THIS METHOD MUST BE IMPLEMENTED BY THE SOUND ENGINE
- // --------------------------------------------------------------
-
/**
* Initialises the sound engine
* @param SampleRate Specifies the sample rate to use.
@@ -195,25 +183,6 @@ public:
uint PlaySoundEx(const Common::String &FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, uint Layer = 0);
/**
- * Plays a sound generated at runtime
- * @param ReadCallback A pointer to a callback function that is called when sound data is needed.
- * See the documentation for DynamicSoundReadCallback for more information.
- * @param UserData A pointer to the data. These are passed to the callback function each time.
- * If no such data is needed, this parameter can be set to NULL.
- * @param Type The type of sound
- * @param SampleRate The sample rate for the sound
- * @param BitsPerSample The size of the sample in bits. This statement is independant of the number of
- * channels. Allowed values are 8, 16, 24, and 32.
- * @param Channels The number of channels. Allowed values are 1 and 2.
- * @param Volume The volume of the sound (0 = off, 1 = full volume)
- * @param Pan Panning (-1 = full left, 1 = right)
- * @param Layer The sound layer
- * @return Returns a handle to the sound. With this handle, the sound can be manipulated during playback.
- * @remark Dynamic sounds cannot be persisted.
- */
- uint PlayDynamicSoundEx(DynamicSoundReadCallback ReadCallback, void *UserData, SOUND_TYPES Type, uint SampleRate, uint BitsPerSample, uint Channels, float Volume = 1.0f, float Pan = 0.0f, uint Layer = 0);
-
- /**
* Sets the volume of a playing sound
* @param Handle The sound handle
* @param Volume The volume of the sound (0 = off, 1 = full volume)
@@ -276,7 +245,7 @@ public:
float GetSoundTime(uint Handle);
Resource *LoadResource(const Common::String &FileName);
- bool CanLoadResource(const Common::String &FileName);
+ bool CanLoadResource(const Common::String &FileName);
bool persist(OutputPersistenceBlock &writer);
bool unpersist(InputPersistenceBlock &reader);
diff --git a/engines/sword25/sfx/soundengine_script.cpp b/engines/sword25/sfx/soundengine_script.cpp
index fad9742c16..808fced94a 100644
--- a/engines/sword25/sfx/soundengine_script.cpp
+++ b/engines/sword25/sfx/soundengine_script.cpp
@@ -44,7 +44,6 @@
#include "sword25/sfx/soundengine.h"
namespace Sword25 {
-// -----------------------------------------------------------------------------
static int Init(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
@@ -62,8 +61,6 @@ static int Init(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int Update(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -75,8 +72,6 @@ static int Update(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int SetVolume(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -89,8 +84,6 @@ static int SetVolume(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int GetVolume(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -102,8 +95,6 @@ static int GetVolume(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int PauseAll(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -115,8 +106,6 @@ static int PauseAll(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int ResumeAll(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -128,8 +117,6 @@ static int ResumeAll(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int PauseLayer(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -141,8 +128,6 @@ static int PauseLayer(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int ResumeLayer(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -154,8 +139,6 @@ static int ResumeLayer(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static void ProcessPlayParams(lua_State *L, Common::String &FileName, SoundEngine::SOUND_TYPES &Type, float &Volume, float &Pan, bool &Loop, int &LoopStart, int &LoopEnd, uint &Layer) {
FileName = luaL_checkstring(L, 1);
@@ -222,8 +205,6 @@ static int PlaySoundEx(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int SetSoundVolume(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -235,8 +216,6 @@ static int SetSoundVolume(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int SetSoundPanning(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -248,8 +227,6 @@ static int SetSoundPanning(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int PauseSound(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -261,8 +238,6 @@ static int PauseSound(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int ResumeSound(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -274,8 +249,6 @@ static int ResumeSound(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int StopSound(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -287,8 +260,6 @@ static int StopSound(lua_State *L) {
return 0;
}
-// -----------------------------------------------------------------------------
-
static int IsSoundPaused(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -300,8 +271,6 @@ static int IsSoundPaused(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int IsSoundPlaying(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -313,8 +282,6 @@ static int IsSoundPlaying(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int GetSoundVolume(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -326,8 +293,6 @@ static int GetSoundVolume(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static int GetSoundPanning(lua_State *L) {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
@@ -339,8 +304,6 @@ static int GetSoundPanning(lua_State *L) {
return 1;
}
-// -----------------------------------------------------------------------------
-
static const char *SFX_LIBRARY_NAME = "Sfx";
static const luaL_reg SFX_FUNCTIONS[] = {
@@ -373,8 +336,6 @@ static const lua_constant_reg SFX_CONSTANTS[] = {
{0, 0}
};
-// -----------------------------------------------------------------------------
-
bool SoundEngine::_RegisterScriptBindings() {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);