diff AudioPlayer.cpp @ 2139:f9b55be70c1b

Слияние
author Ritor1
date Thu, 02 Jan 2014 09:11:28 +0600
parents 68fbaf45ef66
children 4c0c475917dd
line wrap: on
line diff
--- a/AudioPlayer.cpp	Thu Jan 02 09:11:01 2014 +0600
+++ b/AudioPlayer.cpp	Thu Jan 02 09:11:28 2014 +0600
@@ -45,15 +45,17 @@
 
 
 
-unsigned __int8 uSoundVolumeMultiplier = 4;
-unsigned __int8 uVoicesVolumeMultiplier = 4;
-unsigned __int8 uMusicVolimeMultiplier = 4;
+unsigned __int8 uSoundVolumeMultiplier;// = 4;
+unsigned __int8 uVoicesVolumeMultiplier;// = 4;
+unsigned __int8 uMusicVolimeMultiplier;// = 4;
 int bWalkSound; // idb
 
 std::array<float, 10> pSoundVolumeLevels = 
 {
   0.0000000f, 0.1099999f, 0.2199999f, 0.3300000f, 0.4399999f,
- 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9700000f     //changed 0.9900000f to 0.9700000f. for some reason it only works for values below this
+ 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9700000f  
+//  0.0000000f, 0.4900000f, 0.5500000f, 0.6100000f, 0.6700000f,  //for 128.0f
+// 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
 };
 
 
@@ -81,13 +83,16 @@
   {
     for ( uint i = 1; i < pSoundList->sNumSounds; ++i )
     {
-      sprintf(pSoundName, "%s", pSounds[i].pSoundName);
-      pSoundDesc = &pSoundList->pSounds[i];
-      if ( pSoundList->pSounds[i].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[i].pSoundName),
-            pSoundList->pSounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)-1, pSounds[i].uSoundID),
-            !pAudioPlayer->b3DSoundInitialized)
-        || (pSoundDesc = &pSoundList->pSounds[i], !(pSoundDesc->uFlags & SOUND_DESC_SWAP))
-        || !pSoundDesc->pSoundData[0] )
+      sprintf(pSoundName, "%s", pSL_Sounds[i].pSoundName);
+      pSoundDesc = &pSoundList->pSL_Sounds[i];
+      if ( pSoundList->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM )
+        continue;
+      sprintf(pSoundName, "%s", pSL_Sounds[i].pSoundName);
+      pSoundList->pSL_Sounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)-1, pSL_Sounds[i].uSoundID);
+      if ( !pAudioPlayer->b3DSoundInitialized )
+        continue;
+      pSoundDesc = &pSoundList->pSL_Sounds[i];
+      if ( !(pSoundDesc->uFlags & SOUND_DESC_SWAP) || !pSoundDesc->pSoundData[0] )
         continue;
       pSoundData = pSoundDesc->pSoundData[0];
       uSoundSize = *(int *)pSoundData;
@@ -95,7 +100,7 @@
       pType = AIL_file_type(pSoundBytes, uSoundSize);
       if ( !pType )
       {
-        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->pSL_Sounds[i].bDecompressed = false;
         pSoundList->UnloadSound(i, 1);
         continue;
       }
@@ -106,20 +111,20 @@
         {
           if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 )
           {
-            if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[i].p3DSound, &v12) )
+            if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSL_Sounds[i].p3DSound, &v12) )
             {
-              pSoundList->pSounds[i].p3DSound = 0;
-              pSoundList->pSounds[i].bDecompressed = true;
+              pSoundList->pSL_Sounds[i].p3DSound = 0;
+              pSoundList->pSL_Sounds[i].bDecompressed = true;
             }
           }
           pSoundList->UnloadSound(i, 1);
           continue;
         }
-        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->pSL_Sounds[i].bDecompressed = false;
         pSoundList->UnloadSound(i, 1);
         continue;
       }
-      pSoundList->pSounds[i].p3DSound = pSoundList->pSounds[i].pSoundData[0];
+      pSoundList->pSL_Sounds[i].p3DSound = pSoundList->pSL_Sounds[i].pSoundData[0];
       pSoundList->UnloadSound(i, 1);
     }
   }
@@ -136,10 +141,10 @@
   uint       uSoundIdx = 0;
   SoundDesc *pSound = nullptr;
   for (uint i = 1; i < sNumSounds; ++i)
-    if (pSounds[i].uSoundID == a1)
+    if (pSL_Sounds[i].uSoundID == a1)
     {
       uSoundIdx = i;
-      pSound = &pSounds[i];
+      pSound = &pSL_Sounds[i];
       break;
     }
   if (!pSound)
@@ -230,7 +235,7 @@
     v25 = 44;
     while ( 1 )
     {
-      v10 = pSounds;
+      v10 = pSL_Sounds;
       v11 = &v10[v24 / 0x78];
       Args = &v10[v24 / 0x78];
       if ( a2 == v10[v24 / 0x78].uSoundID )
@@ -288,7 +293,7 @@
       v16 = a2;
     }
     result = v26;
-    pSounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer;
+    pSL_Sounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer;
     *pOutSoundSize = v16;
 
   return result;
@@ -304,13 +309,13 @@
   {
     for ( uint i = 0; i < (signed int)this->sNumSounds; ++i )
     {
-      result = this->pSounds;
+      result = this->pSL_Sounds;
       v5 = result[i].pSoundData[0];
       if ( v5 )
       {
         ReleaseSoundData(v5);
-        this->pSounds[i].pSoundData[0] = 0;
-        result = (SoundDesc *)((char *)&this->pSounds[i] + 40);
+        this->pSL_Sounds[i].pSoundData[0] = 0;
+        result = (SoundDesc *)((char *)&this->pSL_Sounds[i] + 40);
         *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu;
       }
     }
@@ -323,14 +328,14 @@
 {
   for ( int i = 0; i < (signed int)this->sNumSounds; ++i )
   {
-    if ( this->pSounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSounds[i].eType != SOUND_DESC_LOCK) )
+    if ( this->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSL_Sounds[i].eType != SOUND_DESC_LOCK) )
     {
-      if ( this->pSounds[i].pSoundData[0] )
+      if ( this->pSL_Sounds[i].pSoundData[0] )
       {
-        ReleaseSoundData(this->pSounds[i].pSoundData[0]);
-        this->pSounds[i].pSoundData[0] = 0;
+        ReleaseSoundData(this->pSL_Sounds[i].pSoundData[0]);
+        this->pSL_Sounds[i].pSoundData[0] = 0;
       }
-      this->pSounds[i].uFlags &= ~SOUND_DESC_SYSTEM;
+      this->pSL_Sounds[i].uFlags &= ~SOUND_DESC_SYSTEM;
     }
   }
 }
