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
|
||||
for (int i = 0; i < barCount; i++) {
|
||||
float barHeight = 2;
|
||||
float barHeight = 0;
|
||||
for (int j = 0; j < binsPerBar; j++) {
|
||||
barHeight += Math.abs(audioPCM[j+i*binsPerBar]);
|
||||
}
|
||||
@ -92,7 +92,11 @@ public class BasicVisualizer extends VisualizerCore {
|
||||
avg /= smoothRange*2;
|
||||
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++) {
|
||||
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) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package zero1hd.rhythmbullet.audio.visualizer;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
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() {
|
||||
return rotation;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package zero1hd.rhythmbullet.audio.visualizer;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
@ -13,28 +15,39 @@ public class VisualizerCore implements Disposable {
|
||||
protected float width, height;
|
||||
protected float xPos, yPos;
|
||||
protected int barCount;
|
||||
|
||||
private boolean calc;
|
||||
private ReentrantLock lock;
|
||||
public VisualizerCore(int width, int height, int x, int y) {
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.xPos = x;
|
||||
this.yPos = y;
|
||||
|
||||
lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
public void calculate() {
|
||||
if (mm != null) {
|
||||
mm.playbackIndexUpdate();
|
||||
while (mm.isPlaying() && mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
|
||||
while (calc && mm.isPlaying() && mm.getPlaybackIndexPosition() > mm.getCurrentReadWindowIndex()) {
|
||||
lock.lock();
|
||||
mm.readSamples(audioPCM);
|
||||
fft.realForward(audioPCM);
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setMM(MusicManager mm) {
|
||||
if (audioPCM == null || audioPCM.length != mm.getReadWindowSize()) {
|
||||
calc = false;
|
||||
lock.lock();
|
||||
fft = new FloatFFT_1D(mm.getReadWindowSize());
|
||||
audioPCM = new float[mm.getReadWindowSize()];
|
||||
lock.unlock();
|
||||
}
|
||||
this.mm = mm;
|
||||
fft = new FloatFFT_1D(mm.getReadWindowSize());
|
||||
audioPCM = new float[mm.getReadWindowSize()];
|
||||
calc = true;
|
||||
}
|
||||
|
||||
public void render(Batch batch, float parentAlpha) {
|
||||
|
@ -42,7 +42,8 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
||||
pixmap.fill();
|
||||
bgTexture = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
|
||||
setColor(0.451f, 0, 0, 1f);
|
||||
|
||||
bg = new Image(bgTexture);
|
||||
bg.setSize(getWidth(), getHeight());
|
||||
addActor(bg);
|
||||
@ -68,6 +69,8 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
bg.setColor(getColor());
|
||||
visual.setColor(getColor());
|
||||
super.setColor(color);
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
|
||||
@Override
|
||||
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);
|
||||
stage.act();
|
||||
stage.draw();
|
||||
|
Loading…
Reference in New Issue
Block a user