hedgewars/uSound.pas
changeset 565 092cb8deffc5
parent 564 17fb45c670c1
child 576 35a1af355ada
equal deleted inserted replaced
564:17fb45c670c1 565:092cb8deffc5
   100 var s: string;
   100 var s: string;
   101 begin
   101 begin
   102 {$IFDEF HAVE_MUSIC}
   102 {$IFDEF HAVE_MUSIC}
   103 if not isSoundEnabled then exit;
   103 if not isSoundEnabled then exit;
   104 if Mix_PlayingMusic() <> 0 then exit;
   104 if Mix_PlayingMusic() <> 0 then exit;
       
   105 
   105 Mix_FreeMusic(Mus);
   106 Mix_FreeMusic(Mus);
       
   107 
       
   108 CurrMusic:= playlistchain[CurrMusic];
       
   109 
   106 s:= PathPrefix + '/Music/' + playlist[CurrMusic];
   110 s:= PathPrefix + '/Music/' + playlist[CurrMusic];
   107 CurrMusic:= playlistchain[CurrMusic];
       
   108 WriteToConsole(msgLoading + s + ' ');
   111 WriteToConsole(msgLoading + s + ' ');
       
   112 
   109 Mus:= Mix_LoadMUS(Str2PChar(s));
   113 Mus:= Mix_LoadMUS(Str2PChar(s));
   110 TryDo(Mus <> nil, msgFailed, false);
   114 TryDo(Mus <> nil, msgFailed, false);
   111 WriteLnToConsole(msgOK);
   115 WriteLnToConsole(msgOK);
   112 
   116 
   113 Mix_PlayMusic(Mus, 0)
   117 Mix_PlayMusic(Mus, 1)
   114 {$ENDIF}
   118 {$ENDIF}
   115 end;
   119 end;
   116 
   120 
   117 function ChangeVolume(voldelta: LongInt): LongInt;
   121 function ChangeVolume(voldelta: LongInt): LongInt;
   118 begin
   122 begin
   126 Mix_VolumeMusic(Volume * 3 div 8);
   130 Mix_VolumeMusic(Volume * 3 div 8);
   127 ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
   131 ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
   128 end;
   132 end;
   129 
   133 
   130 procedure InitPlaylistChunk(seed: LongWord);
   134 procedure InitPlaylistChunk(seed: LongWord);
   131 var i, t, tmp: Longword;
   135 var i, t, nt: Longword;
   132 begin
   136 begin
   133 {$IFDEF HAVE_MUSIC}
   137 {$IFDEF HAVE_MUSIC}
   134 for i:= 0 to Pred(cPlayListLength) do
   138 for i:= 0 to Pred(cPlayListLength) do
   135     playlistchain[i]:= i;
   139     playlistchain[i]:= 0;
   136 
   140 
   137 for i:= 0 to Pred(cPlayListLength) do
   141 t:= 0;
       
   142 for i:= 0 to cPlayListLength - 2 do
   138     begin
   143     begin
   139     t:= (i + 1) mod cPlayListLength;
   144     repeat
   140     tmp:= playlistchain[t];
   145       seed:= seed * 1664525 + 1013904223;
   141     playlistchain[t]:= playlistchain[i];
   146       nt:= seed mod cPlayListLength;
   142     playlistchain[i]:= tmp;
   147     until (t <> nt) and (playlistchain[nt] = 0);
       
   148     playlistchain[t]:= nt;
       
   149     t:= nt;
   143     end
   150     end
   144 {$ENDIF}
   151 {$ENDIF}
   145 end;
   152 end;
   146 
   153 
   147 end.
   154 end.