minor cleanup
This commit is contained in:
parent
7b8f442f98
commit
df56545408
@ -27,13 +27,15 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
private MusicManager mm;
|
private MusicManager mm;
|
||||||
private ShortBuffer buffer;
|
private ShortBuffer buffer;
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
|
private float visRefreshRate = 1f/60f;
|
||||||
|
private float timer;
|
||||||
public Visualizer() {
|
public Visualizer() {
|
||||||
vis = new BasicVisualizer();
|
vis = new BasicVisualizer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Field tempBufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
|
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
|
||||||
tempBufferField.setAccessible(true);
|
bufferField.setAccessible(true);
|
||||||
buffer = ((ByteBuffer) tempBufferField.get(null)).asShortBuffer();
|
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer();
|
||||||
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.");
|
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);
|
vis.setxPos((getWidth() - vis.getActualWidth())/2f);
|
||||||
}
|
}
|
||||||
if (mmSet) {
|
if (mmSet) {
|
||||||
setupPCMData();
|
if (timer >= visRefreshRate) {
|
||||||
}
|
timer = 0;
|
||||||
|
calcPCMData();
|
||||||
vis.calculate(delta);
|
vis.calculate(delta);
|
||||||
|
} else {
|
||||||
|
timer += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
super.act(delta);
|
super.act(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupPCMData() {
|
public void calcPCMData() {
|
||||||
short chanVal;
|
short chanVal;
|
||||||
|
|
||||||
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET)-4));
|
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET)));
|
||||||
try {
|
try {
|
||||||
buffer.position((int) Math.max(0, pos));
|
buffer.position(pos);
|
||||||
} catch (IllegalArgumentException outOfBounds) {
|
} catch (IllegalArgumentException outOfBounds) {
|
||||||
System.out.println(outOfBounds);
|
System.out.println(outOfBounds);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user