author | unc0rr |
Sat, 02 Apr 2011 20:01:20 +0400 | |
changeset 5077 | 7915668502a6 |
parent 5052 | 74a81c276d67 |
child 5107 | d7fc678d78f4 |
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 |
5052 | 232 |
voicepack:= voicepack; // avoid compiler hint |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
233 |
LoopSound:= LoopSound(snd, nil, 0) |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
234 |
end; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
235 |
|
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
236 |
function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
3664 | 237 |
var s: shortstring; |
2647 | 238 |
begin |
4948 | 239 |
if (not isSoundEnabled) or fastUntilLag then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
240 |
begin |
3529 | 241 |
LoopSound:= -1; |
242 |
exit |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
243 |
end; |
2647 | 244 |
|
3664 | 245 |
if (voicepack <> nil) then |
246 |
begin |
|
247 |
if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then |
|
248 |
begin |
|
249 |
s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; |
|
250 |
WriteToConsole(msgLoading + s + ' '); |
|
251 |
voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
252 |
if voicepack^.chunks[snd] = nil then |
|
253 |
WriteLnToConsole(msgFailed) |
|
254 |
else |
|
255 |
WriteLnToConsole(msgOK) |
|
256 |
end; |
|
3529 | 257 |
LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
3664 | 258 |
end |
3529 | 259 |
else |
3664 | 260 |
begin |
261 |
if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then |
|
262 |
begin |
|
263 |
s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; |
|
264 |
WriteToConsole(msgLoading + s + ' '); |
|
265 |
defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
|
266 |
TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true); |
|
267 |
WriteLnToConsole(msgOK); |
|
268 |
end; |
|
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
269 |
if fadems > 0 then |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
270 |
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
|
271 |
else |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
272 |
LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1); |
3664 | 273 |
end; |
2647 | 274 |
end; |
275 |
||
282 | 276 |
procedure StopSound(snd: TSound); |
4 | 277 |
begin |
3529 | 278 |
if not isSoundEnabled then exit; |
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
279 |
|
3529 | 280 |
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
|
281 |
begin |
3529 | 282 |
Mix_HaltChannel(lastChan[snd]); |
283 |
lastChan[snd]:= -1; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
284 |
end; |
4 | 285 |
end; |
286 |
||
2745 | 287 |
procedure StopSound(chn: LongInt); |
288 |
begin |
|
3529 | 289 |
if not isSoundEnabled then exit; |
290 |
||
291 |
if (chn <> -1) and (Mix_Playing(chn) <> 0) then |
|
292 |
Mix_HaltChannel(chn); |
|
2745 | 293 |
end; |
294 |
||
4956
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
295 |
procedure StopSound(chn, fadems: LongInt); |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
296 |
begin |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
297 |
if not isSoundEnabled then exit; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
298 |
|
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
299 |
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
|
300 |
Mix_FadeOutChannel(chn, fadems); |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
301 |
end; |
48e1f9a04c28
usound: added function for loops with fade in and out
koda
parents:
4948
diff
changeset
|
302 |
|
4 | 303 |
procedure PlayMusic; |
2905 | 304 |
var s: shortstring; |
4 | 305 |
begin |
3529 | 306 |
if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then |
307 |
exit; |
|
308 |
||
309 |
s:= PathPrefix + '/Music/' + MusicFN; |
|
310 |
WriteToConsole(msgLoading + s + ' '); |
|
565 | 311 |
|
3529 | 312 |
Mus:= Mix_LoadMUS(Str2PChar(s)); |
313 |
TryDo(Mus <> nil, msgFailed, false); |
|
314 |
WriteLnToConsole(msgOK); |
|
565 | 315 |
|
3529 | 316 |
SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false) |
4 | 317 |
end; |
318 |
||
371 | 319 |
function ChangeVolume(voldelta: LongInt): LongInt; |
174 | 320 |
begin |
3529 | 321 |
if not isSoundEnabled then |
322 |
exit(0); |
|
2327 | 323 |
|
3529 | 324 |
inc(Volume, voldelta); |
325 |
if Volume < 0 then Volume:= 0; |
|
326 |
Mix_Volume(-1, Volume); |
|
327 |
Volume:= Mix_Volume(-1, -1); |
|
328 |
if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); |
|
329 |
ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME |
|
174 | 330 |
end; |
331 |
||
1712 | 332 |
procedure PauseMusic; |
333 |
begin |
|
3529 | 334 |
if (MusicFN = '') or (not isMusicEnabled) then |
335 |
exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
336 |
|
3529 | 337 |
Mix_PauseMusic(Mus); |
1712 | 338 |
end; |
339 |
||
340 |
procedure ResumeMusic; |
|
341 |
begin |
|
3529 | 342 |
if (MusicFN = '') or (not isMusicEnabled) then |
343 |
exit; |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
344 |
|
3529 | 345 |
Mix_ResumeMusic(Mus); |
1712 | 346 |
end; |
347 |
||
4748 | 348 |
procedure ChangeMusic; |
349 |
begin |
|
350 |
if (MusicFN = '') or (not isMusicEnabled) then |
|
351 |
exit; |
|
352 |
||
353 |
if Mus <> nil then |
|
354 |
Mix_FreeMusic(Mus); |
|
355 |
||
356 |
PlayMusic; |
|
357 |
end; |
|
358 |
||
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
|
3038 | 367 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
368 |
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
|
369 |
RegisterVariable('voicepack', vtCommand, @chVoicepack, false); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2905
diff
changeset
|
370 |
MusicFN:=''; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
371 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
372 |
|
3038 | 373 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
374 |
begin |
3615 | 375 |
if isSoundEnabled then |
376 |
ReleaseSound(); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
377 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2674
diff
changeset
|
378 |
|
2515
51d3f4b6293a
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
koda
parents:
2501
diff
changeset
|
379 |
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
|
380 |