Program: 20071
Project: 20071
Buggy source:
/** 
 * Constructs a filter from the parameters. In the current implementation, the filter is a bandpass filter with a triangular shape.  We're given the left and right edges and the center frequency, so we can determine the right and left slopes, which could be not only assymmetric but completely different. We're also given the initial frequency, which may or may not coincide with the left edge, and the frequency step.
 * @param leftEdge the filter's lowest passing frequency
 * @param centerFreq the filter's center frequency
 * @param rightEdge the filter's highest passing frequency
 * @param initialFreq the first frequency bin in the pass band
 * @param deltaFreq the step in the frequency axis betweenfrequency bins
 * @param samplingRate sampling frequency
 */
public void createMelFilter(double leftEdge,double centerFreq,double rightEdge,double initialFreq,double deltaFreq,int samplingRate){
  double filterHeight;
  double leftSlope;
  double rightSlope;
  double currentFreq;
  int indexFilterWeight;
  int numberElementsWeightField;
  numberElementsWeightField=(int)Math.round((rightEdge - leftEdge) / deltaFreq + 1);
  weight=new double[numberElementsWeightField];
  filterHeight=2.0f / (rightEdge - leftEdge);
  leftSlope=filterHeight / (centerFreq - leftEdge);
  rightSlope=filterHeight / (rightEdge - centerFreq);
  for (currentFreq=initialFreq, indexFilterWeight=0; currentFreq <= rightEdge; currentFreq+=deltaFreq, indexFilterWeight++) {
    if (currentFreq < centerFreq) {
      weight[indexFilterWeight]=leftSlope * (currentFreq - leftEdge);
    }
 else {
      weight[indexFilterWeight]=filterHeight + rightSlope * (currentFreq - centerFreq);
    }
  }
  this.initialFreqIndex=(int)Math.round(initialFreq / deltaFreq);
}

Fixed version (ground truth):
/** 
 * Constructs a filter from the parameters. In the current implementation, the filter is a bandpass filter with a triangular shape.  We're given the left and right edges and the center frequency, so we can determine the right and left slopes, which could be not only assymmetric but completely different. We're also given the initial frequency, which may or may not coincide with the left edge, and the frequency step.
 * @param leftEdge the filter's lowest passing frequency
 * @param centerFreq the filter's center frequency
 * @param rightEdge the filter's highest passing frequency
 * @param initialFreq the first frequency bin in the pass band
 * @param deltaFreq the step in the frequency axis betweenfrequency bins
 * @param samplingRate sampling frequency
 */
public void createMelFilter(double leftEdge,double centerFreq,double rightEdge,double initialFreq,double deltaFreq,int samplingRate){
  double filterHeight;
  double leftSlope;
  double rightSlope;
  double currentFreq;
  int indexFilterWeight;
  int numberElementsWeightField;
  numberElementsWeightField=(int)Math.round((rightEdge - leftEdge) / deltaFreq + 1);
  weight=new double[numberElementsWeightField];
  filterHeight=2.0f / (rightEdge - leftEdge);
  leftSlope=filterHeight / (centerFreq - leftEdge);
  rightSlope=filterHeight / (centerFreq - rightEdge);
  for (currentFreq=initialFreq, indexFilterWeight=0; currentFreq <= rightEdge; currentFreq+=deltaFreq, indexFilterWeight++) {
    if (currentFreq < centerFreq) {
      weight[indexFilterWeight]=leftSlope * (currentFreq - leftEdge);
    }
 else {
      weight[indexFilterWeight]=filterHeight + rightSlope * (currentFreq - centerFreq);
    }
  }
  this.initialFreqIndex=(int)Math.round(initialFreq / deltaFreq);
}