index ab799510d62777515048b071d79121e671cd84e7..e0b41e392fd078be32895fd36cc3d709bf891dce 100644 (file)
TOpusLoader = class (TSoundLoader)
public
TOpusLoader = class (TSoundLoader)
public
- function Load(Data: Pointer; Len: LongWord; SStreaming: Boolean): Boolean; override; overload;
- function Load(FName: string; SStreaming: Boolean): Boolean; override; overload;
- function SetPosition(Pos: LongWord): Boolean; override;
+ function Load(Data: Pointer; Len: LongWord; Loop: Boolean): Boolean; override; overload;
+ function Load(FName: string; Loop: Boolean): Boolean; override; overload;
+ function Finished(): Boolean; override;
+ function Restart(): Boolean; override;
function FillBuffer(Buf: Pointer; Len: LongWord): LongWord; override;
function FillBuffer(Buf: Pointer; Len: LongWord): LongWord; override;
- function GetAll(var OutPtr: Pointer): LongWord; override;
procedure Free(); override;
private
FOpus: POggOpusFile;
FBuf: Pointer;
procedure Free(); override;
private
FOpus: POggOpusFile;
FBuf: Pointer;
+ FFinished: Boolean;
+ FLooping: Boolean;
end;
TOpusLoaderFactory = class (TSoundLoaderFactory)
end;
TOpusLoaderFactory = class (TSoundLoaderFactory)
(* TOpusLoader *)
(* TOpusLoader *)
-function TOpusLoader.Load(Data: Pointer; Len: LongWord; SStreaming: Boolean): Boolean;
+function TOpusLoader.Load(Data: Pointer; Len: LongWord; Loop: Boolean): Boolean;
begin
Result := False;
begin
Result := False;
FFormat.SampleBits := 16;
FFormat.SampleRate := 48000; // is this even correct?
FStreaming := True; // opus is always streaming
FFormat.SampleBits := 16;
FFormat.SampleRate := 48000; // is this even correct?
FStreaming := True; // opus is always streaming
+ FFinished := False;
+ FLooping := Loop;
Result := True;
end;
Result := True;
end;
-function TOpusLoader.Load(FName: string; SStreaming: Boolean): Boolean;
+function TOpusLoader.Load(FName: string; Loop: Boolean): Boolean;
begin
Result := False;
begin
Result := False;
FFormat.SampleBits := 16;
FFormat.SampleRate := 48000; // is this even correct?
FStreaming := True; // opus is always streaming
FFormat.SampleBits := 16;
FFormat.SampleRate := 48000; // is this even correct?
FStreaming := True; // opus is always streaming
+ FFinished := False;
+ FLooping := Loop;
Result := True;
end;
Result := True;
end;
-function TOpusLoader.SetPosition(Pos: LongWord): Boolean;
+function TOpusLoader.Finished(): Boolean;
+begin
+ Result := FFinished;
+end;
+
+function TOpusLoader.Restart(): Boolean;
begin
Result := False;
if (FOpus = nil) or (op_seekable(FOpus) = 0) then Exit;
begin
Result := False;
if (FOpus = nil) or (op_seekable(FOpus) = 0) then Exit;
- Result := op_pcm_seek(FOpus, Pos) = 0;
+ Result := op_pcm_seek(FOpus, 0) = 0;
+ FFinished := False;
end;
function TOpusLoader.FillBuffer(Buf: Pointer; Len: LongWord): LongWord;
end;
function TOpusLoader.FillBuffer(Buf: Pointer; Len: LongWord): LongWord;
Ret := op_read_stereo(FOpus, Buf + Rx, (Len - Rx) div 2);
if Ret = OP_HOLE then continue;
if Ret < 0 then break;
Ret := op_read_stereo(FOpus, Buf + Rx, (Len - Rx) div 2);
if Ret = OP_HOLE then continue;
if Ret < 0 then break;
- if FLooping and (Ret = 0) then op_pcm_seek(FOpus, 0); // loop
+ if Ret = 0 then
+ begin
+ if FLooping then
+ op_pcm_seek(FOpus, 0)
+ else
+ begin
+ FFinished := True;
+ break;
+ end;
+ end;
Rx := Rx + Ret * 4;
end;
Result := Rx;
end;
Rx := Rx + Ret * 4;
end;
Result := Rx;
end;
-function TOpusLoader.GetAll(var OutPtr: Pointer): LongWord;
-begin
- Result := 0; // always streaming
-end;
-
procedure TOpusLoader.Free();
begin
if FOpus <> nil then
procedure TOpusLoader.Free();
begin
if FOpus <> nil then
FOpus := nil;
FBuf := nil;
FStreaming := False;
FOpus := nil;
FBuf := nil;
FStreaming := False;
+ FFinished := False;
+ FLooping := False;
end;
initialization
end;
initialization