@@ -338,20 +343,20 @@
 //----- (004A9DCD) --------------------------------------------------------
 void SoundList::UnloadSound(unsigned int uSoundID, char a3)
 {
-  if ( pSounds[uSoundID].eType != SOUND_DESC_SYSTEM )
+  if ( pSL_Sounds[uSoundID].eType != SOUND_DESC_SYSTEM )
   {
-    if ( (pSounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSounds[uSoundID].p3DSound && a3 )
+    if ( (pSL_Sounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSL_Sounds[uSoundID].p3DSound && a3 )
     {
-      if ( pSounds[uSoundID].bDecompressed)
-        AIL_mem_free_lock(pSounds[uSoundID].p3DSound);
-      pSounds[uSoundID].p3DSound = 0;
-      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
+      if ( pSL_Sounds[uSoundID].bDecompressed)
+        AIL_mem_free_lock(pSL_Sounds[uSoundID].p3DSound);
+      pSL_Sounds[uSoundID].p3DSound = 0;
+      pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
-    if ( pSounds[uSoundID].pSoundData[0] )
+    if ( pSL_Sounds[uSoundID].pSoundData[0] )
     {
-      ReleaseSoundData(pSounds[uSoundID].pSoundData[0]);
-      pSounds[uSoundID].pSoundData[0] = NULL;
-      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
+      ReleaseSoundData(pSL_Sounds[uSoundID].pSoundData[0]);
+      pSL_Sounds[uSoundID].pSoundData[0] = NULL;
+      pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
   }
 }
@@ -367,7 +372,7 @@
     Error("Unable to save dsounds.bin!");
 
   fwrite(this, 4, 1, v2);
-  fwrite(this->pSounds, 0x78u, this->sNumSounds, v2);
+  fwrite(this->pSL_Sounds, 0x78u, this->sNumSounds, v2);
   fclose(v2);
 }
 
@@ -382,12 +387,12 @@
   assert(sNumSounds);
   assert(!num_mm8_sounds);
 
-  pSounds = (SoundDesc *)malloc(sNumSounds * sizeof(SoundDesc));
-  memcpy(pSounds, (char *)data_mm7 + 4, num_mm7_sounds * sizeof(SoundDesc));
+  pSL_Sounds = (SoundDesc *)malloc(sNumSounds * sizeof(SoundDesc));
+  memcpy(pSL_Sounds, (char *)data_mm7 + 4, num_mm7_sounds * sizeof(SoundDesc));
   for (uint i = 0; i < num_mm6_sounds; ++i)
   {
     auto src = (SoundDesc_mm6 *)((char *)data_mm6 + 4) + i;
-    SoundDesc* dst = &pSounds[num_mm7_sounds + i];
+    SoundDesc* dst = &pSL_Sounds[num_mm7_sounds + i];
 
     memcpy(dst, src, sizeof(SoundDesc_mm6));
     dst->p3DSound = nullptr;
@@ -417,9 +422,9 @@
   FILE *File; // [sp+2F8h] [bp-4h]@1
   unsigned int Argsa; // [sp+304h] [bp+8h]@3
 
-  free(this->pSounds);
+  free(this->pSL_Sounds);
   v3 = 0;
-  this->pSounds = 0;
+  this->pSL_Sounds = 0;
   this->sNumSounds = 0;
   v4 = fopen(Args, "r");
   File = v4;
@@ -443,7 +448,7 @@
   }
   this->sNumSounds = v5;
   v6 = malloc(120 * v5);
-  this->pSounds = (SoundDesc *)v6;
+  this->pSL_Sounds = (SoundDesc *)v6;
   if ( v6 == (void *)v3 )
     Error("SoundListClass::load - Out of Memory!");
 
@@ -457,16 +462,16 @@
     memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19));
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
-      sprintf(this->pSounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
+      sprintf(this->pSL_Sounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
       v9 = atoi(v19.pProperties[1]);
       v10 = v19.pProperties[2];
-      this->pSounds[this->sNumSounds].uSoundID = v9;
+      this->pSL_Sounds[this->sNumSounds].uSoundID = v9;
       if ( _stricmp(v10, "system") )
       {
         if ( _stricmp(v19.pProperties[2], "swap") )
         {
           v11 = _stricmp(v19.pProperties[2], "lock");
-          v12 = this->pSounds;
+          v12 = this->pSL_Sounds;
           v13 = v11 == 0;
           v14 = this->sNumSounds;
           if ( v13 )
@@ -475,13 +480,13 @@
             v12[v14].eType = SOUND_DESC_LEVEL;
         }
         else
-          this->pSounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
+          this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
       }
       else
-        this->pSounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
+        this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
       if ( v19.uPropCount >= 4 && !_stricmp(v19.pProperties[3], "3D") )
       {
-        v15 = (int)&this->pSounds[this->sNumSounds].uFlags;
+        v15 = (int)&this->pSL_Sounds[this->sNumSounds].uFlags;
         *(int *)v15 |= SOUND_DESC_SWAP;
       }
       ++this->sNumSounds;
@@ -535,44 +540,30 @@
   if (!bPlayerReady)
     return;
 
-    if ( this->b3DSoundInitialized && a2 && this->uNum3DSamples > 0 )
+  if ( this->b3DSoundInitialized && a2 )
+  {
+    for ( uint i = 0; i < this->uNum3DSamples; ++i )
     {
-      for ( uint i = 0; i < this->uNum3DSamples; ++i )
-      {
-        if ( this->p3DSamples[i].field_4 == a2 && AIL_3D_sample_status(this->p3DSamples[i].hSample) == 4 )
-          AIL_end_3D_sample(this->p3DSamples[i].hSample);
-      }
-      goto LABEL_9;
+      if ( this->p3DSamples[i].field_4 == a2 && AIL_3D_sample_status(this->p3DSamples[i].hSample) == AIL::Sample::Playing )
+        AIL_end_3D_sample(this->p3DSamples[i].hSample);
     }
-    else
+  }
+  if ( this->hDigDriver && a2 )
+  {
+    for ( uint i = 0; i < this->uMixerChannels; ++i )
     {
-LABEL_9:
-      if ( this->hDigDriver )
+      if ( this->pMixerChannels[i].source_pid == a2 && AIL_sample_status(this->pMixerChannels[i].hSample) == AIL::Sample::Playing)
       {
-        if ( a2 && this->uMixerChannels > 0 )
-        {
-          for ( uint i = 0; i < this->uMixerChannels; ++i )
-          {
-            if ( this->pMixerChannels[i].source_pid == a2 )
-            {
-              if ( AIL_sample_status(this->pMixerChannels[i].hSample) == AIL::Sample::Playing)
-              {
-                AIL_end_sample(this->pMixerChannels[i].hSample);
-                FreeChannel(&this->pMixerChannels[i]);
-              }
-            }
-          }
-        }
+        AIL_end_sample(this->pMixerChannels[i].hSample);
+        FreeChannel(&this->pMixerChannels[i]);
       }
     }
+  }
 }
 
 //----- (004AA306) --------------------------------------------------------
-void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate)
+void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int source_x, signed int source_y, int a7, float uVolume, int sPlaybackRate)
 {
-  //AudioPlayer *pAudioPlayer1; // esi@1
-  //signed int pNum; // edx@5
-  //int *pSoundID; // ecx@6
   int v12; // edi@13
   signed int v13; // ecx@17
   signed int v14; // eax@20
@@ -598,9 +589,7 @@
   int v34; // eax@70
   char v35; // zf@70
   signed int v36; // ebx@74
-  //AudioPlayer *pAudioPlayer2; // edi@79
   AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79
-  //unsigned int v39; // ebx@80
   int v40; // eax@81
   char *v41; // edi@82
   int v42; // esi@82
@@ -616,47 +605,16 @@
   int v52; // eax@104
   float v53; // ST0C_4@106
   float v54; // ST04_4@106
-  //AudioPlayer *pAudioPlayer3; // edx@106
   SoundDesc *pSoundDesc; // edx@107
   SpriteObject *pLayingItem3; // eax@114
-  //int v58; // edx@115
-  //int v59; // ecx@115
-  //Actor *pActor2; // eax@118
-  //MixerChannel *pMixerChannel; // esi@126
   signed int v62; // esi@133
-  //AudioPlayer *pAudioPlayer4; // ebx@133
-  //MixerChannel *pMixerChannel2; // edi@134
-  //int v65; // ebx@141
-  //AudioPlayer *pAudioPlayer5; // ecx@142
-  //MixerChannel *pMixerChannel3; // edi@142
   int v68; // eax@143
-  //MixerChannel *pMixerChannel4; // edi@149
-  //int v70; // ecx@152
-  //SoundDesc *pSoundDesc2; // eax@153
-  //int v72; // edi@156
-  //MixerChannel *pMixerChannel5; // esi@157
-  //unsigned int pVolume; // eax@157
-  //int pPartyX; // ebx@159
-  //int v76; // ebx@160
-  //SpriteObject *pLayingItem4; // edi@164
-  //unsigned int pPosY; // edx@166
-  //unsigned int pPosX; // ecx@166
-  //int v80; // eax@167
-  //Actor *pActor3; // edi@168
-  //BLVDoor *pBLVDoor2; // edi@173
-  //int v83; // eax@183
-  //int v84; // eax@183
-  //_SAMPLE *v85; // ST18_4@186
   unsigned int v86; // [sp+14h] [bp-60h]@84
-  //int v87; // [sp+14h] [bp-60h]@115
   RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1
-  //unsigned int v89; // [sp+54h] [bp-20h]@12
   int v90; // [sp+58h] [bp-1Ch]@68
   float v91; // [sp+5Ch] [bp-18h]@68
-  //unsigned int v92; // [sp+60h] [bp-14h]@10
   float v93; // [sp+64h] [bp-10h]@1
   signed int varC; // [sp+68h] [bp-Ch]@68
-  //AudioPlayer *pAudioPlayer; // [sp+6Ch] [bp-8h]@1
   int v96; // [sp+70h] [bp-4h]@19
   signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93
   float uNumRepeatsa; // [sp+84h] [bp+10h]@104
@@ -666,25 +624,14 @@
   int v102; // [sp+90h] [bp+1Ch]@60
   int v103; // [sp+90h] [bp+1Ch]@68
 
-  if (!bPlayerReady)
-    return;
-  if (!uSoundVolumeMultiplier)
-    return;
-  if (!hDigDriver)
-    return;
-  if (eSoundID == SOUND_Invalid)
+  if ( !bPlayerReady || !uSoundVolumeMultiplier || !hDigDriver || eSoundID == SOUND_Invalid )
     return;
 
-  //pAudioPlayer = this;
-  //v35 = this->bPlayerReady == 0;
-  //pAudioPlayer = this;
-  //LODWORD(v93) = 10000;
   int sample_volume = 10000;
 
-
   int sound_id = 0;
   for (uint i = 0; i < pSoundList->sNumSounds; ++i)
-    if (pSoundList->pSounds[i].uSoundID == eSoundID)
+    if (pSoundList->pSL_Sounds[i].uSoundID == eSoundID)
     {
       sound_id = i;
       break;
@@ -695,345 +642,501 @@
     Log::Warning(L"SoundID = %u not found", eSoundID);
     return;
   }
+  assert(sound_id < pSoundList->sNumSounds);
+  if ( !a7 )
+  {
+    if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[0] )
+    {
+      if ( pSoundList->pSL_Sounds[sound_id].eType == SOUND_DESC_SWAP )
+        pSoundList->LoadSound(eSoundID, 0);
+    }
+  }
+  if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[a7] )
+    return;
 
   int start_channel = 0,
       end_channel = 0;
