// File: /workspace/github_cpp_makefile_star2_O1/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, %r14d
leal -0x8(%r14), %eax
cmpl $-0x6, %eax
jbe 0x4df2
movq %rsi, %rbx
movl $0x8, %edi
callq 0x41e0
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
callq 0x4fac
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testl %eax, %eax
je 0x4df7
movq 0x8(%rbx), %rdi
callq 0x4320
movl %eax, 0x30(%rsp)
movl %eax, 0x40(%rsp)
movq 0x10(%rbx), %rdi
callq 0x4320
movl %eax, 0x28(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, %r13d
cmpl $0x4, %r14d
jl 0x474f
movq 0x18(%rbx), %rdi
callq 0x4320
movl %eax, %r13d
cmpl $0x5, %r14d
jl 0x4762
movq 0x20(%rbx), %rdi
callq 0x4320
movl %eax, 0x60(%rsp)
xorl %r12d, %r12d
movl $0x0, %ebp
cmpl $0x6, %r14d
jl 0x477b
movq 0x28(%rbx), %rdi
callq 0x4320
movl %eax, %ebp
cmpl $0x7, %r14d
jl 0x478d
movq 0x30(%rbx), %rdi
callq 0x4320
movl %eax, %r12d
movq (%r15), %rdi
movb $0x1, 0x1a0(%rdi)
movl $0x200, 0x2c(%rsp)      # imm = 0x200
movq $0x0, 0x34(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x60(%rsp), %ebx
movl %ebx, 0x34(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x38(%rsp)
movl %r12d, 0x3c(%rsp)
movl %r13d, 0x54(%rsp)
movl %eax, 0x58(%rsp)
movl %ebp, 0x5c(%rsp)
testl %r13d, %r13d
jne 0x47e1
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, 0x54(%rsp)
testl %ebx, %ebx
jne 0x47f2
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x34(%rsp)
movl 0x28(%rsp), %r8d
movl %r8d, %eax
cvtsi2sd %rax, %xmm1
movsd 0x4801(%rip), %xmm0     # 0x9008
movsd %xmm1, 0x60(%rsp)
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
leaq 0x40(%rsp), %rcx
movl %eax, 0x4(%rcx)
imull $0x32, %r8d, %eax
movl %eax, 0x30(%rsp)
movl %eax, 0xc(%rcx)
movl $0x0, 0x10(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq -0x232(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x34(%rsp), %rsi
leaq 0x54(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
callq 0x5140
movq 0x875b(%rip), %rdi      # 0xcfc8
leaq 0x4989(%rip), %rsi      # 0x91fd
movl $0x1d, %edx
callq 0x4200
movq 0x8753(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4290
movl $0xa, %ebp
movq 0x872a(%rip), %rbx      # 0xcfc8
leaq 0x4976(%rip), %r12      # 0x921b
leaq 0x4983(%rip), %r13      # 0x922f
movl $0x0, 0x48(%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 0x48ac
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movsd 0x60(%rsp), %xmm0
mulsd 0x46fb(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %rax
movl %eax, 0x4c(%rsp)
movl $0x1, 0x50(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x32d(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x34(%rsp), %rsi
leaq 0x54(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
movl 0x28(%rsp), %r8d
callq 0x5140
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x863a(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x863b(%rip), %rdi      # 0xcfc8
leaq 0x48b7(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x8633(%rip), %r14      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %r14, %rdi
callq 0x4290
xorl %ebp, %ebp
movq 0x860d(%rip), %rbx      # 0xcfc8
leaq 0x4859(%rip), %r12      # 0x921b
leaq 0x48a4(%rip), %r13      # 0x926d
movl $0x0, 0x48(%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 0x4a02
movl $0x1388, %edi           # imm = 0x1388
callq 0x42a0
jmp 0x49ea
movl $0x2e, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
incl %ebp
cmpl $0xa, %ebp
jne 0x49c9
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x2, 0x50(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x43b(%rip), %rax      # 0x4614
movq %rax, (%rsp)
leaq 0x34(%rsp), %rsi
leaq 0x54(%rsp), %rdx
leaq 0x2c(%rsp), %r9
movl $0x8, %ecx
movq %r15, %rdi
movl 0x28(%rsp), %r8d
callq 0x5140
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x852c(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x852d(%rip), %rdi      # 0xcfc8
leaq 0x47a9(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x8525(%rip), %rbx      # 0xcfd8
leaq 0x27(%rsp), %rsi
movq %rbx, %rdi
callq 0x4290
xorl %ebp, %ebp
movq 0x84ff(%rip), %r14      # 0xcfc8
leaq 0x474b(%rip), %r12      # 0x921b
leaq 0x47c5(%rip), %r13      # 0x929c
movl $0x0, 0x48(%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 0x4b10
movl $0x1388, %edi           # imm = 0x1388
callq 0x42a0
jmp 0x4af8
movl $0x2e, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x4200
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x42a0
incl %ebp
cmpl $0xa, %ebp
jne 0x4ad7
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl $0x0, 0x50(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4390
movq 0x8456(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x8457(%rip), %rdi      # 0xcfc8
leaq 0x46d3(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x844f(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4290
movl $0xa, %r12d
leaq 0x2c(%rsp), %r13
movq 0x8423(%rip), %rbp      # 0xcfc8
leaq 0x471f(%rip), %r14      # 0x92cb
leaq 0x4730(%rip), %rbx      # 0x92e3
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x5ba(%rip), %rax      # 0x4614
movq %rax, (%rsp)
movl $0x8, %ecx
movq %r15, %rdi
leaq 0x34(%rsp), %rsi
leaq 0x54(%rsp), %rdx
movl 0x28(%rsp), %r8d
movq %r13, %r9
callq 0x5140
movl $0x0, 0x48(%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 0x4bb3
movq %r15, %rdi
callq 0x5130
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
movq 0x836b(%rip), %rdi      # 0xcfd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x4390
movq 0x8336(%rip), %rax      # 0xcfb8
movq (%rax), %rdi
callq 0x4220
movq 0x8337(%rip), %rdi      # 0xcfc8
leaq 0x45b3(%rip), %rsi      # 0x924b
movl $0x21, %edx
callq 0x4200
movq 0x832f(%rip), %rdi      # 0xcfd8
leaq 0x27(%rsp), %rsi
callq 0x4290
movl $0xa, %r12d
movq 0x8308(%rip), %r13      # 0xcfc8
leaq 0x4643(%rip), %rbp      # 0x930a
leaq 0x4661(%rip), %r14      # 0x932f
movl $0x8, %edi
xorl %r15d, %r15d
callq 0x41e0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x4fac
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq -0x6ef(%rip), %rax      # 0x4614
movq %rax, (%rsp)
movl $0x8, %ecx
movq %rbx, %r15
movq %rbx, %rdi
leaq 0x34(%rsp), %rsi
leaq 0x54(%rsp), %rdx
movl 0x28(%rsp), %r8d
leaq 0x2c(%rsp), %r9
callq 0x5140
movl $0x0, 0x48(%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 0x5130
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 0x4cce
xorl %r15d, %r15d
testq %r15, %r15
je 0x4de1
movq (%r15), %rdi
cmpl $-0x32, 0x1bc(%rdi)
je 0x4dcc
movq (%rdi), %rax
callq *0x38(%rax)
movq %r15, %rdi
callq 0x5130
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x459c
movq 0x81ca(%rip), %rdi      # 0xcfc8
leaq 0x43de(%rip), %rsi      # 0x91e3
callq 0x41d0
movl $0x1, %edi
callq 0x4250
jmp 0x4e64
jmp 0x4e64
jmp 0x4e64
jmp 0x4e64
jmp 0x4e64
jmp 0x4e64
jmp 0x4e64
movq %rax, %r14
movl $0x8, %esi
movq %r15, %rdi
callq 0x41f0
movq %r14, %rdi
callq 0x43b0
movq %rdx, %r12
movq %rax, %r14
jmp 0x4e5d
jmp 0x4e84
jmp 0x4e84
jmp 0x4e84
jmp 0x4e84
movq %rdx, %r12
movq %rax, %r14
movl $0x8, %esi
movq %rbx, %rdi
callq 0x41f0
xorl %r15d, %r15d
jmp 0x4e7a
jmp 0x4e64
movq %rax, %rdi
callq 0x4ea7
jmp 0x4e84
jmp 0x4e84
jmp 0x4e84
jmp 0x4e84
movq %rdx, %r12
movq %rax, %r14
cmpl $0x2, %r12d
je 0x4e8c
jmp 0x4e32
jmp 0x4e84
movq %rax, %r14
cmpl $0x2, %edx
jne 0x4e32
movq %r14, %rdi
callq 0x40a0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
callq 0x4380
jmp 0x4db5