// File: /workspace/github_c_makefile_star2_O1/jonof[P]jfaudiolib/src/multivoc.c
// Function: MV_ServiceVoc
static void MV_ServiceVoc
   (
   void
   )

   {
   VoiceNode *voice;
   VoiceNode *next;
   //int        flags;

   // Toggle which buffer we'll mix next
   MV_MixPage++;
   if ( MV_MixPage >= MV_NumberOfBuffers )
      {
      MV_MixPage -= MV_NumberOfBuffers;
      }

   if ( MV_ReverbLevel == 0 )
      {
      // Initialize buffer
      //Commented out so that the buffer is always cleared.
      //This is so the guys at Echo Speech can mix into the
      //buffer even when no sounds are playing.
      //if ( !MV_BufferEmpty[ MV_MixPage ] )
         {
         ClearBuffer_DW( MV_MixBuffer[ MV_MixPage ], MV_Silence, MV_BufferSize >> 2 );
         MV_BufferEmpty[ MV_MixPage ] = TRUE;
         }
      }
   else
      {
      char *end;
      char *source;
      char *dest;
      unsigned int   count;
      unsigned int   length;

      end = MV_MixBuffer[ 0 ] + MV_BufferLength;;
      dest = MV_MixBuffer[ MV_MixPage ];
      source = MV_MixBuffer[ MV_MixPage ] - MV_ReverbDelay;
      if ( source < MV_MixBuffer[ 0 ] )
         {
         source += MV_BufferLength;
         }

      length = MV_BufferSize;
      while( length > 0 )
         {
         count = length;
         if ( source + count > end )
            {
            count = (unsigned int)(end - source);
            }

         if ( MV_Bits == 16 )
            {
            if ( MV_ReverbTable != NULL )
               {
               MV_16BitReverb( source, dest, MV_ReverbTable, count / 2 );
               }
            else
               {
               MV_16BitReverbFast( source, dest, count / 2, MV_ReverbLevel );
               }
            }
         else
            {
            if ( MV_ReverbTable != NULL )
               {
               MV_8BitReverb( (signed char *) source, (signed char *) dest, MV_ReverbTable, count );
               }
            else
               {
               MV_8BitReverbFast( (signed char *) source, (signed char *) dest, count, MV_ReverbLevel );
               }
            }

         // if we go through the loop again, it means that we've wrapped around the buffer
         source  = MV_MixBuffer[ 0 ];
         dest   += count;
         length -= count;
         }
      }

   // Play any waiting voices
   //flags = DisableInterrupts();

   for( voice = VoiceList.next; voice != &VoiceList; voice = next )
      {
      if ( voice->Paused )
         {
         next = voice->next;
         continue;
         }

      MV_BufferEmpty[ MV_MixPage ] = FALSE;

      MV_MixFunction( voice, MV_MixPage );

      next = voice->next;

      // Is this voice done?
      if ( !voice->Playing )
         {
         //JBF: prevent a deadlock caused by MV_StopVoice grabbing the mutex again
         //MV_StopVoice( voice );
         LL_Remove( voice, next, prev );
         LL_Add( (VoiceNode*) &VoicePool, voice, next, prev );

         if ( MV_CallBackFunc )
            {
            MV_CallBackFunc( voice->callbackval );
            }
         }
      }

   //RestoreInterrupts(flags);
   }

