changeset 484:e584b0b8b4a2

Added SoundEmitter::getDecodedLength and SoundEmitter::getDuration. The getDuration function will allow a timer to be registered to fire after the sound has been played. This is not a callback as requested but it does provide the functionality if required. I will be committing an example of it in the shooter demo shortly. [t:346]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 30 Apr 2010 15:33:27 +0000
parents 82d44c471959
children d365eb58f3d6
files engine/core/audio/soundemitter.h engine/core/audio/soundemitter.i engine/core/util/time/timeevent.cpp
diffstat 3 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/audio/soundemitter.h	Thu Apr 29 16:09:56 2010 +0000
+++ b/engine/core/audio/soundemitter.h	Fri Apr 30 15:33:27 2010 +0000
@@ -165,6 +165,31 @@
 			return 0;
 		}
 
+		/** Returns the length of the decoded length in bytes
+		 */
+		unsigned long getDecodedLength() const{
+			if (m_soundclip) {
+				return m_soundclip->getDecoder()->getDecodedLength();
+
+			}
+			return 0;
+		}
+
+		/** Returns the duration of the sound clip in milliseconds
+		 */
+		unsigned long getDuration() const{
+			if (m_soundclip) {
+				float samplerate = static_cast<float>(getSampleRate());
+				float bitres = static_cast<float>(getBitResolution());
+				float size = static_cast<float>(getDecodedLength());
+				float stereo = (isStereo() ? 2.0f : 1.0f);
+				float time = (( size / samplerate * bitres / 8.0f) * 1000.0f ) / stereo / 2.0f;
+
+				return static_cast<unsigned long>(time);
+			}
+			return 0;
+		 }
+
 		/** Sets the cursor position in the audio file
 		 */
 		void setCursor(SoundPositionType type, float value);
--- a/engine/core/audio/soundemitter.i	Thu Apr 29 16:09:56 2010 +0000
+++ b/engine/core/audio/soundemitter.i	Fri Apr 30 15:33:27 2010 +0000
@@ -63,6 +63,8 @@
 		bool isStereo();
 		short getBitResolution();
 		unsigned long getSampleRate();
+		unsigned long getDecodedLength();
+		unsigned long getDuration();
 
 		void setCursor(SoundPositionType type, float value);
 		float getCursor(SoundPositionType type);
--- a/engine/core/util/time/timeevent.cpp	Thu Apr 29 16:09:56 2010 +0000
+++ b/engine/core/util/time/timeevent.cpp	Fri Apr 30 15:33:27 2010 +0000
@@ -29,13 +29,14 @@
 // These includes are split up in two parts, separated by one empty line
 // First block: files included from the FIFE root src directory
 // Second block: files included from the same folder
+#include "timemanager.h"
 #include "timeevent.h"
 
 namespace FIFE {
 
 	TimeEvent::TimeEvent(int period):
 		m_period(period),
-		m_last_updated(SDL_GetTicks()) {
+		m_last_updated(TimeManager::instance()->getTime()) {
 	}
 
 	TimeEvent::~TimeEvent() {
@@ -47,7 +48,7 @@
 		if (m_period < 0) {
 			return;
 		} else if (m_period == 0 || time_delta >= m_period) {
-			updateEvent(time);
+			updateEvent(time_delta);
 			m_last_updated = time;
 		}
 	}
@@ -68,5 +69,5 @@
 		m_last_updated = ms;
 	}
 
-	
+
 } //FIFE