'Process raw buffer (callback from RtClient).
Note: Do not print log messages during regular use. It will be printed
asynchronously which is annoying when working in an interactive shell.
Parameters
raw_buffer : array of float, shape=(nchan, n_times)
The raw buffer.'

def _process_raw_buffer(self, raw_buffer):

    verbose = 'ERROR'
    sfreq = self.info['sfreq']
    n_samp = len(self._raw_times)
    tmin_samp = int(round((sfreq * self.tmin)))
    tmax_samp = (tmin_samp + n_samp)
    last_samp = ((self._first_samp + raw_buffer.shape[1]) - 1)
    raw_buffer = (self._cals * raw_buffer)
    data = np.abs(raw_buffer[self._stim_picks]).astype(np.int)
    if (self._last_buffer is not None):
        prev_data = self._last_buffer[self._stim_picks, (- raw_buffer.shape[1]):].astype(np.int)
        data = np.concatenate((prev_data, data), axis=1)
        data = np.atleast_2d(data)
        buff_events = _find_events(data, (self._first_samp - raw_buffer.shape[1]), verbose=verbose, **self._find_events_kwargs)
    else:
        data = np.atleast_2d(data)
        buff_events = _find_events(data, self._first_samp, verbose=verbose, **self._find_events_kwargs)
    events = self._event_backlog
    min_event_samp = (self._first_samp - int(self._find_events_kwargs['min_samples']))
    if (len(self._event_backlog) > 0):
        backlog_samps = np.array(self._event_backlog)[:, 0]
        min_event_samp = (backlog_samps[(-1)] + 1)
    if (buff_events.shape[0] > 0):
        valid_events_idx = (buff_events[:, 0] >= min_event_samp)
        buff_events = buff_events[valid_events_idx]
    for event_id in self.event_id.values():
        idx = np.where((buff_events[:, (-1)] == event_id))[0]
        events.extend(zip(list(buff_events[(idx, 0)]), list(buff_events[(idx, (-1))])))
    events.sort()
    event_backlog = list()
    for (event_samp, event_id) in events:
        epoch = None
        if (((event_samp + tmin_samp) >= self._first_samp) and ((event_samp + tmax_samp) <= last_samp)):
            start = ((event_samp + tmin_samp) - self._first_samp)
            stop = ((event_samp + tmax_samp) - self._first_samp)
            epoch = raw_buffer[:, start:stop]
        elif (((event_samp + tmin_samp) < self._first_samp) and ((event_samp + tmax_samp) <= last_samp)):
            if (self._last_buffer is None):
                continue
            n_last = (self._first_samp - (event_samp + tmin_samp))
            n_this = (n_samp - n_last)
            epoch = np.c_[(self._last_buffer[:, (- n_last):], raw_buffer[:, :n_this])]
        elif ((event_samp + tmax_samp) > last_samp):
            event_backlog.append((event_samp, event_id))
        else:
            raise RuntimeError('Unhandled    case..')
        if (epoch is not None):
            self._append_epoch_to_queue(epoch, event_samp, event_id)
    self._event_backlog = event_backlog
    n_buffer = raw_buffer.shape[1]
    if (self._last_buffer is None):
        self._last_buffer = raw_buffer
        self._first_samp = (last_samp + 1)
    elif (self._last_buffer.shape[1] <= (n_samp + n_buffer)):
        self._last_buffer = np.c_[(self._last_buffer, raw_buffer)]
    else:
        self._first_samp = (self._first_samp + n_buffer)
        self._last_buffer[:, :(- n_buffer)] = self._last_buffer[:, n_buffer:]
        self._last_buffer[:, (- n_buffer):] = raw_buffer
