1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
29 // each sound file format has its own loader factory and loader class,
30 // each sound has its own loader instance for streaming purposes
34 FFormat
: TSoundFormat
;
39 function Load(Data
: Pointer; Len
: LongWord; SStreaming
: Boolean): Boolean; virtual; abstract; overload
;
40 function Load(FName
: string; SStreaming
: Boolean): Boolean; virtual; abstract; overload
;
42 function SetPosition(Pos
: LongWord): Boolean; virtual; abstract;
43 function FillBuffer(Buf
: Pointer; Len
: LongWord): LongWord; virtual; abstract;
45 function GetAll(var OutPtr
: Pointer): LongWord; virtual; abstract;
47 procedure Free(); virtual; abstract;
49 property Format
: TSoundFormat read FFormat
;
50 property Streaming
: Boolean read FStreaming
;
51 property Looping
: Boolean read FLooping write FLooping
;
54 TSoundLoaderFactory
= class
56 function MatchHeader(Data
: Pointer; Len
: LongWord): Boolean; virtual; abstract;
57 function MatchExtension(FName
: string): Boolean; virtual; abstract;
58 function GetLoader(): TSoundLoader
; virtual; abstract;
61 function e_GetSoundLoader(Data
: Pointer; Len
: LongWord): TSoundLoader
; overload
;
62 function e_GetSoundLoader(FName
: string): TSoundLoader
; overload
;
64 procedure e_AddSoundLoader(Loader
: TSoundLoaderFactory
);
69 e_SoundLoaders
: array of TSoundLoaderFactory
;
71 function e_GetSoundLoader(FName
: string): TSoundLoader
; overload
;
76 for I
:= Low(e_SoundLoaders
) to High(e_SoundLoaders
) do
77 if e_SoundLoaders
[I
].MatchExtension(FName
) then
79 Result
:= e_SoundLoaders
[I
].GetLoader();
84 function e_GetSoundLoader(Data
: Pointer; Len
: LongWord): TSoundLoader
; overload
;
89 for I
:= Low(e_SoundLoaders
) to High(e_SoundLoaders
) do
90 if e_SoundLoaders
[I
].MatchHeader(Data
, Len
) then
92 Result
:= e_SoundLoaders
[I
].GetLoader();
97 procedure e_AddSoundLoader(Loader
: TSoundLoaderFactory
);
99 SetLength(e_SoundLoaders
, Length(e_SoundLoaders
) + 1);
100 e_SoundLoaders
[High(e_SoundLoaders
)] := Loader
;