From 4d6cbaa652ad929ab7ab751ee0356090c6efb5bd Mon Sep 17 00:00:00 2001 From: Recrown Date: Thu, 11 Jan 2018 00:14:57 -0600 Subject: [PATCH] added comments --- .../graphics/ui/components/Visualizer.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) 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 643ae11..780bf58 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java @@ -5,7 +5,6 @@ import static org.lwjgl.openal.AL10.*; import java.nio.ByteBuffer; import java.nio.ShortBuffer; -import org.lwjgl.BufferUtils; import org.lwjgl.openal.AL11; import com.badlogic.gdx.Gdx; @@ -106,30 +105,36 @@ public class Visualizer extends Widget implements Disposable { } vis.getAudioPCM()[sid] /= Short.MAX_VALUE+1f; } + readWindowIndex++; + //Take down original buffer position so we don't need to sync again after... int originalPos = buffer.position(); - + //Begin comparison buffer.rewind(); - compareBuffer.rewind(); if (compareBuffer.compareTo(buffer) != 0) { - prevBuffer.clear(); - prevBuffer.put(compareBuffer); - System.out.println("Buffer switched: " + prevBuffer.get(5) + "-" + buffer.get(5) + "-" + compareBuffer.get(5)); - } else { + bufferChanged(); } + + //Begin copying current buffer to the comparison buffer compareBuffer.clear(); compareBuffer.put(buffer); compareBuffer.flip(); + + //Reset buffer to proper position. buffer.position(originalPos); - readWindowIndex++; + } + + private void bufferChanged() { + prevBuffer.clear(); + prevBuffer.put(compareBuffer); } private int updateBufferPosition() { int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-mm.getReadWindowSize()*mm.getChannelCount()); try { - readWindowIndex = mm.getPlaybackIndexPosition(); + readWindowIndex = mm.getPlaybackIndexPosition()-1; buffer.position(pos); } catch (IllegalArgumentException iae) { buffer.position(0);