minor cleanup

This commit is contained in:
Harrison Deng 2018-01-10 01:41:21 -06:00
parent 7b8f442f98
commit df56545408

View File

@ -27,13 +27,15 @@ public class Visualizer extends Widget implements Disposable {
private MusicManager mm;
private ShortBuffer buffer;
private int sourceID;
private float visRefreshRate = 1f/60f;
private float timer;
public Visualizer() {
vis = new BasicVisualizer();
try {
Field tempBufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
tempBufferField.setAccessible(true);
buffer = ((ByteBuffer) tempBufferField.get(null)).asShortBuffer();
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
bufferField.setAccessible(true);
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer();
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
e.printStackTrace();
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.");
@ -64,18 +66,23 @@ public class Visualizer extends Widget implements Disposable {
vis.setxPos((getWidth() - vis.getActualWidth())/2f);
}
if (mmSet) {
setupPCMData();
}
if (timer >= visRefreshRate) {
timer = 0;
calcPCMData();
vis.calculate(delta);
} else {
timer += delta;
}
}
super.act(delta);
}
public void setupPCMData() {
public void calcPCMData() {
short chanVal;
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET)-4));
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET)));
try {
buffer.position((int) Math.max(0, pos));
buffer.position(pos);
} catch (IllegalArgumentException outOfBounds) {
System.out.println(outOfBounds);
}