secondary backed array to get previous windows. Not sure whether or not to use.
This commit is contained in:
parent
03966d124a
commit
193f972d01
@ -5,6 +5,7 @@ import static org.lwjgl.openal.AL10.*;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.openal.AL11;
|
import org.lwjgl.openal.AL11;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
@ -25,6 +26,8 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
private boolean updatePositioning = true;
|
private boolean updatePositioning = true;
|
||||||
private boolean mmSet;
|
private boolean mmSet;
|
||||||
private MusicManager mm;
|
private MusicManager mm;
|
||||||
|
private ShortBuffer prevBuffer;
|
||||||
|
private ShortBuffer compareBuffer;
|
||||||
private ShortBuffer buffer;
|
private ShortBuffer buffer;
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
private float visRefreshRate = 1f/60f;
|
private float visRefreshRate = 1f/60f;
|
||||||
@ -81,18 +84,45 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
|
|
||||||
public void calcPCMData() {
|
public void calcPCMData() {
|
||||||
short chanVal;
|
short chanVal;
|
||||||
|
int bufferPosOffset = 0;
|
||||||
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
||||||
updateBufferPosition();
|
bufferPosOffset = updateBufferPosition();
|
||||||
|
if (bufferPosOffset < 0) {
|
||||||
|
prevBuffer.position(prevBuffer.limit()+bufferPosOffset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int sid = 0; sid < vis.getAudioPCM().length && sid < buffer.remaining(); sid++) {
|
for (int sid = 0; sid < vis.getAudioPCM().length && sid < buffer.remaining(); sid++) {
|
||||||
for (int channel = 0; channel < mm.getChannelCount(); channel ++) {
|
for (int channel = 0; channel < mm.getChannelCount(); channel ++) {
|
||||||
|
if (prevBuffer.position() < prevBuffer.limit()) {
|
||||||
|
if (vis.getAudioPCM()[sid] < (chanVal = prevBuffer.get())) {
|
||||||
|
vis.getAudioPCM()[sid] = chanVal;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (vis.getAudioPCM()[sid] < (chanVal = buffer.get())) {
|
if (vis.getAudioPCM()[sid] < (chanVal = buffer.get())) {
|
||||||
vis.getAudioPCM()[sid] = chanVal;
|
vis.getAudioPCM()[sid] = chanVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
vis.getAudioPCM()[sid] /= Short.MAX_VALUE+1f;
|
vis.getAudioPCM()[sid] /= Short.MAX_VALUE+1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int originalPos = buffer.position();
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
}
|
||||||
|
compareBuffer.clear();
|
||||||
|
compareBuffer.put(buffer);
|
||||||
|
compareBuffer.flip();
|
||||||
|
buffer.position(originalPos);
|
||||||
readWindowIndex++;
|
readWindowIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +133,6 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
buffer.position(pos);
|
buffer.position(pos);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
Gdx.app.error("BufferPosition", iae + " position was " + pos);
|
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@ -116,6 +145,20 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
} catch (ReflectionException e) {
|
} catch (ReflectionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
int originalPos = buffer.position();
|
||||||
|
|
||||||
|
|
||||||
|
prevBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
|
buffer.rewind();
|
||||||
|
prevBuffer.put(buffer);
|
||||||
|
prevBuffer.flip();
|
||||||
|
|
||||||
|
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
|
buffer.rewind();
|
||||||
|
compareBuffer.put(buffer);
|
||||||
|
compareBuffer.flip();
|
||||||
|
|
||||||
|
buffer.position(originalPos);
|
||||||
this.mm = mm;
|
this.mm = mm;
|
||||||
mmSet = false;
|
mmSet = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user