// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d
leal -0x7(%r12), %eax
cmpl $-0x4, %eax
jbe 0x48a2
movq %rsi, %r15
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4a90
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x48a7
movq 0x8(%r15), %rdi
callq 0x4350
movl %eax, %r14d
movq 0x10(%r15), %rdi
callq 0x4350
movl %eax, 0x38(%rsp)
movq 0x18(%r15), %rbx
xorl %r13d, %r13d
movl $0x0, %ebp
cmpl $0x5, %r12d
jl 0x46fc
movq 0x20(%r15), %rdi
callq 0x4350
movl %eax, %ebp
cmpl $0x6, %r12d
jl 0x470e
movq 0x28(%r15), %rdi
callq 0x4350
movl %eax, %r13d
leaq 0x4a25(%rip), %rsi      # 0x913a
movq %rbx, %rdi
callq 0x4250
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x48c1
movl $0x200, 0x34(%rsp)      # imm = 0x200
movl %ebp, 0x3c(%rsp)
movl %r14d, 0x40(%rsp)
movl %r13d, 0x44(%rsp)
testl %ebp, %ebp
jne 0x4754
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rax
movl %r14d, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x13c(%rip), %rax      # 0x4635
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0x34(%rsp), %r9
movl $0x2, %ecx
xorl %edx, %edx
movl 0x38(%rsp), %r8d
callq 0x4c24
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x7829(%rip), %r14      # 0xbfd0
leaq 0x49ad(%rip), %rsi      # 0x915b
movl $0x12, %edx
movq %r14, %rdi
callq 0x4230
testq %rbx, %rbx
je 0x47dc
movq %rbx, %rdi
callq 0x40c0
movq 0x7801(%rip), %rdi      # 0xbfd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4230
jmp 0x47f4
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x43c0
movq 0x77d5(%rip), %rdi      # 0xbfd0
leaq 0x496c(%rip), %rsi      # 0x916e
movl $0x12, %edx
callq 0x4230
movl 0x34(%rsp), %esi
movq 0x77b9(%rip), %rdi      # 0xbfd0
callq 0x4150
movq %rax, %rbx
leaq 0x495b(%rip), %rsi      # 0x9181
movl $0x2, %edx
movq %rax, %rdi
callq 0x4230
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x41e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4160
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42c0
movq 0x28(%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
je 0x485a
movq 0x48(%rsp), %rdi
callq 0x4200
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
leaq 0x28(%rsp), %rdi
callq 0x4c14
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x45cc
movq 0x7722(%rip), %rdi      # 0xbfd0
leaq 0x486b(%rip), %rsi      # 0x9120
callq 0x41f0
xorl %edi, %edi
callq 0x4280
movq 0x7708(%rip), %rdi      # 0xbfd0
leaq 0x486e(%rip), %rsi      # 0x913d
callq 0x41f0
movl $0x1, %edi
callq 0x4280
jmp 0x48ec
jmp 0x4975
jmp 0x4975
jmp 0x48ec
movq %rax, %rdi
callq 0x498a
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x4978
movq %rbx, %rdi
callq 0x40a0
movq %rax, %rbx
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x76ba(%rip), %rdi      # 0xbfd0
movl $0x1, %edx
callq 0x4230
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r14, %rdi
callq 0x4230
leaq 0x27(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4230
movq %rax, %rdi
callq 0x40d0
callq 0x43b0
jmp 0x4872
jmp 0x4975
movq %rax, %rbx
callq 0x43b0
jmp 0x4978
jmp 0x48ec
jmp 0x4975
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4c14
movq %rbx, %rdi
callq 0x43e0