author | Colin Rice (clr_) |
Wed, 23 Mar 2011 14:15:20 +0100 | |
changeset 5042 | f26c5eb040af |
parent 4976 | 088d40d8aba2 |
child 5052 | 74a81c276d67 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2004-2011 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 |
|
4357
a1fcfc341a52
Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents:
3825
diff
changeset
|
23 |
uses SDLh, uConsts, uTypes; |
4 | 24 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
25 |
var MusicFN: shortstring; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
26 |
|
3038 | 27 |
procedure initModule; |
28 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
29 |
|
4 | 30 |
procedure InitSound; |
31 |
procedure ReleaseSound; |
|
32 |
procedure SoundLoad; |
|
2745 | 33 |
procedure PlaySound(snd: TSound); |
3202 | 34 |
procedure PlaySound(snd: TSound; keepPlaying: boolean); |
2745 | 35 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
3201 | 36 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
3529 | 37 |
function LoopSound(snd: TSound): LongInt; |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
38 |
function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
3529 | 39 |
function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
40 |
function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
4 | 41 |
procedure PlayMusic; |
1712 | 42 |
procedure PauseMusic; |
43 |
procedure ResumeMusic; |
|
4748 | 44 |
procedure ChangeMusic; |
282 | 45 |
procedure StopSound(snd: TSound); |
2745 | 46 |
procedure StopSound(chn: LongInt); |
4966
fa612a614317
make defective mines explode if they take enough damage, add missing interface line for koda's new uSound fade
nemo
parents:
4956
diff
changeset
|
47 |
procedure StopSound(chn, fadems: 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 |
4948 | 53 |
uses uVariables, uConsole, uUtils, uCommands, uDebug; |
564 | 54 |
|
3418 | 55 |
const chanTPU = 32; |
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; |
|
3529 | 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 |
3529 | 68 |
inc(i); |
69 |
TryDo(i <= cMaxTeams, 'Engine bug: AskForVoicepack i > cMaxTeams', true) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
70 |
end; |
1654 | 71 |
|
3529 | 72 |
voicepacks[i].name:= name; |
73 |
AskForVoicepack:= @voicepacks[i] |
|
1654 | 74 |
end; |
4 | 75 |
|
76 |
procedure InitSound; |
|
2647 | 77 |
var i: TSound; |
3825 | 78 |
channels: LongInt; |
4 | 79 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
80 |
if not isSoundEnabled then exit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
81 |
WriteToConsole('Init sound...'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
82 |
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
|
83 |
|
3825 | 84 |
{$IFDEF IPHONEOS} |
85 |
channels:= 1; |
|
86 |
{$ELSE} |
|
87 |
channels:= 2; |
|
88 |
{$ENDIF} |
|
89 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
90 |
if isSoundEnabled then |
3825 | 91 |
isSoundEnabled:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0; |
2327 | 92 |
|
3182 | 93 |
{$IFDEF SDL_MIXER_NEWER} |
94 |
WriteToConsole('Init SDL_mixer... '); |
|
95 |
SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true); |
|
96 |
WriteLnToConsole(msgOK); |
|
97 |
{$ENDIF} |
|
98 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
99 |
if isSoundEnabled then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
100 |
WriteLnToConsole(msgOK) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
101 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
102 |
WriteLnToConsole(msgFailed); |
2647 | 103 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
104 |
Mix_AllocateChannels(Succ(chanTPU)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
105 |
if isMusicEnabled then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
106 |
Mix_VolumeMusic(50); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
107 |
for i:= Low(TSound) to High(TSound) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
108 |
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
|
109 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
110 |
Volume:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
111 |
ChangeVolume(cInitVolume) |
4 | 112 |
end; |
113 |
||
114 |
procedure ReleaseSound; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
115 |
var i: TSound; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
116 |
t: Longword; |
4 | 117 |
begin |
3529 | 118 |
for t:= 0 to cMaxTeams do |
119 |
if voicepacks[t].name <> '' then |
|
120 |
for i:= Low(TSound) to High(TSound) do |
|
121 |
if voicepacks[t].chunks[i] <> nil then |
|
122 |
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
|
123 |
|
3529 | 124 |
if Mus <> nil then |
125 |
Mix_FreeMusic(Mus); |
|
3182 | 126 |
|
127 |
{$IFDEF SDL_MIXER_NEWER} |
|
3529 | 128 |
// make sure all instances of sdl_mixer are unloaded before continuing |
129 |
while Mix_Init(0) <> 0 do |
|
130 |
Mix_Quit(); |
|
3697 | 131 |
{$ENDIF} |
3182 | 132 |
|
3529 | 133 |
Mix_CloseAudio(); |
4 | 134 |
end; |
135 |
||
136 |
procedure SoundLoad; |
|
137 |
var i: TSound; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
138 |
t: Longword; |
3667 | 139 |
s:shortstring; |
4 | 140 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
141 |
if not isSoundEnabled then exit; |
1656
209cf0e2fc36
Finish voicepacks support in engine (not tested though)
unc0rr
parents:
1654
diff
changeset
|
142 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
143 |
defVoicepack:= AskForVoicepack('Default'); |
3697 | 144 |
|
3529 | 145 |
for t:= 0 to cMaxTeams do |
146 |
if voicepacks[t].name <> '' then |
|
147 |
for i:= Low(TSound) to High(TSound) do |
|
3667 | 148 |
voicepacks[t].chunks[i]:= nil; |
3697 | 149 |
|
3667 | 150 |
for i:= Low(TSound) to High(TSound) do |
151 |
begin |
|
152 |
defVoicepack^.chunks[i]:= nil; |
|
153 |
// preload all the big sound files (>32k) that would otherwise lockup the game |
|
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4404
diff
changeset
|
154 |
if (i in [sndBeeWater, sndBee, sndCake, sndHellishImpact1, sndHellish, sndHomerun, |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4404
diff
changeset
|
155 |
sndMolotov, sndMortar, sndRideOfTheValkyries, sndYoohoo]) |
3667 | 156 |
and (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then |
157 |
begin |
|
158 |
s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; |
|
159 |
WriteToConsole(msgLoading + s + ' '); |
|
160 |
defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
161 |
TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); |
|
162 |
WriteLnToConsole(msgOK); |
|
163 |
end; |
|
164 |
end; |
|
3664 | 165 |
|
4 | 166 |
end; |
167 |
||
2745 | 168 |
procedure PlaySound(snd: TSound); |
169 |
begin |
|
3201 | 170 |
PlaySound(snd, nil, false); |
2745 | 171 |
end; |
172 |
||
3202 | 173 |
procedure PlaySound(snd: TSound; keepPlaying: boolean); |
174 |
begin |
|
175 |
PlaySound(snd, nil, keepPlaying); |
|
176 |
end; |
|
177 |
||
2745 | 178 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
4 | 179 |
begin |
3201 | 180 |
PlaySound(snd, voicepack, false); |
181 |
end; |
|
182 |
||
183 |
procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
|
3664 | 184 |
var s:shortstring; |
3201 | 185 |
begin |
4948 | 186 |
if (not isSoundEnabled) or fastUntilLag then |
3529 | 187 |
exit; |
3201 | 188 |
|
3529 | 189 |
if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then |
190 |
exit; |
|
191 |
||
3664 | 192 |
if (voicepack <> nil) then |
193 |
begin |
|
194 |
if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then |
|
195 |
begin |
|
196 |
s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; |
|
197 |
WriteToConsole(msgLoading + s + ' '); |
|
198 |
voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
199 |
if voicepack^.chunks[snd] = nil then |
|
200 |
WriteLnToConsole(msgFailed) |
|
201 |
else |
|
202 |
WriteLnToConsole(msgOK) |
|
203 |
end; |
|
3529 | 204 |
lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1) |
3664 | 205 |
end |
3529 | 206 |
else |
3664 | 207 |
begin |
208 |
if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then |
|
209 |
begin |
|
210 |
s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; |
|
211 |
WriteToConsole(msgLoading + s + ' '); |
|
212 |
defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
213 |
TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true); |
|
214 |
WriteLnToConsole(msgOK); |
|
215 |
end; |
|
3529 | 216 |
lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1) |
3664 | 217 |
end; |
4 | 218 |
end; |
219 |
||
2745 | 220 |
function LoopSound(snd: TSound): LongInt; |
221 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
222 |
LoopSound:= LoopSound(snd, nil) |
2745 | 223 |
end; |
224 |
||
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
225 |
function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
226 |
begin |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
227 |
LoopSound:= LoopSound(snd, nil, fadems) |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
228 |
end; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
229 |
|
2745 | 230 |
function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
231 |
begin |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
232 |
LoopSound:= LoopSound(snd, nil, 0) |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
233 |
end; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
234 |
|
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
235 |
function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
3664 | 236 |
var s: shortstring; |
2647 | 237 |
begin |
4948 | 238 |
if (not isSoundEnabled) or fastUntilLag then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
239 |
begin |
3529 | 240 |
LoopSound:= -1; |
241 |
exit |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
242 |
end; |
2647 | 243 |
|
3664 | 244 |
if (voicepack <> nil) then |
245 |
begin |
|
246 |
if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then |
|
247 |
begin |
|
248 |
s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; |
|
249 |
WriteToConsole(msgLoading + s + ' '); |
|
250 |
voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
251 |
if voicepack^.chunks[snd] = nil then |
|
252 |
WriteLnToConsole(msgFailed) |
|
253 |
else |
|
254 |
WriteLnToConsole(msgOK) |
|
255 |
end; |
|
3529 | 256 |
LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
3664 | 257 |
end |
3529 | 258 |
else |
3664 | 259 |
begin |
260 |
if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then |
|
261 |
begin |
|
262 |
s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; |
|
263 |
WriteToConsole(msgLoading + s + ' '); |
|
264 |
defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
265 |
TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true); |
|
266 |
WriteLnToConsole(msgOK); |
|
267 |
end; |
|
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
268 |
if fadems > 0 then |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
269 |
LoopSound:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1) |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
270 |
else |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
271 |
LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1); |
3664 | 272 |
end; |
2647 | 273 |
end; |
274 |
||
282 | 275 |
procedure StopSound(snd: TSound); |
4 | 276 |
begin |
3529 | 277 |
if not isSoundEnabled then exit; |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
278 |
|
3529 | 279 |
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
|
280 |
begin |
3529 | 281 |
Mix_HaltChannel(lastChan[snd]); |
282 |
lastChan[snd]:= -1; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
283 |
end; |
4 | 284 |
end; |
285 |
||
2745 | 286 |
procedure StopSound(chn: LongInt); |
287 |
begin |
|
3529 | 288 |
if not isSoundEnabled then exit; |
289 |
||
290 |
if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
|
291 |
Mix_HaltChannel(chn); |
|
2745 | 292 |
end; |
293 |
||
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
294 |
procedure StopSound(chn, fadems: LongInt); |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
295 |
begin |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
296 |
if not isSoundEnabled then exit; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
297 |
|
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
298 |
if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
299 |
Mix_FadeOutChannel(chn, fadems); |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
300 |
end; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
301 |
|
4 | 302 |
procedure PlayMusic; |
2905 | 303 |
var s: shortstring; |
4 | 304 |
begin |
3529 | 305 |
if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then |
306 |
exit; |
|
307 |
||
308 |
s:= PathPrefix + '/Music/' + MusicFN; |
|
309 |
WriteToConsole(msgLoading + s + ' '); |
|
565 | 310 |
|
3529 | 311 |
Mus:= Mix_LoadMUS(Str2PChar(s)); |
312 |
TryDo(Mus <> nil, msgFailed, false); |
|
313 |
WriteLnToConsole(msgOK); |
|
565 | 314 |
|
3529 | 315 |
SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false) |
4 | 316 |
end; |
317 |
||
371 | 318 |
function ChangeVolume(voldelta: LongInt): LongInt; |
174 | 319 |
begin |
3529 | 320 |
if not isSoundEnabled then |
321 |
exit(0); |
|
2327 | 322 |
|
3529 | 323 |
inc(Volume, voldelta); |
324 |
if Volume < 0 then Volume:= 0; |
|
325 |
Mix_Volume(-1, Volume); |
|
326 |
Volume:= Mix_Volume(-1, -1); |
|
327 |
if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); |
|
328 |
ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME |
|
174 | 329 |
end; |
330 |
||
1712 | 331 |
procedure PauseMusic; |
332 |
begin |
|
3529 | 333 |
if (MusicFN = '') or (not isMusicEnabled) then |
334 |
exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
335 |
|
3529 | 336 |
Mix_PauseMusic(Mus); |
1712 | 337 |
end; |
338 |
||
339 |
procedure ResumeMusic; |
|
340 |
begin |
|
3529 | 341 |
if (MusicFN = '') or (not isMusicEnabled) then |
342 |
exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
343 |
|
3529 | 344 |
Mix_ResumeMusic(Mus); |
1712 | 345 |
end; |
346 |
||
4748 | 347 |
procedure ChangeMusic; |
348 |
begin |
|
349 |
if (MusicFN = '') or (not isMusicEnabled) then |
|
350 |
exit; |
|
351 |
||
352 |
if Mus <> nil then |
|
353 |
Mix_FreeMusic(Mus); |
|
354 |
||
355 |
PlayMusic; |
|
356 |
end; |
|
357 |
||
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
358 |
procedure chVoicepack(var s: shortstring); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
359 |
begin |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
360 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/voicepack"', true); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
361 |
if s[1]='"' then Delete(s, 1, 1); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
362 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
363 |
CurrentTeam^.voicepack:= AskForVoicepack(s) |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
364 |
end; |
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
365 |
|
3038 | 366 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
367 |
begin |
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4377
diff
changeset
|
368 |
RegisterVariable('voicepack', vtCommand, @chVoicepack, false); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
369 |
MusicFN:=''; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
370 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
371 |
|
3038 | 372 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
373 |
begin |
3615 | 374 |
if isSoundEnabled then |
375 |
ReleaseSound(); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
376 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
377 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
378 |
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
|
379 |