hedgewars/uSound.pas
branchqmlfrontend
changeset 11408 b894922d58cc
parent 11342 ed5a6478e710
child 11504 9c5d9993b14b
equal deleted inserted replaced
11076:fcbdee9cdd74 11408:b894922d58cc
   299     voicepacks[i].name:= name;
   299     voicepacks[i].name:= name;
   300     AskForVoicepack:= @voicepacks[i]
   300     AskForVoicepack:= @voicepacks[i]
   301 end;
   301 end;
   302 
   302 
   303 procedure InitSound;
   303 procedure InitSound;
   304 const channels: LongInt = {$IFDEF MOBILE}1{$ELSE}2{$ENDIF};
   304 const channels: LongInt = 2;
   305 var success: boolean;
   305 var success: boolean;
   306 begin
   306 begin
   307     if not (isSoundEnabled or isMusicEnabled) then
   307     if not (isSoundEnabled or isMusicEnabled) then
   308         exit;
   308         exit;
   309     WriteToConsole('Init sound...');
   309     WriteToConsole('Init sound...');
   320         isSoundEnabled:= false;
   320         isSoundEnabled:= false;
   321         isMusicEnabled:= false;
   321         isMusicEnabled:= false;
   322     end;
   322     end;
   323 
   323 
   324     WriteToConsole('Init SDL_mixer... ');
   324     WriteToConsole('Init SDL_mixer... ');
   325     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
   325     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, 'Mix_Init', true);
   326     WriteLnToConsole(msgOK);
   326     WriteLnToConsole(msgOK);
   327 
   327 
   328     Mix_AllocateChannels(Succ(chanTPU));
   328     Mix_AllocateChannels(Succ(chanTPU));
   329     ChangeVolume(cInitVolume);
   329     ChangeVolume(cInitVolume);
   330 end;
   330 end;
   422         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   422         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   423             begin
   423             begin
   424             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   424             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   425             WriteToConsole(msgLoading + s + ' ');
   425             WriteToConsole(msgLoading + s + ' ');
   426             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   426             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   427             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   427             SDLTry(defVoicepack^.chunks[snd] <> nil, 'Mix_LoadWAV_RW', true);
   428             WriteLnToConsole(msgOK);
   428             WriteLnToConsole(msgOK);
   429             end;
   429             end;
   430         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   430         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   431         end;
   431         end;
   432 end;
   432 end;
   521         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   521         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   522             begin
   522             begin
   523             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   523             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   524             WriteToConsole(msgLoading + s + ' ');
   524             WriteToConsole(msgLoading + s + ' ');
   525             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   525             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   526             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   526             SDLTry(defVoicepack^.chunks[snd] <> nil, 'Mix_LoadWAV_RW', true);
   527             WriteLnToConsole(msgOK);
   527             WriteLnToConsole(msgOK);
   528             end;
   528             end;
   529         if fadems > 0 then
   529         if fadems > 0 then
   530             LoopSoundV:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1)
   530             LoopSoundV:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1)
   531         else
   531         else
   572          s:= '/Music/' + SDMusicFN
   572          s:= '/Music/' + SDMusicFN
   573     else s:= '/Music/' + MusicFN;
   573     else s:= '/Music/' + MusicFN;
   574     WriteToConsole(msgLoading + s + ' ');
   574     WriteToConsole(msgLoading + s + ' ');
   575 
   575 
   576     Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
   576     Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
   577     SDLTry(Mus <> nil, false);
   577     SDLTry(Mus <> nil, 'Mix_LoadMUS_RW', false);
   578     WriteLnToConsole(msgOK);
   578     WriteLnToConsole(msgOK);
   579 
   579 
   580     SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
   580     SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, 'Mix_FadeInMusic', false)
   581 end;
   581 end;
   582 
   582 
   583 procedure SetVolume(vol: LongInt);
   583 procedure SetVolume(vol: LongInt);
   584 begin
   584 begin
   585     cInitVolume:= vol;
   585     cInitVolume:= vol;