// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
leal -0x8(%r15), %eax
cmpl $-0x6, %eax
jbe 0x4cab
movq %rsi, %r14
pushq $0x8
popq %rdi
callq 0x41d0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x4ea6
movq %r13, %rdi
callq 0x4d92
testl %eax, %eax
je 0x4cb0
movq 0x8(%r14), %rdi
callq 0x4300
movl %eax, %ebx
movl %eax, 0x30(%rsp)
movq 0x10(%r14), %rdi
callq 0x4300
movl %eax, 0x28(%rsp)
xorl %eax, %eax
cmpl $0x4, %r15d
jb 0x46bd
movq 0x18(%r14), %rdi
callq 0x4300
movl %eax, %r12d
cmpl $0x4, %r15d
jne 0x46c6
xorl %edx, %edx
xorl %ebp, %ebp
jmp 0x46fb
xorl %edx, %edx
xorl %r12d, %r12d
xorl %ebp, %ebp
jmp 0x46fd
movq 0x20(%r14), %rdi
callq 0x4300
movl %eax, %ebp
cmpl $0x6, %r15d
jb 0x46f9
movq 0x28(%r14), %rdi
callq 0x4300
movl %eax, %edx
cmpl $0x6, %r15d
je 0x46fb
movq 0x30(%r14), %rdi
movl %edx, %r14d
callq 0x4300
movl %r14d, %edx
jmp 0x46fd
xorl %edx, %edx
xorl %eax, %eax
movq (%r13), %rcx
movb $0x1, 0x1a0(%rcx)
movl $0x200, 0x2c(%rsp)      # imm = 0x200
movl %ebp, 0x50(%rsp)
movl %ebx, 0x54(%rsp)
movl %eax, 0x58(%rsp)
movl %r12d, 0x44(%rsp)
movl %ebx, 0x48(%rsp)
movl %edx, 0x4c(%rsp)
testl %r12d, %r12d
jne 0x473a
movq %r13, %rdi
callq 0x4da6
movl %eax, 0x44(%rsp)
testl %ebp, %ebp
jne 0x474a
movq %r13, %rdi
callq 0x4dba
movl %eax, 0x50(%rsp)
movl 0x28(%rsp), %r8d
movl %r8d, %eax
cvtsi2sd %rax, %xmm1
movsd 0x48a9(%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)
andl $0x0, 0x10(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq -0x1d7(%rip), %rax      # 0x45c4
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
pushq $0x8
popq %rcx
leaq 0x2c(%rsp), %r9
movq %r13, %rdi
callq 0x4fca
movq 0x8808(%rip), %rdi      # 0xcfc8
leaq 0x4a36(%rip), %rsi      # 0x91fd
callq 0x41c0
movq 0x8805(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4280
pushq $0xa
popq %rbp
movq 0x87de(%rip), %rbx      # 0xcfc8
leaq 0x4a2a(%rip), %r15      # 0x921b
leaq 0x4a37(%rip), %r12      # 0x922f
subl $0x1, %ebp
jb 0x4842
andl $0x0, 0x38(%rsp)
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41c0
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x4290
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41c0
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x4290
jmp 0x47f8
movq %r13, %rdi
callq 0x4dce
movsd 0x60(%rsp), %xmm0
mulsd 0x47b8(%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 -0x2c0(%rip), %rax      # 0x45c4
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
pushq $0x8
popq %rcx
leaq 0x2c(%rsp), %r9
movq %r13, %rdi
movl 0x28(%rsp), %r8d
callq 0x4fca
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4370
movq 0x8701(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x4210
movq 0x86fa(%rip), %rdi      # 0xcfc8
leaq 0x4976(%rip), %rsi      # 0x924b
callq 0x41c0
movq 0x86f7(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4280
xorl %ebp, %ebp
movq 0x86d1(%rip), %rbx      # 0xcfc8
leaq 0x491d(%rip), %r15      # 0x921b
leaq 0x4968(%rip), %r12      # 0x926d
cmpl $0xa, %ebp
je 0x4956
andl $0x0, 0x38(%rsp)
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41c0
movq (%r13), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x493d
movl $0x1388, %edi           # imm = 0x1388
callq 0x4290
jmp 0x4924
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41c0
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x4290
incl %ebp
jmp 0x4905
movq %r13, %rdi
callq 0x4dce
movl $0x2, 0x40(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x3bd(%rip), %rax      # 0x45c4
movq %rax, (%rsp)
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
pushq $0x8
popq %rcx
leaq 0x2c(%rsp), %r9
movq %r13, %rdi
movl 0x28(%rsp), %r8d
callq 0x4fca
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4370
movq 0x8604(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x4210
movq 0x85fd(%rip), %rdi      # 0xcfc8
leaq 0x4879(%rip), %rsi      # 0x924b
callq 0x41c0
movq 0x85fa(%rip), %rbx      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %rbx, %rdi
callq 0x4280
xorl %ebp, %ebp
movq 0x85d4(%rip), %r14      # 0xcfc8
leaq 0x4820(%rip), %r15      # 0x921b
leaq 0x489a(%rip), %r12      # 0x929c
cmpl $0xa, %ebp
je 0x4a53
andl $0x0, 0x38(%rsp)
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq %r14, %rdi
movq %r15, %rsi
callq 0x41c0
movq (%r13), %rax
cmpl $0x2, 0x1bc(%rax)
jne 0x4a3a
movl $0x1388, %edi           # imm = 0x1388
callq 0x4290
jmp 0x4a21
movq %r14, %rdi
movq %r12, %rsi
callq 0x41c0
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x4290
incl %ebp
jmp 0x4a02
movq %r13, %rdi
callq 0x4dce
andl $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 0x4370
movq 0x8540(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x4210
movq 0x8539(%rip), %rdi      # 0xcfc8
leaq 0x47b5(%rip), %rsi      # 0x924b
callq 0x41c0
movq 0x8536(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
pushq $0xa
popq %r12
leaq 0x2c(%rsp), %rbp
movq 0x850c(%rip), %r14      # 0xcfc8
leaq 0x4808(%rip), %rbx      # 0x92cb
leaq 0x4819(%rip), %r15      # 0x92e3
subl $0x1, %r12d
jb 0x4b60
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x52b(%rip), %rax      # 0x45c4
movq %rax, (%rsp)
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
pushq $0x8
popq %rcx
movl 0x28(%rsp), %r8d
movq %rbp, %r9
callq 0x4fca
andl $0x0, 0x38(%rsp)
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x41c0
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x4290
movq (%r13), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movq %r13, %rdi
callq 0x4dce
movq %r14, %rdi
movq %r15, %rsi
callq 0x41c0
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x4290
jmp 0x4aca
movq %r13, %rdi
callq 0x4fba
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x41e0
movq 0x845e(%rip), %rdi      # 0xcfd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x4370
movq 0x8431(%rip), %rax      # 0xcfc0
movq (%rax), %rdi
callq 0x4210
movq 0x842a(%rip), %rdi      # 0xcfc8
leaq 0x46a6(%rip), %rsi      # 0x924b
callq 0x41c0
movq 0x8427(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4280
pushq $0xa
popq %r15
pushq $0x8
popq %r14
movq 0x83fe(%rip), %rbp      # 0xcfc8
leaq 0x475e(%rip), %r12      # 0x932f
subl $0x1, %r15d
jb 0x4d80
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x41d0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x4ea6
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x64a(%rip), %rax      # 0x45c4
movq %rax, (%rsp)
movq %rbx, %r13
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x44(%rsp), %rdx
movq %r14, %rcx
movl 0x28(%rsp), %r8d
leaq 0x2c(%rsp), %r9
callq 0x4fca
andl $0x0, 0x38(%rsp)
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rbx, %r13
callq *0x40(%rax)
movq %rbx, %r13
movq %rbp, %rdi
leaq 0x46b8(%rip), %rsi      # 0x930a
callq 0x41c0
movq %rbx, %r13
movl $0x61a80, %edi          # imm = 0x61A80
callq 0x4290
movq (%rbx), %rdi
movq (%rdi), %rax
movq %rbx, %r13
callq *0x48(%rax)
movq %rbx, %rdi
callq 0x4dce
movq %rbx, %rdi
callq 0x4fba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41e0
xorl %r13d, %r13d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x41c0
xorl %r13d, %r13d
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x4290
jmp 0x4bd1
callq 0x454c
movq 0x8311(%rip), %rdi      # 0xcfc8
leaq 0x4525(%rip), %rsi      # 0x91e3
callq 0x41c0
pushq $0x1
popq %rdi
callq 0x4240
movq %rax, %r14
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x41e0
movq %r14, %rdi
callq 0x4390
movq %rdx, %r15
movq %rax, %r14
jmp 0x4d02
jmp 0x4d3a
jmp 0x4d3a
jmp 0x4d3a
jmp 0x4d3a
movq %rdx, %r15
movq %rax, %r14
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x41e0
xorl %r13d, %r13d
jmp 0x4d15
jmp 0x4d3a
jmp 0x4d3a
jmp 0x4d3a
jmp 0x4d3a
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0x4cd9
movq %r14, %rdi
callq 0x4090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4360
testq %r13, %r13
jne 0x4d58
jmp 0x4d80
jmp 0x4d3a
movq %rax, %r14
cmpl $0x1, %edx
jne 0x4cd9
movq %r14, %rdi
callq 0x4090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4360
movq (%r13), %rax
cmpl $-0x32, 0x1bc(%rax)
je 0x4d6d
movq %r13, %rdi
callq 0x4dce
movq %r13, %rdi
callq 0x4fba
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x41e0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop