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