-v62 = start_channel;
-  assert(sound_id < pSoundList->sNumSounds);
-  SoundDesc* sound_desc = &pSoundList->pSounds[sound_id];
-  if (!b3DSoundInitialized || sound_desc->Is3D())
+  v62 = start_channel;
+
+  if (!b3DSoundInitialized || pSoundList->pSL_Sounds[sound_id].Is3D())
   {
-    if (!a3)  // generic sound like from UI
+    if (a3 == 0)  // generic sound like from UI
     {
       start_channel = 10;
       end_channel = 12;
-      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      for (uint i = start_channel; i <= end_channel; ++i)
       {
-        MixerChannel* channel = pMixerChannels + v62;
-        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+        if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
         {
-          AIL_end_sample(channel->hSample);
-          if (channel->uSourceTrackIdx)
-            FreeChannel(channel);
-          break;
+          if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+            return;                          // already playing the same sound from the same source - return
+          AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+          FreeChannel(&pMixerChannels[i]);
         }
       }
+      for ( uint j = start_channel; j <= end_channel; j++ )
+      {
+        if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
+        {
+          AIL_init_sample(pMixerChannels[j].hSample);
+          char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+          if (a7 == 0)  p = p + 4;//for RIFF
+		  if ( eSoundID == 75 )// Ritor1: include +7 for pSounds[20]
+			  p = p + 7;
+          AIL_set_sample_file(pMixerChannels[j].hSample, p, -1);
+          if ( sample_volume == 10000 )
+            sample_volume = uMasterVolume;
+          if (uVolume)
+            sample_volume = uVolume;
+          int object_type = PID_TYPE(a3),
+              object_id = PID_ID(a3);
+          if (source_x != -1)//        
+          {
+            //if (!source_x)
+              //source_x = pParty->vPosition.x;
+            //if (!source_y)
+              //source_y = pParty->vPosition.y;
+           if ( source_x )//Ritor1: for pedestals
+           {
+              AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(source_x, source_y));
+              int vol = GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z);
+              AIL_set_sample_volume(pMixerChannels[j].hSample, vol);
+           }
+          }
+          if (uNumRepeats)
+            AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+          pMixerChannels[j].uSourceTrackIdx = sound_id;
+          pMixerChannels[j].source_pid = a3;
+          pMixerChannels[j].uSourceTrackID = eSoundID;
+          int rval = AIL_start_sample(pMixerChannels[j].hSample);
+          if ( sPlaybackRate )
+            AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+          if (object_type == OBJECT_Player)
+            AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+          return;
+        }
+      }
+      return;
     }
     else if (a3 == -1)  // exclusive sounds - can override
     {
-      start_channel = 13;
-      end_channel = 13;
-      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      /*if ( AIL_sample_status(pMixerChannels[13].hSample) == AIL::Sample::Done )
       {
-        MixerChannel* channel = pMixerChannels + v62;
-        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+          AIL_end_sample(pMixerChannels[13].hSample);
+          if ( pMixerChannels[13].uSourceTrackIdx )
+            FreeChannel(&pMixerChannels[13]);
+      }*/
+      AIL_init_sample(pMixerChannels[13].hSample);
+      char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+      if (a7 == 0)
+        p = p + 4;//for RIFF
+	  if ( eSoundID == 75 )//  Ritor1: include +7 for pSounds[20]
+		  p = p + 7;
+       AIL_set_sample_file(pMixerChannels[13].hSample, p, -1);
+       if ( sample_volume == 10000 )
+         sample_volume = uMasterVolume;
+       if (uVolume)
+         sample_volume = uVolume;
+       AIL_set_sample_volume(pMixerChannels[13].hSample, sample_volume);
+       int object_type = PID_TYPE(a3),
+           object_id = PID_ID(a3);
+       if (uNumRepeats)
+         AIL_set_sample_loop_count(pMixerChannels[13].hSample, uNumRepeats - 1);
+       pMixerChannels[13].uSourceTrackIdx = sound_id;
+       pMixerChannels[13].source_pid = a3;
+       pMixerChannels[13].uSourceTrackID = eSoundID;
+       int rval = AIL_start_sample(pMixerChannels[13].hSample);//no sound chest close 
+       if ( sPlaybackRate )
+         AIL_set_sample_playback_rate(pMixerChannels[13].hSample, sPlaybackRate);
+       if (object_type == OBJECT_Player)
+         AIL_sample_ms_position(pMixerChannels[13].hSample, &sLastTrackLengthMS, 0);
+       return;
+    }
+    else if (a3 < 0)    // exclusive sounds - no override (close chest)
+    {
+      start_channel = 14;
+      end_channel = 14;
+      for (uint i = start_channel; i <= end_channel; ++i)
+      {
+        if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
         {
-          AIL_end_sample(channel->hSample);
-          if (channel->uSourceTrackIdx)
-            FreeChannel(channel);
-          break;
+          if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+            return;                          // already playing the same sound from the same source - return
+          AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+          FreeChannel(&pMixerChannels[i]);
         }
       }
+      for ( uint j = start_channel; j <= end_channel; j++ )
+      {
+        if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
+        {
+          AIL_init_sample(pMixerChannels[j].hSample);
+          char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+          if (a7 == 0)  p = p + 4;//for RIFF
+		  if ( eSoundID == 75 )//  Ritor1: include +7 for pSounds[20]
+			  p = p + 7;
+          AIL_set_sample_file(pMixerChannels[j].hSample, p, -1);
+          if ( sample_volume == 10000 )
+            sample_volume = uMasterVolume;
+          if (uVolume)
+            sample_volume = uVolume;
+          int object_type = PID_TYPE(a3),
+              object_id = PID_ID(a3);
+          if (uNumRepeats)
+            AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+          pMixerChannels[j].uSourceTrackIdx = sound_id;
+          pMixerChannels[j].source_pid = a3;
+          pMixerChannels[j].uSourceTrackID = eSoundID;
+          int rval = AIL_start_sample(pMixerChannels[j].hSample);//no sound chest close 
+          if ( sPlaybackRate )
+            AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+          if (object_type == OBJECT_Player)
+            AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+          return;
+        }
+      }
+      return;
     }
     else
     {
-      if (a3 < 0)    // exclusive sounds - no override
-      {
-        start_channel = 14;
-        end_channel = 14;
-        for (uint i = 0; i < uMixerChannels; ++i)
-        {
-          MixerChannel* channel = &pMixerChannels[i];
-          if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
-          {
-            if (channel->uSourceTrackIdx == sound_id)
-              return;                          // already playing the same sound from the same source - return
-            AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-            FreeChannel(channel);
-          }
-        }
-      }
-      else
-      {
         int object_type = PID_TYPE(a3),
             object_id = PID_ID(a3);
         switch (object_type)
         {
           case OBJECT_BLVDoor:
+          {
+            assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
+            assert(object_id < pIndoor->uNumDoors);
+            if ( !pIndoor->pDoors[object_id].uDoorID )
+              return;
+
+            start_channel = 10;
+            end_channel = 12;
+            for (uint i = start_channel; i <= end_channel; ++i)
+            {
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
+              {
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                /*if (!GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0], pIndoor->pDoors[object_id].pZOffsets[0]))
+                {
+                  AIL_end_sample(pMixerChannels[j].hSample);
+                  FreeChannel(&pMixerChannels[j]);
+                  return;
+                } */
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0]));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
+              }
+            }
+          }
+          return;
+
           case OBJECT_Player:
           {
             start_channel = 10;
             end_channel = 12;
-            for (v62 = start_channel; v62 <= end_channel; ++v62)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = pMixerChannels + v62;
-              if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                AIL_end_sample(channel->hSample);
-                if (channel->uSourceTrackIdx)
-                  FreeChannel(channel);
-                break;
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Actor:
           {
             start_channel = 0;
             end_channel = 3;
-
             assert(object_id < uNumActors);
-            Actor* actor = &pActors[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  return;                          // already playing the same sound from the same source - return
-                AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z))
+                  return;
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Decoration:
           {
             start_channel = 4;
             end_channel = 4;
-
             assert(object_id < uNumLevelDecorations);
-            LevelDecoration* decor = &pLevelDecorations[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )//        
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  return;                          // already playing the same sound from the same source - return
-                AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z))
+                  return;
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Item:
           {
             start_channel = 5;
             end_channel = 7;
-
             assert(object_id < uNumSpriteObjects);
-            SpriteObject* object = &pSpriteObjects[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if (pMixerChannels[i].uSourceTrackIdx == sound_id)
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  return;                          // already playing the same sound from the same source - return
-                AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z) )
+                  return;
+                AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_BModel:
           {
             start_channel = 8;
             end_channel = 9;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  return;                          // already playing the same sound from the same source - return
-                AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           default:
             assert(false);
         }
       }
