// File: /workspace/github_cpp_makefile_star2_O1/ke6jjj[P]r-dat/AudioFrameReceiver.cc
// Function: AudioFrameReceiver::ReceiveFrame(Track const&, Track const&)
void
AudioFrameReceiver::ReceiveFrame(const Track& a, const Track& b)
{
  const uint8_t *item;
  uint32_t absoluteFrame = 0;

  printf("\n");

  //
  // Examine the Absolute Time subcode.
  //
  if (a.GetSubcode(2, &item)) {
    TimeCode time(item);
    absoluteFrame = time.AbsoluteFrame();
    printf("Absolute time: %02dh-%02dm-%02ds-%02df (%d)\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame(),
      absoluteFrame
    );
    uint16_t program = time.Program();
    switch (program) {
    case TimeCode::PROGRAM_NOT_VALID:
      break;
    case TimeCode::PROGRAM_LEAD_IN:
    case TimeCode::PROGRAM_LEAD_OUT:
      printf("Program ID   : (%s)\n",
             program == TimeCode::PROGRAM_LEAD_IN ? "LEAD IN" : "LEAD_OUT");
      break;
    default:
      printf("Program ID   : %03d\n", program);
      break;
    }
    uint8_t index = time.Index();
    switch (index) {
    case TimeCode::INDEX_NOT_VALID:
      break;
    default:
      printf("Index ID     : %03d\n", index);
      break;
    }
  }
  
  //
  // If the absolute frame number is corrupted or the universal "I don't know"
  // value of 100h-100m-100s-100f (12203433), then display a session-psuedo
  // frame.
  //
  if (absoluteFrame == 0 || absoluteFrame == 12203433) {
    TimeCode time(static_cast<uint32_t>(mNextSessionFrameNumber));
    printf("Psuedo   time: %02dh-%02dm-%02ds-%02df (%d)\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame(),
      mNextSessionFrameNumber
    );
    absoluteFrame = mNextSessionFrameNumber;
  }

  uint8_t control_id;
  if (a.GetControlID(control_id) && control_id != 0) {
    printf("Control      :");
    if (control_id & 0x1)
      // TOC ID
      printf(" TOC");
    if (control_id & 0x2)
      // Shortening ID
      printf(" SKIP");
    if (control_id & 0x4)
      // Start ID
      printf(" START");
    if (control_id & 0x8)
      printf(" PRIORITY");
    printf("\n");
  }
  
  //
  // Examine Program Time subcode.
  //
  if (a.GetSubcode(1, &item)) {
    TimeCode time(item);
    printf("Program time : %02dh-%02dm-%02ds-%02df\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame()
    );
  }
    
  //
  // Examine Running Time / Pro R time.
  //
  if (a.GetSubcode(3, &item)) {
    TimeCode time(item);
    if (item[0] & 0x4) {
      //
      // Running Time.
      //
      printf("Running time : %02dh-%02dm-%02ds-%02df\n",
        time.Hour(),
        time.Minute(),
        time.Second(),
        time.Frame()
      );
    } else {
      //
      // Pro R Time
      //
      uint8_t sid = (item[0] & 3);
      uint8_t freq = (item[1] & 0xC0) >> 6;
      uint8_t xrate = (item[1] & 0x38) >> 3;
      uint8_t msb = (item[1] & 0x07);
      uint8_t lsb = item[2];
      const char *code_type;
      switch (sid) {
      case 0:
        code_type = "IEC/SMPTE";
        break;
      case 1:
        code_type = "Pro DIO; sample address";
        break;
      case 2:
        code_type = "Pro DIO; Time-of-day";
        break;
      case 3:
        code_type = "Reserved-3";
        break;
      default:
        code_type = "?";
        break;
      }
      const char *freq_str;
      switch (freq) {
      case 0:
        freq_str = "48 kHz";
        break;
      case 1:
        freq_str = "44.1 kHz";
        break;
      case 2:
        freq_str = "32 kHz";
        break;
      case 3:
        freq_str = "Reserved-3";
        break;
      default:
        freq_str = "?";
        break;
      }
      const char *smpte_xrate;
      switch (xrate) {
      case 0:
        smpte_xrate = "30 Hz";
        break;
      case 1:
        smpte_xrate = "29.97 Hz NDF";
        break;
      case 2:
        smpte_xrate = "29.97 Hz DF";
        break;
      case 3:
        smpte_xrate = "25 Hz";
        break;
      case 4:
        smpte_xrate = "24 Hz";
        break;
      case 5:
        smpte_xrate = "Reserved-5";
        break;
      case 6:
        smpte_xrate = "Reserved-6";
        break;
      case 7:
        smpte_xrate = "Reserved-7";
        break;
      default:
        smpte_xrate = "?";
        break;
      }
      printf("Pro R Time   : %02dh-%02dm-%02ds-%02df (%s-%s-%s)\n",
        time.Hour(),
        time.Minute(),
        time.Second(),
        time.Frame(),
        code_type,
        freq_str,
        smpte_xrate
      );
    }
  }

  //
  // Examine Table of Contents subcode.
  //
  if (a.GetSubcode(4, &item)) {
    printf("Table of Cont:\n");
    TimeCode time(item);
    uint16_t program = time.Program();
    switch (program) {
    case TimeCode::PROGRAM_NOT_VALID:
      break;
    case TimeCode::PROGRAM_LEAD_IN:
    case TimeCode::PROGRAM_LEAD_OUT:
      printf("  Program ID : (%s)\n",
             program == TimeCode::PROGRAM_LEAD_IN ? "LEAD IN" : "LEAD_OUT");
      break;
    default:
      printf("  Program ID : %03d\n", program);
      break;
    }
    uint8_t index = time.Index();
    switch (index) {
    case TimeCode::INDEX_NOT_VALID:
      break;
    default:
      printf("  Index ID   : %03d\n", index);
      break;
    }
    printf("  Time       : %02dh-%02dm-%02ds-%02df\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame()
    );
  }

  //
  // Examine the Date & Time subcode.
  //
  if (a.GetSubcode(5, &item))
    HandleDateTime(item, absoluteFrame);
  else
    HandleDateTime(NULL, absoluteFrame);

  //
  // Examine Catalog Number subcode.
  //
  if (a.GetSubcode(6, &item)) {
  }

  //
  // Examine ISRC subcode.
  //
  if (a.GetSubcode(7, &item)) {
    printf("ISRC         : (not yet)\n");
  }

  //
  // Examine Pro Binary subcode.
  //
  if (a.GetSubcode(8, &item)) {
    printf("Pro Binary   : (not yet)\n");
  }

  //
  // Print the sub-code signature.
  //
  const Track::SubcodeSignatureArray& signature = a.SubcodeSignature();
  printf("Subcode packs:");
  for (size_t i = 0; i < 7; i++)
    printf(" %-2d", signature[i]);
  putchar('\n');

  //
  // Fetch and demultiplex all the data from the track pair.
  //
  mFrame.FillFromTrackPair(a, b);
  const DATFrame::DataArray& data = mFrame.Data();

  //
  // Print out error statistics for the frame.
  //
  unsigned int c1_errors = mFrame.C1Errors();
  unsigned int c1_uncorrectable = mFrame.C1UncorrectableErrors();
  unsigned int c1_corrected = c1_errors - c1_uncorrectable;
  unsigned int c2_uncorrectable = mFrame.C2UncorrectableErrors();
  unsigned int c2_corrected = c1_uncorrectable - c2_uncorrectable;

  printf("Errors  C1/C2: %d/%d",
    c1_corrected,
    c2_corrected
  );

  if (c2_uncorrectable > 0)
    printf(" %d UNCORRECTED\n", c2_uncorrectable);
  else
    printf(" (all corrected)\n");
  

  printf("Samples      : L    R\n");
  for (size_t i = 0; i < 8; i++) {
    printf("               %02x%02x %02x%02x\n",
      data[i][1], data[i][0],
      data[i][3], data[i][2]
    );
  }

  //
  // Ensure that everything printed so far is immediately visible.
  //
  fflush(stdout);

  //
  // Dump samples to file, if asked.
  //
  if (mFile != NULL) {
    for (size_t i = 0; i < DATFrame::kUserDataRows; i++) {
      fwrite(data[i], DATFrame::kBytesPerRow, 1, mFile);
    }
    mFramesWritten += DATFrame::kUserDataRows;
  }

  mHaveLastAbsoluteFrameNumber = true;
  mLastAbsoluteFrameNumber = absoluteFrame;
  mNextSessionFrameNumber++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x2, %esi
callq 0x35cc
xorl %r13d, %r13d
testb %al, %al
je 0x3d68
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x7798
movq %r14, %rdi
callq 0x78d0
movl %eax, %r13d
leaq 0xe(%rsp), %rdi
callq 0x78c0
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x78c4
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x78c8
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x78cc
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5f05(%rip), %rdi      # 0x9be9
movl %r13d, %r9d
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x78b8
movzwl %ax, %esi
cmpl $0x80aa, %esi           # imm = 0x80AA
je 0x3d49
cmpl $0x80bb, %esi           # imm = 0x80BB
je 0x3d13
cmpl $0x80ee, %esi           # imm = 0x80EE
jne 0x3d3b
cmpl $0x80bb, %esi           # imm = 0x80BB
leaq 0x5f0b(%rip), %rax      # 0x9c2b
leaq 0x5f0c(%rip), %rsi      # 0x9c33
cmoveq %rax, %rsi
leaq 0x5ee4(%rip), %rdi      # 0x9c16
xorl %eax, %eax
callq 0x2040
jmp 0x3d49
leaq 0x5efa(%rip), %rdi      # 0x9c3c
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x78bc
cmpb $-0x56, %al
je 0x3d68
movzbl %al, %esi
leaq 0x5ef0(%rip), %rdi      # 0x9c51
xorl %eax, %eax
callq 0x2040
cmpl $0xba35a9, %r13d        # imm = 0xBA35A9
je 0x3d76
testl %r13d, %r13d
jne 0x3ddc
movl 0x2db8(%rbx), %esi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x783a
movq %r14, %rdi
callq 0x78c0
movzbl %al, %ebp
movq %r14, %rdi
callq 0x78c4
movzbl %al, %r12d
movq %r14, %rdi
callq 0x78c8
movl %eax, %r13d
movq %r14, %rdi
callq 0x78cc
movzbl %r13b, %ecx
movzbl %al, %r8d
movl 0x2db8(%rbx), %r9d
leaq 0x5e9d(%rip), %rdi      # 0x9c66
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2040
movl 0x2db8(%rbx), %r13d
leaq 0xd(%rsp), %rsi
movq %r15, %rdi
callq 0x3994
testb %al, %al
je 0x3e60
cmpb $0x0, 0xd(%rsp)
je 0x3e60
leaq 0x5e98(%rip), %rdi      # 0x9c93
xorl %eax, %eax
callq 0x2040
testb $0x1, 0xd(%rsp)
je 0x3e17
leaq 0x5e92(%rip), %rdi      # 0x9ca2
xorl %eax, %eax
callq 0x2040
testb $0x2, 0xd(%rsp)
je 0x3e2c
leaq 0x5e82(%rip), %rdi      # 0x9ca7
xorl %eax, %eax
callq 0x2040
testb $0x4, 0xd(%rsp)
je 0x3e41
leaq 0x5e73(%rip), %rdi      # 0x9cad
xorl %eax, %eax
callq 0x2040
testb $0x8, 0xd(%rsp)
je 0x3e56
leaq 0x5e65(%rip), %rdi      # 0x9cb4
xorl %eax, %eax
callq 0x2040
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x1, %esi
callq 0x35cc
testb %al, %al
je 0x3ed4
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x7798
movq %r14, %rdi
callq 0x78c0
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x78c4
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x78c8
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x78cc
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5df1(%rip), %rdi      # 0x9cbe
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x3, %esi
callq 0x35cc
testb %al, %al
movl %r13d, 0x24(%rsp)
je 0x4015
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %rdi
callq 0x7798
movq 0x18(%rsp), %rcx
movzbl (%rcx), %eax
testb $0x4, %al
jne 0x3fc7
andl $0x3, %eax
movzbl 0x1(%rcx), %ecx
leaq 0x6180(%rip), %r12      # 0xa0a0
movslq (%r12,%rax,4), %rax
movq %rax, 0x38(%rsp)
movl %ecx, %eax
shrl $0x6, %eax
leaq 0x619b(%rip), %r13      # 0xa0d0
movslq (%r13,%rax,4), %rax
movq %rax, 0x30(%rsp)
shrl %ecx
andl $0x1c, %ecx
leaq 0x6165(%rip), %r14      # 0xa0b0
movslq (%rcx,%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x78c0
movb %al, 0x17(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x78c4
movb %al, 0x16(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x78c8
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x78cc
addq 0x38(%rsp), %r12
addq 0x30(%rsp), %r13
addq 0x28(%rsp), %r14
movzbl 0x17(%rsp), %esi
movzbl 0x16(%rsp), %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5e05(%rip), %rdi      # 0x9db3
movq %r12, %r9
xorl %eax, %eax
pushq %r14
pushq %r13
callq 0x2040
addq $0x10, %rsp
movl 0x24(%rsp), %r13d
jmp 0x4015
leaq 0xe(%rsp), %rdi
callq 0x78c0
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x78c4
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x78c8
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x78cc
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5cd8(%rip), %rdi      # 0x9ce6
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x4, %esi
callq 0x35cc
testb %al, %al
je 0x4113
leaq 0x5eff(%rip), %rdi      # 0x9f35
callq 0x21b0
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x7798
movq %r14, %rdi
callq 0x78b8
movzwl %ax, %esi
cmpl $0x80aa, %esi           # imm = 0x80AA
je 0x40a6
cmpl $0x80bb, %esi           # imm = 0x80BB
je 0x4070
cmpl $0x80ee, %esi           # imm = 0x80EE
jne 0x4098
cmpl $0x80bb, %esi           # imm = 0x80BB
leaq 0x5bae(%rip), %rax      # 0x9c2b
leaq 0x5baf(%rip), %rsi      # 0x9c33
cmoveq %rax, %rsi
leaq 0x5d57(%rip), %rdi      # 0x9de6
xorl %eax, %eax
callq 0x2040
jmp 0x40a6
leaq 0x5d5c(%rip), %rdi      # 0x9dfb
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x78bc
cmpb $-0x56, %al
je 0x40c5
movzbl %al, %esi
leaq 0x5d52(%rip), %rdi      # 0x9e10
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x78c0
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x78c4
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x78c8
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x78cc
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5d19(%rip), %rdi      # 0x9e25
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movl $0x5, %esi
movq %r12, %rdx
callq 0x35cc
testb %al, %al
je 0x4133
movq 0x18(%rsp), %rsi
jmp 0x4135
xorl %esi, %esi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x4316
movq %r15, %rdi
movl $0x6, %esi
movq %r12, %rdx
callq 0x35cc
movq %r15, %rdi
movl $0x7, %esi
movq %r12, %rdx
callq 0x35cc
testb %al, %al
je 0x4170
leaq 0x5dd9(%rip), %rdi      # 0x9f44
callq 0x21b0
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x8, %esi
callq 0x35cc
testb %al, %al
je 0x4192
leaq 0x5dd0(%rip), %rdi      # 0x9f5d
callq 0x21b0
movq %r15, %rdi
callq 0x3626
movq %rax, %r14
leaq 0x5ca9(%rip), %rdi      # 0x9e4d
xorl %eax, %eax
callq 0x2040
leaq 0x5caa(%rip), %r12      # 0x9e5c
xorl %r13d, %r13d
movzbl (%r14,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x2040
incq %r13
cmpq $0x7, %r13
jne 0x41b5
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %rdx
callq 0x58ea
movq %r12, %rdi
callq 0x5ae6
movq %rax, %r14
movq %r12, %rdi
callq 0x5b0a
movq %rax, %r13
movq %r12, %rdi
callq 0x5b12
movq %rax, %rbp
subl %ebp, %r13d
movq %r12, %rdi
callq 0x5b1a
movq %rax, %r15
subl %r15d, %ebp
leaq 0x5c3e(%rip), %rdi      # 0x9e62
movl %r13d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2040
testl %r15d, %r15d
je 0x4248
leaq 0x5c3b(%rip), %rdi      # 0x9e77
movl %r15d, %esi
xorl %eax, %eax
callq 0x2040
jmp 0x4254
leaq 0x5d27(%rip), %rdi      # 0x9f76
callq 0x21b0
movl 0x24(%rsp), %ebp
leaq 0x5d28(%rip), %rdi      # 0x9f87
callq 0x21b0
leaq 0x5c1d(%rip), %r15      # 0x9e88
xorl %r12d, %r12d
movzbl 0x1(%r14,%r12,4), %esi
movzbl (%r14,%r12,4), %edx
movzbl 0x3(%r14,%r12,4), %ecx
movzbl 0x2(%r14,%r12,4), %r8d
movq %r15, %rdi
xorl %eax, %eax
callq 0x2040
incq %r12
cmpq $0x8, %r12
jne 0x426e
movq 0xbd21(%rip), %rax      # 0xffc0
movq (%rax), %rdi
callq 0x2110
cmpq $0x0, 0x8(%rbx)
je 0x42dd
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
movq 0x8(%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x21f0
addq $0x4, %r15
cmpq $0x1680, %r15           # imm = 0x1680
jne 0x42b1
addq $0x5a0, 0x10(%rbx)      # imm = 0x5A0
movb $0x1, 0x2db0(%rbx)
movl %ebp, 0x2db4(%rbx)
incl 0x2db8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x430d
jmp 0x430d
jmp 0x430d
jmp 0x430d
jmp 0x430d
jmp 0x430d
jmp 0x430d
movq %rax, %rdi
callq 0x21d0
nop