def first_sample_of_frame(frame,
                          frame_shift_in_samples,
                          window_size_in_samples):
    """
    Returns the sample-index of the first sample of the frame with index
    'frame'.  Caution: this may be negative; we treat out-of-range samples
    as zero.
    Analogous to with kaldi10's FirstSampleOfFrame in feat/feature-window.h

    Args:
        frame (int): The frame index >= 0.
        frame_shift_in_samples (int) The frame shift in samples
        window_size_in_samples (int)  The window size in samples
    Returns:
        int: The first sample of this frame (caution: may be negative).
    """
    midpoint_of_frame = frame_shift_in_samples * frame + (frame_shift_in_samples // 2)
    beginning_of_frame = midpoint_of_frame - window_size_in_samples // 2
    assert isinstance(beginning_of_frame, int)  # indirectly check inputs were
                                                # int.
    return beginning_of_frame