[Scummvm-cvs-logs] SF.net SVN: scummvm:[53366] scummvm/trunk/engines/sword25/sfx

sev at users.sourceforge.net sev at users.sourceforge.net
Wed Oct 13 01:56:07 CEST 2010


Revision: 53366
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53366&view=rev
Author:   sev
Date:     2010-10-12 23:56:07 +0000 (Tue, 12 Oct 2010)

Log Message:
-----------
SWORD25: Initial work on sound

Modified Paths:
--------------
    scummvm/trunk/engines/sword25/sfx/soundengine.cpp
    scummvm/trunk/engines/sword25/sfx/soundengine.h

Modified: scummvm/trunk/engines/sword25/sfx/soundengine.cpp
===================================================================
--- scummvm/trunk/engines/sword25/sfx/soundengine.cpp	2010-10-12 23:55:44 UTC (rev 53365)
+++ scummvm/trunk/engines/sword25/sfx/soundengine.cpp	2010-10-12 23:56:07 UTC (rev 53366)
@@ -35,7 +35,10 @@
 #define BS_LOG_PREFIX "SOUNDENGINE"
 
 #include "sword25/sfx/soundengine.h"
+#include "sword25/package/packagemanager.h"
 
+#include "sound/decoders/vorbis.h"
+
 namespace Sword25 {
 
 SoundEngine::SoundEngine(Kernel *pKernel) : ResourceService(pKernel) {
@@ -45,6 +48,9 @@
 		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::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;
 }
 

Modified: scummvm/trunk/engines/sword25/sfx/soundengine.h
===================================================================
--- scummvm/trunk/engines/sword25/sfx/soundengine.h	2010-10-12 23:55:44 UTC (rev 53365)
+++ scummvm/trunk/engines/sword25/sfx/soundengine.h	2010-10-12 23:56:07 UTC (rev 53366)
@@ -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,10 +57,20 @@
 
 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 @@
 
 private:
 	bool _RegisterScriptBindings();
+	SndHandle *getHandle(uint *id);
 
 private:
 	Audio::Mixer *_mixer;
+	SndHandle _handles[SOUND_HANDLES];
 };
 
 } // End of namespace Sword25


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list