hedgewars/uSound.pas
changeset 2671 7e0f88013fe8
parent 2647 0e1208e92dfe
child 2672 0f1403bf267a
equal deleted inserted replaced
2670:1b327b7515ed 2671:7e0f88013fe8
    68 end;
    68 end;
    69 
    69 
    70 procedure InitSound;
    70 procedure InitSound;
    71 var i: TSound;
    71 var i: TSound;
    72 begin
    72 begin
    73 if not isSoundEnabled then exit;
    73 	if not isSoundEnabled then exit;
    74 WriteToConsole('Init sound...');
    74 	WriteToConsole('Init sound...');
    75 isSoundEnabled:= SDL_Init(SDL_INIT_AUDIO) >= 0;
    75 	isSoundEnabled:= SDL_Init(SDL_INIT_AUDIO) >= 0;
    76 if isSoundEnabled then
    76 
    77    isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
    77 	if isSoundEnabled then
    78 if isSoundEnabled then WriteLnToConsole(msgOK)
    78 		isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
    79                   else WriteLnToConsole(msgFailed);
    79 
    80 Mix_AllocateChannels(Succ(chanTPU));
    80 	if isSoundEnabled then
    81 if isMusicEnabled then Mix_VolumeMusic(50);
    81 		WriteLnToConsole(msgOK)
    82 
    82 	else
    83 for i:= Low(TSound) to High(TSound) do
    83 		WriteLnToConsole(msgFailed);
    84 	lastChan[i]:= -1;
    84 
    85 
    85 	Mix_AllocateChannels(Succ(chanTPU));
    86 Volume:= 0;
    86 	if isMusicEnabled then
    87 ChangeVolume(cInitVolume)
    87 		Mix_VolumeMusic(50);
       
    88 	for i:= Low(TSound) to High(TSound) do
       
    89 		lastChan[i]:= -1;
       
    90 
       
    91 	Volume:= 0;
       
    92 	ChangeVolume(cInitVolume)
    88 end;
    93 end;
    89 
    94 
    90 procedure ReleaseSound;
    95 procedure ReleaseSound;
    91 var i: TSound;
    96 var i: TSound;
    92 	t: Longword;
    97 	t: Longword;
    96 		for i:= Low(TSound) to High(TSound) do
   101 		for i:= Low(TSound) to High(TSound) do
    97 			if voicepacks[t].chunks[i] <> nil then
   102 			if voicepacks[t].chunks[i] <> nil then
    98 				Mix_FreeChunk(voicepacks[t].chunks[i]);
   103 				Mix_FreeChunk(voicepacks[t].chunks[i]);
    99 
   104 
   100 Mix_FreeMusic(Mus);
   105 Mix_FreeMusic(Mus);
   101 Mix_CloseAudio
   106 Mix_CloseAudio();
   102 end;
   107 end;
   103 
   108 
   104 procedure SoundLoad;
   109 procedure SoundLoad;
   105 var i: TSound;
   110 var i: TSound;
   106 	s: shortstring;
   111 	s: shortstring;
   107 	t: Longword;
   112 	t: Longword;
   108 begin
   113 begin
   109 if not isSoundEnabled then exit;
   114 	if not isSoundEnabled then exit;
   110 
   115 
   111 defVoicepack:= AskForVoicepack('Default');
   116 	WriteToConsole('Init SDL_mixer... ');
       
   117 	SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
       
   118 	WriteLnToConsole(msgOK);
       
   119 	
       
   120 	defVoicepack:= AskForVoicepack('Default');
   112 
   121 
   113 for i:= Low(TSound) to High(TSound) do
   122 for i:= Low(TSound) to High(TSound) do
   114 	if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   123 	if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   115 		begin
   124 		begin
   116 		s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
   125 		s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
   131 				if voicepacks[t].chunks[i] = nil then
   140 				if voicepacks[t].chunks[i] = nil then
   132 					WriteLnToConsole(msgFailed)
   141 					WriteLnToConsole(msgFailed)
   133 				else
   142 				else
   134 					WriteLnToConsole(msgOK)
   143 					WriteLnToConsole(msgOK)
   135 				end;
   144 				end;
       
   145 	
       
   146 	Mix_Quit();
   136 end;
   147 end;
   137 
   148 
   138 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
   149 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
   139 var loops: LongInt;
   150 var loops: LongInt;
   140 begin
   151 begin