// Assembly:
movl 0x15338(%rip), %eax     # 0x194f8
incl %eax
movl %eax, 0x15330(%rip)     # 0x194f8
subl 0xc052(%rip), %eax      # 0x10220
jl 0x41d6
movl %eax, 0x15322(%rip)     # 0x194f8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x0, 0x15268(%rip)     # 0x19450
je 0x42bb
movl 0xc02f(%rip), %r14d     # 0x10224
testl %r14d, %r14d
je 0x42ec
movq 0x1526b(%rip), %rax     # 0x19470
movzbl 0x1525c(%rip), %ecx     # 0x19468
shll $0xc, %ecx
leaq (%rax,%rcx), %r15
movslq 0x152de(%rip), %rdx     # 0x194f8
leaq 0x1524f(%rip), %rsi     # 0x19470
movq (%rsi,%rdx,8), %rbx
movslq 0x15234(%rip), %rdx     # 0x19460
movq %rbx, %rsi
subq %rdx, %rsi
xorl %edi, %edi
cmpq %rax, %rsi
cmovbq %rcx, %rdi
addq %rsi, %rdi
movl %r14d, %eax
addq %rdi, %rax
movl %r15d, %ebp
subl %edi, %ebp
cmpq %r15, %rax
cmovbel %r14d, %ebp
cmpl $0x10, 0xbfc1(%rip)     # 0x10218
movq 0x151fa(%rip), %rdx     # 0x19458
jne 0x4273
movl %ebp, %ecx
shrl %ecx
testq %rdx, %rdx
je 0x4284
movq %rbx, %rsi
callq 0x5d1c
jmp 0x42a8
testq %rdx, %rdx
je 0x4298
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x5d55
jmp 0x42a8
movl 0x151c6(%rip), %eax     # 0x19450
movq %rbx, %rsi
movl %ecx, %edx
movl %eax, %ecx
callq 0x5d72
jmp 0x42a8
movl 0x151b2(%rip), %ecx     # 0x19450
movq %rbx, %rsi
movl %ebp, %edx
callq 0x5d8b
movq 0x151c1(%rip), %rdi     # 0x19470
movl %ebp, %eax
addq %rax, %rbx
subl %ebp, %r14d
jne 0x423e
jmp 0x42ec
movslq 0x15236(%rip), %rax     # 0x194f8
leaq 0x151a7(%rip), %rcx     # 0x19470
movq (%rcx,%rax,8), %rdi
xorl %eax, %eax
cmpb $0x0, 0x1518e(%rip)     # 0x19464
movl $0x80808080, %esi       # imm = 0x80808080
cmovnel %eax, %esi
movl 0xbf40(%rip), %edx      # 0x10224
shrl $0x2, %edx
callq 0x5774
movq 0xbfe5(%rip), %rbx      # 0x102d8
leaq 0xbfde(%rip), %r14      # 0x102d8
cmpq %r14, %rbx
je 0x446a
leaq 0x15166(%rip), %r15     # 0x19470
cmpl $0x0, 0x74(%rbx)
je 0x4318
movq (%rbx), %r12
jmp 0x445e
movslq 0x151d9(%rip), %r12     # 0x194f8
cmpl $0x0, 0x60(%rbx)
jne 0x4334
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x4409
movl 0x50(%rbx), %r13d
movq (%r15,%r12,8), %rax
movq %rax, 0x151d5(%rip)     # 0x19518
movq 0x90(%rbx), %rdx
movq %rdx, 0x140e7(%rip)     # 0x18438
movq 0x98(%rbx), %rcx
movq %rcx, 0x140d1(%rip)     # 0x18430
cmpl $0x2, 0xbeb6(%rip)      # 0x1021c
jne 0x438c
leaq 0xc0c1(%rip), %rsi      # 0x10430
cmpq %rsi, %rdx
jne 0x438c
movq %rcx, 0x140bd(%rip)     # 0x18438
movslq 0x150ea(%rip), %rcx     # 0x1946c
addq %rcx, %rax
movq %rax, 0x1518c(%rip)     # 0x19518
movl $0x100, %r12d           # imm = 0x100
movq 0x58(%rbx), %rcx
movl 0x68(%rbx), %esi
movl 0x6c(%rbx), %edi
leal (%rdi,%r13), %edx
movl 0x60(%rbx), %eax
movl %r12d, %ebp
cmpl %eax, %edx
jb 0x43be
cmpl %eax, %edi
jae 0x4403
movsbl 0x15(%rbx), %edx
addl %esi, %eax
addl %edi, %edx
subl %edx, %eax
xorl %edx, %edx
divl %esi
movl %eax, %ebp
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x43ce
movq %rcx, %rdx
movl %ebp, %ecx
callq *%rax
movl 0x1514c(%rip), %eax     # 0x19520
movl %eax, 0x6c(%rbx)
subl %ebp, %r12d
cmpl 0x60(%rbx), %eax
jb 0x43fc
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x4409
movsbl 0x15(%rbx), %ecx
movl %r12d, %eax
subl %ecx, %eax
jl 0x43fc
imull 0x68(%rbx), %eax
movl %eax, %r13d
testl %r12d, %r12d
jg 0x4392
jmp 0x4409
movq %rbx, %rdi
callq *0x18(%rbx)
movq (%rbx), %r12
cmpl $0x0, 0x70(%rbx)
jne 0x445e
movq 0x8(%rbx), %rax
movq %r12, (%rax)
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %rbx, 0x8(%rbx)
leaq 0xbf5d(%rip), %rax      # 0x10388
movq %rax, (%rbx)
movq 0xbf5b(%rip), %rax      # 0x10390
movq %rax, 0x8(%rbx)
movq 0xbf50(%rip), %rax      # 0x10390
movq %rbx, (%rax)
movq %rbx, 0xbf46(%rip)      # 0x10390
movq 0xbf2f(%rip), %rax      # 0x10380
testq %rax, %rax
je 0x445e
movl 0xa0(%rbx), %edi
callq *%rax
movq %r12, %rbx
cmpq %r14, %r12
jne 0x430a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq