From 0fdc65796d993bb4c87134613118c8f573cb9071 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 18 May 2018 01:25:02 -0500 Subject: [PATCH] visualizer should now be stable (with proper new buffer system) --- .../rhythmbullet/audio/MusicManager.java | 2 +- .../audio/visualizer/DesktopVisualizer.java | 23 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicManager.java b/core/src/zero1hd/rhythmbullet/audio/MusicManager.java index fbf8bc9..8e3521a 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicManager.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicManager.java @@ -9,7 +9,7 @@ import com.badlogic.gdx.utils.Disposable; public interface MusicManager extends Disposable { /** * sets a integer variable to the current window of audio data the playback is at. - * Useful for efficiency because we compute once for that frame then get the values everytime it is required instead of calculating every time we get the index. + * Useful for efficiency because we compute once for that frame then get the values every time it is required instead of calculating every time we get the index. * @return the playback window index. */ public int playbackIndexUpdate(); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java index 2710642..0858f14 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/audio/visualizer/DesktopVisualizer.java @@ -10,6 +10,7 @@ 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; @@ -47,21 +48,17 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { int bufferPosOffset = 0; if (mm.playbackIndexUpdate() != readWindowIndex) { bufferPosOffset = updateBufferPosition(); - if (bufferPosOffset < 0 && playingBuffer.limit()+bufferPosOffset > 0) { - playingBuffer.position(playingBuffer.limit()+bufferPosOffset); + if (bufferPosOffset < 0) { + playingBuffer.position(Math.max(playingBuffer.limit()+bufferPosOffset, 0)); + } else { + buffer.position(bufferPosOffset); } } - - for (int sid = 0; sid < getAudioPCM().length && sid < buffer.remaining(); sid++) { + for (int sid = 0; sid < getAudioPCM().length && sid < playingBuffer.remaining(); sid++) { + getAudioPCM()[sid] = 0; for (int channel = 0; channel < mm.getChannelCount(); channel ++) { - if (playingBuffer.position() < playingBuffer.limit()) { - if (getAudioPCM()[sid] < (chanVal = playingBuffer.get())) { - getAudioPCM()[sid] = chanVal; - } - } else { - if (getAudioPCM()[sid] < (chanVal = buffer.get())) { - getAudioPCM()[sid] = chanVal; - } + if (getAudioPCM()[sid] < (chanVal = playingBuffer.get())) { + getAudioPCM()[sid] = chanVal; } } getAudioPCM()[sid] /= Short.MAX_VALUE+1f; @@ -96,7 +93,7 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer { //put the second portion into the first... playingBuffer.put(playingBuffer.array(), buffer.capacity(), buffer.capacity()); } - //put the new buffer in the second portion. + //put the new buffer into the remaining portion. playingBuffer.put(compareBuffer); }