// File: /workspace/github_cpp_makefile_star2_O1/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, %r13d
leal -0x8(%r13), %eax
cmpl $-0x6, %eax
jbe 0x4d93
movq %rsi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4f70
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4d98
movq 0x8(%rbx), %rdi
callq 0x4310
movl %eax, %r12d
movl %eax, 0x8954(%rip)      # 0xd228
movq 0x10(%rbx), %rdi
callq 0x4310
movl %eax, %ebp
xorl %r15d, %r15d
movl $0x0, %eax
cmpl $0x4, %r13d
jl 0x48f6
movq 0x18(%rbx), %rdi
callq 0x4310
movl %eax, 0x30(%rsp)
cmpl $0x5, %r13d
jl 0x490c
movq 0x20(%rbx), %rdi
callq 0x4310
movl %eax, %r15d
xorl %r14d, %r14d
movl $0x0, %eax
cmpl $0x6, %r13d
jl 0x4923
movq 0x28(%rbx), %rdi
callq 0x4310
movl %eax, 0x2c(%rsp)
cmpl $0x7, %r13d
jl 0x4939
movq 0x30(%rbx), %rdi
callq 0x4310
movl %eax, %r14d
movl %r12d, %edi
movl $0x8, %esi
callq 0x4120
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x10(%rsp)      # imm = 0x200
xorl %eax, %eax
movq %rax, 0x14(%rsp)
movl %eax, 0x1c(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movl %r15d, 0x14(%rsp)
movl %r12d, 0x18(%rsp)
movl %r14d, 0x1c(%rsp)
testl %r15d, %r15d
jne 0x498f
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x14(%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 -0x3ba(%rip), %r10      # 0x4604
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %r9
movl $0x20, %ecx
xorl %edx, %edx
movl %ebp, %r8d
pushq %rax
pushq %r12
pushq %rbx
pushq %r10
callq 0x5104
addq $0x20, %rsp
movq 0x85db(%rip), %rdi      # 0xcfc8
leaq 0x481a(%rip), %rsi      # 0x920e
movl $0x12, %edx
callq 0x4210
movq 0x8(%rsp), %rdi
callq 0x589a
movq 0x85b9(%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 0x8575(%rip), %rdi      # 0xcfc8
leaq 0x47c7(%rip), %rsi      # 0x9221
movl $0x24, %edx
callq 0x4210
movq 0x856d(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x8541(%rip), %rdi      # 0xcfc8
leaq 0x47b8(%rip), %rsi      # 0x9246
movl $0x1a, %edx
callq 0x4210
movq 0x8539(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x850d(%rip), %rdi      # 0xcfc8
leaq 0x479f(%rip), %rsi      # 0x9261
movl $0x2a, %edx
callq 0x4210
movq 0x8505(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq 0x84d9(%rip), %rdi      # 0xcfc8
leaq 0x4796(%rip), %rsi      # 0x928c
movl $0x20, %edx
callq 0x4210
movq 0x84d1(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x84a5(%rip), %rdi      # 0xcfc8
leaq 0x4783(%rip), %rsi      # 0x92ad
movl $0x35, %edx
callq 0x4210
movq 0x849d(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4b59
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x1, 0x38(%rsp)
leaq -0x45c(%rip), %rax      # 0x470c
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %r9
movl $0x20, %ecx
xorl %edx, %edx
movl %ebp, %r8d
pushq $0x0
pushq %r12
pushq %rbx
pushq %rax
callq 0x5104
addq $0x20, %rsp
movq 0x8431(%rip), %rdi      # 0xcfc8
leaq 0x4745(%rip), %rsi      # 0x92e3
movl $0x31, %edx
callq 0x4210
movq 0x8429(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x83fd(%rip), %rdi      # 0xcfc8
leaq 0x464f(%rip), %rsi      # 0x9221
movl $0x24, %edx
callq 0x4210
movq 0x83f5(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4c01
movq (%rdi), %rax
callq *0x38(%rax)
movl 0x30(%rsp), %ecx
movl %ecx, 0x20(%rsp)
movl 0x8619(%rip), %eax      # 0xd228
movl %eax, 0x24(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x28(%rsp)
testl %ecx, %ecx
jne 0x4c2e
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, 0x20(%rsp)
movl $0x1, 0x38(%rsp)
leaq 0x34(%rsp), %rax
leaq -0x435(%rip), %r10      # 0x480d
leaq 0x8(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %r9
movl $0x8, %ecx
movl %ebp, %r8d
pushq $0x0
pushq %r12
pushq %rax
pushq %r10
callq 0x5104
addq $0x20, %rsp
movl 0x10(%rsp), %eax
imull 0x85af(%rip), %eax      # 0xd228
shll $0x2, %eax
movl %eax, 0x34(%rsp)
movq 0x8341(%rip), %rdi      # 0xcfc8
leaq 0x4687(%rip), %rsi      # 0x9315
movl $0x29, %edx
callq 0x4210
movq 0x8339(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x830d(%rip), %rdi      # 0xcfc8
leaq 0x467d(%rip), %rsi      # 0x933f
movl $0x24, %edx
callq 0x4210
movq 0x8305(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x82d9(%rip), %rdi      # 0xcfc8
leaq 0x466e(%rip), %rsi      # 0x9364
movl $0x27, %edx
callq 0x4210
movq 0x82d1(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x82a5(%rip), %rdi      # 0xcfc8
leaq 0x4615(%rip), %rsi      # 0x933f
movl $0x24, %edx
callq 0x4210
movq 0x829d(%rip), %rdi      # 0xcfd8
leaq 0x7(%rsp), %rsi
callq 0x4290
movq 0x8(%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4d59
movq (%rdi), %rax
callq *0x38(%rax)
movq %rbx, %rdi
callq 0x4230
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4d78
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4200
leaq 0x8(%rsp), %rdi
callq 0x50f4
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x458c
movq 0x8229(%rip), %rdi      # 0xcfc8
leaq 0x444e(%rip), %rsi      # 0x91f4
callq 0x41e0
movl $0x1, %edi
callq 0x4250
jmp 0x4dd4
jmp 0x4dd4
jmp 0x4dd4
jmp 0x4dd4
jmp 0x4dd4
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x50f4
movq %r14, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x4e6c
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e4c
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d45
jmp 0x4e49
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e4c
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d45
jmp 0x4e49
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e4c
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4370
jmp 0x4d45
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4dc2
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4200
jmp 0x4dc2