hedgewars/uSound.pas
changeset 5638 e35ba2a400d8
parent 5239 f34f391a223b
child 5652 28a8e14a4b8d
equal deleted inserted replaced
5636:c18aed7ad618 5638:e35ba2a400d8
    74 // Stops the normal/looped sound of the given type/in the given channel
    74 // Stops the normal/looped sound of the given type/in the given channel
    75 // [with a fade-out effect for fadems milliseconds].
    75 // [with a fade-out effect for fadems milliseconds].
    76 procedure StopSound(snd: TSound);
    76 procedure StopSound(snd: TSound);
    77 procedure StopSound(chn: LongInt);
    77 procedure StopSound(chn: LongInt);
    78 procedure StopSound(chn, fadems: LongInt);
    78 procedure StopSound(chn, fadems: LongInt);
       
    79 
       
    80 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
       
    81 procedure PlayNextVoice;
    79 
    82 
    80 
    83 
    81 // MISC
    84 // MISC
    82 
    85 
    83 // Modifies the sound volume of the game by voldelta and returns the new volume level.
    86 // Modifies the sound volume of the game by voldelta and returns the new volume level.
   253 
   256 
   254     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
   257     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
   255         exit;
   258         exit;
   256 
   259 
   257     if (voicepack <> nil) then
   260     if (voicepack <> nil) then
   258     begin
   261         begin
   259         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   262         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   260         begin
   263             begin
   261             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   264             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   262             if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   265             if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   263             WriteToConsole(msgLoading + s + ' ');
   266             WriteToConsole(msgLoading + s + ' ');
   264             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   267             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   265             if voicepack^.chunks[snd] = nil then
   268             if voicepack^.chunks[snd] = nil then
   266                 WriteLnToConsole(msgFailed)
   269                 WriteLnToConsole(msgFailed)
   267             else
   270             else
   268                 WriteLnToConsole(msgOK)
   271                 WriteLnToConsole(msgOK)
   269         end;
   272             end;
   270         lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1)
   273         lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1)
   271     end
   274         end
   272     else
   275     else
   273     begin
   276         begin
   274         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   277         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   275         begin
   278             begin
   276             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   279             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   277             if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   280             if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   278             WriteToConsole(msgLoading + s + ' ');
   281             WriteToConsole(msgLoading + s + ' ');
   279             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   282             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   280             TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true);
   283             TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true);
   281             WriteLnToConsole(msgOK);
   284             WriteLnToConsole(msgOK);
   282         end;
   285             end;
   283         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   286         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   284     end;
   287         end;
       
   288 end;
       
   289 
       
   290 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
       
   291 var i : LongInt;
       
   292 begin
       
   293     i:= 0;
       
   294     while (i<8) and (VoiceList[i].snd <> sndNone) do inc(i);
       
   295 
       
   296     VoiceList[i].snd:= snd;
       
   297     VoiceList[i].voicepack:= voicepack;
       
   298 end;
       
   299 
       
   300 procedure PlayNextVoice;
       
   301 var i : LongInt;
       
   302 begin
       
   303     if (LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0) then exit;
       
   304     i:= 0;
       
   305     while (i<8) and (VoiceList[i].snd = sndNone) do inc(i);
       
   306     
       
   307     if (VoiceList[i].snd <> sndNone) then
       
   308         begin
       
   309         LastVoice.snd:= VoiceList[i].snd;
       
   310         LastVoice.voicepack:= VoiceList[i].voicepack;
       
   311         VoiceList[i].snd:= sndNone;
       
   312         PlaySound(LastVoice.snd, LastVoice.voicepack)
       
   313         end
       
   314     else LastVoice.snd:= sndNone;
   285 end;
   315 end;
   286 
   316 
   287 function LoopSound(snd: TSound): LongInt;
   317 function LoopSound(snd: TSound): LongInt;
   288 begin
   318 begin
   289     LoopSound:= LoopSound(snd, nil)
   319     LoopSound:= LoopSound(snd, nil)