From 3e05e66a38ac2c4b6c6678a071b4b4d82a1e5213 Mon Sep 17 00:00:00 2001 From: Recrown Date: Mon, 11 Sep 2017 14:58:04 -0500 Subject: [PATCH] switched to using sprites for testing (in progress) --- .../visualizer/HorizontalVisualizer.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java index 3a622fe..09a5bd3 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.MathUtils; import zero1hd.rhythmbullet.audio.MusicDataPack; @@ -16,9 +17,11 @@ public class HorizontalVisualizer extends VisualizerCore { private int barWidth; private int binsPerBar; private int spaceBetweenBars; - private int[] barHeights; + private Sprite[] bars; private int smoothRange; private float barHeightMultiplier; + private float rotation; + public HorizontalVisualizer() { super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0); barHeightMultiplier = Gdx.graphics.getHeight()*0.01f; @@ -32,34 +35,41 @@ public class HorizontalVisualizer extends VisualizerCore { spaceBetweenBars = (barWidth-2); barWidth -= spaceBetweenBars; smoothRange = 4; - barHeights = new int[barCount]; + bars = new Sprite[barCount]; + for (int i = 0; i < bars.length; i++) { + bars[i] = new Sprite(bar); + } } @Override public void render(Batch batch, float parentAlpha) { if (cmi != null) { + //Averaging bins together for (int i = 0; i < barCount; i++) { - barHeights[i] = 0; + bars[i].setSize(barWidth, 0); + float barHeight = 0; for (int j = 0; j < binsPerBar; j++) { - barHeights[i] += Math.abs(audioPCM[j+i*binsPerBar]); + barHeight += Math.abs(audioPCM[j+i*binsPerBar]); } - barHeights[i] /= binsPerBar; - barHeights[i] *= barHeightMultiplier; + barHeight /= binsPerBar; + barHeight *= barHeightMultiplier; + bars[i].setSize(barWidth, barHeight); } + //Drawing... for (int i = 0; i < barCount; i++) { int avg = 0; + //Averaging the bars for (int range = 0; range < smoothRange; range++) { if (i+range < barCount) { - avg += barHeights[i+range]; + avg += bars[i+range].getHeight(); } if (i-range >= 0) { - avg += barHeights[i-range]; + avg += bars[i-range].getHeight(); } - } - barHeights[i] = avg/(smoothRange*2); - batch.draw(bar, xPos + i*(barWidth+spaceBetweenBars), yPos, barWidth, barHeights[i]); + bars[i].setSize(barWidth, avg/(smoothRange*2)); + bars[i].draw(batch); } } super.render(batch, parentAlpha);