1 | unit AudioSystemFMOD;
|
---|
2 |
|
---|
3 | {$I CoolAudioConfig.inc}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | {$UNDEF AudioSystemFMOD}
|
---|
8 | {$IFDEF AudioSystemFMOD}
|
---|
9 | uses
|
---|
10 | Classes, SysUtils, fmoddyn, fmodtypes, AudioSystem, DateUtils;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TAudioSystemFMOD }
|
---|
15 |
|
---|
16 | TAudioSystemFMOD = class(TAudioSystem)
|
---|
17 | private
|
---|
18 | procedure SetOutputMode(AValue: TOutputDriver); override;
|
---|
19 | public
|
---|
20 | function GetMediaPlayerDriverClass: TMediaPlayerDriverClass; override;
|
---|
21 | constructor Create(AOwner: TComponent); override;
|
---|
22 | destructor Destroy; override;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | { TPlayerFMOD }
|
---|
26 |
|
---|
27 | TPlayerFMOD = class(TMediaPlayerDriver)
|
---|
28 | private
|
---|
29 | FHandle: PFSoundStream;
|
---|
30 | FVolume: Real;
|
---|
31 | function GetLength: TDateTime; override;
|
---|
32 | function GetPosition: TDateTime; override;
|
---|
33 | function GetVolume: Real; override;
|
---|
34 | function GetMuted: Boolean; override;
|
---|
35 | procedure SetPosition(AValue: TDateTime); override;
|
---|
36 | procedure SetVolume(AValue: Real); override;
|
---|
37 | procedure SetMuted(AValue: Boolean); override;
|
---|
38 | public
|
---|
39 | procedure Play; override;
|
---|
40 | procedure Pause; override;
|
---|
41 | procedure Stop; override;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | {$ENDIF}
|
---|
45 |
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | {$IFDEF AudioSystemFMOD}
|
---|
50 |
|
---|
51 | { TAudioSystemFMOD }
|
---|
52 |
|
---|
53 | procedure TAudioSystemFMOD.SetOutputMode(AValue: TOutputDriver);
|
---|
54 | begin
|
---|
55 | inherited SetOutputMode(AValue);
|
---|
56 | {$ifdef linux}
|
---|
57 | if FOutputDriver = omOSS then begin
|
---|
58 | if not FSOUND_SetOutput(FSOUND_OUTPUT_OSS) then EOpenOutputFailed.Create(SOpenOutputFailed);
|
---|
59 | end else
|
---|
60 | if FOutputDriver = omALSA then begin
|
---|
61 | if not FSOUND_SetOutput(FSOUND_OUTPUT_ALSA) then raise EOpenOutputFailed.Create(SOpenOutputFailed);
|
---|
62 | end else raise EOpenOutputFailed.Create(SOpenOutputFailed);
|
---|
63 | {$endif}
|
---|
64 | end;
|
---|
65 |
|
---|
66 | function TAudioSystemFMOD.GetMediaPlayerDriverClass: TMediaPlayerDriverClass;
|
---|
67 | begin
|
---|
68 | Result := TPlayerFMOD;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | constructor TAudioSystemFMOD.Create(AOwner: TComponent);
|
---|
72 | begin
|
---|
73 | inherited;
|
---|
74 | fmod_load('');
|
---|
75 | OutputMode := omALSA;
|
---|
76 | FSOUND_Init(44100, 32, 0);
|
---|
77 | end;
|
---|
78 |
|
---|
79 | destructor TAudioSystemFMOD.Destroy;
|
---|
80 | begin
|
---|
81 | FMOD_Unload;
|
---|
82 | inherited Destroy;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | { TPlayerFMOD }
|
---|
86 |
|
---|
87 | function TPlayerFMOD.GetLength: TDateTime;
|
---|
88 | begin
|
---|
89 | Result := FVolume;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | function TPlayerFMOD.GetPosition: TDateTime;
|
---|
93 | begin
|
---|
94 |
|
---|
95 | end;
|
---|
96 |
|
---|
97 | function TPlayerFMOD.GetVolume: Real;
|
---|
98 | begin
|
---|
99 | Result := FSOUND_GetVolume(0) / 256;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | function TPlayerFMOD.GetMuted: Boolean;
|
---|
103 | begin
|
---|
104 | Result := FSOUND_GetMute(0);
|
---|
105 | end;
|
---|
106 |
|
---|
107 | procedure TPlayerFMOD.SetPosition(AValue: TDateTime);
|
---|
108 | begin
|
---|
109 | if FPlaying then FSOUND_Stream_SetPosition(FHandle, Trunc(AValue / OneMillisecond));
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TPlayerFMOD.SetVolume(AValue: Real);
|
---|
113 | begin
|
---|
114 | FSOUND_SetVolume(0, Trunc(AValue * 256));
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TPlayerFMOD.SetMuted(AValue: Boolean);
|
---|
118 | begin
|
---|
119 | FSOUND_SetMute(0, AValue)
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TPlayerFMOD.Play;
|
---|
123 | begin
|
---|
124 | //FHandle := FSOUND_Stream_Open(tmpp, FSOUND_NONBLOCKING, 0, 0);
|
---|
125 | FPlaying := True;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TPlayerFMOD.Pause;
|
---|
129 | begin
|
---|
130 | if FPlaying then
|
---|
131 | FSOUND_Setpaused(0, not FSOUND_Getpaused(0));
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TPlayerFMOD.Stop;
|
---|
135 | begin
|
---|
136 | if FPlaying then begin
|
---|
137 | FSOUND_Stream_Stop(FHandle);
|
---|
138 | FSOUND_Stream_Close(FHandle);
|
---|
139 | FPlaying := False;
|
---|
140 | end;
|
---|
141 | FSOUND_Close;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | {$ENDIF}
|
---|
145 |
|
---|
146 | end.
|
---|
147 |
|
---|