hedgewars/uSound.pas
changeset 13121 de07c8423beb
parent 13039 aed4b25ff242
child 13161 aa7915ceb69f
equal deleted inserted replaced
13120:be5d9fd2c56a 13121:de07c8423beb
    61 // Plays the sound snd [from a given voicepack],
    61 // Plays the sound snd [from a given voicepack],
    62 // if keepPlaying is given and true,
    62 // if keepPlaying is given and true,
    63 // then the sound's playback won't be interrupted if asked to play again.
    63 // then the sound's playback won't be interrupted if asked to play again.
    64 procedure PlaySound(snd: TSound);
    64 procedure PlaySound(snd: TSound);
    65 procedure PlaySound(snd: TSound; keepPlaying: boolean);
    65 procedure PlaySound(snd: TSound; keepPlaying: boolean);
       
    66 procedure PlaySound(snd: TSound; keepPlaying: boolean; ignoreMask: boolean);
    66 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
    67 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
    67 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
    68 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
       
    69 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean; ignoreMask: boolean);
    68 
    70 
    69 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in.
    71 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in.
    70 // Returns sound channel of the looped sound.
    72 // Returns sound channel of the looped sound.
    71 function  LoopSound(snd: TSound): LongInt;
    73 function  LoopSound(snd: TSound): LongInt;
    72 function  LoopSound(snd: TSound; fadems: LongInt): LongInt;
    74 function  LoopSound(snd: TSound; fadems: LongInt): LongInt;
    78 procedure StopSound(snd: TSound);
    80 procedure StopSound(snd: TSound);
    79 procedure StopSoundChan(chn: LongInt);
    81 procedure StopSoundChan(chn: LongInt);
    80 procedure StopSoundChan(chn, fadems: LongInt);
    82 procedure StopSoundChan(chn, fadems: LongInt);
    81 
    83 
    82 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
    84 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
       
    85 procedure AddVoice(snd: TSound; voicepack: PVoicepack; ignoreMask: boolean);
    83 procedure PlayNextVoice;
    86 procedure PlayNextVoice;
    84 
    87 
    85 
    88 
    86 // GLOBAL FUNCTIONS
    89 // GLOBAL FUNCTIONS
    87 
    90 
   412         end;
   415         end;
   413 end;
   416 end;
   414 
   417 
   415 procedure PlaySound(snd: TSound);
   418 procedure PlaySound(snd: TSound);
   416 begin
   419 begin
   417     PlaySoundV(snd, nil, false);
   420     PlaySoundV(snd, nil, false, false);
   418 end;
   421 end;
   419 
   422 
   420 procedure PlaySound(snd: TSound; keepPlaying: boolean);
   423 procedure PlaySound(snd: TSound; keepPlaying: boolean);
   421 begin
   424 begin
   422     PlaySoundV(snd, nil, keepPlaying);
   425     PlaySoundV(snd, nil, keepPlaying, false);
       
   426 end;
       
   427 
       
   428 procedure PlaySound(snd: TSound; keepPlaying: boolean; ignoreMask: boolean);
       
   429 begin
       
   430     PlaySoundV(snd, nil, keepPlaying, ignoreMask);
   423 end;
   431 end;
   424 
   432 
   425 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
   433 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
   426 begin
   434 begin
   427     PlaySoundV(snd, voicepack, false);
   435     PlaySoundV(snd, voicepack, false, false);
   428 end;
   436 end;
   429 
   437 
   430 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
   438 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
       
   439 begin
       
   440     PlaySoundV(snd, voicepack, keepPlaying, false);
       
   441 end;
       
   442 
       
   443 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean; ignoreMask: boolean);
   431 var s:shortstring;
   444 var s:shortstring;
   432 rwops: PSDL_RWops;
   445 rwops: PSDL_RWops;
   433 begin
   446 begin
   434     if (not isSoundEnabled) or fastUntilLag then
   447     if (not isSoundEnabled) or fastUntilLag then
   435         exit;
   448         exit;
   436 
   449 
   437     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
   450     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
       
   451         exit;
       
   452 
       
   453     if (ignoreMask = false) and (MaskedSounds[snd] = true) then
   438         exit;
   454         exit;
   439 
   455 
   440     if (voicepack <> nil) then
   456     if (voicepack <> nil) then
   441         begin
   457         begin
   442         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   458         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   484         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   500         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   485         end;
   501         end;
   486 end;
   502 end;
   487 
   503 
   488 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
   504 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
       
   505 begin
       
   506     AddVoice(snd, voicepack, false);
       
   507 end;
       
   508 
       
   509 procedure AddVoice(snd: TSound; voicepack: PVoicepack; ignoreMask: boolean);
   489 var i : LongInt;
   510 var i : LongInt;
   490 begin
   511 begin
       
   512 
   491     if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and  (LastVoice.voicepack = voicepack)) then
   513     if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and  (LastVoice.voicepack = voicepack)) then
   492         exit;
   514         exit;
       
   515     if (ignoreMask = false) and (MaskedSounds[snd] = true) then
       
   516         exit;
       
   517 
   493     if (snd = sndVictory) or (snd = sndFlawless) then
   518     if (snd = sndVictory) or (snd = sndFlawless) then
   494         begin
   519         begin
   495         Mix_FadeOutChannel(-1, 800);
   520         Mix_FadeOutChannel(-1, 800);
   496         for i:= 0 to High(VoiceList) do
   521         for i:= 0 to High(VoiceList) do
   497             VoiceList[i].snd:= sndNone;
   522             VoiceList[i].snd:= sndNone;