コード例 #1
0
  // **********************  PlugInTemplate Overrides  *************************//
  protected void processRequest(ChannelMap fwdData, PlugInChannelMap out) throws SAPIException {
    if (fwdData.NumberOfChannels() == 0) return;

    // Override member defaults with dynamic options:
    int minDecimation = this.minDecimation, maxSamples = this.maxSamples;
    boolean antiAlias = this.antiAlias;

    java.util.Properties opts = getRequestOptions();
    String temp;
    if ((temp = opts.getProperty("minDecimation")) != null) minDecimation = Integer.parseInt(temp);
    if ((temp = opts.getProperty("maxSamples")) != null) maxSamples = Integer.parseInt(temp);
    if ((temp = opts.getProperty("antiAlias")) != null) antiAlias = "true".equals(temp);

    // 2007/08/15  WHF  maxSamples applies to all channels:
    // 2007/08/15  WHF  Changed their mind.  Uncomment to re-enable.
    /*if (fwdData.NumberOfChannels() == 0) return;
    maxSamples /= fwdData.NumberOfChannels();
    if (maxSamples < 1) maxSamples = 1; */

    for (int index = 0; index < fwdData.NumberOfChannels(); ++index) {
      Object data;

      // Will add if necessary, otherwise just a lookup:
      int outIndex = out.Add(fwdData.GetName(index));

      // data = GetDataAsArray.get(fwdData, index);
      data = fwdData.GetDataAsArray(index);
      if (data == null) {
        System.err.println("ResamplePlugIn: Unsupported datatype.");
        continue;
      }

      int npts = Array.getLength(data);

      if (npts <= maxSamples && minDecimation < 2) {
        // length okay, just copy:
        out.PutTimeRef(fwdData, index);
        out.PutDataRef(outIndex, fwdData, index);
        continue;
      }

      // Calculate the decimation factor for this set:
      int ndeci = (int) Math.ceil(((double) npts) / maxSamples);
      if (ndeci < minDecimation) ndeci = minDecimation;

      double[] ddata = null;
      if (antiAlias) {
        if (fwdData.GetType(index) == ChannelMap.TYPE_FLOAT64) {
          ddata = (double[]) data;
        } else {
          ddata = new double[npts];
          for (int ii = 0; ii < npts; ++ii) ddata[ii] = Array.getDouble(data, ii);
        }
        double[] dataOut = new double[ddata.length];
        Filter lowPass = new Filter(1.0 / ndeci);
        lowPass.filter(ddata, dataOut);
        data = dataOut;
      }

      Object result = decimate(data, ndeci);
      out.PutTime(fwdData.GetTimeStart(index), fwdData.GetTimeDuration(index));
      if (antiAlias) {
        out.PutDataAsFloat64(outIndex, (double[]) result);
      } else {
        switch (fwdData.GetType(index)) {
          case ChannelMap.TYPE_FLOAT32:
            out.PutDataAsFloat32(outIndex, (float[]) result);
            break;

          case ChannelMap.TYPE_FLOAT64:
            out.PutDataAsFloat64(outIndex, (double[]) result);
            break;

          case ChannelMap.TYPE_INT16:
            out.PutDataAsInt16(outIndex, (short[]) result);
            break;

          case ChannelMap.TYPE_INT32:
            out.PutDataAsInt32(outIndex, (int[]) result);
            break;

          case ChannelMap.TYPE_INT64:
            out.PutDataAsInt64(outIndex, (long[]) result);
            break;

          case ChannelMap.TYPE_INT8:
            out.PutDataAsInt8(outIndex, (byte[]) result);
            break;
        }
      }
    }
  }