Beispiel #1
0
  private static void removeMultipleHits(PriorityQueue<Result> results, int sampleLength) {
    if (results.isEmpty()) return;

    ArrayList<Result> acceptedResults = new ArrayList<Result>();

    boolean isOccupied[] = new boolean[sampleLength];
    while (!results.isEmpty()) {
      Result r = results.poll();

      int hitCount = 0;
      int firstHitPosition = -1;
      for (int i = 0; i < r.getLength(); i++) {
        if (!isOccupied[r.getSampleStartPosition() + i]) {
          if (hitCount == 0) {
            firstHitPosition = r.getSampleStartPosition() + i;
          }
          hitCount++;
          isOccupied[r.getSampleStartPosition() + i] = true;
        } else if (hitCount != 0) {
          break;
        }
      }

      if (hitCount >= FRAME_COUNT_ACCEPTANCE_THRESHOLD) {
        r.setSampleStartPosition(firstHitPosition);
        r.setLength(hitCount);
        acceptedResults.add(r);
      }
    }

    results.addAll(acceptedResults);
  }
Beispiel #2
0
  private static void printProductionOutput(PriorityQueue<Result> results, double sizeOfWindow) {
    while (!results.isEmpty()) {
      Result r = results.poll();

      long startSec = Math.round(r.getSampleStartPosition() * sizeOfWindow);
      long startMin = startSec / 60L;
      startSec %= 60L;

      long endSec = Math.round((r.getSampleStartPosition() + r.getLength()) * sizeOfWindow);
      long endMin = endSec / 60L;
      endSec %= 60L;

      System.out.println(
          startMin + " " + startSec + " " + endMin + " " + endSec + " " + r.getSong());
    }
  }
Beispiel #3
0
 @Override
 public int compare(Result a, Result b) {
   return Integer.compare(a.getSampleStartPosition(), b.getSampleStartPosition());
 }
Beispiel #4
0
  private static void flattenResults(
      PriorityQueue<Result> results, int songLength, int sampleLength) {
    if (results.isEmpty()) return;

    String songName = results.peek().getSong();
    double lowerThreshold = results.peek().getMfcc() - MFCC_FLATTEN_LOWER_THRESHOLD;

    double mfccAverage = 0.0;
    for (Result i : results) {
      mfccAverage += i.getMfcc();
    }
    //		System.err.println(songName);
    //		System.err.println("Flatten: " + results.size());
    //		System.err.println(mfccAverage / results.size());
    //		System.err.println();

    double mfccScores[] = new double[sampleLength];
    while (!results.isEmpty()) {
      Result r = results.poll();
      if (r.getMfcc() < lowerThreshold) continue;
      //			System.out.println(r);
      for (int i = 0; i < r.getLength(); i++) {
        if (mfccScores[r.getSampleStartPosition() + i] == 0.0) {
          mfccScores[r.getSampleStartPosition() + i] = r.getMfcc();
        }
      }
    }

    //		System.out.println(songName);

    PriorityQueue<Result> resultsByTime =
        new PriorityQueue<Result>(Result.SAMPLE_START_TIME_COMPARATOR);

    double totalMfccScore = 0.0;
    int totalMfccCount = 0;
    int i;
    for (i = 0; i < mfccScores.length; i++) {
      if (mfccScores[i] == 0.0) {
        if (totalMfccCount != 0) {
          resultsByTime.add(
              new Result(
                  totalMfccScore / totalMfccCount,
                  -1,
                  i - totalMfccCount,
                  totalMfccCount,
                  songName));
          totalMfccScore = 0.0;
          totalMfccCount = 0;
        }
      } else {
        totalMfccScore += mfccScores[i];
        totalMfccCount++;
      }
    }

    if (totalMfccCount != 0) {
      resultsByTime.add(
          new Result(
              totalMfccScore / totalMfccCount, -1, i - totalMfccCount, totalMfccCount, songName));
      totalMfccScore = 0.0;
      totalMfccCount = 0;
    }

    if (resultsByTime.isEmpty()) return;

    Result currentResult = resultsByTime.poll();
    while (!resultsByTime.isEmpty()) {
      Result nextResult = resultsByTime.poll();
      if (nextResult.getSampleStartPosition()
              - currentResult.getSampleStartPosition()
              - currentResult.getLength()
          <= NON_MATCH_FRAME_TOLERANCE) {

        // new Result(mfcc, songStartPosition, sampleStartPosition, length, song)
        currentResult =
            new Result(
                currentResult.getMfcc()
                        * currentResult.getLength()
                        / (currentResult.getLength() + nextResult.getLength())
                    + nextResult.getMfcc()
                        * nextResult.getLength()
                        / (currentResult.getLength() + nextResult.getLength()),
                currentResult.getSongStartPosition(),
                currentResult.getSampleStartPosition(),
                currentResult.getLength()
                    + nextResult.getLength()
                    + (nextResult.getSampleStartPosition()
                        - currentResult.getSampleStartPosition()
                        - currentResult.getLength()),
                currentResult.getSong());
      } else {
        results.add(currentResult);
        currentResult = nextResult;
      }
    }
    results.add(currentResult);
  }