-    }
-      /*if ( start_channel <= end_channel)
-      {
-        pMixerChannel2 = &pAudioPlayer->pMixerChannels[start_channel];
-        while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done)
-        {
-          ++v62;
-          ++pMixerChannel2;
-          if ( v62 > end_channel )
-            goto LABEL_140;
-        }
-        AIL_end_sample(pMixerChannel2->hSample);
-        if ( pMixerChannel2->uSourceTrackIdx )
-          _4ABE55(pMixerChannel2);
-      }
-LABEL_140:*/
 
+	  __debugbreak();//Ritor1
       if (start_channel > end_channel)  // no free channel - occupy the quitest one
       {
         start_channel = -1;
-
         int min_volume = sample_volume;
         for (uint i = start_channel; i <= end_channel; ++i)
         {
-          MixerChannel* channel = &pMixerChannels[i];
-
-          int volume = AIL_sample_volume(channel->hSample);
+          int volume = AIL_sample_volume(pMixerChannels[i].hSample);
           if (volume < min_volume)
           {
             min_volume = volume;
             start_channel = i;
           }
         }
-        /*v65 = start_channel;
-        v91 = v93;
-      if (start_channel <= end_channel)
-      {
-        //pAudioPlayer5 = pAudioPlayer;
-        pMixerChannel3 = &pAudioPlayer->pMixerChannels[start_channel];
-        do
-        {
-          v68 = AIL_sample_volume(pMixerChannel3->hSample);
-          if ( v68 < SLODWORD(v91) )
-          {
-            LODWORD(v91) = v68;
-            v62 = v65;
-          }
-          ++v65;
-          ++pMixerChannel3;
-        }
-        while ( v65 <= end_channel );*/
-
         if (v62 == -1)   // no free channels at all - only channel 13 allows override (a3 == -1)
         {
           if (start_channel != 13)
             return;
           v62 = 13;
         }
-
-        MixerChannel* channel = &pMixerChannels[v62];
-        AIL_end_sample(channel->hSample);
-        FreeChannel(channel);
+        AIL_end_sample(pMixerChannels[v62].hSample);
+        FreeChannel(&pMixerChannels[v62]);
       }
 
       if (v62 > end_channel)//10!=13
         return;
 
-//LABEL_150:
-      if (sample_volume == 10000)
+      if ( sample_volume == 10000 )
         sample_volume = uMasterVolume;
 
-        //v70 = 0;
-      if ( !a7 )
-      {
-          //pSoundDesc = pSoundList->pSounds;
-          //pSoundDesc2 = &pSoundList->pSounds[sound_id];
-        if (!sound_desc->pSoundData[0])
-        {
-          if (sound_desc->eType == SOUND_DESC_SWAP)
-            pSoundList->LoadSound(eSoundID, 0);
-        }
-      }
-        //v72 = 4 * (a7 + 30 * sound_id) + 44;
-      if (!pSoundList->pSounds[sound_id].pSoundData[a7])
-        return;
-
-        //pMixerChannel5 = &pAudioPlayer->pMixerChannels[v62];
-      MixerChannel* channel = &pMixerChannels[v62];
-      AIL_init_sample(channel->hSample);
-      AIL_set_sample_file(channel->hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+      AIL_init_sample(pMixerChannels[v62].hSample);
+      AIL_set_sample_file(pMixerChannels[v62].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
       if (uVolume)
         sample_volume = uVolume;
-      AIL_set_sample_volume(channel->hSample, sample_volume);
+      AIL_set_sample_volume(pMixerChannels[v62].hSample, sample_volume);
 
       int object_type = PID_TYPE(a3),
           object_id = PID_ID(a3);
-      if (PartyX != -1)
-      {
-        if (!PartyX) PartyX = pParty->vPosition.x;
-        if (!PartyY) PartyY = pParty->vPosition.y;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(PartyX, PartyY));
-        AIL_set_sample_volume(channel->hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z));
-      }
-      else if (object_type == OBJECT_BLVDoor)
+      if (source_x != -1)
       {
-        assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
-
-        assert(object_id < pIndoor->uNumDoors);
-        BLVDoor* door = &pIndoor->pDoors[object_id];
-        if (!door->uDoorID)
-          return;
-
-        if (!GetSoundStrengthByDistanceFromParty(door->pXOffsets[0], door->pYOffsets[0], door->pZOffsets[0]))
-        {
-          AIL_end_sample(channel->hSample);
-          FreeChannel(channel);
-          return;
-        }
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(door->pXOffsets[0], door->pYOffsets[0]));
-      }
-      else if (object_type == OBJECT_Item)
-      {
-        assert(object_id < uNumSpriteObjects);
-        SpriteObject* object = &pSpriteObjects[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z) )
-            return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(object->vPosition.x, object->vPosition.y));
-      }
-      else if (object_type == OBJECT_Actor)
-      {
-        assert(object_id < uNumActors);
-        Actor* actor = &pActors[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z))
-          return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(actor->vPosition.x, actor->vPosition.y));
-      }
-      else if (object_type == OBJECT_Decoration)
-      {
-        assert(object_id < uNumLevelDecorations);
-        LevelDecoration* decor = &pLevelDecorations[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z))
-          return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(decor->vPosition.x, decor->vPosition.y));
+        if (!source_x)
+          source_x = pParty->vPosition.x;
+        if (!source_y)
+          source_y = pParty->vPosition.y;
+        AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(source_x, source_y));
+        AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z));
       }
 
