diff AudioPlayer.cpp @ 2085:52abdea20b9e

Door_switch_animation
author Ritor1
date Wed, 11 Dec 2013 23:12:54 +0600
parents 28cb79ae2f6f
children 9574c5bfb96f
line wrap: on
line diff
--- a/AudioPlayer.cpp	Tue Dec 03 16:35:57 2013 +0600
+++ b/AudioPlayer.cpp	Wed Dec 11 23:12:54 2013 +0600
@@ -321,30 +321,17 @@
 //----- (004A9D79) --------------------------------------------------------
 void SoundList::_4A9D79(int a2)
 {
-  SoundList *v2; // esi@1
-  int v3; // edi@1
-  signed int i; // ebx@1
-  SoundDesc *v5; // eax@2
-  SOUND_DESC_TYPE v6; // ecx@2
-  void *v7; // eax@5
-
-  v2 = this;
-  v3 = 0;
-  for ( i = 0; i < (signed int)v2->sNumSounds; ++v3 )
+  for ( int i = 0; i < (signed int)this->sNumSounds; ++i )
   {
-    v5 = &v2->pSounds[v3];
-    v6 = v5->eType;
-    if ( v6 != SOUND_DESC_SYSTEM && (a2 || v6 != SOUND_DESC_LOCK) )
+    if ( this->pSounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSounds[i].eType != SOUND_DESC_LOCK) )
     {
-      v7 = v5->pSoundData[0];
-      if ( v7 )
+      if ( this->pSounds[i].pSoundData[0] )
       {
-        ReleaseSoundData(v7);
-        v2->pSounds[v3].pSoundData[0] = 0;
+        ReleaseSoundData(this->pSounds[i].pSoundData[0]);
+        this->pSounds[i].pSoundData[0] = 0;
       }
-      v2->pSounds[v3].uFlags &= ~SOUND_DESC_SYSTEM;
+      this->pSounds[i].uFlags &= ~SOUND_DESC_SYSTEM;
     }
-    ++i;
   }
 }
 
@@ -373,19 +360,15 @@
 //----- (004A9E3D) --------------------------------------------------------
 void SoundList::ToFile()
 {
-  SoundList *v1; // esi@1
   FILE *v2; // eax@1
-  FILE *v3; // edi@1
 
-  v1 = this;
   v2 = fopen("data\\dsounds.bin", "wb");
-  v3 = v2;
   if ( !v2 )
     Error("Unable to save dsounds.bin!");
 
-  fwrite(v1, 4u, 1u, v2);
-  fwrite(v1->pSounds, 0x78u, v1->sNumSounds, v3);
-  fclose(v3);
+  fwrite(this, 4, 1, v2);
+  fwrite(this->pSounds, 0x78u, this->sNumSounds, v2);
+  fclose(v2);
 }
 
 //----- (004A9E89) --------------------------------------------------------
@@ -415,7 +398,6 @@
 //----- (004A9ED0) --------------------------------------------------------
 int SoundList::FromFileTxt(const char *Args)
 {
-  SoundList *v2; // ebx@1
   __int32 v3; // edi@1
   FILE *v4; // eax@1
   unsigned int v5; // esi@3
@@ -435,11 +417,10 @@
   FILE *File; // [sp+2F8h] [bp-4h]@1
   unsigned int Argsa; // [sp+304h] [bp+8h]@3
 
-  v2 = this;
   free(this->pSounds);
   v3 = 0;
-  v2->pSounds = 0;
-  v2->sNumSounds = 0;
+  this->pSounds = 0;
+  this->sNumSounds = 0;
   v4 = fopen(Args, "r");
   File = v4;
   if ( !v4 )
@@ -460,15 +441,15 @@
     v5 = Argsa;
     v3 = 0;
   }
-  v2->sNumSounds = v5;
+  this->sNumSounds = v5;
   v6 = malloc(120 * v5);
-  v2->pSounds = (SoundDesc *)v6;
+  this->pSounds = (SoundDesc *)v6;
   if ( v6 == (void *)v3 )
     Error("SoundListClass::load - Out of Memory!");
 
-  memset(v6, v3, 120 * v2->sNumSounds);
+  memset(v6, v3, 120 * this->sNumSounds);
   v7 = File;
