add volumeeffect
This commit is contained in:
parent
139b4245ea
commit
2041227002
3 changed files with 8 additions and 13 deletions
|
@ -16,8 +16,8 @@ public class EffectManager {
|
||||||
private boolean sweep = false;
|
private boolean sweep = false;
|
||||||
|
|
||||||
|
|
||||||
private final LEDEffect[] effects = new LEDEffect[]{new ClockEffect(), new NetworkSpeedEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
|
private final LEDEffect[] effects = new LEDEffect[]{new ClockEffect(), new NetworkSpeedEffect(), new AudioVolumeEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
|
||||||
private int activeId = 4;
|
private int activeId = 0;
|
||||||
private final TrayIcon trayIcon;
|
private final TrayIcon trayIcon;
|
||||||
|
|
||||||
public EffectManager() {
|
public EffectManager() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import de.zuim.ledcontrol.LEDEffect;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AudioEffect implements LEDEffect {
|
public abstract class AudioEffect implements LEDEffect {
|
||||||
|
@ -82,14 +83,14 @@ public abstract class AudioEffect implements LEDEffect {
|
||||||
double[] magnitudes = toMagnitudes(realPart, imaginaryPart);
|
double[] magnitudes = toMagnitudes(realPart, imaginaryPart);
|
||||||
cachedAudioData.add(new AudioData(magnitudes, targetLine.getLevel()));
|
cachedAudioData.add(new AudioData(magnitudes, targetLine.getLevel()));
|
||||||
|
|
||||||
/*System.out.println("M"+ Arrays.toString(magnitudes));
|
//System.out.println("M"+ Arrays.toString(magnitudes));
|
||||||
float max = 0, avg = 0, min = 11111111;
|
/*float max = 0, avg = 0, min = 11111111;
|
||||||
for (float m : fBuf) {
|
for (float m : fBuf) {
|
||||||
avg += m;
|
avg += m;
|
||||||
if (m > max)
|
if (m > max)
|
||||||
max = (int) m;
|
max = m;
|
||||||
if (m < min)
|
if (m < min)
|
||||||
min = (int) m;
|
min = m;
|
||||||
}
|
}
|
||||||
System.out.println("M"+ max+" "+min+" "+avg/fBuf.length+ " "+read+" "+fBuf.length);*/
|
System.out.println("M"+ max+" "+min+" "+avg/fBuf.length+ " "+read+" "+fBuf.length);*/
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,11 @@ public class AudioVolumeEffect extends AudioFFTEffect {
|
||||||
|
|
||||||
if (!getData().isEmpty()) {
|
if (!getData().isEmpty()) {
|
||||||
float avg = 0;
|
float avg = 0;
|
||||||
float max = 0;
|
|
||||||
for (double v : getData().get(0).magnitudes) {
|
for (double v : getData().get(0).magnitudes) {
|
||||||
avg += Math.abs(v);
|
avg += Math.abs(v);
|
||||||
if (v > max) {
|
|
||||||
max = (float) v;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
avg /= getData().get(0).magnitudes.length;
|
avg /= getData().get(0).magnitudes.length;
|
||||||
System.out.println(avg);
|
volHistory.add((int) (((avg*-1)+40)/3));
|
||||||
volHistory.add((int) (getData().get(0).level * 100));
|
|
||||||
getData().clear();
|
getData().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +36,6 @@ public class AudioVolumeEffect extends AudioFFTEffect {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < volHistory.size(); x++) {
|
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.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);
|
g.drawRect(x, HEIGHT - volHistory.get(x), 0, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue