hedgewars/uSound.pas
changeset 6862 87e060b69926
parent 6700 e04da46ee43c
child 6898 344b0dbd9690
--- a/hedgewars/uSound.pas	Sat Apr 07 22:13:15 2012 +0200
+++ b/hedgewars/uSound.pas	Sun Apr 08 18:11:37 2012 +0200
@@ -36,6 +36,7 @@
 uses SDLh, uConsts, uTypes, sysutils;
 
 var MusicFN: shortstring; // music file name
+    previousVolume: LongInt; // cached volume value
 
 procedure initModule;
 procedure freeModule;
@@ -90,6 +91,9 @@
 // Returns a pointer to the voicepack with the given name.
 function  AskForVoicepack(name: shortstring): Pointer;
 
+// Drastically lower the volume when we lose focus (and restore the previous value)
+procedure DampenAudio;
+procedure UndampenAudio;
 
 implementation
 uses uVariables, uConsole, uUtils, uCommands, uDebug;
@@ -477,6 +481,17 @@
     ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
 end;
 
+procedure DampenAudio;
+begin
+previousVolume:= Volume;
+ChangeVolume(-Volume * 7 div 9);
+end;
+
+procedure UndampenAudio;
+begin
+ChangeVolume(previousVolume - Volume);
+end;
+
 procedure PauseMusic;
 begin
     if (MusicFN = '') or (not isMusicEnabled) then