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

  // minimal command-line checking
  if ( argc < 4 || argc > 6 ) usage();

  RtAudio dac;
  if ( dac.getDeviceCount() < 1 ) {
    std::cout << "\nNo audio devices found!\n";
    exit( 0 );
  }

  channels = (unsigned int) atoi( argv[1]) ;
  fs = (unsigned int) atoi( argv[2] );
  file = argv[3];
  if ( argc > 4 )
    device = (unsigned int) atoi( argv[4] );
  if ( argc > 5 )
    offset = (unsigned int) atoi( argv[5] );

  OutputData data;
  data.fd = fopen( file, "rb" );
  if ( !data.fd ) {
    std::cout << "Unable to find or open file!\n";
    exit( 1 );
  }

  // 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();

  data.channels = channels;
  try {
    dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &output, (void *)&data );
    dac.startStream();
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  std::cout << "\nPlaying raw file " << file << " (buffer frames = " << bufferFrames << ")." << std::endl;
  while ( 1 ) {
    SLEEP( 100 ); // wake every 100 ms to check if we're done
    if ( dac.isStreamRunning() == false ) break;
  }

 cleanup:
  fclose( data.fd );
  dac.closeStream();

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edi, %r13d
leal -0x7(%r13), %eax
cmpl $-0x4, %eax
jbe 0x47c5
movq %rsi, %r12
leaq 0x28(%rsp), %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4982
movq %rbx, %rdi
callq 0x4884
testl %eax, %eax
je 0x47ca
movq 0x8(%r12), %rdi
callq 0x4320
movl %eax, %r14d
movq 0x10(%r12), %rdi
callq 0x4320
movl %eax, 0x38(%rsp)
movq 0x18(%r12), %rbx
cmpl $0x5, %r13d
jb 0x469c
movq 0x20(%r12), %rdi
callq 0x4320
movl %eax, %ebp
cmpl $0x5, %r13d
je 0x469e
movq 0x28(%r12), %rdi
callq 0x4320
movl %eax, %r15d
jmp 0x469e
xorl %ebp, %ebp
leaq 0x3a95(%rip), %rsi      # 0x813a
movq %rbx, %rdi
callq 0x4230
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x47e4
movl $0x200, 0x34(%rsp)      # imm = 0x200
movl %ebp, 0x3c(%rsp)
movl %r14d, 0x40(%rsp)
movl %r15d, 0x44(%rsp)
testl %ebp, %ebp
jne 0x46e3
leaq 0x28(%rsp), %rdi
callq 0x4898
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rax
movl %r14d, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x13b(%rip), %rax      # 0x45c5
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
pushq $0x2
popq %rcx
leaq 0x34(%rsp), %r9
xorl %edx, %edx
movl 0x38(%rsp), %r8d
callq 0x4aa6
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x789c(%rip), %rdi      # 0xbfd0
leaq 0x3a20(%rip), %rsi      # 0x815b
callq 0x41d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x41d0
leaq 0x3a1c(%rip), %rsi      # 0x816e
movq %rax, %rdi
callq 0x41d0
movl 0x34(%rsp), %esi
movq %rax, %rdi
callq 0x4140
leaq 0x3a14(%rip), %rsi      # 0x8181
movq %rax, %rdi
callq 0x41d0
movq %rax, %rdi
callq 0x40d0
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
movq 0x28(%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
je 0x477d
movq 0x48(%rsp), %rdi
callq 0x41e0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x48b8
movq %rbx, %rdi
callq 0x4a96
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x455c
movq 0x77ff(%rip), %rdi      # 0xbfd0
leaq 0x3948(%rip), %rsi      # 0x8120
callq 0x41d0
xorl %edi, %edi
callq 0x4260
movq 0x77e5(%rip), %rdi      # 0xbfd0
leaq 0x394b(%rip), %rsi      # 0x813d
callq 0x41d0
pushq $0x1
popq %rdi
callq 0x4260
jmp 0x486f
jmp 0x486f
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4872
movq %rbx, %rdi
callq 0x4090
movq %rax, %rbx
movq 0x77b3(%rip), %rdi      # 0xbfd0
pushq $0xa
popq %rsi
callq 0x4210
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x41a0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x40d0
callq 0x4380
jmp 0x4795
jmp 0x486f
movq %rax, %rbx
callq 0x4380
jmp 0x4872
movq %rax, %rdi
callq 0x48ac
jmp 0x486f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4a96
movq %rbx, %rdi
callq 0x43a0