Changed on 23th June 2004:
Resynchronization was quite easy to do as I already had two overloaded methods called ReadFromStream which return TRUE if a valid frame (valid header) was found at the actual or passed stream position.
So I added a third one and here's the code:
function TMPEGAudioFrame.ReadFromStream(Stream: TStream; Offset,
SyncDistance, SubsequentFrames: Integer): Boolean;
var Frames: Integer;
Distance: Integer;
FramesSize: Integer;
begin
Distance := 0;
Frames := 0;
while (Frames < SubsequentFrames) and (Distance < SyncDistance) do begin
Frames := 0;
FramesSize := 0;
while (ReadFromStream(Stream, Offset+Distance+FramesSize)) and (Frames < SubsequentFrames) do begin
inc(Frames);
inc(FramesSize,Header.FrameSize);
end;
if (Frames = SubsequentFrames)
then ReadFromStream(Stream, Offset+Distance)
else inc(Distance);
end;
end;
As you can see you can set the maximum resync distance in the SyncDistance parameter and the number of subsequent valid frames to check in the SubsequentFrames parameter. Old TMPEGaudio tries to read two subsequent valid frames, I suggest searching for three frames and will do so in the new TMPEGAudio component.