51 lines
1.1 KiB
Java
51 lines
1.1 KiB
Java
package de.zuim.ledcontrol.effects;
|
|
|
|
import java.awt.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import static de.zuim.ledcontrol.LEDControl.HEIGHT;
|
|
import static de.zuim.ledcontrol.LEDControl.WIDTH;
|
|
|
|
public class AudioVolumeEffect extends AudioFFTEffect {
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Audio Volume";
|
|
}
|
|
|
|
List<Integer> volHistory = new ArrayList<>();
|
|
long timeDeltaSum = 0;
|
|
|
|
@Override
|
|
public void render(long timeDelta, Graphics g) {
|
|
timeDeltaSum += timeDelta;
|
|
|
|
if (!getData().isEmpty()) {
|
|
/*float avg = 0;
|
|
float max = 0;
|
|
for (double v : getData().get(0)) {
|
|
avg += Math.abs(v);
|
|
if (v > max) {
|
|
max = (float) v;
|
|
}
|
|
}
|
|
avg /= cachedMagnitudes.get(0).length;*/
|
|
System.out.println(getData().get(0).level);
|
|
volHistory.add((int) (getData().get(0).level * 100));
|
|
getData().clear();
|
|
}
|
|
|
|
if (volHistory.size() > WIDTH) {
|
|
volHistory.remove(0);
|
|
}
|
|
|
|
for (int x = 0; x < volHistory.size(); x++) {
|
|
|
|
g.setColor(new Color((int) ((Math.abs(volHistory.get(x)) + 1) * ((WIDTH - x) / (float) WIDTH)), 2, 0));
|
|
g.drawRect(x, HEIGHT - volHistory.get(x), 0, HEIGHT);
|
|
}
|
|
}
|
|
|
|
}
|