Digital Audio Sampling, Philips I2S 1-BCLK Delay & i.MX6ULL SAI2 FIFOs

Synchronous digital audio leaves zero room for clock drift or single-bit framing error: a 1-BCLK mismatch between CPU SAI2 and an external codec shifts every PCM sample by 6 dB and wraps peak waveforms into harsh two's-complement clipping.

20 minfree previewLinux 6.12C11glibc 2.39→ module 1 lab
What you'll learn
  • Compute exact MCLK, BCLK, LRCLK, and TCR2 divider values across 8 kHz to 48 kHz PCM families.
  • Diagnose +6 dB gain shift and two's-complement wraparound clipping caused by 1-BCLK versus 0-BCLK framing mismatches.
  • Evaluate i.MX6ULL SAI2 32x32-bit TX/RX FIFO drain budgets and SDMA watermark thresholds.

Continuous Acoustic Sampling, PCM Quantization, and Nyquist Clock Ratios

Microphones convert continuous acoustic air-pressure waves into millivolt analog signals, whereas ARMv7-A processors compute exclusively on discrete binary words. Bridging those domains requires an audio CODEC combining an analog-to-digital converter (ADC) for capture and a digital-to-analog converter (DAC) for playback. Under the Nyquist-Shannon sampling theorem, sampling at rate fs reconstructs frequencies strictly below fs / 2; standard voice and music pipelines therefore run at 8 kHz (4 kHz speech), 44.1 kHz (Compact Disc), or 48 kHz (broadcast and embedded video), quantizing each amplitude into 16-bit, 24-bit, or 32-bit signed two's-complement Pulse-Code Modulation (PCM) integers.

Modern embedded codecs such as the WM8960 do not use resistor-ladder converters clocked directly at fs. Instead, their 24-bit delta-sigma modulators oversample the analog stage using a low-jitter master clock MCLK = 256 * fs (or 384 * fs), achieving 98 dB DAC signal-to-noise ratio (SNR) and -84 dB total harmonic distortion (THD) at 48 kHz on a 3.3 V supply. That math splits audio clocks into two incompatible crystal families: 48 kHz multiples (8, 16, 32, 48 kHz) require MCLK = 12.288 MHz, whereas 44.1 kHz multiples (11.025, 22.05, 44.1 kHz) require 11.2896 MHz.

fig_m01_l01_a.svg — Synchronous MCLK/BCLK/LRCLK chain and acoustic failure…

Figure 1.1a. Synchronous MCLK/BCLK/LRCLK chain and acoustic failure of 0-BCLK versus 1-BCLK mismatch.

mental model: Picture a dual-lane bottling conveyor driven by one master gearshaft: a lane-select gate flips between left and right chutes once per crate, while a tooth-indexed chain advances exactly one bottle slot per click after a one-tooth mechanical guard gap.

Where it stops working: Unlike mechanical bottles that jam visibly when misaligned, a serial audio shift register silently latches every bit one position early or late without raising a bus error interrupt.

definition (Inter-IC Sound (Philips I2S)): Standardized by Philips Semiconductors in 1986 for board-level digital audio transport, Inter-IC Sound (I2S) separates bit clock (BCLK), word-select frame clock (LRCLK), and serial PCM data (SDATA), shifting each channel's most significant bit (MSB) exactly one BCLK period after the LRCLK edge.

ast_m01_l01.svg — MCLK=256*fs, BCLK=2*fs*slot_bits, Philips I2S delays…step 1/4
  1. Step 1. Derive a coherent 256*fs MCLK (12.288 MHz for 48 kHz, 11.2896 MHz for 44.1 kHz) from PLL4_AUDIO_DIV.
  2. Step 2. Refill the 32x32-bit SAI2 TX FIFO via SDMA channel 38 whenever free slots reach the TCR1 watermark.
  3. Step 3. Assert LRCLK low for Left (high for Right) and hold a 1-BCLK delay before shifting out the MSB.
  4. Step 4. Latch bit-exact two's-complement samples in the 24-bit codec converter without MSB bit-slip.

Figure 1.1b. MCLK=256*fs, BCLK=2*fs*slot_bits, Philips I2S delays MSB by 1 BCLK, and SAI2 32-word FIFOs feed SDMA 37/38.

Philips I2S 1-BCLK MSB Framing and i.MX6ULL SAI2 32-Word FIFOs

Between i.MX6ULL and WM8960, full-duplex digital audio crosses a synchronous 6-wire link: MCLK, bit clock BCLK = 2 * fs * slot_bits, frame sync LRCLK = fs (DACLRC / ADCLRC), DACDAT, and ADCDAT. In Philips I2S framing, LRCLK goes low (0) for Left and high (1) for Right, while the transmitter delays each sample's MSB until one full BCLK cycle after the LRCLK edge. That 1-BCLK guard lets receivers register LRCLK on one rising edge and latch MSB cleanly on the next, zero-padding low bits inside 32-bit slots.

On silicon, the i.MX6ULL Synchronous Audio Interface SAI2 (0x0202C000, GIC SPI 98) implements this shift engine in hardware. Both its transmit and receive paths contain dedicated 32 x 32-bit FIFOs (TDR0 and RDR0) supporting frames up to 32 words wide and automatic FIFO-error recovery. At 48 kHz stereo (96,000 words/s), a 32-word FIFO holds 16 stereo frames — just 333.3 us of audio! Interrupting the Cortex-A7 core every 166 us would waste CPU cycles and risk scheduling glitches, so SAI2 asserts DMA requests at programmable watermarks (TCR1.TFWM / RCR1.RFWM) to SDMA channel 37 (RX) and channel 38 (TX).

fig_m01_l01_b.svg — i.MX6ULL SAI2 framing registers at 0x0202C000 and…

Figure 1.1b. i.MX6ULL SAI2 framing registers at 0x0202C000 and deterministic verification pipeline.

Serial FormatLRCLK PolarityMSB Position vs LRCLK EdgeMismatch Consequence
Philips I2S0 = Left, 1 = RightDelayed by 1 BCLK (2nd rising edge)Expected baseline for SAI2 + WM8960
Left-Justified (LJ)1 = Left, 0 = RightImmediate (0 BCLK delay on edge)1-bit shift (+6 dB clip) + L/R channel swap
Right-Justified (RJ)1 = Left, 0 = RightLSB aligned to trailing LRCLK edgeSevere gain loss unless exact word width matches
DSP / TDM Mode A1-BCLK frame pulse1 BCLK after sync pulse (<= 32 slots)Multi-channel slot scrambling if FRSZ != 2
learner@ksa: ~/gl-e07/m01-l01
learner@ksa:~/gl-e07/m01-l01$ bat -H 22 -H 26 sai2_i2s_regs.c File: sai2_i2s_regs.c    /* i.MX6ULL SAI2 (0x0202C000) Philips I2S 32-bit slot register setup */    #include <stdint.h>        #define SAI2_BASE        0x0202C000u    #define SAI_TCSR_TE      (1u << 31)    #define SAI_TCSR_FRDE    (1u << 0)   /* FIFO Request DMA Enable -> SDMA ch 38 */    #define SAI_TCR2_MSEL_M1 (1u << 26)  /* Select Audio Master Clock 1 (PLL4) */    #define SAI_TCR2_BCP     (1u << 25)  /* Drive TX data on BCLK falling edge */    #define SAI_TCR2_BCD     (1u << 24)  /* BCLK generated internally (master) */    #define SAI_TCR4_FRSZ(n) (((uint32_t)((n) - 1) & 0x1Fu) << 16)    #define SAI_TCR4_SYWD(w) (((uint32_t)((w) - 1) & 0x1Fu) << 8)    #define SAI_TCR4_MF      (1u << 4)   /* MSB transmitted first */    #define SAI_TCR4_FSE     (1u << 3)   /* Frame Sync Early = 1-BCLK I2S delay! */    #define SAI_TCR4_FSP     (1u << 1)   /* Frame Sync active-low (0 = Left) */    #define SAI_TCR4_FSD     (1u << 0)   /* Frame Sync generated internally */        struct imx_sai_tx_regs {        volatile uint32_t tcsr, tcr1, tcr2, tcr3, tcr4, tcr5, rsvd[2], tdr0;    };        void sai2_configure_i2s_48k_32b(struct imx_sai_tx_regs *sai) {      uint32_t div = (12288000u / (2u * 48000u * 32u) / 2u) - 1u; /* DIV = 1 -> /4 */        sai->tcr1 = 16u; /* TFWM = 16 words: trigger SDMA ch 38 at half-empty */        sai->tcr2 = SAI_TCR2_MSEL_M1 | SAI_TCR2_BCP | SAI_TCR2_BCD | (div & 0xFFu);        sai->tcr4 = SAI_TCR4_FRSZ(2) | SAI_TCR4_SYWD(32) |                  SAI_TCR4_MF | SAI_TCR4_FSE | SAI_TCR4_FSP | SAI_TCR4_FSD;        sai->tcr5 = (31u << 24) | (31u << 16) | (31u << 8); /* WNW=31, W0W=31, FBT=31 */        sai->tcsr = SAI_TCSR_TE | SAI_TCSR_FRDE;    }
  1. TCR2[7:0] divides MCLK by (DIV + 1) * 2: DIV=1 divides 12.288 MHz by 4 to yield 3.072 MHz BCLK.
  2. TCR4_FSE asserts LRCLK one BCLK before bit 31, implementing the Philips I2S 1-BCLK MSB delay.
