// File: /workspace/github_cpp_makefile_star2_O3/tobias93[P]piano/rtaudio/tests/teststops.cpp
// Function: main
int main( int argc, char *argv[] )
{
  unsigned int bufferFrames, fs, oDevice = 0, iDevice = 0, iOffset = 0, oOffset = 0;
  unsigned int runtime, pausetime;
  char input;

  // minimal command-line checking
  if (argc < 3 || argc > 7 ) usage();

  RtAudio *adc = new RtAudio();
  if ( adc->getDeviceCount() < 1 ) {
    std::cout << "\nNo audio devices found!\n";
    exit( 1 );
  }

  MyData mydata;
  mydata.channels = (unsigned int) atoi( argv[1] );
  fs = (unsigned int) atoi( argv[2] );
  if ( argc > 3 )
    iDevice = (unsigned int) atoi( argv[3] );
  if ( argc > 4 )
    oDevice = (unsigned int) atoi(argv[4]);
  if ( argc > 5 )
    iOffset = (unsigned int) atoi(argv[5]);
  if ( argc > 6 )
    oOffset = (unsigned int) atoi(argv[6]);

  // Let RtAudio print messages to stderr.
  adc->showWarnings( true );

  runtime = static_cast<unsigned int>(RUNTIME * 1000);
  pausetime = static_cast<unsigned int>(PAUSETIME * 1000);

  // Set our stream parameters for a duplex stream.
  bufferFrames = 512;
  RtAudio::StreamParameters oParams, iParams;
  oParams.deviceId = oDevice;
  oParams.nChannels = mydata.channels;
  oParams.firstChannel = oOffset;

  iParams.deviceId = iDevice;
  iParams.nChannels = mydata.channels;
  iParams.firstChannel = iOffset;

  if ( iDevice == 0 )
    iParams.deviceId = adc->getDefaultInputDevice();
  if ( oDevice == 0 )
    oParams.deviceId = adc->getDefaultOutputDevice();

  // First, test external stopStream() calls.
  mydata.pulseCount = static_cast<unsigned int>(PULSE_RATE * fs);
  mydata.nFrames = 50 * fs;
  mydata.returnValue = 0;
  try {
    adc->openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &pulse, (void *)&mydata );

    std::cout << "Press <enter> to start test.\n";
    std::cin.get( input );

    for (int i=0; i<REPETITIONS; i++ ) {
      mydata.frameCounter = 0;
      adc->startStream();
      std::cout << "Stream started ... ";
      SLEEP( runtime );
      adc->stopStream();
      std::cout << "stream externally stopped.\n";
      SLEEP( pausetime );
    }
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  adc->closeStream();

  // Next, test internal stopStream() calls.
  mydata.nFrames = (unsigned int) (RUNTIME * fs);
  mydata.returnValue = 1;
  try {
    adc->openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &pulse, (void *)&mydata );

    std::cin.clear();
    fflush(stdin);
    std::cout << "\nPress <enter> to continue test.\n";
    std::cin.get( input );

    for (int i=0; i<REPETITIONS; i++ ) {
      mydata.frameCounter = 0;
      adc->startStream();
      std::cout << "Stream started ... ";
      while ( adc->isStreamRunning() ) SLEEP( 5 );
      std::cout << "stream stopped via callback return value = 1.\n";
      SLEEP( pausetime );
    }
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  adc->closeStream();

  // Test internal abortStream() calls.
  mydata.returnValue = 2;
  try {
    adc->openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &pulse, (void *)&mydata );
    std::cin.clear();
    fflush(stdin);
    std::cout << "\nPress <enter> to continue test.\n";
    std::cin.get( input );

    for (int i=0; i<REPETITIONS; i++ ) {
      mydata.frameCounter = 0;
      adc->startStream();
      std::cout << "Stream started ... ";
      while ( adc->isStreamRunning() ) SLEEP( 5 );
      std::cout << "stream aborted via callback return value = 2.\n";
      SLEEP( pausetime );
    }
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  adc->closeStream();

  // Test consecutive stream re-opening.
  mydata.returnValue = 0;
  mydata.nFrames = 50 * fs;
  try {

    std::cin.clear();
    fflush(stdin);
    std::cout << "\nPress <enter> to continue test.\n";
    std::cin.get( input );

    for (int i=0; i<REPETITIONS; i++ ) {
      adc->openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &pulse, (void *)&mydata );
      mydata.frameCounter = 0;
      adc->startStream();
      std::cout << "New stream started ... ";
      SLEEP( runtime );
      adc->stopStream();
      adc->closeStream();
      std::cout << "stream stopped externally and closed.\n";
      SLEEP( pausetime );
    }
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

  delete adc;
  adc = 0;

  // Test consecutive RtAudio creating and deletion.
  try {

    std::cin.clear();
    fflush(stdin);
    std::cout << "\nPress <enter> to continue test.\n";
    std::cin.get( input );

    for (int i=0; i<REPETITIONS; i++ ) {
      adc = new RtAudio();      
      adc->openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &pulse, (void *)&mydata );
      mydata.frameCounter = 0;
      adc->startStream();
      std::cout << "New instance and stream started ... ";
      SLEEP( runtime );
      adc->stopStream();
      adc->closeStream();
      delete adc;
      adc = 0;
      std::cout << "stream stopped and instance deleted.\n";
      SLEEP( pausetime );
    }
  }
  catch ( RtAudioError& e ) {
    e.printMessage();
    goto cleanup;
  }

 cleanup:
  if ( adc && adc->isStreamOpen() ) adc->closeStream();
  if ( adc ) delete adc;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edi, %r12d
