hedgewars/uSound.pas
changeset 2745 11fce231f24a
parent 2744 803d0142594e
child 2832 8cb73c0e77a1
--- a/hedgewars/uSound.pas	Thu Feb 04 14:35:31 2010 +0000
+++ b/hedgewars/uSound.pas	Thu Feb 04 14:48:49 2010 +0000
@@ -36,12 +36,15 @@
 procedure InitSound;
 procedure ReleaseSound;
 procedure SoundLoad;
-procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
-procedure LoopSound(snd: TSound; voicepack: PVoicepack);
+procedure PlaySound(snd: TSound);
+procedure PlaySound(snd: TSound; voicepack: PVoicepack);
+function LoopSound(snd: TSound): LongInt;
+function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
 procedure PlayMusic;
 procedure PauseMusic;
 procedure ResumeMusic;
 procedure StopSound(snd: TSound);
+procedure StopSound(chn: LongInt);
 function  ChangeVolume(voldelta: LongInt): LongInt;
 function  AskForVoicepack(name: shortstring): Pointer;
 
@@ -152,28 +155,34 @@
 {$ENDIF}	
 end;
 
-procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
-var loops: LongInt;
+procedure PlaySound(snd: TSound);
+begin
+	PlaySound(snd, nil);
+end;
+
+procedure PlaySound(snd: TSound; voicepack: PVoicepack);
 begin
 if (not isSoundEnabled) or fastUntilLag then exit;
-if infinite and (lastChan[snd] <> -1) then exit;
-if infinite then loops:= -1 else loops:= 0;
 
 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
-	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], loops, -1)
+	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1)
 else
-	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1)
+	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
 end;
 
-procedure LoopSound(snd: TSound; voicepack: PVoicepack);
+function LoopSound(snd: TSound): LongInt;
+begin
+	LoopSound:= LoopSound(snd, nil)
+end;
+
+function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
 begin
 if (not isSoundEnabled) or fastUntilLag then exit;
-if lastChan[snd] <> -1 then exit;
 
 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
-	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1)
+	LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1)
 else
-	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1)
+	LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1)
 end;
 
 procedure StopSound(snd: TSound);
@@ -186,6 +195,11 @@
 	end;
 end;
 
+procedure StopSound(chn: LongInt);
+begin
+	if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_HaltChannel(chn);
+end;
+
 procedure PlayMusic;
 var s: string;
 begin