hedgewars/uSound.pas
changeset 282 b1e3387389b6
parent 183 57c2ef19f719
child 287 b0eef98928f8
equal deleted inserted replaced
281:5b483aa9f2ab 282:b1e3387389b6
    22 {$INCLUDE options.inc}
    22 {$INCLUDE options.inc}
    23 
    23 
    24 procedure InitSound;
    24 procedure InitSound;
    25 procedure ReleaseSound;
    25 procedure ReleaseSound;
    26 procedure SoundLoad;
    26 procedure SoundLoad;
    27 procedure PlaySound(snd: TSound);
    27 procedure PlaySound(snd: TSound; const infinite: boolean = false);
    28 procedure PlayMusic;
    28 procedure PlayMusic;
    29 procedure StopTPUSound;
    29 procedure StopSound(snd: TSound);
    30 function  ChangeVolume(voldelta: integer): integer;
    30 function  ChangeVolume(voldelta: integer): integer;
    31 
    31 
    32 implementation
    32 implementation
    33 uses uMisc, uConsole;
    33 uses uMisc, uConsole;
    34 const chanTPU = 12;
    34 const chanTPU = 12;
    80 Mus:= Mix_LoadMUS(PChar(s));
    80 Mus:= Mix_LoadMUS(PChar(s));
    81 TryDo(Mus <> nil, msgFailed, false);
    81 TryDo(Mus <> nil, msgFailed, false);
    82 WriteLnToConsole(msgOK)
    82 WriteLnToConsole(msgOK)
    83 end;
    83 end;
    84 
    84 
    85 procedure PlaySound(snd: TSound);
    85 procedure PlaySound(snd: TSound; const infinite: boolean = false);
       
    86 var loops: integer;
    86 begin
    87 begin
    87 if not isSoundEnabled then exit;
    88 if not isSoundEnabled then exit;
    88 if snd <> sndThrowPowerUp then Mix_PlayChannelTimed(-1, Soundz[snd].id, 0, -1)
    89 if infinite then loops:= -1 else loops:= 0;
    89                           else Mix_PlayChannelTimed(chanTPU, Soundz[snd].id, 0, -1)
    90 Soundz[snd].lastChan:= Mix_PlayChannelTimed(-1, Soundz[snd].id, loops, -1)
    90 end;
    91 end;
    91 
    92 
    92 procedure StopTPUSound;
    93 procedure StopSound(snd: TSound);
    93 begin
    94 begin
    94 if not isSoundEnabled then exit;
    95 if not isSoundEnabled then exit;
    95 if Mix_Playing(chanTPU) <> 0 then
    96 if Mix_Playing(Soundz[snd].lastChan) <> 0 then
    96    Mix_HaltChannel(chanTPU)
    97    Mix_HaltChannel(Soundz[snd].lastChan)
    97 end;
    98 end;
    98 
    99 
    99 procedure PlayMusic;
   100 procedure PlayMusic;
   100 begin
   101 begin
   101 if not isSoundEnabled then exit;
   102 if not isSoundEnabled then exit;