-//LABEL_184:
       if (uNumRepeats)
-        AIL_set_sample_loop_count(channel->hSample, uNumRepeats - 1);
-      channel->uSourceTrackIdx = sound_id;
-      channel->source_pid = a3;
-      channel->uSourceTrackID = eSoundID;
-      int rval = AIL_start_sample(channel->hSample);
+        AIL_set_sample_loop_count(pMixerChannels[v62].hSample, uNumRepeats - 1);
+      pMixerChannels[v62].uSourceTrackIdx = sound_id;
+      pMixerChannels[v62].source_pid = a3;
+      pMixerChannels[v62].uSourceTrackID = eSoundID;
+      int rval = AIL_start_sample(pMixerChannels[v62].hSample);
       if ( sPlaybackRate )
-        AIL_set_sample_playback_rate(channel->hSample, sPlaybackRate);
+        AIL_set_sample_playback_rate(pMixerChannels[v62].hSample, sPlaybackRate);
       if (object_type == OBJECT_Player)
-        AIL_sample_ms_position(channel->hSample, &sLastTrackLengthMS, 0);
-      return;
+        AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0);
+      return; 
   }
-
+  else
+  {
   __debugbreak(); // 3d sound stuff, refactor
   v12 = 13;
   if ( a3 < 0 )
@@ -1255,18 +1358,18 @@
     v102 = v36;
   }
   //v39 = v89;
-  if ( pSoundList->pSounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) )
+  if ( pSoundList->pSL_Sounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) )
   {
     v41 = (char *)pAudioPlayer + 16 * v102;
     v42 = (int)(v41 + 20);
-    if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + sound_id * sizeof(SoundDesc))) )
+    if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSL_Sounds->p3DSound + sound_id * sizeof(SoundDesc))) )
     {
       if ( uNumRepeats )
         v86 = uNumRepeats - 1;
       else
         v86 = 1;
       AIL_set_3D_sample_loop_count(*(int *)v42, v86);
-      if ( PartyX == -1 )
+      if ( source_x == -1 )
       {
         if ( PID_TYPE(a3) == 1 )
         {
@@ -1349,13 +1452,14 @@
         v47 = (double)pLayingItem2->vPosition.z;
         goto LABEL_101;
       }
-      pRenderVertexSoft.vWorldPosition.x = (double)PartyX;
-      v43 = (double)PartyY;
+      pRenderVertexSoft.vWorldPosition.x = (double)source_x;
+      v43 = (double)source_y;
       pRenderVertexSoft.vWorldPosition.y = v43;
       v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
       goto LABEL_101;
     }
   }
+  }
 }
 
 //----- (0040DEA5) --------------------------------------------------------
@@ -1373,7 +1477,7 @@
   //unsigned __int8 v3; // zf@1
   //int *v4; // eax@2
   //unsigned __int8 v5; // sf@4
-  AudioPlayer_3DSample *v6; // esi@5
+  //AudioPlayer_3DSample *v6; // esi@5
   int v7; // ebx@6
   int v8; // ebx@9
   int v9; // ebx@10
@@ -1437,164 +1541,360 @@
   if (!bPlayerReady)
     return;
   
-  if (field_2D0_time_left <= pEventTimer->uTimeElapsed)
-    field_2D0_time_left = 32;
-  else
+  //if (field_2D0_time_left <= pEventTimer->uTimeElapsed)
+    //field_2D0_time_left = 32;
+  //else
+  //{
+    //field_2D0_time_left -= pEventTimer->uTimeElapsed;
+    //return;
+  //}
+  field_2D0_time_left -= pEventTimer->uTimeElapsed;
+  if ( field_2D0_time_left <= 0 )
   {
-    field_2D0_time_left -= pEventTimer->uTimeElapsed;
-    return;
-  }
-
-  //v3 = this->b3DSoundInitialized == 0;
-  if ( b3DSoundInitialized )
+  field_2D0_time_left = 32;
+  if ( b3DSoundInitialized )//for 3D sound
   {
     __debugbreak(); // refactor refactor
-    //v3 = this->uNum3DSamples == 0;
-    //v5 = this->uNum3DSamples < 0;
-    v59 = 0;
-    if (uNum3DSamples > 0)
+    v2 = 0;
+    for ( v59 = 0; v59 < pAudioPlayer->uNum3DSamples; ++v59 )
     {
-      v6 = this->p3DSamples;
-      while ( 1 )
+      v7 = PID_TYPE(this->p3DSamples[v59].field_4);
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) == AIL::Sample::Done )
       {
-        v7 = PID_TYPE(v6->field_4);
-        if ( AIL_3D_sample_status(v6->hSample) == 2 )
-        {
-          AIL_end_3D_sample(v6->hSample);
-          pAudioPlayer->_4ABF23(v6);
-        }
-        if ( AIL_3D_sample_status(v6->hSample) != 4 )
-          goto LABEL_35;
-        v8 = v7 - 1;//
-        if ( v8 )//> 1
-          break;
-        if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
-          goto LABEL_31;
-        pDoor = &pIndoor->pDoors[PID_ID(v6->field_4)];
-        if ( pDoor->uDoorID )
-        {
-          uNumRepeats = *pDoor->pXOffsets;
-          a1.vWorldPosition.x = (double)uNumRepeats;
-          uNumRepeats = *pDoor->pYOffsets;
-          a1.vWorldPosition.y = (double)uNumRepeats;
-          uNumRepeats = *pDoor->pZOffsets;
-          v11 = (double)uNumRepeats;
-          goto LABEL_21;
-        }
-LABEL_35:
-        ++v59;
-        ++v6;
-        if ( v59 >= pAudioPlayer->uNum3DSamples )
-        {
-          v2 = 0;
-          goto LABEL_37;
-        }
+        AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+        pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
       }
