smoothed out bar height changes, used locks to better remedy song transition bar height issue
This commit is contained in:
parent
087b709a02
commit
8cbefb1f0f
@ -70,7 +70,7 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
|
|
||||||
//Averaging bins together
|
//Averaging bins together
|
||||||
for (int i = 0; i < barCount; i++) {
|
for (int i = 0; i < barCount; i++) {
|
||||||
float barHeight = 2;
|
float barHeight = 0;
|
||||||
for (int j = 0; j < binsPerBar; j++) {
|
for (int j = 0; j < binsPerBar; j++) {
|
||||||
barHeight += Math.abs(audioPCM[j+i*binsPerBar]);
|
barHeight += Math.abs(audioPCM[j+i*binsPerBar]);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,11 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
avg /= smoothRange*2;
|
avg /= smoothRange*2;
|
||||||
barHeights[i] = avg;
|
barHeights[i] = avg;
|
||||||
|
|
||||||
bars[i].setSize(barWidth, bars[i].getHeight() <= barHeights[i] ? barHeights[i] : bars[i].getHeight() - 1.1f*Gdx.graphics.getHeight()*delta);
|
if (bars[i].getHeight() > barHeights[i]) {
|
||||||
|
bars[i].setSize(barWidth, bars[i].getHeight() - (20f*delta*(bars[i].getHeight()-barHeights[i])));
|
||||||
|
} else {
|
||||||
|
bars[i].setSize(barWidth, bars[i].getHeight() + (27f*delta*(barHeights[i] - bars[i].getHeight())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +144,9 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
for (int i = 0; i < bars.length; i++) {
|
for (int i = 0; i < bars.length; i++) {
|
||||||
bars[i].setColor(color);
|
bars[i].setColor(color);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < mirrors.size; i++) {
|
||||||
|
mirrors.get(i).setColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(float r, float g, float b, float a) {
|
public void setColor(float r, float g, float b, float a) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package zero1hd.rhythmbullet.audio.visualizer;
|
package zero1hd.rhythmbullet.audio.visualizer;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
@ -47,6 +48,12 @@ public class MirrorVisualizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
for (int i = 0; i < bars.length; i++) {
|
||||||
|
bars[i].setColor(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public float getRotation() {
|
public float getRotation() {
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package zero1hd.rhythmbullet.audio.visualizer;
|
package zero1hd.rhythmbullet.audio.visualizer;
|
||||||
|
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
@ -13,28 +15,39 @@ public class VisualizerCore implements Disposable {
|
|||||||
protected float width, height;
|
protected float width, height;
|
||||||
protected float xPos, yPos;
|
protected float xPos, yPos;
|
||||||
protected int barCount;
|
protected int barCount;
|
||||||
|
private boolean calc;
|
||||||
|
private ReentrantLock lock;
|
||||||
public VisualizerCore(int width, int height, int x, int y) {
|
public VisualizerCore(int width, int height, int x, int y) {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.xPos = x;
|
this.xPos = x;
|
||||||
this.yPos = y;
|
this.yPos = y;
|
||||||
|
|
||||||
|
lock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculate() {
|
public void calculate() {
|
||||||
if (mm != null) {
|
if (mm != null) {
|
||||||
mm.playbackIndexUpdate();
|
mm.playbackIndexUpdate();
|
||||||
while (mm.isPlaying() && mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
|
while (calc && mm.isPlaying() && mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
|
||||||
|
lock.lock();
|
||||||
mm.readSamples(audioPCM);
|
mm.readSamples(audioPCM);
|
||||||
fft.realForward(audioPCM);
|
fft.realForward(audioPCM);
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMM(MusicManager mm) {
|
public void setMM(MusicManager mm) {
|
||||||
this.mm = mm;
|
if (audioPCM == null || audioPCM.length != mm.getReadWindowSize()) {
|
||||||
|
calc = false;
|
||||||
|
lock.lock();
|
||||||
fft = new FloatFFT_1D(mm.getReadWindowSize());
|
fft = new FloatFFT_1D(mm.getReadWindowSize());
|
||||||
audioPCM = new float[mm.getReadWindowSize()];
|
audioPCM = new float[mm.getReadWindowSize()];
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
this.mm = mm;
|
||||||
|
calc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Batch batch, float parentAlpha) {
|
public void render(Batch batch, float parentAlpha) {
|
||||||
|
@ -42,6 +42,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
pixmap.fill();
|
pixmap.fill();
|
||||||
bgTexture = new Texture(pixmap);
|
bgTexture = new Texture(pixmap);
|
||||||
pixmap.dispose();
|
pixmap.dispose();
|
||||||
|
setColor(0.451f, 0, 0, 1f);
|
||||||
|
|
||||||
bg = new Image(bgTexture);
|
bg = new Image(bgTexture);
|
||||||
bg.setSize(getWidth(), getHeight());
|
bg.setSize(getWidth(), getHeight());
|
||||||
@ -68,6 +69,8 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor(Color color) {
|
public void setColor(Color color) {
|
||||||
|
bg.setColor(getColor());
|
||||||
|
visual.setColor(getColor());
|
||||||
super.setColor(color);
|
super.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
Gdx.gl.glClearColor(0.212f, 0.094f, 0f, 1f);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
stage.act();
|
stage.act();
|
||||||
stage.draw();
|
stage.draw();
|
||||||
|
Loading…
Reference in New Issue
Block a user