Keep video in sync with audio

This commit is contained in:
Paul Chote
2010-08-11 23:02:45 +12:00
parent ca6debde66
commit b88512df43
2 changed files with 42 additions and 29 deletions

View File

@@ -109,11 +109,15 @@ namespace OpenRA.FileFormats
CollectAudioData();
// Load the first frame
currentFrame = 0;
AdvanceFrame();
Reset();
}
public void Reset()
{
currentFrame = cbOffset = cbChunk = 0;
LoadFrame();
}
void CollectAudioData()
{
var ms = new MemoryStream();
@@ -147,9 +151,18 @@ namespace OpenRA.FileFormats
audioData = AudLoader.LoadSound(ms.ToArray(), ref adpcmIndex);
}
public void AdvanceFrame()
{
currentFrame++;
LoadFrame();
}
void LoadFrame()
{
if (currentFrame >= Frames)
return;
// Seek to the start of the frame
stream.Seek(offsets[currentFrame], SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
@@ -176,8 +189,6 @@ namespace OpenRA.FileFormats
// Chunks are aligned on even bytes; advance by a byte if the next one is null
if (reader.PeekChar() == 0) reader.ReadByte();
}
if (++currentFrame == Frames)
currentFrame = cbOffset = cbChunk = 0;
}
// VQA Frame