visualizer should now be stable (with proper new buffer system)
This commit is contained in:
parent
874ef52bb9
commit
0fdc65796d
@ -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();
|
||||
|
@ -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,22 +48,18 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user