fsl_sai / I2S Clocking(4-ksa) at a glance — GL-E07
fsl_sai / I2S Clocking(4-ksa) GL-E07 Quick Reference fsl_sai / I2S Clocking(4-ksa) NAME       fsl_sai — i.MX6ULL Synchronous Audio Interface (SAI1..SAI3) register &       clock contract        ADDRESS & RESOURCES SAI2 MMIO : 0x0202C000 .. 0x0202FFFF (16 KB), GIC       SPI 98 SDMA Req : Event 37 (SAI2_RX -> RDR0), Event 38 (SAI2_TX <-       TDR0) FIFOs : 32 words x 32 bits TX + 32 words x 32 bits RX CLOCK EQUATIONS       MCLK = 256 * fs (12,288,000 Hz @ 48 kHz; 11,289,600 Hz @ 44.1 kHz) BCLK       = 2 * fs * slot_bits TCR2 = ((MCLK / BCLK) / 2) - 1 (even integer       divider >= 2) Kernel Systems Academy        Lesson 1.1         fsl_sai / I2S Clocking(4-ksa) GL-E07 quick reference · full manual page: man 4-ksa fsl_sai / I2S Clocking 

Simulating SAI2 Clock Dividers and 1-BCLK Bit-Slip Distortion in ISO C11

Before flashing a Linux kernel image or probing JTAG_TDI (SAI2_TX_BCLK) with an oscilloscope, we can verify both SAI2 clock-tree arithmetic and serial bit-shift framing deterministically on the Linux host. The ISO C11 program below solves MCLK, BCLK, TCR2[DIV], and 32-word FIFO underrun windows for 48 kHz and 44.1 kHz streams, then shifts a stereo 16-bit peak sample (+23170, 0x5A82, -3 dBFS) onto a 64-bit (2 x 32-bit slot) Philips I2S wire.

To expose why format mismatches sound metallic and clipped rather than completely silent, the model decodes that identical 64-bit wire under both a matched Philips I2S (1-BCLK delay) receiver and a misconfigured Left-Justified (0-BCLK delay) receiver. Note the verification boundary: host C11 proves integer divider exactness and serial bit-alignment logic, whereas clock jitter, pad drive strength (0x17088), and SDMA bus contention require measurement on ARMv7-A Cortex-A7 silicon.

