-added looping of banner wav sound files (its not 100% exact as you

will hear but better than no looping at all)
This commit is contained in:
fix94.1 2012-08-11 19:47:13 +00:00
parent efaa4ea569
commit 7e9fd00e83
4 changed files with 47 additions and 0 deletions

View File

@ -130,6 +130,12 @@ void SoundDecoder::Decode()
Rewind(); Rewind();
continue; continue;
} }
else if(LoopStart)
{
Rewind();
CurPos = LoopStart;
continue;
}
else else
{ {
EndOfFile = true; EndOfFile = true;

View File

@ -68,6 +68,7 @@ public:
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); }; virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
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 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); };
@ -82,6 +83,7 @@ protected:
int SoundBlockSize; int SoundBlockSize;
int CurPos; int CurPos;
bool Loop; bool Loop;
int LoopStart;
bool EndOfFile; bool EndOfFile;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;

View File

@ -121,6 +121,22 @@ void WavDecoder::OpenFile()
else if(le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4) else if(le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
Format = VOICE_STEREO_16BIT; Format = VOICE_STEREO_16BIT;
SWaveChunk LoopChunk;
SWaveSmplChunk SmplChunk;
SmplChunk.Start = 0;
file_fd->seek(DataOffset + DataSize, SEEK_SET);
while(file_fd->read((u8 *)&LoopChunk, sizeof(SWaveChunk)) == sizeof(SWaveChunk))
{
if(LoopChunk.magicDATA == 'smpl')
{
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) + 8091) & ~8091;
break;
}
file_fd->seek(le32(LoopChunk.size), SEEK_CUR);
}
SetLoopStart(SmplChunk.Start);
Decode(); Decode();
} }

View File

@ -53,6 +53,29 @@ typedef struct
u32 size; u32 size;
} SWaveChunk; } SWaveChunk;
typedef struct
{
u32 magicDATA;
u32 size;
/* Bleh */
u32 Manufacturer;
u32 Product;
u32 SamplePeriod;
u32 MIDIUnityNote;
u32 MIDIPitchFraction;
u32 SMPTEFormat;
u32 SMPTEOffset;
u32 SampleLoops;
u32 SamplerData;
/* The important stuff */
u32 Identifier;
u32 Type;
u32 Start;
u32 End;
u32 Fraction;
u32 PlayCount;
} SWaveSmplChunk;
class WavDecoder : public SoundDecoder class WavDecoder : public SoundDecoder
{ {
public: public: