// File: /workspace/github_cpp_makefile_star2_O2/tobias93[P]piano/rtaudio/tests/playsaw.cpp
// Function: main
int main( int argc, char *argv[] )
{
  unsigned int bufferFrames, fs, device = 0, offset = 0;

  // minimal command-line checking
  if (argc < 3 || argc > 6 ) 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 )
    device = (unsigned int) atoi( argv[3] );
  if ( argc > 4 )
    offset = (unsigned int) atoi( argv[4] );
  if ( argc > 5 )
    nFrames = (unsigned int) (fs * atof( argv[5] ));
  if ( nFrames > 0 ) checkCount = true;

  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;
  oParams.deviceId = device;
  oParams.nChannels = channels;
  oParams.firstChannel = offset;

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

  options.flags = RTAUDIO_HOG_DEVICE;
  options.flags |= RTAUDIO_SCHEDULE_REALTIME;
#if !defined( USE_INTERLEAVED )
  options.flags |= RTAUDIO_NONINTERLEAVED;
#endif
  try {
    dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback );
    dac.startStream();
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  if ( checkCount ) {
    while ( dac.isStreamRunning() == true ) SLEEP( 100 );
  }
  else {
    char input;
    //std::cout << "Stream latency = " << dac.getStreamLatency() << "\n" << std::endl;
    std::cout << "\nPlaying ... press <enter> to quit (buffer size = " << bufferFrames << ").\n";
    std::cin.get( input );

    try {
      // Stop the stream
      dac.stopStream();
    }
    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 $0x28, %rsp
movl %edi, %r13d
leal -0x7(%r13), %eax
cmpl $-0x5, %eax
jbe 0x5988
movq %rsi, %rbx
movq %rsp, %r15
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
callq 0x5bc2
movq %r15, %rdi
callq 0x5a60
testl %eax, %eax
je 0x598d
movq 0x8(%rbx), %rdi
callq 0x5310
movl %eax, %r15d
movl %eax, 0x7a45(%rip)      # 0xd22c
movq 0x10(%rbx), %rdi
callq 0x5310
movl %eax, %ebp
cmpl $0x4, %r13d
jb 0x5845
movq 0x18(%rbx), %rdi
callq 0x5310
movl %eax, %r12d
cmpl $0x4, %r13d
je 0x5848
movq 0x20(%rbx), %rdi
callq 0x5310
movl %eax, %r14d
cmpl $0x6, %r13d
jb 0x5848
movl %ebp, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %rdi
callq 0x5260
mulsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x7a25(%rip)      # 0xd268
jmp 0x584e
xorl %r12d, %r12d
movl 0x7a1a(%rip), %eax      # 0xd268
testl %eax, %eax
je 0x5859
movb $0x1, 0x7a0b(%rip)      # 0xd264
movl %r15d, %edi
pushq $0x8
popq %rsi
callq 0x5120
movq %rax, %rbx
movq (%rsp), %rax
movb $0x1, 0x1a0(%rax)
movl $0x200, 0x10(%rsp)      # imm = 0x200
movl %r12d, 0x14(%rsp)
movl %r15d, 0x18(%rsp)
movl %r14d, 0x1c(%rsp)
testl %r12d, %r12d
jne 0x589a
movq %rsp, %rdi
callq 0x5a74
movl %eax, 0x14(%rsp)
movl $0xd, 0x798c(%rip)      # 0xd230
leaq 0x7985(%rip), %rax      # 0xd230
leaq -0x2ad(%rip), %r10      # 0x5605
leaq -0x231(%rip), %r11      # 0x5688
movq %rsp, %rdi
leaq 0x14(%rsp), %rsi
pushq $0x2
popq %rcx
leaq 0x10(%rsp), %r9
xorl %edx, %edx
movl %ebp, %r8d
pushq %r10
pushq %rax
pushq %rbx
pushq %r11
callq 0x5ce6
addq $0x20, %rsp
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
cmpb $0x1, 0x7976(%rip)      # 0xd264
jne 0x5909
movq (%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x5952
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x52a0
jmp 0x58f0
movq 0x76b8(%rip), %rdi      # 0xcfc8
leaq 0x38a9(%rip), %rsi      # 0x91c0
callq 0x51d0
movl 0x10(%rsp), %esi
movq %rax, %rdi
callq 0x5140
leaq 0x38c4(%rip), %rsi      # 0x91f3
movq %rax, %rdi
callq 0x51d0
movq 0x769a(%rip), %rdi      # 0xcfd8
leaq 0xf(%rsp), %rsi
callq 0x5290
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq (%rsp), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x5967
movq %rsp, %rdi
callq 0x5a88
movq %rbx, %rdi
callq 0x5220
movq %rsp, %rdi
callq 0x5cd6
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x559c
movq 0x7634(%rip), %rdi      # 0xcfc8
leaq 0x380b(%rip), %rsi      # 0x91a6
callq 0x51d0
pushq $0x1
popq %rdi
callq 0x5240
movq %rax, %r14
cmpl $0x1, %edx
jne 0x59f6
movq %r14, %rdi
callq 0x5090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x5370
jmp 0x5952
jmp 0x59f3
jmp 0x59f3
jmp 0x59f3
movq %rax, %r14
cmpl $0x1, %edx
jne 0x59f6
movq %r14, %rdi
callq 0x5090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x5370
jmp 0x5952
jmp 0x59f3
movq %rax, %r14
movq %rsp, %rdi
callq 0x5cd6
movq %r14, %rdi
callq 0x5390