From dcdf6ceb104b305703fb6ee09d512c966455ac01 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Fri, 31 Aug 2012 20:01:53 +0000 Subject: [PATCH] -improved wav banner sound loop support --- source/music/SoundDecoder.cpp | 11 ++++------- source/music/SoundDecoder.hpp | 2 ++ source/music/WavDecoder.cpp | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/music/SoundDecoder.cpp b/source/music/SoundDecoder.cpp index 08f616e8..35d8707a 100644 --- a/source/music/SoundDecoder.cpp +++ b/source/music/SoundDecoder.cpp @@ -66,6 +66,7 @@ void SoundDecoder::Init() SoundBlockSize = 8192; CurPos = 0; LoopStart = 0; + LoopEnd = 0; Loop = false; EndOfFile = false; Decoding = false; @@ -126,15 +127,11 @@ void SoundDecoder::Decode() if(ret <= 0) { - if(Loop) + if(Loop || LoopStart || LoopEnd) { Rewind(); - continue; - } - else if(LoopStart) - { - Rewind(); - CurPos = LoopStart; + if(LoopStart) + CurPos = LoopStart; continue; } else diff --git a/source/music/SoundDecoder.hpp b/source/music/SoundDecoder.hpp index 3f017419..972b33fd 100644 --- a/source/music/SoundDecoder.hpp +++ b/source/music/SoundDecoder.hpp @@ -69,6 +69,7 @@ public: virtual bool IsEOF() { return EndOfFile; }; virtual void SetLoop(bool l) { Loop = l; }; virtual void SetLoopStart(int s) { LoopStart = s; }; + virtual void SetLoopEnd(int e) { LoopEnd = e; }; virtual u8 GetSoundType() { return SoundType; }; virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); }; virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); }; @@ -84,6 +85,7 @@ protected: int CurPos; bool Loop; int LoopStart; + int LoopEnd; bool EndOfFile; bool Decoding; bool ExitRequested; diff --git a/source/music/WavDecoder.cpp b/source/music/WavDecoder.cpp index 33f3ffad..0607db7f 100644 --- a/source/music/WavDecoder.cpp +++ b/source/music/WavDecoder.cpp @@ -124,6 +124,7 @@ void WavDecoder::OpenFile() SWaveChunk LoopChunk; SWaveSmplChunk SmplChunk; SmplChunk.Start = 0; + SmplChunk.End = 0; file_fd->seek(DataOffset + DataSize, SEEK_SET); while(file_fd->read((u8 *)&LoopChunk, sizeof(SWaveChunk)) == sizeof(SWaveChunk)) { @@ -132,11 +133,13 @@ void WavDecoder::OpenFile() file_fd->seek(-8, SEEK_CUR); file_fd->read((u8*)&SmplChunk, sizeof(SWaveSmplChunk)); SmplChunk.Start = ((le32(SmplChunk.Start) * le16(FmtChunk.channels) * le16(FmtChunk.bps) / 8) + 8191) & ~8191; + SmplChunk.End = ((le32(SmplChunk.End) * le16(FmtChunk.channels) * le16(FmtChunk.bps) / 8) + 8191) & ~8191; break; } file_fd->seek(le32(LoopChunk.size), SEEK_CUR); } SetLoopStart(SmplChunk.Start); + SetLoopEnd(SmplChunk.End); Decode(); }