From c91a08bc3b911394eb01cbebe1d9c5a89f59b337 Mon Sep 17 00:00:00 2001 From: Recrown Date: Sun, 14 Jan 2018 14:07:55 -0600 Subject: [PATCH] visualizer synching improved --- .../graphics/ui/components/Visualizer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 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 d9fb24d..8b03cb2 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/Visualizer.java @@ -25,7 +25,7 @@ public class Visualizer extends Widget implements Disposable { private boolean updatePositioning = true; private boolean mmSet; private MusicManager mm; - private ShortBuffer prevBuffer; + private ShortBuffer playingBuffer; private ShortBuffer compareBuffer; private ShortBuffer buffer; private int sourceID; @@ -87,15 +87,15 @@ public class Visualizer extends Widget implements Disposable { int bufferPosOffset = 0; if (mm.playbackIndexUpdate() != readWindowIndex) { bufferPosOffset = updateBufferPosition(); - if (bufferPosOffset < 0) { - prevBuffer.position(prevBuffer.limit()+bufferPosOffset); + if (bufferPosOffset < 0 && playingBuffer.limit()+bufferPosOffset > 0) { + playingBuffer.position(playingBuffer.limit()+bufferPosOffset); } } for (int sid = 0; sid < vis.getAudioPCM().length && sid < buffer.remaining(); sid++) { for (int channel = 0; channel < mm.getChannelCount(); channel ++) { - if (prevBuffer.position() < prevBuffer.limit()) { - if (vis.getAudioPCM()[sid] < (chanVal = prevBuffer.get())) { + if (playingBuffer.position() < playingBuffer.limit()) { + if (vis.getAudioPCM()[sid] < (chanVal = playingBuffer.get())) { vis.getAudioPCM()[sid] = chanVal; } } else { @@ -128,12 +128,12 @@ public class Visualizer extends Widget implements Disposable { } private void bufferChanged() { - prevBuffer.clear(); - prevBuffer.put(compareBuffer); + playingBuffer.clear(); + playingBuffer.put(compareBuffer); } private int updateBufferPosition() { - int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-mm.getReadWindowSize()*mm.getChannelCount()); + int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize()); try { readWindowIndex = mm.getPlaybackIndexPosition()-1; buffer.position(pos); @@ -154,10 +154,10 @@ public class Visualizer extends Widget implements Disposable { int originalPos = buffer.position(); System.out.println(visRefreshRate); - prevBuffer = ShortBuffer.allocate(buffer.capacity()); + playingBuffer = ShortBuffer.allocate(buffer.capacity()); buffer.rewind(); - prevBuffer.put(buffer); - prevBuffer.flip(); + playingBuffer.put(buffer); + playingBuffer.flip(); compareBuffer = ShortBuffer.allocate(buffer.capacity()); buffer.rewind();