def local_frame_indices(local_first, nlocal, frame_offset, frame_size):
    """Compute frame overlap with local data.

    Args:
        local_first (int): the first sample of the local data.
        nlocal (int): the number of local samples.
        frame_offset (int): the first sample of the frame.
        frame_size (int): the number of samples in the frame.

    Returns:
        tuple: the local sample offset (zero == start of local data) of the
            overlap data, the frame sample offset (zero == start of frame) of
            the overlap data, the number of samples in the overlap.

    """
    # The first sample in our local data buffer
    local_off = None

    # The first sample in the frame data buffer
    froff = None

    # The number of samples of overlap
    nsamp = None

    # Does this frame overlap with any of our data?
    if (frame_offset < local_first + nlocal) and (
        frame_offset + frame_size > local_first
    ):
        # compute offsets into our local data and the frame
        if frame_offset >= local_first:
            # The frame starts in the middle of our local sample range.
            local_off = frame_offset - local_first
            froff = 0
        else:
            # Our local samples start in the middle of the frame.
            local_off = 0
            froff = local_first - frame_offset
        nsamp = frame_size
        if local_off + nsamp > nlocal:
            # The frame extends beyond our local samples
            nsamp = nlocal - local_off

    return (local_off, froff, nsamp)