From 45e3b55d846dff5c54ab2f2461ee53479387ca23 Mon Sep 17 00:00:00 2001 From: Recrown Date: Tue, 22 May 2018 23:30:52 -0500 Subject: [PATCH] new sync system for visualizer --- .../audio/visualizer/HorizontalVisualizer.java | 2 +- .../audio/visualizer/DesktopVisualizer.java | 15 +++------------ .../ui/components/HorizontalVisualizerWidget.java | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java index 6dccd75..964dfa4 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/HorizontalVisualizer.java @@ -133,7 +133,7 @@ public class HorizontalVisualizer implements Disposable { } public void updatePositionInfo() { - barHeightMultiplier = height*0.03f; + barHeightMultiplier = height; int barSpace = 0; angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java index 0858f14..169850d 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java @@ -10,7 +10,6 @@ import org.lwjgl.openal.AL11; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.Field; import com.badlogic.gdx.utils.reflect.ReflectionException; @@ -24,7 +23,6 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { private ShortBuffer compareBuffer; private ShortBuffer buffer; private int sourceID; - private int readWindowIndex; public DesktopVisualizer() { super(); @@ -46,14 +44,9 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { public void calcPCMData() { short chanVal; int bufferPosOffset = 0; - if (mm.playbackIndexUpdate() != readWindowIndex) { - bufferPosOffset = updateBufferPosition(); - if (bufferPosOffset < 0) { - playingBuffer.position(Math.max(playingBuffer.limit()+bufferPosOffset, 0)); - } else { - buffer.position(bufferPosOffset); - } - } + bufferPosOffset = updateBufferPosition(); + playingBuffer.position(Math.max(playingBuffer.limit()+bufferPosOffset, 0)); + for (int sid = 0; sid < getAudioPCM().length && sid < playingBuffer.remaining(); sid++) { getAudioPCM()[sid] = 0; for (int channel = 0; channel < mm.getChannelCount(); channel ++) { @@ -63,7 +56,6 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { } getAudioPCM()[sid] /= Short.MAX_VALUE+1f; } - readWindowIndex++; //Take down original buffer position so we don't need to sync again after... @@ -99,7 +91,6 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { private int updateBufferPosition() { int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize()); - readWindowIndex = mm.getPlaybackIndexPosition()-1; return pos; } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HorizontalVisualizerWidget.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HorizontalVisualizerWidget.java index f078999..18cf596 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HorizontalVisualizerWidget.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HorizontalVisualizerWidget.java @@ -49,8 +49,8 @@ public class HorizontalVisualizerWidget extends Widget implements Disposable { if (mm != null && initialLoad) { if (timer >= visRefreshRate) { timer = 0; - vis.calcPCMData(); vis.calculate(); + vis.calcPCMData(); } else { timer += delta; }