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

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

View File

@ -46,13 +46,13 @@ public class MainPage extends Page implements Observer {
this.mc = musicController; this.mc = musicController;
this.mc.addObserver(this); this.mc.addObserver(this);
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) (getHeight()*0.3), screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc)); dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) 0, 2.5f, 0, screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc));
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f)); dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class)); title = new Image(assetManager.get("title.png", Texture.class));
title.setScale((dhv.getHeight() - 14)/title.getHeight()); title.setScale((getHeight()/3f - 14)/title.getHeight());
if (title.getWidth()*title.getScaleX() > dhv.getWidth() - 30) { if (title.getWidth()*title.getScaleX() > getWidth() - 30) {
title.setScale((dhv.getWidth() - 30)/title.getWidth()*getScaleX()); title.setScale((getWidth() - 30)/title.getWidth()*getScaleX());
} }
title.setPosition((getWidth()-title.getWidth()*title.getScaleX())/2f, (getHeight()-title.getHeight()*title.getScaleY())/2f); title.setPosition((getWidth()-title.getWidth()*title.getScaleX())/2f, (getHeight()-title.getHeight()*title.getScaleY())/2f);
addActor(title); addActor(title);
@ -62,7 +62,7 @@ public class MainPage extends Page implements Observer {
addActor(versionLabel); addActor(versionLabel);
menuTable = new Table(); menuTable = new Table();
menuTable.setSize(getWidth(), dhv.getY()); menuTable.setSize(getWidth(), title.getY());
menuTable.align(Align.center); menuTable.align(Align.center);
menuTable.defaults().space(10f); menuTable.defaults().space(10f);
addActor(menuTable); addActor(menuTable);
@ -100,14 +100,14 @@ public class MainPage extends Page implements Observer {
@Override @Override
public void act(float delta) { public void act(float delta) {
super.act(delta);
dhv.act(delta); dhv.act(delta);
super.act(delta);
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
dhv.draw(batch, parentAlpha); dhv.draw(batch, parentAlpha);
super.draw(batch, parentAlpha);
} }
@Override @Override