hedgewars/uSound.pas
branchhedgeroid
changeset 5655 44c2d19f79e2
parent 5635 0c17c8791ac9
parent 5653 fa58dea8a9ad
child 5725 e27100a0e2d0
equal deleted inserted replaced
5647:28ab6763da9d 5655:44c2d19f79e2
    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     if (not isSoundEnabled) or fastUntilLag then exit;
       
   294     i:= 0;
       
   295     while (i<8) and (VoiceList[i].snd <> sndNone) do inc(i);
       
   296 
       
   297     VoiceList[i].snd:= snd;
       
   298     VoiceList[i].voicepack:= voicepack;
       
   299 end;
       
   300 
       
   301 procedure PlayNextVoice;
       
   302 var i : LongInt;
       
   303 begin
       
   304     if (not isSoundEnabled) or fastUntilLag or (LastVoice.snd = sndNone) or (lastChan[LastVoice.snd] = -1) or (Mix_Playing(lastChan[LastVoice.snd]) = 0) then exit;
       
   305     i:= 0;
       
   306     while (i<8) and (VoiceList[i].snd = sndNone) do inc(i);
       
   307     
       
   308     if (VoiceList[i].snd <> sndNone) then
       
   309         begin
       
   310         LastVoice.snd:= VoiceList[i].snd;
       
   311         LastVoice.voicepack:= VoiceList[i].voicepack;
       
   312         VoiceList[i].snd:= sndNone;
       
   313         PlaySound(LastVoice.snd, LastVoice.voicepack)
       
   314         end
       
   315     else LastVoice.snd:= sndNone;
   285 end;
   316 end;
   286 
   317 
   287 function LoopSound(snd: TSound): LongInt;
   318 function LoopSound(snd: TSound): LongInt;
   288 begin
   319 begin
   289     LoopSound:= LoopSound(snd, nil)
   320     LoopSound:= LoopSound(snd, nil)