/** computes the estimated event rate for a packet of events */
 private void computeEstimatedEventRate(AEPacketRaw events) {
   if (events == null || events.getNumEvents() < 2) {
     estimatedEventRate = 0;
   } else {
     int[] ts = events.getTimestamps();
     int n = events.getNumEvents();
     int dt = ts[n - 1] - ts[0];
     estimatedEventRate = (int) (1e6f * (float) n / (float) dt);
   }
 }
    /**
     * extracts the meaning of the raw events.
     *
     * @param in the raw events, can be null
     * @return out the processed events. these are partially processed in-place. empty packet is
     *     returned if null is supplied as in.
     */
    @Override
    public synchronized EventPacket extractPacket(AEPacketRaw in) {
      if (out == null) {
        out = new EventPacket<PolarityEvent>(chip.getEventClass());
      } else {
        out.clear();
      }
      if (in == null) {
        return out;
      }
      int n = in.getNumEvents(); // addresses.length;

      int skipBy = 1;
      if (isSubSamplingEnabled()) {
        while (n / skipBy > getSubsampleThresholdEventCount()) {
          skipBy++;
        }
      }
      int[] a = in.getAddresses();
      int[] timestamps = in.getTimestamps();
      OutputEventIterator outItr = out.outputIterator();
      for (int i = 0; i < n; i += skipBy) { // bug here
        int addr = a[i];
        PolarityEvent e = (PolarityEvent) outItr.nextOutput();
        e.address = addr;
        e.timestamp = (timestamps[i]);
        e.x = (short) (((addr & XMASK) >>> XSHIFT));
        e.y = (short) ((addr & YMASK) >>> YSHIFT);
        e.type = (byte) (addr & 1);
        e.polarity = e.type == 1 ? PolarityEvent.Polarity.Off : PolarityEvent.Polarity.On;
        if (e.x < 0 || e.x >= sizeX || e.y < 0 || e.y >= sizeY) {
          log.warning(
              e.toString()
                  + " is outside size of chip"); // TODO should remove for speed once problems with
                                                 // y address outside legal range are sorted out
        }
      }
      return out;
    }