예제 #1
0
  public static List<Double> audioAnalysis(
      String deviceName, String channel, long averages, NodeContext context) {
    AudioSource source = (AudioSource) context.getData().get(deviceName + ".source");
    if (source == null) return ImmutableList.of();
    FFT fft = new FFT(source.bufferSize(), source.sampleRate());
    fft.window(FFT.HANN);

    if (averages > 0) fft.linAverages((int) averages);

    if (channel.equals("left")) {
      fft.forward(source.left);
    } else if (channel.equals("right")) {
      fft.forward(source.right);
    } else {
      fft.forward(source.mix);
    }

    ImmutableList.Builder<Double> b = new ImmutableList.Builder<Double>();
    if (averages == 0) {
      for (int i = 0; i < fft.specSize(); i++) b.add((double) fft.getBand(i));
    } else {
      for (int i = 0; i < fft.avgSize(); i++) b.add((double) fft.getAvg(i));
    }
    return b.build();
  }
예제 #2
0
  public void fftLogUpdate() {
    fftThreshold = Constants.FFT_THRESHOLD;
    for (int i = 0; i < getFftLog().avgSize(); i++) {
      fftPrev[i] = getFftLog().getAvg(i);
    }
    getFftLog().forward(song.mix);

    largeAmp = getFftLog().getAvg(0);
    largeBand = 0;
    for (int i = 0; i < getFftLog().avgSize(); i++) {
      fftDiff[i] = getFftLog().getAvg(i) - fftPrev[i];
      if (fftDiff[i] >= fftThreshold) {
        beats[i] = true;
      } else {
        beats[i] = false;
      }
      if (fft.getAvg(i) > largeAmp) {
        largeAmp = getFftLog().getAvg(i);
        largeBand = i;
      }
    }
    if (enemiesGenned > 0) {
      consecFramesGenned++;
    } else if (enemiesGenned == 0) {
      consecFramesGenned--;
      if (consecFramesGenned < 0) {
        consecFramesGenned = 0;
      }
    }

    // System.out.println("EnemiesGenned: " + enemiesGenned + " consecFrames: " +
    // consecFramesGenned);

    if (consecFramesGenned == 0 && Constants.FFT_THRESHOLD > Constants.FFT_THRESHOLD_MIN) {
      Constants.FFT_THRESHOLD--;
      // System.out.println("FFT Minus: "+Constants.FFT_THRESHOLD);
    }
    if (consecFramesGenned >= 2 && Constants.FFT_THRESHOLD < Constants.FFT_THRESHOLD_MAX) {
      Constants.FFT_THRESHOLD++;
      // System.out.println("FFT Plus: "+Constants.FFT_THRESHOLD);

    }
  }
예제 #3
0
  public static List<Double> audioLogAvg(
      String deviceName, String channel, long baseFreq, long bandsPerOctave, NodeContext context) {
    AudioSource source = (AudioSource) context.getData().get(deviceName + ".source");
    if (source == null) return ImmutableList.of();
    FFT fft = new FFT(source.bufferSize(), source.sampleRate());
    fft.window(FFT.HANN);

    fft.logAverages((int) baseFreq, (int) bandsPerOctave);

    if (channel.equals("left")) {
      fft.forward(source.left);
    } else if (channel.equals("right")) {
      fft.forward(source.right);
    } else {
      fft.forward(source.mix);
    }

    ImmutableList.Builder<Double> b = new ImmutableList.Builder<Double>();
    for (int i = 0; i < fft.avgSize(); i++) b.add((double) fft.getAvg(i));
    return b.build();
  }