// File: /workspace/github_c_makefile_star2_O2/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 0x14558(%rip), %eax     # 0x18508
incl %eax
movl %eax, 0x14550(%rip)     # 0x18508
movl %eax, %ecx
subl 0xb270(%rip), %ecx      # 0xf230
jl 0x3fca
movl %ecx, 0x14540(%rip)     # 0x18508
movl %ecx, %eax
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x0, 0x14484(%rip)     # 0x18460
cltq
leaq 0x1449b(%rip), %rsi     # 0x18480
je 0x40ae
movq 0x1448e(%rip), %rcx     # 0x18480
movzbl 0x1447f(%rip), %edx     # 0x18478
shll $0xc, %edx
leaq (%rcx,%rdx), %r15
movq %rsi, %r12
movq (%rsi,%rax,8), %rbx
movslq 0x14462(%rip), %rax     # 0x18470
movq %rbx, %rsi
subq %rax, %rsi
xorl %edi, %edi
cmpq %rcx, %rsi
cmovbq %rdx, %rdi
addq %rsi, %rdi
movl 0xb20d(%rip), %r14d     # 0xf234
testl %r14d, %r14d
je 0x40d4
movl %r14d, %eax
addq %rdi, %rax
movl %r15d, %ebp
subl %edi, %ebp
cmpq %r15, %rax
cmovbel %r14d, %ebp
cmpl $0x10, 0xb1df(%rip)     # 0xf228
movq 0x14418(%rip), %rdx     # 0x18468
jne 0x4065
movl %ebp, %ecx
shrl %ecx
testq %rdx, %rdx
je 0x4076
movq %rbx, %rsi
callq 0x58f3
jmp 0x409a
testq %rdx, %rdx
je 0x408a
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x592c
jmp 0x409a
movl 0x143e4(%rip), %eax     # 0x18460
movq %rbx, %rsi
movl %ecx, %edx
movl %eax, %ecx
callq 0x5949
jmp 0x409a
movl 0x143d0(%rip), %ecx     # 0x18460
movq %rbx, %rsi
movl %ebp, %edx
callq 0x5962
movq 0x143df(%rip), %rdi     # 0x18480
movl %ebp, %eax
addq %rax, %rbx
subl %ebp, %r14d
jmp 0x4027
movq %rsi, %r12
movq (%rsi,%rax,8), %rdi
xorl %eax, %eax
cmpb $0x0, 0x143b6(%rip)     # 0x18474
movl $0x80808080, %esi       # imm = 0x80808080
cmovnel %eax, %esi
movl 0xb168(%rip), %edx      # 0xf234
shrl $0x2, %edx
callq 0x53ac
movq 0xb20d(%rip), %r14      # 0xf2e8
leaq 0xb206(%rip), %r15      # 0xf2e8
cmpq %r15, %r14
je 0x425a
movq %r14, %rbx
cmpl $0x0, 0x74(%r14)
je 0x40fa
movq (%rbx), %r14
jmp 0x40e2
movslq 0x14407(%rip), %r14     # 0x18508
cmpl $0x0, 0x60(%rbx)
jne 0x4116
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x41ff
movl 0x50(%rbx), %r13d
movq (%r12,%r14,8), %rax
movq %rax, 0x14403(%rip)     # 0x18528
movq 0x90(%rbx), %rdx
movq %rdx, 0x13315(%rip)     # 0x17448
movq 0x98(%rbx), %rcx
movq %rcx, 0x132ff(%rip)     # 0x17440
cmpl $0x2, 0xb0e4(%rip)      # 0xf22c
sete %sil
leaq 0xb2ed(%rip), %rdi      # 0xf440
cmpq %rdi, %rdx
sete %dl
andb %sil, %dl
cmpb $0x1, %dl
jne 0x4179
movq %rcx, 0x132e0(%rip)     # 0x17448
movslq 0x1430d(%rip), %rcx     # 0x1847c
addq %rcx, %rax
movq %rax, 0x143af(%rip)     # 0x18528
movl $0x100, %r14d           # imm = 0x100
testl %r14d, %r14d
jle 0x41ff
movq 0x58(%rbx), %rcx
movl 0x68(%rbx), %esi
movl 0x6c(%rbx), %edi
leal (%rdi,%r13), %eax
movl 0x60(%rbx), %r8d
movl %r14d, %ebp
cmpl %r8d, %eax
jb 0x41b5
cmpl %r8d, %edi
jae 0x41f9
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 0x41c9
movq %rcx, %rdx
movl %ebp, %ecx
callq *%rax
movl 0x60(%rbx), %r8d
movl 0x14361(%rip), %eax     # 0x18530
movl %eax, 0x6c(%rbx)
subl %ebp, %r14d
cmpl %r8d, %eax
jb 0x417f
movq %rbx, %rdi
callq *0x18(%rbx)
cmpl $0x1, %eax
jne 0x41ff
movsbl 0x15(%rbx), %ecx
movl %r14d, %eax
subl %ecx, %eax
jl 0x417f
imull 0x68(%rbx), %eax
movl %eax, %r13d
jmp 0x417f
movq %rbx, %rdi
callq *0x18(%rbx)
movq (%rbx), %r14
cmpl $0x0, 0x70(%rbx)
jne 0x40e2
movq 0x8(%rbx), %rax
movq %r14, (%rax)
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %rbx, 0x8(%rbx)
leaq 0xb173(%rip), %rax      # 0xf398
movq %rax, (%rbx)
movq 0xb171(%rip), %rax      # 0xf3a0
movq %rax, 0x8(%rbx)
movq %rbx, (%rax)
movq %rbx, 0xb163(%rip)      # 0xf3a0
movq 0xb14c(%rip), %rax      # 0xf390
testq %rax, %rax
je 0x40e2
movl 0xa0(%rbx), %edi
callq *%rax
jmp 0x40e2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq