equal
deleted
inserted
replaced
30 |
30 |
31 procedure InitSound; |
31 procedure InitSound; |
32 procedure ReleaseSound; |
32 procedure ReleaseSound; |
33 procedure SoundLoad; |
33 procedure SoundLoad; |
34 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack); |
34 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack); |
|
35 procedure LoopSound(snd: TSound; voicepack: PVoicepack); |
35 procedure PlayMusic; |
36 procedure PlayMusic; |
36 procedure PauseMusic; |
37 procedure PauseMusic; |
37 procedure ResumeMusic; |
38 procedure ResumeMusic; |
38 procedure StopSound(snd: TSound); |
39 procedure StopSound(snd: TSound); |
39 function ChangeVolume(voldelta: LongInt): LongInt; |
40 function ChangeVolume(voldelta: LongInt): LongInt; |
65 voicepacks[i].name:= name; |
66 voicepacks[i].name:= name; |
66 AskForVoicepack:= @voicepacks[i] |
67 AskForVoicepack:= @voicepacks[i] |
67 end; |
68 end; |
68 |
69 |
69 procedure InitSound; |
70 procedure InitSound; |
|
71 var i: TSound; |
70 begin |
72 begin |
71 if not isSoundEnabled then exit; |
73 if not isSoundEnabled then exit; |
72 WriteToConsole('Init sound...'); |
74 WriteToConsole('Init sound...'); |
73 isSoundEnabled:= SDL_Init(SDL_INIT_AUDIO) >= 0; |
75 isSoundEnabled:= SDL_Init(SDL_INIT_AUDIO) >= 0; |
74 if isSoundEnabled then |
76 if isSoundEnabled then |
76 if isSoundEnabled then WriteLnToConsole(msgOK) |
78 if isSoundEnabled then WriteLnToConsole(msgOK) |
77 else WriteLnToConsole(msgFailed); |
79 else WriteLnToConsole(msgFailed); |
78 Mix_AllocateChannels(Succ(chanTPU)); |
80 Mix_AllocateChannels(Succ(chanTPU)); |
79 if isMusicEnabled then Mix_VolumeMusic(50); |
81 if isMusicEnabled then Mix_VolumeMusic(50); |
80 |
82 |
|
83 for i:= Low(TSound) to High(TSound) do |
|
84 lastChan[i]:= -1; |
|
85 |
81 Volume:= 0; |
86 Volume:= 0; |
82 ChangeVolume(cInitVolume) |
87 ChangeVolume(cInitVolume) |
83 end; |
88 end; |
84 |
89 |
85 procedure ReleaseSound; |
90 procedure ReleaseSound; |
104 if not isSoundEnabled then exit; |
109 if not isSoundEnabled then exit; |
105 |
110 |
106 defVoicepack:= AskForVoicepack('Default'); |
111 defVoicepack:= AskForVoicepack('Default'); |
107 |
112 |
108 for i:= Low(TSound) to High(TSound) do |
113 for i:= Low(TSound) to High(TSound) do |
109 if Soundz[i].Path <> ptVoices then |
114 if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then |
110 begin |
115 begin |
111 s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; |
116 s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; |
112 WriteToConsole(msgLoading + s + ' '); |
117 WriteToConsole(msgLoading + s + ' '); |
113 defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
118 defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
114 TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); |
119 TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); |
116 end; |
121 end; |
117 |
122 |
118 for t:= 0 to cMaxTeams do |
123 for t:= 0 to cMaxTeams do |
119 if voicepacks[t].name <> '' then |
124 if voicepacks[t].name <> '' then |
120 for i:= Low(TSound) to High(TSound) do |
125 for i:= Low(TSound) to High(TSound) do |
121 if Soundz[i].Path = ptVoices then |
126 if (Soundz[i].Path = ptVoices) and (Soundz[i].FileName <> '') then |
122 begin |
127 begin |
123 s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; |
128 s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; |
124 WriteToConsole(msgLoading + s + ' '); |
129 WriteToConsole(msgLoading + s + ' '); |
125 voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
130 voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); |
126 if voicepacks[t].chunks[i] = nil then |
131 if voicepacks[t].chunks[i] = nil then |
140 lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], loops, -1) |
145 lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], loops, -1) |
141 else |
146 else |
142 lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1) |
147 lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1) |
143 end; |
148 end; |
144 |
149 |
|
150 procedure LoopSound(snd: TSound; voicepack: PVoicepack); |
|
151 begin |
|
152 if (not isSoundEnabled) or fastUntilLag then exit; |
|
153 if lastChan[snd] <> -1 then exit; |
|
154 |
|
155 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then |
|
156 lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) |
|
157 else |
|
158 lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1) |
|
159 end; |
|
160 |
145 procedure StopSound(snd: TSound); |
161 procedure StopSound(snd: TSound); |
146 begin |
162 begin |
147 if not isSoundEnabled then exit; |
163 if not isSoundEnabled then exit; |
148 if Mix_Playing(lastChan[snd]) <> 0 then |
164 if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then |
149 Mix_HaltChannel(lastChan[snd]) |
165 begin |
|
166 Mix_HaltChannel(lastChan[snd]); |
|
167 lastChan[snd]:= -1; |
|
168 end; |
150 end; |
169 end; |
151 |
170 |
152 procedure PlayMusic; |
171 procedure PlayMusic; |
153 var s: string; |
172 var s: string; |
154 begin |
173 begin |