index df4aa45dfa2c04a01b4e8b4af2c601b7a032c748..c508593235bc070b10a2d348efcc7942131e4885 100644 (file)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
TSoundLoader = class;
TSoundFormat = record
TSoundLoader = class;
TSoundFormat = record
- Loader: TSoundLoader;
SampleBits: Integer;
SampleRate: Integer;
Channels: Integer;
end;
SampleBits: Integer;
SampleRate: Integer;
Channels: Integer;
end;
- // each sound file format has its own loader
- // TODO: maybe make TBasicSound contain an instance of its loader
- // and add a FetchSamples method or something, for streaming shit
+ // each sound file format has its own loader factory and loader class,
+ // each sound has its own loader instance for streaming purposes
+
TSoundLoader = class
TSoundLoader = class
+ protected
+ FFormat: TSoundFormat;
+ FStreaming: Boolean;
+
+ public
+ function Load(Data: Pointer; Len: LongWord; Loop: Boolean): Boolean; virtual; abstract; overload;
+ function Load(FName: string; Loop: Boolean): Boolean; virtual; abstract; overload;
+
+ function Finished(): Boolean; virtual; abstract;
+ function Restart(): Boolean; virtual; abstract;
+ function FillBuffer(Buf: Pointer; Len: LongWord): LongWord; virtual; abstract;
+
+ procedure Free(); virtual; abstract;
+
+ property Format: TSoundFormat read FFormat;
+ property Streaming: Boolean read FStreaming;
+ end;
+
+ TSoundLoaderFactory = class
public
public
- // can this loader load the sound file in Data?
- function CanLoad(Data: Pointer; Len: Integer): Boolean; virtual; abstract; overload;
- // can this loader load the sound file at FName?
- function CanLoad(FName: string): Boolean; virtual; abstract; overload;
- // load from memory
- function Load(Data: Pointer; Len: Integer; var OutLen: Integer; var OutFmt: TSoundFormat): Pointer; virtual; abstract; overload;
- // load from file
- function Load(FName: string; var OutLen: Integer; var OutFmt: TSoundFormat): Pointer; virtual; abstract; overload;
- // needed in case memory is allocated in a lib or something
- procedure Free(Data: Pointer); virtual; abstract;
+ function MatchHeader(Data: Pointer; Len: LongWord): Boolean; virtual; abstract;
+ function MatchExtension(FName: string): Boolean; virtual; abstract;
+ function GetLoader(): TSoundLoader; virtual; abstract;
end;
end;
-function e_GetSoundLoader(Data: Pointer; Len: Integer): TSoundLoader; overload;
+function e_GetSoundLoader(Data: Pointer; Len: LongWord): TSoundLoader; overload;
function e_GetSoundLoader(FName: string): TSoundLoader; overload;
function e_GetSoundLoader(FName: string): TSoundLoader; overload;
-procedure e_AddSoundLoader(Loader: TSoundLoader);
+procedure e_AddSoundLoader(Loader: TSoundLoaderFactory);
implementation
var
implementation
var
- e_SoundLoaders: array of TSoundLoader;
+ e_SoundLoaders: array of TSoundLoaderFactory;
function e_GetSoundLoader(FName: string): TSoundLoader; overload;
var
function e_GetSoundLoader(FName: string): TSoundLoader; overload;
var
begin
Result := nil;
for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
begin
Result := nil;
for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
- if e_SoundLoaders[I].CanLoad(FName) then
+ if e_SoundLoaders[I].MatchExtension(FName) then
begin
begin
- Result := e_SoundLoaders[I];
+ Result := e_SoundLoaders[I].GetLoader();
break;
end;
end;
break;
end;
end;
-function e_GetSoundLoader(Data: Pointer; Len: Integer): TSoundLoader; overload;
+function e_GetSoundLoader(Data: Pointer; Len: LongWord): TSoundLoader; overload;
var
I: Integer;
begin
Result := nil;
for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
var
I: Integer;
begin
Result := nil;
for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
- if e_SoundLoaders[I].CanLoad(Data, Len) then
+ if e_SoundLoaders[I].MatchHeader(Data, Len) then
begin
begin
- Result := e_SoundLoaders[I];
+ Result := e_SoundLoaders[I].GetLoader();
break;
end;
end;
break;
end;
end;
-procedure e_AddSoundLoader(Loader: TSoundLoader);
+procedure e_AddSoundLoader(Loader: TSoundLoaderFactory);
begin
SetLength(e_SoundLoaders, Length(e_SoundLoaders) + 1);
e_SoundLoaders[High(e_SoundLoaders)] := Loader;
begin
SetLength(e_SoundLoaders, Length(e_SoundLoaders) + 1);
e_SoundLoaders[High(e_SoundLoaders)] := Loader;