hedgewars/uSound.pas
changeset 2262 0dc94341bf42
parent 2258 3dd028604cfd
child 2303 f411e9f8e6d4
--- a/hedgewars/uSound.pas	Tue Jul 14 20:02:07 2009 +0000
+++ b/hedgewars/uSound.pas	Wed Jul 15 00:35:59 2009 +0000
@@ -55,6 +55,8 @@
 procedure StopSound(snd: TSound);
 function  ChangeVolume(voldelta: LongInt): LongInt;
 function  AskForVoicepack(name: shortstring): Pointer;
+function  soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
+
 
 {*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
 function openal_init		(memsize: LongInt)                      : boolean; cdecl; external OpenALBridge;
@@ -65,7 +67,7 @@
 function openal_setglobalvolume	(percentage: byte)			: boolean; cdecl; external OpenALBridge;
 function openal_fadeout		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
 function openal_fadein		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
-function openal_fade		(index: LongInt; quantity: integer; direction: byte)	: boolean; cdecl; external OpenALBridge;
+function openal_fade		(index: LongInt; quantity: integer; direction: boolean)	: boolean; cdecl; external OpenALBridge;
 function openal_playsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
 function openal_pausesound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
 function openal_stopsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
@@ -150,21 +152,34 @@
 				end;
 end;
 
+function soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
+begin
+if not isSoundEnabled then exit(0);
+if (voicepack <> nil) and (voicepack^.chunks[snd] >= 0) then openal_fadeout(defVoicepack^.chunks[snd], qt)
+else if (defVoicepack^.chunks[snd] >= 0) then openal_fadeout(defVoicepack^.chunks[snd], qt);
+end;
+
 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
 begin
 if (not isSoundEnabled) or fastUntilLag then exit;
 
-if (voicepack <> nil) and (voicepack^.chunks[snd] >= 0) then
+if (voicepack <> nil) then
 begin
+if voicepack^.chunks[snd] >= 0 then
+	begin
 	if infinite then openal_toggleloop(voicepack^.chunks[snd]);
 	openal_playsound(voicepack^.chunks[snd]);
 	lastChan[snd]:=voicepack^.chunks[snd];
+	end
 end
 else
 begin
+if (defVoicepack^.chunks[snd] >= 0) then
+	begin
 	if infinite then openal_toggleloop(defVoicepack^.chunks[snd]);
 	openal_playsound(defVoicepack^.chunks[snd]);
 	lastChan[snd]:=defVoicepack^.chunks[snd];
+	end
 end
 end;