Mercurial > mm7
annotate Media/Audio/AudioPlayer.cpp @ 2572:d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
author | a.parshin |
---|---|
date | Sat, 05 Mar 2016 01:51:54 +0200 |
parents | d569340b05ff |
children | a76d408c5132 |
rev | line source |
---|---|
2502 | 1 #define _CRTDBG_MAP_ALLOC |
2567 | 2 #define _CRT_SECURE_NO_WARNINGS |
2502 | 3 #include <stdlib.h> |
4 #include <crtdbg.h> | |
2508 | 5 #include <sstream> |
2541 | 6 #include <string> |
2508 | 7 |
2541 | 8 #include "Engine/Engine.h" |
9 | |
2502 | 10 #include "Engine/ZlibWrapper.h" |
11 | |
12 #include "../MediaPlayer.h" | |
13 #include "AudioPlayer.h" | |
14 #include "Engine/Tables/FrameTableInc.h" | |
15 #include "Engine/Graphics/Indoor.h" | |
16 #include "Engine/Objects/SpriteObject.h" | |
17 #include "Engine/Party.h" | |
18 #include "Engine/Objects/Actor.h" | |
19 #include "Engine/Graphics/DecorationList.h" | |
20 #include "Engine/Timer.h" | |
21 #include "Engine/OurMath.h" | |
22 #include "Engine/MapInfo.h" | |
23 #include "GUI/GUIWindow.h" | |
24 #include "Engine/Graphics/Level/Decoration.h" | |
25 #include "Engine/Registry.h" | |
26 | |
27 #include "Media/Video/Bink_Smacker.h" | |
28 | |
2508 | 29 #include "Engine/MMT.h" |
2502 | 30 |
31 | |
32 PCMWAVEFORMAT pcmWaveFormat; | |
33 | |
34 int uFindSound_BinSearch_ResultID; // weak | |
35 int uLastLoadedSoundID; // weak | |
36 int sLastTrackLengthMS; | |
37 std::array<Sound, 3000> pSounds; | |
38 AudioPlayer *pAudioPlayer; | |
39 SoundList *pSoundList; | |
40 | |
41 | |
42 std::array<stru339_spell_sound, 4> stru_A750F8; | |
43 std::array<stru339_spell_sound, 4> AA1058_PartyQuickSpellSound; | |
44 | |
45 | |
46 | |
47 unsigned __int8 uSoundVolumeMultiplier;// = 4; | |
48 unsigned __int8 uVoicesVolumeMultiplier;// = 4; | |
49 unsigned __int8 uMusicVolimeMultiplier;// = 4; | |
50 int bWalkSound; // idb | |
51 | |
52 std::array<float, 10> pSoundVolumeLevels = | |
53 { | |
54 0.0000000f, 0.1099999f, 0.2199999f, 0.3300000f, 0.4399999f, | |
55 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9700000f | |
56 // 0.0000000f, 0.4900000f, 0.5500000f, 0.6100000f, 0.6700000f, //for 128.0f | |
57 // 0.7000000f, 0.7600000f, 0.8200000f, 0.8800000f, 0.9700000f //changed 0.9900000f to 0.9700000f. for some reason it only works for values below this | |
58 }; | |
59 | |
60 | |
61 | |
62 | |
63 void ReleaseSoundData(void *_this); | |
64 _DIG_DRIVER *Audio_GetFirstHardwareDigitalDriver(); | |
65 | |
66 | |
67 | |
68 | |
69 //----- (004A9953) -------------------------------------------------------- | |
70 void SoundList::Initialize() | |
71 { | |
72 SoundDesc *pSoundDesc; // eax@5 | |
73 void *pSoundData; // ebx@7 | |
74 unsigned int uSoundSize; // eax@7 | |
75 char *pSoundBytes; // ebx@7 | |
76 AILFILETYPE pType; // eax@7 | |
77 int v8; // eax@8 | |
78 char pSoundName[120]; // [sp+4h] [bp-A4h]@4 | |
79 AILSOUNDINFO pInfo; // [sp+7Ch] [bp-2Ch]@10 | |
80 int v12; // [sp+A0h] [bp-8h]@12 | |
81 | |
82 if ( sNumSounds > 1 ) | |
83 { | |
84 for ( uint i = 1; i < pSoundList->sNumSounds; ++i ) | |
85 { | |
86 sprintf(pSoundName, "%s", pSL_Sounds[i].pSoundName); | |
87 pSoundDesc = &pSoundList->pSL_Sounds[i]; | |
2506 | 88 //if ( pSL_Sounds[i].uSoundID == 75 ) |
89 //__debugbreak(); | |
2502 | 90 if ( pSoundList->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM ) |
91 continue; | |
92 pSoundList->pSL_Sounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)-1, pSL_Sounds[i].uSoundID); // Ritor result crash exe file | |
93 if ( !pAudioPlayer->b3DSoundInitialized ) | |
94 continue; | |
95 pSoundDesc = &pSoundList->pSL_Sounds[i]; | |
96 if ( !(pSoundDesc->uFlags & SOUND_DESC_SWAP) || !pSoundDesc->pSoundData[0] ) | |
97 continue; | |
98 pSoundData = pSoundDesc->pSoundData[0]; | |
99 uSoundSize = *(int *)pSoundData; | |
100 pSoundBytes = (char *)pSoundData + 4; | |
101 pType = AIL_file_type(pSoundBytes, uSoundSize); | |
102 if ( !pType ) | |
103 { | |
104 pSoundList->pSL_Sounds[i].bDecompressed = false; | |
105 pSoundList->UnloadSound(i, 1); | |
106 continue; | |
107 } | |
108 v8 = pType - 1; | |
109 if ( v8 ) | |
110 { | |
111 if ( v8 == 1 ) | |
112 { | |
113 if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 ) | |
114 { | |
115 if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSL_Sounds[i].p3DSound, &v12) ) | |
116 { | |
117 pSoundList->pSL_Sounds[i].p3DSound = 0; | |
118 pSoundList->pSL_Sounds[i].bDecompressed = true; | |
119 } | |
120 } | |
121 pSoundList->UnloadSound(i, 1); | |
122 continue; | |
123 } | |
124 pSoundList->pSL_Sounds[i].bDecompressed = false; | |
125 pSoundList->UnloadSound(i, 1); | |
126 continue; | |
127 } | |
128 pSoundList->pSL_Sounds[i].p3DSound = pSoundList->pSL_Sounds[i].pSoundData[0]; | |
129 pSoundList->UnloadSound(i, 1); | |
130 } | |
131 } | |
132 //_CrtDumpMemoryLeaks(); | |
133 } | |
134 | |
135 //----- (004A9A67) -------------------------------------------------------- | |
136 __int16 SoundList::LoadSound(int a1, unsigned int a3) | |
137 { | |
138 AILSOUNDINFO v24; // [sp+84h] [bp-28h]@23 | |
139 | |
140 if (bNoSound || !sNumSounds) | |
141 return 0; | |
142 | |
143 uint uSoundIdx = 0; | |
144 SoundDesc *pSound = nullptr; | |
145 for (uint i = 1; i < sNumSounds; ++i) | |
146 if (pSL_Sounds[i].uSoundID == a1) | |
147 { | |
148 uSoundIdx = i; | |
149 pSound = &pSL_Sounds[i]; | |
150 break; | |
151 } | |
152 if (!pSound) | |
153 return 0; | |
154 | |
155 if (pSound->uFlags & SOUND_DESC_SWAP && pSound->p3DSound || | |
156 ~pSound->uFlags & SOUND_DESC_SWAP && pSound->pSoundData[0]) | |
157 return uSoundIdx; | |
158 | |
159 if (!pSound->pSoundData[0]) | |
160 pSound->pSoundData[0] = ::LoadSound(pSound->pSoundName, (SoundData *)-1, pSound->uSoundID); | |
161 | |
162 if (!pSound->pSoundData[0]) | |
163 return 0; | |
164 | |
165 if (a3) | |
166 pSound->uFlags |= SOUND_DESC_SYSTEM; | |
167 | |
168 if (!pAudioPlayer->b3DSoundInitialized) | |
169 return uSoundIdx; | |
170 | |
171 if (~pSound->uFlags & SOUND_DESC_SWAP || !pSound->pSoundData[0]) | |
172 return uSoundIdx; | |
173 | |
174 | |
175 SoundData* pSoundData = pSound->pSoundData[0]; | |
176 switch (AIL_file_type((void *)pSoundData->pData, pSoundData->uDataSize)) | |
177 { | |
178 default: | |
179 case AILFILETYPE_UNKNOWN: | |
180 pSound->bDecompressed = false; | |
181 return 0; | |
182 | |
183 case AILFILETYPE_PCM_WAV: | |
184 pSound->p3DSound = pSound->pSoundData[0]; | |
185 return uSoundIdx; | |
186 | |
187 case AILFILETYPE_ADPCM_WAV: | |
188 if (AIL_WAV_info((void *)pSoundData->pData, &v24) && v24.uChannels != 2) | |
189 { | |
190 if (!AIL_decompress_ADPCM(&v24, &pSound->p3DSound, &a1) ) | |
191 { | |
192 pSound->p3DSound = nullptr; | |
193 pSound->bDecompressed = true; | |
194 UnloadSound(uSoundIdx, 0); | |
195 } | |
196 } | |
197 return uSoundIdx; | |
198 }; | |
199 } | |
200 | |
201 //----- (004A9BBD) -------------------------------------------------------- | |
202 int SoundList::LoadSound(unsigned int a2, LPVOID lpBuffer, int uBufferSizeLeft, int *pOutSoundSize, int a6) | |
203 { | |
204 void *v18; // ebx@19 | |
205 DWORD NumberOfBytesRead; | |
206 | |
207 if (!sNumSounds) | |
208 return 0; | |
209 | |
210 for ( uint i = 0; i < sNumSounds; ++i ) | |
211 { | |
212 if ( a2 == pSL_Sounds[i].uSoundID ) | |
213 { | |
214 if ( !a6 && pSL_Sounds[i].pSoundData ) | |
215 return i; | |
216 for ( uint j = 0; j < (signed int)pAudioPlayer->uNumSoundHeaders; ++j ) | |
217 { | |
218 if ( !_stricmp(pAudioPlayer->pSoundHeaders[j].pSoundName, pSL_Sounds[i].pSoundName) ) | |
219 { | |
220 if ( (signed int)pAudioPlayer->pSoundHeaders[j].uDecompressedSize > uBufferSizeLeft ) | |
221 Error("Sound %s is size %i bytes, sound buffer size is %i bytes", pSL_Sounds[i].pSoundName, pAudioPlayer->pSoundHeaders[j].uDecompressedSize, uBufferSizeLeft); | |
222 SetFilePointer(pAudioPlayer->hAudioSnd, pAudioPlayer->pSoundHeaders[j].uFileOffset, 0, 0); | |
223 if ( (signed int)pAudioPlayer->pSoundHeaders[j].uCompressedSize >= (signed int)pAudioPlayer->pSoundHeaders[j].uDecompressedSize ) | |
224 { | |
225 if ( pAudioPlayer->pSoundHeaders[j].uCompressedSize == pAudioPlayer->pSoundHeaders[j].uDecompressedSize ) | |
226 ReadFile(pAudioPlayer->hAudioSnd, lpBuffer, pAudioPlayer->pSoundHeaders[j].uDecompressedSize, &NumberOfBytesRead, 0); | |
227 else | |
228 MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:666", 0); | |
229 } | |
230 else | |
231 { | |
232 v18 = malloc(pAudioPlayer->pSoundHeaders[j].uCompressedSize); | |
233 ReadFile(pAudioPlayer->hAudioSnd, v18, pAudioPlayer->pSoundHeaders[j].uCompressedSize, &NumberOfBytesRead, 0); | |
234 zlib::MemUnzip(lpBuffer, &pAudioPlayer->pSoundHeaders[j].uDecompressedSize, v18, pAudioPlayer->pSoundHeaders[j].uCompressedSize); | |
235 free(v18); | |
236 } | |
237 pSL_Sounds[i].pSoundData[a6] = (SoundData *)lpBuffer; | |
238 *pOutSoundSize = a2; | |
239 return i; | |
240 } | |
241 } | |
242 } | |
243 } | |
244 return 0; | |
245 } | |
246 | |
247 //----- (004A9D3E) -------------------------------------------------------- | |
248 SoundDesc *SoundList::Release() | |
249 { | |
250 SoundDesc *result; // eax@3 | |
251 //void *v5; // ecx@3 | |
252 | |
253 if ( (signed int)this->sNumSounds > 0 ) | |
254 { | |
255 for ( uint i = 0; i < (signed int)this->sNumSounds; ++i ) | |
256 { | |
257 result = this->pSL_Sounds; | |
258 //v5 = this->pSL_Sounds[i].pSoundData[0]; | |
259 if ( this->pSL_Sounds[i].pSoundData[0] ) | |
260 { | |
261 ReleaseSoundData(this->pSL_Sounds[i].pSoundData[0]); | |
262 this->pSL_Sounds[i].pSoundData[0] = nullptr; | |
2505 | 263 this->pSL_Sounds[i].uFlags &= 0xFFFFFFFE;//~0x00000001 |
2502 | 264 } |
265 } | |
266 } | |
267 return result; | |
268 } | |
269 | |
270 //----- (004A9D79) -------------------------------------------------------- | |
271 void SoundList::_4A9D79(int a2) | |
272 { | |
273 for ( int i = 0; i < (signed int)this->sNumSounds; ++i ) | |
274 { | |
275 if ( this->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSL_Sounds[i].eType != SOUND_DESC_LOCK) ) | |
276 { | |
277 if ( this->pSL_Sounds[i].pSoundData[0] ) | |
278 { | |
279 ReleaseSoundData(this->pSL_Sounds[i].pSoundData[0]); | |
280 this->pSL_Sounds[i].pSoundData[0] = nullptr; | |
281 } | |
282 this->pSL_Sounds[i].uFlags &= ~SOUND_DESC_SYSTEM; | |
283 } | |
284 } | |
285 } | |
286 | |
287 //----- (004A9DCD) -------------------------------------------------------- | |
288 void SoundList::UnloadSound(unsigned int uSoundID, char a3) | |
289 { | |
290 if ( pSL_Sounds[uSoundID].eType != SOUND_DESC_SYSTEM ) | |
291 { | |
292 if ( (pSL_Sounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSL_Sounds[uSoundID].p3DSound && a3 ) | |
293 { | |
294 if ( pSL_Sounds[uSoundID].bDecompressed) | |
295 AIL_mem_free_lock(pSL_Sounds[uSoundID].p3DSound); | |
296 pSL_Sounds[uSoundID].p3DSound = 0; | |
297 pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM; | |
298 } | |
299 if ( pSL_Sounds[uSoundID].pSoundData[0] ) | |
300 { | |
301 ReleaseSoundData(pSL_Sounds[uSoundID].pSoundData[0]); | |
302 pSL_Sounds[uSoundID].pSoundData[0] = nullptr; | |
303 pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM; | |
304 } | |
305 } | |
306 } | |
307 | |
308 | |
309 //----- (004A9E3D) -------------------------------------------------------- | |
310 void SoundList::ToFile() | |
311 { | |
312 FILE *v2; // eax@1 | |
313 | |
314 v2 = fopen("data\\dsounds.bin", "wb"); | |
315 if ( !v2 ) | |
316 Error("Unable to save dsounds.bin!"); | |
317 | |
318 fwrite(this, 4, 1, v2); | |
319 fwrite(this->pSL_Sounds, 0x78u, this->sNumSounds, v2); | |
320 fclose(v2); | |
321 } | |
322 | |
323 //----- (004A9E89) -------------------------------------------------------- | |
324 void SoundList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) | |
325 { | |
326 uint num_mm6_sounds = data_mm6 ? *(int *)data_mm6 : 0, | |
327 num_mm7_sounds = data_mm7 ? *(int *)data_mm7 : 0, | |
328 num_mm8_sounds = data_mm8 ? *(int *)data_mm8 : 0; | |
329 | |
330 sNumSounds = num_mm6_sounds + num_mm7_sounds + num_mm8_sounds; | |
331 assert(sNumSounds); | |
332 assert(!num_mm8_sounds); | |
333 | |
334 pSL_Sounds = (SoundDesc *)malloc(sNumSounds * sizeof(SoundDesc)); | |
335 memcpy(pSL_Sounds, (char *)data_mm7 + 4, num_mm7_sounds * sizeof(SoundDesc)); | |
336 for (uint i = 0; i < num_mm6_sounds; ++i) | |
337 { | |
338 auto src = (SoundDesc_mm6 *)((char *)data_mm6 + 4) + i; | |
339 SoundDesc* dst = &pSL_Sounds[num_mm7_sounds + i]; | |
340 | |
341 memcpy(dst, src, sizeof(SoundDesc_mm6)); | |
342 dst->p3DSound = nullptr; | |
343 dst->bDecompressed = false; | |
344 } | |
345 } | |
346 | |
347 //----- (004A9ED0) -------------------------------------------------------- | |
348 int SoundList::FromFileTxt(const char *Args) | |
349 { | |
350 __int32 v3; // edi@1 | |
351 FILE *v4; // eax@1 | |
352 unsigned int v5; // esi@3 | |
353 void *v6; // eax@9 | |
354 FILE *v7; // ST0C_4@11 | |
355 char *i; // eax@11 | |
356 char Buf; // [sp+Ch] [bp-2F0h]@3 | |
357 FrameTableTxtLine v18; // [sp+200h] [bp-FCh]@4 | |
358 FrameTableTxtLine v19; // [sp+27Ch] [bp-80h]@4 | |
359 FILE *File; // [sp+2F8h] [bp-4h]@1 | |
360 unsigned int Argsa; // [sp+304h] [bp+8h]@3 | |
361 | |
362 free(this->pSL_Sounds); | |
363 v3 = 0; | |
364 this->pSL_Sounds = 0; | |
365 this->sNumSounds = 0; | |
366 v4 = fopen(Args, "r"); | |
367 File = v4; | |
368 if ( !v4 ) | |
369 Error("SoundListClass::load - Unable to open file: %s."); | |
370 | |
371 v5 = 0; | |
372 Argsa = 0; | |
373 if ( fgets(&Buf, 490, v4) ) | |
374 { | |
375 do | |
376 { | |
377 *strchr(&Buf, 10) = 0; | |
378 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); | |
379 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) | |
380 ++Argsa; | |
381 } | |
382 while ( fgets(&Buf, 490, File) ); | |
383 v5 = Argsa; | |
384 v3 = 0; | |
385 } | |
386 this->sNumSounds = v5; | |
387 v6 = malloc(120 * v5); | |
388 this->pSL_Sounds = (SoundDesc *)v6; | |
389 if ( v6 == (void *)v3 ) | |
390 Error("SoundListClass::load - Out of Memory!"); | |
391 | |
392 memset(v6, v3, 120 * this->sNumSounds); | |
393 v7 = File; | |
394 this->sNumSounds = v3; | |
395 fseek(v7, v3, v3); | |
396 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
397 { | |
398 *strchr(&Buf, 10) = 0; | |
399 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); | |
400 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) | |
401 { | |
402 sprintf(this->pSL_Sounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]); | |
403 this->pSL_Sounds[this->sNumSounds].uSoundID = atoi(v19.pProperties[1]); | |
404 if ( _stricmp(v19.pProperties[2], "system") ) | |
405 { | |
406 if ( _stricmp(v19.pProperties[2], "swap") ) | |
407 { | |
408 if ( !_stricmp(v19.pProperties[2], "lock") ) | |
409 this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_LOCK; | |
410 else | |
411 this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_LEVEL; | |
412 } | |
413 else | |
414 this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SWAP; | |
415 } | |
416 else | |
417 this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM; | |
418 if ( v19.uPropCount >= 4 && !_stricmp(v19.pProperties[3], "3D") ) | |
419 this->pSL_Sounds[this->sNumSounds].uFlags |= SOUND_DESC_SWAP; | |
420 ++this->sNumSounds; | |
421 } | |
422 } | |
423 fclose(File); | |
424 return 1; | |
425 } | |
2516 | 426 //char to wchar_t |
2508 | 427 bool char2wchar_t(char *str1, wchar_t *str2) |
428 { | |
2516 | 429 std::wstringstream st; |
430 st << str1; | |
431 return !(st >> str2).fail(); | |
432 } | |
2502 | 433 //----- (004AA13F) -------------------------------------------------------- |
434 void AudioPlayer::PlayMusicTrack(MusicID eTrack) | |
435 { | |
2508 | 436 if (!bNoSound && bPlayerReady && uMusicVolimeMultiplier) |
2502 | 437 { |
2508 | 438 if ( use_music_folder ) |
2516 | 439 { |
2508 | 440 alSourceStop(mSourceID); |
2534 | 441 |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2567
diff
changeset
|
442 char string[256]; |
2516 | 443 sprintf(string, "Music\\%d.mp3", eTrack); |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2567
diff
changeset
|
444 |
2509 | 445 if (!FileExists(string)) |
2516 | 446 { |
2534 | 447 Log::Warning(L"Music\\%d.mp3 not found", eTrack); |
2516 | 448 return; |
449 } | |
450 LPWSTR wStr = new WCHAR[255]; | |
451 char2wchar_t(string, wStr); | |
452 PlayAudio(wStr); | |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2567
diff
changeset
|
453 delete [] wStr; |
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2567
diff
changeset
|
454 alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]); |
2516 | 455 } |
456 else if ( hAILRedbook ) | |
457 { | |
2508 | 458 AIL_redbook_stop(hAILRedbook); |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2567
diff
changeset
|
459 AIL_redbook_set_volume(hAILRedbook, 64.0f * pSoundVolumeLevels[uMusicVolimeMultiplier]); |
2508 | 460 AIL_redbook_track_info(hAILRedbook, eTrack, &uCurrentMusicTrackStartMS, &uCurrentMusicTrackEndMS); |
461 AIL_redbook_play(hAILRedbook, uCurrentMusicTrackStartMS + 1, uCurrentMusicTrackEndMS); | |
462 uCurrentMusicTrackLength = ((uCurrentMusicTrackEndMS - uCurrentMusicTrackStartMS) * 128) / 1000; | |
2516 | 463 } |
2502 | 464 } |
465 } | |
466 | |
467 //----- (004AA1F3) -------------------------------------------------------- | |
468 void AudioPlayer::SetMusicVolume(int vol) | |
469 { | |
470 if (bPlayerReady) | |
471 { | |
472 if (hAILRedbook) | |
473 AIL_redbook_set_volume(hAILRedbook, vol); | |
474 } | |
475 } | |
476 | |
477 //----- (004AA214) -------------------------------------------------------- | |
478 void AudioPlayer::SetMasterVolume(float fVolume) | |
479 { | |
480 if ( bPlayerReady ) | |
481 { | |
482 uMasterVolume = fVolume; | |
483 if ( hDigDriver ) | |
484 AIL_set_digital_master_volume(hDigDriver, fVolume); | |
485 if ( b3DSoundInitialized ) | |
486 s3DSoundVolume = fVolume * 0.5f; | |
487 } | |
488 } | |
489 // 4D8304: using guessed type int __stdcall AIL_set_digital_master_volume(int, int); | |
490 | |
491 //----- (004AA258) -------------------------------------------------------- | |
492 void AudioPlayer::_4AA258(int a2) | |
493 { | |
494 if (!bPlayerReady) | |
495 return; | |
496 | |
497 if ( this->b3DSoundInitialized && a2 ) | |
498 { | |
499 for ( uint i = 0; i < this->uNum3DSamples; ++i ) | |
500 { | |
501 if ( this->p3DSamples[i].field_4 == a2 && AIL_3D_sample_status(this->p3DSamples[i].hSample) == AIL::Sample::Playing ) | |
502 AIL_end_3D_sample(this->p3DSamples[i].hSample); | |
503 } | |
504 } | |
505 if ( this->hDigDriver && a2 ) | |
506 { | |
507 for ( uint i = 0; i < this->uMixerChannels; ++i ) | |
508 { | |
509 if ( this->pMixerChannels[i].source_pid == a2 && AIL_sample_status(this->pMixerChannels[i].hSample) == AIL::Sample::Playing) | |
510 { | |
511 AIL_end_sample(this->pMixerChannels[i].hSample); | |
512 FreeChannel(&this->pMixerChannels[i]); | |
513 } | |
514 } | |
515 } | |
516 } | |
517 | |
518 //----- (004AA306) -------------------------------------------------------- | |
519 void AudioPlayer::PlaySound(SoundID eSoundID, signed int pid, unsigned int uNumRepeats, signed int source_x, signed int source_y, int sound_data_id, float uVolume, int sPlaybackRate) | |
520 { | |
521 int v12; // edi@13 | |
522 signed int v13; // ecx@17 | |
523 signed int v14; // eax@20 | |
524 int v15; // eax@24 | |
525 signed int v16; // eax@25 | |
526 SpriteObject *pLayingItem; // eax@28 | |
527 signed int v18; // eax@29 | |
528 Actor *pActor1; // eax@32 | |
529 signed int v20; // ecx@32 | |
530 double v21; // st7@32 | |
531 signed int v22; // ecx@33 | |
532 AudioPlayer_3DSample *pAudioPlayer_3DSample; // esi@53 | |
533 AudioPlayer_3DSample *pAudioPlayer_3DSample1; // esi@61 | |
534 int v25; // esi@67 | |
535 double v26; // st7@68 | |
536 int v27; // ST18_4@68 | |
537 int v28; // ebx@68 | |
538 int v29; // eax@68 | |
539 AudioPlayer_3DSample *pAudioPlayer_3DSample2; // esi@69 | |
540 int v31; // ST18_4@70 | |
541 int v32; // ebx@70 | |
542 int v33; // eax@70 | |
543 int v34; // eax@70 | |
544 char v35; // zf@70 | |
545 signed int v36; // ebx@74 | |
546 AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79 | |
547 int v40; // eax@81 | |
548 char *v41; // edi@82 | |
549 int v42; // esi@82 | |
550 double v43; // st7@91 | |
551 SpriteObject *pLayingItem2; // eax@92 | |
552 Actor *pActor; // eax@93 | |
553 signed int v46; // ecx@93 | |
554 double v47; // st7@93 | |
555 BLVDoor *pBLVDoor; // eax@97 | |
556 double v49; // st7@104 | |
557 int v50; // ST18_4@104 | |
558 int v51; // ebx@104 | |
559 int v52; // eax@104 | |
560 float v53; // ST0C_4@106 | |
561 float v54; // ST04_4@106 | |
562 signed int v62; // esi@133 | |
563 unsigned int v86; // [sp+14h] [bp-60h]@84 | |
564 RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1 | |
565 int v90; // [sp+58h] [bp-1Ch]@68 | |
566 float v91; // [sp+5Ch] [bp-18h]@68 | |
567 float v93; // [sp+64h] [bp-10h]@1 | |
568 signed int varC; // [sp+68h] [bp-Ch]@68 | |
569 int v96; // [sp+70h] [bp-4h]@19 | |
570 signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93 | |
571 float uNumRepeatsa; // [sp+84h] [bp+10h]@104 | |
572 float v99; // [sp+8Ch] [bp+18h]@104 | |
573 signed int v100; // [sp+90h] [bp+1Ch]@32 | |
574 int v101; // [sp+90h] [bp+1Ch]@52 | |
575 int v102; // [sp+90h] [bp+1Ch]@60 | |
576 int v103; // [sp+90h] [bp+1Ch]@68 | |
577 | |
578 if ( !bPlayerReady || !uSoundVolumeMultiplier || !hDigDriver || eSoundID == SOUND_Invalid ) | |
579 return; | |
580 | |
2505 | 581 float sample_volume = 10000; |
2502 | 582 |
583 int sound_id = 0; | |
584 for (uint i = 0; i < pSoundList->sNumSounds; ++i) | |
585 if (pSoundList->pSL_Sounds[i].uSoundID == eSoundID) | |
586 { | |
587 sound_id = i; | |
588 break; | |
589 } | |
590 | |
591 if (!sound_id) | |
592 { | |
593 Log::Warning(L"SoundID = %u not found", eSoundID); | |
594 return; | |
595 } | |
596 assert(sound_id < pSoundList->sNumSounds); | |
597 if ( !sound_data_id ) | |
598 { | |
599 if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[0] ) | |
600 { | |
601 if ( pSoundList->pSL_Sounds[sound_id].eType == SOUND_DESC_SWAP ) | |
602 pSoundList->LoadSound(eSoundID, 0); | |
603 } | |
604 } | |
605 if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] ) | |
606 return; | |
607 | |
608 int start_channel = 0, | |
609 end_channel = 0; | |
610 v62 = start_channel; | |
611 | |
612 if (!b3DSoundInitialized || pSoundList->pSL_Sounds[sound_id].Is3D()) | |
613 { | |
614 if (pid == 0) // generic sound like from UI | |
615 { | |
616 start_channel = 10; | |
617 end_channel = 12; | |
618 for (uint i = start_channel; i <= end_channel; ++i) | |
619 { | |
620 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
621 { | |
622 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
623 return; // already playing the same sound from the same source - return | |
624 AIL_end_sample(pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
625 FreeChannel(&pMixerChannels[i]); | |
626 } | |
627 } | |
628 for ( uint j = start_channel; j <= end_channel; j++ ) | |
629 { | |
630 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
631 { | |
632 AIL_init_sample(pMixerChannels[j].hSample); | |
2506 | 633 AIL_set_sample_file(pMixerChannels[j].hSample, pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id]->pData, -1); |
2502 | 634 if ( sample_volume == 10000 ) |
635 sample_volume = uMasterVolume; | |
636 if (uVolume) | |
637 sample_volume = uVolume; | |
638 int object_type = PID_TYPE(pid), | |
639 object_id = PID_ID(pid); | |
640 if (source_x != -1)//ñðàáàòûâàåò íàïðèìåð ó ôîðòà â Õåðìîíäåéëå çâóê âûñòðåëîâ ïóøåê | |
641 { | |
642 //if (!source_x) | |
643 //source_x = pParty->vPosition.x; | |
644 //if (!source_y) | |
645 //source_y = pParty->vPosition.y; | |
646 if ( source_x )//Ritor1: for pedestals | |
647 { | |
648 AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(source_x, source_y)); | |
649 int vol = GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z); | |
650 AIL_set_sample_volume(pMixerChannels[j].hSample, vol); | |
651 } | |
652 } | |
653 if (uNumRepeats) | |
654 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
655 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
656 pMixerChannels[j].source_pid = pid; | |
657 pMixerChannels[j].uSourceTrackID = eSoundID; | |
658 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
659 if ( sPlaybackRate ) | |
660 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
661 if (object_type == OBJECT_Player) | |
662 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
663 return; | |
664 } | |
665 } | |
666 return; | |
667 } | |
668 else if (pid == -1) // exclusive sounds - can override | |
669 { | |
670 /*if ( AIL_sample_status(pMixerChannels[13].hSample) == AIL::Sample::Done ) | |
671 { | |
672 AIL_end_sample(pMixerChannels[13].hSample); | |
673 if ( pMixerChannels[13].uSourceTrackIdx ) | |
674 FreeChannel(&pMixerChannels[13]); | |
675 }*/ | |
676 AIL_init_sample(pMixerChannels[13].hSample); | |
2506 | 677 AIL_set_sample_file(pMixerChannels[13].hSample, pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id]->pData, -1); |
678 if ( sample_volume == 10000 ) | |
679 sample_volume = uMasterVolume; | |
680 if (uVolume) | |
681 sample_volume = uVolume; | |
682 AIL_set_sample_volume(pMixerChannels[13].hSample, sample_volume); | |
683 int object_type = PID_TYPE(pid), | |
684 object_id = PID_ID(pid); | |
685 if (uNumRepeats) | |
686 AIL_set_sample_loop_count(pMixerChannels[13].hSample, uNumRepeats - 1); | |
687 pMixerChannels[13].uSourceTrackIdx = sound_id; | |
688 pMixerChannels[13].source_pid = pid; | |
689 pMixerChannels[13].uSourceTrackID = eSoundID; | |
690 int rval = AIL_start_sample(pMixerChannels[13].hSample);//no sound chest close | |
691 if ( sPlaybackRate ) | |
692 AIL_set_sample_playback_rate(pMixerChannels[13].hSample, sPlaybackRate); | |
693 if (object_type == OBJECT_Player) | |
694 AIL_sample_ms_position(pMixerChannels[13].hSample, &sLastTrackLengthMS, 0); | |
695 return; | |
2502 | 696 } |
697 else if (pid < 0) // exclusive sounds - no override (close chest) | |
698 { | |
699 start_channel = 14; | |
700 end_channel = 14; | |
701 for (uint i = start_channel; i <= end_channel; ++i) | |
702 { | |
703 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
704 { | |
705 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
706 return; // already playing the same sound from the same source - return | |
707 AIL_end_sample(pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
708 FreeChannel(&pMixerChannels[i]); | |
709 } | |
710 } | |
711 for ( uint j = start_channel; j <= end_channel; j++ ) | |
712 { | |
713 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
714 { | |
715 AIL_init_sample(pMixerChannels[j].hSample); | |
716 char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id]; | |
2506 | 717 if (sound_data_id == 0) |
718 p = p + 4;//for RIFF | |
2502 | 719 AIL_set_sample_file(pMixerChannels[j].hSample, p, -1); |
720 if ( sample_volume == 10000 ) | |
721 sample_volume = uMasterVolume; | |
722 if (uVolume) | |
723 sample_volume = uVolume; | |
724 int object_type = PID_TYPE(pid), | |
725 object_id = PID_ID(pid); | |
726 if (uNumRepeats) | |
727 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
728 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
729 pMixerChannels[j].source_pid = pid; | |
730 pMixerChannels[j].uSourceTrackID = eSoundID; | |
731 int rval = AIL_start_sample(pMixerChannels[j].hSample);//no sound chest close | |
732 if ( sPlaybackRate ) | |
733 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
734 if (object_type == OBJECT_Player) | |
735 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
736 return; | |
737 } | |
738 } | |
739 return; | |
740 } | |
741 else | |
742 { | |
743 int object_type = PID_TYPE(pid), | |
744 object_id = PID_ID(pid); | |
745 switch (object_type) | |
746 { | |
747 case OBJECT_BLVDoor: | |
748 { | |
749 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); | |
750 assert(object_id < pIndoor->uNumDoors); | |
751 if ( !pIndoor->pDoors[object_id].uDoorID ) | |
752 return; | |
753 | |
754 start_channel = 10; | |
755 end_channel = 12; | |
756 for (uint i = start_channel; i <= end_channel; ++i) | |
757 { | |
758 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
759 { | |
760 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
761 return; // already playing the same sound from the same source - return | |
762 AIL_end_sample( pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
763 FreeChannel(&pMixerChannels[i]); | |
764 } | |
765 } | |
766 for ( uint j = start_channel; j <= end_channel; j++ ) | |
767 { | |
768 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
769 { | |
770 AIL_init_sample(pMixerChannels[j].hSample); | |
771 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
772 if (uVolume) | |
773 sample_volume = uVolume; | |
774 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); | |
775 /*if (!GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0], pIndoor->pDoors[object_id].pZOffsets[0])) | |
776 { | |
777 AIL_end_sample(pMixerChannels[j].hSample); | |
778 FreeChannel(&pMixerChannels[j]); | |
779 return; | |
780 } */ | |
781 AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0])); | |
782 if (uNumRepeats) | |
783 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
784 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
785 pMixerChannels[j].source_pid = pid; | |
786 pMixerChannels[j].uSourceTrackID = eSoundID; | |
787 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
788 if ( sPlaybackRate ) | |
789 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
790 if (object_type == OBJECT_Player) | |
791 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
792 return; | |
793 } | |
794 } | |
795 } | |
796 return; | |
797 | |
798 case OBJECT_Player: | |
799 { | |
800 start_channel = 10; | |
801 end_channel = 12; | |
802 for (uint i = start_channel; i <= end_channel; ++i) | |
803 { | |
804 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
805 { | |
806 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
807 return; // already playing the same sound from the same source - return | |
808 AIL_end_sample( pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
809 FreeChannel(&pMixerChannels[i]); | |
810 } | |
811 } | |
812 for ( uint j = start_channel; j <= end_channel; j++ ) | |
813 { | |
814 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
815 { | |
816 AIL_init_sample(pMixerChannels[j].hSample); | |
817 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
818 if (uVolume) | |
819 sample_volume = uVolume; | |
820 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); | |
821 if (uNumRepeats) | |
822 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
823 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
824 pMixerChannels[j].source_pid = pid; | |
825 pMixerChannels[j].uSourceTrackID = eSoundID; | |
826 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
827 if ( sPlaybackRate ) | |
828 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
829 if (object_type == OBJECT_Player) | |
830 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
831 return; | |
832 } | |
833 } | |
834 } | |
835 return; | |
836 | |
837 case OBJECT_Actor: | |
838 { | |
839 start_channel = 0; | |
840 end_channel = 3; | |
841 assert(object_id < uNumActors); | |
842 sample_volume = GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z); | |
843 if (!sample_volume) | |
844 return; | |
845 for (uint i = start_channel; i <= end_channel; ++i) | |
846 { | |
847 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
848 { | |
849 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
850 return; // already playing the same sound from the same source - return | |
851 AIL_end_sample( pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
852 FreeChannel(&pMixerChannels[i]); | |
853 } | |
854 } | |
855 for ( uint j = start_channel; j <= end_channel; j++ ) | |
856 { | |
857 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
858 { | |
859 AIL_init_sample(pMixerChannels[j].hSample); | |
860 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
861 if (uVolume) | |
862 sample_volume = uVolume; | |
863 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); | |
864 if (!GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z)) | |
865 return; | |
866 AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y)); | |
867 if (uNumRepeats) | |
868 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
869 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
870 pMixerChannels[j].source_pid = pid; | |
871 pMixerChannels[j].uSourceTrackID = eSoundID; | |
872 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
873 if ( sPlaybackRate ) | |
874 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
875 if (object_type == OBJECT_Player) | |
876 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
877 return; | |
878 } | |
879 } | |
880 } | |
881 return; | |
882 | |
883 case OBJECT_Decoration: | |
884 { | |
885 start_channel = 4; | |
886 end_channel = 4; | |
887 assert(object_id < uNumLevelDecorations); | |
888 sample_volume = GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z); | |
2505 | 889 if (sample_volume == 0.0) |
2502 | 890 return; |
2505 | 891 if ( pid > 0 ) |
892 { | |
2502 | 893 for (uint i = start_channel; i <= end_channel; ++i) |
894 { | |
895 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )//çâóê ôîíòàíà è øàãîâ íå ïðîõîäÿò ïðîâåðêó íà ïîâòîð | |
896 { | |
897 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
898 return; // already playing the same sound from the same source - return | |
899 AIL_end_sample(pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
900 FreeChannel(&pMixerChannels[i]); | |
901 } | |
902 } | |
2505 | 903 } |
2502 | 904 for ( uint j = start_channel; j <= end_channel; j++ ) |
905 { | |
906 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
907 { | |
908 AIL_init_sample(pMixerChannels[j].hSample); | |
909 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
2505 | 910 if (uVolume == 0.0) |
911 sample_volume = uMasterVolume; | |
2502 | 912 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); |
913 if (!GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z)) | |
914 return; | |
2505 | 915 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); |
2502 | 916 AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y)); |
917 if (uNumRepeats) | |
918 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
919 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
920 pMixerChannels[j].source_pid = pid; | |
921 pMixerChannels[j].uSourceTrackID = eSoundID; | |
922 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
923 if ( sPlaybackRate ) | |
924 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
925 if (object_type == OBJECT_Player) | |
926 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
927 return; | |
928 } | |
929 } | |
930 } | |
931 return; | |
932 | |
933 case OBJECT_Item: | |
934 { | |
935 start_channel = 5; | |
936 end_channel = 7; | |
937 assert(object_id < uNumSpriteObjects); | |
938 sample_volume = GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z); | |
939 if (!sample_volume) | |
940 return; | |
941 for (uint i = start_channel; i <= end_channel; ++i) | |
942 { | |
943 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
944 { | |
945 if (pMixerChannels[i].uSourceTrackIdx == sound_id) | |
946 return; // already playing the same sound from the same source - return | |
947 AIL_end_sample(pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
948 FreeChannel(&pMixerChannels[i]); | |
949 } | |
950 } | |
951 for ( uint j = start_channel; j <= end_channel; j++ ) | |
952 { | |
953 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
954 { | |
955 AIL_init_sample(pMixerChannels[j].hSample); | |
956 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
957 if (uVolume) | |
958 sample_volume = uVolume; | |
959 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); | |
960 if (!GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z) ) | |
961 return; | |
962 AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y)); | |
963 if (uNumRepeats) | |
964 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
965 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
966 pMixerChannels[j].source_pid = pid; | |
967 pMixerChannels[j].uSourceTrackID = eSoundID; | |
968 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
969 if ( sPlaybackRate ) | |
970 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
971 if (object_type == OBJECT_Player) | |
972 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
973 return; | |
974 } | |
975 } | |
976 } | |
977 return; | |
978 | |
979 case OBJECT_BModel: | |
980 { | |
981 start_channel = 8; | |
982 end_channel = 9; | |
983 for (uint i = start_channel; i <= end_channel; ++i) | |
984 { | |
985 if ( pMixerChannels[i].source_pid == pid && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) | |
986 { | |
987 if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) | |
988 return; // already playing the same sound from the same source - return | |
989 AIL_end_sample(pMixerChannels[i].hSample); // requested new sound from the same source - end & switch | |
990 FreeChannel(&pMixerChannels[i]); | |
991 } | |
992 } | |
993 for ( uint j = start_channel; j <= end_channel; j++ ) | |
994 { | |
995 if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) | |
996 { | |
997 AIL_init_sample(pMixerChannels[j].hSample); | |
998 AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
999 if (uVolume) | |
1000 sample_volume = uVolume; | |
1001 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); | |
1002 if (uNumRepeats) | |
1003 AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); | |
1004 pMixerChannels[j].uSourceTrackIdx = sound_id; | |
1005 pMixerChannels[j].source_pid = pid; | |
1006 pMixerChannels[j].uSourceTrackID = eSoundID; | |
1007 int rval = AIL_start_sample(pMixerChannels[j].hSample); | |
1008 if ( sPlaybackRate ) | |
1009 AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); | |
1010 if (object_type == OBJECT_Player) | |
1011 AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); | |
1012 return; | |
1013 } | |
1014 } | |
1015 } | |
1016 return; | |
1017 | |
1018 default: | |
1019 assert(false); | |
1020 } | |
1021 } | |
1022 | |
1023 __debugbreak();//Ritor1 | |
1024 if (start_channel > end_channel) // no free channel - occupy the quitest one | |
1025 { | |
1026 start_channel = -1; | |
1027 int min_volume = sample_volume; | |
1028 for (uint i = start_channel; i <= end_channel; ++i) | |
1029 { | |
1030 int volume = AIL_sample_volume(pMixerChannels[i].hSample); | |
1031 if (volume < min_volume) | |
1032 { | |
1033 min_volume = volume; | |
1034 start_channel = i; | |
1035 } | |
1036 } | |
1037 if (v62 == -1) // no free channels at all - only channel 13 allows override (a3 == -1) | |
1038 { | |
1039 if (start_channel != 13) | |
1040 return; | |
1041 v62 = 13; | |
1042 } | |
1043 AIL_end_sample(pMixerChannels[v62].hSample); | |
1044 FreeChannel(&pMixerChannels[v62]); | |
1045 } | |
1046 | |
1047 if (v62 > end_channel)//10!=13 | |
1048 return; | |
1049 | |
1050 if ( sample_volume == 10000 ) | |
1051 sample_volume = uMasterVolume; | |
1052 | |
1053 AIL_init_sample(pMixerChannels[v62].hSample); | |
1054 AIL_set_sample_file(pMixerChannels[v62].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[sound_data_id] + 4 * (sound_data_id == 0), -1); | |
1055 if (uVolume) | |
1056 sample_volume = uVolume; | |
1057 AIL_set_sample_volume(pMixerChannels[v62].hSample, sample_volume); | |
1058 | |
1059 int object_type = PID_TYPE(pid), | |
1060 object_id = PID_ID(pid); | |
1061 if (source_x != -1) | |
1062 { | |
1063 if (!source_x) | |
1064 source_x = pParty->vPosition.x; | |
1065 if (!source_y) | |
1066 source_y = pParty->vPosition.y; | |
1067 AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(source_x, source_y)); | |
1068 AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z)); | |
1069 } | |
1070 | |
1071 if (uNumRepeats) | |
1072 AIL_set_sample_loop_count(pMixerChannels[v62].hSample, uNumRepeats - 1); | |
1073 pMixerChannels[v62].uSourceTrackIdx = sound_id; | |
1074 pMixerChannels[v62].source_pid = pid; | |
1075 pMixerChannels[v62].uSourceTrackID = eSoundID; | |
1076 int rval = AIL_start_sample(pMixerChannels[v62].hSample); | |
1077 if ( sPlaybackRate ) | |
1078 AIL_set_sample_playback_rate(pMixerChannels[v62].hSample, sPlaybackRate); | |
1079 if (object_type == OBJECT_Player) | |
1080 AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0); | |
1081 return; | |
1082 } | |
1083 else | |
1084 { | |
1085 __debugbreak(); // 3d sound stuff, refactor | |
1086 v12 = 13; | |
1087 if ( pid < 0 ) | |
1088 { | |
1089 v15 = pAudioPlayer->uNum3DSamples; | |
1090 if ( pid == -1 ) | |
1091 { | |
1092 if ( v15 < 16 ) | |
1093 v12 = v15 - 1; | |
1094 v96 = v12; | |
1095 //goto LABEL_46; | |
1096 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1097 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1098 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1099 goto LABEL_47; | |
1100 } | |
1101 if ( v15 >= 16 ) | |
1102 v15 = 14; | |
1103 v12 = v15; | |
1104 //goto LABEL_45; | |
1105 v96 = v15; | |
1106 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1107 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1108 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1109 goto LABEL_47; | |
1110 } | |
1111 if ( PID_TYPE(pid) == 2 ) | |
1112 { | |
1113 v22 = pAudioPlayer->uNum3DSamples; | |
1114 if ( v22 < 16 ) | |
1115 { | |
1116 v12 = 5 * v22 / 16; | |
1117 v96 = 7 * v22 / 16; | |
1118 } | |
1119 else | |
1120 { | |
1121 v96 = 7; | |
1122 v12 = 5; | |
1123 } | |
1124 pLayingItem = &pSpriteObjects[PID_ID(pid)]; | |
1125 } | |
1126 else | |
1127 { | |
1128 if ( PID_TYPE(pid) == 3 ) | |
1129 { | |
1130 v18 = pAudioPlayer->uNum3DSamples; | |
1131 v12 = 0; | |
1132 if ( v18 < 16 ) | |
1133 v96 = 3 * v18 / 16; | |
1134 else | |
1135 v96 = 3; | |
1136 pActor1 = &pActors[PID_ID(pid)]; | |
1137 v20 = pActor1->vPosition.y; | |
1138 pRenderVertexSoft.vWorldPosition.x = (double)pActor1->vPosition.x; | |
1139 v100 = pActor1->vPosition.z; | |
1140 pRenderVertexSoft.vWorldPosition.y = (double)v20; | |
1141 v21 = (double)v100; | |
1142 goto LABEL_47; | |
1143 } | |
1144 if ( PID_TYPE(pid) != 5 ) | |
1145 { | |
1146 v13 = pAudioPlayer->uNum3DSamples; | |
1147 if ( PID_TYPE(pid) == 6 ) | |
1148 { | |
1149 if ( v13 >= 16 ) | |
1150 { | |
1151 v96 = 9; | |
1152 v12 = 8; | |
1153 //goto LABEL_46; | |
1154 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1155 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1156 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1157 goto LABEL_47; | |
1158 } | |
1159 v12 = 8 * v13 / 16; | |
1160 v14 = 9 * v13; | |
1161 } | |
1162 else | |
1163 { | |
1164 if ( v13 >= 16 ) | |
1165 { | |
1166 v96 = 12; | |
1167 v12 = 10; | |
1168 //LABEL_46: | |
1169 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1170 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1171 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1172 goto LABEL_47; | |
1173 } | |
1174 v12 = 10 * v13 / 16; | |
1175 v14 = 12 * v13; | |
1176 } | |
1177 v15 = v14 / 16; | |
1178 //LABEL_45: | |
1179 v96 = v15; | |
1180 //goto LABEL_46; | |
1181 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1182 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1183 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1184 goto LABEL_47; | |
1185 } | |
1186 v16 = pAudioPlayer->uNum3DSamples; | |
1187 if ( v16 < 16 ) | |
1188 { | |
1189 v12 = v16 / 4; | |
1190 v96 = v16 / 4; | |
1191 } | |
1192 else | |
1193 { | |
1194 v12 = 4; | |
1195 v96 = 4; | |
1196 } | |
1197 pLayingItem = (SpriteObject *)&pLevelDecorations[PID_ID(pid)]; | |
1198 } | |
1199 pRenderVertexSoft.vWorldPosition.x = (double)pLayingItem->vPosition.x; | |
1200 pRenderVertexSoft.vWorldPosition.y = (double)pLayingItem->vPosition.y; | |
1201 v21 = (double)pLayingItem->vPosition.z; | |
1202 LABEL_47: | |
1203 pRenderVertexSoft.vWorldPosition.z = v21; | |
1204 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1205 sub_4AAEA6_transform(&pRenderVertexSoft); | |
1206 else | |
2543 | 1207 pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1); |
2502 | 1208 if ( pid ) |
1209 { | |
1210 if ( pid != -1 ) | |
1211 { | |
1212 v101 = 0; | |
1213 if ( pAudioPlayer->uNum3DSamples > 0 ) | |
1214 { | |
1215 pAudioPlayer_3DSample = pAudioPlayer->p3DSamples; | |
1216 do | |
1217 { | |
1218 if ( AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 | |
1219 && pAudioPlayer_3DSample->field_4 == pid && AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 ) | |
1220 { | |
1221 if ( pAudioPlayer_3DSample->field_8 == sound_id ) | |
1222 return; | |
1223 AIL_end_3D_sample(pAudioPlayer_3DSample->hSample); | |
1224 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample); | |
1225 } | |
1226 ++v101; | |
1227 ++pAudioPlayer_3DSample; | |
1228 } | |
1229 while ( v101 < pAudioPlayer->uNum3DSamples ); | |
1230 } | |
1231 } | |
1232 } | |
1233 v102 = v12; | |
1234 if ( v12 <= v96 ) | |
1235 { | |
1236 pAudioPlayer_3DSample1 = &pAudioPlayer->p3DSamples[v12]; | |
1237 while ( AIL_3D_sample_status(pAudioPlayer_3DSample1->hSample) != 2 ) | |
1238 { | |
1239 ++v102; | |
1240 ++pAudioPlayer_3DSample1; | |
1241 if ( v102 > v96 ) | |
1242 goto LABEL_67; | |
1243 } | |
1244 AIL_end_3D_sample(pAudioPlayer_3DSample1->hSample); | |
1245 if ( pAudioPlayer_3DSample1->field_8 ) | |
1246 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample1); | |
1247 } | |
1248 LABEL_67: | |
1249 v25 = v96; | |
1250 if ( v102 == v96 + 1 ) | |
1251 { | |
1252 LODWORD(v91) = -1; | |
1253 v103 = 0; | |
1254 *(float *)&varC = pRenderVertexSoft.vWorldViewPosition.y * -0.012207031; | |
1255 v93 = 0.0; | |
1256 v26 = pRenderVertexSoft.vWorldViewPosition.x * 0.012207031; | |
1257 *(float *)&uVolume = v26; | |
1258 v27 = abs((signed __int64)v26); | |
1259 v28 = abs((signed __int64)v93); | |
1260 v29 = abs((signed __int64)*(float *)&varC); | |
1261 v90 = int_get_vector_length(v29, v28, v27); | |
1262 sPlaybackRate = v12; | |
1263 if ( v12 > v25 ) | |
1264 goto LABEL_192; | |
1265 pAudioPlayer_3DSample2 = &pAudioPlayer->p3DSamples[v12]; | |
1266 do | |
1267 { | |
1268 AIL_3D_position(pAudioPlayer_3DSample2->hSample, &varC, &v93, (long *)&uVolume); | |
1269 v31 = abs((signed __int64)*(float *)&uVolume); | |
1270 v32 = abs((signed __int64)v93); | |
1271 v33 = abs((signed __int64)*(float *)&varC); | |
1272 v34 = int_get_vector_length(v33, v32, v31); | |
1273 v35 = v103 == v34; | |
1274 if ( v103 < v34 ) | |
1275 { | |
1276 v103 = v34; | |
1277 v35 = 1; | |
1278 } | |
1279 if ( v35 && v90 < v103 ) | |
1280 { | |
1281 v36 = sPlaybackRate; | |
1282 LODWORD(v91) = sPlaybackRate; | |
1283 } | |
1284 else | |
1285 { | |
1286 v36 = LODWORD(v91); | |
1287 } | |
1288 ++sPlaybackRate; | |
1289 ++pAudioPlayer_3DSample2; | |
1290 } | |
1291 while ( sPlaybackRate <= v96 ); | |
1292 if ( v36 == -1 ) | |
1293 { | |
1294 LABEL_192: | |
1295 v36 = 13; | |
1296 if ( v12 != 13 ) | |
1297 return; | |
1298 } | |
1299 //pAudioPlayer2 = pAudioPlayer; | |
1300 pAudioPlayer_3DSample3 = &pAudioPlayer->p3DSamples[v36]; | |
1301 AIL_end_3D_sample(pAudioPlayer_3DSample3->hSample); | |
1302 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample3); | |
1303 v102 = v36; | |
1304 } | |
1305 //v39 = v89; | |
1306 if ( pSoundList->pSL_Sounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) ) | |
1307 { | |
1308 v41 = (char *)pAudioPlayer + 16 * v102; | |
1309 v42 = (int)(v41 + 20); | |
1310 if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSL_Sounds->p3DSound + sound_id * sizeof(SoundDesc))) ) | |
1311 { | |
1312 if ( uNumRepeats ) | |
1313 v86 = uNumRepeats - 1; | |
1314 else | |
1315 v86 = 1; | |
1316 AIL_set_3D_sample_loop_count(*(int *)v42, v86); | |
1317 if ( source_x == -1 ) | |
1318 { | |
1319 if ( PID_TYPE(pid) == 1 ) | |
1320 { | |
1321 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1322 { | |
1323 //goto LABEL_103; | |
1324 pBLVDoor = &pIndoor->pDoors[PID_ID(pid)]; | |
1325 if ( !pBLVDoor->uDoorID ) | |
1326 return; | |
1327 pRenderVertexSoft.vWorldPosition.x = (double)*pBLVDoor->pXOffsets; | |
1328 pRenderVertexSoft.vWorldPosition.y = (double)*pBLVDoor->pYOffsets; | |
1329 v47 = (double)*pBLVDoor->pZOffsets; | |
1330 LABEL_101: | |
1331 pRenderVertexSoft.vWorldPosition.z = v47; | |
1332 //if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1333 //{ | |
1334 sub_4AAEA6_transform(&pRenderVertexSoft); | |
1335 //goto LABEL_104; | |
1336 //} | |
1337 } | |
1338 //LABEL_103: | |
1339 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor ) | |
2543 | 1340 pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1); |
2502 | 1341 //LABEL_104: |
1342 AIL_start_3D_sample(*(int *)v42); | |
1343 AIL_set_3D_sample_float_distances(*(int **)v42, 100.0, 20.0, 100.0, 20.0); | |
1344 AIL_set_3D_sample_volume(*(int **)v42, pAudioPlayer->s3DSoundVolume); | |
1345 v99 = pRenderVertexSoft.vWorldViewPosition.y * -0.012207031; | |
1346 v49 = pRenderVertexSoft.vWorldViewPosition.x * 0.012207031; | |
1347 uNumRepeatsa = v49; | |
1348 v50 = abs((signed __int64)v49); | |
1349 v51 = abs(0); | |
1350 v52 = abs((signed __int64)v99); | |
1351 if ( int_get_vector_length(v52, v51, v50) <= 100 ) | |
1352 { | |
1353 AIL_set_3D_position((void *)*(int *)v42, LODWORD(v99), 0.0, LODWORD(uNumRepeatsa)); | |
1354 v53 = -uNumRepeatsa; | |
1355 v54 = -v99; | |
1356 AIL_set_3D_orientation((void *)*(int *)v42, LODWORD(v54), 0.0, LODWORD(v53), 0.0, 1.0, 0.0); | |
1357 //pAudioPlayer3 = pAudioPlayer; | |
1358 *((int *)v41 + 6) = pid; | |
1359 *((int *)v41 + 7) = sound_id; | |
1360 *(&pAudioPlayer->bEAXSupported + 4 * (v102 + 2)) = eSoundID; | |
1361 } | |
1362 else | |
1363 { | |
1364 AIL_end_3D_sample(*(int **)v42); | |
1365 pAudioPlayer->_4ABF23((AudioPlayer_3DSample *)(v41 + 20)); | |
1366 } | |
1367 return; | |
1368 } | |
1369 if ( PID_TYPE(pid) == 2 ) | |
1370 { | |
1371 pLayingItem2 = &pSpriteObjects[PID_ID(pid)]; | |
1372 } | |
1373 else | |
1374 { | |
1375 if ( PID_TYPE(pid) == 3 ) | |
1376 { | |
1377 pActor = &pActors[PID_ID(pid)]; | |
1378 v46 = pActor->vPosition.y; | |
1379 pRenderVertexSoft.vWorldPosition.x = (double)pActor->vPosition.x; | |
1380 uNumRepeatsb = pActor->vPosition.z; | |
1381 pRenderVertexSoft.vWorldPosition.y = (double)v46; | |
1382 v47 = (double)uNumRepeatsb; | |
1383 goto LABEL_101; | |
1384 } | |
1385 if ( PID_TYPE(pid) != 5 ) | |
1386 { | |
1387 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1388 v43 = (double)pParty->vPosition.y; | |
1389 pRenderVertexSoft.vWorldPosition.y = v43; | |
1390 v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1391 goto LABEL_101; | |
1392 } | |
1393 pLayingItem2 = (SpriteObject *)&pLevelDecorations[PID_ID(pid)]; | |
1394 } | |
1395 pRenderVertexSoft.vWorldPosition.x = (double)pLayingItem2->vPosition.x; | |
1396 pRenderVertexSoft.vWorldPosition.y = (double)pLayingItem2->vPosition.y; | |
1397 v47 = (double)pLayingItem2->vPosition.z; | |
1398 goto LABEL_101; | |
1399 } | |
1400 pRenderVertexSoft.vWorldPosition.x = (double)source_x; | |
1401 v43 = (double)source_y; | |
1402 pRenderVertexSoft.vWorldPosition.y = v43; | |
1403 v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1404 goto LABEL_101; | |
1405 } | |
1406 } | |
1407 } | |
1408 } | |
1409 | |
1410 //----- (0040DEA5) -------------------------------------------------------- | |
1411 void AudioPlayer::MessWithChannels() | |
1412 { | |
1413 pAudioPlayer->StopChannels(-1, -1); | |
1414 } | |
1415 | |
1416 | |
1417 //----- (004AAFCF) -------------------------------------------------------- | |
1418 void AudioPlayer::UpdateSounds() | |
1419 { | |
1420 int v2; // ebx@1 | |
1421 int v7; // ebx@6 | |
1422 int v8; // ebx@9 | |
1423 int v9; // ebx@10 | |
1424 int v10; // ebx@11 | |
1425 double v11; // st7@13 | |
1426 SpriteObject *v12; // eax@14 | |
1427 Actor *v13; // eax@15 | |
1428 BLVDoor *pDoor; // eax@19 | |
1429 double v16; // st7@22 | |
1430 double v17; // st6@22 | |
1431 double v18; // st5@23 | |
1432 double v19; // st4@24 | |
1433 double v20; // st3@24 | |
1434 double v21; // st6@28 | |
1435 double v22; // st7@32 | |
1436 int v23; // ST1C_4@32 | |
1437 int v24; // ebx@32 | |
1438 int v25; // eax@32 | |
1439 float v26; // ST10_4@34 | |
1440 float v27; // ST08_4@34 | |
1441 signed int v53; // eax@88 | |
1442 RenderVertexSoft a1; // [sp+24h] [bp-48h]@1 | |
1443 float v55; // [sp+54h] [bp-18h]@22 | |
1444 float v56; // [sp+58h] [bp-14h]@22 | |
1445 int uNumRepeats; // [sp+5Ch] [bp-10h]@15 | |
1446 float v58; // [sp+60h] [bp-Ch]@23 | |
1447 int v59; // [sp+64h] [bp-8h]@4 | |
1448 | |
1449 v2 = 0; | |
1450 if (!bPlayerReady) | |
1451 return; | |
1452 | |
1453 //if (field_2D0_time_left <= pEventTimer->uTimeElapsed) | |
1454 //field_2D0_time_left = 32; | |
1455 //else | |
1456 //{ | |
1457 //field_2D0_time_left -= pEventTimer->uTimeElapsed; | |
1458 //return; | |
1459 //} | |
1460 field_2D0_time_left -= pEventTimer->uTimeElapsed; | |
1461 if ( field_2D0_time_left <= 0 ) | |
1462 { | |
1463 field_2D0_time_left = 32; | |
1464 if ( b3DSoundInitialized )//for 3D sound | |
1465 { | |
1466 __debugbreak(); // refactor refactor | |
1467 v2 = 0; | |
1468 for ( v59 = 0; v59 < pAudioPlayer->uNum3DSamples; ++v59 ) | |
1469 { | |
1470 v7 = PID_TYPE(this->p3DSamples[v59].field_4); | |
1471 if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) == AIL::Sample::Done ) | |
1472 { | |
1473 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1474 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1475 } | |
1476 if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) != AIL::Sample::Playing ) | |
1477 continue; | |
1478 v8 = v7 - 1;// | |
1479 if ( v8 )//> 1 | |
1480 { | |
1481 v9 = v8 - 1;// | |
1482 if ( v9 )//> 2 | |
1483 { | |
1484 v10 = v9 - 1;// | |
1485 if ( !v10 )//3 | |
1486 { | |
1487 v13 = &pActors[PID_ID(this->p3DSamples[v59].field_4)]; | |
1488 //uNumRepeats = v13->vPosition.x; | |
1489 //v14 = v13->vPosition.y; | |
1490 a1.vWorldPosition.x = (double)v13->vPosition.x; | |
1491 //uNumRepeats = v13->vPosition.z; | |
1492 a1.vWorldPosition.y = (double)v13->vPosition.y; | |
1493 //v11 = (double)uNumRepeats; | |
1494 a1.vWorldPosition.z = v13->vPosition.z; | |
1495 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1496 { | |
2543 | 1497 v16 = pIndoorCameraD3D->fRotationXCosine; |
1498 v17 = pIndoorCameraD3D->fRotationXSine; | |
1499 v55 = pIndoorCameraD3D->fRotationYCosine; | |
1500 v56 = pIndoorCameraD3D->fRotationYSine; | |
1501 if (pIndoorCameraD3D->sRotationX) | |
2502 | 1502 { |
1503 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1504 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1505 v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1506 //if ( pRenderer->pRenderD3D ) | |
1507 { | |
1508 v19 = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1509 v20 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1510 } | |
2557 | 1511 //else |
1512 // { | |
1513 // v19 = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1514 // v20 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1515 //} | |
2502 | 1516 a1.vWorldViewPosition.x = v19 * v16 - v18 * v17; |
1517 a1.vWorldViewPosition.y = v20; | |
1518 a1.vWorldViewPosition.z = v19 * v17 + v18 * v16; | |
1519 } | |
1520 else | |
1521 { | |
1522 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1523 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1524 //if ( pRenderer->pRenderD3D ) | |
1525 { | |
1526 a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1527 v21 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1528 } | |
2557 | 1529 //else |
1530 //{ | |
1531 // a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1532 // v21 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1533 //} | |
2502 | 1534 a1.vWorldViewPosition.y = v21; |
1535 a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1536 } | |
1537 } | |
1538 else | |
2543 | 1539 pIndoorCameraD3D->ViewTransform(&a1, 1); |
2502 | 1540 v58 = a1.vWorldViewPosition.y * -0.012207031; |
1541 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1542 *(float *)&uNumRepeats = v22; | |
1543 v23 = abs((signed __int64)v22); | |
1544 v24 = abs(0); | |
1545 v25 = abs((signed __int64)v58); | |
1546 if ( int_get_vector_length(v25, v24, v23) <= 100 ) | |
1547 { | |
1548 AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1549 v26 = -*(float *)&uNumRepeats; | |
1550 v27 = -v58; | |
1551 AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1552 } | |
1553 else | |
1554 { | |
1555 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1556 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1557 } | |
1558 continue; | |
1559 } | |
1560 if ( v10 != 2 )//4 | |
1561 { | |
1562 a1.vWorldPosition.x = (double)pParty->vPosition.x; | |
1563 a1.vWorldPosition.y = (double)pParty->vPosition.y; | |
1564 v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1565 a1.vWorldPosition.z = v11; | |
1566 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1567 { | |
2543 | 1568 v16 = pIndoorCameraD3D->fRotationXCosine; |
1569 v17 = pIndoorCameraD3D->fRotationXSine; | |
1570 v55 = pIndoorCameraD3D->fRotationYCosine; | |
1571 v56 = pIndoorCameraD3D->fRotationYSine; | |
1572 if (pIndoorCameraD3D->sRotationX) | |
2502 | 1573 { |
1574 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1575 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1576 v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1577 //if ( pRenderer->pRenderD3D ) | |
1578 { | |
1579 v19 = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1580 v20 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1581 } | |
2557 | 1582 //else |
1583 //{ | |
1584 // v19 = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1585 // v20 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1586 //} | |
2502 | 1587 a1.vWorldViewPosition.x = v19 * v16 - v18 * v17; |
1588 a1.vWorldViewPosition.y = v20; | |
1589 a1.vWorldViewPosition.z = v19 * v17 + v18 * v16; | |
1590 } | |
1591 else | |
1592 { | |
1593 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1594 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1595 //if ( pRenderer->pRenderD3D ) | |
1596 { | |
1597 a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1598 v21 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1599 } | |
2557 | 1600 //else |
1601 //{ | |
1602 // a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1603 // v21 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1604 //} | |
2502 | 1605 a1.vWorldViewPosition.y = v21; |
1606 a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1607 } | |
1608 } | |
1609 else | |
2543 | 1610 pIndoorCameraD3D->ViewTransform(&a1, 1); |
2502 | 1611 v58 = a1.vWorldViewPosition.y * -0.012207031; |
1612 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1613 *(float *)&uNumRepeats = v22; | |
1614 v23 = abs((signed __int64)v22); | |
1615 v24 = abs(0); | |
1616 v25 = abs((signed __int64)v58); | |
1617 if ( int_get_vector_length(v25, v24, v23) <= 100 ) | |
1618 { | |
1619 AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1620 v26 = -*(float *)&uNumRepeats; | |
1621 v27 = -v58; | |
1622 AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1623 } | |
1624 else | |
1625 { | |
1626 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1627 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1628 } | |
1629 continue; | |
1630 }//5 | |
1631 v12 = (SpriteObject *)&pLevelDecorations[PID_ID(this->p3DSamples[v59].field_4)]; | |
1632 } | |
1633 else//2 | |
1634 v12 = &pSpriteObjects[PID_ID(this->p3DSamples[v59].field_4)]; | |
1635 a1.vWorldPosition.x = (double)v12->vPosition.x; | |
1636 a1.vWorldPosition.y = (double)v12->vPosition.y; | |
1637 v11 = (double)v12->vPosition.z; | |
1638 //LABEL_21: | |
1639 a1.vWorldPosition.z = v11; | |
1640 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1641 { | |
2543 | 1642 v16 = pIndoorCameraD3D->fRotationXCosine; |
1643 v17 = pIndoorCameraD3D->fRotationXSine; | |
1644 v55 = pIndoorCameraD3D->fRotationYCosine; | |
1645 v56 = pIndoorCameraD3D->fRotationYSine; | |
1646 if (pIndoorCameraD3D->sRotationX) | |
2502 | 1647 { |
1648 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1649 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1650 v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1651 //if ( pRenderer->pRenderD3D ) | |
1652 { | |
1653 v19 = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1654 v20 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1655 } | |
2557 | 1656 //else |
1657 // { | |
1658 // v19 = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1659 // v20 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1660 //} | |
2502 | 1661 a1.vWorldViewPosition.x = v19 * v16 - v18 * v17; |
1662 a1.vWorldViewPosition.y = v20; | |
1663 a1.vWorldViewPosition.z = v19 * v17 + v18 * v16; | |
1664 } | |
1665 else | |
1666 { | |
1667 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1668 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1669 //if ( pRenderer->pRenderD3D ) | |
1670 { | |
1671 a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1672 v21 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1673 } | |
2557 | 1674 //else |
1675 //{ | |
1676 //a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1677 //v21 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1678 //} | |
2502 | 1679 a1.vWorldViewPosition.y = v21; |
1680 a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1681 } | |
1682 } | |
1683 else | |
2543 | 1684 pIndoorCameraD3D->ViewTransform(&a1, 1); |
2502 | 1685 v58 = a1.vWorldViewPosition.y * -0.012207031; |
1686 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1687 *(float *)&uNumRepeats = v22; | |
1688 v23 = abs((signed __int64)v22); | |
1689 v24 = abs(0); | |
1690 v25 = abs((signed __int64)v58); | |
1691 if ( int_get_vector_length(v25, v24, v23) <= 100 ) | |
1692 { | |
1693 AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1694 v26 = -*(float *)&uNumRepeats; | |
1695 v27 = -v58; | |
1696 AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1697 } | |
1698 else | |
1699 { | |
1700 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1701 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1702 } | |
1703 continue; | |
1704 } | |
1705 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1 | |
1706 { | |
2543 | 1707 pIndoorCameraD3D->ViewTransform(&a1, 1); |
2502 | 1708 v58 = a1.vWorldViewPosition.y * -0.012207031; |
1709 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1710 *(float *)&uNumRepeats = v22; | |
1711 v23 = abs((signed __int64)v22); | |
1712 v24 = abs(0); | |
1713 v25 = abs((signed __int64)v58); | |
1714 if ( int_get_vector_length(v25, v24, v23) <= 100 ) | |
1715 { | |
1716 AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1717 v26 = -*(float *)&uNumRepeats; | |
1718 v27 = -v58; | |
1719 AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1720 } | |
1721 else | |
1722 { | |
1723 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1724 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1725 } | |
1726 continue; | |
1727 } | |
1728 pDoor = &pIndoor->pDoors[PID_ID(this->p3DSamples[v59].field_4)]; | |
1729 if ( pDoor->uDoorID ) | |
1730 { | |
1731 uNumRepeats = *pDoor->pXOffsets; | |
1732 a1.vWorldPosition.x = (double)uNumRepeats; | |
1733 uNumRepeats = *pDoor->pYOffsets; | |
1734 a1.vWorldPosition.y = (double)uNumRepeats; | |
1735 uNumRepeats = *pDoor->pZOffsets; | |
1736 v11 = (double)uNumRepeats; | |
1737 a1.vWorldPosition.z = v11; | |
1738 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1739 { | |
2543 | 1740 v16 = pIndoorCameraD3D->fRotationXCosine; |
1741 v17 = pIndoorCameraD3D->fRotationXSine; | |
1742 v55 = pIndoorCameraD3D->fRotationYCosine; | |
1743 v56 = pIndoorCameraD3D->fRotationYSine; | |
1744 if (pIndoorCameraD3D->sRotationX) | |
2502 | 1745 { |
1746 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1747 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1748 v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1749 //if ( pRenderer->pRenderD3D ) | |
1750 { | |
1751 v19 = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1752 v20 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1753 } | |
2557 | 1754 //else |
1755 //{ | |
1756 // v19 = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1757 // v20 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1758 //} | |
2502 | 1759 a1.vWorldViewPosition.x = v19 * v16 - v18 * v17; |
1760 a1.vWorldViewPosition.y = v20; | |
1761 a1.vWorldViewPosition.z = v19 * v17 + v18 * v16; | |
1762 } | |
1763 else | |
1764 { | |
1765 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1766 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1767 //if ( pRenderer->pRenderD3D ) | |
1768 { | |
1769 a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1770 v21 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1771 } | |
2557 | 1772 //else |
1773 //{ | |
1774 // a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1775 // v21 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1776 //} | |
2502 | 1777 a1.vWorldViewPosition.y = v21; |
1778 a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1779 } | |
1780 } | |
1781 else | |
2543 | 1782 pIndoorCameraD3D->ViewTransform(&a1, 1); |
2502 | 1783 v58 = a1.vWorldViewPosition.y * -0.012207031; |
1784 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1785 *(float *)&uNumRepeats = v22; | |
1786 v23 = abs((signed __int64)v22); | |
1787 v24 = abs(0); | |
1788 v25 = abs((signed __int64)v58); | |
1789 if ( int_get_vector_length(v25, v24, v23) <= 100 ) | |
1790 { | |
1791 AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1792 v26 = -*(float *)&uNumRepeats; | |
1793 v27 = -v58; | |
1794 AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1795 } | |
1796 else | |
1797 { | |
1798 AIL_end_3D_sample(this->p3DSamples[v59].hSample); | |
1799 pAudioPlayer->_4ABF23(&this->p3DSamples[v59]); | |
1800 } | |
1801 } | |
1802 } | |
1803 //} | |
1804 } | |
1805 | |
1806 //LABEL_37: | |
1807 for (int i = 0; i < uMixerChannels; ++i) | |
1808 { | |
1809 if (AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Done) | |
1810 { | |
1811 AIL_end_sample(pMixerChannels[i].hSample); | |
1812 FreeChannel(&pMixerChannels[i]); | |
1813 } | |
1814 } | |
1815 | |
1816 for (int i = 0; i < uMixerChannels; ++i) | |
1817 { | |
1818 if (pMixerChannels[i].source_pid <= 0) | |
1819 continue; | |
1820 | |
1821 int source_type = PID_TYPE(pMixerChannels[i].source_pid), | |
1822 source_id = PID_ID(pMixerChannels[i].source_pid); | |
1823 // int source_x, | |
1824 // int source_y, | |
1825 // source_z; | |
1826 | |
1827 switch (source_type) | |
1828 { | |
1829 case 0: | |
1830 case OBJECT_Player: | |
1831 case OBJECT_BModel: | |
1832 continue; | |
1833 | |
1834 case OBJECT_BLVDoor: | |
1835 { | |
1836 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); | |
1837 | |
1838 assert(source_id < pIndoor->uNumDoors); | |
1839 if (!pIndoor->pDoors[source_id].uDoorID) | |
1840 continue; | |
1841 | |
1842 //source_x = pIndoor->pDoors[source_id].pXOffsets[0]; | |
1843 //source_y = pIndoor->pDoors[source_id].pYOffsets[0]; | |
1844 //source_z = pIndoor->pDoors[source_id].pZOffsets[0]; | |
1845 int sound_strength = GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[source_id].pXOffsets[0], | |
1846 pIndoor->pDoors[source_id].pYOffsets[0], | |
1847 pIndoor->pDoors[source_id].pZOffsets[0]); | |
1848 if ( sound_strength ) | |
1849 { | |
1850 AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength); | |
1851 AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pIndoor->pDoors[source_id].pXOffsets[0], | |
1852 pIndoor->pDoors[source_id].pYOffsets[0])); | |
1853 } | |
1854 else | |
1855 { | |
1856 AIL_end_sample(pMixerChannels[i].hSample); | |
1857 FreeChannel(&pMixerChannels[i]); | |
1858 } | |
1859 } | |
1860 continue; | |
1861 | |
1862 case OBJECT_Item: | |
1863 { | |
1864 //assert(source_id < uNumSpriteObjects); // Ritor1:â èäà äî è ïîñëå ïåðåõîäà îäèíàêîâî | |
1865 | |
1866 //source_x = pSpriteObjects[source_id].vPosition.x; | |
1867 //source_y = pSpriteObjects[source_id].vPosition.y; | |
1868 //source_z = pSpriteObjects[source_id].vPosition.z; | |
1869 int sound_strength = GetSoundStrengthByDistanceFromParty(pSpriteObjects[source_id].vPosition.x, | |
1870 pSpriteObjects[source_id].vPosition.y, | |
1871 pSpriteObjects[source_id].vPosition.z); | |
1872 if ( sound_strength ) | |
1873 { | |
1874 AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength); | |
1875 AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pSpriteObjects[source_id].vPosition.x, | |
1876 pSpriteObjects[source_id].vPosition.y)); | |
1877 } | |
1878 else | |
1879 { | |
1880 AIL_end_sample(pMixerChannels[i].hSample); | |
1881 FreeChannel(&pMixerChannels[i]); | |
1882 } | |
1883 } | |
1884 continue; | |
1885 | |
1886 case OBJECT_Decoration: | |
1887 { | |
1888 assert(source_id < uNumLevelDecorations); | |
1889 | |
1890 //source_x = pLevelDecorations[source_id].vPosition.x; | |
1891 //source_y = pLevelDecorations[source_id].vPosition.y; | |
1892 //source_z = pLevelDecorations[source_id].vPosition.z; | |
1893 int sound_strength = GetSoundStrengthByDistanceFromParty(pLevelDecorations[source_id].vPosition.x, | |
1894 pLevelDecorations[source_id].vPosition.y, | |
1895 pLevelDecorations[source_id].vPosition.z); | |
1896 if ( sound_strength ) | |
1897 { | |
2505 | 1898 //AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength); |
2502 | 1899 AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pLevelDecorations[source_id].vPosition.x, |
1900 pLevelDecorations[source_id].vPosition.y)); | |
1901 } | |
1902 else | |
1903 { | |
1904 AIL_end_sample(pMixerChannels[i].hSample); | |
1905 FreeChannel(&pMixerChannels[i]); | |
1906 } | |
1907 } | |
1908 continue; | |
1909 | |
1910 case OBJECT_Actor: | |
1911 { | |
1912 assert(source_id < uNumActors); | |
1913 | |
1914 //source_x = pActors[source_id].vPosition.x; | |
1915 //source_y = pActors[source_id].vPosition.y; | |
1916 //source_z = pActors[source_id].vPosition.z; | |
1917 int sound_strength = GetSoundStrengthByDistanceFromParty(pActors[source_id].vPosition.x, | |
1918 pActors[source_id].vPosition.y, | |
1919 pActors[source_id].vPosition.z); | |
1920 if ( sound_strength ) | |
1921 { | |
1922 AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength); | |
1923 AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pActors[source_id].vPosition.x, | |
1924 pActors[source_id].vPosition.y)); | |
1925 } | |
1926 else | |
1927 { | |
1928 AIL_end_sample(pMixerChannels[i].hSample); | |
1929 FreeChannel(&pMixerChannels[i]); | |
1930 } | |
1931 } | |
1932 continue; | |
1933 | |
1934 default: | |
1935 assert(false); | |
1936 continue; | |
1937 } | |
1938 | |
1939 /*if (int sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z)) | |
1940 { | |
1941 AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength); | |
1942 AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(source_x, source_y)); | |
1943 } | |
1944 else | |
1945 { | |
1946 AIL_end_sample(pMixerChannels[i].hSample); | |
1947 FreeChannel(&pMixerChannels[i]); | |
1948 } */ | |
1949 } | |
1950 | |
2541 | 1951 if (current_screen_type != SCREEN_GAME) //îòêëþ÷åíèå çâóêà äåêîðàöèé ïðè ïåðåêëþ÷åíèè îêíà èãðû |
2502 | 1952 { |
1953 if (AIL_sample_status(pMixerChannels[4].hSample) == AIL::Sample::Playing) | |
1954 AIL_end_sample(pMixerChannels[4].hSample); | |
1955 return; | |
1956 } | |
1957 if (!_6807E0_num_decorations_with_sounds_6807B8) | |
1958 return; | |
1959 | |
1960 v55 = 0; | |
1961 //v59 = 0; | |
1962 for (uint i = 0; i < _6807E0_num_decorations_with_sounds_6807B8; ++i) | |
1963 { | |
1964 LODWORD(v56) = 1; | |
1965 //v43 = _6807B8_level_decorations_ids[v59]; | |
1966 //v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]]; | |
1967 //v45 = abs(v44->vPosition.z - pParty->vPosition.z); | |
1968 //v46 = abs(v44->vPosition.y - pParty->vPosition.y); | |
1969 //v47 = abs(v44->vPosition.x - pParty->vPosition.x); | |
1970 LevelDecoration* decor = &pLevelDecorations[_6807B8_level_decorations_ids[i]]; | |
1971 if (int_get_vector_length(abs(decor->vPosition.x - pParty->vPosition.x), | |
1972 abs(decor->vPosition.y - pParty->vPosition.y), | |
2505 | 1973 abs(decor->vPosition.z - pParty->vPosition.z)) > 8192) |
2502 | 1974 continue; |
1975 | |
1976 DecorationDesc* decor_desc = &pDecorationList->pDecorations[decor->uDecorationDescID]; | |
1977 //v48 = &pDecorationList->pDecorations[decor->uDecorationDescID]; | |
1978 //v49 = v48->uFlags; | |
1979 uNumRepeats = (~(unsigned __int8)decor_desc->uFlags & DECORATION_DESC_SLOW_LOOP) >> 6; | |
1980 | |
1981 if (decor_desc->SoundOnDawn() || decor_desc->SoundOnDusk()) | |
1982 { | |
1983 //v50 = decor->field_1A; | |
1984 v55 = 0.0; | |
1985 uNumRepeats = 2; | |
1986 if (decor->field_1A) | |
1987 { | |
1988 //v51 = decor->field_1A - 32; | |
1989 decor->field_1A = decor->field_1A - 32; | |
1990 if ( decor->field_1A < 0 ) | |
1991 decor->field_1A = 0; | |
1992 } | |
1993 } | |
1994 | |
1995 //v52 = v48->uFlags; | |
1996 if (!decor_desc->SoundOnDawn()) | |
1997 { | |
1998 if (!decor_desc->SoundOnDusk()) | |
1999 { | |
2000 if ( v55 == 0.0 ) | |
2001 { | |
2002 if ( v56 != 0.0 ) | |
2003 { | |
2004 v53 = 8 * _6807B8_level_decorations_ids[i]; | |
2005 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
2006 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);//sound of Boat and water(çâóêè êîðàáëÿ, ïëåñêàíèÿ âîäû) | |
2007 } | |
2008 continue; | |
2009 } | |
2010 if ( !decor->field_1A ) | |
2011 decor->field_1A = (rand() % 15 + 1) << 7; | |
2012 if ( v56 != 0.0 ) | |
2013 { | |
2014 v53 = 8 * _6807B8_level_decorations_ids[i]; | |
2015 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
2016 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | |
2017 } | |
2018 continue; | |
2019 } | |
2020 if ( v55 != 0.0 ) | |
2021 { | |
2022 if ( !decor->field_1A ) | |
2023 decor->field_1A = (rand() % 15 + 1) << 7; | |
2024 if ( v56 != 0.0 ) | |
2025 { | |
2026 v53 = 8 * _6807B8_level_decorations_ids[i]; | |
2027 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
2028 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | |
2029 } | |
2030 continue; | |
2031 } | |
2032 } | |
2033 v56 = 0.0; | |
2034 | |
2035 if (pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 || | |
2036 pParty->uCurrentHour >= 20 && pParty->uCurrentHour < 21) | |
2037 { | |
2038 if ( !decor->field_1A && rand() % 100 < 100 ) | |
2039 LODWORD(v56) = 1; | |
2040 LODWORD(v55) = 1; | |
2041 } | |
2042 if ( v55 == 0.0 ) | |
2043 { | |
2044 if ( v56 != 0.0 ) | |
2045 { | |
2046 v53 = 8 * _6807B8_level_decorations_ids[i]; | |
2047 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
2048 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | |
2049 } | |
2050 continue; | |
2051 } | |
2052 if ( !decor->field_1A ) | |
2053 decor->field_1A = (rand() % 15 + 1) << 7; | |
2054 if ( v56 != 0.0 ) | |
2055 { | |
2056 v53 = 8 * _6807B8_level_decorations_ids[i]; | |
2057 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
2058 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | |
2059 } | |
2060 continue; | |
2061 } | |
2062 } | |
2063 } | |
2064 | |
2065 //----- (004AB66C) -------------------------------------------------------- | |
2066 int __fastcall sub_4AB66C(int a1, int a2) | |
2067 { | |
2068 signed int v2; // eax@1 | |
2069 | |
2070 v2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->Atan2(a1 - pParty->vPosition.x, a2 - pParty->vPosition.y) | |
2071 - stru_5C6E00->uIntegerHalfPi - pParty->sRotationY); | |
2072 if ( v2 > (signed int)stru_5C6E00->uIntegerPi ) | |
2073 v2 = 2 * stru_5C6E00->uIntegerPi - v2; | |
2505 | 2074 v2 =(v2 >> 3) - (v2 >> 10) ; |
2075 return v2; | |
2502 | 2076 } |
2077 // 4AB66C: using guessed type int __fastcall sub_4AB66C(int, int); | |
2078 | |
2079 //----- (004AB6B1) -------------------------------------------------------- | |
2080 int GetSoundStrengthByDistanceFromParty(int x, int y, int z) | |
2081 { | |
2082 int dir_x; // ST08_4@1 | |
2083 int dir_y; // esi@1 | |
2084 int dir_z; // eax@1 | |
2085 int length; // [sp+10h] [bp+8h]@1 | |
2086 | |
2087 dir_z = abs(z - pParty->vPosition.z); | |
2088 dir_y = abs(y - pParty->vPosition.y); | |
2089 dir_x = abs(x - pParty->vPosition.x); | |
2090 length = int_get_vector_length(dir_x, dir_y, dir_z); | |
2534 | 2091 if ( length <= 0x2000 ) |
2502 | 2092 return 114 - (unsigned __int64)(signed __int64)((double)length * 0.0001220703125 * 100.0); |
2093 else | |
2094 return 0; | |
2095 } | |
2096 | |
2097 //----- (004AB71F) -------------------------------------------------------- | |
2098 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel) | |
2099 { | |
2100 if ( bPlayerReady ) | |
2101 { | |
2102 if ( b3DSoundInitialized ) | |
2103 { | |
2104 for ( uint i = 0; i < uNum3DSamples; ++i ) | |
2105 { | |
2106 if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel) | |
2107 && p3DSamples[i].field_8 && pSoundList->pSL_Sounds[p3DSamples[i].field_8].eType != SOUND_DESC_SYSTEM) | |
2108 { | |
2109 AIL_end_3D_sample(p3DSamples[i].hSample); | |
2110 _4ABF23(&p3DSamples[i]); | |
2111 p3DSamples[i].field_4 = 0; | |
2112 } | |
2113 } | |
2114 } | |
2115 if ( hDigDriver ) | |
2116 { | |
2117 for ( int i = 0; i < uMixerChannels; ++i ) | |
2118 { | |
2119 if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel) | |
2120 && pSoundList->pSL_Sounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)//âñå, êðîìå ñèñòåìíûõ çâóêîâ, îòêëþ÷àþòñÿ | |
2121 { | |
2122 AIL_end_sample(pMixerChannels[i].hSample); | |
2123 FreeChannel(&pMixerChannels[i]); | |
2124 pMixerChannels[i].source_pid = 0; | |
2125 } | |
2126 } | |
2127 } | |
2128 if (hSequence) | |
2129 AIL_end_sequence(hSequence); | |
2130 if (hStream) | |
2131 AIL_pause_stream(hStream, 1); | |
2132 } | |
2133 } | |
2134 | |
2135 //----- (004AB818) -------------------------------------------------------- | |
2136 void AudioPlayer::LoadAudioSnd() | |
2137 { | |
2138 DWORD NumberOfBytesRead; // [sp+Ch] [bp-4h]@3 | |
2139 | |
2140 hAudioSnd = CreateFileA("Sounds\\Audio.snd", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, 0); | |
2141 if (hAudioSnd == INVALID_HANDLE_VALUE) | |
2142 { | |
2143 Log::Warning(L"Can't open file: %s", L"Sounds\\Audio.snd"); | |
2144 return; | |
2145 } | |
2146 | |
2147 ReadFile(hAudioSnd, &uNumSoundHeaders, 4, &NumberOfBytesRead, 0); | |
2148 pSoundHeaders = nullptr; | |
2149 pSoundHeaders = (SoundHeader *)malloc(52 * uNumSoundHeaders + 2); | |
2150 ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0); | |
2151 } | |
2152 | |
2153 //----- (004AB8CE) -------------------------------------------------------- | |
2154 void AudioPlayer::Initialize() | |
2155 { | |
2156 int v3; // ebx@1 | |
2157 _PROVIDER *v6; // eax@9 | |
2158 int v12; // [sp+Ch] [bp-Ch]@9 | |
2159 char *Str1; // [sp+10h] [bp-8h]@6 | |
2160 int v14; // [sp+14h] [bp-4h]@5 | |
2161 | |
2162 //WriteWindowsRegistryString( "3DSoundProvider", "Aureal A3D Interactive(TM)");//çàïèñü â ðååñòð äëÿ 3D çâóêà(Microsoft DirectSound3D with Creative Labs EAX(TM)) | |
2163 | |
2164 v3 = 0; | |
2165 //this->hWindow = hWnd; | |
2166 this->hAILRedbook = 0; | |
2167 this->hDigDriver = 0; | |
2168 this->dword_0002AC = 0; | |
2169 this->hSequence = 0; | |
2170 this->uMasterVolume = 127; | |
2171 this->dword_0002C8 = 64; | |
2172 this->dword_0002CC = 2; | |
2173 | |
2174 MSS32_DLL_Initialize(); | |
2175 BINKW32_DLL_Initialize(); | |
2176 SMACKW32_DLL_Initialize(); | |
2177 | |
2178 AIL_startup(); | |
2179 if (bCanLoadFromCD) | |
2180 hAILRedbook = AIL_redbook_open_drive(cMM7GameCDDriveLetter/*cGameCDDriveLetter*/); | |
2181 //else | |
2182 // hAILRedbook = AIL_redbook_open(0); | |
2183 //v4 = Audio_GetFirstHardwareDigitalDriver(); | |
2184 | |
2185 hDigDriver = Audio_GetFirstHardwareDigitalDriver(); | |
2186 if ( hDigDriver ) | |
2187 SmackSoundUseMSS(hDigDriver); | |
2188 if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 && true)//pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ) | |
2189 { | |
2190 v14 = 0; | |
2191 bEAXSupported = 0; | |
2192 b3DSoundInitialized = 0; | |
2193 ReadWindowsRegistryString("3DSoundProvider", p3DSoundProvider, 128, "NONE"); | |
2194 CheckA3DSupport(true); | |
2195 HPROVIDER prov; | |
2196 while ( AIL_enumerate_3D_providers(&v14, &prov, &Str1) ) | |
2197 { | |
2198 if ( !strcmp(Str1, p3DSoundProvider) ) | |
2199 { | |
2200 if ( AIL_open_3D_provider(prov) ) | |
2201 { | |
2202 bEAXSupported = 0; | |
2203 b3DSoundInitialized = 0; | |
2204 h3DSoundProvider = 0; | |
2205 } | |
2206 else | |
2207 { | |
2208 v6 = prov; | |
2209 //v7 = prov; | |
2210 b3DSoundInitialized = 1; | |
2211 h3DSoundProvider = v6; | |
2212 uNum3DSamples = 4; | |
2213 AIL_3D_provider_attribute(prov, "EAX environment selection", &v12); | |
2214 if ( v12 != -1 ) | |
2215 bEAXSupported = 1; | |
2216 } | |
2217 pAudioPlayer->_4AC0A2(); | |
2218 break; | |
2219 } | |
2220 } | |
2221 } | |
2222 for ( v3; v3 < uMixerChannels; ++v3 ) | |
2223 { | |
2224 pMixerChannels[v3].hSample = AIL_allocate_sample_handle(hDigDriver); | |
2225 if ( !pMixerChannels[v3].hSample ) | |
2226 break; | |
2227 } | |
2228 uMixerChannels = v3; | |
2229 if ( bPlayerReady ) | |
2230 StopChannels(-1, -1); | |
2231 //v10 = hAILRedbook; | |
2232 bPlayerReady = true; | |
2233 if ( hAILRedbook ) | |
2234 { | |
2235 AIL_redbook_stop(hAILRedbook); | |
2236 uNumRedbookTracks = AIL_redbook_tracks(hAILRedbook); | |
2237 } | |
2238 pAudioPlayer->sRedbookVolume = AIL_redbook_volume(hAILRedbook); | |
2239 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f); | |
2508 | 2240 if ( bPlayerReady ) |
2241 { | |
2242 if ( use_music_folder ) | |
2243 alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]); | |
2244 else if ( hAILRedbook ) | |
2245 AIL_redbook_set_volume(hAILRedbook, (unsigned __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f) >> 32); | |
2246 } | |
2502 | 2247 LoadAudioSnd(); |
2248 } | |
2249 | |
2250 //----- (004ABAF7) -------------------------------------------------------- | |
2251 _DIG_DRIVER *Audio_GetFirstHardwareDigitalDriver(void) | |
2252 { | |
2253 int v0; // ecx@1 | |
2254 size_t v2; // eax@4 | |
2255 signed int v3; // kr14_4@9 | |
2256 int v5; // [sp+10h] [bp-Ch]@2 | |
2257 unsigned int pNum_devices; // [sp+14h] [bp-8h]@1 | |
2258 _DIG_DRIVER *hDrv; // [sp+18h] [bp-4h]@3 | |
2259 | |
2260 static int sample_Rate = 22050; | |
2261 static int bitsPerSample = 16; | |
2262 static int channels = 2; | |
2263 | |
2264 AIL_set_preference(15, 0); | |
2265 AIL_set_preference(33, 1); | |
2266 v0 = sample_Rate; | |
2267 pAudioPlayer->pDeviceNames[0][0] = 0; | |
2268 pAudioPlayer->uNumDevices = 0; | |
2269 pNum_devices = 0; | |
2270 | |
2271 if ( sample_Rate < 11025 ) | |
2272 return 0; | |
2273 v5 = 0; | |
2274 while ( 1 ) | |
2275 { | |
2276 while ( 1 ) | |
2277 { | |
2278 pcmWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM; | |
2279 pcmWaveFormat.wf.nChannels = channels; // Channels: 1 = mono, 2 = stereo | |
2280 pcmWaveFormat.wf.nSamplesPerSec = v0; //÷àñòîòà îöèôðîâêè | |
2281 pcmWaveFormat.wf.nBlockAlign = channels * bitsPerSample / 8; //êîëè÷åñòâî äàííûõ â áëîêå | |
2282 pcmWaveFormat.wBitsPerSample = bitsPerSample; | |
2283 pcmWaveFormat.wf.nAvgBytesPerSec = pcmWaveFormat.wf.nSamplesPerSec * pcmWaveFormat.wf.nBlockAlign; | |
2284 if ( !AIL_waveOutOpen(&hDrv, 0, -1, &pcmWaveFormat.wf) ) | |
2285 { | |
2286 strcpy(pAudioPlayer->pDeviceNames[v5], "Device: "); | |
2287 v2 = strlen(pAudioPlayer->pDeviceNames[v5]); | |
2534 | 2288 AIL_digital_configuration(hDrv, (int *)pAudioPlayer->pFrequency + v5, (int *)pAudioPlayer->array_000C30 + v5, (char *)pAudioPlayer->pDeviceNames + v2 + v5 * 32); |
2502 | 2289 ++pNum_devices; |
2290 v5++; | |
2291 pAudioPlayer->uNumDevices = pNum_devices; | |
2292 if ( AIL_get_preference(15) ) | |
2293 return hDrv; | |
2294 if ( !strstr(pAudioPlayer->pDeviceNames[v5 - 1], "Emulated") ) | |
2295 return hDrv; | |
2296 AIL_waveOutClose(hDrv); | |
2297 AIL_set_preference(15, 1); | |
2298 break; | |
2299 } | |
2300 if ( !AIL_get_preference(15) ) | |
2301 { | |
2302 AIL_set_preference(15, 1); | |
2303 if ( sample_Rate < 11025 ) | |
2304 return 0; | |
2305 break; | |
2306 } | |
2307 //v3 = sample_Rate; | |
2308 v0 = sample_Rate / 2; | |
2309 sample_Rate /= 2; | |
2310 if ( sample_Rate / 2 < 11025 ) | |
2311 { | |
2312 if ( bitsPerSample == 8 ) | |
2313 { | |
2314 v0 = 22050; | |
2315 bitsPerSample = 8; | |
2316 sample_Rate = 22050; | |
2317 } | |
2318 if ( v0 < 11025 ) | |
2319 return 0; | |
2320 break; | |
2321 } | |
2322 } | |
2323 } | |
2324 } | |
2325 | |
2326 //----- (004ABC9B) -------------------------------------------------------- | |
2327 void AudioPlayer::CheckA3DSupport(bool query) | |
2328 { | |
2329 DWORD cbData; // [sp+8h] [bp-Ch]@1 | |
2330 HKEY hKey; // [sp+10h] [bp-4h]@1 | |
2331 hKey = 0; | |
2332 cbData = 4; | |
2333 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Aureal\\A3D", 0, KEY_READ|KEY_WOW64_32KEY, &hKey)) | |
2334 { | |
2335 int Aureal3D_SplashAudio = 0; | |
2336 if (query) | |
2337 RegQueryValueExA(hKey, "SplashAudio", 0, 0, (LPBYTE)&Aureal3D_SplashAudio, &cbData); | |
2338 RegSetValueExA(hKey, "SplashAudio", 0, 4, (const BYTE *)&Aureal3D_SplashAudio, 4); | |
2339 | |
2340 int Aureal3D_SplashScreen = 0; | |
2341 if (query) | |
2342 RegQueryValueExA(hKey, "SplashScreen", 0, 0, (LPBYTE)&Aureal3D_SplashScreen, &cbData); | |
2343 RegSetValueExA(hKey, "SplashScreen", 0, 4, (const BYTE *)&Aureal3D_SplashScreen, 4); | |
2344 RegCloseKey(hKey); | |
2345 } | |
2346 } | |
2347 | |
2348 | |
2349 //----- (004ABD5B) -------------------------------------------------------- | |
2350 void AudioPlayer::Release() //Îñâîáîäèòü | |
2351 { | |
2352 MixerChannel *pMixerChannel; // ebx@3 | |
2353 // char v4; // dl@5 | |
2354 AudioPlayer_3DSample *p3DSample; // edi@7 | |
2355 void *v9; // ecx@15 | |
2356 | |
2357 if ( this->bPlayerReady ) | |
2358 { | |
2359 free(pSoundHeaders); | |
2360 CloseHandle(pMediaPlayer->hMagicVid); | |
2361 CloseHandle(pMediaPlayer->hMightVid); | |
2362 pAudioPlayer->StopChannels(-1, -1); | |
2363 if ( pAudioPlayer->uMixerChannels > 0 ) | |
2364 { | |
2365 pMixerChannel = pAudioPlayer->pMixerChannels; | |
2366 for ( uint i = 0; i < pAudioPlayer->uMixerChannels; ++i ) | |
2367 { | |
2368 AIL_release_sample_handle(pMixerChannel->hSample); | |
2369 ++pMixerChannel; | |
2370 } | |
2371 } | |
2372 if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 ) | |
2373 { | |
2374 CheckA3DSupport(false); | |
2375 if ( pAudioPlayer->uNum3DSamples > 0 ) | |
2376 { | |
2377 p3DSample = pAudioPlayer->p3DSamples; | |
2378 for ( uint i = 0; i < pAudioPlayer->uNum3DSamples; ++i ) | |
2379 { | |
2380 if ( p3DSample->hSample ) | |
2381 { | |
2382 AIL_release_3D_sample_handle(p3DSample->hSample); | |
2383 p3DSample->hSample = 0; | |
2384 } | |
2385 ++p3DSample; | |
2386 } | |
2387 } | |
2388 if ( pAudioPlayer->h3DSoundProvider ) | |
2389 { | |
2390 AIL_close_3D_provider(pAudioPlayer->h3DSoundProvider); | |
2391 pAudioPlayer->h3DSoundProvider = 0; | |
2392 } | |
2393 } | |
2394 if ( pAudioPlayer->hAILRedbook ) | |
2395 { | |
2396 AIL_redbook_stop(pAudioPlayer->hAILRedbook); | |
2397 AIL_redbook_set_volume((HREDBOOK)&pAudioPlayer->hAILRedbook, pAudioPlayer->sRedbookVolume); | |
2398 AIL_redbook_close(pAudioPlayer->hAILRedbook); | |
2399 } | |
2400 AIL_shutdown(); | |
2401 pSoundList->Release(); | |
2402 v9 = *(void **)&pAudioPlayer->field_C78[0]; | |
2403 if ( v9 ) | |
2404 ReleaseSoundData(v9); | |
2405 CloseHandle(pAudioPlayer->hAudioSnd); | |
2406 } | |
2407 } | |
2408 | |
2409 //----- (004ABE55) -------------------------------------------------------- | |
2410 void AudioPlayer::FreeChannel(MixerChannel *pChannel) | |
2411 { | |
2412 int num_same_sound_on_channels; // eax@8 | |
2413 int v10; // ecx@12 | |
2414 int v12; // eax@13 | |
2415 int v14[16]; // [sp+Ch] [bp-48h]@8 | |
2416 int num_playing_channels; // [sp+4Ch] [bp-8h]@5 | |
2417 | |
2418 if (!pSoundList->pSL_Sounds) | |
2419 return; | |
2420 | |
2421 //v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx]; | |
2422 if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP) | |
2423 { | |
2424 if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].pSoundData[0] && | |
2425 !(pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) ) | |
2426 { | |
2427 num_playing_channels = 0; | |
2428 num_same_sound_on_channels = 0; | |
2429 if ( this->uMixerChannels <= 0 ) | |
2430 goto LABEL_16; | |
2431 for ( uint i = 0; i < uMixerChannels; i++ ) | |
2432 { | |
2433 if ( pChannel->uSourceTrackID == pMixerChannels[i].uSourceTrackID ) | |
2434 { | |
2435 v14[num_same_sound_on_channels++] = i; | |
2436 if ( AIL_sample_status((HSAMPLE)pMixerChannels[i].hSample) == AIL::Sample::Playing) | |
2437 ++num_playing_channels; | |
2438 } | |
2439 } | |
2440 if ( !num_playing_channels ) | |
2441 { | |
2442 LABEL_16: | |
2443 pSoundList->UnloadSound(pChannel->uSourceTrackIdx, 1); | |
2444 for ( v10 = 0; v10 < num_same_sound_on_channels; v10++ ) | |
2445 { | |
2446 v12 = 16 * (v14[v10] + 47); | |
2447 pMixerChannels[v14[v10]].uSourceTrackID = 0; | |
2448 *(unsigned int *)((char *)&bEAXSupported + v12) = 0; | |
2449 } | |
2450 } | |
2451 } | |
2452 } | |
2453 } | |
2454 | |
2455 //----- (004ABF23) -------------------------------------------------------- | |
2456 void AudioPlayer::_4ABF23(AudioPlayer_3DSample *a2) | |
2457 { | |
2458 int v2; // ebx@1 | |
2459 unsigned __int8 v5; // zf@5 | |
2460 unsigned __int8 v6; // sf@5 | |
2461 char *v7; // edi@6 | |
2462 int v8; // eax@8 | |
2463 int v10; // ecx@12 | |
2464 int v11; // eax@13 | |
2465 int v13[16]; // [sp+Ch] [bp-48h]@8 | |
2466 int v14; // [sp+4Ch] [bp-8h]@5 | |
2467 int v15; // [sp+50h] [bp-4h]@5 | |
2468 | |
2469 if ( pSoundList->pSL_Sounds ) | |
2470 { | |
2471 //v4 = &pSoundList->pSounds[a2->field_8]; | |
2472 if ( pSoundList->pSL_Sounds[a2->field_8].eType == SOUND_DESC_SWAP) | |
2473 { | |
2474 if ( pSoundList->pSL_Sounds[a2->field_8].p3DSound && !(pSoundList->pSL_Sounds[a2->field_8].uFlags & SOUND_DESC_SYSTEM) ) | |
2475 { | |
2476 v5 = this->uNum3DSamples == 0; | |
2477 v6 = this->uNum3DSamples < 0; | |
2478 v14 = 0; | |
2479 v15 = 0; | |
2480 if ( v6 | v5 ) | |
2481 goto LABEL_16; | |
2482 v7 = (char *)this->p3DSamples; | |
2483 __debugbreak();//Ritor1 | |
2484 for ( v2 = 0; v2 < uNum3DSamples; ++v2 ) | |
2485 { | |
2486 if ( a2->field_C == *((int *)v7 + 3) ) | |
2487 { | |
2488 v8 = v15; | |
2489 //v9 = this->p3DSamples[v2]; | |
2490 ++v15; | |
2491 v13[v8] = v2; | |
2492 if ( AIL_3D_sample_status(&this->p3DSamples[v2]) == 4 ) | |
2493 ++v14; | |
2494 } | |
2495 v7 += 16; | |
2496 } | |
2497 if ( !v14 ) | |
2498 { | |
2499 LABEL_16: | |
2500 pSoundList->UnloadSound(a2->field_8, 1); | |
2501 for ( v10 = 0; v10 < v15; v10++ ) | |
2502 { | |
2503 v11 = v13[v10]; | |
2504 *(&bEAXSupported + 4 * (v11 + 2)) = 0; | |
2505 p3DSamples[v11].field_8 = 0; | |
2506 } | |
2507 } | |
2508 } | |
2509 } | |
2510 } | |
2511 } | |
2512 | |
2513 //----- (004ABFDB) -------------------------------------------------------- | |
2514 void PlayLevelMusic() | |
2515 { | |
2534 | 2516 unsigned int map_id; // eax@1 |
2502 | 2517 |
2534 | 2518 map_id = pMapStats->GetMapInfo(pCurrentMapName); |
2519 if ( map_id ) | |
2520 pAudioPlayer->PlayMusicTrack((MusicID)pMapStats->pInfos[map_id].uRedbookTrackID); | |
2502 | 2521 } |
2522 | |
2523 //----- (004AC004) -------------------------------------------------------- | |
2524 void AudioPlayer::SetEAXPreferences() | |
2525 { | |
2526 float v4; // [sp+4h] [bp-4h]@2 | |
2527 | |
2528 if ( this->bEAXSupported ) | |
2529 { | |
2530 v4 = 0.0; | |
2531 AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX effect volume", (int *)&v4); | |
2532 v4 = 1.0; | |
2533 AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX damping", (int *)&v4); | |
2534 } | |
2535 } | |
2536 // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); | |
2537 | |
2538 //----- (004AC041) -------------------------------------------------------- | |
2539 void AudioPlayer::SetMapEAX() | |
2540 { | |
2541 unsigned int pMapID; // eax@1 | |
2542 int v3; // [sp+4h] [bp-4h]@3 | |
2543 | |
2544 pMapID = pMapStats->GetMapInfo(pCurrentMapName); | |
2545 if ( this->b3DSoundInitialized && this->bEAXSupported ) | |
2546 { | |
2547 v3 = pMapStats->pInfos[pMapID].uEAXEnv; | |
2548 if ( (unsigned int)v3 >= 0x1A ) | |
2549 { | |
2550 SetEAXPreferences(); | |
2551 this->field_214 = -1; | |
2552 } | |
2553 else | |
2554 { | |
2555 AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX environment selection", &v3); | |
2556 this->field_214 = v3; | |
2557 } | |
2558 } | |
2559 } | |
2560 // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); | |
2561 | |
2562 //----- (004AC0A2) -------------------------------------------------------- | |
2563 int AudioPlayer::_4AC0A2() | |
2564 { | |
2565 unsigned int map_id; // eax@1 | |
2566 void *v9; // eax@8 | |
2567 int v12; // [sp+1Ch] [bp-8h]@1 | |
2568 | |
2569 if ( this->b3DSoundInitialized ) | |
2570 { | |
2571 //v5 = &this->uNum3DSamples; | |
2572 AIL_3D_provider_attribute(this->h3DSoundProvider, "Maximum supported samples", &this->uNum3DSamples); | |
2573 if ( this->uNum3DSamples > 32 ) | |
2574 this->uNum3DSamples = 32; | |
2575 //v6 = this->uNum3DSamples; | |
2576 if ( !this->uNum3DSamples ) | |
2577 { | |
2578 this->b3DSoundInitialized = 0; | |
2579 return -1; | |
2580 } | |
2581 //v13 = 0; | |
2582 //if ( this->uNum3DSamples > 0 ) | |
2583 //{ | |
2584 //v8 = this->p3DSamples; | |
2585 //while ( 1 ) | |
2586 for ( int i = 0; i < this->uNum3DSamples; ++i ) | |
2587 { | |
2588 v9 = (void *)AIL_allocate_3D_sample_handle(this->h3DSoundProvider); | |
2589 this->p3DSamples[i].hSample = v9; | |
2590 if ( !v9 ) | |
2591 this->uNum3DSamples = i; | |
2592 AIL_set_3D_sample_float_distances(v9, 4096.0, 256.0, 4096.0, 256.0); | |
2593 AIL_set_3D_sample_volume(this->p3DSamples[i].hSample, this->s3DSoundVolume); | |
2594 //++v8; | |
2595 } | |
2596 //} | |
2597 if ( this->bEAXSupported ) | |
2598 { | |
2599 //v10 = v4; | |
2600 //v11 = pMapStats->pInfos[map_id].uEAXEnv; | |
2601 map_id = pMapStats->GetMapInfo(pCurrentMapName); | |
2602 v12 = pMapStats->pInfos[map_id].uEAXEnv; | |
2603 if ( pMapStats->pInfos[map_id].uEAXEnv >= 0x1A ) | |
2604 { | |
2605 pAudioPlayer->SetEAXPreferences(); | |
2606 this->field_214 = -1; | |
2607 } | |
2608 else | |
2609 { | |
2610 AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX environment selection", &v12); | |
2611 this->field_214 = v12; | |
2612 } | |
2613 } | |
2614 } | |
2615 return 1; | |
2616 } | |
2617 | |
2618 //----- (004A96BE) -------------------------------------------------------- | |
2619 void ReleaseSoundData(void *_this) | |
2620 { | |
2621 //for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ ) | |
2622 for ( uint i = 0; i < 2999; i++ ) | |
2623 { | |
2624 if ( pSounds[i].pSoundData == _this ) | |
2625 { | |
2626 free(_this); | |
2627 memset(&pSounds[i], 0, sizeof(pSounds[i])); | |
2628 } | |
2629 } | |
2630 | |
2631 } | |
2632 | |
2633 //----- (004A96FF) -------------------------------------------------------- | |
2634 struct SoundHeader *FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName) | |
2635 { | |
2636 /* SoundHeader *result; // eax@2 | |
2637 SoundHeader *pSound; | |
2638 signed int v6; // ebx@11 | |
2639 | |
2640 while ( 1 ) | |
2641 { | |
2642 v6 = uEnd - uStart; | |
2643 pSound = &pAudioPlayer->pSoundHeaders[v6 / 2 + uStart]; | |
2644 if ( !pSound ) | |
2645 return false; | |
2646 result = (SoundHeader *)_stricmp(pName, pSound->pSoundName); | |
2647 if ( !_stricmp(pName, pSound->pSoundName) ) | |
2648 uFindSound_BinSearch_ResultID = v6 / 2 + uStart; | |
2649 if ( uStart == uEnd ) | |
2650 { | |
2651 uFindSound_BinSearch_ResultID = -1; | |
2652 return result; | |
2653 } | |
2654 if ( (signed int)result < 0 ) | |
2655 break; | |
2656 | |
2657 if ( v6 <= 4 ) | |
2658 { | |
2659 if ( (signed int)uStart < (signed int)uEnd ) | |
2660 { | |
2661 for ( uint i = uStart; i < (signed int)uEnd; ++i ) | |
2662 { | |
2663 if ( !_stricmp(pName, pAudioPlayer->pSoundHeaders[i].pSoundName) ) | |
2664 { | |
2665 uFindSound_BinSearch_ResultID = i; | |
2666 return &pAudioPlayer->pSoundHeaders[i]; | |
2667 } | |
2668 } | |
2669 } | |
2670 uFindSound_BinSearch_ResultID = -1; | |
2671 return false; | |
2672 } | |
2673 | |
2674 uStart += v6 / 2; | |
2675 LABEL_10: | |
2676 ; | |
2677 } | |
2678 if ( v6 > 4 ) | |
2679 { | |
2680 uEnd = v6 / 2 + uStart; | |
2681 goto LABEL_10; | |
2682 } | |
2683 if ( (signed int)uStart >= (signed int)uEnd ) | |
2684 { | |
2685 uFindSound_BinSearch_ResultID = -1; | |
2686 return false; | |
2687 }*/ | |
2688 for ( uint i = uStart; i < (signed int)uEnd; ++i ) | |
2689 { | |
2690 if ( !_stricmp(pName, pAudioPlayer->pSoundHeaders[i].pSoundName) ) | |
2691 { | |
2692 uFindSound_BinSearch_ResultID = i; | |
2693 return &pAudioPlayer->pSoundHeaders[i]; | |
2694 } | |
2695 } | |
2696 uFindSound_BinSearch_ResultID = -1; | |
2697 return false; | |
2698 } | |
2699 // F1B4C8: using guessed type int uFindSound_BinSearch_ResultID; | |
2700 | |
2701 //----- (004A97C6) -------------------------------------------------------- | |
2702 SoundData *LoadSound(const char *pSoundName, SoundData *pOutBuff, unsigned int uID) | |
2703 { | |
2704 DWORD NumberOfBytesRead; // [sp+14h] [bp-8h]@8 | |
2705 | |
2706 for (uint i = 0; i < 3000; ++i) | |
2707 { | |
2708 if (pSounds[i].uID == uID) | |
2709 return pSounds[i].pSoundData; | |
2710 } | |
2711 FindSound_BinSearch(0, pAudioPlayer->uNumSoundHeaders, pSoundName); | |
2712 if ( uFindSound_BinSearch_ResultID == -1 ) | |
2713 return 0; | |
2714 if ( pOutBuff == (SoundData *)-1 ) | |
2715 pOutBuff = (SoundData *)malloc(pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize + 4); | |
2716 SetFilePointer(pAudioPlayer->hAudioSnd, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uFileOffset, 0, 0); | |
2717 if ( (signed int)pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize >= (signed int)pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize ) | |
2718 { | |
2719 pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize; | |
2720 if ( pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize ) | |
2721 ReadFile(pAudioPlayer->hAudioSnd, pOutBuff->pData, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, &NumberOfBytesRead, 0);// Ritor1: pSounds[20] | |
2722 else | |
2723 MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:448", 0); | |
2724 } | |
2725 else | |
2726 { | |
2727 uID = (unsigned int)malloc(pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize); | |
2728 ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize, &NumberOfBytesRead, 0); | |
2729 zlib::MemUnzip(pOutBuff->pData, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize); | |
2730 free((void *)uID); | |
2731 } | |
2732 if ( pOutBuff ) | |
2733 { | |
2734 pOutBuff->uDataSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize; | |
2506 | 2735 |
2736 if ( uID == SOUND_StartMainChoice02 )//Ritor1: code included (BUG) | |
2737 { | |
2738 char *p = (char *)pOutBuff->pData; | |
2739 p = p+7; | |
2740 memcpy(&pOutBuff->pData, p, NumberOfBytesRead - 7); | |
2741 pOutBuff->uDataSize = NumberOfBytesRead - 7; | |
2742 } | |
2502 | 2743 uLastLoadedSoundID = 0; |
2744 if ( pSounds[0].pSoundData ) | |
2745 { | |
2746 for ( uint i = 0; pSounds[i].pSoundData; i++ ) | |
2747 ++uLastLoadedSoundID; | |
2748 } | |
2749 strcpy((char *)pSounds[uLastLoadedSoundID].SoundName, pSoundName); | |
2750 pSoundList->uTotalLoadedSoundSize += pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize; | |
2751 pSounds[uLastLoadedSoundID].pSoundData = pOutBuff; | |
2752 return pOutBuff; | |
2753 } | |
2754 else | |
2755 return 0; | |
2756 } |