Mirage is correct.
[pascal]const
P2D_OGG_BUFSIZE = 1024*8;
P2D_THREAD_DELAY = 5; // milliseconds
procedure TOggPlayer.Update;
var
pos : DWORD;
size: DWORD;
buf : pchar;
pbuf: pchar;
sec : Integer;
ret : Integer;
begin
if FDone then Exit;
if FPaused then Exit;
FDSBuffer.GetCurrentPosition(@pos, nil);
//nCurSection = pos<BUFSIZE?0:1;
if pos<P2D_OGG_BUFSIZE then
FCurSection := 0
else
FCurSection := 1;
// section changed?
if (FCurSection <> FLastSection) then
begin
if (FDone = True) and (FLoop = False) then
begin
Stop();
end;
// gotta use this trick 'cause otherwise there wont be played all bits
if (FAlmostDone = True) and (FLoop = False) then
begin
FDone := True;
Stop();
end;
size := P2D_OGG_BUFSIZE;
// fill the section we just left
buf := nil;
FDSBuffer.Lock(FLastSection*P2D_OGG_BUFSIZE, size, @buf, @size, nil, nil, 0 );
pos := 0;
sec := 0;
ret := 1;
while((ret > 0) and (pos<size> 0) and (pos<size)) do
begin
pbuf := buf + pos;
ret := ov_read(FVorbisFile, pbuf^, size-pos, 0, 2, 1, @sec);
inc(pos, ret);
end;
end
else if ((ret = 0) and (FLoop = False)) then
begin
// not looping so fill the rest with 0
while(pos<size) do
begin
pbuf := buf + pos;
pbuf^ := #0;
inc(pos);
end;
// and say that after the current section no other sectin follows
FAlmostDone := True;
end;
FDSBuffer.Unlock( buf, size, nil, 0);
FLastSection := FCurSection;
end;
end;
procedure TOggAudioThread.Execute;
begin
repeat
CriticalSection_Enter;
if Assigned(Audio) then
begin
Audio.Update;
end;
Sleep(P2D_THREAD_DELAY);
CriticalSection_Leave;
until Terminated;
end;[/pascal]
Bookmarks