-
-      v9 = v8 - 1;//
-      if ( v9 )//> 2
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) != AIL::Sample::Playing )
+        continue;
+      v8 = v7 - 1;//
+      if ( v8 )//> 1
       {
-        v10 = v9 - 1;//
-        if ( !v10 )//3
-        {
-          v13 = &pActors[PID_ID(v6->field_4)];
-          uNumRepeats = v13->vPosition.x;
-          v14 = v13->vPosition.y;
-          a1.vWorldPosition.x = (double)uNumRepeats;
-          uNumRepeats = v13->vPosition.z;
-          a1.vWorldPosition.y = (double)v14;
-          v11 = (double)uNumRepeats;
-          goto LABEL_21;
-        }
-        if ( v10 != 2 )//4
+        v9 = v8 - 1;//
+        if ( v9 )//> 2
         {
-          a1.vWorldPosition.x = (double)pParty->vPosition.x;
-          a1.vWorldPosition.y = (double)pParty->vPosition.y;
-          v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
-          goto LABEL_21;
-        }//5
-        v12 = (SpriteObject *)&pLevelDecorations[PID_ID(v6->field_4)];
-      }
-      else//2
-      {
-        v12 = &pSpriteObjects[PID_ID(v6->field_4)];
-      }
-      a1.vWorldPosition.x = (double)v12->vPosition.x;
-      a1.vWorldPosition.y = (double)v12->vPosition.y;
-      v11 = (double)v12->vPosition.z;
-LABEL_21:
-      a1.vWorldPosition.z = v11;
-      if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-      {
-        v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-        v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-        v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-        v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-        if (pGame->pIndoorCameraD3D->sRotationX)
+          v10 = v9 - 1;//
+          if ( !v10 )//3
+          {
+            v13 = &pActors[PID_ID(this->p3DSamples[v59].field_4)];
+            //uNumRepeats = v13->vPosition.x;
+            //v14 = v13->vPosition.y;
+            a1.vWorldPosition.x = (double)v13->vPosition.x;
+            //uNumRepeats = v13->vPosition.z;
+            a1.vWorldPosition.y = (double)v13->vPosition.y;
+            //v11 = (double)uNumRepeats;
+            a1.vWorldPosition.z = v13->vPosition.z;
+            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+            {
+              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+              if (pGame->pIndoorCameraD3D->sRotationX)
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+                if ( pRenderer->pRenderD3D )
+                {
+                  v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+                a1.vWorldViewPosition.y = v20;
+                a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+              }
+              else
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                if ( pRenderer->pRenderD3D )
+                {
+                  a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.y = v21;
+                a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+              }
+            }
+            else
+              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+            v58 = a1.vWorldViewPosition.y * -0.012207031;
+            v22 = a1.vWorldViewPosition.x * 0.012207031;
+            *(float *)&uNumRepeats = v22;
+            v23 = abs((signed __int64)v22);
+            v24 = abs(0);
+            v25 = abs((signed __int64)v58);
+            if ( int_get_vector_length(v25, v24, v23) <= 100 )
+            {
+              AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+              v26 = -*(float *)&uNumRepeats;
+              v27 = -v58;
+              AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+            }
+            else
+            {
+              AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+              pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+            }
+            continue;
+          }
+          if ( v10 != 2 )//4
+          {
+            a1.vWorldPosition.x = (double)pParty->vPosition.x;
+            a1.vWorldPosition.y = (double)pParty->vPosition.y;
+            v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
+            a1.vWorldPosition.z = v11;
+            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+            {
+              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+              if (pGame->pIndoorCameraD3D->sRotationX)
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+                if ( pRenderer->pRenderD3D )
+                {
+                  v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+                a1.vWorldViewPosition.y = v20;
+                a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+              }
+              else
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                if ( pRenderer->pRenderD3D )
+                {
+                  a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.y = v21;
+                a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+              }
+            }
+            else
+              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+            v58 = a1.vWorldViewPosition.y * -0.012207031;
+            v22 = a1.vWorldViewPosition.x * 0.012207031;
+            *(float *)&uNumRepeats = v22;
+            v23 = abs((signed __int64)v22);
+            v24 = abs(0);
+            v25 = abs((signed __int64)v58);
+            if ( int_get_vector_length(v25, v24, v23) <= 100 )
+            {
+              AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+              v26 = -*(float *)&uNumRepeats;
+              v27 = -v58;
+              AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+            }
+            else
+            {
+              AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+              pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+            }
+            continue;
+          }//5
+          v12 = (SpriteObject *)&pLevelDecorations[PID_ID(this->p3DSamples[v59].field_4)];
+        }
+        else//2
+          v12 = &pSpriteObjects[PID_ID(this->p3DSamples[v59].field_4)];
+        a1.vWorldPosition.x = (double)v12->vPosition.x;
+        a1.vWorldPosition.y = (double)v12->vPosition.y;
+        v11 = (double)v12->vPosition.z;
+//LABEL_21:
+        a1.vWorldPosition.z = v11;
+        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
         {
-          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-          v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
-          if ( pRenderer->pRenderD3D )
+          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+          if (pGame->pIndoorCameraD3D->sRotationX)
           {
-            v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
-            v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+            if ( pRenderer->pRenderD3D )
+            {
+              v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+            a1.vWorldViewPosition.y = v20;
+            a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
           }
           else
           {
-            v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
-            v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            if ( pRenderer->pRenderD3D )
+            {
+              a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.y = v21;
+            a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
           }
-          a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
-          a1.vWorldViewPosition.y = v20;
-          a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+        }
+        else
+          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
         }
         else
         {
-          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-          if ( pRenderer->pRenderD3D )
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+        }
+        continue;
+      }
+      if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
+      {
+        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+        }
+        else
+        {
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+        }
+        continue;
+      }
+      pDoor = &pIndoor->pDoors[PID_ID(this->p3DSamples[v59].field_4)];
+      if ( pDoor->uDoorID )
+      {
+        uNumRepeats = *pDoor->pXOffsets;
+        a1.vWorldPosition.x = (double)uNumRepeats;
+        uNumRepeats = *pDoor->pYOffsets;
+        a1.vWorldPosition.y = (double)uNumRepeats;
+        uNumRepeats = *pDoor->pZOffsets;
+        v11 = (double)uNumRepeats;
+        a1.vWorldPosition.z = v11;
+        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+        {
+          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+          if (pGame->pIndoorCameraD3D->sRotationX)
           {
-            a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
-            v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+            if ( pRenderer->pRenderD3D )
+            {
+              v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+            a1.vWorldViewPosition.y = v20;
+            a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
           }
           else
           {
-            a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
-            v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            if ( pRenderer->pRenderD3D )
+            {
+              a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.y = v21;
+            a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
           }
-          a1.vWorldViewPosition.y = v21;
-          a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+        }
+        else
+          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+        }
+        else
+        {
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
         }
       }
-      else
-      {
-LABEL_31:
-        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
-      }
-      v58 = a1.vWorldViewPosition.y * -0.012207031;
-      v22 = a1.vWorldViewPosition.x * 0.012207031;
-      *(float *)&uNumRepeats = v22;
-      v23 = abs((signed __int64)v22);
-      v24 = abs(0);
-      v25 = abs((signed __int64)v58);
-      if ( int_get_vector_length(v25, v24, v23) <= 100 )
-      {
-        AIL_set_3D_position(v6->hSample, LODWORD(v58), 0.0, uNumRepeats);
-        v26 = -*(float *)&uNumRepeats;
-        v27 = -v58;
-        AIL_set_3D_orientation(v6->hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
-      }
-      else
-      {
-        AIL_end_3D_sample(v6->hSample);
-        pAudioPlayer->_4ABF23(v6);
-      }
-      goto LABEL_35;
     }
+    //}
   }
 
