public void identfyOnsets(double[] onset_vel, ArrayList<Integer> onset_peaks, ArrayList<Integer> onset_starts,
                            ArrayList<Integer> onset_ends) {
    double max = -Double.MAX_VALUE;
    int max_idx = -1;
    boolean in_peak = false;

    for (int i = 0; i < onset_vel.length; ++i) {
      if (!in_peak) {
        if (onset_vel[i] != 0) {
          onset_starts.add(i);
          in_peak = true;
        }
      } else { // in_peak == true
        if (onset_vel[i] > max) {
          max = onset_vel[i];
          max_idx = i;
        }
        if (onset_vel[i] == 0) {
          onset_ends.add(i);
          assert max_idx != -1;
          onset_peaks.add(max_idx);
          in_peak = false;
          max = -Double.MAX_VALUE;
          max_idx = -1;
        }
      }
    }
    if (in_peak) {
      onset_ends.add(onset_vel.length - 1);
      if (max_idx == -1)
        onset_peaks.add(onset_vel.length - 1);
      else
        onset_peaks.add(max_idx);
    }
  }