-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;
CurPos = 0;
LoopStart = 0;
LoopEnd = 0;
Loop = false;
EndOfFile = false;
Decoding = false;
@ -126,14 +127,10 @@ void SoundDecoder::Decode()
if(ret <= 0)
{
if(Loop)
{
Rewind();
continue;
}
else if(LoopStart)
if(Loop || LoopStart || LoopEnd)
{
Rewind();
if(LoopStart)
CurPos = LoopStart;
continue;
}

View File

@ -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;

View File

@ -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();
}