// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movl %edi, %r15d
leal -0x8(%r15), %eax
cmpl $-0x6, %eax
jbe 0x4db9
movq %rsi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4f9a
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4dbe
movq 0x8(%rbx), %rdi
callq 0x4310
movl %eax, %r12d
movl %eax, 0x8955(%rip)      # 0xd228
movq 0x10(%rbx), %rdi
callq 0x4310
movl %eax, %ebp
xorl %r13d, %r13d
cmpl $0x4, %r15d
jb 0x4908
movq 0x18(%rbx), %rdi
callq 0x4310
movl %eax, 0x18(%rsp)
cmpl $0x4, %r15d
jne 0x4d72
movl $0x0, 0x10(%rsp)
jmp 0x4918
movl $0x0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
xorl %r14d, %r14d
movl %r12d, %edi
movl $0x8, %esi
callq 0x4120
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x14(%rsp)      # imm = 0x200
movq $0x0, 0x1c(%rsp)
movl $0x0, 0x24(%rsp)
movl %r14d, 0x28(%rsp)
movl %r12d, 0x2c(%rsp)
movl %r13d, 0x30(%rsp)
testl %r14d, %r14d
jne 0x496e
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x28(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb $0x0, (%r15)
movl $0x0, 0x10(%r15)
movq $0x4, -0x18(%r15)
leaq 0x38(%rsp), %r12
leaq -0x399(%rip), %r10      # 0x4604
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x14(%rsp), %r9
movl $0x20, %ecx
xorl %edx, %edx
movl %ebp, %r8d
pushq %rax
pushq %r12
pushq %rbx
pushq %r10
callq 0x512e
addq $0x20, %rsp
movq 0x85fc(%rip), %rdi      # 0xcfc8
leaq 0x483b(%rip), %rsi      # 0x920e
movl $0x12, %edx
callq 0x4210
movq 0x8(%rsp), %rdi
callq 0x58ec
movq 0x85da(%rip), %rdi      # 0xcfc8
movq %rax, %rsi
callq 0x41c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x41d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4140
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x8596(%rip), %rdi      # 0xcfc8
leaq 0x47e8(%rip), %rsi      # 0x9221
movl $0x24, %edx
callq 0x4210
movq 0x858e(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x8562(%rip), %rdi      # 0xcfc8
leaq 0x47d9(%rip), %rsi      # 0x9246
movl $0x1a, %edx
callq 0x4210
movq 0x855a(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x852e(%rip), %rdi      # 0xcfc8
leaq 0x47c0(%rip), %rsi      # 0x9261
movl $0x2a, %edx
callq 0x4210
movq 0x8526(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq 0x84fa(%rip), %rdi      # 0xcfc8
leaq 0x47b7(%rip), %rsi      # 0x928c
movl $0x20, %edx
callq 0x4210
movq 0x84f2(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x84c6(%rip), %rdi      # 0xcfc8
leaq 0x47a4(%rip), %rsi      # 0x92ad
movl $0x35, %edx
callq 0x4210
movq 0x84be(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4b38
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x1, 0x38(%rsp)
leaq -0x43c(%rip), %rax      # 0x470b
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x14(%rsp), %r9
movl $0x20, %ecx
xorl %edx, %edx
movl %ebp, %r8d
pushq $0x0
pushq %r12
pushq %rbx
pushq %rax
callq 0x512e
addq $0x20, %rsp
movq 0x8452(%rip), %rdi      # 0xcfc8
leaq 0x4766(%rip), %rsi      # 0x92e3
movl $0x31, %edx
callq 0x4210
movq 0x844a(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x841e(%rip), %rdi      # 0xcfc8
leaq 0x4670(%rip), %rsi      # 0x9221
movl $0x24, %edx
callq 0x4210
movq 0x8416(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4be0
movq (%rdi), %rax
callq *0x38(%rax)
movl 0x18(%rsp), %ecx
movl %ecx, 0x1c(%rsp)
movl 0x863a(%rip), %eax      # 0xd228
movl %eax, 0x20(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x24(%rsp)
testl %ecx, %ecx
jne 0x4c0d
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, 0x1c(%rsp)
movl $0x1, 0x38(%rsp)
leaq 0x34(%rsp), %rax
leaq -0x415(%rip), %r10      # 0x480c
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x14(%rsp), %r9
movl $0x8, %ecx
movl %ebp, %r8d
pushq $0x0
pushq %r12
pushq %rax
pushq %r10
callq 0x512e
addq $0x20, %rsp
movl 0x14(%rsp), %eax
imull 0x85d0(%rip), %eax      # 0xd228
shll $0x2, %eax
movl %eax, 0x34(%rsp)
movq 0x8362(%rip), %rdi      # 0xcfc8
leaq 0x46a8(%rip), %rsi      # 0x9315
movl $0x29, %edx
callq 0x4210
movq 0x835a(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x832e(%rip), %rdi      # 0xcfc8
leaq 0x469e(%rip), %rsi      # 0x933f
movl $0x24, %edx
callq 0x4210
movq 0x8326(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x82fa(%rip), %rdi      # 0xcfc8
leaq 0x468f(%rip), %rsi      # 0x9364
movl $0x27, %edx
callq 0x4210
movq 0x82f2(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x82c6(%rip), %rdi      # 0xcfc8
leaq 0x4636(%rip), %rsi      # 0x933f
movl $0x24, %edx
callq 0x4210
movq 0x82be(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4d38
movq (%rdi), %rax
callq *0x38(%rax)
movq %rbx, %rdi
callq 0x4230
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4d57
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4200
leaq 0x8(%rsp), %rdi
callq 0x511e
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rbx), %rdi
callq 0x4310
movl %eax, %r14d
cmpl $0x6, %r15d
jb 0x4dac
movq 0x28(%rbx), %rdi
callq 0x4310
movl %eax, 0x10(%rsp)
cmpl $0x6, %r15d
je 0x491b
movq 0x30(%rbx), %rdi
callq 0x4310
movl %eax, %r13d
jmp 0x491b
movl $0x0, 0x10(%rsp)
jmp 0x491b
callq 0x458c
movq 0x8203(%rip), %rdi      # 0xcfc8
leaq 0x4428(%rip), %rsi      # 0x91f4
callq 0x41e0
movl $0x1, %edi
callq 0x4250
jmp 0x4dfa
jmp 0x4dfa
jmp 0x4dfa
jmp 0x4dfa
jmp 0x4dfa
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x511e
movq %r14, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x4e92
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e72
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d24
jmp 0x4e6f
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e72
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d24
jmp 0x4e6f
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e72
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d24
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4de8
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4200
jmp 0x4de8