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

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

  RtAudio adc;
  if ( adc.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 )
    time = (double) atof( argv[3] );
  if ( argc > 4 )
    device = (unsigned int) atoi( argv[4] );
  if ( argc > 5 )
    offset = (unsigned int) atoi( argv[5] );

  // Let RtAudio print messages to stderr.
  adc.showWarnings( true );

  // Set our stream parameters for input only.
  bufferFrames = 512;
  RtAudio::StreamParameters iParams;
  if ( device == 0 )
    iParams.deviceId = adc.getDefaultInputDevice();
  else
    iParams.deviceId = device;
  iParams.nChannels = channels;
  iParams.firstChannel = offset;

  InputData data;
  data.buffer = 0;
  try {
    adc.openStream( NULL, &iParams, FORMAT, fs, &bufferFrames, &input, (void *)&data );
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  data.bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
  data.totalFrames = (unsigned long) (fs * time);
  data.frameCounter = 0;
  data.channels = channels;
  unsigned long totalBytes;
  totalBytes = data.totalFrames * channels * sizeof( MY_TYPE );

  // Allocate the entire data buffer before starting stream.
  data.buffer = (MY_TYPE*) malloc( totalBytes );
  if ( data.buffer == 0 ) {
    std::cout << "Memory allocation error ... quitting!\n";
    goto cleanup;
  }

  try {
    adc.startStream();
  }
  catch ( RtAudioError& e ) {
    std::cout << '\n' << e.getMessage() << '\n' << std::endl;
    goto cleanup;
  }

  std::cout << "\nRecording for " << time << " seconds ... writing file 'record.raw' (buffer frames = " << bufferFrames << ")." << std::endl;
  while ( adc.isStreamRunning() ) {
    SLEEP( 100 ); // wake every 100 ms to check if we're done
  }

  // Now write the entire data to the file.
  fd = fopen( "record.raw", "wb" );
  fwrite( data.buffer, sizeof( MY_TYPE ), data.totalFrames * channels, fd );
  fclose( fd );

 cleanup:
  if ( adc.isStreamOpen() ) adc.closeStream();
  if ( data.buffer ) free( data.buffer );

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edi, %r12d
leal -0x7(%r12), %eax
cmpl $-0x5, %eax
jbe 0x58e1
movq %rsi, %r15
leaq 0x28(%rsp), %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5aee
movq %rbx, %rdi
callq 0x59ee
testl %eax, %eax
je 0x58e6
movq 0x8(%r15), %rdi
callq 0x5330
movl %eax, %ebx
movq 0x10(%r15), %rdi
callq 0x5330
movl %eax, %ebp
cmpl $0x4, %r12d
jb 0x56ef
movq 0x18(%r15), %rdi
callq 0x5280
movsd %xmm0, 0x38(%rsp)
cmpl $0x4, %r12d
je 0x56fd
movq 0x20(%r15), %rdi
callq 0x5330
movl %eax, %r13d
cmpl $0x6, %r12d
jb 0x5700
movq 0x28(%r15), %rdi
callq 0x5330
movl %eax, %r14d
jmp 0x5700
movsd 0x3911(%rip), %xmm0     # 0x9008
movsd %xmm0, 0x38(%rsp)
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movb $0x1, 0x1a0(%rax)
movl $0x200, 0x34(%rsp)      # imm = 0x200
andq $0x0, 0x44(%rsp)
andl $0x0, 0x4c(%rsp)
testl %r13d, %r13d
jne 0x5731
leaq 0x28(%rsp), %rdi
callq 0x5a02
movl %eax, %r13d
leaq 0x44(%rsp), %rdx
movl %r13d, (%rdx)
movl %ebx, 0x4(%rdx)
movl %r14d, 0x8(%rdx)
leaq 0x50(%rsp), %rax
andq $0x0, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq -0x16a(%rip), %rax      # 0x55f5
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
pushq $0x2
popq %rcx
leaq 0x34(%rsp), %r9
xorl %esi, %esi
movl %ebp, %r8d
callq 0x5c12
movl 0x34(%rsp), %eax
imull %ebx, %eax
addq %rax, %rax
movl %ebp, %ecx
cvtsi2sd %rcx, %xmm0
movq %rax, 0x58(%rsp)
mulsd 0x38(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x3866(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movq %rdi, 0x60(%rsp)
andq $0x0, 0x68(%rsp)
movl %ebx, 0x70(%rsp)
movl %ebx, %ebx
imulq %rbx, %rdi
addq %rdi, %rdi
callq 0x5290
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x5891
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq 0x77de(%rip), %rdi      # 0xcfd0
leaq 0x39a2(%rip), %rsi      # 0x919b
callq 0x51d0
movq %rax, %rdi
movsd 0x38(%rsp), %xmm0
callq 0x5360
leaq 0x3998(%rip), %rsi      # 0x91ab
movq %rax, %rdi
callq 0x51d0
movl 0x34(%rsp), %esi
movq %rax, %rdi
callq 0x5140
leaq 0x39b6(%rip), %rsi      # 0x91e4
movq %rax, %rdi
callq 0x51d0
movq %rax, %rdi
callq 0x50d0
movq 0x28(%rsp), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x5858
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x52c0
jmp 0x583e
leaq 0x3988(%rip), %rdi      # 0x91e7
leaq 0x398c(%rip), %rsi      # 0x91f2
callq 0x5230
movq %rax, %r14
movq 0x50(%rsp), %rdi
imulq 0x60(%rsp), %rbx
pushq $0x2
popq %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x5430
movq %r14, %rdi
callq 0x51e0
jmp 0x58a4
movq 0x7738(%rip), %rdi      # 0xcfd0
leaq 0x38d5(%rip), %rsi      # 0x9174
callq 0x51d0
movq 0x28(%rsp), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x58bc
leaq 0x28(%rsp), %rdi
callq 0x5a22
movq 0x50(%rsp), %rdi
callq 0x5240
leaq 0x28(%rsp), %rdi
callq 0x5c02
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x558c
movq 0x76e3(%rip), %rdi      # 0xcfd0
leaq 0x3866(%rip), %rsi      # 0x915a
callq 0x51d0
pushq $0x1
popq %rdi
callq 0x5260
jmp 0x59d8
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x59db
movq %rbx, %rdi
callq 0x5090
movq %rax, %rbx
movq 0x76ac(%rip), %rdi      # 0xcfd0
pushq $0xa
popq %rsi
callq 0x5210
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x51a0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x5210
movq %rax, %rdi
callq 0x50d0
callq 0x53a0
jmp 0x58a4
jmp 0x59d8
movq %rax, %rbx
callq 0x53a0
jmp 0x59db
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x59db
movq %rbx, %rdi
callq 0x5090
movq %rax, %rbx
movq 0x764a(%rip), %rdi      # 0xcfd0
pushq $0xa
popq %rsi
callq 0x5210
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x51a0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x5210
movq %rax, %rdi
callq 0x50d0
callq 0x53a0
jmp 0x58a4
jmp 0x59d8
movq %rax, %rbx
callq 0x53a0
jmp 0x59db
movq %rax, %rdi
callq 0x5a16
jmp 0x59d8
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5c02
movq %rbx, %rdi
callq 0x53c0
nop