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