new sync system for visualizer

This commit is contained in:
Harrison Deng 2018-05-22 23:30:52 -05:00
parent 0fdc65796d
commit 45e3b55d84
3 changed files with 5 additions and 14 deletions

View File

@ -133,7 +133,7 @@ public class HorizontalVisualizer implements Disposable {
} }
public void updatePositionInfo() { public void updatePositionInfo() {
barHeightMultiplier = height*0.03f; barHeightMultiplier = height;
int barSpace = 0; int barSpace = 0;
angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));

View File

@ -10,7 +10,6 @@ import org.lwjgl.openal.AL11;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic; import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic;
import com.badlogic.gdx.graphics.g2d.Batch; 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.ClassReflection;
import com.badlogic.gdx.utils.reflect.Field; import com.badlogic.gdx.utils.reflect.Field;
import com.badlogic.gdx.utils.reflect.ReflectionException; import com.badlogic.gdx.utils.reflect.ReflectionException;
@ -24,7 +23,6 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer {
private ShortBuffer compareBuffer; private ShortBuffer compareBuffer;
private ShortBuffer buffer; private ShortBuffer buffer;
private int sourceID; private int sourceID;
private int readWindowIndex;
public DesktopVisualizer() { public DesktopVisualizer() {
super(); super();
@ -46,14 +44,9 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer {
public void calcPCMData() { public void calcPCMData() {
short chanVal; short chanVal;
int bufferPosOffset = 0; int bufferPosOffset = 0;
if (mm.playbackIndexUpdate() != readWindowIndex) { bufferPosOffset = updateBufferPosition();
bufferPosOffset = updateBufferPosition(); playingBuffer.position(Math.max(playingBuffer.limit()+bufferPosOffset, 0));
if (bufferPosOffset < 0) {
playingBuffer.position(Math.max(playingBuffer.limit()+bufferPosOffset, 0));
} else {
buffer.position(bufferPosOffset);
}
}
for (int sid = 0; sid < getAudioPCM().length && sid < playingBuffer.remaining(); sid++) { for (int sid = 0; sid < getAudioPCM().length && sid < playingBuffer.remaining(); sid++) {
getAudioPCM()[sid] = 0; getAudioPCM()[sid] = 0;
for (int channel = 0; channel < mm.getChannelCount(); channel ++) { 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; getAudioPCM()[sid] /= Short.MAX_VALUE+1f;
} }
readWindowIndex++;
//Take down original buffer position so we don't need to sync again after... //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() { private int updateBufferPosition() {
int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize()); int pos = (int) ((alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET))-buffer.limit()-mm.getChannelCount()*mm.getReadWindowSize());
readWindowIndex = mm.getPlaybackIndexPosition()-1;
return pos; return pos;
} }

View File

@ -49,8 +49,8 @@ public class HorizontalVisualizerWidget extends Widget implements Disposable {
if (mm != null && initialLoad) { if (mm != null && initialLoad) {
if (timer >= visRefreshRate) { if (timer >= visRefreshRate) {
timer = 0; timer = 0;
vis.calcPCMData();
vis.calculate(); vis.calculate();
vis.calcPCMData();
} else { } else {
timer += delta; timer += delta;
} }