The S/PDIF protocol is a bi-phase mark encoded continuous data stream divided into blocks, frames and subframes of data. Each data stream contains continuous audio data from one source.
Each subframe in the protocol contains a single audio sample from one channel. Multiple subframes are combined into one frame. Each frame therefore contains a single audio sample from each audio channel in the data stream. Commonly two channels are contained in a data stream, but the protocol does not define a specific number of audio channels within the data stream.
192 frames of data are then combined into a larger logical unit called a block. The block structure is used to transfer additional data contained in a few extra bits of each subframe.
Figure 1: SPDIF block and frame architecture
A single subframe consist of 32-bits: 4 header bits, 4 auxiliary data bits, 20 audio data bits, and 4 status bits. The auxiliary data bits may be combined with the audio data to represent a 24-bit audio sample. The following diagram shows the subframe structure from least to most significant bit.
Figure 2: SPDIF subframe architecture
The bits within each subframe are encoded using bi-phase mark coding (BMC). The signal has a transition at the beginning of each bit interval and an additional transition in the middle of the bit interval for an ON bit. An OFF bit has the same signal state for the entire bit interval. The following diagram shows how a set of data bits is encoded into its BMC equivalent using a clock that runs at twice the bit rate.
Figure 3: Bi-phase mark coding scheme
The bit rate of the SPDIF data stream is matched to the audio sample rate to create a continuous bit stream without any gaps between subframes, frames, or blocks. For example, a 48 kHz audio sample rate, common in many applications, results in a bit rate of 3.072 MHz and a clock rate of 6.144 MHz. In this case the duration of an OFF bit is ~325.5ns, while an ON bit consists of two alternating ~162.7ns states.
The 4-bit header defined in the subframe structure is used to indicate the start of a subframe and allows the receiver to synchronize itself with the data stream. The structure of the header does not follow the rules of the bi-phase mark coding. It starts with an extra long state (one and half bits in length) which allows the receiver to differentiate the start of the header from the rest of the data stream. There are three different header combinations to indicate the type of subframe that follows. The first subframe in each frame is identified as channel A, while all subsequent subframes are channel B. The first subframe in a new block of frames (192 frames per block) also has a unique header. The following figure illustrates the three different header types.
Figure 4: SPDIF header coding