learner@ksa: ~/gl-e07/m01-l01
learner@ksa:~/gl-e07/m01-l01$ bat -H 10 -H 33 verify.c File: verify.c    #include <inttypes.h>    #include <stdbool.h>    #include <stdint.h>    #include <stdio.h>        static uint64_t pack_i2s_64(int16_t left, int16_t right, bool delay_1bclk) {        uint32_t l_u = ((uint32_t)(uint16_t)left) << 16;        uint32_t r_u = ((uint32_t)(uint16_t)right) << 16;        /* Slot is 32 BCLKs/channel: 1-BCLK delay places MSB at bit 30 of each 32b half */      uint32_t l_slot = delay_1bclk ? (l_u >> 1) : l_u;        uint32_t r_slot = delay_1bclk ? (r_u >> 1) : r_u;        return ((uint64_t)l_slot << 32) | (uint64_t)r_slot;    }        static int16_t unpack_left_16(uint64_t wire, bool expect_1bclk) {        uint32_t l_slot = (uint32_t)(wire >> 32);        uint32_t aligned = expect_1bclk ? (l_slot << 1) : l_slot;        return (int16_t)(aligned >> 16);    }        int main(void) {        const uint32_t fs_48k = 48000u, mclk_48k = 256u * fs_48k;        const uint32_t bclk_32 = 2u * fs_48k * 32u;        const uint32_t tcr2_div = (mclk_48k / bclk_32 / 2u) - 1u;        const uint32_t fifo_ns = (uint32_t)((16ULL * 1000000000ULL) / fs_48k);            const uint32_t fs_44k1 = 44100u, mclk_44k1 = 256u * fs_44k1;        const uint32_t bclk_44k1_16 = 2u * fs_44k1 * 16u;            int16_t tx_peak = 23170; /* 0x5A82: -3.01 dBFS sine crest */        uint64_t wire = pack_i2s_64(tx_peak, -tx_peak, true);        int16_t rx_i2s = unpack_left_16(wire, true);      int16_t rx_lj_bug = unpack_left_16(wire, false);        /* Also check inverse bug: TX Left-Justified (0-BCLK) -> RX Philips I2S (1-BCLK) */        int16_t rx_clip_bug = unpack_left_16(pack_i2s_64(tx_peak, -tx_peak, false), true);            printf("48k:  MCLK=%u Hz BCLK_32=%u Hz TCR2.DIV=%u FIFO_32w=%u ns\n",               mclk_48k, bclk_32, tcr2_div, fifo_ns);        printf("44k1: MCLK=%u Hz BCLK_16=%u Hz ratio=%u\n",               mclk_44k1, bclk_44k1_16, mclk_44k1 / bclk_44k1_16);        printf("TX=%d (0x%04X) -> RX_I2S=%d | RX_0BCLK_ATTEN=%d | RX_1BCLK_CLIP=%d (0x%04X)\n",               tx_peak, (uint16_t)tx_peak, rx_i2s, rx_lj_bug,               rx_clip_bug, (uint16_t)rx_clip_bug);            return (tcr2_div == 1u && rx_i2s == tx_peak && rx_clip_bug == -19196) ? 0 : 1;    }
  1. Philips I2S shifts each 32-bit slot right by 1 BCLK so bit 31 (MSB) lands on the 2nd BCLK edge.
  2. When TX omits the 1-BCLK delay and RX expects I2S, +23170 (0x5A82) shifts left to 0xB504 (-19196)!

Inspecting Bit-Clock Divider Precision and Frame Alignment Output

Check all three lines of ./verify in the shell transcript below. At 48 kHz with 32-bit stereo slots, MCLK = 12,288,000 Hz divides by 4 (TCR2.DIV = 1) with zero remainder to produce BCLK = 3,072,000 Hz, and the 32-word SAI2 FIFO (16 stereo frames) spans 333,333 ns (333.3 us), giving SDMA channel 38 166.7 us to service a half-empty watermark (TFWM = 16).

Next inspect the bit-slip results and strace exit status (0). Matched I2S framing recovers TX = 23170 (0x5A82) identically, whereas a 1-bit early latch (RX_0BCLK_ATTEN = 11585) halves amplitude (-6.02 dB) and a 1-bit late latch (RX_1BCLK_CLIP = -19196, 0xB504) shifts bit 14 into the two's-complement sign bit, inverting positive wave crests into negative spikes.

learner@ksa: ~/gl-e07/m01-l01
learner@ksa:~/gl-e07/m01-l01gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e07/m01-l01./verify48k:  MCLK=12288000 Hz BCLK_32=3072000 Hz TCR2.DIV=1 FIFO_32w=333333 ns44k1: MCLK=11289600 Hz BCLK_16=1411200 Hz ratio=8TX=23170 (0x5A82) -> RX_I2S=23170 | RX_0BCLK_ATTEN=11585 | RX_1BCLK_CLIP=-19196 (0xB504)learner@ksa:~/gl-e07/m01-l01
strace — learner@ksa: ~/gl-e07/m01-l01
learner@ksa:~/gl-e07/m01-l01strace -e trace=write,exit_group ./verifywrite(1, "48k:  MCLK=12288000 Hz BCLK_32=3"..., 211) = 211exit_group(0)                           = ?+++ exited with 0 +++

