add volumeeffect

This commit is contained in:
Felix Klenner 2021-03-14 16:41:22 +01:00
parent 139b4245ea
commit 2041227002
3 changed files with 8 additions and 13 deletions

View file

@ -16,8 +16,8 @@ public class EffectManager {
private boolean sweep = false;
private final LEDEffect[] effects = new LEDEffect[]{new ClockEffect(), new NetworkSpeedEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
private int activeId = 4;
private final LEDEffect[] effects = new LEDEffect[]{new ClockEffect(), new NetworkSpeedEffect(), new AudioVolumeEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
private int activeId = 0;
private final TrayIcon trayIcon;
public EffectManager() {

View file

@ -6,6 +6,7 @@ import de.zuim.ledcontrol.LEDEffect;
import javax.sound.sampled.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class AudioEffect implements LEDEffect {
@ -82,14 +83,14 @@ public abstract class AudioEffect implements LEDEffect {
double[] magnitudes = toMagnitudes(realPart, imaginaryPart);
cachedAudioData.add(new AudioData(magnitudes, targetLine.getLevel()));
/*System.out.println("M"+ Arrays.toString(magnitudes));
float max = 0, avg = 0, min = 11111111;
//System.out.println("M"+ Arrays.toString(magnitudes));
/*float max = 0, avg = 0, min = 11111111;
for (float m : fBuf) {
avg += m;
if (m > max)
max = (int) m;
max = m;
if (m < min)
min = (int) m;
min = m;
}
System.out.println("M"+ max+" "+min+" "+avg/fBuf.length+ " "+read+" "+fBuf.length);*/

View file

@ -23,16 +23,11 @@ public class AudioVolumeEffect extends AudioFFTEffect {
if (!getData().isEmpty()) {
float avg = 0;
float max = 0;
for (double v : getData().get(0).magnitudes) {
avg += Math.abs(v);
if (v > max) {
max = (float) v;
}
}
avg /= getData().get(0).magnitudes.length;
System.out.println(avg);
volHistory.add((int) (getData().get(0).level * 100));
volHistory.add((int) (((avg*-1)+40)/3));
getData().clear();
}
@ -41,7 +36,6 @@ public class AudioVolumeEffect extends AudioFFTEffect {
}
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);
}