// File: ke6jjj[P]r-dat/AudioFrameReceiver.cc
// Function: AudioFrameReceiver::Stop()
void
AudioFrameReceiver::Stop()
{
  //
  // Processing has stopped. If we were dumping audio to a file, go back
  // and fill in the file headers.
  //
  if (mFile != NULL) {
    //
    // Write WAV header.
    //
    XDR hdr(kWAVHeaderSize);
    hdr.AddString("RIFF", 4);
    hdr.AddU32(kWAVFormatChunkHeaderSize+
               kWAVDataChunkHeaderSize+
               mFramesWritten * 4+
               4);
    hdr.AddString("WAVE", 4);
    
    fseek(mFile, SEEK_SET, 0);
    fwrite(hdr.Data(), hdr.Size(), 1, mFile);

    //
    // Write format chunk.
    //
    XDR xdr(kWAVFormatChunkHeaderSize);
    
    // ID             chunkID;
    xdr.AddString("fmt ", 4);
    // long           chunkSize;
    xdr.AddU32(kWAVFormatChunkHeaderSize-8);
    
    // short          wFormatTag;
    xdr.AddI16(1); // PCM data
    // unsigned short wChannels;
    xdr.AddU16(2);
    // unsigned long  dwSamplesPerSec;
    xdr.AddU32(48000);
    // unsigned long  dwAvgBytesPerSec;
    xdr.AddU32(48000 * 4); // 4 bytes per frame (2 16-bit samples)
    // unsigned short wBlockAlign;
    xdr.AddU16(4); // 4 bytes per frame (2 16-bit samples)
    // unsigned short wBitsPerSample;
    xdr.AddU16(16);

    fwrite(xdr.Data(), xdr.Size(), 1, mFile);

    //
    // Write data chunk.
    //
    XDR data(kWAVDataChunkHeaderSize);

    data.AddString("data", 4);
    data.AddU32(mFramesWritten * 4);

    fwrite(data.Data(), data.Size(), 1, mFile);

    //
    // Close file.
    //
    fclose(mFile);
    mFile = NULL;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, 0x8(%rax)
je 0x69b6
leaq -0x20(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl $0xc, %esi
callq 0xc690
movq -0x70(%rbp), %rdi
leaq 0x89d2(%rip), %rsi      # 0xf121
movl $0x4, %edx
callq 0xc720
jmp 0x675b
movq -0x68(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, %eax
leal 0x24(,%rax,4), %esi
leaq -0x20(%rbp), %rdi
callq 0xc9a0
jmp 0x6776
leaq 0x89a9(%rip), %rsi      # 0xf126
leaq -0x20(%rbp), %rdi
movl $0x4, %edx
callq 0xc720
jmp 0x678d
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2110
jmp 0x67a0
leaq -0x20(%rbp), %rdi
callq 0xca60
movq %rax, -0x78(%rbp)
jmp 0x67af
leaq -0x20(%rbp), %rdi
callq 0xca80
movq %rax, -0x80(%rbp)
jmp 0x67be
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x21f0
jmp 0x67da
leaq -0x48(%rbp), %rdi
movl $0x18, %esi
callq 0xc690
jmp 0x67ea
leaq 0x893a(%rip), %rsi      # 0xf12b
leaq -0x48(%rbp), %rdi
movl $0x4, %edx
callq 0xc720
jmp 0x6801
leaq -0x48(%rbp), %rdi
movl $0x10, %esi
callq 0xc9a0
jmp 0x6811
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0xc7c0
jmp 0x6821
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0xc850
jmp 0x6831
leaq -0x48(%rbp), %rdi
movl $0xbb80, %esi           # imm = 0xBB80
callq 0xc9a0
jmp 0x6841
leaq -0x48(%rbp), %rdi
movl $0x2ee00, %esi          # imm = 0x2EE00
callq 0xc9a0
jmp 0x6851
leaq -0x48(%rbp), %rdi
movl $0x4, %esi
callq 0xc850
jmp 0x6861
leaq -0x48(%rbp), %rdi
movl $0x10, %esi
callq 0xc850
jmp 0x6871
leaq -0x48(%rbp), %rdi
callq 0xca60
movq %rax, -0x88(%rbp)
jmp 0x6883
leaq -0x48(%rbp), %rdi
callq 0xca80
movq %rax, -0x90(%rbp)
jmp 0x6895
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x21f0
jmp 0x68b7
leaq -0x60(%rbp), %rdi
movl $0x8, %esi
callq 0xc690
jmp 0x68c7
leaq 0x8862(%rip), %rsi      # 0xf130
leaq -0x60(%rbp), %rdi
movl $0x4, %edx
callq 0xc720
jmp 0x68de
movq -0x68(%rbp), %rax
movl 0x10(%rax), %esi
shll $0x2, %esi
leaq -0x60(%rbp), %rdi
callq 0xc9a0
jmp 0x68f3
leaq -0x60(%rbp), %rdi
callq 0xca60
movq %rax, -0x98(%rbp)
jmp 0x6905
leaq -0x60(%rbp), %rdi
callq 0xca80
movq %rax, -0xa0(%rbp)
jmp 0x6917
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x21f0
jmp 0x6939
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20e0
jmp 0x6948
movq -0x68(%rbp), %rax
movq $0x0, 0x8(%rax)
leaq -0x60(%rbp), %rdi
callq 0xc6f0
leaq -0x48(%rbp), %rdi
callq 0xc6f0
leaq -0x20(%rbp), %rdi
callq 0xc6f0
jmp 0x69b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x69ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x69a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xc6f0
leaq -0x48(%rbp), %rdi
callq 0xc6f0
leaq -0x20(%rbp), %rdi
callq 0xc6f0
jmp 0x69bf
addq $0xa0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x21d0
nopl (%rax,%rax)