// File: ke6jjj[P]r-dat/RDATDecoder.cc
// Function: RDATDecoder::EvaluateClock()
void
RDATDecoder::EvaluateClock()
{
  int i, maxI, minI;
  float max = 0.0, min = 100.0, ratio;

  for (i = maxI = 0; i < mSyncWindowSize; i++) {
    //
    // Find the highest peak.
    //
    if (mSyncWindow[i] > max) {
      max = mSyncWindow[i];
      maxI = i;
    }
    //
    // And the lowest valley.
    //
    if (mSyncWindow[i] < min)
      min = mSyncWindow[i];
  }
  
  if (maxI != mSyncWindowSyncPos) {
    //
    // We've found a new sync position.
    // In the future we might calculate clock error here.
    //
    mSyncWindowSyncPos = maxI;
    mSyncWindowNextEvalPos = (maxI + mSyncWindowSize / 2) %
                              mSyncWindowSize;
  }
  
  //
  // If there is a significant difference between the highest
  // peak and the lowest valley then we have a good clock signal.
  //
  if (max > 0.0)
    ratio = min / max;
  else
    ratio = 0.0;

  if (ratio < mClockRatioThreshold) {
    if (!mClockDetected && mDecoder != NULL)
      mDecoder->ClockDetected(true);
    mClockDetected = true;
  } else {
    if (mClockDetected && mDecoder != NULL)
      mDecoder->ClockDetected(false);
    mClockDetected = false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
movss 0xb320(%rip), %xmm0     # 0xe304
movss %xmm0, -0x1c(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x28(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x3074
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss -0x18(%rbp), %xmm0
jbe 0x3036
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3067
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0x3069
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2ff7
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x20(%rcx), %eax
je 0x30ad
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %eax
movl %eax, 0x20(%rcx)
movl -0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl 0x18(%rcx), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x2c(%rbp), %eax
addl %edx, %eax
cltd
idivl 0x18(%rcx)
movq -0x28(%rbp), %rax
movl %edx, 0x28(%rax)
movss -0x18(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x30d0
movss -0x1c(%rbp), %xmm0
divss -0x18(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
jmp 0x30d8
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x28(%rbp), %rax
movss -0x20(%rbp), %xmm1
movss 0x30(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x311d
movq -0x28(%rbp), %rax
testb $0x1, 0x2c(%rax)
jne 0x3113
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3113
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x8(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0x314a
movq -0x28(%rbp), %rax
testb $0x1, 0x2c(%rax)
je 0x3142
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3142
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x8(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x2c(%rax)
addq $0x30, %rsp
popq %rbp
retq