// File: /workspace/github_c_makefile_star2_O3/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 0x1534a(%rip), %eax     # 0x194f8
incl %eax
movl %eax, 0x15342(%rip)     # 0x194f8
movl %eax, %ecx
subl 0xc062(%rip), %ecx      # 0x10220
jl 0x41c8
movl %ecx, 0x15332(%rip)     # 0x194f8
movl %ecx, %eax
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x0, 0x15276(%rip)     # 0x19450
je 0x42a8
movl 0xc03d(%rip), %r14d     # 0x10224
testl %r14d, %r14d
je 0x42d4
movq 0x15279(%rip), %rcx     # 0x19470
movzbl 0x1526a(%rip), %edx     # 0x19468
shll $0xc, %edx
leaq (%rcx,%rdx), %r15
cltq
leaq 0x15262(%rip), %rsi     # 0x19470
movq (%rsi,%rax,8), %rbx
movslq 0x15247(%rip), %rax     # 0x19460
movq %rbx, %rsi
subq %rax, %rsi
xorl %edi, %edi
cmpq %rcx, %rsi
cmovbq %rdx, %rdi
addq %rsi, %rdi
movl %r14d, %eax
addq %rdi, %rax
movl %r15d, %ebp
subl %edi, %ebp
cmpq %r15, %rax
cmovbel %r14d, %ebp
cmpl $0x10, 0xbfd4(%rip)     # 0x10218
movq 0x1520d(%rip), %rdx     # 0x19458
jne 0x4260
movl %ebp, %ecx
shrl %ecx
testq %rdx, %rdx
je 0x4271
movq %rbx, %rsi
callq 0x5db2
jmp 0x4295
testq %rdx, %rdx
je 0x4285
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x5deb
jmp 0x4295
movl 0x151d9(%rip), %eax     # 0x19450
movq %rbx, %rsi
movl %ecx, %edx
movl %eax, %ecx
callq 0x5e08
jmp 0x4295
movl 0x151c5(%rip), %ecx     # 0x19450
movq %rbx, %rsi
movl %ebp, %edx
callq 0x5e21
movq 0x151d4(%rip), %rdi     # 0x19470
movl %ebp, %eax
addq %rax, %rbx
subl %ebp, %r14d
jne 0x422b
jmp 0x42d4
cltq
leaq 0x151bf(%rip), %rcx     # 0x19470
movq (%rcx,%rax,8), %rdi
xorl %eax, %eax
cmpb $0x0, 0x151a6(%rip)     # 0x19464
movl $0x80808080, %esi       # imm = 0x80808080
cmovnel %eax, %esi
movl 0xbf58(%rip), %edx      # 0x10224
shrl $0x2, %edx
callq 0x572c
movq 0xbffd(%rip), %rbx      # 0x102d8
leaq 0xbff6(%rip), %r14      # 0x102d8
cmpq %r14, %rbx
je 0x4454
leaq 0x1517e(%rip), %r15     # 0x19470
cmpl $0x0, 0x74(%rbx)
je 0x4300
movq (%rbx), %r12
jmp 0x4448
movslq 0x151f1(%rip), %r12     # 0x194f8
cmpl $0x0, 0x60(%rbx)
jne 0x431c
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x43fa
movl 0x50(%rbx), %r13d
movq (%r15,%r12,8), %rax
movq %rax, 0x151ed(%rip)     # 0x19518
movq 0x90(%rbx), %rdx
movq %rdx, 0x140ff(%rip)     # 0x18438
movq 0x98(%rbx), %rcx
movq %rcx, 0x140e9(%rip)     # 0x18430
cmpl $0x2, 0xbece(%rip)      # 0x1021c
jne 0x4374
leaq 0xc0d9(%rip), %rsi      # 0x10430
cmpq %rsi, %rdx
jne 0x4374
movq %rcx, 0x140d5(%rip)     # 0x18438
movslq 0x15102(%rip), %rcx     # 0x1946c
addq %rcx, %rax
movq %rax, 0x151a4(%rip)     # 0x19518
movl $0x100, %r12d           # imm = 0x100
movq 0x58(%rbx), %rcx
movl 0x68(%rbx), %esi
movl 0x6c(%rbx), %edi
leal (%rdi,%r13), %eax
movl 0x60(%rbx), %r8d
movl %r12d, %ebp
cmpl %r8d, %eax
jb 0x43ab
cmpl %r8d, %edi
jae 0x43f4
movsbl 0x15(%rbx), %edx
leal (%rsi,%r8), %eax
addl %edi, %edx
subl %edx, %eax
xorl %edx, %edx
divl %esi
movl %eax, %ebp
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x43bf
movq %rcx, %rdx
movl %ebp, %ecx
callq *%rax
movl 0x60(%rbx), %r8d
movl 0x1515b(%rip), %eax     # 0x19520
movl %eax, 0x6c(%rbx)
subl %ebp, %r12d
cmpl %r8d, %eax
jb 0x43ed
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x43fa
movsbl 0x15(%rbx), %ecx
movl %r12d, %eax
subl %ecx, %eax
jl 0x43ed
imull 0x68(%rbx), %eax
movl %eax, %r13d
testl %r12d, %r12d
jg 0x437a
jmp 0x43fa
movq %rbx, %rdi
callq *0x18(%rbx)
movq (%rbx), %r12
cmpl $0x0, 0x70(%rbx)
jne 0x4448
movq 0x8(%rbx), %rax
movq %r12, (%rax)
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %rbx, 0x8(%rbx)
leaq 0xbf6c(%rip), %rax      # 0x10388
movq %rax, (%rbx)
movq 0xbf6a(%rip), %rax      # 0x10390
movq %rax, 0x8(%rbx)
movq %rbx, (%rax)
movq %rbx, 0xbf5c(%rip)      # 0x10390
movq 0xbf45(%rip), %rax      # 0x10380
testq %rax, %rax
je 0x4448
movl 0xa0(%rbx), %edi
callq *%rax
movq %r12, %rbx
cmpq %r14, %r12
jne 0x42f2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq