Program: 20087
Project: 20087
Buggy source:
/** 
 * Build a mel filterbank with the parameters given. Each filter will be shaped as a triangle. The triangles overlap so that they cover the whole frequency range requested. The edges of a given triangle will be by default at the center of the  neighboring triangles.
 * @param NPoint number of points in the power spectrum
 * @param numberFilters number of filters in the filterbank
 * @param minFreq lowest frequency in the range of interest
 * @param maxFreq highest frequency in the range of interest
 */
private void buildFilterbank(int NPoint,int numberFilters,double minFreq,double maxFreq){
  double minFreqMel;
  double maxFreqMel;
  double deltaFreqMel;
  double leftEdge;
  double centerFreq;
  double centerFreqMel;
  double rightEdge;
  double rightEdgeMel;
  double initialFreqBin;
  double deltaFreq;
  this.filter=new MelFilter[numberFilters];
  minFreqMel=linToMelFreq(minFreq);
  maxFreqMel=linToMelFreq(maxFreq);
  deltaFreqMel=(maxFreqMel - minFreqMel) / (numberFilters + 1);
  deltaFreq=(double)sampleRate / NPoint;
  leftEdge=minFreq;
  centerFreqMel=minFreqMel + deltaFreqMel;
  centerFreq=melToLinFreq(centerFreqMel);
  for (int i=0; i < numberFilters; i++) {
    initialFreqBin=Math.round((leftEdge / deltaFreq)) * deltaFreq;
    rightEdgeMel=centerFreqMel + deltaFreqMel;
    rightEdge=melToLinFreq(rightEdgeMel);
    this.filter[i]=new MelFilter();
    this.filter[i].createMelFilter(leftEdge,centerFreq,rightEdge,initialFreqBin,deltaFreq,(sampleRate >> 1));
    leftEdge=centerFreq;
    centerFreq=rightEdge;
    centerFreqMel=rightEdgeMel;
  }
}

Fixed version (ground truth):
/** 
 * Build a mel filterbank with the parameters given. Each filter will be shaped as a triangle. The triangles overlap so that they cover the whole frequency range requested. The edges of a given triangle will be by default at the center of the  neighboring triangles.
 * @param NPoint number of points in the power spectrum
 * @param numberFilters number of filters in the filterbank
 * @param minFreq lowest frequency in the range of interest
 * @param maxFreq highest frequency in the range of interest
 */
private void buildFilterbank(int NPoint,int numberFilters,double minFreq,double maxFreq){
  double minFreqMel;
  double maxFreqMel;
  double deltaFreqMel;
  double[] leftEdge=new double[numberFilters];
  double[] centerFreq=new double[numberFilters];
  double[] rightEdge=new double[numberFilters];
  double nextEdgeMel;
  double nextEdge;
  double initialFreqBin;
  double deltaFreq;
  this.filter=new MelFilter[numberFilters];
  deltaFreq=(double)sampleRate / NPoint;
  minFreqMel=linToMelFreq(minFreq);
  maxFreqMel=linToMelFreq(maxFreq);
  deltaFreqMel=(maxFreqMel - minFreqMel) / (numberFilters + 1);
  leftEdge[0]=setToNearestFrequencyBin(minFreq,deltaFreq);
  nextEdgeMel=minFreqMel;
  for (int i=0; i < numberFilters; i++) {
    nextEdgeMel+=deltaFreqMel;
    nextEdge=melToLinFreq(nextEdgeMel);
    centerFreq[i]=setToNearestFrequencyBin(nextEdge,deltaFreq);
    if (i > 0) {
      rightEdge[i - 1]=centerFreq[i];
    }
    if (i < numberFilters - 1) {
      leftEdge[i + 1]=centerFreq[i];
    }
  }
  nextEdgeMel=nextEdgeMel + deltaFreqMel;
  nextEdge=melToLinFreq(nextEdgeMel);
  rightEdge[numberFilters - 1]=setToNearestFrequencyBin(nextEdge,deltaFreq);
  for (int i=0; i < numberFilters; i++) {
    initialFreqBin=setToNearestFrequencyBin(leftEdge[i],deltaFreq);
    if (initialFreqBin < leftEdge[i]) {
      initialFreqBin+=deltaFreq;
    }
    this.filter[i]=new MelFilter(leftEdge[i],centerFreq[i],rightEdge[i],initialFreqBin,deltaFreq);
  }
}