-improved wav banner sound loop support

This commit is contained in:
fix94.1 2012-08-31 20:01:53 +00:00
parent db0ca2e965
commit dcdf6ceb10
3 changed files with 9 additions and 7 deletions

View File

@ -66,6 +66,7 @@ void SoundDecoder::Init()
SoundBlockSize = 8192; SoundBlockSize = 8192;
CurPos = 0; CurPos = 0;
LoopStart = 0; LoopStart = 0;
LoopEnd = 0;
Loop = false; Loop = false;
EndOfFile = false; EndOfFile = false;
Decoding = false; Decoding = false;
@ -126,15 +127,11 @@ void SoundDecoder::Decode()
if(ret <= 0) if(ret <= 0)
{ {
if(Loop) if(Loop || LoopStart || LoopEnd)
{ {
Rewind(); Rewind();
continue; if(LoopStart)
} CurPos = LoopStart;
else if(LoopStart)
{
Rewind();
CurPos = LoopStart;
continue; continue;
} }
else else

View File

@ -69,6 +69,7 @@ public:
virtual bool IsEOF() { return EndOfFile; }; virtual bool IsEOF() { return EndOfFile; };
virtual void SetLoop(bool l) { Loop = l; }; virtual void SetLoop(bool l) { Loop = l; };
virtual void SetLoopStart(int s) { LoopStart = s; }; virtual void SetLoopStart(int s) { LoopStart = s; };
virtual void SetLoopEnd(int e) { LoopEnd = e; };
virtual u8 GetSoundType() { return SoundType; }; virtual u8 GetSoundType() { return SoundType; };
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); }; virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); }; virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
@ -84,6 +85,7 @@ protected:
int CurPos; int CurPos;
bool Loop; bool Loop;
int LoopStart; int LoopStart;
int LoopEnd;
bool EndOfFile; bool EndOfFile;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;

View File

@ -124,6 +124,7 @@ void WavDecoder::OpenFile()
SWaveChunk LoopChunk; SWaveChunk LoopChunk;
SWaveSmplChunk SmplChunk; SWaveSmplChunk SmplChunk;
SmplChunk.Start = 0; SmplChunk.Start = 0;
SmplChunk.End = 0;
file_fd->seek(DataOffset + DataSize, SEEK_SET); file_fd->seek(DataOffset + DataSize, SEEK_SET);
while(file_fd->read((u8 *)&LoopChunk, sizeof(SWaveChunk)) == sizeof(SWaveChunk)) 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->seek(-8, SEEK_CUR);
file_fd->read((u8*)&SmplChunk, sizeof(SWaveSmplChunk)); file_fd->read((u8*)&SmplChunk, sizeof(SWaveSmplChunk));
SmplChunk.Start = ((le32(SmplChunk.Start) * le16(FmtChunk.channels) * le16(FmtChunk.bps) / 8) + 8191) & ~8191; 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; break;
} }
file_fd->seek(le32(LoopChunk.size), SEEK_CUR); file_fd->seek(le32(LoopChunk.size), SEEK_CUR);
} }
SetLoopStart(SmplChunk.Start); SetLoopStart(SmplChunk.Start);
SetLoopEnd(SmplChunk.End);
Decode(); Decode();
} }