예제 #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 static List<Map<String, Double>> audioWave(String deviceName, NodeContext context) {
   AudioSource source = (AudioSource) context.getData().get(deviceName + ".source");
   if (source == null) return ImmutableList.of();
   ImmutableList.Builder<Map<String, Double>> b = ImmutableList.builder();
   for (int i = 0; i < source.bufferSize(); i++) {
     ImmutableMap.Builder<String, Double> mb = ImmutableMap.builder();
     mb.put("left", (double) source.left.get(i));
     mb.put("right", (double) source.right.get(i));
     mb.put("mix", (double) source.mix.get(i));
     b.add(mb.build());
   }
   return b.build();
 }
예제 #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();
  }