Mercurial > fife-parpg
diff engine/core/audio/soundemitter.h @ 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 | 64738befdf3b |
children | 7f1c42b66aa4 |
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);