hedgewars/uSound.pas
changeset 13628 d5e029b84e16
parent 13495 f725701ca529
child 13872 f01798038c2e
--- a/hedgewars/uSound.pas	Tue Aug 07 10:29:01 2018 +0200
+++ b/hedgewars/uSound.pas	Tue Aug 07 11:37:37 2018 +0200
@@ -43,6 +43,7 @@
 procedure ReleaseSound(complete: boolean);      // Releases sound-system and used resources.
 procedure ResetSound;                           // Reset sound state to the previous state.
 procedure SetSound(enabled: boolean);           // Enable/disable sound-system and backup status.
+procedure SetAudioDampen(enabled: boolean);     // Enable/disable automatic dampening if losing window focus.
 
 // MUSIC
 
@@ -129,6 +130,7 @@
     Mus: PMixMusic; // music pointer
     isMusicEnabled: boolean;
     isSoundEnabled: boolean;
+    isAutoDampening: boolean;
     isSEBackup: boolean;
     VoiceList : array[0..7] of TVoice =  (
                     ( snd: sndNone; voicepack: nil),
@@ -388,6 +390,11 @@
     isSoundEnabled:= enabled;
 end;
 
+procedure SetAudioDampen(enabled: boolean);
+begin
+    isAutoDampening:= enabled;
+end;
+
 // when complete is false, this procedure just releases some of the chucks on inactive channels
 // in this way music is not stopped, nor are chucks currently being played
 procedure ReleaseSound(complete: boolean);
@@ -752,7 +759,7 @@
 
 procedure DampenAudio;
 begin
-    if (isAudioMuted) then
+    if (isAudioMuted or (not isAutoDampening)) then
         exit;
     previousVolume:= Volume;
     ChangeVolume(-Volume * 7 div 9);
@@ -760,7 +767,7 @@
 
 procedure UndampenAudio;
 begin
-     if (isAudioMuted) then
+    if (isAudioMuted or (not isAutoDampening)) then
         exit;
     ChangeVolume(previousVolume - Volume);
 end;
@@ -849,6 +856,7 @@
 begin
     isMusicEnabled:= true;
     isSoundEnabled:= true;
+    isAutoDampening:= true;
     cInitVolume:= 100;
 end;