re-organized visualizer setup for future ease of use
This commit is contained in:
parent
7f51ca2c55
commit
b9f70e0c9d
@ -17,7 +17,7 @@ public class MirrorVisualizer {
|
|||||||
rectCoordRot = new Vector2();
|
rectCoordRot = new Vector2();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setup(Sprite[] bars, float xPos, float yPos, float rotation) {
|
public void setup(Sprite[] bars, float xPos, float yPos, float rotation) {
|
||||||
this.bars = new Sprite[bars.length];
|
this.bars = new Sprite[bars.length];
|
||||||
this.xPos = (int) xPos;
|
this.xPos = (int) xPos;
|
||||||
this.yPos = (int) yPos;
|
this.yPos = (int) yPos;
|
||||||
|
@ -8,21 +8,14 @@ import com.badlogic.gdx.utils.Disposable;
|
|||||||
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
||||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||||
|
|
||||||
public class VisualizerCore implements Disposable {
|
public class MusicManagerFFT implements Disposable {
|
||||||
protected MusicManager mm;
|
protected MusicManager mm;
|
||||||
private FloatFFT_1D fft;
|
private FloatFFT_1D fft;
|
||||||
protected float width, height;
|
|
||||||
protected float xPos, yPos;
|
|
||||||
protected int barCount;
|
|
||||||
private boolean calc;
|
private boolean calc;
|
||||||
private ReentrantLock lock;
|
private ReentrantLock lock;
|
||||||
protected float[] audioPCM;
|
protected float[] audioPCM;
|
||||||
|
|
||||||
public VisualizerCore(int width, int height, int x, int y) {
|
public MusicManagerFFT() {
|
||||||
this.height = height;
|
|
||||||
this.width = width;
|
|
||||||
this.xPos = x;
|
|
||||||
this.yPos = y;
|
|
||||||
lock = new ReentrantLock();
|
lock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,36 +49,6 @@ public class VisualizerCore implements Disposable {
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setxPos(float xPos) {
|
|
||||||
this.xPos = xPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setyPos(float yPos) {
|
|
||||||
this.yPos = yPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWidth(float width) {
|
|
||||||
this.width = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHeight(float height) {
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getxPos() {
|
|
||||||
return xPos;
|
|
||||||
}
|
|
||||||
public float getyPos() {
|
|
||||||
return yPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
public float getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MusicManager getMm() {
|
public MusicManager getMm() {
|
||||||
return mm;
|
return mm;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package zero1hd.rhythmbullet.audio.visualizer;
|
package zero1hd.rhythmbullet.desktop.audio.visualizer;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
@ -12,8 +12,9 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||||
|
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
|
||||||
|
|
||||||
public class BasicVisualizer extends VisualizerCore {
|
public class HorizontalVisualizer extends Visualizer {
|
||||||
private Pixmap pixmap;
|
private Pixmap pixmap;
|
||||||
private Texture barTexture;
|
private Texture barTexture;
|
||||||
private int barWidth;
|
private int barWidth;
|
||||||
@ -30,14 +31,23 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
private boolean reverse;
|
private boolean reverse;
|
||||||
private float maxAvgHeight;
|
private float maxAvgHeight;
|
||||||
private float currentAvg;
|
private float currentAvg;
|
||||||
|
private int barCount;
|
||||||
|
private float width, height, x, y;
|
||||||
|
|
||||||
public BasicVisualizer() {
|
public HorizontalVisualizer() {
|
||||||
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
|
super();
|
||||||
mirrors = new Array<>();
|
mirrors = new Array<>();
|
||||||
pixmap = new Pixmap(2, 2, Format.RGBA8888);
|
pixmap = new Pixmap(2, 2, Format.RGBA8888);
|
||||||
pixmap.setColor(Color.WHITE);
|
pixmap.setColor(Color.WHITE);
|
||||||
pixmap.fill();
|
pixmap.fill();
|
||||||
barCount = 70;
|
barCount = 70;
|
||||||
|
|
||||||
|
width = Gdx.graphics.getWidth();
|
||||||
|
height = Gdx.graphics.getHeight()/2f;
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
|
||||||
|
|
||||||
smoothRange = 3;
|
smoothRange = 3;
|
||||||
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
||||||
bars = new Sprite[barCount];
|
bars = new Sprite[barCount];
|
||||||
@ -65,41 +75,43 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(float delta) {
|
public void update(float delta) {
|
||||||
//Averaging bins together
|
if (mm != null) {
|
||||||
for (int i = 0; i < barCount; i++) {
|
//Averaging bins together
|
||||||
float barHeight = 0;
|
for (int i = 0; i < barCount; i++) {
|
||||||
for (int j = 0; j < binsPerBar; j++) {
|
float barHeight = 0;
|
||||||
barHeight += Math.abs(audioPCM[j+i*binsPerBar +1]);
|
for (int j = 0; j < binsPerBar; j++) {
|
||||||
}
|
barHeight += Math.abs(audioPCM[j+i*binsPerBar +1]);
|
||||||
barHeight /= binsPerBar;
|
|
||||||
barHeight *= barHeightMultiplier;
|
|
||||||
barHeights[i] = barHeight;
|
|
||||||
}
|
|
||||||
currentAvg = 0;
|
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
if (i-range >= 0) {
|
barHeight /= binsPerBar;
|
||||||
avg += barHeights[i-range];
|
barHeight *= barHeightMultiplier;
|
||||||
|
barHeights[i] = barHeight;
|
||||||
|
}
|
||||||
|
currentAvg = 0;
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
if (i-range >= 0) {
|
||||||
|
avg += barHeights[i-range];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avg /= smoothRange*2;
|
||||||
|
barHeights[i] = avg;
|
||||||
|
currentAvg += barHeights[i];
|
||||||
|
if (bars[i].getHeight() > barHeights[i]) {
|
||||||
|
bars[i].setSize(barWidth, bars[i].getHeight() - (15f*delta*(bars[i].getHeight()-barHeights[i])));
|
||||||
|
} else {
|
||||||
|
bars[i].setSize(barWidth, bars[i].getHeight() + (20f*delta*(barHeights[i] - bars[i].getHeight())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
avg /= smoothRange*2;
|
currentAvg /= barHeights.length;
|
||||||
barHeights[i] = avg;
|
if (currentAvg > maxAvgHeight) {
|
||||||
currentAvg += barHeights[i];
|
maxAvgHeight = currentAvg;
|
||||||
if (bars[i].getHeight() > barHeights[i]) {
|
|
||||||
bars[i].setSize(barWidth, bars[i].getHeight() - (15f*delta*(bars[i].getHeight()-barHeights[i])));
|
|
||||||
} else {
|
|
||||||
bars[i].setSize(barWidth, bars[i].getHeight() + (20f*delta*(barHeights[i] - bars[i].getHeight())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentAvg /= barHeights.length;
|
|
||||||
if (currentAvg > maxAvgHeight) {
|
|
||||||
maxAvgHeight = currentAvg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -134,9 +146,9 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
bars[i].setRotation(rotation);
|
bars[i].setRotation(rotation);
|
||||||
}
|
}
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
bars[bars.length-i-1].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
|
bars[bars.length-i-1].setPosition(x + barSpace*angleRot.x, y + barSpace*angleRot.y);
|
||||||
} else {
|
} else {
|
||||||
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
|
bars[i].setPosition(x + barSpace*angleRot.x, y + barSpace*angleRot.y);
|
||||||
}
|
}
|
||||||
for (int mirrorIndex = 0; mirrorIndex < mirrors.size; mirrorIndex++) {
|
for (int mirrorIndex = 0; mirrorIndex < mirrors.size; mirrorIndex++) {
|
||||||
mirrors.get(mirrorIndex).position(i, barWidth, spaceBetweenBars);
|
mirrors.get(mirrorIndex).position(i, barWidth, spaceBetweenBars);
|
||||||
@ -181,9 +193,9 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
|
|
||||||
public void addMirrorVisualizer(MirrorVisualizer mirror) {
|
public void addMirrorVisualizer(MirrorVisualizer mirror) {
|
||||||
updatePositionInfo();
|
updatePositionInfo();
|
||||||
mirror.setup(bars, xPos, yPos, rotation);
|
mirror.setup(bars, x, y, rotation);
|
||||||
mirrors.add(mirror);
|
mirrors.add(mirror);
|
||||||
setxPos(((getWidth() - getActualWidth())/2f));
|
x = (int) (((width - getActualWidth())/2f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMirrorVisualizer(MirrorVisualizer mirror) {
|
public void removeMirrorVisualizer(MirrorVisualizer mirror) {
|
||||||
@ -221,4 +233,36 @@ public class BasicVisualizer extends VisualizerCore {
|
|||||||
public int getSpaceBetweenBars() {
|
public int getSpaceBetweenBars() {
|
||||||
return spaceBetweenBars;
|
return spaceBetweenBars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setX(float x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(float y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(float width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(float height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,218 +1,126 @@
|
|||||||
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
|
package zero1hd.rhythmbullet.desktop.audio.visualizer;
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL10.*;
|
import static org.lwjgl.openal.AL10.alGetSourcef;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.lwjgl.openal.AL11;
|
import org.lwjgl.openal.AL11;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic;
|
import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.utils.reflect.Field;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
|
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||||
import com.badlogic.gdx.utils.reflect.Field;
|
import zero1hd.rhythmbullet.audio.visualizer.MusicManagerFFT;
|
||||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
|
||||||
|
public class Visualizer extends MusicManagerFFT {
|
||||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
private ShortBuffer playingBuffer;
|
||||||
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
|
private ShortBuffer compareBuffer;
|
||||||
|
private ShortBuffer buffer;
|
||||||
public class Visualizer extends Widget implements Disposable {
|
private int sourceID;
|
||||||
private BasicVisualizer vis;
|
private int readWindowIndex;
|
||||||
private boolean updatePositioning = true;
|
|
||||||
private boolean mmSet;
|
public Visualizer() {
|
||||||
private MusicManager mm;
|
super();
|
||||||
private ShortBuffer playingBuffer;
|
try {
|
||||||
private ShortBuffer compareBuffer;
|
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
|
||||||
private ShortBuffer buffer;
|
bufferField.setAccessible(true);
|
||||||
private int sourceID;
|
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
|
||||||
private float visRefreshRate;
|
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
||||||
private float timer;
|
e.printStackTrace();
|
||||||
private int readWindowIndex;
|
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.");
|
||||||
public Visualizer() {
|
Gdx.app.exit();
|
||||||
vis = new BasicVisualizer();
|
}
|
||||||
|
}
|
||||||
try {
|
|
||||||
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
|
public void calcPCMData() {
|
||||||
bufferField.setAccessible(true);
|
short chanVal;
|
||||||
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
|
int bufferPosOffset = 0;
|
||||||
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
||||||
e.printStackTrace();
|
bufferPosOffset = updateBufferPosition();
|
||||||
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.");
|
if (bufferPosOffset < 0 && playingBuffer.limit()+bufferPosOffset > 0) {
|
||||||
Gdx.app.exit();
|
playingBuffer.position(playingBuffer.limit()+bufferPosOffset);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
for (int sid = 0; sid < getAudioPCM().length && sid < buffer.remaining(); sid++) {
|
||||||
@Override
|
for (int channel = 0; channel < mm.getChannelCount(); channel ++) {
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
if (playingBuffer.position() < playingBuffer.limit()) {
|
||||||
vis.render(batch, parentAlpha);
|
if (getAudioPCM()[sid] < (chanVal = playingBuffer.get())) {
|
||||||
super.draw(batch, parentAlpha);
|
getAudioPCM()[sid] = chanVal;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
@Override
|
if (getAudioPCM()[sid] < (chanVal = buffer.get())) {
|
||||||
public void act(float delta) {
|
getAudioPCM()[sid] = chanVal;
|
||||||
if (mm != null && mm.isFinishedLoading() && !mmSet) {
|
}
|
||||||
vis.setMM(mm);
|
}
|
||||||
visRefreshRate = mm.getReadWindowSize()/mm.getSampleRate();
|
}
|
||||||
mmSet = true;
|
getAudioPCM()[sid] /= Short.MAX_VALUE+1f;
|
||||||
Gdx.app.debug("Visualizer", "\nsample count: " + mm.getSampleCount()
|
}
|
||||||
+ "\nDuration in seconds: " + mm.getDuration() +
|
readWindowIndex++;
|
||||||
"\nSample rate: " + mm.getSampleRate() +
|
|
||||||
"\nRefresh rate: " + visRefreshRate);
|
|
||||||
}
|
//Take down original buffer position so we don't need to sync again after...
|
||||||
|
int originalPos = buffer.position();
|
||||||
vis.update(delta);
|
|
||||||
updateVisualizerProperties();
|
//Begin comparison
|
||||||
if (updatePositioning) {
|
buffer.rewind();
|
||||||
vis.updatePositionInfo();
|
if (compareBuffer.compareTo(buffer) != 0) {
|
||||||
vis.setxPos((getWidth() - vis.getActualWidth())/2f);
|
bufferChanged();
|
||||||
}
|
|
||||||
if (mmSet) {
|
|
||||||
if (timer >= visRefreshRate) {
|
//Begin copying current buffer to the comparison buffer
|
||||||
timer = 0;
|
compareBuffer.clear();
|
||||||
calcPCMData();
|
compareBuffer.put(buffer);
|
||||||
vis.calculate(delta);
|
compareBuffer.flip();
|
||||||
} else {
|
}
|
||||||
timer += delta;
|
|
||||||
}
|
//Reset buffer to proper position.
|
||||||
}
|
buffer.position(originalPos);
|
||||||
super.act(delta);
|
}
|
||||||
}
|
|
||||||
|
private void bufferChanged() {
|
||||||
public void calcPCMData() {
|
playingBuffer.clear();
|
||||||
short chanVal;
|
playingBuffer.put(compareBuffer);
|
||||||
int bufferPosOffset = 0;
|
}
|
||||||
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
|
||||||
bufferPosOffset = updateBufferPosition();
|
private int updateBufferPosition() {
|
||||||
if (bufferPosOffset < 0 && playingBuffer.limit()+bufferPosOffset > 0) {
|
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize());
|
||||||
playingBuffer.position(playingBuffer.limit()+bufferPosOffset);
|
readWindowIndex = mm.getPlaybackIndexPosition()-1;
|
||||||
}
|
if (pos < 0) {
|
||||||
}
|
buffer.position(0);
|
||||||
|
} else {
|
||||||
for (int sid = 0; sid < vis.getAudioPCM().length && sid < buffer.remaining(); sid++) {
|
buffer.position(pos);
|
||||||
for (int channel = 0; channel < mm.getChannelCount(); channel ++) {
|
}
|
||||||
if (playingBuffer.position() < playingBuffer.limit()) {
|
return pos;
|
||||||
if (vis.getAudioPCM()[sid] < (chanVal = playingBuffer.get())) {
|
}
|
||||||
vis.getAudioPCM()[sid] = chanVal;
|
|
||||||
}
|
public void setMM(MusicManager mm) {
|
||||||
} else {
|
try {
|
||||||
if (vis.getAudioPCM()[sid] < (chanVal = buffer.get())) {
|
Field sourceIDField = ClassReflection.getDeclaredField(OpenALMusic.class, "sourceID");
|
||||||
vis.getAudioPCM()[sid] = chanVal;
|
sourceIDField.setAccessible(true);
|
||||||
}
|
sourceID = (int) sourceIDField.get(mm.getMusic());
|
||||||
}
|
} catch (ReflectionException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
vis.getAudioPCM()[sid] /= Short.MAX_VALUE+1f;
|
}
|
||||||
}
|
int originalPos = buffer.position();
|
||||||
readWindowIndex++;
|
|
||||||
|
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
|
buffer.rewind();
|
||||||
//Take down original buffer position so we don't need to sync again after...
|
playingBuffer.put(buffer);
|
||||||
int originalPos = buffer.position();
|
playingBuffer.flip();
|
||||||
|
|
||||||
//Begin comparison
|
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
if (compareBuffer.compareTo(buffer) != 0) {
|
compareBuffer.put(buffer);
|
||||||
bufferChanged();
|
compareBuffer.flip();
|
||||||
|
|
||||||
|
buffer.position(originalPos);
|
||||||
//Begin copying current buffer to the comparison buffer
|
this.mm = mm;
|
||||||
compareBuffer.clear();
|
|
||||||
compareBuffer.put(buffer);
|
super.setMM(mm);
|
||||||
compareBuffer.flip();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset buffer to proper position.
|
|
||||||
buffer.position(originalPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bufferChanged() {
|
|
||||||
playingBuffer.clear();
|
|
||||||
playingBuffer.put(compareBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int updateBufferPosition() {
|
|
||||||
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize());
|
|
||||||
readWindowIndex = mm.getPlaybackIndexPosition()-1;
|
|
||||||
if (pos < 0) {
|
|
||||||
buffer.position(0);
|
|
||||||
} else {
|
|
||||||
buffer.position(pos);
|
|
||||||
}
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMM(MusicManager mm) {
|
|
||||||
try {
|
|
||||||
Field sourceIDField = ClassReflection.getDeclaredField(OpenALMusic.class, "sourceID");
|
|
||||||
sourceIDField.setAccessible(true);
|
|
||||||
sourceID = (int) sourceIDField.get(mm.getMusic());
|
|
||||||
} catch (ReflectionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
int originalPos = buffer.position();
|
|
||||||
|
|
||||||
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
|
||||||
buffer.rewind();
|
|
||||||
playingBuffer.put(buffer);
|
|
||||||
playingBuffer.flip();
|
|
||||||
|
|
||||||
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
|
||||||
buffer.rewind();
|
|
||||||
compareBuffer.put(buffer);
|
|
||||||
compareBuffer.flip();
|
|
||||||
|
|
||||||
buffer.position(originalPos);
|
|
||||||
this.mm = mm;
|
|
||||||
mmSet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setColor(Color color) {
|
|
||||||
vis.setColor(color);
|
|
||||||
super.setColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setColor(float r, float g, float b, float a) {
|
|
||||||
vis.setColor(r, g, b, a);
|
|
||||||
super.setColor(r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateVisualizerProperties() {
|
|
||||||
vis.setHeight(getHeight());
|
|
||||||
vis.setWidth(getWidth());
|
|
||||||
vis.setxPos(getX());
|
|
||||||
vis.setyPos(getY());
|
|
||||||
vis.setRotation(getRotation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdatePositioning(boolean updatePositioning) {
|
|
||||||
updateVisualPosition();
|
|
||||||
this.updatePositioning = updatePositioning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateVisualPosition() {
|
|
||||||
updateVisualizerProperties();
|
|
||||||
vis.updatePositionInfo();
|
|
||||||
vis.setxPos(((vis.getWidth() - vis.getActualWidth())/2f));
|
|
||||||
vis.updatePositionInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUpdatePositioning() {
|
|
||||||
return updatePositioning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicVisualizer getVis() {
|
|
||||||
return vis;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
vis.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,110 @@
|
|||||||
|
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
|
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||||
|
import zero1hd.rhythmbullet.desktop.audio.visualizer.HorizontalVisualizer;
|
||||||
|
|
||||||
|
public class HorizontalVisualizerWidget extends Widget implements Disposable {
|
||||||
|
private HorizontalVisualizer vis;
|
||||||
|
private boolean updatePositioning = true;
|
||||||
|
private MusicManager mm;
|
||||||
|
private boolean initialLoad;
|
||||||
|
private float visRefreshRate;
|
||||||
|
private float timer;
|
||||||
|
public HorizontalVisualizerWidget() {
|
||||||
|
vis = new HorizontalVisualizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
|
vis.render(batch, parentAlpha);
|
||||||
|
super.draw(batch, parentAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void act(float delta) {
|
||||||
|
if (mm != null && mm.isFinishedLoading() && !initialLoad) {
|
||||||
|
visRefreshRate = mm.getReadWindowSize()/mm.getSampleRate();
|
||||||
|
Gdx.app.debug("Visualizer", "\nsample count: " + mm.getSampleCount()
|
||||||
|
+ "\nDuration in seconds: " + mm.getDuration() +
|
||||||
|
"\nSample rate: " + mm.getSampleRate() +
|
||||||
|
"\nRefresh rate: " + visRefreshRate);
|
||||||
|
vis.setMM(mm);
|
||||||
|
initialLoad = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatePositioning) {
|
||||||
|
vis.updatePositionInfo();
|
||||||
|
vis.setX((getWidth() - vis.getActualWidth())/2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
vis.update(delta);
|
||||||
|
updateVisualizerProperties();
|
||||||
|
if (mm != null && initialLoad) {
|
||||||
|
if (timer >= visRefreshRate) {
|
||||||
|
timer = 0;
|
||||||
|
vis.calcPCMData();
|
||||||
|
vis.calculate(delta);
|
||||||
|
} else {
|
||||||
|
timer += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.act(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMM(MusicManager mm) {
|
||||||
|
initialLoad = false;
|
||||||
|
this.mm = mm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColor(Color color) {
|
||||||
|
vis.setColor(color);
|
||||||
|
super.setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setColor(float r, float g, float b, float a) {
|
||||||
|
vis.setColor(r, g, b, a);
|
||||||
|
super.setColor(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateVisualizerProperties() {
|
||||||
|
vis.setHeight(getHeight());
|
||||||
|
vis.setWidth(getWidth());
|
||||||
|
vis.setX(getX());
|
||||||
|
vis.setY(getY());
|
||||||
|
vis.setRotation(getRotation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatePositioning(boolean updatePositioning) {
|
||||||
|
updateVisualPosition();
|
||||||
|
this.updatePositioning = updatePositioning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateVisualPosition() {
|
||||||
|
updateVisualizerProperties();
|
||||||
|
vis.updatePositionInfo();
|
||||||
|
vis.setX(((vis.getWidth() - vis.getActualWidth())/2f));
|
||||||
|
vis.updatePositionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUpdatePositioning() {
|
||||||
|
return updatePositioning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HorizontalVisualizer getVis() {
|
||||||
|
return vis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
vis.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,7 +19,7 @@ import com.badlogic.gdx.utils.Disposable;
|
|||||||
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
|
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
|
||||||
|
|
||||||
public class TitleBarVisualizer extends Group implements Disposable {
|
public class TitleBarVisualizer extends Group implements Disposable {
|
||||||
private Visualizer visual;
|
private HorizontalVisualizerWidget visual;
|
||||||
private MirrorVisualizer visual2;
|
private MirrorVisualizer visual2;
|
||||||
private Texture bgTexture;
|
private Texture bgTexture;
|
||||||
private Image bg;
|
private Image bg;
|
||||||
@ -32,7 +32,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
private float particleLimitTime;
|
private float particleLimitTime;
|
||||||
public TitleBarVisualizer(AssetManager assets) {
|
public TitleBarVisualizer(AssetManager assets) {
|
||||||
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
|
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
|
||||||
visual = new Visualizer();
|
visual = new HorizontalVisualizerWidget();
|
||||||
visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()- 2);
|
visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()- 2);
|
||||||
addActor(visual);
|
addActor(visual);
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
|
|||||||
super.draw(batch, parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Visualizer getHvisual() {
|
public HorizontalVisualizerWidget getHvisual() {
|
||||||
return visual;
|
return visual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user