Synchronous Audio Framing Invariants and Hardware Failure Modes

Every digital audio glitch traces back to one of three physical invariants: frequency coherence (MCLK and BCLK derived from the same PLL4 fractional divider), bit-position alignment (TCR4.FSE matching the codec interface format), or FIFO flow continuity (SDMA bursts beating the 333 us FIFO drain deadline).

When debugging distorted or silent I2S links on i.MX6ULL, resist tuning software mixer gains first. Verify the clock ratios (MCLK / LRCLK == 256 or 384) and confirm both DAI endpoints agree on SND_SOC_DAIFMT_I2S (1-BCLK delay, LRCLK low-for-left) before touching analog PGA controls.

Feeding 44.1 kHz WAV Streams into a Fixed 12.288 MHz MCLK Without PLL Reconfiguration:

  • Symptom: 44.1 kHz audio plays 8.8% too fast and sharp in pitch, or clicks periodically as codec PLL loses lock.
  • Root Cause: 12,288,000 / 44,100 = 278.639, violating the integer 256*fs (11.2896 MHz) oversampling ratio required by synchronous dividers.
  • Fix: Let WM8960 generate BCLK/LRCLK via its fractional PLL (codec-master) or switch PLL4_AUDIO_DIV rate dynamically in hw_params.

Setting SAI2 Watermark TFWM Too Close to 0 or 32:

  • Symptom: Intermittent metallic pops (SAI_TCSR_FEF FIFO Error Flag) during concurrent Ethernet or MMC DMA bursts.
  • Root Cause: With TFWM >= 28, only 4 stereo slots (41 us at 48 kHz) remain when SDMA channel 38 is requested, losing arbitration under bus load.
  • Fix: Set TCR1.TFWM and RCR1.RFWM to mid-FIFO (8..16 words) and enable TCSR.FEIE/graceful FIFO error recovery.

Guided Practice

Calculate MCLK, BCLK, TCR2.DIV, and the 32-word SAI2 TX FIFO drain duration in microseconds for a 16 kHz wideband voice stream packed into 16-bit slots (2 channels, MCLK = 256 * fs). Verify that (MCLK / BCLK) is an even integer and check how much extra SDMA response margin 16 kHz provides compared with 48 kHz (1000 us full FIFO vs 333.3 us).

Independent Practice

Extend verify.c on your host to pack 24-bit signed two's-complement audio samples (-8388608 .. +8388607) into 32-bit Philips I2S slots (MSB at bit 30, 8 trailing zero bits [7:0] plus 1 leading guard bit [31]). Confirm with -Wall -Wextra -Werror that sign extension on unpack preserves negative amplitudes without leaking trailing pad bits.

Verification Checks

quiz · 1 of 3

At fs = 48 kHz stereo with 32-bit slots per channel and MCLK = 256 * fs, what exact (MCLK, BCLK) pair must drive SAI2 and WM8960?

quiz · 2 of 3

Why does transmitting Left-Justified (0-BCLK delay) data into a codec configured for Philips I2S (1-BCLK delay) cause harsh distortion on loud passages?

quiz · 3 of 3

How much playback time does a full 32 x 32-bit i.MX6ULL SAI2 TX FIFO hold at 48 kHz stereo (2 words per stereo frame)?

Key takeaways

  • Philips I2S drives LRCLK low for the left channel and high for the right channel while delaying each sample's MSB by exactly 1 BCLK cycle after every LRCLK transition.
  • Oversampled delta-sigma codecs lock to MCLK = 256 * fs (12.288 MHz at 48 kHz, 11.2896 MHz at 44.1 kHz) while serial bit transport runs at BCLK = 2 * fs * slot_bits.
  • Configuring one link partner for Philips I2S (1-BCLK delay) and the other for Left-Justified (0-BCLK delay) shifts PCM words by 1 bit, adding +6.02 dB gain and sign-wrapping peaks above half scale.
  • The i.MX6ULL SAI2 peripheral at 0x0202C000 pairs 32 x 32-bit TX and RX FIFOs with SDMA event 37 (RX) and event 38 (TX) to absorb bus latency without CPU polling.
Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure