Reading Dolby AC-4 frames from an .ac4 file

In an .ac4 file, each raw_ac4_frame is encapsulated in an ac4_syncframe, as defined in ETSI TS 103 190-1. An AC-4 sync frame must first be converted to a raw AC-4 frame by stripping its sync word, frame size, and optional CRC words before packetization.

Procedure

  1. To locate the start of an AC-4 raw frame, search for the 16-bit sync word. The value of the sync word can be either 0xAC40 or 0xAC41.
  2. Read the 16 bits immediately succeeding the sync word.
    • If the 16-bit value is not equal to 0xFFFF, the value is the frame size.
    • If the 16-bit value is equal to 0xFFFF, read the next 24 bits as the frame size.
  3. According to the frame size, read the next bits succeeding the frame size as the raw AC-4 frame.
  4. Optional : If the sync word is 0xAC41, the AC-4 simple transport frame includes a 16-bit CRC word based on the frame_size element and the raw_ac4_frame element. Read the 16 bits immediately succeeding the raw AC-4 frame, and verify that the value matches the CRC calculated using the IBM-CRC-16 polynomial: x¹⁶+x¹⁵+x²+1.
  5. Read the next 16 bits.
    • If the sync word is 0xAC40, they are the 16 bits immediately succeeding the raw AC-4 frame.
    • If the sync word is 0xAC41, they are the 16 bits immediately succeeding the CRC word.
  6. Verify that the 16-bit word is also a sync word; otherwise, this is not a proper AC-4 bitstream.