leal -0x8(%r12), %eax
cmpl $-0x6, %eax
jbe 0x4dac
movq %rsi, %r14
movl $0x8, %edi
callq 0x41e0
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
callq 0x4fae
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4db1
movq 0x8(%r14), %rdi
callq 0x4320
movl %eax, %ebx
movl %eax, 0x30(%rsp)
movq 0x10(%r14), %rdi
callq 0x4320
movl %eax, 0x28(%rsp)
xorl %eax, %eax
cmpl $0x4, %r12d
jb 0x4750
movq 0x18(%r14), %rdi
callq 0x4320
movl %eax, %r13d
cmpl $0x4, %r12d
jne 0x4759
xorl %ecx, %ecx
xorl %ebp, %ebp
jmp 0x478e
xorl %ecx, %ecx
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x4790
movq 0x20(%r14), %rdi
callq 0x4320
movl %eax, %ebp
cmpl $0x6, %r12d
jb 0x478c
movq 0x28(%r14), %rdi
callq 0x4320
movl %eax, %ecx
cmpl $0x6, %r12d
je 0x478e
movq 0x30(%r14), %rdi
movl %ecx, %r14d
callq 0x4320
movl %r14d, %ecx
jmp 0x4790
xorl %ecx, %ecx
xorl %eax, %eax
movq (%r15), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x2c(%rsp)      # imm = 0x200
movl %ebp, 0x50(%rsp)
movl %ebx, 0x54(%rsp)
movl %eax, 0x58(%rsp)
movl %r13d, 0x44(%rsp)
movl %ebx, 0x48(%rsp)
movl %ecx, 0x4c(%rsp)
testl %r13d, %r13d
jne 0x47ca
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, 0x44(%rsp)
testl %ebp, %ebp
jne 0x47db
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x50(%rsp)
movl 0x28(%rsp), %r8d
movl %r8d, %eax
cvtsi2sd %rax, %xmm1
movsd 0x4818(%rip), %xmm0     # 0x9008
movsd %xmm1, 0x60(%rsp)
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
leaq 0x30(%rsp), %rcx
movl %eax, 0x4(%rcx)
imull $0x32, %r8d, %eax
movl %eax, 0x5c(%rsp)
movl %eax, 0xc(%rcx)
movl $0x0, 0x10(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq -0x21b(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
callq 0x5142
movq 0x8772(%rip), %rdi      # 0xcfc8
leaq 0x49a0(%rip), %rsi      # 0x91fd
movl $0x1d, %edx
callq 0x4200
movq 0x876a(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4290
movl $0xa, %ebp
movq 0x8741(%rip), %rbx      # 0xcfc8
leaq 0x498d(%rip), %r12      # 0x921b
leaq 0x499a(%rip), %r13      # 0x922f
movl $0x0, 0x38(%rsp)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x13, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4200
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x42a0
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movl $0x1b, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
decl %ebp
jne 0x4895
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movsd 0x60(%rsp), %xmm0
mulsd 0x4712(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %rax
movl %eax, 0x3c(%rsp)
movl $0x1, 0x40(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x316(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
movl 0x28(%rsp), %r8d
callq 0x5142
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x8651(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x8652(%rip), %rdi      # 0xcfc8
leaq 0x48ce(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x864a(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4290
xorl %ebp, %ebp
movq 0x8624(%rip), %rbx      # 0xcfc8
leaq 0x4870(%rip), %r12      # 0x921b
leaq 0x48bb(%rip), %r13      # 0x926d
movl $0x0, 0x38(%rsp)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x13, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4200
movq (%r15), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x49eb
movl $0x1388, %edi           # imm = 0x1388
callq 0x42a0
jmp 0x49d3
movl $0x2e, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
incl %ebp
cmpl $0xa, %ebp
jne 0x49b2
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x2, 0x40(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x424(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
movl 0x28(%rsp), %r8d
callq 0x5142
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x8543(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x8544(%rip), %rdi      # 0xcfc8
leaq 0x47c0(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x853c(%rip), %rbx      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %rbx, %rdi
callq 0x4290
xorl %ebp, %ebp
movq 0x8516(%rip), %r14      # 0xcfc8
leaq 0x4762(%rip), %r12      # 0x921b
leaq 0x47dc(%rip), %r13      # 0x929c
movl $0x0, 0x38(%rsp)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x13, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4200
movq (%r15), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x4af9
movl $0x1388, %edi           # imm = 0x1388
callq 0x42a0
jmp 0x4ae1
movl $0x2e, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
incl %ebp
cmpl $0xa, %ebp
jne 0x4ac0
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x0, 0x40(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x846d(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x846e(%rip), %rdi      # 0xcfc8
leaq 0x46ea(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x8466(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4290
movl $0xa, %r12d
leaq 0x2c(%rsp), %r13
movq 0x843a(%rip), %rbp      # 0xcfc8
leaq 0x4736(%rip), %r14      # 0x92cb
leaq 0x4747(%rip), %rbx      # 0x92e3
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x5a3(%rip), %rax      # 0x4614
movq %rax, (%rsp)
movl $0x8, %ecx
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
movl 0x28(%rsp), %r8d
movq %r13, %r9
callq 0x5142
movl $0x0, 0x38(%rsp)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x17, %edx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4200
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x42a0
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x26, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
decl %r12d
jne 0x4b9c
movq %r15, %rdi
callq 0x5132
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
movq 0x8382(%rip), %rdi      # 0xcfd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x4390
movq 0x834d(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x834e(%rip), %rdi      # 0xcfc8
leaq 0x45ca(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x8346(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4290
movl $0xa, %r12d
movq 0x831f(%rip), %r13      # 0xcfc8
leaq 0x465a(%rip), %rbp      # 0x930a
leaq 0x4678(%rip), %r14      # 0x932f
movl $0x8, %edi
xorl %r15d, %r15d
callq 0x41e0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x4fae
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x6d8(%rip), %rax      # 0x4614
movq %rax, (%rsp)
movl $0x8, %ecx
movq %rbx, %r15
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
movl 0x28(%rsp), %r8d
leaq 0x2c(%rsp), %r9
callq 0x5142
movl $0x0, 0x38(%rsp)
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rbx, %r15
callq *0x40(%rax)
movl $0x24, %edx
movq %rbx, %r15
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4200
movq %rbx, %r15
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x42a0
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rbx, %r15
callq *0x48(%rax)
movq (%rbx), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq %rbx, %rdi
callq 0x5132
movl $0x8, %esi
movq %rbx, %rdi
callq 0x41f0
movl $0x25, %edx
xorl %r15d, %r15d
movq %r13, %rdi
movq %r14, %rsi
callq 0x4200
xorl %r15d, %r15d
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
decl %r12d
jne 0x4cb7
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x459c
movq 0x8210(%rip), %rdi      # 0xcfc8
leaq 0x4424(%rip), %rsi      # 0x91e3
callq 0x41d0
movl $0x1, %edi
callq 0x4250
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
jmp 0x4e1c
movq %rax, %r14
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
movq %r14, %rdi
callq 0x43b0
movq %rdx, %r12
movq %rax, %r14
jmp 0x4e15
jmp 0x4e5a
jmp 0x4e5a
jmp 0x4e5a
jmp 0x4e5a
movq %rdx, %r12
movq %rax, %r14
movl $0x8, %esi
movq %rbx, %rdi
callq 0x41f0
xorl %r15d, %r15d
jmp 0x4e32
jmp 0x4e1c
movq %rax, %rdi
callq 0x4ea9
jmp 0x4e5a
jmp 0x4e5a
jmp 0x4e5a
jmp 0x4e5a
movq %rdx, %r12
movq %rax, %r14
cmpl $0x2, %r12d
jne 0x4dea
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4380
testq %r15, %r15
jne 0x4e78
jmp 0x4d9b
jmp 0x4e5a
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4dea
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4380
movq (%r15), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4e8a
movq (%rdi), %rax
callq *0x38(%rax)
movq %r15, %rdi
callq 0x5132
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
jmp 0x4d9b
jmp 0x4e1c