author | palewolf |
Tue, 30 Mar 2010 20:18:54 +0000 | |
changeset 3186 | 8d3e4e9a5199 |
parent 3182 | f75d546414c4 |
child 3201 | 400c98815100 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
1654 | 3 |
* Copyright (c) 2005, 2007, 2009 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uSound; |
22 |
interface |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
23 |
uses SDLh, uConsts; |
4 | 24 |
|
1654 | 25 |
type PVoicepack = ^TVoicepack; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
26 |
TVoicepack = record |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
27 |
name: shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
28 |
chunks: array [TSound] of PMixChunk; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
29 |
end; |
1654 | 30 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
31 |
var MusicFN: shortstring; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
32 |
|
3038 | 33 |
procedure initModule; |
34 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
35 |
|
4 | 36 |
procedure InitSound; |
37 |
procedure ReleaseSound; |
|
38 |
procedure SoundLoad; |
|
2745 | 39 |
procedure PlaySound(snd: TSound); |
40 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
|
41 |
function LoopSound(snd: TSound): LongInt; |
|
42 |
function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
|
4 | 43 |
procedure PlayMusic; |
1712 | 44 |
procedure PauseMusic; |
45 |
procedure ResumeMusic; |
|
282 | 46 |
procedure StopSound(snd: TSound); |
2745 | 47 |
procedure StopSound(chn: LongInt); |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
48 |
function ChangeVolume(voldelta: LongInt): LongInt; |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
49 |
function AskForVoicepack(name: shortstring): Pointer; |
4 | 50 |
|
1097 | 51 |
|
4 | 52 |
implementation |
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2222
diff
changeset
|
53 |
uses uMisc, uConsole; |
564 | 54 |
|
13 | 55 |
const chanTPU = 12; |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
56 |
var Volume: LongInt; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
57 |
lastChan: array [TSound] of LongInt; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
58 |
voicepacks: array[0..cMaxTeams] of TVoicepack; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
59 |
defVoicepack: PVoicepack; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
60 |
Mus: PMixMusic = nil; |
1654 | 61 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
62 |
function AskForVoicepack(name: shortstring): Pointer; |
1654 | 63 |
var i: Longword; |
64 |
begin |
|
65 |
i:= 0; |
|
66 |
while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
67 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
68 |
inc(i); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
69 |
TryDo(i <= cMaxTeams, 'Engine bug: AskForVoicepack i > cMaxTeams', true) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
70 |
end; |
1654 | 71 |
|
72 |
voicepacks[i].name:= name; |
|
73 |
AskForVoicepack:= @voicepacks[i] |
|
74 |
end; |
|
4 | 75 |
|
76 |
procedure InitSound; |
|
2647 | 77 |
var i: TSound; |
4 | 78 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
79 |
if not isSoundEnabled then exit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
80 |
WriteToConsole('Init sound...'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
81 |
isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0; |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2647
diff
changeset
|
82 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
83 |
if isSoundEnabled then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
84 |
isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0; |
2327 | 85 |
|
3182 | 86 |
{$IFDEF SDL_MIXER_NEWER} |
87 |
WriteToConsole('Init SDL_mixer... '); |
|
88 |
SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true); |
|
89 |
WriteLnToConsole(msgOK); |
|
90 |
{$ENDIF} |
|
91 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
92 |
if isSoundEnabled then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
93 |
WriteLnToConsole(msgOK) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
94 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
95 |
WriteLnToConsole(msgFailed); |
2647 | 96 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
97 |
Mix_AllocateChannels(Succ(chanTPU)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
98 |
if isMusicEnabled then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
99 |
Mix_VolumeMusic(50); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
100 |
for i:= Low(TSound) to High(TSound) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
101 |
lastChan[i]:= -1; |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2647
diff
changeset
|
102 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
103 |
Volume:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
104 |
ChangeVolume(cInitVolume) |
4 | 105 |
end; |
106 |
||
107 |
procedure ReleaseSound; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
108 |
var i: TSound; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
109 |
t: Longword; |
4 | 110 |
begin |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
111 |
for t:= 0 to cMaxTeams do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
112 |
if voicepacks[t].name <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
113 |
for i:= Low(TSound) to High(TSound) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
114 |
if voicepacks[t].chunks[i] <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
115 |
Mix_FreeChunk(voicepacks[t].chunks[i]); |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
116 |
|
3182 | 117 |
if Mus <> nil then |
118 |
Mix_FreeMusic(Mus); |
|
119 |
||
120 |
{$IFDEF SDL_MIXER_NEWER} |
|
121 |
// make sure all instances of sdl_mixer are unloaded before continuing |
|
122 |
while Mix_Init(0) <> 0 do |
|
123 |
Mix_Quit(); |
|
124 |
{$ENDIF} |
|
125 |
||
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2647
diff
changeset
|
126 |
Mix_CloseAudio(); |
4 | 127 |
end; |
128 |
||
129 |
procedure SoundLoad; |
|
130 |
var i: TSound; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
131 |
s: shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
132 |
t: Longword; |
4 | 133 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
134 |
if not isSoundEnabled then exit; |
1656
209cf0e2fc36
Finish voicepacks support in engine (not tested though)
unc0rr
parents:
1654
diff
changeset
|
135 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
136 |
defVoicepack:= AskForVoicepack('Default'); |
1654 | 137 |
|
4 | 138 |
for i:= Low(TSound) to High(TSound) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
139 |
if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
140 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
141 |
s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
142 |
WriteToConsole(msgLoading + s + ' '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
143 |
defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
144 |
TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
145 |
WriteLnToConsole(msgOK); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
146 |
end; |
1656
209cf0e2fc36
Finish voicepacks support in engine (not tested though)
unc0rr
parents:
1654
diff
changeset
|
147 |
|
209cf0e2fc36
Finish voicepacks support in engine (not tested though)
unc0rr
parents:
1654
diff
changeset
|
148 |
for t:= 0 to cMaxTeams do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
149 |
if voicepacks[t].name <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
150 |
for i:= Low(TSound) to High(TSound) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
151 |
if (Soundz[i].Path = ptVoices) and (Soundz[i].FileName <> '') then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
152 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
153 |
s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
154 |
WriteToConsole(msgLoading + s + ' '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
155 |
voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
156 |
if voicepacks[t].chunks[i] = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
157 |
WriteLnToConsole(msgFailed) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
158 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
159 |
WriteLnToConsole(msgOK) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
160 |
end; |
4 | 161 |
end; |
162 |
||
2745 | 163 |
procedure PlaySound(snd: TSound); |
164 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
165 |
PlaySound(snd, nil); |
2745 | 166 |
end; |
167 |
||
168 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
|
4 | 169 |
begin |
1562
c0eea030347b
Don't play sounds when quick replaying in spectate mode
unc0rr
parents:
1225
diff
changeset
|
170 |
if (not isSoundEnabled) or fastUntilLag then exit; |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2418
diff
changeset
|
171 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
172 |
if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
173 |
lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1) |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
174 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
175 |
lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1) |
4 | 176 |
end; |
177 |
||
2745 | 178 |
function LoopSound(snd: TSound): LongInt; |
179 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
180 |
LoopSound:= LoopSound(snd, nil) |
2745 | 181 |
end; |
182 |
||
183 |
function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
|
2647 | 184 |
begin |
2832 | 185 |
if (not isSoundEnabled) or fastUntilLag then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
186 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
187 |
LoopSound:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
188 |
exit |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
189 |
end; |
2647 | 190 |
|
191 |
if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
192 |
LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
2647 | 193 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
194 |
LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1) |
2647 | 195 |
end; |
196 |
||
282 | 197 |
procedure StopSound(snd: TSound); |
4 | 198 |
begin |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
199 |
if not isSoundEnabled then exit; |
2647 | 200 |
if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
201 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
202 |
Mix_HaltChannel(lastChan[snd]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
203 |
lastChan[snd]:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
204 |
end; |
4 | 205 |
end; |
206 |
||
2745 | 207 |
procedure StopSound(chn: LongInt); |
208 |
begin |
|
2832 | 209 |
if not isSoundEnabled then exit; |
210 |
if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_HaltChannel(chn); |
|
2745 | 211 |
end; |
212 |
||
4 | 213 |
procedure PlayMusic; |
2905 | 214 |
var s: shortstring; |
4 | 215 |
begin |
1097 | 216 |
if (not isSoundEnabled) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
217 |
or (MusicFN = '') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
218 |
or (not isMusicEnabled) then exit; |
565 | 219 |
|
1097 | 220 |
s:= PathPrefix + '/Music/' + MusicFN; |
564 | 221 |
WriteToConsole(msgLoading + s + ' '); |
565 | 222 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
223 |
Mus:= Mix_LoadMUS(Str2PChar(s)); |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
224 |
TryDo(Mus <> nil, msgFailed, false); |
564 | 225 |
WriteLnToConsole(msgOK); |
226 |
||
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
227 |
SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false) |
4 | 228 |
end; |
229 |
||
371 | 230 |
function ChangeVolume(voldelta: LongInt): LongInt; |
174 | 231 |
begin |
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
232 |
if not isSoundEnabled then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
233 |
exit(0); |
2327 | 234 |
|
235 |
inc(Volume, voldelta); |
|
236 |
if Volume < 0 then Volume:= 0; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
237 |
Mix_Volume(-1, Volume); |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
238 |
Volume:= Mix_Volume(-1, -1); |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
239 |
if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); |
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
240 |
ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME |
174 | 241 |
end; |
242 |
||
1712 | 243 |
procedure PauseMusic; |
244 |
begin |
|
245 |
if (MusicFN = '') or (not isMusicEnabled) then exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
246 |
|
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
247 |
Mix_PauseMusic(Mus); |
1712 | 248 |
end; |
249 |
||
250 |
procedure ResumeMusic; |
|
251 |
begin |
|
252 |
if (MusicFN = '') or (not isMusicEnabled) then exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
253 |
|
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
254 |
Mix_ResumeMusic(Mus); |
1712 | 255 |
end; |
256 |
||
3038 | 257 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
258 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
259 |
MusicFN:=''; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
260 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
261 |
|
3038 | 262 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
263 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
264 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
265 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
266 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
267 |
end. |
2192
4763a778c033
- Fix quickplay sound bug triggered by two faults: ttsmj's (passing voicepack with empty name in team config) and koda's (he changed fallback to default scheme condition)
unc0rr
parents:
2191
diff
changeset
|
268 |