visualizer now more flexible, leading to new visualizer design for main

page
This commit is contained in:
2018-08-17 02:37:17 -05:00
parent 1e98d34035
commit 89e3abed63
2 changed files with 19 additions and 21 deletions

View File

@@ -21,24 +21,25 @@ public class DoubleHorizontalVisualizer implements Disposable {
private int binsPerBar;
private float offset;
private int boundaryThickness;
private float baseSensitivity;
private float targetDelta;
private float spacePercentage = 0.85f;
private int barCount = 80;
private float normalFactor = 0.8f;
private float spacePercentage = 0.7f;
private int barCount = 90;
private float barChangeRate = 14f;
private int smoothRange = 1;
private int binsToInclude = 160;
private Color color = new Color(1f, 1f, 1f, 0.85f);
private int binsToInclude = 180;
private Color color = new Color(0.5f, 0.6f, 0.8f, 0.46f);
/**
*
* @param barCount amount of bars this visualizer should have.
* @param width the width of the visualizer.
* @param spacePercentage the percentage of a bar that should be space.
*/
public DoubleHorizontalVisualizer(int width, int height, int targetFPS, MusicController musicController, PCMSystem PCMSystem) {
public DoubleHorizontalVisualizer(int width, int height, float baseSensitivity, int boundaryThickness, int targetFPS, MusicController musicController, PCMSystem PCMSystem) {
this.barWidth = width/barCount;
this.spaceBetweenBars = MathUtils.round(barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars;
this.baseSensitivity = baseSensitivity;
pcm = PCMSystem;
binsPerBar = (binsToInclude/barCount);
this.width = width;
@@ -52,17 +53,13 @@ public class DoubleHorizontalVisualizer implements Disposable {
}
public void act(float delta) {
if (color.r > 1f) color.r = 0f;
if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f;
float[] freqBins = pcm.getFrequencyBins();
for (int bar = 0; bar < amplitudes.length; bar++) {
float normalizedAmplitude = 0;
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
normalizedAmplitude += Math.abs(freqBins[freq]);
}
amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
amplitudes[bar] += normalizedAmplitude * baseSensitivity;
amplitudes[bar] /= binsPerBar;
}
for (int bar = 0; bar < barHeights.length; bar++) {
@@ -88,7 +85,6 @@ public class DoubleHorizontalVisualizer implements Disposable {
barHeights[bar] += pixelsMoved;
if (barHeights[bar] < 0) barHeights[bar] = 0;
if (barHeights[bar] > height) barHeights[bar] = height;
}
}
@@ -99,8 +95,10 @@ public class DoubleHorizontalVisualizer implements Disposable {
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
shapeRenderer.rect(x, y, width, boundaryThickness);
shapeRenderer.rect(x, y+height, width, -boundaryThickness);
if (boundaryThickness > 0) {
shapeRenderer.rect(x, y, width, boundaryThickness);
shapeRenderer.rect(x, y+height, width, -boundaryThickness);
}
for (int bar = 0; bar < barCount; bar++) {
shapeRenderer.setColor(color);