DEADSOFTWARE

Sound: Initial OpenAL driver impl
[d2df-sdl.git] / src / engine / e_soundfile.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit e_soundfile;
19 interface
21 type
22 TSoundLoader = class;
24 TSoundFormat = record
25 Loader: TSoundLoader;
26 SampleBits: Integer;
27 SampleRate: Integer;
28 Channels: Integer;
29 end;
31 // each sound file format has its own loader
32 // TODO: maybe make TBasicSound contain an instance of its loader
33 // and add a FetchSamples method or something, for streaming shit
34 TSoundLoader = class
35 public
36 // can this loader load the sound file in Data?
37 function CanLoad(Data: Pointer; Len: Integer): Boolean; virtual; abstract; overload;
38 // can this loader load the sound file at FName?
39 function CanLoad(FName: string): Boolean; virtual; abstract; overload;
40 // load from memory
41 function Load(Data: Pointer; Len: Integer; var OutLen: Integer; var OutFmt: TSoundFormat): Pointer; virtual; abstract; overload;
42 // load from file
43 function Load(FName: string; var OutLen: Integer; var OutFmt: TSoundFormat): Pointer; virtual; abstract; overload;
44 // needed in case memory is allocated in a lib or something
45 procedure Free(Data: Pointer); virtual; abstract;
46 end;
48 function e_GetSoundLoader(Data: Pointer; Len: Integer): TSoundLoader; overload;
49 function e_GetSoundLoader(FName: string): TSoundLoader; overload;
51 procedure e_AddSoundLoader(Loader: TSoundLoader);
53 implementation
55 var
56 e_SoundLoaders: array of TSoundLoader;
58 function e_GetSoundLoader(FName: string): TSoundLoader; overload;
59 var
60 I: Integer;
61 begin
62 Result := nil;
63 for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
64 if e_SoundLoaders[I].CanLoad(FName) then
65 begin
66 Result := e_SoundLoaders[I];
67 break;
68 end;
69 end;
71 function e_GetSoundLoader(Data: Pointer; Len: Integer): TSoundLoader; overload;
72 var
73 I: Integer;
74 begin
75 Result := nil;
76 for I := Low(e_SoundLoaders) to High(e_SoundLoaders) do
77 if e_SoundLoaders[I].CanLoad(Data, Len) then
78 begin
79 Result := e_SoundLoaders[I];
80 break;
81 end;
82 end;
84 procedure e_AddSoundLoader(Loader: TSoundLoader);
85 begin
86 SetLength(e_SoundLoaders, Length(e_SoundLoaders) + 1);
87 e_SoundLoaders[High(e_SoundLoaders)] := Loader;
88 end;
90 end.