// File: ke6jjj[P]r-dat/RDATDecoder.cc
// Function: RDATDecoder::Process(float*, unsigned long)
void
RDATDecoder::Process(float *samples, size_t count)
{
  size_t i;
  float signal;
  bool sign, zeroCross;
  
  for (i = 0; i < count; i++) {
    //
    // Look at the sample.
    //
    signal = samples[i];

    //
    // Check if this sample has made a zero-crossing.
    //
    sign = signal > 0.0;
    zeroCross = sign != mLastSign;

    //
    // Send the baseband signal to the clock detector.
    // If it returns true, then the clock detector has
    // achieved a good lock and suggests sampling the
    // signal now.
    //
    if (ClockDetect(zeroCross)) {
      //
      // Signal should be sampled now. Dump our integrator.
      //
      mDecoder->ReceiveBit(mIntegrator > 0.0);
      mIntegrator = 0.0;
    }

    //
    // Update the integrator.
    //
    mIntegrator += signal;
    mLastSign = sign;

    //
    // If there's no track in progress, see if a new one has perhaps
    // started.
    //
    if (!mTrackInProgress) {
      //
      // We're in the idle time between tracks. Check if a track has started.
      //
      if (mDecoder->PreambleDetected()) {
        //
        // A track appears to have started. Start the track progress timer.
        //
        mTrackInProgress = true;
        mTrackSampleCount = mTrackDuration;

        //
        // Notify the downstream decoder.
        //
        mDecoder->TrackDetected(true);
      }
    } else {
      //
      // There's a track in progress. See if the track timer has expired.
      //
      mTrackSampleCount--;
      if (mTrackSampleCount == 0) {
        //
        // The track should have ended by now. Declare it over.
        //
        mTrackInProgress = false;
        mDecoder->TrackDetected(false);
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x2ea4
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta -0x25(%rbp)
movzbl -0x25(%rbp), %eax
andl $0x1, %eax
movzbl 0x38(%rdi), %ecx
andl $0x1, %ecx
subl %ecx, %eax
setne -0x26(%rbp)
movb -0x26(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm0
callq 0x2eb0
testb $0x1, %al
jne 0x2dd7
jmp 0x2e0d
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %cl
movq (%rdi), %rax
movq 0x10(%rax), %rax
movzbl %cl, %esi
andl $0x1, %esi
callq *%rax
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x3c(%rax)
movq -0x30(%rbp), %rax
movss -0x24(%rbp), %xmm0
addss 0x3c(%rax), %xmm0
movss %xmm0, 0x3c(%rax)
movb -0x25(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x38(%rax)
testb $0x1, 0x40(%rax)
jne 0x2e64
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0x2e43
jmp 0x2e62
movq -0x30(%rbp), %rax
movb $0x1, 0x40(%rax)
movq 0x48(%rax), %rcx
movq %rcx, 0x50(%rax)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x20(%rax)
jmp 0x2e91
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x50(%rax)
cmpq $0x0, 0x50(%rax)
jne 0x2e8f
movq -0x30(%rbp), %rax
movb $0x0, 0x40(%rax)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x20(%rax)
jmp 0x2e91
jmp 0x2e93
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2d74
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)