public void split(int threshold, int interval, int duration) { int k = 0; int start = 0, end = 0; do { // loops above threshold values appear while (Math.abs(buf[k]) < threshold && ++k < length) ; // if the above threshold value is found if (k < length) { start = k; end = k; // loops until it founds out below // threshold period longer than duration value while ((Math.abs(buf[k]) > threshold || k - end < duration) && ++k < length) { if (Math.abs(buf[k]) > threshold) end = k; } // if the above threshold period is longer than interval value // and below threshold period is longer than duration value if (end - start > interval && (k - end >= duration || k >= length)) { add(new Segment(start, end)); } } } while (++k < length); }