getNoiseAreas method

List<int> getNoiseAreas(
  1. List<int> list
)

Implementation

List<int> getNoiseAreas(List<int> list) {
  //delete traling zeros
  removeTrailingZeros(list);

  List<int> bpmCorrected = [];
  correctionCount = 0;
  //reduce zeros and jumps
  for (int i = 0; i < list.length; i++) {
    if (list[i] == 0) {
      correctionCount = correctionCount! + 1;
      list[i] = getNextNonZeroBpm(i, list);
      bpmCorrected.add(i);
    }
  }

  //Log.i("Correction count", correctionCount + "");
  for (int i = 1; i < list.length; i++) {
    int startData = list[i - 1];
    int stopData = list[i];
    if (startData < 60 ||
        stopData < 60 ||
        startData > 210 ||
        stopData > 210 ||
        (startData - stopData).abs() > 35) {
      correctionCount = correctionCount! + 1;
      if (stopData - startData > 50 && startData > 60 && stopData > 110) {
        list[--i] = ((startData + stopData) / 2).truncate();
        continue;
      } else {
        list[i] = getNextValidBpm(i, list);
      }
      if (!bpmCorrected.contains(i)) bpmCorrected.add(i);
      //Log.i("Correction", i + "");
    }
  }
  //Log.i("Correction count", correctionCount + "");

  bpmCorrected.sort();
  return bpmCorrected;
}