def build_delay_indices(
    B: int, T: int, C: int, delay_pattern: tp.List[int]
) -> tp.Tuple[mx.array, mx.array]:
    """
    Precompute (t_idx_BxTxC, indices_BTCx3) so that out[t, c] = in[t - delay[c], c].
    Negative t_idx => BOS; t_idx >= T => PAD.
    """
    delay_arr = mx.array(delay_pattern, dtype=mx.int32)

    t_idx_BxT = mx.broadcast_to(
        mx.arange(T, dtype=mx.int32)[None, :],
        [B, T],
    )
    t_idx_BxTx1 = mx.expand_dims(t_idx_BxT, -1)
    t_idx_BxTxC = t_idx_BxTx1 - mx.reshape(delay_arr, (1, 1, C))

    b_idx_BxTxC = mx.broadcast_to(
        mx.reshape(mx.arange(B, dtype=mx.int32), (B, 1, 1)),
        [B, T, C],
    )
    c_idx_BxTxC = mx.broadcast_to(
        mx.reshape(mx.arange(C, dtype=mx.int32), (1, 1, C)),
        [B, T, C],
    )

    # We must clamp time indices to [0..T-1] so gather_nd equivalent won't fail
    t_clamped_BxTxC = mx.clip(t_idx_BxTxC, 0, T - 1)

    indices_BTCx3 = mx.stack(
        [
            mx.reshape(b_idx_BxTxC, (-1,)),
            mx.reshape(t_clamped_BxTxC, (-1,)),
            mx.reshape(c_idx_BxTxC, (-1,)),
        ],
        axis=1,
    ).astype(mx.int32)

    return t_idx_BxTxC, indices_BTCx3

    Precompute (t_idx_BxTxC, indices_BTCx3) so that out[t, c] = in[t - delay[c], c].
    Negative t_idx => BOS; t_idx >= T => PAD.
    
mlx_audio/tts/models/dia/audio.py