Mercurial > mm7
comparison AudioPlayer.cpp @ 378:50875632e776
AudioPlayer::UpdateSounds (004AAFCF) take 1
author | Nomad |
---|---|
date | Fri, 22 Feb 2013 21:59:28 +0200 |
parents | 8e23edf57e27 |
children | 5bea494a2365 |
comparison
equal
deleted
inserted
replaced
373:edd2d8b7e3c4 | 378:50875632e776 |
---|---|
1 #include <string> | 1 #include <string> |
2 #include <assert.h> | |
2 | 3 |
3 #include "AudioPlayer.h" | 4 #include "AudioPlayer.h" |
4 #include "Allocator.h" | 5 #include "Allocator.h" |
5 #include "FrameTableInc.h" | 6 #include "FrameTableInc.h" |
6 #include "Indoor.h" | 7 #include "Indoor.h" |
11 #include "DecorationList.h" | 12 #include "DecorationList.h" |
12 #include "Time.h" | 13 #include "Time.h" |
13 #include "OSInfo.h" | 14 #include "OSInfo.h" |
14 #include "Math.h" | 15 #include "Math.h" |
15 #include "MapInfo.h" | 16 #include "MapInfo.h" |
17 #include "Actor.h" | |
18 #include "GUIWindow.h" | |
16 #include "Log.h" | 19 #include "Log.h" |
17 | 20 |
18 #include "Bink_Smacker.h" | 21 #include "Bink_Smacker.h" |
19 | 22 |
20 #include "mm7_data.h" | 23 #include "mm7_data.h" |
600 if ( v2->uMixerChannels > 0 ) | 603 if ( v2->uMixerChannels > 0 ) |
601 { | 604 { |
602 v6 = v2->pMixerChannels; | 605 v6 = v2->pMixerChannels; |
603 do | 606 do |
604 { | 607 { |
605 if ( v6->dword_000004 == a2 ) | 608 if ( v6->source_pid == a2 ) |
606 { | 609 { |
607 if ( AIL_sample_status(v6->hSample) == 4 ) | 610 if ( AIL_sample_status(v6->hSample) == 4 ) |
608 { | 611 { |
609 AIL_end_sample(v6->hSample); | 612 AIL_end_sample(v6->hSample); |
610 _4ABE55(v6); | 613 _4ABE55(v6); |
778 if ( pAudioPlayer->uMixerChannels > 0 ) | 781 if ( pAudioPlayer->uMixerChannels > 0 ) |
779 { | 782 { |
780 pMixerChannel = pAudioPlayer->pMixerChannels; | 783 pMixerChannel = pAudioPlayer->pMixerChannels; |
781 do | 784 do |
782 { | 785 { |
783 if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->dword_000004 == a3 | 786 if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->source_pid == a3 |
784 && AIL_sample_status(pMixerChannel->hSample) == 4 ) | 787 && AIL_sample_status(pMixerChannel->hSample) == 4 ) |
785 { | 788 { |
786 if ( pMixerChannel->uSourceTrackIdx == pNum ) | 789 if ( pMixerChannel->uSourceTrackIdx == pNum ) |
787 return; | 790 return; |
788 AIL_end_sample(pMixerChannel->hSample); | 791 AIL_end_sample(pMixerChannel->hSample); |
901 LABEL_184: | 904 LABEL_184: |
902 if ( uNumRepeats ) | 905 if ( uNumRepeats ) |
903 AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1); | 906 AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1); |
904 v85 = pMixerChannel5->hSample; | 907 v85 = pMixerChannel5->hSample; |
905 pMixerChannel5->uSourceTrackIdx = pNum; | 908 pMixerChannel5->uSourceTrackIdx = pNum; |
906 pMixerChannel5->dword_000004 = v76; | 909 pMixerChannel5->source_pid = v76; |
907 pMixerChannel5->uSourceTrackID = eSoundID; | 910 pMixerChannel5->uSourceTrackID = eSoundID; |
908 AIL_start_sample(v85); | 911 AIL_start_sample(v85); |
909 if ( sPlaybackRate ) | 912 if ( sPlaybackRate ) |
910 AIL_set_sample_playback_rate(pMixerChannel5->hSample, sPlaybackRate); | 913 AIL_set_sample_playback_rate(pMixerChannel5->hSample, sPlaybackRate); |
911 if ( (v76 & 7) == 4 ) | 914 if ( (v76 & 7) == 4 ) |
1338 } | 1341 } |
1339 | 1342 |
1340 | 1343 |
1341 | 1344 |
1342 //----- (004AAFCF) -------------------------------------------------------- | 1345 //----- (004AAFCF) -------------------------------------------------------- |
1343 void AudioPlayer::_4AAFCF() | 1346 void AudioPlayer::UpdateSounds() |
1344 { | 1347 { |
1345 AudioPlayer *pAudioPlayer; // edi@1 | 1348 //AudioPlayer *pAudioPlayer; // edi@1 |
1346 int v2; // ebx@1 | 1349 int v2; // ebx@1 |
1347 unsigned __int8 v3; // zf@1 | 1350 //unsigned __int8 v3; // zf@1 |
1348 int *v4; // eax@2 | 1351 //int *v4; // eax@2 |
1349 unsigned __int8 v5; // sf@4 | 1352 //unsigned __int8 v5; // sf@4 |
1350 AudioPlayer_3DSample *v6; // esi@5 | 1353 AudioPlayer_3DSample *v6; // esi@5 |
1351 int v7; // ebx@6 | 1354 int v7; // ebx@6 |
1352 int v8; // ebx@9 | 1355 int v8; // ebx@9 |
1353 int v9; // ebx@10 | 1356 int v9; // ebx@10 |
1354 int v10; // ebx@11 | 1357 int v10; // ebx@11 |
1367 int v23; // ST1C_4@32 | 1370 int v23; // ST1C_4@32 |
1368 int v24; // ebx@32 | 1371 int v24; // ebx@32 |
1369 int v25; // eax@32 | 1372 int v25; // eax@32 |
1370 float v26; // ST10_4@34 | 1373 float v26; // ST10_4@34 |
1371 float v27; // ST08_4@34 | 1374 float v27; // ST08_4@34 |
1372 MixerChannel *v28; // esi@38 | 1375 //MixerChannel *v28; // esi@38 |
1373 unsigned __int8 v29; // of@43 | 1376 //unsigned __int8 v29; // of@43 |
1374 MixerChannel *v30; // esi@44 | 1377 //MixerChannel *v30; // esi@44 |
1375 int v31; // eax@45 | 1378 //int v31; // eax@45 |
1376 LayingItem *v32; // eax@49 | 1379 //LayingItem *v32; // eax@49 |
1377 Actor *v33; // edi@50 | 1380 //Actor *v33; // edi@50 |
1378 int v34; // eax@50 | 1381 //int v34; // eax@50 |
1379 unsigned int v35; // edx@51 | 1382 //unsigned int v35; // edx@51 |
1380 unsigned int v36; // ecx@51 | 1383 //unsigned int v36; // ecx@51 |
1381 LayingItem *v37; // edi@53 | 1384 //LayingItem *v37; // edi@53 |
1382 int v38; // eax@53 | 1385 int v38; // eax@53 |
1383 BLVDoor *v39; // edi@56 | 1386 //BLVDoor *v39; // edi@56 |
1384 int v40; // eax@57 | 1387 //int v40; // eax@57 |
1385 int v41; // eax@60 | 1388 //int v41; // eax@60 |
1386 MixerChannel *v42; // edi@65 | 1389 MixerChannel *v42; // edi@65 |
1387 int v43; // ebx@68 | 1390 int v43; // ebx@68 |
1388 LevelDecoration *v44; // esi@68 | 1391 LevelDecoration *v44; // esi@68 |
1389 int v45; // ST1C_4@68 | 1392 int v45; // ST1C_4@68 |
1390 int v46; // edi@68 | 1393 int v46; // edi@68 |
1399 float v55; // [sp+54h] [bp-18h]@22 | 1402 float v55; // [sp+54h] [bp-18h]@22 |
1400 float v56; // [sp+58h] [bp-14h]@22 | 1403 float v56; // [sp+58h] [bp-14h]@22 |
1401 int uNumRepeats; // [sp+5Ch] [bp-10h]@15 | 1404 int uNumRepeats; // [sp+5Ch] [bp-10h]@15 |
1402 float v58; // [sp+60h] [bp-Ch]@23 | 1405 float v58; // [sp+60h] [bp-Ch]@23 |
1403 int v59; // [sp+64h] [bp-8h]@4 | 1406 int v59; // [sp+64h] [bp-8h]@4 |
1404 AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 | 1407 //AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 |
1405 | 1408 |
1406 pAudioPlayer = this; | 1409 //pAudioPlayer = this; |
1407 v2 = 0; | 1410 v2 = 0; |
1408 thisa = this; | 1411 //thisa = this; |
1409 v3 = this->bPlayerReady == 0; | 1412 //v3 = this->bPlayerReady == 0; |
1410 a1.flt_2C = 0.0; | 1413 //a1.flt_2C = 0.0; |
1411 if ( !v3 ) | 1414 if (!bPlayerReady) |
1412 { | 1415 return; |
1413 v4 = &this->field_2D0_time_left; | 1416 |
1414 *v4 -= pEventTimer->uTimeElapsed; | 1417 if (field_2D0_time_left <= pEventTimer->uTimeElapsed) |
1415 if ( this->field_2D0_time_left <= 0 ) | 1418 field_2D0_time_left = 32; |
1416 { | 1419 else |
1417 v3 = this->b3DSoundInitialized == 0; | 1420 { |
1418 *v4 = 32; | 1421 field_2D0_time_left -= pEventTimer->uTimeElapsed; |
1419 if ( !v3 ) | 1422 return; |
1420 { | 1423 } |
1421 v3 = this->uNum3DSamples == 0; | 1424 |
1422 v5 = this->uNum3DSamples < 0; | 1425 //v3 = this->b3DSoundInitialized == 0; |
1426 if (b3DSoundInitialized) | |
1427 { | |
1428 __debugbreak(); // refactor refactor | |
1429 //v3 = this->uNum3DSamples == 0; | |
1430 //v5 = this->uNum3DSamples < 0; | |
1423 v59 = 0; | 1431 v59 = 0; |
1424 if ( !(v5 | v3) ) | 1432 if (uNum3DSamples > 0) |
1425 { | 1433 { |
1426 v6 = this->p3DSamples; | 1434 v6 = this->p3DSamples; |
1427 while ( 1 ) | 1435 while ( 1 ) |
1428 { | 1436 { |
1429 v7 = v6->field_4 & 7; | 1437 v7 = v6->field_4 & 7; |
1457 { | 1465 { |
1458 v2 = 0; | 1466 v2 = 0; |
1459 goto LABEL_37; | 1467 goto LABEL_37; |
1460 } | 1468 } |
1461 } | 1469 } |
1470 | |
1462 v9 = v8 - 1; | 1471 v9 = v8 - 1; |
1463 if ( v9 ) | 1472 if ( v9 ) |
1464 { | 1473 { |
1465 v10 = v9 - 1; | 1474 v10 = v9 - 1; |
1466 if ( !v10 ) | 1475 if ( !v10 ) |
1559 pAudioPlayer->_4ABF23(v6); | 1568 pAudioPlayer->_4ABF23(v6); |
1560 } | 1569 } |
1561 goto LABEL_35; | 1570 goto LABEL_35; |
1562 } | 1571 } |
1563 } | 1572 } |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | |
1564 LABEL_37: | 1580 LABEL_37: |
1565 if ( pAudioPlayer->uMixerChannels > v2 ) | 1581 for (uint i = 0; i < uMixerChannels; ++i) |
1566 { | 1582 { |
1567 v28 = pAudioPlayer->pMixerChannels; | 1583 auto channel = pMixerChannels + i; |
1568 do | 1584 |
1569 { | 1585 AIL_end_sample(channel->hSample); |
1570 if ( AIL_sample_status(v28->hSample) == 2 ) | 1586 _4ABE55(channel); |
1571 { | 1587 } |
1572 AIL_end_sample(v28->hSample); | 1588 |
1573 pAudioPlayer->_4ABE55(v28); | 1589 //v59 = 0; |
1574 } | 1590 for (uint i = 0; i < uMixerChannels; ++i) |
1575 ++v2; | 1591 { |
1576 ++v28; | 1592 //v30 = pAudioPlayer->pMixerChannels; |
1577 } | 1593 auto channel = pMixerChannels + i; |
1578 while ( v2 < pAudioPlayer->uMixerChannels ); | 1594 //while ( 1 ) |
1579 v2 = 0; | 1595 //{ |
1580 } | 1596 //v31 = v30->dword_000004; |
1581 //v29 = __OFSUB__(v1->uMixerChannels, v2); | 1597 int source_type = channel->source_pid & 7, |
1582 v29 = pAudioPlayer->uMixerChannels > v2; | 1598 source_id = channel->source_pid >> 3; |
1583 v3 = pAudioPlayer->uMixerChannels == v2; | 1599 int source_x, |
1584 v5 = pAudioPlayer->uMixerChannels - v2 < 0; | 1600 source_y, |
1585 v59 = v2; | 1601 source_z; |
1586 if ( !((unsigned __int8)(v5 ^ v29) | v3) ) | 1602 |
1587 { | 1603 switch (source_type) |
1588 v30 = pAudioPlayer->pMixerChannels; | 1604 { |
1589 while ( 1 ) | 1605 case 0: |
1590 { | 1606 case OBJECT_Player: |
1591 v31 = v30->dword_000004; | 1607 continue; |
1592 if ( (v30->dword_000004 & 7) == 1 ) | 1608 |
1593 { | 1609 case OBJECT_BLVDoor: |
1594 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | 1610 { |
1595 { | 1611 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); |
1596 v39 = &pIndoor->pDoors[v31 >> 3]; | 1612 |
1597 if ( !v39->uDoorID ) | 1613 assert(source_id < pIndoor->uNumDoors); |
1598 { | 1614 auto door = pIndoor->pDoors + source_id; |
1599 LABEL_61: | 1615 if (!door->uDoorID) |
1600 pAudioPlayer = thisa; | 1616 continue; |
1601 goto LABEL_62; | 1617 |
1602 } | 1618 source_x = door->pXOffsets[0]; |
1603 v40 = GetSoundStrengthByDistanceFromParty(*v39->pXOffsets, *v39->pYOffsets, *v39->pZOffsets); | 1619 source_y = door->pYOffsets[0]; |
1604 if ( !v40 ) | 1620 source_z = door->pZOffsets[0]; |
1605 { | 1621 } |
1606 LABEL_58: | 1622 break; |
1607 AIL_end_sample(v30->hSample); | 1623 |
1608 thisa->_4ABE55(v30); | 1624 case OBJECT_Item: |
1609 goto LABEL_61; | 1625 case OBJECT_Decoration: |
1610 } | 1626 { |
1611 AIL_set_sample_volume(v30->hSample, v40); | 1627 LayingItem *object = nullptr; |
1612 v35 = *v39->pYOffsets; | 1628 if (source_type == OBJECT_Item) |
1613 v36 = *v39->pXOffsets; | 1629 { |
1614 LABEL_60: | 1630 assert(source_id < uNumLayingItems); |
1615 v41 = sub_4AB66C(v36, v35); | 1631 object = &pLayingItems[source_id]; |
1616 AIL_set_sample_pan(v30->hSample, v41); | 1632 } |
1617 goto LABEL_61; | 1633 else |
1618 } | 1634 { |
1619 } | 1635 assert(source_id < uNumLevelDecorations); |
1620 else | 1636 object = (LayingItem *)&pLevelDecorations[source_id]; |
1621 { | 1637 } |
1622 if ( (v30->dword_000004 & 7) == 2 ) | 1638 |
1623 { | 1639 source_x = object->vPosition.x; |
1624 v32 = &pLayingItems[v31 >> 3]; | 1640 source_y = object->vPosition.y; |
1625 goto LABEL_53; | 1641 source_z = object->vPosition.z; |
1626 } | 1642 } |
1627 if ( (v30->dword_000004 & 7) == 3 ) | 1643 break; |
1628 { | 1644 |
1629 v33 = &pActors[v31 >> 3]; | 1645 case OBJECT_Actor: |
1630 v34 = GetSoundStrengthByDistanceFromParty(v33->vPosition.x, v33->vPosition.y, v33->vPosition.z); | 1646 { |
1631 if ( !v34 ) | 1647 assert(source_id < uNumActors); |
1632 goto LABEL_58; | 1648 auto actor = pActors + source_id; |
1633 AIL_set_sample_volume(v30->hSample, v34); | 1649 |
1634 v35 = v33->vPosition.y; | 1650 source_x = actor->vPosition.x; |
1635 v36 = v33->vPosition.x; | 1651 source_y = actor->vPosition.y; |
1636 goto LABEL_60; | 1652 source_z = actor->vPosition.z; |
1637 } | 1653 } |
1638 if ( (v30->dword_000004 & 7) == 5 ) | 1654 break; |
1639 { | 1655 |
1640 v32 = (LayingItem *)&pLevelDecorations[v31 >> 3]; | 1656 default: |
1641 LABEL_53: | 1657 assert(false); |
1642 v37 = v32; | 1658 continue; |
1643 v38 = GetSoundStrengthByDistanceFromParty(v32->vPosition.x, v32->vPosition.y, v32->vPosition.z); | 1659 } |
1644 if ( !v38 ) | 1660 |
1645 goto LABEL_58; | 1661 if (auto sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z)) |
1646 AIL_set_sample_volume(v30->hSample, v38); | 1662 { |
1647 v35 = v37->vPosition.y; | 1663 AIL_set_sample_volume(channel->hSample, sound_strength); |
1648 v36 = v37->vPosition.x; | 1664 AIL_set_sample_pan(channel->hSample, sub_4AB66C(source_x, source_y)); |
1649 goto LABEL_60; | 1665 } |
1650 } | 1666 else |
1651 } | 1667 { |
1652 LABEL_62: | 1668 AIL_end_sample(channel->hSample); |
1653 ++v59; | 1669 _4ABE55(channel); |
1654 ++v30; | 1670 } |
1655 if ( v59 >= pAudioPlayer->uMixerChannels ) | 1671 } |
1656 { | 1672 |
1657 v2 = 0; | 1673 |
1658 break; | 1674 v55 = 0; |
1659 } | 1675 if ( pCurrentScreen != SCREEN_GAME ) |
1660 } | |
1661 } | |
1662 if ( pCurrentScreen != v2 ) | |
1663 { | 1676 { |
1664 v42 = &pAudioPlayer->pMixerChannels[4]; | 1677 v42 = &pAudioPlayer->pMixerChannels[4]; |
1665 if ( AIL_sample_status(v42->hSample) == 4 ) | 1678 if ( AIL_sample_status(v42->hSample) == 4 ) |
1666 AIL_end_sample(v42->hSample); | 1679 AIL_end_sample(v42->hSample); |
1667 return; | 1680 return; |
1722 LABEL_87: | 1735 LABEL_87: |
1723 if ( v56 != 0.0 ) | 1736 if ( v56 != 0.0 ) |
1724 { | 1737 { |
1725 v53 = 8 * *(int *)v43; | 1738 v53 = 8 * *(int *)v43; |
1726 LOBYTE(v53) = v53 | 5; | 1739 LOBYTE(v53) = v53 | 5; |
1727 thisa->PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | 1740 PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); |
1728 } | 1741 } |
1729 goto LABEL_89; | 1742 goto LABEL_89; |
1730 } | 1743 } |
1731 LABEL_85: | 1744 LABEL_85: |
1732 if ( !v44->field_1A ) | 1745 if ( !v44->field_1A ) |
1733 v44->field_1A = (rand() % 15 + 1) << 7; | 1746 v44->field_1A = (rand() % 15 + 1) << 7; |
1734 goto LABEL_87; | 1747 goto LABEL_87; |
1735 } | |
1736 } | |
1737 } | 1748 } |
1738 | 1749 |
1739 | 1750 |
1740 | 1751 |
1741 //----- (004AB66C) -------------------------------------------------------- | 1752 //----- (004AB66C) -------------------------------------------------------- |
1823 if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel) | 1834 if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel) |
1824 && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM) | 1835 && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM) |
1825 { | 1836 { |
1826 AIL_end_sample(pChannel->hSample); | 1837 AIL_end_sample(pChannel->hSample); |
1827 _4ABE55(pChannel); | 1838 _4ABE55(pChannel); |
1828 pChannel->dword_000004 = 0; | 1839 pChannel->source_pid = 0; |
1829 } | 1840 } |
1830 ++v6; | 1841 ++v6; |
1831 ++pChannel; | 1842 ++pChannel; |
1832 } | 1843 } |
1833 while (v6 < uMixerChannels); | 1844 while (v6 < uMixerChannels); |