source: trunk/Packages/CoolAudio/Systems/FMOD/AudioSystemFMOD.pas

Last change on this file was 75, checked in by chronos, 8 months ago
  • Modified: Removed U prefix from CoolAudio package unit names.
File size: 3.0 KB
Line 
1unit AudioSystemFMOD;
2
3{$I CoolAudioConfig.inc}
4
5interface
6
7{$UNDEF AudioSystemFMOD}
8{$IFDEF AudioSystemFMOD}
9uses
10 Classes, SysUtils, fmoddyn, fmodtypes, AudioSystem, DateUtils;
11
12type
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
47implementation
48
49{$IFDEF AudioSystemFMOD}
50
51{ TAudioSystemFMOD }
52
53procedure TAudioSystemFMOD.SetOutputMode(AValue: TOutputDriver);
54begin
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}
64end;
65
66function TAudioSystemFMOD.GetMediaPlayerDriverClass: TMediaPlayerDriverClass;
67begin
68 Result := TPlayerFMOD;
69end;
70
71constructor TAudioSystemFMOD.Create(AOwner: TComponent);
72begin
73 inherited;
74 fmod_load('');
75 OutputMode := omALSA;
76 FSOUND_Init(44100, 32, 0);
77end;
78
79destructor TAudioSystemFMOD.Destroy;
80begin
81 FMOD_Unload;
82 inherited Destroy;
83end;
84
85{ TPlayerFMOD }
86
87function TPlayerFMOD.GetLength: TDateTime;
88begin
89 Result := FVolume;
90end;
91
92function TPlayerFMOD.GetPosition: TDateTime;
93begin
94
95end;
96
97function TPlayerFMOD.GetVolume: Real;
98begin
99 Result := FSOUND_GetVolume(0) / 256;
100end;
101
102function TPlayerFMOD.GetMuted: Boolean;
103begin
104 Result := FSOUND_GetMute(0);
105end;
106
107procedure TPlayerFMOD.SetPosition(AValue: TDateTime);
108begin
109 if FPlaying then FSOUND_Stream_SetPosition(FHandle, Trunc(AValue / OneMillisecond));
110end;
111
112procedure TPlayerFMOD.SetVolume(AValue: Real);
113begin
114 FSOUND_SetVolume(0, Trunc(AValue * 256));
115end;
116
117procedure TPlayerFMOD.SetMuted(AValue: Boolean);
118begin
119 FSOUND_SetMute(0, AValue)
120end;
121
122procedure TPlayerFMOD.Play;
123begin
124 //FHandle := FSOUND_Stream_Open(tmpp, FSOUND_NONBLOCKING, 0, 0);
125 FPlaying := True;
126end;
127
128procedure TPlayerFMOD.Pause;
129begin
130 if FPlaying then
131 FSOUND_Setpaused(0, not FSOUND_Getpaused(0));
132end;
133
134procedure TPlayerFMOD.Stop;
135begin
136 if FPlaying then begin
137 FSOUND_Stream_Stop(FHandle);
138 FSOUND_Stream_Close(FHandle);
139 FPlaying := False;
140 end;
141 FSOUND_Close;
142end;
143
144{$ENDIF}
145
146end.
147
Note: See TracBrowser for help on using the repository browser.