-LABEL_37:
+//LABEL_37:
   for (uint i = 0; i < uMixerChannels; ++i)
   {
     if (AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Done)
@@ -1630,48 +1930,104 @@
         if (!pIndoor->pDoors[source_id].uDoorID)
           continue;
 
-        source_x = pIndoor->pDoors[source_id].pXOffsets[0];
-        source_y = pIndoor->pDoors[source_id].pYOffsets[0];
-        source_z = pIndoor->pDoors[source_id].pZOffsets[0];
+        //source_x = pIndoor->pDoors[source_id].pXOffsets[0];
+        //source_y = pIndoor->pDoors[source_id].pYOffsets[0];
+        //source_z = pIndoor->pDoors[source_id].pZOffsets[0];
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[source_id].pXOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pYOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pZOffsets[0]);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pIndoor->pDoors[source_id].pXOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pYOffsets[0]));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Item:
       {
         assert(source_id < uNumSpriteObjects);
 
-        source_x = pSpriteObjects[source_id].vPosition.x;
-        source_y = pSpriteObjects[source_id].vPosition.y;
-        source_z = pSpriteObjects[source_id].vPosition.z;
+        //source_x = pSpriteObjects[source_id].vPosition.x;
+        //source_y = pSpriteObjects[source_id].vPosition.y;
+        //source_z = pSpriteObjects[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pSpriteObjects[source_id].vPosition.x,
+                                                                 pSpriteObjects[source_id].vPosition.y,
+                                                                 pSpriteObjects[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pSpriteObjects[source_id].vPosition.x,
+                                                                   pSpriteObjects[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Decoration:
       {
         assert(source_id < uNumLevelDecorations);
 
-        source_x = pLevelDecorations[source_id].vPosition.x;
-        source_y = pLevelDecorations[source_id].vPosition.y;
-        source_z = pLevelDecorations[source_id].vPosition.z;
+        //source_x = pLevelDecorations[source_id].vPosition.x;
+        //source_y = pLevelDecorations[source_id].vPosition.y;
+        //source_z = pLevelDecorations[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pLevelDecorations[source_id].vPosition.x,
+                                                                 pLevelDecorations[source_id].vPosition.y,
+                                                                 pLevelDecorations[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pLevelDecorations[source_id].vPosition.x,
+                                                                   pLevelDecorations[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Actor:
       {
         assert(source_id < uNumActors);
 
-        source_x = pActors[source_id].vPosition.x;
-        source_y = pActors[source_id].vPosition.y;
-        source_z = pActors[source_id].vPosition.z;
+        //source_x = pActors[source_id].vPosition.x;
+        //source_y = pActors[source_id].vPosition.y;
+        //source_z = pActors[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pActors[source_id].vPosition.x,
+                                                                 pActors[source_id].vPosition.y,
+                                                                 pActors[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pActors[source_id].vPosition.x,
+                                                                   pActors[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       default:
         assert(false);
         continue;
     }
 
-    if (int sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z))
+    /*if (int sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z))
     {
       AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
       AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(source_x, source_y));
@@ -1680,16 +2036,13 @@
     {
       AIL_end_sample(pMixerChannels[i].hSample);
       FreeChannel(&pMixerChannels[i]);
-    }
+    } */
   }
 
-
-
-  if (pCurrentScreen != SCREEN_GAME)
+  if (pCurrentScreen != SCREEN_GAME) //     
   {
-    MixerChannel* channel = &pMixerChannels[4];
-    if (AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
-      AIL_end_sample(channel->hSample);
+    if (AIL_sample_status(pMixerChannels[4].hSample) == AIL::Sample::Playing)
+      AIL_end_sample(pMixerChannels[4].hSample);
     return;
   }
   if (!_6807E0_num_decorations_with_sounds_6807B8)
@@ -1699,8 +2052,6 @@
       //v59 = 0;
   for (uint i = 0; i < _6807E0_num_decorations_with_sounds_6807B8; ++i)
   {
-      //while ( 1 )
-      //{
         LODWORD(v56) = 1;
         //v43 = _6807B8_level_decorations_ids[v59];
         //v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]];
@@ -1725,9 +2076,9 @@
         uNumRepeats = 2;
         if (decor->field_1A)
         {
-          v51 = decor->field_1A - 32;
-          decor->field_1A = v51;
-          if ( v51 < 0 )
+          //v51 = decor->field_1A - 32;
+          decor->field_1A = decor->field_1A - 32;
+          if ( decor->field_1A < 0 )
             decor->field_1A = 0;
         }
     }
@@ -1743,7 +2094,7 @@
           {
             v53 = 8 * _6807B8_level_decorations_ids[i];
             LOBYTE(v53) = v53 | OBJECT_Decoration;
-            PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+            PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);// ,  
           }
           continue;
         }
@@ -1799,6 +2150,7 @@
     }
     continue;
   }
+  }
 }
 
 //----- (004AB66C) --------------------------------------------------------
@@ -1835,37 +2187,27 @@
 //----- (004AB71F) --------------------------------------------------------
 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel)
 {
-  int v4; // ecx@1
-  int v9; // [sp+4h] [bp-4h]@3
-
   if ( bPlayerReady )
   {
     if ( b3DSoundInitialized )
     {
-      v9 = 0;
-      if ( uNum3DSamples > 0 )
+      for ( uint i = 0; i < uNum3DSamples; ++i )
       {
-        for ( v4 = 0; v4 < uNum3DSamples; ++v4 )
+        if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
+            && p3DSamples[i].field_8 && pSoundList->pSL_Sounds[p3DSamples[i].field_8].eType != SOUND_DESC_SYSTEM)
         {
-          if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel)
-              && p3DSamples[v4].field_8
-              && pSoundList->pSounds[p3DSamples[v4].field_8].eType != SOUND_DESC_SYSTEM)
-          {
-            AIL_end_3D_sample(p3DSamples[v4].hSample);
-            _4ABF23(&p3DSamples[v4]);
-            p3DSamples[v4].field_4 = 0;
-            v4 = v9;
-          }
-          v9 = v4;
+          AIL_end_3D_sample(p3DSamples[i].hSample);
+          _4ABF23(&p3DSamples[i]);
+          p3DSamples[i].field_4 = 0;
         }
       }
     }
-    if ( hDigDriver && uMixerChannels > 0 )
+    if ( hDigDriver )
     {
       for ( int i = 0; i < uMixerChannels; ++i )
       {
         if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
-          && pSoundList->pSounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
+          && pSoundList->pSL_Sounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)//,   , 
         {
           AIL_end_sample(pMixerChannels[i].hSample);
           FreeChannel(&pMixerChannels[i]);
@@ -1892,7 +2234,7 @@
     return;
   }
 
-  ReadFile(hAudioSnd, &uNumSoundHeaders, 4u, &NumberOfBytesRead, 0);
+  ReadFile(hAudioSnd, &uNumSoundHeaders, 4, &NumberOfBytesRead, 0);
   pSoundHeaders = nullptr;
   pSoundHeaders = (SoundHeader *)malloc(52 * uNumSoundHeaders + 2);
   ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0);
@@ -2184,14 +2526,14 @@
   int num_playing_channels; // [sp+4Ch] [bp-8h]@5
   //int v16; // [sp+50h] [bp-4h]@5
 
-  if (!pSoundList->pSounds)
+  if (!pSoundList->pSL_Sounds)
     return;
  
     //v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx];
