hedgewars/uSound.pas
changeset 4461 2f4f5d649bcd
parent 4404 6bae4e9461aa
child 4748 ce9b48de1f52
equal deleted inserted replaced
4460:bdace1e2f8aa 4461:2f4f5d649bcd
    44 function  ChangeVolume(voldelta: LongInt): LongInt;
    44 function  ChangeVolume(voldelta: LongInt): LongInt;
    45 function  AskForVoicepack(name: shortstring): Pointer;
    45 function  AskForVoicepack(name: shortstring): Pointer;
    46 
    46 
    47 
    47 
    48 implementation
    48 implementation
    49 uses uVariables, uConsole, uUtils, uCommands, uDebug;
    49 uses uVariables, uConsole, uUtils, uCommands, uDebug, uMobile;
    50 
    50 
    51 const chanTPU = 32;
    51 const chanTPU = 32;
    52 var Volume: LongInt;
    52 var Volume: LongInt;
    53     lastChan: array [TSound] of LongInt;
    53     lastChan: array [TSound] of LongInt;
    54     voicepacks: array[0..cMaxTeams] of TVoicepack;
    54     voicepacks: array[0..cMaxTeams] of TVoicepack;
   145 
   145 
   146     for i:= Low(TSound) to High(TSound) do
   146     for i:= Low(TSound) to High(TSound) do
   147     begin
   147     begin
   148         defVoicepack^.chunks[i]:= nil;
   148         defVoicepack^.chunks[i]:= nil;
   149         // preload all the big sound files (>32k) that would otherwise lockup the game
   149         // preload all the big sound files (>32k) that would otherwise lockup the game
   150         if (i in [sndBeeWater, sndBee, sndCake, sndHellishImpact1, sndHellish, sndHomerun, sndMolotov, sndMortar, sndRideOfTheValkyries, sndYoohoo])
   150         if (i in [sndBeeWater, sndBee, sndCake, sndHellishImpact1, sndHellish, sndHomerun,
       
   151                   sndMolotov, sndMortar, sndRideOfTheValkyries, sndYoohoo])
   151             and (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   152             and (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   152         begin
   153         begin
   153             s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
   154             s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
   154             WriteToConsole(msgLoading + s + ' ');
   155             WriteToConsole(msgLoading + s + ' ');
   155             defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   156             defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
   176 end;
   177 end;
   177 
   178 
   178 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
   179 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
   179 var s:shortstring;
   180 var s:shortstring;
   180 begin
   181 begin
   181     if (not isSoundEnabled) or fastUntilLag then
   182     if (not isSoundEnabled) or fastUntilLag or isDeviceMute() then
   182         exit;
   183         exit;
   183 
   184 
   184     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
   185     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
   185         exit;
   186         exit;
   186 
   187 
   218 end;
   219 end;
   219 
   220 
   220 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
   221 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
   221 var s: shortstring;
   222 var s: shortstring;
   222 begin
   223 begin
   223     if (not isSoundEnabled) or fastUntilLag then
   224     if (not isSoundEnabled) or fastUntilLag or isDeviceMute() then
   224     begin
   225     begin
   225         LoopSound:= -1;
   226         LoopSound:= -1;
   226         exit
   227         exit
   227     end;
   228     end;
   228 
   229