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