-  v2->sNumSounds = v3;
+  this->sNumSounds = v3;
   fseek(v7, v3, v3);
   for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
   {
@@ -476,38 +457,34 @@
     memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19));
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
-      sprintf(v2->pSounds[v2->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
+      sprintf(this->pSounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
       v9 = atoi(v19.pProperties[1]);
       v10 = v19.pProperties[2];
-      v2->pSounds[v2->sNumSounds].uSoundID = v9;
+      this->pSounds[this->sNumSounds].uSoundID = v9;
       if ( _stricmp(v10, "system") )
       {
         if ( _stricmp(v19.pProperties[2], "swap") )
         {
           v11 = _stricmp(v19.pProperties[2], "lock");
-          v12 = v2->pSounds;
+          v12 = this->pSounds;
           v13 = v11 == 0;
-          v14 = v2->sNumSounds;
+          v14 = this->sNumSounds;
           if ( v13 )
             v12[v14].eType = SOUND_DESC_LOCK;
           else
             v12[v14].eType = SOUND_DESC_LEVEL;
         }
         else
-        {
-          v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SWAP;
-        }
+          this->pSounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
       }
       else
-      {
-        v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SYSTEM;
-      }
+        this->pSounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
       if ( v19.uPropCount >= 4 && !_stricmp(v19.pProperties[3], "3D") )
       {
-        v15 = (int)&v2->pSounds[v2->sNumSounds].uFlags;
+        v15 = (int)&this->pSounds[this->sNumSounds].uFlags;
         *(int *)v15 |= SOUND_DESC_SWAP;
       }
-      ++v2->sNumSounds;
+      ++this->sNumSounds;
     }
   }
   fclose(File);
@@ -721,22 +698,42 @@
 
   int start_channel = 0,
       end_channel = 0;
-
+v62 = start_channel;
   assert(sound_id < pSoundList->sNumSounds);
-  SoundDesc* sound_desc = pSoundList->pSounds + sound_id;
+  SoundDesc* sound_desc = &pSoundList->pSounds[sound_id];
   if (!b3DSoundInitialized || sound_desc->Is3D())
   {
     if (!a3)  // generic sound like from UI
     {
       start_channel = 10;
       end_channel = 12;
-      goto LABEL_133;
+      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      {
+        MixerChannel* channel = pMixerChannels + v62;
+        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+        {
+          AIL_end_sample(channel->hSample);
+          if (channel->uSourceTrackIdx)
+            FreeChannel(channel);
+          break;
+        }
+      }
     }
     else if (a3 == -1)  // exclusive sounds - can override
     {
       start_channel = 13;
       end_channel = 13;
-      goto LABEL_133;
+      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      {
+        MixerChannel* channel = pMixerChannels + v62;
+        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+        {
+          AIL_end_sample(channel->hSample);
+          if (channel->uSourceTrackIdx)
+            FreeChannel(channel);
+          break;
+        }
+      }
     }
     else
     {
@@ -744,7 +741,17 @@
       {
         start_channel = 14;
         end_channel = 14;
-        goto LABEL_123;
+        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
       {
@@ -757,7 +764,17 @@
           {
             start_channel = 10;
             end_channel = 12;
-            goto LABEL_133;
+            for (v62 = start_channel; v62 <= end_channel; ++v62)
+            {
+              MixerChannel* channel = pMixerChannels + v62;
+              if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+              {
+                AIL_end_sample(channel->hSample);
+                if (channel->uSourceTrackIdx)
+                  FreeChannel(channel);
+                break;
+              }
+            }
           }
           break;
 
@@ -772,8 +789,19 @@
             sample_volume = GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z);
             if (!sample_volume)
               return;
-            goto LABEL_123;
+            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);
+              }
+            }
           }
+          break;
 
           case OBJECT_Decoration:
           {
@@ -786,7 +814,17 @@
             sample_volume = GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z);
             if (!sample_volume)
               return;
-            goto LABEL_123;
+            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);
+              }
+            }
           }
           break;
 
@@ -801,7 +839,17 @@
             sample_volume = GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z);
             if (!sample_volume)
               return;
-            goto LABEL_123;
+            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);
+              }
+            }
           }
           break;
 
@@ -809,7 +857,17 @@
           {
             start_channel = 8;
             end_channel = 9;
-            goto LABEL_123;
+            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);
+              }
+            }
           }
           break;
 
@@ -818,33 +876,6 @@
         }
       }
     }
-LABEL_123:
-    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);
-      }
-    }
-LABEL_133:
-      v62 = start_channel;
-      //pAudioPlayer4 = pAudioPlayer;
-      for (v62 = start_channel; v62 <= end_channel; ++v62)
-      {
-        MixerChannel* channel = pMixerChannels + v62;
-        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
-        {
-          AIL_end_sample(channel->hSample);
-          if (channel->uSourceTrackIdx)
-            FreeChannel(channel);
-          break;
-        }
-      }
       /*if ( start_channel <= end_channel)
       {
         pMixerChannel2 = &pAudioPlayer->pMixerChannels[start_channel];
@@ -861,9 +892,9 @@
       }
 LABEL_140:*/
 
