// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
leal -0x7(%r15), %eax
cmpl $-0x5, %eax
jbe 0x4a78
movq %rsi, %rbx
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4da8
movq (%r14), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4a7d
movq 0x8(%rbx), %rdi
callq 0x4330
movl %eax, %r14d
movl %eax, 0x7976(%rip)      # 0xc23c
movq 0x10(%rbx), %rdi
callq 0x4330
movl %eax, %ebp
xorl %r12d, %r12d
movl $0x0, %r13d
cmpl $0x4, %r15d
jl 0x48ec
movq 0x18(%rbx), %rdi
callq 0x4330
movl %eax, %r13d
cmpl $0x5, %r15d
jl 0x48fe
movq 0x20(%rbx), %rdi
callq 0x4330
movl %eax, %r12d
cmpl $0x6, %r15d
jl 0x492b
movl %ebp, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rbx), %rdi
callq 0x4270
mulsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x794d(%rip)      # 0xc278
cmpl $0x0, 0x7946(%rip)      # 0xc278
je 0x493b
movb $0x1, 0x7939(%rip)      # 0xc274
movl %r14d, %edi
movl $0x8, %esi
callq 0x4120
movq %rax, %rbx
movq (%rsp), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x10(%rsp)      # imm = 0x200
movl %r13d, 0x14(%rsp)
movl %r14d, 0x18(%rsp)
movl %r12d, 0x1c(%rsp)
testl %r13d, %r13d
jne 0x497c
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x14(%rsp)
movl $0xd, 0x78ba(%rip)      # 0xc240
leaq 0x78b3(%rip), %rax      # 0xc240
leaq -0x32f(%rip), %r10      # 0x4665
leaq -0x26e(%rip), %r11      # 0x472d
movq %rsp, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %r9
movl $0x2, %ecx
xorl %edx, %edx
movl %ebp, %r8d
pushq %r10
pushq %rax
pushq %rbx
pushq %r11
callq 0x4f3c
addq $0x20, %rsp
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
cmpb $0x1, 0x78a2(%rip)      # 0xc274
jne 0x49ed
movq (%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x4a44
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42b0
jmp 0x49d4
movq 0x75d4(%rip), %rdi      # 0xbfc8
leaq 0x47c5(%rip), %rsi      # 0x91c0
movl $0x32, %edx
callq 0x4210
movl 0x10(%rsp), %esi
movq 0x75b8(%rip), %rdi      # 0xbfc8
callq 0x4140
leaq 0x47d7(%rip), %rsi      # 0x91f3
movl $0x3, %edx
movq %rax, %rdi
callq 0x4210
movq 0x75a8(%rip), %rdi      # 0xbfd8
leaq 0xf(%rsp), %rsi
callq 0x42a0
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq (%rsp), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4a57
movq (%rdi), %rax
callq *0x38(%rax)
movq %rbx, %rdi
callq 0x4230
movq %rsp, %rdi
callq 0x4f2c
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x45fc
movq 0x7544(%rip), %rdi      # 0xbfc8
leaq 0x471b(%rip), %rsi      # 0x91a6
callq 0x41e0
movl $0x1, %edi
callq 0x4250
jmp 0x4ac2
jmp 0x4ac2
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4af4
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4390
jmp 0x4a44
jmp 0x4af1
jmp 0x4af1
movq %rax, %rdi
callq 0x4b96
jmp 0x4af1
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4af4
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4390
jmp 0x4a44
jmp 0x4af1
movq %rax, %r14
movq %rsp, %rdi
callq 0x4f2c
movq %r14, %rdi
callq 0x43c0