hedgewars/uSound.pas
changeset 13039 aed4b25ff242
parent 12915 4d3b52f1ba18
child 13121 de07c8423beb
equal deleted inserted replaced
13038:356995c8c48b 13039:aed4b25ff242
    98 // Set the initial volume
    98 // Set the initial volume
    99 procedure SetVolume(vol: LongInt);
    99 procedure SetVolume(vol: LongInt);
   100 
   100 
   101 // Modifies the sound volume of the game by voldelta and returns the new volume level.
   101 // Modifies the sound volume of the game by voldelta and returns the new volume level.
   102 function  ChangeVolume(voldelta: LongInt): LongInt;
   102 function  ChangeVolume(voldelta: LongInt): LongInt;
       
   103 
       
   104 // Returns the current volume in percent
       
   105 function  GetVolumePercent(): LongInt;
   103 
   106 
   104 // Returns a pointer to the voicepack with the given name.
   107 // Returns a pointer to the voicepack with the given name.
   105 function  AskForVoicepack(name: shortstring): Pointer;
   108 function  AskForVoicepack(name: shortstring): Pointer;
   106 
   109 
   107 var MusicFN: shortstring; // music file name
   110 var MusicFN: shortstring; // music file name
   670 procedure SetVolume(vol: LongInt);
   673 procedure SetVolume(vol: LongInt);
   671 begin
   674 begin
   672     cInitVolume:= vol;
   675     cInitVolume:= vol;
   673 end;
   676 end;
   674 
   677 
       
   678 function GetVolumePercent(): LongInt;
       
   679 begin
       
   680     GetVolumePercent:= Volume * 100 div MIX_MAX_VOLUME;
       
   681 end;
       
   682 
   675 function ChangeVolume(voldelta: LongInt): LongInt;
   683 function ChangeVolume(voldelta: LongInt): LongInt;
   676 begin
   684 begin
   677     ChangeVolume:= 0;
   685     ChangeVolume:= 0;
   678     if not (isSoundEnabled or isMusicEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then
   686     if not (isSoundEnabled or isMusicEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then
   679         exit;
   687         exit;
   685     Mix_Volume(-1, Volume);
   693     Mix_Volume(-1, Volume);
   686     // get assigned Volume
   694     // get assigned Volume
   687     Volume:= Mix_Volume(-1, -1);
   695     Volume:= Mix_Volume(-1, -1);
   688     if isMusicEnabled then
   696     if isMusicEnabled then
   689         Mix_VolumeMusic(Volume * 4 div 8);
   697         Mix_VolumeMusic(Volume * 4 div 8);
   690     ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME;
   698     ChangeVolume:= GetVolumePercent();
   691 
   699 
   692     if (isMusicEnabled) then
   700     if (isMusicEnabled) then
   693         if (Volume = 0) then
   701         if (Volume = 0) then
   694             PauseMusic
   702             PauseMusic
   695             else
   703             else
   791     if s[byte(s[0])]='"' then
   799     if s[byte(s[0])]='"' then
   792         Delete(s, byte(s[0]), 1);
   800         Delete(s, byte(s[0]), 1);
   793     CurrentTeam^.voicepack:= AskForVoicepack(s)
   801     CurrentTeam^.voicepack:= AskForVoicepack(s)
   794 end;
   802 end;
   795 
   803 
   796 procedure chMute(var s: shortstring);
       
   797 begin
       
   798     s:= s; // avoid compiler hint
       
   799     MuteAudio;
       
   800 end;
       
   801 
       
   802 procedure preInitModule;
   804 procedure preInitModule;
   803 begin
   805 begin
   804     isMusicEnabled:= true;
   806     isMusicEnabled:= true;
   805     isSoundEnabled:= true;
   807     isSoundEnabled:= true;
   806     cInitVolume:= 100;
   808     cInitVolume:= 100;
   809 procedure initModule;
   811 procedure initModule;
   810 var t: LongInt;
   812 var t: LongInt;
   811     i: TSound;
   813     i: TSound;
   812 begin
   814 begin
   813     RegisterVariable('voicepack', @chVoicepack, false);
   815     RegisterVariable('voicepack', @chVoicepack, false);
   814     RegisterVariable('mute'     , @chMute     , true );
       
   815 
   816 
   816     MusicFN:='';
   817     MusicFN:='';
   817     SDMusicFN:= 'sdmusic.ogg';
   818     SDMusicFN:= 'sdmusic.ogg';
   818     Mus:= nil;
   819     Mus:= nil;
   819     isAudioMuted:= false;
   820     isAudioMuted:= false;