hedgewars/uSound.pas
changeset 174 0b2c5b22f644
parent 97 e7c1df9cce2c
child 175 d226d976d836
equal deleted inserted replaced
173:004493dd60e4 174:0b2c5b22f644
    40 procedure ReleaseSound;
    40 procedure ReleaseSound;
    41 procedure SoundLoad;
    41 procedure SoundLoad;
    42 procedure PlaySound(snd: TSound);
    42 procedure PlaySound(snd: TSound);
    43 procedure PlayMusic;
    43 procedure PlayMusic;
    44 procedure StopTPUSound;
    44 procedure StopTPUSound;
       
    45 function  ChangeVolume(voldelta: integer): integer;
    45 
    46 
    46 implementation
    47 implementation
    47 uses uMisc, uConsole;
    48 uses uMisc, uConsole;
    48 const chanTPU = 12;
    49 const chanTPU = 12;
    49 var Mus: PMixMusic;
    50 var Mus: PMixMusic;
       
    51     Volume: integer;
    50 
    52 
    51 procedure InitSound;
    53 procedure InitSound;
    52 begin
    54 begin
    53 if not isSoundEnabled then exit;
    55 if not isSoundEnabled then exit;
    54 WriteToConsole('Init sound...');
    56 WriteToConsole('Init sound...');
    56 if isSoundEnabled then
    58 if isSoundEnabled then
    57    isSoundEnabled:= Mix_OpenAudio(22050, $8010, 2, 512) = 0;
    59    isSoundEnabled:= Mix_OpenAudio(22050, $8010, 2, 512) = 0;
    58 if isSoundEnabled then WriteLnToConsole(msgOK)
    60 if isSoundEnabled then WriteLnToConsole(msgOK)
    59                   else WriteLnToConsole(msgFailed);
    61                   else WriteLnToConsole(msgFailed);
    60 Mix_AllocateChannels(Succ(chanTPU));
    62 Mix_AllocateChannels(Succ(chanTPU));
    61 Mix_VolumeMusic(48)
    63 Mix_VolumeMusic(48);
       
    64 
       
    65 Volume:= cInitVolume;
       
    66 if Volume < 0 then Volume:= 0;
       
    67 Volume:= Mix_Volume(-1, Volume)
    62 end;
    68 end;
    63 
    69 
    64 procedure ReleaseSound;
    70 procedure ReleaseSound;
    65 var i: TSound;
    71 var i: TSound;
    66 begin
    72 begin
   110 if not isSoundEnabled then exit;
   116 if not isSoundEnabled then exit;
   111 if Mix_PlayingMusic = 0 then
   117 if Mix_PlayingMusic = 0 then
   112    Mix_PlayMusic(Mus, -1)
   118    Mix_PlayMusic(Mus, -1)
   113 end;
   119 end;
   114 
   120 
       
   121 function ChangeVolume(voldelta: integer): integer;
       
   122 begin
       
   123 inc(Volume, voldelta);
       
   124 if Volume < 0 then Volume:= 0;
       
   125 Volume:= Mix_Volume(-1, Volume);
       
   126 Result:= Volume * 100 div MIX_MAX_VOLUME
       
   127 end;
       
   128 
   115 end.
   129 end.