// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x8(%rbp)
jl 0x87d3
cmpl $0x6, -0x8(%rbp)
jle 0x87d8
callq 0x8670
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x8df0
leaq -0x38(%rbp), %rdi
callq 0x8b30
cmpl $0x1, %eax
jae 0x881e
movq 0xe7d8(%rip), %rdi      # 0x16fd0
leaq 0x9921(%rip), %rsi      # 0x12120
callq 0x8210
jmp 0x8806
xorl %edi, %edi
callq 0x8300
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x8b13
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x83f0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x83f0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
cmpl $0x4, -0x8(%rbp)
jle 0x8860
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x83f0
movl %eax, -0x20(%rbp)
cmpl $0x5, -0x8(%rbp)
jle 0x8876
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x83f0
movl %eax, -0x24(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x98b9(%rip), %rsi      # 0x1213a
callq 0x82d0
movq %rax, -0x80(%rbp)
jmp 0x888c
movq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x88ba
movq 0xe72e(%rip), %rdi      # 0x16fd0
leaq 0x9894(%rip), %rsi      # 0x1213d
callq 0x8210
jmp 0x88b0
movl $0x1, %edi
callq 0x8300
movl $0x200, -0x1c(%rbp)     # imm = 0x200
leaq -0x64(%rbp), %rdi
callq 0x8b70
jmp 0x88cc
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x88f0
leaq -0x38(%rbp), %rdi
callq 0x8ba0
movl %eax, -0x64(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x18(%rbp), %r8d
movq %rsp, %rax
leaq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x21c(%rip), %rcx      # 0x86f0
movq %rcx, (%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x10(%rax)
xorl %eax, %eax
movl %eax, %edx
leaq -0x38(%rbp), %rdi
leaq -0x64(%rbp), %rsi
movl $0x2, %ecx
leaq -0x1c(%rbp), %r9
callq 0x9000
jmp 0x893b
leaq -0x38(%rbp), %rdi
callq 0x8be0
jmp 0x8946
jmp 0x8a19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8b13
movq -0x40(%rbp), %rdi
callq 0x80b0
movq %rax, -0x70(%rbp)
movq 0xe655(%rip), %rdi      # 0x16fd0
movl $0xa, %esi
callq 0x82b0
movq %rax, -0x88(%rbp)
jmp 0x898e
movq -0x70(%rbp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x81e0
movq %rax, -0x90(%rbp)
jmp 0x89b3
movq -0x90(%rbp), %rdi
movl $0xa, %esi
callq 0x82b0
movq %rax, -0x98(%rbp)
jmp 0x89cd
movq -0x98(%rbp), %rdi
movq 0xe5dd(%rip), %rsi      # 0x16fb8
callq 0x8260
jmp 0x89e2
movl $0x2, -0x74(%rbp)
callq 0x8440
jmp 0x8a03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x8440
jmp 0x8a14
movl -0x74(%rbp), %eax
subl $0x2, %eax
je 0x8adc
jmp 0x8afe
jmp 0x8b13
movq 0xe5b0(%rip), %rdi      # 0x16fd0
leaq 0x9734(%rip), %rsi      # 0x1215b
callq 0x8210
movq %rax, -0xa0(%rbp)
jmp 0x8a35
movq -0xa0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x8210
movq %rax, -0xa8(%rbp)
jmp 0x8a4e
movq -0xa8(%rbp), %rdi
leaq 0x9712(%rip), %rsi      # 0x1216e
callq 0x8210
movq %rax, -0xb0(%rbp)
jmp 0x8a6a
movq -0xb0(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x8330
movq %rax, -0xb8(%rbp)
jmp 0x8a82
movq -0xb8(%rbp), %rdi
leaq 0x96f1(%rip), %rsi      # 0x12181
callq 0x8210
movq %rax, -0xc0(%rbp)
jmp 0x8a9e
movq -0xc0(%rbp), %rdi
movq 0xe50c(%rip), %rsi      # 0x16fb8
callq 0x8260
jmp 0x8ab3
jmp 0x8ab5
jmp 0x8ab7
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x8370
jmp 0x8ac3
leaq -0x38(%rbp), %rdi
callq 0x8c10
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x8ad8
jmp 0x8ada
jmp 0x8ab5
jmp 0x8adc
movq -0x58(%rbp), %rdi
callq 0x8220
jmp 0x8ae7
leaq -0x38(%rbp), %rdi
callq 0x8c40
movl $0x0, -0x4(%rbp)
movl $0x1, -0x74(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x8fc0
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x8fc0
movq -0x40(%rbp), %rdi
callq 0x8470
movq %rax, %rdi
callq 0x8c00
nopl (%rax)