import bisect


def get_concatenated_signal_index_data(segment_bounds, index):
    
    """
    Gets time index data for a concatenated signal.
    
    Given an index in the concatenated signal, this function returns
    the corresponding segment number and segment index.
    
    Parameters
    ----------
    
    segment_bounds : int sequence
        concatenated signal indices of segment boundaries.
        
        The length of this sequence must be one more than the number of
        segments in the concatenated signal. The ith element of the
        sequence must be the sum of the lengths of segments zero through i.
    
    index : int
        concatenated signal index.
        
        This parameter can be less than zero or greater than the
        concatenated signal length.
    
    Returns
    -------
    
    segment_num : int
        the number of the signal segment that includes the specified signal
        index.
        
        This return value will be -1 if the specified index is negative,
        or the number of signal segments if the specified index is greater
        than the concatenated signal length.
    
    segment_index : int
        the index within segment `segment_num` of the specified signal index.
        
        This return value will be negative if `segment_num` is -1,
        indicating a number of sample frames prior to the start of the
        signal. Otherwise it will be nonnegative.
    """
    
    if index < 0:
        # index prior to signal start
        
        return -1, index
    
    else:
        # index not prior to signal start
        
        segment_num = bisect.bisect_right(segment_bounds, index) - 1
        segment_index = index - segment_bounds[segment_num]
        return segment_num, segment_index