diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java index ce0a156..fb04aee 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java @@ -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; + } } - vis.calculate(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); }