// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edi, %r15d
leal -0x8(%r15), %eax
cmpl $-0x6, %eax
jbe 0x4c57
movq %rsi, %r14
leaq 0x28(%rsp), %r12
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4e1e
movq %r12, %rdi
callq 0x4d0a
testl %eax, %eax
je 0x4c5c
movq 0x8(%r14), %rdi
callq 0x42f0
movl %eax, %r13d
movl %eax, 0x7a54(%rip)      # 0xc218
movq 0x10(%r14), %rdi
callq 0x42f0
movl %eax, %ebp
cmpl $0x4, %r15d
jb 0x47f6
movq 0x18(%r14), %rdi
callq 0x42f0
movl %eax, 0x38(%rsp)
cmpl $0x4, %r15d
jne 0x4c11
movl $0x0, 0x30(%rsp)
jmp 0x4806
movl $0x0, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
xorl %r12d, %r12d
movl %r13d, %edi
pushq $0x8
popq %rsi
callq 0x4120
movq %rax, %r14
movq 0x28(%rsp), %rax
movb $0x1, 0x1a0(%rax)
andq $0x0, 0x3c(%rsp)
movl $0x200, 0x34(%rsp)      # imm = 0x200
andl $0x0, 0x44(%rsp)
movl %r12d, 0x48(%rsp)
movl %r13d, 0x4c(%rsp)
movl %ebx, 0x50(%rsp)
testl %r12d, %r12d
jne 0x4857
leaq 0x28(%rsp), %rdi
callq 0x4d1e
movl %eax, 0x48(%rsp)
leaq 0x60(%rsp), %rbx
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andl $0x0, 0x10(%rax)
movq $0x4, -0x18(%rax)
leaq 0x58(%rsp), %r12
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
andq $0x0, 0x18(%rsp)
leaq -0x2f1(%rip), %rax      # 0x45a4
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
pushq $0x20
popq %rcx
leaq 0x34(%rsp), %r9
xorl %edx, %edx
movl %ebp, %r8d
callq 0x4f42
movq 0x770c(%rip), %rdi      # 0xbfc8
leaq 0x394b(%rip), %rsi      # 0x820e
callq 0x41d0
movq %rax, %r15
movq 0x28(%rsp), %rdi
callq 0x558c
movq %r15, %rdi
movq %rax, %rsi
callq 0x41c0
movq %rax, %rdi
callq 0x40d0
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x76ce(%rip), %rdi      # 0xbfc8
leaq 0x3920(%rip), %rsi      # 0x8221
callq 0x41d0
movq 0x76cb(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x769f(%rip), %rdi      # 0xbfc8
leaq 0x3916(%rip), %rsi      # 0x8246
callq 0x41d0
movq 0x769c(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7670(%rip), %rdi      # 0xbfc8
leaq 0x3902(%rip), %rsi      # 0x8261
callq 0x41d0
movq 0x766d(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq 0x7641(%rip), %rdi      # 0xbfc8
leaq 0x38fe(%rip), %rsi      # 0x828c
callq 0x41d0
movq 0x763e(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7612(%rip), %rdi      # 0xbfc8
leaq 0x38f0(%rip), %rsi      # 0x82ad
callq 0x41d0
movq 0x760f(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x49eb
leaq 0x28(%rsp), %rdi
callq 0x4d32
movl $0x1, 0x58(%rsp)
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
andq $0x0, 0x18(%rsp)
leaq -0x39f(%rip), %rax      # 0x466b
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
pushq $0x20
popq %rcx
leaq 0x34(%rsp), %r9
xorl %edx, %edx
movl %ebp, %r8d
callq 0x4f42
movq 0x7597(%rip), %rdi      # 0xbfc8
leaq 0x38ab(%rip), %rsi      # 0x82e3
callq 0x41d0
movq 0x7594(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7568(%rip), %rdi      # 0xbfc8
leaq 0x37ba(%rip), %rsi      # 0x8221
callq 0x41d0
movq 0x7565(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x4a95
leaq 0x28(%rsp), %rdi
callq 0x4d32
movl 0x38(%rsp), %ecx
movl %ecx, 0x3c(%rsp)
movl 0x7775(%rip), %eax      # 0xc218
movl %eax, 0x40(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x44(%rsp)
testl %ecx, %ecx
jne 0x4ac1
leaq 0x28(%rsp), %rdi
callq 0x4d46
movl %eax, 0x3c(%rsp)
movl $0x1, 0x58(%rsp)
movq %r12, 0x10(%rsp)
leaq 0x54(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x3b5(%rip), %rax      # 0x472a
andq $0x0, 0x18(%rsp)
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x3c(%rsp), %rdx
pushq $0x8
popq %rcx
leaq 0x34(%rsp), %r9
movl %ebp, %r8d
callq 0x4f42
movl 0x34(%rsp), %eax
imull 0x7705(%rip), %eax      # 0xc218
shll $0x2, %eax
movl %eax, 0x54(%rsp)
movq 0x74a7(%rip), %rdi      # 0xbfc8
leaq 0x37ed(%rip), %rsi      # 0x8315
callq 0x41d0
movq 0x74a4(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7478(%rip), %rdi      # 0xbfc8
leaq 0x37e8(%rip), %rsi      # 0x833f
callq 0x41d0
movq 0x7475(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x7449(%rip), %rdi      # 0xbfc8
leaq 0x37de(%rip), %rsi      # 0x8364
callq 0x41d0
movq 0x7446(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x741a(%rip), %rdi      # 0xbfc8
leaq 0x378a(%rip), %rsi      # 0x833f
callq 0x41d0
movq 0x7417(%rip), %rdi      # 0xbfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
movq 0x28(%rsp), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x4be3
leaq 0x28(%rsp), %rdi
callq 0x4d32
movq %r14, %rdi
callq 0x4220
movq %rbx, %rdi
callq 0x40c0
leaq 0x28(%rsp), %rdi
callq 0x4f32
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rdi
callq 0x42f0
movl %eax, %r12d
cmpl $0x6, %r15d
jb 0x4c4a
movq 0x28(%r14), %rdi
callq 0x42f0
movl %eax, 0x30(%rsp)
cmpl $0x6, %r15d
je 0x4809
movq 0x30(%r14), %rdi
callq 0x42f0
movl %eax, %ebx
jmp 0x4809
movl $0x0, 0x30(%rsp)
jmp 0x4809
callq 0x452c
movq 0x7365(%rip), %rdi      # 0xbfc8
leaq 0x358a(%rip), %rsi      # 0x81f4
callq 0x41d0
pushq $0x1
popq %rdi
callq 0x4240
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x4f32
movq %r15, %rdi
callq 0x4370
movq %rax, %r15
cmpl $0x1, %edx
jne 0x4cfc
movq %r15, %rdi
callq 0x4090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4350
jmp 0x4bcb
jmp 0x4cf9
movq %rax, %r15
cmpl $0x1, %edx
jne 0x4cfc
movq %r15, %rdi
callq 0x4090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4350
jmp 0x4bcb
jmp 0x4cf9
movq %rax, %r15
cmpl $0x1, %edx
jne 0x4cfc
movq %r15, %rdi
callq 0x4090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4350
jmp 0x4bcb
movq %rax, %r15
movq %rbx, %rdi
callq 0x40c0
jmp 0x4c7a
nop