visualizer synching improved
This commit is contained in:
parent
b07c9ffd44
commit
c91a08bc3b
@ -25,7 +25,7 @@ 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 playingBuffer;
|
||||||
private ShortBuffer compareBuffer;
|
private ShortBuffer compareBuffer;
|
||||||
private ShortBuffer buffer;
|
private ShortBuffer buffer;
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
@ -87,15 +87,15 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
int bufferPosOffset = 0;
|
int bufferPosOffset = 0;
|
||||||
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
if (mm.playbackIndexUpdate() != readWindowIndex) {
|
||||||
bufferPosOffset = updateBufferPosition();
|
bufferPosOffset = updateBufferPosition();
|
||||||
if (bufferPosOffset < 0) {
|
if (bufferPosOffset < 0 && playingBuffer.limit()+bufferPosOffset > 0) {
|
||||||
prevBuffer.position(prevBuffer.limit()+bufferPosOffset);
|
playingBuffer.position(playingBuffer.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 (playingBuffer.position() < playingBuffer.limit()) {
|
||||||
if (vis.getAudioPCM()[sid] < (chanVal = prevBuffer.get())) {
|
if (vis.getAudioPCM()[sid] < (chanVal = playingBuffer.get())) {
|
||||||
vis.getAudioPCM()[sid] = chanVal;
|
vis.getAudioPCM()[sid] = chanVal;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -128,12 +128,12 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bufferChanged() {
|
private void bufferChanged() {
|
||||||
prevBuffer.clear();
|
playingBuffer.clear();
|
||||||
prevBuffer.put(compareBuffer);
|
playingBuffer.put(compareBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int updateBufferPosition() {
|
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 {
|
try {
|
||||||
readWindowIndex = mm.getPlaybackIndexPosition()-1;
|
readWindowIndex = mm.getPlaybackIndexPosition()-1;
|
||||||
buffer.position(pos);
|
buffer.position(pos);
|
||||||
@ -154,10 +154,10 @@ public class Visualizer extends Widget implements Disposable {
|
|||||||
int originalPos = buffer.position();
|
int originalPos = buffer.position();
|
||||||
|
|
||||||
System.out.println(visRefreshRate);
|
System.out.println(visRefreshRate);
|
||||||
prevBuffer = ShortBuffer.allocate(buffer.capacity());
|
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
prevBuffer.put(buffer);
|
playingBuffer.put(buffer);
|
||||||
prevBuffer.flip();
|
playingBuffer.flip();
|
||||||
|
|
||||||
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user