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