aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/sfx/fmodexchannel.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2010-07-29 19:53:02 +0000
committerEugene Sandulenko2010-10-12 21:38:20 +0000
commita683a420a9e43705c972b5e74d55e319729e1a81 (patch)
treebde6e4abd417bdfaec120aa951da9a19be36b654 /engines/sword25/sfx/fmodexchannel.cpp
parent7723d91c957d07205c51be32498d45cd0a78568f (diff)
downloadscummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.tar.gz
scummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.tar.bz2
scummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.zip
SWORD25: Importing original sources
svn-id: r53171
Diffstat (limited to 'engines/sword25/sfx/fmodexchannel.cpp')
-rwxr-xr-xengines/sword25/sfx/fmodexchannel.cpp299
1 files changed, 299 insertions, 0 deletions
diff --git a/engines/sword25/sfx/fmodexchannel.cpp b/engines/sword25/sfx/fmodexchannel.cpp
new file mode 100755
index 0000000000..88ad9640c5
--- /dev/null
+++ b/engines/sword25/sfx/fmodexchannel.cpp
@@ -0,0 +1,299 @@
+// -----------------------------------------------------------------------------
+// This file is part of Broken Sword 2.5
+// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
+//
+// Broken Sword 2.5 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.
+//
+// Broken Sword 2.5 is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Broken Sword 2.5; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+// -----------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------
+// Logging
+// -----------------------------------------------------------------------------
+
+#define BS_LOG_PREFIX "FMODEXCHANNEL"
+
+// -----------------------------------------------------------------------------
+// Includes
+// -----------------------------------------------------------------------------
+
+#include "fmod.h"
+#include "fmodexexception.h"
+#include "fmodexchannel.h"
+
+// -----------------------------------------------------------------------------
+// Konstruktion / Destruktion
+// -----------------------------------------------------------------------------
+
+BS_FMODExChannel::BS_FMODExChannel(FMOD_CHANNEL * ChannelPtr, FMOD_SOUND * SoundPtr) :
+ m_ChannelPtr(ChannelPtr),
+ m_SoundPtr(SoundPtr)
+{
+}
+
+// -----------------------------------------------------------------------------
+
+BS_FMODExChannel::~BS_FMODExChannel()
+{
+ if (m_ChannelPtr) FMOD_Channel_Stop(m_ChannelPtr);
+ if (m_SoundPtr) FMOD_Sound_Release(m_SoundPtr);
+}
+
+// -----------------------------------------------------------------------------
+// FMOD Ex macht alle Kanäle ungültig, sobald sie nicht mehr abgespielt werden,
+// oder wenn der Kanal in der zwischenzeit neu vergeben wurde.
+// Dann führen alle Aufrufe von Funktionen dieser Kanäle zu dem Fehlern
+// FMOD_ERR_INVALID_HANDLE oder FMOD_ERR_CHANNEL_STOLEN
+// Dieses Soundsystem entfernt aber nur jeden Frame alle toten Kanäle. Daher
+// kann es vorkommen, dass an einem bereits toten Kanal Aufrufe getätigt werden.
+// Diese Fehler werden daher von den folgenden Methoden ignoriert.
+// -----------------------------------------------------------------------------
+
+namespace
+{
+ bool IsImportantError(FMOD_RESULT Result)
+ {
+ return Result != FMOD_OK && Result != FMOD_ERR_INVALID_HANDLE && Result != FMOD_ERR_CHANNEL_STOLEN;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Setter
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetPaused(bool Paused)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetPaused(m_ChannelPtr, Paused ? 1 : 0);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetPaused()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetVolume(float Volume)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetVolume(m_ChannelPtr, Volume);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetVolume()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetPanning(float Panning)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetPan(m_ChannelPtr, Panning);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetPan()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetLoop(bool Loop)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetLoopCount(m_ChannelPtr, Loop ? -1 : 0);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetLoopCount()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetLoopPoints(unsigned int LoopStart, unsigned int LoopEnd)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetLoopPoints(m_ChannelPtr, LoopStart, FMOD_TIMEUNIT_PCM, LoopEnd, FMOD_TIMEUNIT_PCM);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetLoopPoints()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::SetPosition(unsigned int Position)
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_SetPosition(m_ChannelPtr, Position, FMOD_TIMEUNIT_PCM);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_SetPosition()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::Stop()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_RESULT Result = FMOD_Channel_Stop(m_ChannelPtr);
+ if (IsImportantError(Result))
+ {
+ BS_FMODExException("FMOD_Channel_Stop()", Result).Log();
+ return false;
+ }
+ else
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+// Getter
+// -----------------------------------------------------------------------------
+
+float BS_FMODExChannel::GetVolume()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ float Volume = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetVolume(m_ChannelPtr, &Volume);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetVolume()", Result).Log();
+
+ return Volume;
+}
+
+// -----------------------------------------------------------------------------
+
+float BS_FMODExChannel::GetPanning()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ float Panning = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetPan(m_ChannelPtr, &Panning);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetPan()", Result).Log();
+
+ return Panning;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int BS_FMODExChannel::GetPosition()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ unsigned int Position = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetPosition(m_ChannelPtr, &Position, FMOD_TIMEUNIT_PCM);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetPosition()", Result).Log();
+
+ return Position;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int BS_FMODExChannel::GetTime()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ unsigned int Time = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetPosition(m_ChannelPtr, &Time, FMOD_TIMEUNIT_MS);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetPosition()", Result).Log();
+
+ return Time;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int BS_FMODExChannel::GetLoopStart()
+{
+ BS_ASSERT(m_ChannelPtr);
+ unsigned int LoopStart = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetLoopPoints(m_ChannelPtr, &LoopStart, FMOD_TIMEUNIT_PCM, 0, FMOD_TIMEUNIT_PCM);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetLoopPoints()", Result).Log();
+
+ return LoopStart;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int BS_FMODExChannel::GetLoopEnd()
+{
+ BS_ASSERT(m_ChannelPtr);
+ unsigned int LoopEnd = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetLoopPoints(m_ChannelPtr, 0, FMOD_TIMEUNIT_PCM, &LoopEnd, FMOD_TIMEUNIT_PCM);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetLoopPoints()", Result).Log();
+
+ return LoopEnd;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::IsLooping()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ int LoopCount = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetLoopCount(m_ChannelPtr, &LoopCount);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetLoopCount()", Result).Log();
+
+ return LoopCount == -1;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::IsPaused()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_BOOL Paused = 0;
+ FMOD_RESULT Result = FMOD_Channel_GetPaused(m_ChannelPtr, &Paused);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_GetPaused()", Result).Log();
+
+ return Paused != 0;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_FMODExChannel::IsPlaying()
+{
+ BS_ASSERT(m_ChannelPtr);
+
+ FMOD_BOOL Playing = 0;
+ FMOD_RESULT Result = FMOD_Channel_IsPlaying(m_ChannelPtr, &Playing);
+ if (IsImportantError(Result)) BS_FMODExException("FMOD_Channel_IsPlaying()", Result).Log();
+
+ return Playing != 0;
+}