-    if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
+    if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
     {
-      if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
-          !(pSoundList->pSounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
+          !(pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) )
       {
         num_playing_channels = 0;
         num_same_sound_on_channels = 0;
@@ -2226,7 +2568,7 @@
 {
   int v2; // ebx@1
   //AudioPlayer *v3; // esi@1
-  SoundDesc *v4; // eax@2
+  //SoundDesc *v4; // eax@2
   unsigned __int8 v5; // zf@5
   unsigned __int8 v6; // sf@5
   char *v7; // edi@6
@@ -2239,14 +2581,12 @@
   int v14; // [sp+4Ch] [bp-8h]@5
   int v15; // [sp+50h] [bp-4h]@5
 
-  v2 = 0;
-  //v3 = this;
-  if ( pSoundList->pSounds )
+  if ( pSoundList->pSL_Sounds )
   {
-    v4 = &pSoundList->pSounds[a2->field_8];
-    if ( v4->eType == SOUND_DESC_SWAP)
+    //v4 = &pSoundList->pSounds[a2->field_8];
+    if ( pSoundList->pSL_Sounds[a2->field_8].eType == SOUND_DESC_SWAP)
     {
-      if ( v4->p3DSound && !(v4->uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSL_Sounds[a2->field_8].p3DSound && !(pSoundList->pSL_Sounds[a2->field_8].uFlags & SOUND_DESC_SYSTEM) )
       {
         v5 = this->uNum3DSamples == 0;
         v6 = this->uNum3DSamples < 0;
@@ -2255,37 +2595,29 @@
         if ( v6 | v5 )
           goto LABEL_16;
         v7 = (char *)this->p3DSamples;
-        do
+        __debugbreak();//Ritor1
+        for ( v2 = 0; v2 < uNum3DSamples; ++v2 )
         {
           if ( a2->field_C == *((int *)v7 + 3) )
           {
             v8 = v15;
-            v9 = *(int *)v7;
+            //v9 = this->p3DSamples[v2];
             ++v15;
             v13[v8] = v2;
-            if ( AIL_3D_sample_status((void *)v9) == 4 )
+            if ( AIL_3D_sample_status(&this->p3DSamples[v2]) == 4 )
               ++v14;
           }
-          ++v2;
           v7 += 16;
         }
-        while ( v2 < uNum3DSamples );
         if ( !v14 )
         {
 LABEL_16:
           pSoundList->UnloadSound(a2->field_8, 1);
-          v10 = 0;
-          if ( v15 > 0 )
+          for ( v10 = 0; v10 < v15; v10++ )
           {
-            do
-            {
-              v11 = v13[v10++];
-              *(&bEAXSupported + 4 * (v11 + 2)) = 0;
-              v12 = __OFSUB__(v10, v15);
-              v6 = v10 - v15 < 0;
-              p3DSamples[v11].field_8 = 0;
-            }
-            while ( v6 ^ v12 );
+            v11 = v13[v10];
+            *(&bEAXSupported + 4 * (v11 + 2)) = 0;
+            p3DSamples[v11].field_8 = 0;
           }
         }
       }
@@ -2345,71 +2677,61 @@
 //----- (004AC0A2) --------------------------------------------------------
 int AudioPlayer::_4AC0A2()
 {
-  AudioPlayer *v1; // esi@1
-  unsigned int v2; // eax@1
-  char v3; // zf@1
-  int v4; // ebx@1
-  int *v5; // edi@2
-  int v6; // eax@4
-  AudioPlayer_3DSample *v8; // ebx@7
+  unsigned int map_id; // eax@1
+  //int v4; // ebx@1
+  //int *v5; // edi@2
+  //int v6; // eax@4
+  //AudioPlayer_3DSample *v8; // ebx@7
   void *v9; // eax@8
-  int v10; // ebx@14
-  unsigned int v11; // eax@14
+  //int v10; // ebx@14
+  //unsigned int v11; // eax@14
   int v12; // [sp+1Ch] [bp-8h]@1
-  int v13; // [sp+20h] [bp-4h]@6
+  //int v13; // [sp+20h] [bp-4h]@6
 
-  v1 = this;
-  v2 = pMapStats->GetMapInfo(pCurrentMapName);
-  v3 = v1->b3DSoundInitialized == 0;
-  v4 = v2;
-  v12 = v2;
-  if ( !v3 )
+  __debugbreak();//Ritor1
+  map_id = pMapStats->GetMapInfo(pCurrentMapName);
+  if ( this->b3DSoundInitialized )
   {
-    v5 = &v1->uNum3DSamples;
-    AIL_3D_provider_attribute(v1->h3DSoundProvider, "Maximum supported samples", &v1->uNum3DSamples);
-    if ( v1->uNum3DSamples > 32 )
-      *v5 = 32;
-    v6 = *v5;
-    if ( !*v5 )
+    //v5 = &this->uNum3DSamples;
+    AIL_3D_provider_attribute(this->h3DSoundProvider, "Maximum supported samples", &this->uNum3DSamples);
+    if ( this->uNum3DSamples > 32 )
+      this->uNum3DSamples = 32;
+    //v6 = this->uNum3DSamples;
+    if ( !this->uNum3DSamples )
     {
-      v1->b3DSoundInitialized = 0;
+      this->b3DSoundInitialized = 0;
       return -1;
     }
-    v13 = 0;
-    if ( v6 > 0 )
-    {
-      v8 = v1->p3DSamples;
-      while ( 1 )
+    //v13 = 0;
+    //if ( this->uNum3DSamples > 0 )
+    //{
+      //v8 = this->p3DSamples;
+      //while ( 1 )
+      for ( uint i = 0; i < this->uNum3DSamples; ++i )
       {
-        v9 = (void *)AIL_allocate_3D_sample_handle(v1->h3DSoundProvider);
-        v8->hSample = v9;
+        v9 = (void *)AIL_allocate_3D_sample_handle(this->h3DSoundProvider);
+        this->p3DSamples[i].hSample = v9;
         if ( !v9 )
-          break;
+          this->uNum3DSamples = i;
         AIL_set_3D_sample_float_distances(v9, 4096.0, 256.0, 4096.0, 256.0);
-        AIL_set_3D_sample_volume(v8->hSample, v1->s3DSoundVolume);
-        ++v13;
-        ++v8;
-        if ( v13 >= *v5 )
-          goto LABEL_12;
+        AIL_set_3D_sample_volume(this->p3DSamples[i].hSample, this->s3DSoundVolume);
+        //++v8;
       }
-      *v5 = v13;
-LABEL_12:
-      v4 = v12;
-    }
-    if ( v1->bEAXSupported )
+    //}
+    if ( this->bEAXSupported )
     {
-      v10 = v4;
-      v11 = pMapStats->pInfos[v10].uEAXEnv;
-      v12 = pMapStats->pInfos[v10].uEAXEnv;
-      if ( v11 >= 0x1A )
+      //v10 = v4;
+      //v11 = pMapStats->pInfos[map_id].uEAXEnv;
+      v12 = pMapStats->pInfos[map_id].uEAXEnv;
+      if ( pMapStats->pInfos[map_id].uEAXEnv >= 0x1A )
       {
         pAudioPlayer->SetEAXPreferences();
-        v1->field_214 = -1;
+        this->field_214 = -1;
       }
       else
       {
-        AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v12);
-        v1->field_214 = v12;
+        AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX environment selection", &v12);
+        this->field_214 = v12;
       }
     }
   }
@@ -2419,7 +2741,8 @@
 //----- (004A96BE) --------------------------------------------------------
 void ReleaseSoundData(void *_this)
 {
-  for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ )
+  //for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ )
+  for ( uint i = 0; i < 2999; i++ )
   {
     if ( pSounds[i].pSoundData == _this )
     {
@@ -2519,7 +2842,7 @@
     pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
     if ( pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize )
     {
-      ReadFile(pAudioPlayer->hAudioSnd, (char *)pOutBuff + 4, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, &NumberOfBytesRead, 0);
+      ReadFile(pAudioPlayer->hAudioSnd, pOutBuff->pData, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize + 7, &NumberOfBytesRead, 0);// Ritor1: include +7 for pSounds[20]
     }
     else
     {
@@ -2530,12 +2853,12 @@
   {
     uID = (unsigned int)malloc(pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
     ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize, &NumberOfBytesRead, 0);
-    zlib::MemUnzip((char *)pOutBuff + 4, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
+    zlib::MemUnzip(pOutBuff->pData, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
     free((void *)uID);
   }
   if ( pOutBuff )
   {
-    *(int *)pOutBuff = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
+    pOutBuff->uDataSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
     uLastLoadedSoundID = 0;
     if ( pSounds[0].pSoundData )
     {