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

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

  RtAudio dac;
  if ( dac.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]);

  double *data = (double *) calloc( channels, sizeof( double ) );

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

  // Set our stream parameters for output only.
  bufferFrames = 512;
  RtAudio::StreamParameters oParams, iParams;
  oParams.deviceId = oDevice;
  oParams.nChannels = channels;
  oParams.firstChannel = oOffset;

  if ( oDevice == 0 )
    oParams.deviceId = dac.getDefaultOutputDevice();

  RtAudio::StreamOptions options;
  options.flags = RTAUDIO_HOG_DEVICE;
  try {
    dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawi, (void *)data, &options );
    std::cout << "\nStream latency = " << dac.getStreamLatency() << std::endl;

    // Start the stream
    dac.startStream();
    std::cout << "\nPlaying ... press <enter> to stop.\n";
    std::cin.get( input );

    // Stop the stream
    dac.stopStream();

    // Restart again
    std::cout << "Press <enter> to restart.\n";
    std::cin.get( input );
    dac.startStream();

    // Test abort function
    std::cout << "Playing again ... press <enter> to abort.\n";
    std::cin.get( input );
    dac.abortStream();

    // Restart another time
    std::cout << "Press <enter> to restart again.\n";
    std::cin.get( input );
    dac.startStream();

    std::cout << "Playing again ... press <enter> to close the stream.\n";
    std::cin.get( input );
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  if ( dac.isStreamOpen() ) dac.closeStream();

  // Test non-interleaved functionality
  options.flags = RTAUDIO_NONINTERLEAVED;
  try {
    dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawni, (void *)data, &options );

    std::cout << "Press <enter> to start non-interleaved playback.\n";
    std::cin.get( input );

    // Start the stream
    dac.startStream();
    std::cout << "\nPlaying ... press <enter> to stop.\n";
    std::cin.get( input );
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  if ( dac.isStreamOpen() ) dac.closeStream();

  // Now open a duplex stream.
  unsigned int bufferBytes;
  iParams.deviceId = iDevice;
  iParams.nChannels = channels;
  iParams.firstChannel = iOffset;
  if ( iDevice == 0 )
    iParams.deviceId = dac.getDefaultInputDevice();
  options.flags = RTAUDIO_NONINTERLEAVED;
  try {
    dac.openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );

    bufferBytes = bufferFrames * channels * 4;

    std::cout << "Press <enter> to start duplex operation.\n";
    std::cin.get( input );

    // Start the stream
    dac.startStream();
    std::cout << "\nRunning ... press <enter> to stop.\n";
    std::cin.get( input );

    // Stop the stream
    dac.stopStream();
    std::cout << "\nStopped ... press <enter> to restart.\n";
    std::cin.get( input );

    // Restart the stream
    dac.startStream();
    std::cout << "\nRunning ... press <enter> to stop.\n";
    std::cin.get( input );
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
  }

 cleanup:
  if ( dac.isStreamOpen() ) dac.closeStream();
  free( data );

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x3, -0x8(%rbp)
jl 0x8a21
cmpl $0x7, -0x8(%rbp)
jle 0x8a26
callq 0x8650
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x9500
leaq -0x38(%rbp), %rdi
callq 0x90d0
cmpl $0x1, %eax
jae 0x8a6f
movq 0xf582(%rip), %rdi      # 0x17fc8
leaq 0xa7a7(%rip), %rsi      # 0x131f4
callq 0x8220
jmp 0x8a54
movl $0x1, %edi
callq 0x82f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x90af
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x83c0
movl %eax, 0xf80e(%rip)      # 0x18290
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x83c0
movl %eax, -0x18(%rbp)
cmpl $0x3, -0x8(%rbp)
jle 0x8aa8
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x83c0
movl %eax, -0x20(%rbp)
cmpl $0x4, -0x8(%rbp)
jle 0x8abe
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x83c0
movl %eax, -0x1c(%rbp)
cmpl $0x5, -0x8(%rbp)
jle 0x8ad4
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x83c0
movl %eax, -0x24(%rbp)
cmpl $0x6, -0x8(%rbp)
jle 0x8aea
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x83c0
movl %eax, -0x28(%rbp)
movl 0xf7a0(%rip), %eax      # 0x18290
movl %eax, %edi
movl $0x8, %esi
callq 0x8150
movq %rax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x9110
movl $0x200, -0x14(%rbp)     # imm = 0x200
leaq -0x5c(%rbp), %rdi
callq 0x9150
jmp 0x8b20
leaq -0x68(%rbp), %rdi
callq 0x9150
jmp 0x8b2b
movl -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0xf759(%rip), %eax      # 0x18290
movl %eax, -0x58(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x8b52
leaq -0x38(%rbp), %rdi
callq 0x9180
movl %eax, -0x5c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x91c0
jmp 0x8b60
movl $0x4, -0x98(%rbp)
movl -0x18(%rbp), %r8d
movq -0x50(%rbp), %rcx
movq %rsp, %rax
leaq -0x98(%rbp), %rdx
movq %rdx, 0x10(%rax)
movq %rcx, 0x8(%rax)
leaq -0x4ab(%rip), %rcx      # 0x86e0
movq %rcx, (%rax)
movq $0x0, 0x18(%rax)
xorl %eax, %eax
movl %eax, %edx
leaq -0x38(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
movl $0x20, %ecx
leaq -0x14(%rbp), %r9
callq 0x9710
jmp 0x8bb2
movq 0xf40f(%rip), %rdi      # 0x17fc8
leaq 0xa64e(%rip), %rsi      # 0x1320e
callq 0x8220
movq %rax, -0xc8(%rbp)
jmp 0x8bce
leaq -0x38(%rbp), %rdi
callq 0x9200
movq %rax, -0xd0(%rbp)
jmp 0x8be0
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x8490
movq %rax, -0xd8(%rbp)
jmp 0x8bfc
movq -0xd8(%rbp), %rdi
movq 0xf3a6(%rip), %rsi      # 0x17fb0
callq 0x8260
jmp 0x8c11
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8c1c
movq 0xf3a5(%rip), %rdi      # 0x17fc8
leaq 0xa5f7(%rip), %rsi      # 0x13221
callq 0x8220
jmp 0x8c31
movq 0xf3a0(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8c43
leaq -0x38(%rbp), %rdi
callq 0x9240
jmp 0x8c4e
movq 0xf373(%rip), %rdi      # 0x17fc8
leaq 0xa5ea(%rip), %rsi      # 0x13246
callq 0x8220
jmp 0x8c63
movq 0xf36e(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8c75
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8c80
movq 0xf341(%rip), %rdi      # 0x17fc8
leaq 0xa5d3(%rip), %rsi      # 0x13261
callq 0x8220
jmp 0x8c95
movq 0xf33c(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8ca7
leaq -0x38(%rbp), %rdi
callq 0x9260
jmp 0x8cb2
movq 0xf30f(%rip), %rdi      # 0x17fc8
leaq 0xa5cc(%rip), %rsi      # 0x1328c
callq 0x8220
jmp 0x8cc7
movq 0xf30a(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8cd9
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8ce4
movq 0xf2dd(%rip), %rdi      # 0x17fc8
leaq 0xa5bb(%rip), %rsi      # 0x132ad
callq 0x8220
jmp 0x8cf9
movq 0xf2d8(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8d0b
jmp 0x8d7f
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 0x90a3
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movl $0x2, -0xa4(%rbp)
callq 0x8410
jmp 0x8d5a
movl -0xa4(%rbp), %eax
subl $0x2, %eax
je 0x9050
jmp 0x9082
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x90a3
leaq -0x38(%rbp), %rdi
callq 0x9280
testb $0x1, %al
jne 0x8d8e
jmp 0x8d97
leaq -0x38(%rbp), %rdi
callq 0x92b0
movl $0x1, -0x98(%rbp)
movl -0x18(%rbp), %r8d
movq -0x50(%rbp), %rcx
movq %rsp, %rax
leaq -0x98(%rbp), %rdx
movq %rdx, 0x10(%rax)
movq %rcx, 0x8(%rax)
leaq -0x5a2(%rip), %rcx      # 0x8820
movq %rcx, (%rax)
movq $0x0, 0x18(%rax)
xorl %eax, %eax
movl %eax, %edx
leaq -0x38(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
movl $0x20, %ecx
leaq -0x14(%rbp), %r9
callq 0x9710
jmp 0x8de9
movq 0xf1d8(%rip), %rdi      # 0x17fc8
leaq 0xa4ec(%rip), %rsi      # 0x132e3
callq 0x8220
jmp 0x8dfe
movq 0xf1d3(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8e10
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8e1b
movq 0xf1a6(%rip), %rdi      # 0x17fc8
leaq 0xa3f8(%rip), %rsi      # 0x13221
callq 0x8220
jmp 0x8e30
movq 0xf1a1(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8e42
jmp 0x8ea5
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 0x90a3
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movl $0x2, -0xa4(%rbp)
callq 0x8410
jmp 0x8e91
movl -0xa4(%rbp), %eax
subl $0x2, %eax
je 0x9050
jmp 0x9082
leaq -0x38(%rbp), %rdi
callq 0x9280
testb $0x1, %al
jne 0x8eb4
jmp 0x8ebd
leaq -0x38(%rbp), %rdi
callq 0x92b0
movl -0x20(%rbp), %eax
movl %eax, -0x68(%rbp)
movl 0xf3c7(%rip), %eax      # 0x18290
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x8ee4
leaq -0x38(%rbp), %rdi
callq 0x92e0
movl %eax, -0x68(%rbp)
movl $0x1, -0x98(%rbp)
movl -0x18(%rbp), %r8d
movq %rsp, %rax
leaq -0x98(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq -0xb4(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x5a2(%rip), %rcx      # 0x8970
movq %rcx, (%rax)
movq $0x0, 0x18(%rax)
leaq -0x38(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movl $0x8, %ecx
leaq -0x14(%rbp), %r9
callq 0x9710
jmp 0x8f39
movl -0x14(%rbp), %eax
movl 0xf34e(%rip), %ecx      # 0x18290
imull %ecx, %eax
shll $0x2, %eax
movl %eax, -0xb4(%rbp)
movq 0xf073(%rip), %rdi      # 0x17fc8
leaq 0xa3b9(%rip), %rsi      # 0x13315
callq 0x8220
jmp 0x8f63
movq 0xf06e(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8f75
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8f80
movq 0xf041(%rip), %rdi      # 0x17fc8
leaq 0xa3b1(%rip), %rsi      # 0x1333f
callq 0x8220
jmp 0x8f95
movq 0xf03c(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8fa7
leaq -0x38(%rbp), %rdi
callq 0x9240
jmp 0x8fb2
movq 0xf00f(%rip), %rdi      # 0x17fc8
leaq 0xa3a4(%rip), %rsi      # 0x13364
callq 0x8220
jmp 0x8fc7
movq 0xf00a(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x8fd9
leaq -0x38(%rbp), %rdi
callq 0x9220
jmp 0x8fe4
movq 0xefdd(%rip), %rdi      # 0x17fc8
leaq 0xa34d(%rip), %rsi      # 0x1333f
callq 0x8220
jmp 0x8ff9
movq 0xefd8(%rip), %rdi      # 0x17fd8
leaq -0x29(%rbp), %rsi
callq 0x8340
jmp 0x900b
jmp 0x904e
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 0x90a3
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
callq 0x8410
jmp 0x904c
jmp 0x904e
jmp 0x9050
leaq -0x38(%rbp), %rdi
callq 0x9280
testb $0x1, %al
jne 0x905f
jmp 0x9068
leaq -0x38(%rbp), %rdi
callq 0x92b0
movq -0x50(%rbp), %rdi
callq 0x82d0
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x9320
leaq -0x38(%rbp), %rdi
callq 0x96d0
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x9320
leaq -0x38(%rbp), %rdi
callq 0x96d0
movq -0x40(%rbp), %rdi
callq 0x8440
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)