// File: tobias93[P]piano/rtaudio/tests/duplex.cpp
// Function: main
int main( int argc, char *argv[] )
{
  unsigned int channels, fs, bufferBytes, oDevice = 0, iDevice = 0, iOffset = 0, oOffset = 0;

  // Minimal command-line checking
  if (argc < 3 || argc > 7 ) usage();

  RtAudio adac;
  if ( adac.getDeviceCount() < 1 ) {
    std::cout << "\nNo audio devices found!\n";
    exit( 1 );
  }

  channels = (unsigned int) atoi(argv[1]);
  fs = (unsigned int) atoi(argv[2]);
  if ( argc > 3 )
    iDevice = (unsigned int) atoi(argv[3]);
  if ( argc > 4 )
    oDevice = (unsigned int) atoi(argv[4]);
  if ( argc > 5 )
    iOffset = (unsigned int) atoi(argv[5]);
  if ( argc > 6 )
    oOffset = (unsigned int) atoi(argv[6]);

  // Let RtAudio print messages to stderr.
  adac.showWarnings( true );

  // Set the same number of channels for both input and output.
  unsigned int bufferFrames = 512;
  RtAudio::StreamParameters iParams, oParams;
  iParams.deviceId = iDevice;
  iParams.nChannels = channels;
  iParams.firstChannel = iOffset;
  oParams.deviceId = oDevice;
  oParams.nChannels = channels;
  oParams.firstChannel = oOffset;

  if ( iDevice == 0 )
    iParams.deviceId = adac.getDefaultInputDevice();
  if ( oDevice == 0 )
    oParams.deviceId = adac.getDefaultOutputDevice();

  RtAudio::StreamOptions options;
  //options.flags |= RTAUDIO_NONINTERLEAVED;

  bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
  try {
    adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    exit( 1 );
  }

  // Test RtAudio functionality for reporting latency.
  std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;

  try {
    adac.startStream();

    char input;
    std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
    std::cin.get(input);

    // Stop the stream.
    adac.stopStream();
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

 cleanup:
  if ( adac.isStreamOpen() ) adac.closeStream();

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x8(%rbp)
jl 0x87a1
cmpl $0x7, -0x8(%rbp)
jle 0x87a6
callq 0x8660
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x9060
leaq -0x38(%rbp), %rdi
callq 0x8c50
cmpl $0x1, %eax
jae 0x87ef
movq 0xf802(%rip), %rdi      # 0x17fc8
leaq 0xa9e7(%rip), %rsi      # 0x131b4
callq 0x8220
jmp 0x87d4
movl $0x1, %edi
callq 0x82f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8c2f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x83d0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x83d0
movl %eax, -0x18(%rbp)
cmpl $0x3, -0x8(%rbp)
jle 0x8825
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x83d0
movl %eax, -0x24(%rbp)
cmpl $0x4, -0x8(%rbp)
jle 0x883b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x83d0
movl %eax, -0x20(%rbp)
cmpl $0x5, -0x8(%rbp)
jle 0x8851
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x83d0
movl %eax, -0x28(%rbp)
cmpl $0x6, -0x8(%rbp)
jle 0x8867
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x83d0
movl %eax, -0x2c(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x8c90
movl $0x200, -0x48(%rbp)     # imm = 0x200
leaq -0x54(%rbp), %rdi
callq 0x8cd0
jmp 0x8887
leaq -0x60(%rbp), %rdi
callq 0x8cd0
jmp 0x8892
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x88c8
leaq -0x38(%rbp), %rdi
callq 0x8d00
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x88da
leaq -0x38(%rbp), %rdi
callq 0x8d40
movl %eax, -0x60(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x8d80
jmp 0x88e8
movl -0x48(%rbp), %eax
movl -0x14(%rbp), %ecx
imull %ecx, %eax
addl %eax, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %r8d
movq %rsp, %rax
leaq -0x90(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq -0x1c(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x227(%rip), %rcx      # 0x86f0
movq %rcx, (%rax)
movq $0x0, 0x18(%rax)
leaq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x54(%rbp), %rdx
movl $0x2, %ecx
leaq -0x48(%rbp), %r9
callq 0x9270
jmp 0x893e
jmp 0x8a02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8c23
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0x98(%rbp)
movq 0xf652(%rip), %rdi      # 0x17fc8
movl $0xa, %esi
callq 0x82b0
movq %rax, -0xb8(%rbp)
jmp 0x8989
movq -0x98(%rbp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x81f0
movq %rax, -0xc0(%rbp)
jmp 0x89b1
movq -0xc0(%rbp), %rdi
movl $0xa, %esi
callq 0x82b0
movq %rax, -0xc8(%rbp)
jmp 0x89cb
movq -0xc8(%rbp), %rdi
movq 0xf5d7(%rip), %rsi      # 0x17fb0
callq 0x8260
jmp 0x89e0
movl $0x1, %edi
callq 0x82f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x8420
jmp 0x89fd
jmp 0x8c23
movq 0xf5bf(%rip), %rdi      # 0x17fc8
leaq 0xa7be(%rip), %rsi      # 0x131ce
callq 0x8220
movq %rax, -0xd0(%rbp)
jmp 0x8a1e
leaq -0x38(%rbp), %rdi
callq 0x8dd0
movq %rax, -0xd8(%rbp)
jmp 0x8a30
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdi
callq 0x84a0
movq %rax, -0xe0(%rbp)
jmp 0x8a4c
movq -0xe0(%rbp), %rdi
leaq 0xa787(%rip), %rsi      # 0x131e1
callq 0x8220
movq %rax, -0xe8(%rbp)
jmp 0x8a68
movq -0xe8(%rbp), %rdi
movq 0xf53a(%rip), %rsi      # 0x17fb0
callq 0x8260
jmp 0x8a7d
leaq -0x38(%rbp), %rdi
callq 0x8df0
jmp 0x8a88
movq 0xf539(%rip), %rdi      # 0x17fc8
leaq 0xa753(%rip), %rsi      # 0x131e9
callq 0x8220
movq %rax, -0xf0(%rbp)
jmp 0x8aa4
movq -0xf0(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x8320
movq %rax, -0xf8(%rbp)
jmp 0x8abc
movq -0xf8(%rbp), %rdi
leaq 0xa754(%rip), %rsi      # 0x1321e
callq 0x8220
jmp 0x8ad1
movq 0xf500(%rip), %rdi      # 0x17fd8
leaq -0x99(%rbp), %rsi
callq 0x8350
jmp 0x8ae6
leaq -0x38(%rbp), %rdi
callq 0x8e10
jmp 0x8af1
jmp 0x8bd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8c23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8c23
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0xa8(%rbp)
movq 0xf48e(%rip), %rdi      # 0x17fc8
movl $0xa, %esi
callq 0x82b0
movq %rax, -0x100(%rbp)
jmp 0x8b4d
movq -0xa8(%rbp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movq -0x100(%rbp), %rdi
movq %rax, %rsi
callq 0x81f0
movq %rax, -0x108(%rbp)
jmp 0x8b75
movq -0x108(%rbp), %rdi
movl $0xa, %esi
callq 0x82b0
movq %rax, -0x110(%rbp)
jmp 0x8b8f
movq -0x110(%rbp), %rdi
movq 0xf413(%rip), %rsi      # 0x17fb0
callq 0x8260
jmp 0x8ba4
movl $0x2, -0xac(%rbp)
callq 0x8420
jmp 0x8bc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x8420
jmp 0x8bd5
movl -0xac(%rbp), %eax
subl $0x2, %eax
je 0x8bd9
jmp 0x8c02
jmp 0x8c23
jmp 0x8bd9
leaq -0x38(%rbp), %rdi
callq 0x8e30
testb $0x1, %al
jne 0x8be8
jmp 0x8bf1
leaq -0x38(%rbp), %rdi
callq 0x8e60
movl $0x0, -0x4(%rbp)
movl $0x1, -0xac(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x8e90
leaq -0x38(%rbp), %rdi
callq 0x9230
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x8e90
leaq -0x38(%rbp), %rdi
callq 0x9230
movq -0x40(%rbp), %rdi
callq 0x8450
movq %rax, %rdi
callq 0x8dc0
nopl (%rax)