comparison AudioPlayer.cpp @ 388:d95a91011d57

AudioPlayer::PlaySound
author Nomad
date Sat, 23 Feb 2013 04:01:09 +0200
parents 5bea494a2365
children 35a62d1948d4
comparison
equal deleted inserted replaced
383:c3a0d94c07a5 388:d95a91011d57
626 626
627 //----- (004AA306) -------------------------------------------------------- 627 //----- (004AA306) --------------------------------------------------------
628 void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate) 628 void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate)
629 { 629 {
630 //AudioPlayer *pAudioPlayer1; // esi@1 630 //AudioPlayer *pAudioPlayer1; // esi@1
631 signed int pNum; // edx@5 631 //signed int pNum; // edx@5
632 int *pSoundID; // ecx@6 632 //int *pSoundID; // ecx@6
633 int v12; // edi@13 633 int v12; // edi@13
634 signed int v13; // ecx@17 634 signed int v13; // ecx@17
635 signed int v14; // eax@20 635 signed int v14; // eax@20
636 int v15; // eax@24 636 int v15; // eax@24
637 signed int v16; // eax@25 637 signed int v16; // eax@25
655 int v34; // eax@70 655 int v34; // eax@70
656 char v35; // zf@70 656 char v35; // zf@70
657 signed int v36; // ebx@74 657 signed int v36; // ebx@74
658 //AudioPlayer *pAudioPlayer2; // edi@79 658 //AudioPlayer *pAudioPlayer2; // edi@79
659 AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79 659 AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79
660 unsigned int v39; // ebx@80 660 //unsigned int v39; // ebx@80
661 int v40; // eax@81 661 int v40; // eax@81
662 char *v41; // edi@82 662 char *v41; // edi@82
663 int v42; // esi@82 663 int v42; // esi@82
664 double v43; // st7@91 664 double v43; // st7@91
665 LayingItem *pLayingItem2; // eax@92 665 LayingItem *pLayingItem2; // eax@92
674 float v53; // ST0C_4@106 674 float v53; // ST0C_4@106
675 float v54; // ST04_4@106 675 float v54; // ST04_4@106
676 //AudioPlayer *pAudioPlayer3; // edx@106 676 //AudioPlayer *pAudioPlayer3; // edx@106
677 SoundDesc *pSoundDesc; // edx@107 677 SoundDesc *pSoundDesc; // edx@107
678 LayingItem *pLayingItem3; // eax@114 678 LayingItem *pLayingItem3; // eax@114
679 int v58; // edx@115 679 //int v58; // edx@115
680 int v59; // ecx@115 680 //int v59; // ecx@115
681 Actor *pActor2; // eax@118 681 //Actor *pActor2; // eax@118
682 MixerChannel *pMixerChannel; // esi@126 682 //MixerChannel *pMixerChannel; // esi@126
683 signed int v62; // esi@133 683 signed int v62; // esi@133
684 //AudioPlayer *pAudioPlayer4; // ebx@133 684 //AudioPlayer *pAudioPlayer4; // ebx@133
685 MixerChannel *pMixerChannel2; // edi@134 685 //MixerChannel *pMixerChannel2; // edi@134
686 int v65; // ebx@141 686 //int v65; // ebx@141
687 //AudioPlayer *pAudioPlayer5; // ecx@142 687 //AudioPlayer *pAudioPlayer5; // ecx@142
688 MixerChannel *pMixerChannel3; // edi@142 688 //MixerChannel *pMixerChannel3; // edi@142
689 int v68; // eax@143 689 int v68; // eax@143
690 MixerChannel *pMixerChannel4; // edi@149 690 //MixerChannel *pMixerChannel4; // edi@149
691 int v70; // ecx@152 691 //int v70; // ecx@152
692 SoundDesc *pSoundDesc2; // eax@153 692 //SoundDesc *pSoundDesc2; // eax@153
693 int v72; // edi@156 693 //int v72; // edi@156
694 MixerChannel *pMixerChannel5; // esi@157 694 //MixerChannel *pMixerChannel5; // esi@157
695 unsigned int pVolume; // eax@157 695 //unsigned int pVolume; // eax@157
696 int pPartyX; // ebx@159 696 //int pPartyX; // ebx@159
697 int v76; // ebx@160 697 //int v76; // ebx@160
698 LayingItem *pLayingItem4; // edi@164 698 //LayingItem *pLayingItem4; // edi@164
699 unsigned int pPosY; // edx@166 699 //unsigned int pPosY; // edx@166
700 unsigned int pPosX; // ecx@166 700 //unsigned int pPosX; // ecx@166
701 int v80; // eax@167 701 //int v80; // eax@167
702 Actor *pActor3; // edi@168 702 //Actor *pActor3; // edi@168
703 BLVDoor *pBLVDoor2; // edi@173 703 //BLVDoor *pBLVDoor2; // edi@173
704 int v83; // eax@183 704 //int v83; // eax@183
705 int v84; // eax@183 705 //int v84; // eax@183
706 _SAMPLE *v85; // ST18_4@186 706 //_SAMPLE *v85; // ST18_4@186
707 unsigned int v86; // [sp+14h] [bp-60h]@84 707 unsigned int v86; // [sp+14h] [bp-60h]@84
708 int v87; // [sp+14h] [bp-60h]@115 708 //int v87; // [sp+14h] [bp-60h]@115
709 RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1 709 RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1
710 unsigned int v89; // [sp+54h] [bp-20h]@12 710 //unsigned int v89; // [sp+54h] [bp-20h]@12
711 int v90; // [sp+58h] [bp-1Ch]@68 711 int v90; // [sp+58h] [bp-1Ch]@68
712 float v91; // [sp+5Ch] [bp-18h]@68 712 float v91; // [sp+5Ch] [bp-18h]@68
713 //unsigned int v92; // [sp+60h] [bp-14h]@10 713 //unsigned int v92; // [sp+60h] [bp-14h]@10
714 float v93; // [sp+64h] [bp-10h]@1 714 float v93; // [sp+64h] [bp-10h]@1
715 signed int varC; // [sp+68h] [bp-Ch]@68 715 signed int varC; // [sp+68h] [bp-Ch]@68
716 AudioPlayer *pAudioPlayer; // [sp+6Ch] [bp-8h]@1 716 //AudioPlayer *pAudioPlayer; // [sp+6Ch] [bp-8h]@1
717 int v96; // [sp+70h] [bp-4h]@19 717 int v96; // [sp+70h] [bp-4h]@19
718 signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93 718 signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93
719 float uNumRepeatsa; // [sp+84h] [bp+10h]@104 719 float uNumRepeatsa; // [sp+84h] [bp+10h]@104
720 float v99; // [sp+8Ch] [bp+18h]@104 720 float v99; // [sp+8Ch] [bp+18h]@104
721 signed int v100; // [sp+90h] [bp+1Ch]@32 721 signed int v100; // [sp+90h] [bp+1Ch]@32
722 int v101; // [sp+90h] [bp+1Ch]@52 722 int v101; // [sp+90h] [bp+1Ch]@52
723 int v102; // [sp+90h] [bp+1Ch]@60 723 int v102; // [sp+90h] [bp+1Ch]@60
724 int v103; // [sp+90h] [bp+1Ch]@68 724 int v103; // [sp+90h] [bp+1Ch]@68
725 725
726 pAudioPlayer = this; 726 if (!bPlayerReady)
727 v35 = this->bPlayerReady == 0; 727 return;
728 if (!uSoundVolumeMultiplier)
729 return;
730 if (!hDigDriver)
731 return;
732 if (eSoundID == SOUND_Invalid)
733 return;
734
728 //pAudioPlayer = this; 735 //pAudioPlayer = this;
729 pRenderVertexSoft.flt_2C = 0.0; 736 //v35 = this->bPlayerReady == 0;
730 LODWORD(v93) = 10000; 737 //pAudioPlayer = this;
731 if ( v35 || !uSoundVolumeMultiplier || !this->hDigDriver || !eSoundID ) 738 //LODWORD(v93) = 10000;
739 int sample_volume = 10000;
740
741
742 int sound_id = 0;
743 for (uint i = 0; i < pSoundList->uNumSounds; ++i)
744 if (pSoundList->pSounds[i].uSoundID == eSoundID)
745 {
746 sound_id = i;
747 break;
748 }
749
750 if (!sound_id)
751 {
752 Log::Warning(L"SoundID = %u not found", eSoundID);
732 return; 753 return;
733 pNum = 0; 754 }
734 if ( (signed int)pSoundList->uNumSounds <= 0 ) 755
735 { 756 int start_channel = 0,
736 LABEL_9: 757 end_channel = 0;
737 pNum = 0; 758
738 } 759 assert(sound_id < pSoundList->uNumSounds);
739 else 760 auto sound_desc = pSoundList->pSounds + sound_id;
740 { 761 if (!b3DSoundInitialized || sound_desc->Is3D())
741 pSoundID = (int *)&pSoundList->pSounds->uSoundID; 762 {
742 while ( *pSoundID != eSoundID ) 763 if (!a3) // generic sound like from UI
743 { 764 {
744 ++pNum; 765 start_channel = 10;
745 pSoundID += 30; 766 end_channel = 12;
746 if ( pNum >= (signed int)pSoundList->uNumSounds ) 767 goto LABEL_133;
747 goto LABEL_9; 768 }
748 } 769 else if (a3 == -1) // exclusive sounds - can override
749 } 770 {
750 /* v92 = pNum;//38 771 start_channel = 13;
751 pNum = 0; 772 end_channel = 13;
752 for ( pSoundID = (int *)&pSoundList->pSounds->uSoundID; *pSoundID != eSoundID; pSoundID += 30) 773 goto LABEL_133;
753 { 774 }
754 ++pNum; 775 else
755 }*/ 776 {
756 if ( !pNum ) 777 if (a3 < 0) // exclusive sounds - no override
757 return; 778 {
758 if ( !pAudioPlayer->b3DSoundInitialized || (v89 = 120 * pNum, !(pSoundList->pSounds[pNum].uFlags & 2)) ) 779 start_channel = 14;
759 { 780 end_channel = 14;
760 //pSoundDesc = (SoundDesc *)7; 781 goto LABEL_123;
761 if ( a3 < 0 ) 782 }
762 { 783 else
763 if ( a3 == -1 ) 784 {
764 { 785 int object_type = a3 & 7,
765 varC = 13; 786 object_id = a3 >> 7;
766 v96 = 13; 787 switch (object_type)
767 goto LABEL_133; 788 {
768 } 789 case OBJECT_BLVDoor:
769 varC = 14; 790 case OBJECT_Player:
770 v96 = 14; 791 {
792 start_channel = 10;
793 end_channel = 12;
794 goto LABEL_133;
795 }
796 break;
797
798 case OBJECT_Actor:
799 {
800 start_channel = 0;
801 end_channel = 3;
802
803 assert(object_id < uNumActors);
804 auto actor = &pActors[object_id];
805
806 sample_volume = GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z);
807 if (!sample_volume)
808 return;
809 goto LABEL_123;
810 }
811
812 case OBJECT_Decoration:
813 {
814 start_channel = 4;
815 end_channel = 4;
816
817 assert(object_id < uNumLevelDecorations);
818 auto decor = &pLevelDecorations[object_id];
819
820 sample_volume = GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z);
821 if (!sample_volume)
822 return;
823 goto LABEL_123;
824 }
825 break;
826
827 case OBJECT_Item:
828 {
829 start_channel = 5;
830 end_channel = 7;
831
832 assert(object_id < uNumLayingItems);
833 auto object = &pLayingItems[object_id];
834
835 sample_volume = GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z);
836 if (!sample_volume)
837 return;
838 goto LABEL_123;
839 }
840 break;
841
842 case OBJECT_BModel:
843 {
844 start_channel = 8;
845 end_channel = 9;
846 goto LABEL_123;
847 }
848 break;
849
850 default:
851 assert(false);
852 }
853 }
854 }
855
856
857
858
859
860
771 LABEL_123: 861 LABEL_123:
772 if ( a3 ) 862 for (uint i = 0; i < uMixerChannels; ++i)
773 { 863 {
774 if ( a3 != -1 ) 864 auto channel = pMixerChannels + i;
775 { 865 if (channel->source_pid == a3 &&
776 LODWORD(v91) = 0; 866 AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
777 if ( pAudioPlayer->uMixerChannels > 0 ) 867 {
778 { 868 if (channel->uSourceTrackIdx == sound_id)
779 pMixerChannel = pAudioPlayer->pMixerChannels; 869 return; // already playing the same sound from the same source - return
780 do 870
781 { 871 AIL_end_sample(channel->hSample); // requested new sound from the same source - end & switch
782 if ( AIL_sample_status(pMixerChannel->hSample) == AIL::Sample::Playing && pMixerChannel->source_pid == a3 872 _4ABE55(channel);
783 && AIL_sample_status(pMixerChannel->hSample) == AIL::Sample::Playing) 873 }
784 { 874 }
785 if ( pMixerChannel->uSourceTrackIdx == pNum ) 875
786 return;
787 AIL_end_sample(pMixerChannel->hSample);
788 _4ABE55(pMixerChannel);
789 }
790 ++LODWORD(v91);
791 ++pMixerChannel;
792 }
793 while ( SLODWORD(v91) < pAudioPlayer->uMixerChannels );
794 }
795 }
796 }
797 LABEL_133: 876 LABEL_133:
798 v62 = varC; 877 v62 = start_channel;
799 //pAudioPlayer4 = pAudioPlayer; 878 //pAudioPlayer4 = pAudioPlayer;
800 if ( varC <= v96 ) 879 for (v62 = start_channel; v62 <= end_channel; ++v62)
801 { 880 {
802 pMixerChannel2 = &pAudioPlayer->pMixerChannels[varC]; 881 auto channel = pMixerChannels + v62;
882 if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
883 {
884 AIL_end_sample(channel->hSample);
885 if (channel->uSourceTrackIdx)
886 _4ABE55(channel);
887 break;
888 }
889 }
890 /*if ( start_channel <= end_channel)
891 {
892 pMixerChannel2 = &pAudioPlayer->pMixerChannels[start_channel];
803 while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done) 893 while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done)
804 { 894 {
805 ++v62; 895 ++v62;
806 ++pMixerChannel2; 896 ++pMixerChannel2;
807 if ( v62 > v96 ) 897 if ( v62 > end_channel )
808 goto LABEL_140; 898 goto LABEL_140;
809 } 899 }
810 AIL_end_sample(pMixerChannel2->hSample); 900 AIL_end_sample(pMixerChannel2->hSample);
811 if ( pMixerChannel2->uSourceTrackIdx ) 901 if ( pMixerChannel2->uSourceTrackIdx )
812 _4ABE55(pMixerChannel2); 902 _4ABE55(pMixerChannel2);
813 } 903 }
814 LABEL_140: 904 LABEL_140:*/
815 if ( v62 != v96 + 1 )//10!=13 905
816 { 906 if (v62 > end_channel) // no free channel - occupy the quitest one
817 LABEL_150: 907 {
818 if ( LODWORD(v93) == 10000 ) 908 v62 = -1;
819 LODWORD(v93) = pAudioPlayer->uMasterVolume; 909
820 v70 = 0; 910 int min_volume = sample_volume;
821 if ( !a7 ) 911 for (uint i = start_channel; i <= end_channel; ++i)
822 { 912 {
823 //pSoundDesc = pSoundList->pSounds; 913 auto channel = pMixerChannels + i;
824 pSoundDesc2 = &pSoundList->pSounds[pNum]; 914
825 if ( !pSoundDesc2->pSoundData[0] ) 915 int volume = AIL_sample_volume(channel->hSample);
916 if (volume < min_volume)
826 { 917 {
827 if (pSoundDesc2->eType == SOUND_DESC_SWAP) 918 min_volume = volume;
828 pSoundList->LoadSound(eSoundID, 0); 919 v62 = i;
829 } 920 }
830 } 921 }
831 v72 = 4 * (a7 + 30 * pNum) + 44; 922 /*v65 = start_channel;
832 if ( !*(int *)&pSoundList->pSounds->pSoundName[v72] ) 923 v91 = v93;
833 return; 924 if (start_channel <= end_channel)
834 pMixerChannel5 = &pAudioPlayer->pMixerChannels[v62];
835 AIL_init_sample(pMixerChannel5->hSample);
836 AIL_set_sample_file(pMixerChannel5->hSample, (void *)(*(int *)&pSoundList->pSounds->pSoundName[v72] + 4 * (a7 == 0)), -1);
837 pVolume = uVolume;
838 if ( !uVolume )
839 pVolume = LODWORD(v93);
840 AIL_set_sample_volume(pMixerChannel5->hSample, pVolume);
841 pPartyX = PartyX;
842 if ( PartyX != -1 )
843 {
844 if ( !PartyX )
845 pPartyX = pParty->vPosition.x;
846 if ( !PartyY )
847 PartyY = pParty->vPosition.y;
848 if ( uNumRepeats )
849 AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1);
850 v83 = sub_4AB66C(pPartyX, PartyY);
851 AIL_set_sample_pan(pMixerChannel5->hSample, v83);
852 v84 = GetSoundStrengthByDistanceFromParty(pPartyX, PartyY, pParty->vPosition.z);
853 AIL_set_sample_volume(pMixerChannel5->hSample, v84);
854 v76 = a3;
855 goto LABEL_184;
856 }
857 v76 = a3;
858 if ( (a3 & 7) == 1 )
859 {
860 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
861 goto LABEL_184;
862 pBLVDoor2 = &pIndoor->pDoors[a3 >> 3];
863 if ( !pBLVDoor2->uDoorID )
864 return;
865 if ( !GetSoundStrengthByDistanceFromParty(*pBLVDoor2->pXOffsets, *pBLVDoor2->pYOffsets, *pBLVDoor2->pZOffsets) )
866 {
867 AIL_end_sample(pMixerChannel5->hSample);
868 pAudioPlayer->AudioPlayer::_4ABE55(pMixerChannel5);
869 return;
870 }
871 pPosY = *pBLVDoor2->pYOffsets;
872 pPosX = *pBLVDoor2->pXOffsets;
873 //goto LABEL_167;
874 v80 = sub_4AB66C(pPosX, pPosY);
875 AIL_set_sample_pan(pMixerChannel5->hSample, v80);
876 goto LABEL_184;
877 }
878 if ( (a3 & 7) == 2 )
879 {
880 pLayingItem4 = &pLayingItems[a3 >> 3];
881 if ( !GetSoundStrengthByDistanceFromParty(pLayingItem4->vPosition.x, pLayingItem4->vPosition.y, pLayingItem4->vPosition.z) )
882 return;
883 }
884 else
885 {
886 if ( (a3 & 7) == 3 )
887 {
888 pActor3 = &pActors[a3 >> 3];
889 if ( !GetSoundStrengthByDistanceFromParty(pActor3->vPosition.x, pActor3->vPosition.y, pActor3->vPosition.z) )
890 return;
891 pPosY = pActor3->vPosition.y;
892 pPosX = pActor3->vPosition.x;
893 //goto LABEL_167;
894 v80 = sub_4AB66C(pPosX, pPosY);
895 AIL_set_sample_pan(pMixerChannel5->hSample, v80);
896 goto LABEL_184;
897 }
898 if ( (a3 & 7) != 5 )
899 {
900 LABEL_184:
901 if ( uNumRepeats )
902 AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1);
903 v85 = pMixerChannel5->hSample;
904 pMixerChannel5->uSourceTrackIdx = pNum;
905 pMixerChannel5->source_pid = v76;
906 pMixerChannel5->uSourceTrackID = eSoundID;
907 AIL_start_sample(v85);
908 if ( sPlaybackRate )
909 AIL_set_sample_playback_rate(pMixerChannel5->hSample, sPlaybackRate);
910 if ( (v76 & 7) == 4 )
911 AIL_sample_ms_position(pMixerChannel5->hSample, &sLastTrackLengthMS, 0);
912 return;
913 }
914 pLayingItem4 = (LayingItem *)&pLevelDecorations[a3 >> 3];
915 if ( !GetSoundStrengthByDistanceFromParty(pLayingItem4->vPosition.x, pLayingItem4->vPosition.y, pLayingItem4->vPosition.z) )
916 return;
917 AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1);
918 }
919 pPosY = pLayingItem4->vPosition.y;
920 pPosX = pLayingItem4->vPosition.x;
921 //LABEL_167:
922 v80 = sub_4AB66C(pPosX, pPosY);
923 AIL_set_sample_pan(pMixerChannel5->hSample, v80);
924 goto LABEL_184;
925 }
926 v65 = varC;
927 v62 = -1;
928 v91 = v93;
929 if ( varC <= v96 )
930 { 925 {
931 //pAudioPlayer5 = pAudioPlayer; 926 //pAudioPlayer5 = pAudioPlayer;
932 pMixerChannel3 = &pAudioPlayer->pMixerChannels[varC]; 927 pMixerChannel3 = &pAudioPlayer->pMixerChannels[start_channel];
933 do 928 do
934 { 929 {
935 v68 = AIL_sample_volume(pMixerChannel3->hSample); 930 v68 = AIL_sample_volume(pMixerChannel3->hSample);
936 if ( v68 < SLODWORD(v91) ) 931 if ( v68 < SLODWORD(v91) )
937 { 932 {
939 v62 = v65; 934 v62 = v65;
940 } 935 }
941 ++v65; 936 ++v65;
942 ++pMixerChannel3; 937 ++pMixerChannel3;
943 } 938 }
944 while ( v65 <= v96 ); 939 while ( v65 <= end_channel );*/
945 if ( v62 != -1 ) 940
946 { 941 if (v62 == -1) // no free channels at all - only channel 13 allows override (a3 == -1)
947 //LABEL_149: 942 {
948 //pAudioPlayer4 = pAudioPlayer; 943 if (start_channel != 13)
949 pMixerChannel4 = &pAudioPlayer->pMixerChannels[v62]; 944 return;
950 AIL_end_sample(pMixerChannel4->hSample); 945 v62 = 13;
951 _4ABE55(pMixerChannel4); 946 }
952 goto LABEL_150; 947
953 } 948 auto channel = &pMixerChannels[v62];
954 v65 = varC; 949 AIL_end_sample(channel->hSample);
955 } 950 _4ABE55(channel);
956 v62 = 13; 951 }
957 if ( v65 != 13 ) 952
953 if (v62 > end_channel)//10!=13
958 return; 954 return;
959 //goto LABEL_149; 955
960 //pAudioPlayer4 = pAudioPlayer; 956 //LABEL_150:
961 pMixerChannel4 = &pAudioPlayer->pMixerChannels[v62]; 957 if (sample_volume == 10000)
962 AIL_end_sample(pMixerChannel4->hSample); 958 sample_volume = uMasterVolume;
963 _4ABE55(pMixerChannel4); 959
964 goto LABEL_150; 960 //v70 = 0;
965 } 961 if ( !a7 )
966 if ( (a3 & 7) == 2 ) 962 {
967 { 963 //pSoundDesc = pSoundList->pSounds;
968 varC = 5; 964 //pSoundDesc2 = &pSoundList->pSounds[sound_id];
969 v96 = 7; 965 if (!sound_desc->pSoundData[0])
970 pLayingItem3 = &pLayingItems[a3 >> 3]; 966 {
971 } 967 if (sound_desc->eType == SOUND_DESC_SWAP)
972 else 968 pSoundList->LoadSound(eSoundID, 0);
973 { 969 }
974 if ( (a3 & 7) == 3 ) 970 }
975 { 971 //v72 = 4 * (a7 + 30 * sound_id) + 44;
976 *(float *)&varC = 0.0; 972 if (!pSoundList->pSounds[sound_id].pSoundData[a7])
977 pActor2 = &pActors[a3 >> 3]; 973 return;
978 v96 = 3; 974
979 v58 = pActor2->vPosition.y; 975 //pMixerChannel5 = &pAudioPlayer->pMixerChannels[v62];
980 v87 = pActor2->vPosition.z; 976 auto channel = &pMixerChannels[v62];
981 v59 = pActor2->vPosition.x; 977 AIL_init_sample(channel->hSample);
982 LABEL_116: 978 AIL_set_sample_file(channel->hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
983 LODWORD(v93) = GetSoundStrengthByDistanceFromParty(v59, /*(int)pSoundDesc*/ v58, v87); 979 int s = AIL_sample_status(channel->hSample);
984 if ( v93 == 0.0 ) 980 if (uVolume)
981 sample_volume = uVolume;
982 AIL_set_sample_volume(channel->hSample, sample_volume);
983
984 int object_type = a3 & 7,
985 object_id = a3 >> 7;
986 if (PartyX != -1)
987 {
988 if (!PartyX) PartyX = pParty->vPosition.x;
989 if (!PartyY) PartyY = pParty->vPosition.y;
990 AIL_set_sample_pan(channel->hSample, sub_4AB66C(PartyX, PartyY));
991 AIL_set_sample_volume(channel->hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z));
992 }
993 else if (object_type == OBJECT_BLVDoor)
994 {
995 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
996
997 assert(object_id < pIndoor->uNumDoors);
998 auto door = &pIndoor->pDoors[object_id];
999 if (!door->uDoorID)
985 return; 1000 return;
986 goto LABEL_123; 1001
987 } 1002 if (!GetSoundStrengthByDistanceFromParty(door->pXOffsets[0], door->pYOffsets[0], door->pZOffsets[0]))
988 if ( (a3 & 7) != 5 ) 1003 {
989 { 1004 AIL_end_sample(channel->hSample);
990 if ( (a3 & 7) == 6 ) 1005 _4ABE55(channel);
991 { 1006 return;
992 varC = 8; 1007 }
993 v96 = 9; 1008 AIL_set_sample_pan(channel->hSample, sub_4AB66C(door->pXOffsets[0], door->pYOffsets[0]));
994 } 1009 }
995 else 1010 else if (object_type == OBJECT_Item)
996 { 1011 {
997 varC = 10; 1012 assert(object_id < uNumLayingItems);
998 v96 = 12; 1013 auto object = &pLayingItems[object_id];
999 } 1014 if (!GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z) )
1000 goto LABEL_123; 1015 return;
1001 } 1016 AIL_set_sample_pan(channel->hSample, sub_4AB66C(object->vPosition.x, object->vPosition.y));
1002 varC = 4; 1017 }
1003 v96 = 4; 1018 else if (object_type == OBJECT_Actor)
1004 pLayingItem3 = (LayingItem *)&pLevelDecorations[a3 >> 3]; 1019 {
1005 } 1020 assert(object_id < uNumActors);
1006 v87 = pLayingItem3->vPosition.z; 1021 auto actor = &pActors[object_id];
1007 v58 = pLayingItem3->vPosition.y; 1022 if (!GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z))
1008 v59 = pLayingItem3->vPosition.x; 1023 return;
1009 goto LABEL_116; 1024 AIL_set_sample_pan(channel->hSample, sub_4AB66C(actor->vPosition.x, actor->vPosition.y));
1010 } 1025 }
1026 else if (object_type == OBJECT_Decoration)
1027 {
1028 assert(object_id < uNumLevelDecorations);
1029 auto decor = &pLevelDecorations[object_id];
1030 if (!GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z))
1031 return;
1032 AIL_set_sample_pan(channel->hSample, sub_4AB66C(decor->vPosition.x, decor->vPosition.y));
1033 }
1034
1035 //LABEL_184:
1036 if (uNumRepeats)
1037 AIL_set_sample_loop_count(channel->hSample, uNumRepeats - 1);
1038 channel->uSourceTrackIdx = sound_id;
1039 channel->source_pid = a3;
1040 channel->uSourceTrackID = eSoundID;
1041 int rval = AIL_start_sample(channel->hSample);
1042 if ( sPlaybackRate )
1043 AIL_set_sample_playback_rate(channel->hSample, sPlaybackRate);
1044 if (object_type == OBJECT_Player)
1045 AIL_sample_ms_position(channel->hSample, &sLastTrackLengthMS, 0);
1046 return;
1047 }
1048
1049
1050
1051
1052 __debugbreak(); // 3d sound stuff, refactor
1011 v12 = 13; 1053 v12 = 13;
1012 if ( a3 < 0 ) 1054 if ( a3 < 0 )
1013 { 1055 {
1014 v15 = pAudioPlayer->uNum3DSamples; 1056 v15 = pAudioPlayer->uNum3DSamples;
1015 if ( a3 == -1 ) 1057 if ( a3 == -1 )
1141 do 1183 do
1142 { 1184 {
1143 if ( AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 1185 if ( AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4
1144 && pAudioPlayer_3DSample->field_4 == a3 && AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 ) 1186 && pAudioPlayer_3DSample->field_4 == a3 && AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 )
1145 { 1187 {
1146 if ( pAudioPlayer_3DSample->field_8 == pNum ) 1188 if ( pAudioPlayer_3DSample->field_8 == sound_id )
1147 return; 1189 return;
1148 AIL_end_3D_sample(pAudioPlayer_3DSample->hSample); 1190 AIL_end_3D_sample(pAudioPlayer_3DSample->hSample);
1149 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample); 1191 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample);
1150 } 1192 }
1151 ++v101; 1193 ++v101;
1225 pAudioPlayer_3DSample3 = &pAudioPlayer->p3DSamples[v36]; 1267 pAudioPlayer_3DSample3 = &pAudioPlayer->p3DSamples[v36];
1226 AIL_end_3D_sample(pAudioPlayer_3DSample3->hSample); 1268 AIL_end_3D_sample(pAudioPlayer_3DSample3->hSample);
1227 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample3); 1269 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample3);
1228 v102 = v36; 1270 v102 = v36;
1229 } 1271 }
1230 v39 = v89; 1272 //v39 = v89;
1231 if ( pSoundList->pSounds[v89 / 0x78].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) ) 1273 if ( pSoundList->pSounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) )
1232 { 1274 {
1233 v41 = (char *)pAudioPlayer + 16 * v102; 1275 v41 = (char *)pAudioPlayer + 16 * v102;
1234 v42 = (int)(v41 + 20); 1276 v42 = (int)(v41 + 20);
1235 if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + v39)) ) 1277 if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + sound_id * sizeof(SoundDesc))) )
1236 { 1278 {
1237 if ( uNumRepeats ) 1279 if ( uNumRepeats )
1238 v86 = uNumRepeats - 1; 1280 v86 = uNumRepeats - 1;
1239 else 1281 else
1240 v86 = 1; 1282 v86 = 1;
1279 v53 = -uNumRepeatsa; 1321 v53 = -uNumRepeatsa;
1280 v54 = -v99; 1322 v54 = -v99;
1281 AIL_set_3D_orientation((void *)*(int *)v42, LODWORD(v54), 0.0, LODWORD(v53), 0.0, 1.0, 0.0); 1323 AIL_set_3D_orientation((void *)*(int *)v42, LODWORD(v54), 0.0, LODWORD(v53), 0.0, 1.0, 0.0);
1282 //pAudioPlayer3 = pAudioPlayer; 1324 //pAudioPlayer3 = pAudioPlayer;
1283 *((int *)v41 + 6) = a3; 1325 *((int *)v41 + 6) = a3;
1284 *((int *)v41 + 7) = pNum; 1326 *((int *)v41 + 7) = sound_id;
1285 *(&pAudioPlayer->bEAXSupported + 4 * (v102 + 2)) = eSoundID; 1327 *(&pAudioPlayer->bEAXSupported + 4 * (v102 + 2)) = eSoundID;
1286 } 1328 }
1287 else 1329 else
1288 { 1330 {
1289 AIL_end_3D_sample(*(int **)v42); 1331 AIL_end_3D_sample(*(int **)v42);