-      if (v62 > end_channel)  // no free channel - occupy the quitest one
+      if (start_channel > end_channel)  // no free channel - occupy the quitest one
       {
-        v62 = -1;
+        start_channel = -1;
 
         int min_volume = sample_volume;
         for (uint i = start_channel; i <= end_channel; ++i)
@@ -874,7 +905,7 @@
           if (volume < min_volume)
           {
             min_volume = volume;
-            v62 = i;
+            start_channel = i;
           }
         }
         /*v65 = start_channel;
@@ -1804,12 +1835,7 @@
 //----- (004AB71F) --------------------------------------------------------
 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel)
 {
-  //AudioPlayer *v3; // esi@1
   int v4; // ecx@1
-  //AudioPlayer_3DSample *v5; // edi@4
-  int v6; // ebx@12
-  MixerChannel *pChannel; // edi@14
-  //_STREAM *v8; // esi@23
   int v9; // [sp+4h] [bp-4h]@3
 
   if ( bPlayerReady )
@@ -1819,41 +1845,36 @@
       v9 = 0;
       if ( uNum3DSamples > 0 )
       {
-        //v5 = p3DSamples;//;(char *)&p3DSamples[0].field_8;
         for ( v4 = 0; v4 < uNum3DSamples; ++v4 )
         {
           if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel)
-			  && p3DSamples[v4].field_8
-			  && pSoundList->pSounds[p3DSamples[v4].field_8].eType != SOUND_DESC_SYSTEM)
+              && 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;
           }
-          //v5 += 16;
           v9 = v4;
         }
       }
     }
     if ( hDigDriver && uMixerChannels > 0 )
     {
-      pChannel = pMixerChannels;
-      for ( v6 = 0; v6 < uMixerChannels; ++v6 )
+      for ( int i = 0; i < uMixerChannels; ++i )
       {
-        if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel)
-          && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
+        if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
+          && pSoundList->pSounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
         {
-          AIL_end_sample(pChannel->hSample);
-          FreeChannel(pChannel);
-          pChannel->source_pid = 0;
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+          pMixerChannels[i].source_pid = 0;
         }
-        ++pChannel;
       }
     }
     if (hSequence)
       AIL_end_sequence(hSequence);
-    //v8 = hStream;
     if (hStream)
       AIL_pause_stream(hStream, 1);
   }
@@ -1886,7 +1907,7 @@
   char v5; // dl@5
   _PROVIDER *v6; // eax@9
   //HWND v7; // ST00_4@9
-  MixerChannel *pChannel; // edi@14
+  //MixerChannel *pChannel; // edi@14
   _SAMPLE *v9; // eax@15
   //_REDBOOK *v10; // eax@19
   //int v11; // ecx@21
@@ -1954,19 +1975,11 @@
       }
     }
   }
-  if ( uMixerChannels > 0 )
+  for ( v3; v3 < uMixerChannels; ++v3 )
   {
-    pChannel = pMixerChannels;
-    do
-    {
-      v9 = AIL_allocate_sample_handle(hDigDriver);
-      pChannel->hSample = v9;
-      if ( !v9 )
-        break;
-      ++v3;
-      ++pChannel;
-    }
-    while ( v3 < uMixerChannels );
+    pMixerChannels[v3].hSample = AIL_allocate_sample_handle(hDigDriver);
+    if ( !pMixerChannels[v3].hSample )
+      break;
   }
   uMixerChannels = v3;
   if ( bPlayerReady )
@@ -2197,19 +2210,11 @@
         {
 LABEL_16:
           pSoundList->UnloadSound(pChannel->uSourceTrackIdx, 1);
-          v10 = 0;
-          if ( num_same_sound_on_channels  > 0 )
+          for ( v10 = 0; v10 < num_same_sound_on_channels; v10++ )
           {
-            do
-            {
-              v11 = v14[v10];
-              v12 = 16 * (v14[v10++] + 47);
-              pMixerChannels[v11].uSourceTrackID = 0;
-              //v13 = __OFSUB__(v10, num_same_sound_on_channels);
-              //v6 = v10 - num_same_sound_on_channels < 0;
-              *(unsigned int *)((char *)&bEAXSupported + v12) = 0;
-            }
-            while (v10 < num_same_sound_on_channels);
+            v12 = 16 * (v14[v10] + 47);
+            pMixerChannels[v14[v10]].uSourceTrackID = 0;
+            *(unsigned int *)((char *)&bEAXSupported + v12) = 0;
           }
         }
       }