def validate_length(x, y, hop_size=None):
    """ Validate length
    Args:
        x (ndarray): numpy array with x.shape[0] = len_x
        y (ndarray): numpy array with y.shape[0] = len_y
        hop_size (int): upsampling factor
    Returns:
        (ndarray): length adjusted x with same length y
        (ndarray): length adjusted y with same length x
    """
    if hop_size is None:
        if x.shape[0] < y.shape[0]:
            y = y[:x.shape[0]]
        if x.shape[0] > y.shape[0]:
            x = x[:y.shape[0]]
        assert len(x) == len(y)
    else:
        if x.shape[0] > y.shape[0] * hop_size:
            x = x[:y.shape[0] * hop_size]
        if x.shape[0] < y.shape[0] * hop_size:
            mod_y = y.shape[0] * hop_size - x.shape[0]
            mod_y_frame = mod_y // hop_size + 1
            y = y[:-mod_y_frame]
            x = x[:y.shape[0] * hop_size]
        assert len(x) == len(y) * hop_size

    return x, y