slightly better buffer system

This commit is contained in:
Harrison Deng 2018-04-15 14:04:59 -05:00
parent 62dc7381c6
commit abf3028cfb

View File

@ -89,7 +89,14 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer {
}
private void bufferChanged() {
playingBuffer.clear();
//set position to beginning to prepare for overwrite
playingBuffer.position(0);
//if the backing playing buffer is full, we have two sections: A and B. A is the one before B, and is read from due to playback latency and offset. B is merely a buffer.
if (playingBuffer.limit() == playingBuffer.capacity()) {
//put the second portion into the first...
playingBuffer.put(playingBuffer.array(), buffer.capacity(), buffer.capacity());
}
//put the new buffer in the second portion.
playingBuffer.put(compareBuffer);
}
@ -118,7 +125,7 @@ public class DesktopVisualizer extends MusicManagerFFT implements Visualizer {
}
int originalPos = buffer.position();
playingBuffer = ShortBuffer.allocate(buffer.capacity());
playingBuffer = ShortBuffer.allocate(buffer.capacity()*2);
buffer.rewind();
playingBuffer.put(buffer);
playingBuffer.flip();